mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
style<Dashboard>: move Explore & Open Git Bash & Open In VSCode into one dropdown menu
This commit is contained in:
parent
9e228432e0
commit
9dae37b022
4 changed files with 88 additions and 53 deletions
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -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,27 +304,48 @@ namespace SourceGit.Views.Widgets {
|
|||
#endregion
|
||||
|
||||
#region TOOLBAR_COMMANDS
|
||||
private void Explore(object sender, RoutedEventArgs e) {
|
||||
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 OpenExternal(object sender, RoutedEventArgs e) {
|
||||
var btn = sender as Controls.IconButton;
|
||||
if (btn == null) return;
|
||||
|
||||
if (btn.ContextMenu != null) {
|
||||
btn.ContextMenu.IsOpen = true;
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
e.Handled = true;
|
||||
}
|
||||
}));
|
||||
|
||||
private void OpenInVSCode(object sender, RoutedEventArgs e) {
|
||||
var vscode = Models.ExecutableFinder.Find("code.cmd");
|
||||
if (vscode == 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) {
|
||||
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"));
|
||||
|
@ -348,7 +366,28 @@ namespace SourceGit.Views.Widgets {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue