Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeEditor related changes and ko language added #215

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ private void UpdateStatusBar()
{
int lineNumber = _view.TextEditor.Document.GetLineByOffset(_view.TextEditor.CaretOffset).LineNumber;
int colPosition = _view.TextEditor.TextArea.Caret.VisualColumn + 1;
int charPosition = _view.TextEditor.CaretOffset;

// TODO: Now I don't know about Ch#
//int charPosition = _view.TextEditor.CaretOffset;

if (_statusBar != null && _statusBar.Items.Count >= 3)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Gemini/Framework/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ Task ICommandHandler<RedoCommandDefinition>.Run(Command command)

void ICommandHandler<SaveFileCommandDefinition>.Update(Command command)
{
command.Enabled = this is IPersistedDocument;
var persistedDocument = this as IPersistedDocument;
command.Enabled = (persistedDocument != null && persistedDocument.IsDirty);
}

async Task ICommandHandler<SaveFileCommandDefinition>.Run(Command command)
Expand Down
1 change: 1 addition & 0 deletions src/Gemini/Framework/IPersistedDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Gemini.Framework
public interface IPersistedDocument : IDocument
{
bool IsNew { get; }
bool IsDirty { get; }
string FileName { get; }
string FilePath { get; }

Expand Down
12 changes: 9 additions & 3 deletions src/Gemini/Gemini.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,12 @@
</Compile>
<Compile Include="Modules\Shell\Commands\CloseFileCommandDefinition.cs" />
<Compile Include="Modules\Shell\Commands\CloseFileCommandHandler.cs" />
<Compile Include="Modules\Shell\Commands\OpenRecentCommandListDefinition.cs" />
<Compile Include="Modules\Shell\Commands\OpenRecentCommandHandler.cs" />
<Compile Include="Modules\Shell\Commands\OpenRecentFileCommandListDefinition.cs" />
<Compile Include="Modules\Shell\Commands\OpenRecentFileCommandHandler.cs" />
<Compile Include="Modules\Shell\Commands\RecentFilesCommandDefinition.cs" />
<Compile Include="Modules\Shell\Commands\RecentFilesCommandHandler.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 @@ -457,7 +461,9 @@
<ItemGroup>
<Resource Include="Resources\Icons\Save.png" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Resource Include="Resources\Icons\Saveall.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void InitializeList()
{
Properties.Settings.Default.RecentDocuments = new StringCollection();
}

foreach (string filePath in Properties.Settings.Default.RecentDocuments)
{
_items.Add(new RecentFileItemViewModel(filePath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace Gemini.Modules.Shell.Commands
{
[CommandHandler]
public class OpenRecentFileCommandHandler : ICommandListHandler<OpenRecentCommandListDefinition>
public class OpenRecentFileCommandHandler : ICommandListHandler<OpenRecentFileCommandListDefinition>
{
private readonly IShell _shell;

Expand All @@ -26,7 +26,7 @@ public OpenRecentFileCommandHandler(IShell shell)
}

public void Populate(Command command, List<Command> commands)
{
{
for (var i = 0; i < _shell.RecentFiles.Items.Count; i++)
{
var item = _shell.RecentFiles.Items[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace Gemini.Modules.Shell.Commands
{
[CommandDefinition]
public class OpenRecentCommandListDefinition : CommandListDefinition
public class OpenRecentFileCommandListDefinition : CommandListDefinition
{
public const string CommandName = "File.OpenRecent";
public const string CommandName = "File.OpenRecentFileList";

public override string Name
{
Expand Down
26 changes: 26 additions & 0 deletions src/Gemini/Modules/Shell/Commands/RecentFilesCommandDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Gemini.Framework.Commands;
using Gemini.Properties;

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

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

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

public override string ToolTip
{
get { return Resources.FileOpenRecentCommandToolTip; }
}
}
}
33 changes: 33 additions & 0 deletions src/Gemini/Modules/Shell/Commands/RecentFilesCommandHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Gemini.Framework.Commands;
using Gemini.Framework.Services;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

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

public override void Update(Command command)
{
command.Enabled = (_shell.RecentFiles.Items.Count > 0);
}

public override Task Run(Command command)
{
return null;
}
}
}
43 changes: 43 additions & 0 deletions src/Gemini/Modules/Shell/Commands/SaveAllFilesCommandDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Gemini.Framework.Commands;
using Gemini.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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"); }
}


// TODO: there is a bug in case of multiple modifiers
//[Export]
//public static CommandKeyboardShortcut KeyGesture = new CommandKeyboardShortcut<SaveFileCommandDefinition>(new KeyGesture(Key.S, ModifierKeys.Control | ModifierKeys.Shift));
}
}
52 changes: 52 additions & 0 deletions src/Gemini/Modules/Shell/Commands/SaveAllFilesCommandHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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.Text;
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nitpick, remove the async and return TaskUtility.Completed here, otherwise the compiler will give warnings.

{
var tasks = new List<Task<Tuple<IPersistedDocument, bool>>>();

foreach (var document in _shell.Documents)
{
var persistedDocument = document as IPersistedDocument;
if (persistedDocument == null) continue;

// skip if the file is new
if (!persistedDocument.IsNew)
{
tasks.Add(DoSaveAsync(persistedDocument));
}
}

// TODO: display "Item(s) saved" in statusbar
}

// http://stackoverflow.com/questions/19431494/how-to-use-await-in-a-loop
private async Task<Tuple<IPersistedDocument, bool>> DoSaveAsync(IPersistedDocument persistedDocument)
{
var filePath = persistedDocument.FilePath;
await persistedDocument.Save(filePath);

return Tuple.Create(persistedDocument, true);
}
}
}
16 changes: 10 additions & 6 deletions src/Gemini/Modules/Shell/MenuDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@ public static class MenuDefinitions
MainMenu.MenuDefinitions.FileSaveMenuGroup, 1);

[Export]
public static MenuItemDefinition FileOpenRecentMenuItem = new TextMenuItemDefinition(
MainMenu.MenuDefinitions.FileOpenRecentMenuGroup, 0, Resources.FileOpenRecentCommandText);
public static MenuItemDefinition FileSaveAllMenuItem = new CommandMenuItemDefinition<SaveAllFilesCommandDefinition>(
MainMenu.MenuDefinitions.FileSaveMenuGroup, 2);

[Export]
public static MenuItemGroupDefinition FileOpenRecentCascadeGroup = new MenuItemGroupDefinition(
FileOpenRecentMenuItem, 0);
public static MenuItemDefinition FileRecentFilesMenuItem = new CommandMenuItemDefinition<RecentFilesCommandDefinition>(
MainMenu.MenuDefinitions.FileOpenRecentMenuGroup, 0);

[Export]
public static MenuItemDefinition FileOpenRecentMenuItemList = new CommandMenuItemDefinition<OpenRecentCommandListDefinition>(
FileOpenRecentCascadeGroup, 0);
public static MenuItemGroupDefinition FileRecentFilesCascadeGroup = new MenuItemGroupDefinition(
FileRecentFilesMenuItem, 0);

[Export]
public static MenuItemDefinition FileOpenRecentMenuItemList = new CommandMenuItemDefinition<OpenRecentFileCommandListDefinition>(
FileRecentFilesCascadeGroup, 0);

[Export]
public static MenuItemDefinition FileExitMenuItem = new CommandMenuItemDefinition<ExitCommandDefinition>(
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);
}
}
18 changes: 18 additions & 0 deletions src/Gemini/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Gemini/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,10 @@
<data name="ThemeDarkName" xml:space="preserve">
<value>Dark</value>
</data>
<data name="FileSaveAllCommandText" xml:space="preserve">
<value>Save All</value>
</data>
<data name="FileSaveAllCommandToolTip" xml:space="preserve">
<value>Save All</value>
</data>
</root>
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.