style<Dashboard>: move Explore & Open Git Bash & Open In VSCode into one dropdown menu

This commit is contained in:
leo 2021-10-13 17:14:53 +08:00
parent 9e228432e0
commit 9dae37b022
4 changed files with 88 additions and 53 deletions

View file

@ -116,9 +116,11 @@
<sys:String x:Key="Text.CreateTag.Message">Tag Message :</sys:String>
<sys:String x:Key="Text.CreateTag.Message.Placeholder">Optional.</sys:String>
<sys:String x:Key="Text.Dashboard.Open">Open</sys:String>
<sys:String x:Key="Text.Dashboard.Explore">Open In File Browser</sys:String>
<sys:String x:Key="Text.Dashboard.VSCode">Open In Visual Studio Code</sys:String>
<sys:String x:Key="Text.Dashboard.Terminal">Open Git Bash</sys:String>
<sys:String x:Key="Text.Dashboard.Terminal">Open In Git Bash</sys:String>
<sys:String x:Key="Text.Dashboard.Refresh">Refresh</sys:String>
<sys:String x:Key="Text.Dashboard.Search">Search Commit</sys:String>
<sys:String x:Key="Text.Dashboard.Configure">Configure this repository</sys:String>
<sys:String x:Key="Text.Dashboard.Workspace">WORKSPACE</sys:String>

View file

@ -115,9 +115,11 @@
<sys:String x:Key="Text.CreateTag.Message">标签描述 </sys:String>
<sys:String x:Key="Text.CreateTag.Message.Placeholder">选填</sys:String>
<sys:String x:Key="Text.Dashboard.Open">打开</sys:String>
<sys:String x:Key="Text.Dashboard.Explore">在文件浏览器中打开</sys:String>
<sys:String x:Key="Text.Dashboard.VSCode">在Visual Studio Code中打开</sys:String>
<sys:String x:Key="Text.Dashboard.Terminal">打开GIT终端</sys:String>
<sys:String x:Key="Text.Dashboard.Terminal">在GIT终端中打开</sys:String>
<sys:String x:Key="Text.Dashboard.Refresh">重新加载</sys:String>
<sys:String x:Key="Text.Dashboard.Search">查找提交</sys:String>
<sys:String x:Key="Text.Dashboard.Configure">配置本仓库</sys:String>
<sys:String x:Key="Text.Dashboard.Workspace">工作区</sys:String>

View file

@ -33,23 +33,15 @@
<controls:IconButton
Margin="8,0"
Padding="0,9"
Icon="{DynamicResource Icon.Folder.Open}"
ToolTip="{DynamicResource Text.Dashboard.Explore}"
Click="Explore"/>
<controls:IconButton
x:Name="btnOpenWithVSCode"
Visibility="Collapsed"
Margin="8,0"
Padding="0,9"
Icon="{DynamicResource Icon.VSCode}"
ToolTip="{DynamicResource Text.Dashboard.VSCode}"
Click="OpenInVSCode"/>
Icon="{DynamicResource Icon.Folder}"
ToolTip="{DynamicResource Text.Dashboard.Open}"
Click="OpenExternal"/>
<controls:IconButton
Margin="8,0"
Padding="0,9"
Icon="{DynamicResource Icon.Terminal}"
ToolTip="{DynamicResource Text.Dashboard.Terminal}"
Click="Terminal"/>
Icon="{DynamicResource Icon.Loading}"
ToolTip="{DynamicResource Text.Dashboard.Refresh}"
Click="TriggerRefresh"/>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">

View file

@ -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;
}