style<PageTabBar>: new style for page tab bar

This commit is contained in:
leo 2022-10-14 15:30:06 +08:00
parent 80acfb6b1f
commit c2517701cc
6 changed files with 105 additions and 37 deletions

View file

@ -24,7 +24,7 @@
<sys:String x:Key="Text.SSHKey">SSH Private Key :</sys:String>
<sys:String x:Key="Text.SSHKey.Placeholder">Private SSH key store path</sys:String>
<sys:String x:Key="Text.About">ABOUT</sys:String>
<sys:String x:Key="Text.About">About</sys:String>
<sys:String x:Key="Text.About.Title">SourceGit - OPEN SOURCE GIT CLIENT</sys:String>
<sys:String x:Key="Text.Apply">Patch</sys:String>
@ -280,8 +280,7 @@
<sys:String x:Key="Text.Init.Tip">Invalid repository detected. Run `git init` under this path?</sys:String>
<sys:String x:Key="Text.Launcher">Source Git</sys:String>
<sys:String x:Key="Text.Launcher.Preference">PREFERENCE</sys:String>
<sys:String x:Key="Text.Launcher.About">ABOUT</sys:String>
<sys:String x:Key="Text.Launcher.Menu">Open Main Menu</sys:String>
<sys:String x:Key="Text.Launcher.Error">ERROR</sys:String>
<sys:String x:Key="Text.PageTabBar.New">NEW PAGE</sys:String>

View file

@ -279,8 +279,7 @@
<sys:String x:Key="Text.Init.Tip">点击【确定】将在此目录执行`git init`操作</sys:String>
<sys:String x:Key="Text.Launcher">Source Git</sys:String>
<sys:String x:Key="Text.Launcher.Preference">偏好设置</sys:String>
<sys:String x:Key="Text.Launcher.About">关于</sys:String>
<sys:String x:Key="Text.Launcher.Menu">主菜单</sys:String>
<sys:String x:Key="Text.Launcher.Error">出错了</sys:String>
<sys:String x:Key="Text.PageTabBar.New">新建空白页</sys:String>

View file

@ -25,28 +25,34 @@
<!-- Titlebar -->
<Grid Grid.Row="0" Background="{DynamicResource Brush.TitleBar}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="32"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
<!-- Bottom border -->
<Rectangle Grid.Column="0" Grid.ColumnSpan="2" Fill="{DynamicResource Brush.Border0}" Height="1" VerticalAlignment="Bottom"/>
<Rectangle Grid.Column="0" Grid.ColumnSpan="4" Fill="{DynamicResource Brush.Border0}" Height="1" VerticalAlignment="Bottom"/>
<!-- Main Menu -->
<controls:IconButton
Grid.Column="0"
Margin="4,4,4,0"
Width="14"
Icon="{StaticResource Icon.List}"
ToolTip="{DynamicResource Text.Launcher.Menu}"
WindowChrome.IsHitTestVisibleInChrome="True"
Click="ToggleMainMenu"/>
<!-- Tabs -->
<widgets:PageTabBar
Grid.Column="0"
Grid.Column="1"
x:Name="tabs"
TabAdd="OnTabAdding"
TabSelected="OnTabSelected"
TabClosed="OnTabClosed"/>
<!-- Right controls -->
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Height="27" WindowChrome.IsHitTestVisibleInChrome="True">
<controls:IconButton Click="OpenPreference" Width="28" Padding="6" Icon="{StaticResource Icon.Preference}" ToolTip="{DynamicResource Text.Launcher.Preference}"/>
<controls:IconButton Click="OpenAbout" Width="28" Padding="6" Icon="{StaticResource Icon.Help}" ToolTip="{DynamicResource Text.Launcher.About}"/>
<Rectangle Margin="4,0" Width="1" Height="16" VerticalAlignment="Center" Fill="{DynamicResource Brush.Border2}"/>
<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Height="27" WindowChrome.IsHitTestVisibleInChrome="True">
<controls:IconButton Click="Minimize" Width="28" Padding="9" Icon="{StaticResource Icon.Minimize}" HoverBackground="#40000000" Opacity="1"/>
<ToggleButton Style="{StaticResource Style.ToggleButton.MaxOrRestore}" Width="28" IsChecked="{Binding ElementName=me, Path=IsMaximized}"/>
<controls:IconButton Click="Quit" Width="28" Padding="9" Icon="{StaticResource Icon.Close}" HoverBackground="Red" Opacity="1"/>

View file

