feature<Launcher>: change style of tabs in title bar; bookmark color for repository

This commit is contained in:
leo 2020-12-07 18:03:05 +08:00
parent 7e01792a37
commit a2254ae578
5 changed files with 232 additions and 87 deletions

View file

@ -0,0 +1,52 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
namespace SourceGit.Converters {
/// <summary>
/// Integer to color.
/// </summary>
public class IntToRepoColor : IValueConverter {
/// <summary>
/// All supported colors.
/// </summary>
public static Brush[] Colors = new Brush[] {
Brushes.White,
Brushes.Red,
Brushes.Orange,
Brushes.Yellow,
Brushes.ForestGreen,
Brushes.Purple,
Brushes.DeepSkyBlue,
Brushes.Magenta,
};
/// <summary>
/// Implement IValueConverter.Convert
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
return Colors[((int)value) % Colors.Length];
}
/// <summary>
/// Implement IValueConverter.ConvertBack
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
return ((Thickness)value).Left;
}
}
}

View file

@ -39,6 +39,10 @@ namespace SourceGit.Git {
/// </summary>
public string GroupId { get; set; }
/// <summary>
/// Custom color.
/// </summary>
public int Color { get; set; } = 0;
/// <summary>
/// Last open time(File time format).
/// </summary>
public long LastOpenTime { get; set; }

View file

@ -57,7 +57,7 @@
</Grid.ColumnDefinitions>
<ContentPresenter Name="Icon" Grid.Column="0" Margin="6,0" VerticalAlignment="Center" ContentSource="Icon"/>
<ContentPresenter Name="HeadHost" Grid.Column="1" ContentSource="Header" VerticalAlignment="Center"/>
<ContentPresenter Name="HeadHost" Grid.Column="1" Margin="0,0,8,0" ContentSource="Header" VerticalAlignment="Center"/>
<Path Grid.Column="2" Width="8" Height="8" Style="{DynamicResource Style.Icon}" Data="M 0 0 L 0 7 L 4 3.5 Z"/>
<Popup Name="Popup" Placement="Right" HorizontalOffset="-2" IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Fade">
<Border Name="SubmenuBorder" SnapsToDevicePixels="True" Background="{DynamicResource Brush.BG1}" BorderBrush="{DynamicResource Brush.Border1}" BorderThickness="1">

View file

@ -5,6 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:source="clr-namespace:SourceGit"
xmlns:local="clr-namespace:SourceGit.UI"
xmlns:converters="clr-namespace:SourceGit.Converters"
mc:Ignorable="d"
MinWidth="800" MinHeight="600"
Title="Source Git"
@ -62,41 +64,82 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<StackPanel Orientation="Horizontal"
x:Name="HeaderPanel"
Margin="6,4,0,0"
IsItemsHost="True"
SnapsToDevicePixels="True"
KeyboardNavigation.TabIndex="1"/>
<StackPanel Orientation="Horizontal" x:Name="HeaderPanel" Margin="6,4,0,0" IsItemsHost="True" SnapsToDevicePixels="True" KeyboardNavigation.TabIndex="1"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Style>
<TabControl.Resources>
<converters:IntToRepoColor x:Key="IntToRepoColor"/>
<DataTemplate DataType="{x:Type local:Launcher+ManagerTab}">
<Path Width="14" Height="14" Margin="12,0" Fill="#FFF05133" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Home}"/>
</DataTemplate>
<DataTemplate DataType="{x:Type local:Launcher+RepoTab}">
<Grid MinWidth="72" Margin="12,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*" MinWidth="6"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Path
Grid.Column="0"
Width="12" Height="12"
Fill="{Binding Color, Converter={StaticResource IntToRepoColor}}"
Style="{StaticResource Style.Icon}"
Data="{StaticResource Icon.Git}"/>
<Label
Grid.Column="1"
Content="{Binding Title}"
Foreground="{StaticResource Brush.FG}" FontFamily="Consolas" FontWeight="Bold"/>
<Button Grid.Column="3" Click="CloseRepo" ToolTip="CLOSE">
<Path
Width="8" Height="8"
Fill="{StaticResource Brush.FG}"
Style="{StaticResource Style.Icon}"
Data="{StaticResource Icon.Close}"/>
</Button>
</Grid>
</DataTemplate>
</TabControl.Resources>
<TabControl.ItemContainerStyle>
<Style TargetType="{x:Type TabItem}">
<Setter Property="AllowDrop" Value="{Binding AllowDragDrop}"/>
<Setter Property="AllowDrop" Value="{Binding IsRepo}"/>
<Setter Property="IsSelected" Value="{Binding IsActive, Mode=TwoWay}"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid x:Name="Container" Opacity=".7" SnapsToDevicePixels="True" WindowChrome.IsHitTestVisibleInChrome="True">
<Border x:Name="BG" SnapsToDevicePixels="True" Background="Transparent" BorderThickness="0" BorderBrush="{StaticResource Brush.BG3}" CornerRadius="4,4,0,0">
<Grid SnapsToDevicePixels="True" WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="{Binding Tooltip}">
<Border x:Name="BG" Margin="-1,0" SnapsToDevicePixels="True" Background="Transparent" BorderThickness="0" BorderBrush="{StaticResource Brush.BG3}" CornerRadius="4,4,0,0">
<Border.Effect>
<DropShadowEffect ShadowDepth="0" Opacity=".5"/>
</Border.Effect>
</Border>
<Rectangle
x:Name="Splitter"
HorizontalAlignment="Left"
Width="1" Height="16"
Fill="{StaticResource Brush.FG2}"
Visibility="Hidden"/>
<Path
x:Name="CornerLeft"
Width="6"
Height="6"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Margin="-5,0,0,0"
Margin="-6,0,0,0"
Data="M 0,6 L 6,6 6,0 C 6,0 6,6 0,6 Z"
Fill="Transparent"/>
@ -106,44 +149,50 @@
Height="6"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Margin="0,0,-5,0"
Margin="0,0,-6,0"
Data="M 0,0 L 0,6 6,6 C 6,6 0,6 0,0 Z"
Fill="Transparent"/>
<StackPanel Orientation="Horizontal" Margin="12,0" VerticalAlignment="Center">
<Path Grid.Column="0" Width="14" Height="14" x:Name="Icon" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Git}"/>
<ContentPresenter
x:Name="ContentSite"
VerticalAlignment="Center" HorizontalAlignment="Center"
TextElement.Foreground="{DynamicResource Brush.FG}"
TextElement.FontWeight="Bold"
ContentSource="Header"
Margin="8,0,0,0"
RecognizesAccessKey="True" />
</StackPanel>
<ContentPresenter
x:Name="ContentSite"
VerticalAlignment="Center"
ContentSource="Header"
Opacity=".7"
RecognizesAccessKey="True"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Panel.ZIndex" Value="2"/>
<Setter TargetName="BG" Property="Background" Value="{DynamicResource Brush.BG1}"/>
<Setter TargetName="BG" Property="BorderThickness" Value="1,1,1,0"/>
<Setter TargetName="Container" Property="Opacity" Value="1"/>
<Setter TargetName="CornerLeft" Property="Fill" Value="{StaticResource Brush.BG1}"/>
<Setter TargetName="CornerRight" Property="Fill" Value="{StaticResource Brush.BG1}"/>
<Setter TargetName="ContentSite" Property="Opacity" Value="1"/>
</Trigger>
<Trigger Property="AllowDrop" Value="False">
<Setter TargetName="Icon" Property="Data" Value="{StaticResource Icon.Home}"/>
<Trigger Property="IsSelected" Value="False">
<Setter Property="Panel.ZIndex" Value="-1"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="False"/>
<Condition Property="IsMouseOver" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Panel.ZIndex" Value="-1"/>
<Setter Property="Panel.ZIndex" Value="1"/>
<Setter TargetName="BG" Property="Background" Value="{DynamicResource Brush.BG5}"/>
<Setter TargetName="CornerLeft" Property="Fill" Value="{StaticResource Brush.BG5}"/>
<Setter TargetName="CornerRight" Property="Fill" Value="{StaticResource Brush.BG5}"/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="False"/>
<Condition Property="IsMouseOver" Value="False"/>
<Condition Property="AllowDrop" Value="True"/>
</MultiTrigger.Conditions>
<Setter TargetName="Splitter" Property="Visibility" Value="Visible"/>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
@ -154,16 +203,6 @@
<EventSetter Event="ContextMenuOpening" Handler="TabsContextMenuOpening"/>
</Style>
</TabControl.ItemContainerStyle>
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Grid.Column="1" Text="{Binding Title}" Foreground="{StaticResource Brush.FG}" FontWeight="Bold">
<TextBlock.ToolTip>
<ToolTip Content="{Binding Tooltip}" FontWeight="Normal"/>
</TextBlock.ToolTip>
</TextBlock>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
</ScrollViewer>

