mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-21 05:10:25 +08:00
refactor: move some code from App to Views.ControlExtensions
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -37,12 +37,47 @@ namespace SourceGit
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly Command OpenPreferencesCommand = new Command(async _ => await ShowDialog(new Views.Preferences()));
|
||||
public static readonly Command OpenHotkeysCommand = new Command(async _ => await ShowDialog(new Views.Hotkeys()));
|
||||
public static readonly Command OpenAppDataDirCommand = new Command(_ => Native.OS.OpenInFileManager(Native.OS.DataDir));
|
||||
public static readonly Command OpenAboutCommand = new Command(async _ => await ShowDialog(new Views.About()));
|
||||
public static readonly Command CheckForUpdateCommand = new Command(_ => (Current as App)?.Check4Update(true));
|
||||
public static readonly Command QuitCommand = new Command(_ => Quit(0));
|
||||
public static readonly Command OpenPreferencesCommand = new Command(async _ =>
|
||||
{
|
||||
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
|
||||
{
|
||||
var dialog = new Views.Preferences();
|
||||
await dialog.ShowDialog(owner);
|
||||
}
|
||||
});
|
||||
|
||||
public static readonly Command OpenHotkeysCommand = new Command(async _ =>
|
||||
{
|
||||
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
|
||||
{
|
||||
var dialog = new Views.Hotkeys();
|
||||
await dialog.ShowDialog(owner);
|
||||
}
|
||||
});
|
||||
|
||||
public static readonly Command OpenAppDataDirCommand = new Command(_ =>
|
||||
{
|
||||
Native.OS.OpenInFileManager(Native.OS.DataDir);
|
||||
});
|
||||
|
||||
public static readonly Command OpenAboutCommand = new Command(async _ =>
|
||||
{
|
||||
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
|
||||
{
|
||||
var dialog = new Views.About();
|
||||
await dialog.ShowDialog(owner);
|
||||
}
|
||||
});
|
||||
|
||||
public static readonly Command CheckForUpdateCommand = new Command(_ =>
|
||||
{
|
||||
(Current as App)?.Check4Update(true);
|
||||
});
|
||||
|
||||
public static readonly Command QuitCommand = new Command(_ =>
|
||||
{
|
||||
Quit(0);
|
||||
});
|
||||
|
||||
public static readonly Command HideAppCommand = new Command(_ =>
|
||||
{
|
||||
|
||||
@@ -75,79 +75,6 @@ namespace SourceGit
|
||||
#endregion
|
||||
|
||||
#region Utility Functions
|
||||
public static Task ShowDialog(object data, Window owner = null)
|
||||
{
|
||||
if (owner == null)
|
||||
{
|
||||
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } mainWindow })
|
||||
owner = mainWindow;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
if (data is Views.ChromelessWindow window)
|
||||
return window.ShowDialog(owner);
|
||||
|
||||
window = Views.ControlExtensions.CreateFromViewModels(data) as Views.ChromelessWindow;
|
||||
if (window != null)
|
||||
{
|
||||
window.DataContext = data;
|
||||
return window.ShowDialog(owner);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void ShowWindow(object data)
|
||||
{
|
||||
if (data is not Views.ChromelessWindow window)
|
||||
{
|
||||
window = Views.ControlExtensions.CreateFromViewModels(data) as Views.ChromelessWindow;
|
||||
if (window == null)
|
||||
return;
|
||||
|
||||
window.DataContext = data;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { Windows: { Count: > 0 } windows })
|
||||
{
|
||||
// Try to find the actived window (fall back to `MainWindow`)
|
||||
Window actived = windows[0];
|
||||
if (!actived.IsActive)
|
||||
{
|
||||
for (var i = 1; i < windows.Count; i++)
|
||||
{
|
||||
var test = windows[i];
|
||||
if (test.IsActive)
|
||||
{
|
||||
actived = test;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the screen where current window locates.
|
||||
var screen = actived.Screens.ScreenFromWindow(actived) ?? actived.Screens.Primary;
|
||||
if (screen == null)
|
||||
break;
|
||||
|
||||
// Calculate the startup position (Center Screen Mode) of target window
|
||||
var rect = new PixelRect(PixelSize.FromSize(window.ClientSize, actived.DesktopScaling));
|
||||
var centeredRect = screen.WorkingArea.CenterRect(rect);
|
||||
if (actived.Screens.ScreenFromPoint(centeredRect.Position) == null)
|
||||
break;
|
||||
|
||||
// Use the startup position
|
||||
window.WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
window.Position = centeredRect.Position;
|
||||
}
|
||||
} while (false);
|
||||
|
||||
window.Show();
|
||||
}
|
||||
|
||||
public static async Task<bool> AskConfirmAsync(string message, Models.ConfirmButtonType buttonType = Models.ConfirmButtonType.OkCancel)
|
||||
{
|
||||
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
|
||||
@@ -620,7 +547,12 @@ namespace SourceGit
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(async () =>
|
||||
{
|
||||
await ShowDialog(new ViewModels.SelfUpdate { Data = data });
|
||||
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } owner })
|
||||
{
|
||||
var ctx = new ViewModels.SelfUpdate { Data = data };
|
||||
var dialog = new Views.SelfUpdate() { DataContext = ctx };
|
||||
await dialog.ShowDialog(owner);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -65,14 +65,12 @@ namespace SourceGit.ViewModels
|
||||
Filter = string.Empty;
|
||||
}
|
||||
|
||||
public void Launch()
|
||||
public Blame Launch()
|
||||
{
|
||||
_repoFiles.Clear();
|
||||
_visibleFiles.Clear();
|
||||
Close();
|
||||
|
||||
if (!string.IsNullOrEmpty(_selectedFile))
|
||||
App.ShowWindow(new Blame(_repo, _selectedFile, _head));
|
||||
return !string.IsNullOrEmpty(_selectedFile) ? new Blame(_repo, _selectedFile, _head) : null;
|
||||
}
|
||||
|
||||
private void UpdateVisible()
|
||||
|
||||
@@ -44,13 +44,11 @@ namespace SourceGit.ViewModels
|
||||
Filter = string.Empty;
|
||||
}
|
||||
|
||||
public void Launch()
|
||||
public Compare Launch()
|
||||
{
|
||||
_refs.Clear();
|
||||
Close();
|
||||
|
||||
if (_compareTo != null)
|
||||
App.ShowWindow(new Compare(_repo, _basedOn, _compareTo));
|
||||
return _compareTo != null ? new Compare(_repo, _basedOn, _compareTo) : null;
|
||||
}
|
||||
|
||||
private void UpdateRefs()
|
||||
|
||||
@@ -73,10 +73,9 @@ namespace SourceGit.ViewModels
|
||||
await _wc.UseMineAsync([_change]);
|
||||
}
|
||||
|
||||
public async Task MergeAsync()
|
||||
public MergeConflictEditor CreateOpenMergeEditorRequest()
|
||||
{
|
||||
if (CanMerge)
|
||||
await App.ShowDialog(new MergeConflictEditor(_repo, _head, _change.Path));
|
||||
return CanMerge ? new MergeConflictEditor(_repo, _head, _change.Path) : null;
|
||||
}
|
||||
|
||||
public async Task MergeExternalAsync()
|
||||
|
||||
@@ -60,14 +60,12 @@ namespace SourceGit.ViewModels
|
||||
Filter = string.Empty;
|
||||
}
|
||||
|
||||
public void Launch()
|
||||
public FileHistories Launch()
|
||||
{
|
||||
_repoFiles.Clear();
|
||||
_visibleFiles.Clear();
|
||||
Close();
|
||||
|
||||
if (!string.IsNullOrEmpty(_selectedFile))
|
||||
App.ShowWindow(new FileHistories(_repo, _selectedFile));
|
||||
return !string.IsNullOrEmpty(_selectedFile) ? new FileHistories(_repo, _selectedFile) : null;
|
||||
}
|
||||
|
||||
private void UpdateVisible()
|
||||
|
||||
@@ -418,22 +418,6 @@ namespace SourceGit.ViewModels
|
||||
_repo.ShowPopup(new DropHead(_repo, head, parent));
|
||||
}
|
||||
|
||||
public async Task InteractiveRebaseAsync(Models.Commit commit, Models.InteractiveRebaseAction act)
|
||||
{
|
||||
var prefill = new InteractiveRebasePrefill(commit.SHA, act);
|
||||
var start = act switch
|
||||
{
|
||||
Models.InteractiveRebaseAction.Squash or Models.InteractiveRebaseAction.Fixup => $"{commit.SHA}~~",
|
||||
_ => $"{commit.SHA}~",
|
||||
};
|
||||
|
||||
var on = await new Commands.QuerySingleCommit(_repo.FullPath, start).GetResultAsync();
|
||||
if (on == null)
|
||||
_repo.SendNotification($"Can not squash current commit into parent!", true);
|
||||
else
|
||||
await App.ShowDialog(new InteractiveRebase(_repo, on, prefill));
|
||||
}
|
||||
|
||||
public async Task<string> GetCommitFullMessageAsync(Models.Commit commit)
|
||||
{
|
||||
return await new Commands.QueryCommitFullMessage(_repo.FullPath, commit.SHA)
|
||||
|
||||
@@ -73,7 +73,6 @@ namespace SourceGit.ViewModels
|
||||
_cmds.Add(new("Push", "push", "Push", async () => await repo.PushAsync(false)));
|
||||
_cmds.Add(new("Stash.Title", "stash", "Stashes.Add", async () => await repo.StashAllAsync(false)));
|
||||
_cmds.Add(new("Apply.Title", "apply", "Diff", () => repo.ApplyPatch()));
|
||||
_cmds.Add(new("Configure", "configure", "Settings", async () => await App.ShowDialog(new RepositoryConfigure(repo))));
|
||||
|
||||
_cmds.Sort((l, r) => l.Label.CompareTo(r.Label));
|
||||
_visibleCmds = _cmds;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace SourceGit.Views
|
||||
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
vm.Launch();
|
||||
this.ShowWindow(vm.Launch());
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (e.Key == Key.Up)
|
||||
@@ -55,7 +55,7 @@ namespace SourceGit.Views
|
||||
{
|
||||
if (DataContext is ViewModels.BlameCommandPalette vm)
|
||||
{
|
||||
vm.Launch();
|
||||
this.ShowWindow(vm.Launch());
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,7 +537,7 @@ namespace SourceGit.Views
|
||||
compare.Icon = this.CreateMenuIcon("Icons.Compare");
|
||||
compare.Click += (_, ev) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.Compare(repo, branches[0], branches[1]));
|
||||
this.ShowWindow(new ViewModels.Compare(repo, branches[0], branches[1]));
|
||||
ev.Handled = true;
|
||||
};
|
||||
menu.Items.Add(compare);
|
||||
@@ -819,7 +819,7 @@ namespace SourceGit.Views
|
||||
interactiveRebase.Click += async (_, e) =>
|
||||
{
|
||||
var commit = await new Commands.QuerySingleCommit(repo.FullPath, branch.Head).GetResultAsync();
|
||||
await App.ShowDialog(new ViewModels.InteractiveRebase(repo, commit));
|
||||
await this.ShowDialogAsync(new ViewModels.InteractiveRebase(repo, commit));
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -853,7 +853,7 @@ namespace SourceGit.Views
|
||||
compareWithCurrent.Icon = this.CreateMenuIcon("Icons.Compare");
|
||||
compareWithCurrent.Click += (_, _) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.Compare(repo, branch, current));
|
||||
this.ShowWindow(new ViewModels.Compare(repo, branch, current));
|
||||
};
|
||||
|
||||
var compareWith = new MenuItem();
|
||||
@@ -1154,7 +1154,7 @@ namespace SourceGit.Views
|
||||
interactiveRebase.Click += async (_, e) =>
|
||||
{
|
||||
var commit = await new Commands.QuerySingleCommit(repo.FullPath, branch.Head).GetResultAsync();
|
||||
await App.ShowDialog(new ViewModels.InteractiveRebase(repo, commit));
|
||||
await this.ShowDialogAsync(new ViewModels.InteractiveRebase(repo, commit));
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -1163,7 +1163,7 @@ namespace SourceGit.Views
|
||||
compareWithHead.Icon = this.CreateMenuIcon("Icons.Compare");
|
||||
compareWithHead.Click += (_, _) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.Compare(repo, branch, current));
|
||||
this.ShowWindow(new ViewModels.Compare(repo, branch, current));
|
||||
};
|
||||
|
||||
var compareWith = new MenuItem();
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace SourceGit.Views
|
||||
history.Icon = this.CreateMenuIcon("Icons.Histories");
|
||||
history.Click += (_, ev) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.DirHistories(repo, node.FullPath, commit.SHA));
|
||||
this.ShowWindow(new ViewModels.DirHistories(repo, node.FullPath, commit.SHA));
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
@@ -273,7 +273,7 @@ namespace SourceGit.Views
|
||||
history.Icon = this.CreateMenuIcon("Icons.Histories");
|
||||
history.Click += (_, ev) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.FileHistories(repo.FullPath, change.Path, commit.SHA));
|
||||
this.ShowWindow(new ViewModels.FileHistories(repo.FullPath, change.Path, commit.SHA));
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
@@ -283,7 +283,7 @@ namespace SourceGit.Views
|
||||
blame.IsEnabled = change.Index != Models.ChangeState.Deleted;
|
||||
blame.Click += (_, ev) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.Blame(repo.FullPath, change.Path, commit));
|
||||
this.ShowWindow(new ViewModels.Blame(repo.FullPath, change.Path, commit));
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace SourceGit.Views
|
||||
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
vm.Launch();
|
||||
this.ShowWindow(vm.Launch());
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (e.Key == Key.Up)
|
||||
@@ -55,7 +55,7 @@ namespace SourceGit.Views
|
||||
{
|
||||
if (DataContext is ViewModels.CompareCommandPalette vm)
|
||||
{
|
||||
vm.Launch();
|
||||
this.ShowWindow(vm.Launch());
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,10 @@ namespace SourceGit.Views
|
||||
private async void OnMerge(object _, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.Conflict vm)
|
||||
await vm.MergeAsync();
|
||||
{
|
||||
var request = vm.CreateOpenMergeEditorRequest();
|
||||
await this.ShowDialogAsync(request);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Shapes;
|
||||
using Avalonia.Media;
|
||||
@@ -44,5 +46,63 @@ namespace SourceGit.Views
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void ShowWindow(this Control control, object data)
|
||||
{
|
||||
if (data == null)
|
||||
return;
|
||||
|
||||
if (data is not ChromelessWindow window)
|
||||
{
|
||||
window = CreateFromViewModels(data) as ChromelessWindow;
|
||||
if (window == null)
|
||||
return;
|
||||
|
||||
window.DataContext = data;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
var owner = TopLevel.GetTopLevel(control) as Window;
|
||||
if (owner != null)
|
||||
{
|
||||
// Get the screen where current window locates.
|
||||
var screen = owner.Screens.ScreenFromWindow(owner) ?? owner.Screens.Primary;
|
||||
if (screen == null)
|
||||
break;
|
||||
|
||||
// Calculate the startup position (Center Screen Mode) of target window
|
||||
var rect = new PixelRect(PixelSize.FromSize(window.ClientSize, owner.DesktopScaling));
|
||||
var centeredRect = screen.WorkingArea.CenterRect(rect);
|
||||
if (owner.Screens.ScreenFromPoint(centeredRect.Position) == null)
|
||||
break;
|
||||
|
||||
// Use the startup position
|
||||
window.WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
window.Position = centeredRect.Position;
|
||||
}
|
||||
} while (false);
|
||||
|
||||
window.Show();
|
||||
}
|
||||
|
||||
public static Task ShowDialogAsync(this Control control, object data)
|
||||
{
|
||||
var owner = TopLevel.GetTopLevel(control) as Window;
|
||||
if (owner == null)
|
||||
return null;
|
||||
|
||||
if (data is ChromelessWindow window)
|
||||
return window.ShowDialog(owner);
|
||||
|
||||
window = CreateFromViewModels(data) as ChromelessWindow;
|
||||
if (window != null)
|
||||
{
|
||||
window.DataContext = data;
|
||||
return window.ShowDialog(owner);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace SourceGit.Views
|
||||
if (sender is Button { DataContext: Models.SubmoduleDiff diff } && diff.CanOpenDetails)
|
||||
{
|
||||
var vm = new ViewModels.SubmoduleRevisionCompare(diff);
|
||||
App.ShowWindow(vm);
|
||||
this.ShowWindow(vm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace SourceGit.Views
|
||||
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
vm.Launch();
|
||||
this.ShowWindow(vm.Launch());
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (e.Key == Key.Up)
|
||||
@@ -55,7 +55,7 @@ namespace SourceGit.Views
|
||||
{
|
||||
if (DataContext is ViewModels.FileHistoryCommandPalette vm)
|
||||
{
|
||||
vm.Launch();
|
||||
this.ShowWindow(vm.Launch());
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Collections;
|
||||
@@ -832,7 +833,7 @@ namespace SourceGit.Views
|
||||
manually.Icon = this.CreateMenuIcon("Icons.InteractiveRebase");
|
||||
manually.Click += async (_, e) =>
|
||||
{
|
||||
await App.ShowDialog(new ViewModels.InteractiveRebase(repo, commit));
|
||||
await this.ShowDialogAsync(new ViewModels.InteractiveRebase(repo, commit));
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -841,7 +842,7 @@ namespace SourceGit.Views
|
||||
reword.Icon = this.CreateMenuIcon("Icons.Rename");
|
||||
reword.Click += async (_, e) =>
|
||||
{
|
||||
await vm.InteractiveRebaseAsync(commit, Models.InteractiveRebaseAction.Reword);
|
||||
await InteractiveRebaseWithPrefillActionAsync(repo, commit, Models.InteractiveRebaseAction.Reword);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -850,7 +851,7 @@ namespace SourceGit.Views
|
||||
edit.Icon = this.CreateMenuIcon("Icons.Edit");
|
||||
edit.Click += async (_, e) =>
|
||||
{
|
||||
await vm.InteractiveRebaseAsync(commit, Models.InteractiveRebaseAction.Edit);
|
||||
await InteractiveRebaseWithPrefillActionAsync(repo, commit, Models.InteractiveRebaseAction.Edit);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -859,7 +860,7 @@ namespace SourceGit.Views
|
||||
squash.Icon = this.CreateMenuIcon("Icons.SquashIntoParent");
|
||||
squash.Click += async (_, e) =>
|
||||
{
|
||||
await vm.InteractiveRebaseAsync(commit, Models.InteractiveRebaseAction.Squash);
|
||||
await InteractiveRebaseWithPrefillActionAsync(repo, commit, Models.InteractiveRebaseAction.Squash);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -868,7 +869,7 @@ namespace SourceGit.Views
|
||||
fixup.Icon = this.CreateMenuIcon("Icons.Fix");
|
||||
fixup.Click += async (_, e) =>
|
||||
{
|
||||
await vm.InteractiveRebaseAsync(commit, Models.InteractiveRebaseAction.Fixup);
|
||||
await InteractiveRebaseWithPrefillActionAsync(repo, commit, Models.InteractiveRebaseAction.Fixup);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -877,7 +878,7 @@ namespace SourceGit.Views
|
||||
drop.Icon = this.CreateMenuIcon("Icons.Clear");
|
||||
drop.Click += async (_, e) =>
|
||||
{
|
||||
await vm.InteractiveRebaseAsync(commit, Models.InteractiveRebaseAction.Drop);
|
||||
await InteractiveRebaseWithPrefillActionAsync(repo, commit, Models.InteractiveRebaseAction.Drop);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -902,7 +903,7 @@ namespace SourceGit.Views
|
||||
interactiveRebase.Icon = this.CreateMenuIcon("Icons.InteractiveRebase");
|
||||
interactiveRebase.Click += async (_, e) =>
|
||||
{
|
||||
await App.ShowDialog(new ViewModels.InteractiveRebase(repo, commit));
|
||||
await this.ShowDialogAsync(new ViewModels.InteractiveRebase(repo, commit));
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -1417,6 +1418,22 @@ namespace SourceGit.Views
|
||||
menu.Items.Add(submenu);
|
||||
}
|
||||
|
||||
private async Task InteractiveRebaseWithPrefillActionAsync(ViewModels.Repository repo, Models.Commit target, Models.InteractiveRebaseAction action)
|
||||
{
|
||||
var prefill = new ViewModels.InteractiveRebasePrefill(target.SHA, action);
|
||||
var start = action switch
|
||||
{
|
||||
Models.InteractiveRebaseAction.Squash or Models.InteractiveRebaseAction.Fixup => $"{target.SHA}~~",
|
||||
_ => $"{target.SHA}~",
|
||||
};
|
||||
|
||||
var on = await new Commands.QuerySingleCommit(repo.FullPath, start).GetResultAsync();
|
||||
if (on == null)
|
||||
repo.SendNotification($"Commit '{start}' is not a valid revision for `git rebase -i`!", true);
|
||||
else
|
||||
await this.ShowDialogAsync(new ViewModels.InteractiveRebase(repo, on, prefill));
|
||||
}
|
||||
|
||||
private double _lastGraphStartY = 0;
|
||||
private double _lastGraphClipWidth = 0;
|
||||
private double _lastGraphRowHeight = 0;
|
||||
|
||||
@@ -172,14 +172,14 @@ namespace SourceGit.Views
|
||||
{
|
||||
if (e is { KeyModifiers: KeyModifiers.Control, Key: Key.OemComma })
|
||||
{
|
||||
await App.ShowDialog(new Preferences());
|
||||
await this.ShowDialogAsync(new Preferences());
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (e is { KeyModifiers: KeyModifiers.None, Key: Key.F1 })
|
||||
{
|
||||
await App.ShowDialog(new Hotkeys());
|
||||
await this.ShowDialogAsync(new Hotkeys());
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
@@ -404,7 +404,7 @@ namespace SourceGit.Views
|
||||
configure.Header = App.Text("Workspace.Configure");
|
||||
configure.Click += async (_, ev) =>
|
||||
{
|
||||
await App.ShowDialog(new ViewModels.ConfigureWorkspace());
|
||||
await this.ShowDialogAsync(new ViewModels.ConfigureWorkspace());
|
||||
ev.Handled = true;
|
||||
};
|
||||
menu.Items.Add(configure);
|
||||
|
||||
@@ -386,7 +386,7 @@ namespace SourceGit.Views
|
||||
if (sender is CheckBox box)
|
||||
{
|
||||
ViewModels.Preferences.Instance.UseSystemWindowFrame = box.IsChecked == true;
|
||||
await App.ShowDialog(new ConfirmRestart());
|
||||
await this.ShowDialogAsync(new ConfirmRestart());
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
@@ -486,12 +486,7 @@ namespace SourceGit.Views
|
||||
if (sender is not Button { DataContext: Models.CustomAction act })
|
||||
return;
|
||||
|
||||
var dialog = new ConfigureCustomActionControls()
|
||||
{
|
||||
DataContext = new ViewModels.ConfigureCustomActionControls(act.Controls)
|
||||
};
|
||||
|
||||
await dialog.ShowDialog(this);
|
||||
await this.ShowDialogAsync(new ViewModels.ConfigureCustomActionControls(act.Controls));
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,12 +56,7 @@ namespace SourceGit.Views
|
||||
if (sender is not Button { DataContext: Models.CustomAction act })
|
||||
return;
|
||||
|
||||
var dialog = new ConfigureCustomActionControls()
|
||||
{
|
||||
DataContext = new ViewModels.ConfigureCustomActionControls(act.Controls)
|
||||
};
|
||||
|
||||
await dialog.ShowDialog(this);
|
||||
await this.ShowDialogAsync(new ViewModels.ConfigureCustomActionControls(act.Controls));
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace SourceGit.Views
|
||||
{
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
await App.ShowDialog(new ViewModels.Statistics(repo.FullPath));
|
||||
await this.ShowDialogAsync(new ViewModels.Statistics(repo.FullPath));
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ namespace SourceGit.Views
|
||||
{
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
await App.ShowDialog(new ViewModels.RepositoryConfigure(repo));
|
||||
await this.ShowDialogAsync(new ViewModels.RepositoryConfigure(repo));
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
@@ -387,7 +387,7 @@ namespace SourceGit.Views
|
||||
{
|
||||
locks.Click += async (_, e) =>
|
||||
{
|
||||
await App.ShowDialog(new ViewModels.LFSLocks(repo, repo.Remotes[0].Name));
|
||||
await this.ShowDialogAsync(new ViewModels.LFSLocks(repo, repo.Remotes[0].Name));
|
||||
e.Handled = true;
|
||||
};
|
||||
}
|
||||
@@ -400,7 +400,7 @@ namespace SourceGit.Views
|
||||
lockRemote.Header = remoteName;
|
||||
lockRemote.Click += async (_, e) =>
|
||||
{
|
||||
await App.ShowDialog(new ViewModels.LFSLocks(repo, remoteName));
|
||||
await this.ShowDialogAsync(new ViewModels.LFSLocks(repo, remoteName));
|
||||
e.Handled = true;
|
||||
};
|
||||
locks.Items.Add(lockRemote);
|
||||
@@ -494,7 +494,7 @@ namespace SourceGit.Views
|
||||
{
|
||||
if (DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
await App.ShowDialog(new ViewModels.ViewLogs(repo));
|
||||
await this.ShowDialogAsync(new ViewModels.ViewLogs(repo));
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -472,7 +472,7 @@ namespace SourceGit.Views
|
||||
history.Icon = this.CreateMenuIcon("Icons.Histories");
|
||||
history.Click += (_, ev) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.DirHistories(repo, path, commit.SHA));
|
||||
this.ShowWindow(new ViewModels.DirHistories(repo, path, commit.SHA));
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
@@ -601,7 +601,7 @@ namespace SourceGit.Views
|
||||
history.Icon = this.CreateMenuIcon("Icons.Histories");
|
||||
history.Click += (_, ev) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.FileHistories(repo.FullPath, file.Path, commit.SHA));
|
||||
this.ShowWindow(new ViewModels.FileHistories(repo.FullPath, file.Path, commit.SHA));
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
@@ -611,7 +611,7 @@ namespace SourceGit.Views
|
||||
blame.IsEnabled = file.Type == Models.ObjectType.Blob;
|
||||
blame.Click += (_, ev) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.Blame(repo.FullPath, file.Path, commit));
|
||||
this.ShowWindow(new ViewModels.Blame(repo.FullPath, file.Path, commit));
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -257,7 +257,7 @@ namespace SourceGit.Views
|
||||
histories.Icon = this.CreateMenuIcon("Icons.Histories");
|
||||
histories.Click += (_, ev) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.FileHistories(repo.FullPath, submodule.Path));
|
||||
this.ShowWindow(new ViewModels.FileHistories(repo.FullPath, submodule.Path));
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ namespace SourceGit.Views
|
||||
compareWithHead.Icon = this.CreateMenuIcon("Icons.Compare");
|
||||
compareWithHead.Click += (_, _) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.Compare(repo, tag, repo.CurrentBranch));
|
||||
this.ShowWindow(new ViewModels.Compare(repo, tag, repo.CurrentBranch));
|
||||
};
|
||||
|
||||
var compareWith = new MenuItem();
|
||||
@@ -387,7 +387,7 @@ namespace SourceGit.Views
|
||||
if (based.CreatorDate > to.CreatorDate)
|
||||
(based, to) = (to, based);
|
||||
|
||||
App.ShowWindow(new ViewModels.Compare(repo, based, to));
|
||||
this.ShowWindow(new ViewModels.Compare(repo, based, to));
|
||||
ev.Handled = true;
|
||||
};
|
||||
menu.Items.Add(compare);
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace SourceGit.Views
|
||||
{
|
||||
var repoView = this.FindAncestorOfType<Repository>();
|
||||
if (repoView is { DataContext: ViewModels.Repository repo })
|
||||
await App.ShowDialog(new ViewModels.AssumeUnchangedManager(repo));
|
||||
await this.ShowDialogAsync(new ViewModels.AssumeUnchangedManager(repo));
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
@@ -360,7 +360,7 @@ namespace SourceGit.Views
|
||||
mergeBuiltin.Click += async (_, e) =>
|
||||
{
|
||||
var head = await new Commands.QuerySingleCommit(repo.FullPath, "HEAD").GetResultAsync();
|
||||
await App.ShowDialog(new ViewModels.MergeConflictEditor(repo, head, change.Path));
|
||||
await this.ShowDialogAsync(new ViewModels.MergeConflictEditor(repo, head, change.Path));
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -648,7 +648,7 @@ namespace SourceGit.Views
|
||||
history.Icon = this.CreateMenuIcon("Icons.Histories");
|
||||
history.Click += (_, e) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.DirHistories(repo, selectedSingleFolder));
|
||||
this.ShowWindow(new ViewModels.DirHistories(repo, selectedSingleFolder));
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -662,7 +662,7 @@ namespace SourceGit.Views
|
||||
history.Icon = this.CreateMenuIcon("Icons.Histories");
|
||||
history.Click += (_, e) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.FileHistories(repo.FullPath, change.Path));
|
||||
this.ShowWindow(new ViewModels.FileHistories(repo.FullPath, change.Path));
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -672,7 +672,7 @@ namespace SourceGit.Views
|
||||
blame.Click += async (_, ev) =>
|
||||
{
|
||||
var commit = await new Commands.QuerySingleCommit(repo.FullPath, "HEAD").GetResultAsync();
|
||||
App.ShowWindow(new ViewModels.Blame(repo.FullPath, change.Path, commit));
|
||||
this.ShowWindow(new ViewModels.Blame(repo.FullPath, change.Path, commit));
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
@@ -872,7 +872,7 @@ namespace SourceGit.Views
|
||||
history.Icon = this.CreateMenuIcon("Icons.Histories");
|
||||
history.Click += (_, e) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.DirHistories(repo, selectedSingleFolder));
|
||||
this.ShowWindow(new ViewModels.DirHistories(repo, selectedSingleFolder));
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -1119,7 +1119,7 @@ namespace SourceGit.Views
|
||||
history.Icon = this.CreateMenuIcon("Icons.Histories");
|
||||
history.Click += (_, e) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.DirHistories(repo, selectedSingleFolder));
|
||||
this.ShowWindow(new ViewModels.DirHistories(repo, selectedSingleFolder));
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -1133,7 +1133,7 @@ namespace SourceGit.Views
|
||||
history.Icon = this.CreateMenuIcon("Icons.Histories");
|
||||
history.Click += (_, e) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.FileHistories(repo.FullPath, change.Path));
|
||||
this.ShowWindow(new ViewModels.FileHistories(repo.FullPath, change.Path));
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -1143,7 +1143,7 @@ namespace SourceGit.Views
|
||||
blame.Click += async (_, e) =>
|
||||
{
|
||||
var commit = await new Commands.QuerySingleCommit(repo.FullPath, "HEAD").GetResultAsync();
|
||||
App.ShowWindow(new ViewModels.Blame(repo.FullPath, change.Path, commit));
|
||||
this.ShowWindow(new ViewModels.Blame(repo.FullPath, change.Path, commit));
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
@@ -1263,7 +1263,7 @@ namespace SourceGit.Views
|
||||
history.Icon = this.CreateMenuIcon("Icons.Histories");
|
||||
history.Click += (_, e) =>
|
||||
{
|
||||
App.ShowWindow(new ViewModels.DirHistories(repo, selectedSingleFolder));
|
||||
this.ShowWindow(new ViewModels.DirHistories(repo, selectedSingleFolder));
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user