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,6 +101,7 @@
<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}}"
@ -100,7 +109,14 @@
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,48 +309,11 @@ 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();
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); Process.Start("explorer", repo.Path);
})); }
menu.Items.Add(CreateMenuItem("Icon.Terminal", "Dashboard.Terminal", () => { private void OpenInTerminal(object sender, RoutedEventArgs e) {
var bash = Path.Combine(Models.Preference.Instance.Git.Path, "..", "bash.exe"); var bash = Path.Combine(Models.Preference.Instance.Git.Path, "..", "bash.exe");
if (!File.Exists(bash)) { if (!File.Exists(bash)) {
Models.Exception.Raise(App.Text("MissingBash")); Models.Exception.Raise(App.Text("MissingBash"));
@ -366,24 +334,19 @@ namespace SourceGit.Views.Widgets {
UseShellExecute = true, UseShellExecute = true,
}); });
} }
})); }
private void OpenInVSCode(object sender, RoutedEventArgs e) {
var vscode = Models.ExecutableFinder.Find("code.cmd"); var vscode = Models.ExecutableFinder.Find("code.cmd");
if (vscode != null) { if (vscode == null) return;
vscode = Path.Combine(Path.GetDirectoryName(vscode), "..", "Code.exe"); vscode = Path.Combine(Path.GetDirectoryName(vscode), "..", "Code.exe");
menu.Items.Add(CreateMenuItem("Icon.VSCode", "Dashboard.VSCode", () => {
Process.Start(new ProcessStartInfo { Process.Start(new ProcessStartInfo {
WorkingDirectory = repo.Path, WorkingDirectory = repo.Path,
FileName = vscode, FileName = vscode,
Arguments = $"\"{repo.Path}\"", Arguments = $"\"{repo.Path}\"",
UseShellExecute = false, UseShellExecute = false,
}); });
}));
}
btn.ContextMenu = menu;
menu.IsOpen = true;
e.Handled = true;
} }
private void TriggerRefresh(object sender, RoutedEventArgs e) { private void TriggerRefresh(object sender, RoutedEventArgs e) {