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">Tag Message :</sys:String>
|
||||||
<sys:String x:Key="Text.CreateTag.Message.Placeholder">Optional.</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.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.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.Search">Search Commit</sys:String>
|
||||||
<sys:String x:Key="Text.Dashboard.Configure">Configure this repository</sys:String>
|
<sys:String x:Key="Text.Dashboard.Configure">Configure this repository</sys:String>
|
||||||
<sys:String x:Key="Text.Dashboard.Workspace">WORKSPACE</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">标签描述 :</sys:String>
|
||||||
<sys:String x:Key="Text.CreateTag.Message.Placeholder">选填</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.Explore">在文件浏览器中打开</sys:String>
|
||||||
<sys:String x:Key="Text.Dashboard.VSCode">在Visual Studio Code中打开</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.Search">查找提交</sys:String>
|
||||||
<sys:String x:Key="Text.Dashboard.Configure">配置本仓库</sys:String>
|
<sys:String x:Key="Text.Dashboard.Configure">配置本仓库</sys:String>
|
||||||
<sys:String x:Key="Text.Dashboard.Workspace">工作区</sys:String>
|
<sys:String x:Key="Text.Dashboard.Workspace">工作区</sys:String>
|
||||||
|
|
|
@ -33,23 +33,15 @@
|
||||||
<controls:IconButton
|
<controls:IconButton
|
||||||
Margin="8,0"
|
Margin="8,0"
|
||||||
Padding="0,9"
|
Padding="0,9"
|
||||||
Icon="{DynamicResource Icon.Folder.Open}"
|
Icon="{DynamicResource Icon.Folder}"
|
||||||
ToolTip="{DynamicResource Text.Dashboard.Explore}"
|
ToolTip="{DynamicResource Text.Dashboard.Open}"
|
||||||
Click="Explore"/>
|
Click="OpenExternal"/>
|
||||||
<controls:IconButton
|
|
||||||
x:Name="btnOpenWithVSCode"
|
|
||||||
Visibility="Collapsed"
|
|
||||||
Margin="8,0"
|
|
||||||
Padding="0,9"
|
|
||||||
Icon="{DynamicResource Icon.VSCode}"
|
|
||||||
ToolTip="{DynamicResource Text.Dashboard.VSCode}"
|
|
||||||
Click="OpenInVSCode"/>
|
|
||||||
<controls:IconButton
|
<controls:IconButton
|
||||||
Margin="8,0"
|
Margin="8,0"
|
||||||
Padding="0,9"
|
Padding="0,9"
|
||||||
Icon="{DynamicResource Icon.Terminal}"
|
Icon="{DynamicResource Icon.Loading}"
|
||||||
ToolTip="{DynamicResource Text.Dashboard.Terminal}"
|
ToolTip="{DynamicResource Text.Dashboard.Refresh}"
|
||||||
Click="Terminal"/>
|
Click="TriggerRefresh"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
||||||
|
|
|
@ -56,9 +56,6 @@ namespace SourceGit.Views.Widgets {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
InitPages();
|
InitPages();
|
||||||
|
|
||||||
var vscode = Models.ExecutableFinder.Find("code.cmd");
|
|
||||||
if (vscode != null) btnOpenWithVSCode.Visibility = Visibility.Visible;
|
|
||||||
|
|
||||||
var watcher = Models.Watcher.Get(repo.Path);
|
var watcher = Models.Watcher.Get(repo.Path);
|
||||||
watcher.Navigate += NavigateTo;
|
watcher.Navigate += NavigateTo;
|
||||||
watcher.BranchChanged += UpdateBranches;
|
watcher.BranchChanged += UpdateBranches;
|
||||||
|
@ -307,48 +304,90 @@ namespace SourceGit.Views.Widgets {
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region TOOLBAR_COMMANDS
|
#region TOOLBAR_COMMANDS
|
||||||
private void Explore(object sender, RoutedEventArgs e) {
|
private MenuItem CreateMenuItem(string icon, string header, Action click) {
|
||||||
Process.Start("explorer", repo.Path);
|
var ret = new MenuItem();
|
||||||
e.Handled = true;
|
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) {
|
private void OpenExternal(object sender, RoutedEventArgs e) {
|
||||||
var vscode = Models.ExecutableFinder.Find("code.cmd");
|
var btn = sender as Controls.IconButton;
|
||||||
if (vscode == null) return;
|
if (btn == null) return;
|
||||||
|
|
||||||
vscode = Path.Combine(Path.GetDirectoryName(vscode), "..", "Code.exe");
|
if (btn.ContextMenu != null) {
|
||||||
Process.Start(new ProcessStartInfo {
|
btn.ContextMenu.IsOpen = true;
|
||||||
WorkingDirectory = repo.Path,
|
e.Handled = true;
|
||||||
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"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Models.Preference.Instance.General.UseWindowsTerminal) {
|
var menu = new ContextMenu();
|
||||||
Process.Start(new ProcessStartInfo {
|
menu.PlacementTarget = btn;
|
||||||
WorkingDirectory = repo.Path,
|
menu.Placement = PlacementMode.Bottom;
|
||||||
FileName = "wt",
|
menu.StaysOpen = false;
|
||||||
Arguments = $"-d \"{repo.Path}\" \"{bash}\"",
|
menu.Focusable = true;
|
||||||
UseShellExecute = false,
|
|
||||||
});
|
menu.Items.Add(CreateMenuItem("Icon.Folder.Open", "Dashboard.Explore", () => {
|
||||||
} else {
|
Process.Start("explorer", repo.Path);
|
||||||
Process.Start(new ProcessStartInfo {
|
}));
|
||||||
WorkingDirectory = repo.Path,
|
|
||||||
FileName = bash,
|
menu.Items.Add(CreateMenuItem("Icon.Terminal", "Dashboard.Terminal", () => {
|
||||||
UseShellExecute = true,
|
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;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue