Skip to content

Commit

Permalink
Merge pull request #238 from diluculo/215_SaveAllCommand
Browse files Browse the repository at this point in the history
Add SaveAllCommand
  • Loading branch information
tgjones authored May 21, 2018
2 parents cf4b149 + aadeb81 commit fbddde7
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Gemini/Gemini.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@
<Compile Include="Modules\Shell\Commands\ViewFullscreenCommandDefinition.cs" />
<Compile Include="Modules\Shell\Commands\CloseFileCommandDefinition.cs" />
<Compile Include="Modules\Shell\Commands\CloseFileCommandHandler.cs" />
<Compile Include="Modules\Shell\Commands\SaveAllFilesCommandDefinition.cs" />
<Compile Include="Modules\Shell\Commands\SaveAllFilesCommandHandler.cs" />
<Compile Include="Modules\Shell\Commands\SaveFileAsCommandDefinition.cs" />
<Compile Include="Modules\Shell\Commands\SaveFileCommandDefinition.cs" />
<Compile Include="Modules\Shell\Commands\SwitchToDocumentCommandListDefinition.cs" />
Expand Down Expand Up @@ -460,6 +462,9 @@
<ItemGroup>
<Resource Include="Resources\Icons\Save.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Icons\SaveAll.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Icons\FullScreen.png" />
</ItemGroup>
Expand Down
40 changes: 40 additions & 0 deletions src/Gemini/Modules/Shell/Commands/SaveAllFilesCommandDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Gemini.Framework.Commands;
using Gemini.Properties;
using System;
using System.ComponentModel.Composition;
using System.Windows.Input;

namespace Gemini.Modules.Shell.Commands
{
[CommandDefinition]
public class SaveAllFilesCommandDefinition : CommandDefinition
{
public const string CommandName = "File.SaveAllFiles";

public override string Name
{
get { return CommandName; }
}

public override string Text
{
get { return Resources.FileSaveAllCommandText; }
}

public override string ToolTip
{
get { return Resources.FileSaveAllCommandToolTip; }
}

public override Uri IconSource
{
get
{
return new Uri("pack://application:,,,/Gemini;component/Resources/Icons/SaveAll.png");
}
}

[Export]
public static CommandKeyboardShortcut KeyGesture = new CommandKeyboardShortcut<SaveAllFilesCommandDefinition>(new KeyGesture(Key.S, ModifierKeys.Control | ModifierKeys.Shift));
}
}
35 changes: 35 additions & 0 deletions src/Gemini/Modules/Shell/Commands/SaveAllFilesCommandHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Gemini.Framework;
using Gemini.Framework.Commands;
using Gemini.Framework.Services;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Threading.Tasks;

namespace Gemini.Modules.Shell.Commands
{
[CommandHandler]
public class SaveAllFilesCommandHandler : CommandHandlerBase<SaveAllFilesCommandDefinition>
{
private readonly IShell _shell;

[ImportingConstructor]
public SaveAllFilesCommandHandler(IShell shell)
{
_shell = shell;
}

public override async Task Run(Command command)
{
var tasks = new List<Task<Tuple<IPersistedDocument, bool>>>();

foreach (var document in _shell.Documents.OfType<IPersistedDocument>().Where(x => !x.IsNew))
{
await document.Save(document.FilePath);
}

// TODO: display "Item(s) saved" in statusbar
}
}
}
4 changes: 4 additions & 0 deletions src/Gemini/Modules/Shell/MenuDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public static class MenuDefinitions
public static MenuItemDefinition FileSaveAsMenuItem = new CommandMenuItemDefinition<SaveFileAsCommandDefinition>(
MainMenu.MenuDefinitions.FileSaveMenuGroup, 1);

[Export]
public static MenuItemDefinition FileSaveAllMenuItem = new CommandMenuItemDefinition<SaveAllFilesCommandDefinition>(
MainMenu.MenuDefinitions.FileSaveMenuGroup, 1);

[Export]
public static MenuItemDefinition FileExitMenuItem = new CommandMenuItemDefinition<ExitCommandDefinition>(
MainMenu.MenuDefinitions.FileExitOpenMenuGroup, 0);
Expand Down
4 changes: 4 additions & 0 deletions src/Gemini/Modules/Shell/ToolBarDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ public static class ToolBarDefinitions
[Export]
public static ToolBarItemDefinition SaveFileToolBarItem = new CommandToolBarItemDefinition<SaveFileCommandDefinition>(
StandardOpenSaveToolBarGroup, 2);

[Export]
public static ToolBarItemDefinition SaveAllFilesToolBarItem = new CommandToolBarItemDefinition<SaveAllFilesCommandDefinition>(
StandardOpenSaveToolBarGroup, 4);
}
}
Binary file added src/Gemini/Resources/Icons/SaveAll.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fbddde7

Please sign in to comment.