From 9dae37b022eb6c3b6f0808e24d049aa5b945ccc1 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 13 Oct 2021 17:14:53 +0800 Subject: [PATCH] style: move Explore & Open Git Bash & Open In VSCode into one dropdown menu --- src/Resources/Locales/en_US.xaml | 4 +- src/Resources/Locales/zh_CN.xaml | 4 +- src/Views/Widgets/Dashboard.xaml | 20 ++--- src/Views/Widgets/Dashboard.xaml.cs | 113 +++++++++++++++++++--------- 4 files changed, 88 insertions(+), 53 deletions(-) diff --git a/src/Resources/Locales/en_US.xaml b/src/Resources/Locales/en_US.xaml index 94c819a1..9c7672b0 100644 --- a/src/Resources/Locales/en_US.xaml +++ b/src/Resources/Locales/en_US.xaml @@ -116,9 +116,11 @@ Tag Message : Optional. + Open Open In File Browser Open In Visual Studio Code - Open Git Bash + Open In Git Bash + Refresh Search Commit Configure this repository WORKSPACE diff --git a/src/Resources/Locales/zh_CN.xaml b/src/Resources/Locales/zh_CN.xaml index 96ddc01b..adda3cbd 100644 --- a/src/Resources/Locales/zh_CN.xaml +++ b/src/Resources/Locales/zh_CN.xaml @@ -115,9 +115,11 @@ 标签描述 : 选填 + 打开 在文件浏览器中打开 在Visual Studio Code中打开 - 打开GIT终端 + 在GIT终端中打开 + 重新加载 查找提交 配置本仓库 工作区 diff --git a/src/Views/Widgets/Dashboard.xaml b/src/Views/Widgets/Dashboard.xaml index 99f47505..a3f62bf8 100644 --- a/src/Views/Widgets/Dashboard.xaml +++ b/src/Views/Widgets/Dashboard.xaml @@ -33,23 +33,15 @@ - + Icon="{DynamicResource Icon.Folder}" + ToolTip="{DynamicResource Text.Dashboard.Open}" + Click="OpenExternal"/> + Icon="{DynamicResource Icon.Loading}" + ToolTip="{DynamicResource Text.Dashboard.Refresh}" + Click="TriggerRefresh"/> diff --git a/src/Views/Widgets/Dashboard.xaml.cs b/src/Views/Widgets/Dashboard.xaml.cs index 4e024a47..9cd35bf7 100644 --- a/src/Views/Widgets/Dashboard.xaml.cs +++ b/src/Views/Widgets/Dashboard.xaml.cs @@ -56,9 +56,6 @@ namespace SourceGit.Views.Widgets { InitializeComponent(); InitPages(); - var vscode = Models.ExecutableFinder.Find("code.cmd"); - if (vscode != null) btnOpenWithVSCode.Visibility = Visibility.Visible; - var watcher = Models.Watcher.Get(repo.Path); watcher.Navigate += NavigateTo; watcher.BranchChanged += UpdateBranches; @@ -307,48 +304,90 @@ namespace SourceGit.Views.Widgets { #endregion #region TOOLBAR_COMMANDS - private void Explore(object sender, RoutedEventArgs e) { - Process.Start("explorer", repo.Path); - e.Handled = true; + private MenuItem CreateMenuItem(string icon, string header, Action click) { + var ret = new MenuItem(); + ret.Header = App.Text(header); + ret.Click += (o, e) => { + click(); + e.Handled = true; + }; + + if (!string.IsNullOrEmpty(icon)) { + var geo = new System.Windows.Shapes.Path(); + geo.Data = FindResource(icon) as Geometry; + geo.VerticalAlignment = VerticalAlignment.Center; + geo.Width = 12; + geo.Height = 12; + + ret.Icon = geo; + } + + return ret; } - private void OpenInVSCode(object sender, RoutedEventArgs e) { - var vscode = Models.ExecutableFinder.Find("code.cmd"); - if (vscode == null) return; + private void OpenExternal(object sender, RoutedEventArgs e) { + var btn = sender as Controls.IconButton; + if (btn == null) return; - vscode = Path.Combine(Path.GetDirectoryName(vscode), "..", "Code.exe"); - Process.Start(new ProcessStartInfo { - WorkingDirectory = repo.Path, - FileName = vscode, - Arguments = $"\"{repo.Path}\"", - UseShellExecute = false, - }); - - e.Handled = true; - } - - private void Terminal(object sender, RoutedEventArgs e) { - var bash = Path.Combine(Models.Preference.Instance.Git.Path, "..", "bash.exe"); - if (!File.Exists(bash)) { - Models.Exception.Raise(App.Text("MissingBash")); + if (btn.ContextMenu != null) { + btn.ContextMenu.IsOpen = true; + e.Handled = true; return; } - if (Models.Preference.Instance.General.UseWindowsTerminal) { - Process.Start(new ProcessStartInfo { - WorkingDirectory = repo.Path, - FileName = "wt", - Arguments = $"-d \"{repo.Path}\" \"{bash}\"", - UseShellExecute = false, - }); - } else { - Process.Start(new ProcessStartInfo { - WorkingDirectory = repo.Path, - FileName = bash, - UseShellExecute = true, - }); + var menu = new ContextMenu(); + menu.PlacementTarget = btn; + menu.Placement = PlacementMode.Bottom; + menu.StaysOpen = false; + menu.Focusable = true; + + menu.Items.Add(CreateMenuItem("Icon.Folder.Open", "Dashboard.Explore", () => { + Process.Start("explorer", repo.Path); + })); + + menu.Items.Add(CreateMenuItem("Icon.Terminal", "Dashboard.Terminal", () => { + var bash = Path.Combine(Models.Preference.Instance.Git.Path, "..", "bash.exe"); + if (!File.Exists(bash)) { + Models.Exception.Raise(App.Text("MissingBash")); + return; + } + + if (Models.Preference.Instance.General.UseWindowsTerminal) { + Process.Start(new ProcessStartInfo { + WorkingDirectory = repo.Path, + FileName = "wt", + Arguments = $"-d \"{repo.Path}\" \"{bash}\"", + UseShellExecute = false, + }); + } else { + Process.Start(new ProcessStartInfo { + WorkingDirectory = repo.Path, + FileName = bash, + UseShellExecute = true, + }); + } + })); + + var vscode = Models.ExecutableFinder.Find("code.cmd"); + if (vscode != null) { + vscode = Path.Combine(Path.GetDirectoryName(vscode), "..", "Code.exe"); + menu.Items.Add(CreateMenuItem("Icon.VSCode", "Dashboard.VSCode", () => { + Process.Start(new ProcessStartInfo { + WorkingDirectory = repo.Path, + FileName = vscode, + Arguments = $"\"{repo.Path}\"", + UseShellExecute = false, + }); + })); } + btn.ContextMenu = menu; + menu.IsOpen = true; + e.Handled = true; + } + + private void TriggerRefresh(object sender, RoutedEventArgs e) { + Refresh(); e.Handled = true; }