From 2ed3a79e7f75640ee0b2dd074829f57b6161cb02 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 15 Apr 2026 12:14:55 +0800 Subject: [PATCH] refactor: move some code from `App` to `Views.ControlExtensions` Signed-off-by: leo --- src/App.Commands.cs | 47 ++++++++++-- src/App.axaml.cs | 80 ++------------------ src/ViewModels/BlameCommandPalette.cs | 6 +- src/ViewModels/CompareCommandPalette.cs | 6 +- src/ViewModels/Conflict.cs | 5 +- src/ViewModels/FileHistoryCommandPalette.cs | 6 +- src/ViewModels/Histories.cs | 16 ---- src/ViewModels/RepositoryCommandPalette.cs | 1 - src/Views/BlameCommandPalette.axaml.cs | 4 +- src/Views/BranchTree.axaml.cs | 10 +-- src/Views/CommitDetail.axaml.cs | 6 +- src/Views/CompareCommandPalette.axaml.cs | 4 +- src/Views/Conflict.axaml.cs | 5 +- src/Views/ControlExtensions.cs | 60 +++++++++++++++ src/Views/DiffView.axaml.cs | 2 +- src/Views/FileHistoryCommandPalette.axaml.cs | 4 +- src/Views/Histories.axaml.cs | 31 ++++++-- src/Views/Launcher.axaml.cs | 6 +- src/Views/Preferences.axaml.cs | 9 +-- src/Views/RepositoryConfigure.axaml.cs | 7 +- src/Views/RepositoryToolbar.axaml.cs | 10 +-- src/Views/RevisionFileTreeView.axaml.cs | 6 +- src/Views/SubmodulesView.axaml.cs | 2 +- src/Views/TagsView.axaml.cs | 4 +- src/Views/WorkingCopy.axaml.cs | 20 ++--- 25 files changed, 185 insertions(+), 172 deletions(-) diff --git a/src/App.Commands.cs b/src/App.Commands.cs index 54175070..56c15009 100644 --- a/src/App.Commands.cs +++ b/src/App.Commands.cs @@ -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(_ => { diff --git a/src/App.axaml.cs b/src/App.axaml.cs index c2f03f7f..8d6bafb7 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -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 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 diff --git a/src/ViewModels/BlameCommandPalette.cs b/src/ViewModels/BlameCommandPalette.cs index c277a47c..e7343087 100644 --- a/src/ViewModels/BlameCommandPalette.cs +++ b/src/ViewModels/BlameCommandPalette.cs @@ -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() diff --git a/src/ViewModels/CompareCommandPalette.cs b/src/ViewModels/CompareCommandPalette.cs index bebffe37..7eb49efd 100644 --- a/src/ViewModels/CompareCommandPalette.cs +++ b/src/ViewModels/CompareCommandPalette.cs @@ -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() diff --git a/src/ViewModels/Conflict.cs b/src/ViewModels/Conflict.cs index 06ac6077..380ad68d 100644 --- a/src/ViewModels/Conflict.cs +++ b/src/ViewModels/Conflict.cs @@ -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() diff --git a/src/ViewModels/FileHistoryCommandPalette.cs b/src/ViewModels/FileHistoryCommandPalette.cs index 8a371feb..097e8566 100644 --- a/src/ViewModels/FileHistoryCommandPalette.cs +++ b/src/ViewModels/FileHistoryCommandPalette.cs @@ -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() diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index d7a81b0f..4d0fd02f 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -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 GetCommitFullMessageAsync(Models.Commit commit) { return await new Commands.QueryCommitFullMessage(_repo.FullPath, commit.SHA) diff --git a/src/ViewModels/RepositoryCommandPalette.cs b/src/ViewModels/RepositoryCommandPalette.cs index 6d6c77c8..2b57414a 100644 --- a/src/ViewModels/RepositoryCommandPalette.cs +++ b/src/ViewModels/RepositoryCommandPalette.cs @@ -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; diff --git a/src/Views/BlameCommandPalette.axaml.cs b/src/Views/BlameCommandPalette.axaml.cs index 32c5381f..56de2d6d 100644 --- a/src/Views/BlameCommandPalette.axaml.cs +++ b/src/Views/BlameCommandPalette.axaml.cs @@ -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; } } diff --git a/src/Views/BranchTree.axaml.cs b/src/Views/BranchTree.axaml.cs index c7ca5276..603666b3 100644 --- a/src/Views/BranchTree.axaml.cs +++ b/src/Views/BranchTree.axaml.cs @@ -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(); diff --git a/src/Views/CommitDetail.axaml.cs b/src/Views/CommitDetail.axaml.cs index f0e55665..99969853 100644 --- a/src/Views/CommitDetail.axaml.cs +++ b/src/Views/CommitDetail.axaml.cs @@ -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; }; diff --git a/src/Views/CompareCommandPalette.axaml.cs b/src/Views/CompareCommandPalette.axaml.cs index e0c0c825..44809f27 100644 --- a/src/Views/CompareCommandPalette.axaml.cs +++ b/src/Views/CompareCommandPalette.axaml.cs @@ -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; } } diff --git a/src/Views/Conflict.axaml.cs b/src/Views/Conflict.axaml.cs index cdd616f9..0de67ccc 100644 --- a/src/Views/Conflict.axaml.cs +++ b/src/Views/Conflict.axaml.cs @@ -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; } diff --git a/src/Views/ControlExtensions.cs b/src/Views/ControlExtensions.cs index 5f043d8a..33c20b4f 100644 --- a/src/Views/ControlExtensions.cs +++ b/src/Views/ControlExtensions.cs @@ -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; + } } } diff --git a/src/Views/DiffView.axaml.cs b/src/Views/DiffView.axaml.cs index 43e6e8b4..504df14d 100644 --- a/src/Views/DiffView.axaml.cs +++ b/src/Views/DiffView.axaml.cs @@ -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); } } } diff --git a/src/Views/FileHistoryCommandPalette.axaml.cs b/src/Views/FileHistoryCommandPalette.axaml.cs index 2361e971..4038c44b 100644 --- a/src/Views/FileHistoryCommandPalette.axaml.cs +++ b/src/Views/FileHistoryCommandPalette.axaml.cs @@ -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; } } diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index 39312ec6..f042a78b 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -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; diff --git a/src/Views/Launcher.axaml.cs b/src/Views/Launcher.axaml.cs index 0c8b32c5..20d5617a 100644 --- a/src/Views/Launcher.axaml.cs +++ b/src/Views/Launcher.axaml.cs @@ -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); diff --git a/src/Views/Preferences.axaml.cs b/src/Views/Preferences.axaml.cs index 3c9c2e3f..6ab603f0 100644 --- a/src/Views/Preferences.axaml.cs +++ b/src/Views/Preferences.axaml.cs @@ -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; } diff --git a/src/Views/RepositoryConfigure.axaml.cs b/src/Views/RepositoryConfigure.axaml.cs index 2c5622df..bc445d2a 100644 --- a/src/Views/RepositoryConfigure.axaml.cs +++ b/src/Views/RepositoryConfigure.axaml.cs @@ -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; } diff --git a/src/Views/RepositoryToolbar.axaml.cs b/src/Views/RepositoryToolbar.axaml.cs index e224b1ba..72bb0462 100644 --- a/src/Views/RepositoryToolbar.axaml.cs +++ b/src/Views/RepositoryToolbar.axaml.cs @@ -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; } } diff --git a/src/Views/RevisionFileTreeView.axaml.cs b/src/Views/RevisionFileTreeView.axaml.cs index 4ac1901c..e9a0e22f 100644 --- a/src/Views/RevisionFileTreeView.axaml.cs +++ b/src/Views/RevisionFileTreeView.axaml.cs @@ -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; }; diff --git a/src/Views/SubmodulesView.axaml.cs b/src/Views/SubmodulesView.axaml.cs index e45be0ca..c8205049 100644 --- a/src/Views/SubmodulesView.axaml.cs +++ b/src/Views/SubmodulesView.axaml.cs @@ -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; }; diff --git a/src/Views/TagsView.axaml.cs b/src/Views/TagsView.axaml.cs index 0e66a5cc..3878fcab 100644 --- a/src/Views/TagsView.axaml.cs +++ b/src/Views/TagsView.axaml.cs @@ -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); diff --git a/src/Views/WorkingCopy.axaml.cs b/src/Views/WorkingCopy.axaml.cs index ea7a215d..9a5969de 100644 --- a/src/Views/WorkingCopy.axaml.cs +++ b/src/Views/WorkingCopy.axaml.cs @@ -34,7 +34,7 @@ namespace SourceGit.Views { var repoView = this.FindAncestorOfType(); 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; };