style<Dashboard>: re-arrange toolbar buttons

This commit is contained in:
leo 2021-10-27 11:24:59 +08:00
parent d5ff070505
commit aa331c5562
4 changed files with 60 additions and 83 deletions

View file

@ -116,7 +116,6 @@
<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 In Git Bash</sys:String> <sys:String x:Key="Text.Dashboard.Terminal">Open In Git Bash</sys:String>

View file

@ -115,7 +115,6 @@
<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>

View file

@ -33,15 +33,23 @@
<controls:IconButton <controls:IconButton
Margin="8,0" Margin="8,0"
Padding="0,9" Padding="0,9"
Icon="{DynamicResource Icon.Folder}" Icon="{DynamicResource Icon.Folder.Open}"
ToolTip="{DynamicResource Text.Dashboard.Open}" ToolTip="{DynamicResource Text.Dashboard.Explore}"
Click="OpenExternal"/> Click="OpenInExplorer"/>
<controls:IconButton
x:Name="btnVSCode"
Margin="8,0"
Padding="0,9"
Icon="{DynamicResource Icon.VSCode}"
ToolTip="{DynamicResource Text.Dashboard.VSCode}"
Visibility="Collapsed"
Click="OpenInVSCode"/>
<controls:IconButton <controls:IconButton
Margin="8,0" Margin="8,0"
Padding="0,9" Padding="0,9"
Icon="{DynamicResource Icon.Loading}" Icon="{DynamicResource Icon.Terminal}"
ToolTip="{DynamicResource Text.Dashboard.Refresh}" ToolTip="{DynamicResource Text.Dashboard.Terminal}"
Click="TriggerRefresh"/> Click="OpenInTerminal"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal"> <StackPanel Grid.Column="1" Orientation="Horizontal">
@ -93,14 +101,22 @@
<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right"> <StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right">
<ToggleButton <ToggleButton
Width="16" Height="16" Width="16" Height="16"
Margin="0,0,8,0"
Style="{StaticResource Style.ToggleButton.SplitDirection}" Style="{StaticResource Style.ToggleButton.SplitDirection}"
ToolTip="{DynamicResource Text.Histories.DisplayMode}" ToolTip="{DynamicResource Text.Histories.DisplayMode}"
Visibility="{Binding ElementName=pageHistories,Path=IsSelected,Converter={StaticResource BoolToCollapsed}}" Visibility="{Binding ElementName=pageHistories,Path=IsSelected,Converter={StaticResource BoolToCollapsed}}"
IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=Window.MoveCommitInfoRight, Mode=TwoWay, Converter={StaticResource InverseBool}}" IsChecked="{Binding Source={x:Static models:Preference.Instance}, Path=Window.MoveCommitInfoRight, Mode=TwoWay, Converter={StaticResource InverseBool}}"
Checked="ChangeOrientation" Unchecked="ChangeOrientation"/> Checked="ChangeOrientation" Unchecked="ChangeOrientation"/>
<controls:IconButton <controls:IconButton
Margin="12,0,8,0" Margin="8,0"
Padding="0,9,0,8"
Icon="{DynamicResource Icon.Loading}"
ToolTip="{DynamicResource Text.Dashboard.Refresh}"
Click="TriggerRefresh"/>
<controls:IconButton
Margin="8,0"
Padding="0,8" Padding="0,8"
Icon="{DynamicResource Icon.Setting}" Icon="{DynamicResource Icon.Setting}"
ToolTip="{DynamicResource Text.Dashboard.Configure}" ToolTip="{DynamicResource Text.Dashboard.Configure}"

View file

@ -56,6 +56,11 @@ namespace SourceGit.Views.Widgets {
InitializeComponent(); InitializeComponent();
InitPages(); InitPages();
Task.Run(() => {
var vscode = Models.ExecutableFinder.Find("code.cmd");
if (vscode != null) Dispatcher.Invoke(() => btnVSCode.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;
@ -304,86 +309,44 @@ namespace SourceGit.Views.Widgets {
#endregion #endregion
#region TOOLBAR_COMMANDS #region TOOLBAR_COMMANDS
private MenuItem CreateMenuItem(string icon, string header, Action click) { private void OpenInExplorer(object sender, RoutedEventArgs e) {
var ret = new MenuItem(); Process.Start("explorer", repo.Path);
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) { private void OpenInTerminal(object sender, RoutedEventArgs e) {
var btn = sender as Controls.IconButton; var bash = Path.Combine(Models.Preference.Instance.Git.Path, "..", "bash.exe");
if (btn == null) return; if (!File.Exists(bash)) {
Models.Exception.Raise(App.Text("MissingBash"));
if (btn.ContextMenu != null) {
btn.ContextMenu.IsOpen = true;
e.Handled = true;
return; return;
} }
var menu = new ContextMenu(); if (Models.Preference.Instance.General.UseWindowsTerminal) {
menu.PlacementTarget = btn; Process.Start(new ProcessStartInfo {
menu.Placement = PlacementMode.Bottom; WorkingDirectory = repo.Path,
menu.StaysOpen = false; FileName = "wt",
menu.Focusable = true; Arguments = $"-d \"{repo.Path}\" \"{bash}\"",
UseShellExecute = false,
menu.Items.Add(CreateMenuItem("Icon.Folder.Open", "Dashboard.Explore", () => { });
Process.Start("explorer", repo.Path); } else {
})); Process.Start(new ProcessStartInfo {
WorkingDirectory = repo.Path,
menu.Items.Add(CreateMenuItem("Icon.Terminal", "Dashboard.Terminal", () => { FileName = bash,
var bash = Path.Combine(Models.Preference.Instance.Git.Path, "..", "bash.exe"); UseShellExecute = true,
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; private void OpenInVSCode(object sender, RoutedEventArgs e) {
menu.IsOpen = true; var vscode = Models.ExecutableFinder.Find("code.cmd");
e.Handled = true; 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,
});
} }
private void TriggerRefresh(object sender, RoutedEventArgs e) { private void TriggerRefresh(object sender, RoutedEventArgs e) {