@ -2,7 +2,11 @@ using System;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
namespace SourceGit.Views {
@ -77,15 +81,49 @@ namespace SourceGit.Views {
}
#endregion
#region RIGHT_COMMANDS
private void OpenPreference(object sender, RoutedEventArgs e) {
var dialog = new Preference() { Owner = this };
dialog.ShowDialog();
#region OPERATIONS
private void FillMenu(ContextMenu menu, string icon, string header, RoutedEventHandler onClick) {
var iconMode = new Path();
iconMode.Width = 12;
iconMode.Height = 12;
iconMode.Data = FindResource(icon) as Geometry;
iconMode.SetResourceReference(Path.FillProperty, "Brush.FG2");
var item = new MenuItem();
item.Icon = iconMode;
item.Header = App.Text(header);
item.Click += onClick;
menu.Items.Add(item);
}
private void OpenAbout(object sender, RoutedEventArgs e) {
private void ToggleMainMenu(object sender, RoutedEventArgs e) {
var btn = (sender as Button);
if (btn.ContextMenu != null) {
btn.ContextMenu.IsOpen = true;
e.Handled = true;
return;
}
var menu = new ContextMenu();
menu.Placement = PlacementMode.Bottom;
menu.PlacementTarget = btn;
menu.StaysOpen = false;
menu.Focusable = true;
FillMenu(menu, "Icon.Preference", "Preference", (o, ev) => {
var dialog = new Preference() { Owner = this };
dialog.ShowDialog();
});
FillMenu(menu, "Icon.Help", "About", (o, ev) => {
var dialog = new About() { Owner = this };
dialog.ShowDialog();
});
btn.ContextMenu = menu;
btn.ContextMenu.IsOpen = true;
e.Handled = true;
}
private void Minimize(object sender, RoutedEventArgs e) {

View file

@ -7,16 +7,25 @@
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignHeight="28" d:DesignWidth="800">
<Grid Margin="6,4,0,0">
<Grid Margin="0,4,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- Seperator -->
<Rectangle
Grid.Column="0"
x:Name="startSeperator"
Width="1" Height="16" Margin="0,2,0,0"
Fill="{DynamicResource Brush.FG2}"
Opacity=".5"/>
<!-- Left Scroller -->
<controls:IconButton
Grid.Column="0"
Grid.Column="1"
x:Name="leftScroller"
Click="ScrollLeft"
Width="18" Padding="6"
@ -28,7 +37,7 @@
<!-- Tabs -->
<ScrollViewer
Grid.Column="1"
Grid.Column="2"
x:Name="scroller"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Disabled">
@ -64,12 +73,13 @@
<TextBlock
Margin="4,0"
Width="80" MaxWidth="80" TextAlignment="Center"
Text="{Binding Title}"/>
<controls:IconButton
Click="CloseTab"
Width="16" Height="16"
Margin="4,0,0,0" Padding="4"
Margin="0,0,0,0" Padding="4"
ToolTip="{DynamicResource Text.Close}"
Icon="{StaticResource Icon.Close}"
HoverBackground="{DynamicResource Brush.NewPageHover}"/>
@ -121,7 +131,7 @@
<!-- Right Scroller -->
<controls:IconButton
Grid.Column="2"
Grid.Column="3"
x:Name="rightScroller"
Click="ScrollRight"
Width="18" Padding="6"

View file

@ -189,11 +189,17 @@ namespace SourceGit.Views.Widgets {
private void CalcScrollerVisibilty(object sender, SizeChangedEventArgs e) {
if ((sender as StackPanel).ActualWidth > scroller.ActualWidth) {
startSeperator.Visibility = Visibility.Hidden;
leftScroller.Visibility = Visibility.Visible;
rightScroller.Visibility = Visibility.Visible;
} else {
leftScroller.Visibility = Visibility.Collapsed;
rightScroller.Visibility = Visibility.Collapsed;
if (container.SelectedIndex == 0) {
startSeperator.Visibility = Visibility.Hidden;
} else {
startSeperator.Visibility = Visibility.Visible;
}
}
}
@ -223,17 +229,7 @@ namespace SourceGit.Views.Widgets {
private void SelectionChanged(object sender, SelectionChangedEventArgs e) {
var tab = container.SelectedItem as Tab;
if (tab == null) return;
for (int i = 0; i < Tabs.Count; i++) {
if (Tabs[i] == tab) {
tab.IsSeperatorVisible = false;
if (i > 0) Tabs[i - 1].IsSeperatorVisible = false;
} else {
Tabs[i].IsSeperatorVisible = true;
}
}
UpdateSeperators(tab);
RaiseEvent(new TabEventArgs(TabSelectedEvent, this, tab.Id));
}
@ -260,6 +256,7 @@ namespace SourceGit.Views.Widgets {
RaiseEvent(new TabEventArgs(TabSelectedEvent, this, next.Id));
} else {
Tabs.Remove(tab);
UpdateSeperators(curTab);
}
RaiseEvent(new TabEventArgs(TabClosedEvent, this, tab.Id));
}
@ -366,5 +363,24 @@ namespace SourceGit.Views.Widgets {
menu.IsOpen = true;
e.Handled = true;
}
private void UpdateSeperators(Tab actived) {
int curIdx = 0;
for (int i = 0; i < Tabs.Count; i++) {
if (Tabs[i] == actived) {
curIdx = i;
actived.IsSeperatorVisible = false;
if (i > 0) Tabs[i - 1].IsSeperatorVisible = false;
} else {
Tabs[i].IsSeperatorVisible = true;
}
}
if (leftScroller.Visibility == Visibility.Visible || curIdx == 0) {
startSeperator.Visibility = Visibility.Hidden;
} else {
startSeperator.Visibility = Visibility.Visible;
}
}
}
}