-
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
466 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/Gemini/Modules/RecentFiles/Commands/OpenRecentFileCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Caliburn.Micro; | ||
using Gemini.Framework; | ||
using Gemini.Framework.Commands; | ||
using Gemini.Framework.Services; | ||
using Gemini.Modules.Shell.Commands; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.Composition; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace Gemini.Modules.RecentFiles.Commands | ||
{ | ||
[CommandHandler] | ||
public class OpenRecentFileCommandHandler : ICommandListHandler<OpenRecentFileCommandListDefinition> | ||
{ | ||
private readonly IShell _shell; | ||
|
||
[ImportingConstructor] | ||
public OpenRecentFileCommandHandler(IShell shell) | ||
{ | ||
_shell = 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]; | ||
commands.Add(new Command(command.CommandDefinition) | ||
{ | ||
Text = string.Format("_{0} {1}", i + 1, item.DisplayName), | ||
ToolTip = item.FilePath, | ||
Tag = item.FilePath | ||
}); | ||
} | ||
} | ||
|
||
public async Task Run(Command command) | ||
{ | ||
var newPath = (string)command.Tag; | ||
|
||
// Check if the document is already open | ||
foreach (var document in _shell.Documents.OfType<PersistedDocument>().Where(d => !d.IsNew)) | ||
{ | ||
if (string.IsNullOrEmpty(document.FilePath)) | ||
continue; | ||
|
||
var docPath = Path.GetFullPath(document.FilePath); | ||
if (string.Equals(newPath, docPath, System.StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
_shell.OpenDocument(document); | ||
return; | ||
} | ||
} | ||
|
||
_shell.OpenDocument(await OpenFileCommandHandler.GetEditor(newPath)); | ||
|
||
// Add the file to the recent documents list | ||
_shell.RecentFiles.Update(newPath); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Gemini/Modules/RecentFiles/Commands/OpenRecentFileCommandListDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Gemini.Framework.Commands; | ||
|
||
namespace Gemini.Modules.RecentFiles.Commands | ||
{ | ||
[CommandDefinition] | ||
public class OpenRecentFileCommandListDefinition : CommandListDefinition | ||
{ | ||
public const string CommandName = "File.OpenRecentFileList"; | ||
|
||
public override string Name | ||
{ | ||
get { return CommandName; } | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Gemini/Modules/RecentFiles/Commands/RecentFilesCommandDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Gemini.Framework.Commands; | ||
using Gemini.Properties; | ||
|
||
namespace Gemini.Modules.RecentFiles.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.FileRecentFilesCommandText; } | ||
} | ||
|
||
public override string ToolTip | ||
{ | ||
get { return Resources.FileRecentFilesCommandToolTip; } | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/Gemini/Modules/RecentFiles/Commands/RecentFilesCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Gemini.Framework.Commands; | ||
using Gemini.Framework.Services; | ||
using System.ComponentModel.Composition; | ||
using System.Threading.Tasks; | ||
|
||
namespace Gemini.Modules.RecentFiles.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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Caliburn.Micro; | ||
using Gemini.Modules.RecentFiles.ViewModels; | ||
|
||
namespace Gemini.Modules.RecentFiles | ||
{ | ||
public interface IRecentFiles | ||
{ | ||
IObservableCollection<RecentFileItemViewModel> Items { get; } | ||
|
||
void Update(string filePath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Gemini.Framework.Menus; | ||
using Gemini.Modules.RecentFiles.Commands; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.Composition; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Gemini.Modules.RecentFiles | ||
{ | ||
public static class MenuDefinitions | ||
{ | ||
[Export] | ||
public static MenuItemDefinition FileRecentFilesMenuItem = new CommandMenuItemDefinition<RecentFilesCommandDefinition>( | ||
MainMenu.MenuDefinitions.FileOpenRecentMenuGroup, 0); | ||
|
||
[Export] | ||
public static MenuItemGroupDefinition FileRecentFilesCascadeGroup = new MenuItemGroupDefinition( | ||
FileRecentFilesMenuItem, 0); | ||
|
||
[Export] | ||
public static MenuItemDefinition FileOpenRecentMenuItemList = new CommandMenuItemDefinition<OpenRecentFileCommandListDefinition>( | ||
FileRecentFilesCascadeGroup, 0); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/Gemini/Modules/RecentFiles/ViewModels/RecentFileItemViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Caliburn.Micro; | ||
|
||
namespace Gemini.Modules.RecentFiles.ViewModels | ||
{ | ||
public class RecentFileItemViewModel : PropertyChangedBase | ||
{ | ||
private int _index; | ||
public int Index | ||
{ | ||
get { return _index; } | ||
internal set | ||
{ | ||
_index = value; | ||
NotifyOfPropertyChange(() => Index); | ||
} | ||
} | ||
|
||
private string _filePath; | ||
public string FilePath | ||
{ | ||
get { return _filePath; } | ||
set | ||
{ | ||
_filePath = value; | ||
_displayName = ShortenPath(_filePath); | ||
NotifyOfPropertyChange(() => FilePath); | ||
} | ||
} | ||
|
||
private string _displayName; | ||
public string DisplayName | ||
{ | ||
get { return _displayName; } | ||
} | ||
|
||
// TODO: will implement Pinned | ||
private bool _pinned = false; | ||
public bool Pinned | ||
{ | ||
get { return _pinned; } | ||
set | ||
{ | ||
_pinned = value; | ||
NotifyOfPropertyChange(() => Pinned); | ||
} | ||
} | ||
|
||
public RecentFileItemViewModel(string filePath, bool pinned = false) | ||
{ | ||
_filePath = filePath; | ||
_displayName = ShortenPath(filePath); | ||
|
||
_pinned = pinned; | ||
} | ||
|
||
// http://stackoverflow.com/questions/8360360/function-to-shrink-file-path-to-be-more-human-readable | ||
private string ShortenPath(string path, int maxLength = 50) | ||
{ | ||
string[] splits = path.Split('\\'); | ||
|
||
string output = ""; | ||
|
||
if (splits.Length > 4) | ||
output = splits[0] + "\\" + splits[1] + "\\...\\" + splits[splits.Length - 2] + "\\" + splits[splits.Length - 1]; | ||
else | ||
output = string.Join("\\", splits, 0, splits.Length); | ||
|
||
return output; | ||
} | ||
} | ||
} |
Oops, something went wrong.