View file

@ -1,5 +1,5 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Net;
using System.Reflection;
using System.Text.Json;
@ -8,6 +8,7 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace SourceGit.UI {
@ -19,13 +20,48 @@ namespace SourceGit.UI {
/// <summary>
/// Tab data.
/// </summary>
public class Tab {
public class Tab : INotifyPropertyChanged {
public string Title { get; set; }
public string Tooltip { get; set; }
public bool AllowDragDrop { get; set; }
public bool IsActive { get; set; }
public Git.Repository Repo { get; set; }
public object Page { get; set; }
public bool IsRepo => Repo != null;
public int Color {
get { return Repo == null ? 0 : Repo.Color; }
set {
if (Repo == null || Repo.Color == value) return;
Repo.Color = value;
PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Color"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
/// <summary>
/// Manager tab
/// </summary>
public class ManagerTab : Tab {
public ManagerTab() {
Title = "HOME";
Tooltip = "Repositories Manager";
IsActive = true;
Page = new Manager();
}
}
/// <summary>
/// Repository tab.
/// </summary>
public class RepoTab : Tab {
public RepoTab(Git.Repository repo, Dashboard page) {
Title = repo.Parent == null ? repo.Name : $"{repo.Parent.Name} : {repo.Name}";
Tooltip = repo.Path;
Repo = repo;
IsActive = false;
Page = page;
}
}
/// <summary>
@ -42,16 +78,9 @@ namespace SourceGit.UI {
/// Constructor
/// </summary>
public Launcher() {
Tabs.Add(new Tab() {
Title = "HOME",
Tooltip = "Repositories Manager",
AllowDragDrop = false,
Page = new Manager(),
});
Tabs.Add(new ManagerTab());
InitializeComponent();
openedTabs.SelectedItem = Tabs[0];
if (App.Preference.CheckUpdate) Task.Run(CheckUpdate);
}
@ -69,16 +98,8 @@ namespace SourceGit.UI {
}
repo.Open();
var page = new Dashboard(repo);
var tab = new Tab() {
Title = repo.Parent == null ? repo.Name : $"{repo.Parent.Name} : {repo.Name}",
Tooltip = repo.Path,
AllowDragDrop = true,
Repo = repo,
Page = page,
};
var tab = new RepoTab(repo, page);
repo.SetPopupManager(page.popupManager);
Tabs.Add(tab);
openedTabs.SelectedItem = tab;
@ -112,6 +133,26 @@ namespace SourceGit.UI {
}
#region LAYOUT_CONTENT
/// <summary>
/// Close repository.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CloseRepo(object sender, RoutedEventArgs e) {
var tab = (sender as Button).DataContext as Tab;
if (tab == null || tab.Repo == null) {
e.Handled = true;
return;
}
Tabs.Remove(tab);
tab.Page = null;
tab.Repo.RemovePopup();
tab.Repo.Close();
tab.Repo = null;
}
/// <summary>
/// Context menu for tab items.
/// </summary>
@ -119,34 +160,12 @@ namespace SourceGit.UI {
/// <param name="e"></param>
private void TabsContextMenuOpening(object sender, ContextMenuEventArgs ev) {
var tab = (sender as TabItem).DataContext as Tab;
if (tab == null) {
if (tab == null || tab.Repo == null) {
ev.Handled = true;
return;
}
var repo = tab.Repo;
if (repo == null) {
ev.Handled = true;
return;
}
var close = new MenuItem();
close.Header = "Close";
close.Click += (o, e) => {
Tabs.Remove(tab);
tab.Page = null;
tab.Repo.RemovePopup();
tab.Repo.Close();
tab.Repo = null;
};
var copyPath = new MenuItem();
copyPath.Header = "Copy Path";
copyPath.Click += (o, e) => {
Clipboard.SetText(repo.Path);
e.Handled = true;
};
var refresh = new MenuItem();
refresh.Header = "Refresh";
@ -155,11 +174,39 @@ namespace SourceGit.UI {
e.Handled = true;
};
var bookmark = new MenuItem();
bookmark.Header = "Bookmark";
for (int i = 0; i < Converters.IntToRepoColor.Colors.Length; i++) {
var icon = new System.Windows.Shapes.Path();
icon.Style = FindResource("Style.Icon") as Style;
icon.Data = Geometry.Parse("M 0,0 A 180,180 180 1 1 1,1 Z");
icon.Fill = Converters.IntToRepoColor.Colors[i];
icon.Width = 12;
var mark = new MenuItem();
mark.Icon = icon;
mark.Header = $"{i + 1}";
var refIdx = i;
mark.Click += (o, e) => {
tab.Color = refIdx;
e.Handled = true;
};
bookmark.Items.Add(mark);
}
var copyPath = new MenuItem();
copyPath.Header = "Copy path";
copyPath.Click += (o, e) => {
Clipboard.SetText(repo.Path);
e.Handled = true;
};
var menu = new ContextMenu();
menu.Items.Add(close);
menu.Items.Add(new Separator());
menu.Items.Add(copyPath);
menu.Items.Add(refresh);
menu.Items.Add(bookmark);
menu.Items.Add(copyPath);
menu.IsOpen = true;
ev.Handled = true;
@ -227,11 +274,14 @@ namespace SourceGit.UI {
#region DRAG_DROP
private void TabsMouseMove(object sender, MouseEventArgs e) {
var tab = e.Source as TabItem;
if (tab == null || (tab.DataContext as Tab).Repo == null) return;
var item = e.Source as TabItem;
if (item == null) return;
var tab = item.DataContext as Tab;
if (tab == null || tab.Repo == null) return;
if (Mouse.LeftButton == MouseButtonState.Pressed) {
DragDrop.DoDragDrop(tab, tab, DragDropEffects.All);
DragDrop.DoDragDrop(item, item, DragDropEffects.All);
e.Handled = true;
}
}