Skip to content

Commit 0eaa7d3

Browse files
committed
feature: add hotkeys to save revision file
Signed-off-by: leo <[email protected]>
1 parent 7f838f1 commit 0eaa7d3

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

src/ViewModels/CommitDetail.cs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,33 @@ public void OpenChangeInMergeTool(Models.Change c)
254254
new Commands.DiffTool(_repo.FullPath, toolType, toolPath, opt).Open();
255255
}
256256

257+
public async Task SaveRevisionFile(Models.Object file)
258+
{
259+
var storageProvider = App.GetStorageProvider();
260+
if (storageProvider == null)
261+
return;
262+
263+
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
264+
try
265+
{
266+
var selected = await storageProvider.OpenFolderPickerAsync(options);
267+
if (selected.Count == 1)
268+
{
269+
var folder = selected[0];
270+
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder.Path.ToString();
271+
var saveTo = Path.Combine(folderPath, Path.GetFileName(file.Path)!);
272+
273+
await Commands.SaveRevisionFile
274+
.RunAsync(_repo.FullPath, _commit.SHA, file.Path, saveTo)
275+
.ConfigureAwait(false);
276+
}
277+
}
278+
catch (Exception e)
279+
{
280+
App.RaiseException(_repo.FullPath, $"Failed to save file: {e.Message}");
281+
}
282+
}
283+
257284
public ContextMenu CreateChangeContextMenuByFolder(ChangeTreeNode node, List<Models.Change> changes)
258285
{
259286
var fullPath = Native.OS.GetAbsPath(_repo.FullPath, node.FullPath);
@@ -540,32 +567,10 @@ public ContextMenu CreateRevisionFileContextMenu(Models.Object file)
540567
saveAs.Header = App.Text("SaveAs");
541568
saveAs.Icon = App.CreateMenuIcon("Icons.Save");
542569
saveAs.IsEnabled = file.Type == Models.ObjectType.Blob;
570+
saveAs.Tag = OperatingSystem.IsMacOS() ? "⌘+S" : "Ctrl+S";
543571
saveAs.Click += async (_, ev) =>
544572
{
545-
var storageProvider = App.GetStorageProvider();
546-
if (storageProvider == null)
547-
return;
548-
549-
var options = new FolderPickerOpenOptions() { AllowMultiple = false };
550-
try
551-
{
552-
var selected = await storageProvider.OpenFolderPickerAsync(options);
553-
if (selected.Count == 1)
554-
{
555-
var folder = selected[0];
556-
var folderPath = folder is { Path: { IsAbsoluteUri: true } path } ? path.LocalPath : folder.Path.ToString();
557-
var saveTo = Path.Combine(folderPath, Path.GetFileName(file.Path)!);
558-
559-
await Commands.SaveRevisionFile
560-
.RunAsync(_repo.FullPath, _commit.SHA, file.Path, saveTo)
561-
.ConfigureAwait(false);
562-
}
563-
}
564-
catch (Exception e)
565-
{
566-
App.RaiseException(_repo.FullPath, $"Failed to save file: {e.Message}");
567-
}
568-
573+
await SaveRevisionFile(file);
569574
ev.Handled = true;
570575
};
571576

src/Views/RevisionFileTreeView.axaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ protected override async void OnKeyDown(KeyEventArgs e)
132132
e.Handled = true;
133133
}
134134
}
135+
else if (node.Backend is { Type: Models.ObjectType.Blob } file &&
136+
e.Key == Key.S &&
137+
e.KeyModifiers.HasFlag(OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control))
138+
{
139+
var detailView = this.FindAncestorOfType<CommitDetail>();
140+
if (detailView is { DataContext: ViewModels.CommitDetail detail })
141+
{
142+
await detail.SaveRevisionFile(file);
143+
e.Handled = true;
144+
}
145+
}
135146
}
136147

137148
if (!e.Handled)

0 commit comments

Comments
 (0)