mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
refactor<Launcher>: rewrite title bar of Launcher
This commit is contained in:
parent
567fad495b
commit
72f09e96af
3 changed files with 132 additions and 80 deletions
|
@ -8,6 +8,7 @@
|
|||
<Geometry x:Key="Icon.Bookmark">M192 0l0 1024 320-320 320 320 0-1024z</Geometry>
|
||||
<Geometry x:Key="Icon.Help">M512 96C282.2 96 96 282.2 96 512s186.2 416 416 416 416-186.2 416-416S741.8 96 512 96z m-8.6 608c-23.6 0-42.8-18-42.8-41.2 0-23 19.2-41.2 42.8-41.2 23.8 0 43 18 43 41.2 0 23.2-19 41.2-43 41.2z m80.4-193.8c-34.8 20.2-46.6 35-46.6 60.6v15.8h-69.4l-0.6-17.2c-3.4-41.2 11-66.8 47.2-88 33.8-20.2 48-33 48-57.8s-24-43-53.8-43c-30.2 0-52 19.6-53.6 49.2H384c1.4-64.4 49-110 129.4-110 75 0 126.6 41.6 126.6 101.4 0 39.8-19.2 67.2-56.2 89z</Geometry>
|
||||
<Geometry x:Key="Icon.Detail">M888.832 0H135.168c-32.256 0-58.88 26.112-58.88 58.88v906.24c0 32.256 26.112 58.88 58.88 58.88h753.152c32.256 0 58.88-26.112 58.88-58.88v-906.24c0.512-32.768-26.112-58.88-58.368-58.88z m-164.864 176.64c30.72 0 55.808 25.088 55.808 55.808s-25.088 55.808-55.808 55.808-55.808-25.088-55.808-55.808 24.576-55.808 55.808-55.808z m-211.968 0c30.72 0 55.808 25.088 55.808 55.808S542.72 288.256 512 288.256s-55.808-25.088-55.808-55.808S481.28 176.64 512 176.64z m-211.968 0c30.72 0 55.808 25.088 55.808 55.808s-25.088 55.808-55.808 55.808-55.808-25.088-55.808-55.808 25.088-55.808 55.808-55.808z m208.896 606.208H285.184c-24.576 0-44.032-19.968-44.032-44.032 0-24.576 19.968-44.032 44.032-44.032h223.744c24.576 0 44.032 19.968 44.032 44.032 0 24.064-19.456 44.032-44.032 44.032z m229.888-211.968H285.184c-24.576 0-44.032-19.968-44.032-44.032 0-24.576 19.968-44.032 44.032-44.032h453.12c24.576 0 44.032 19.968 44.032 44.032 0.512 24.064-19.456 44.032-43.52 44.032z</Geometry>
|
||||
<Geometry x:Key="Icon.NewTab">M490.667 85.333l42.667 0 0 853.333-42.667 0 0-853.333zM85.333 490.667l853.333 0 0 42.667-853.333 0 0-42.667z</Geometry>
|
||||
|
||||
<Geometry x:Key="Icon.ScrollLeft">M753.613 996.727L269.38 511.505 754.602 27.272z</Geometry>
|
||||
<Geometry x:Key="Icon.ScrollRight">M270.387 27.273L754.62 512.495 269.398 996.728z</Geometry>
|
||||
|
|
|
@ -47,18 +47,42 @@
|
|||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition x:Name="openedTabsColumn" Width="*"/>
|
||||
<ColumnDefinition Width="32"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="200"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Tabs -->
|
||||
<ScrollViewer x:Name="openedTabsScroller" Grid.Column="0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled">
|
||||
<ScrollViewer x:Name="openedTabsScroller" Grid.Column="0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled" CanContentScroll="True">
|
||||
<TabControl x:Name="openedTabs" Padding="0" SnapsToDevicePixels="True" ItemsSource="{Binding ElementName=me, Path=Tabs}" SizeChanged="OpenedTabsSizeChanged">
|
||||
<TabControl.Style>
|
||||
<Style TargetType="{x:Type TabControl}">
|
||||
<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" Margin="6,4,4,0">
|
||||
<StackPanel Orientation="Horizontal" IsItemsHost="True" SnapsToDevicePixels="True" KeyboardNavigation.TabIndex="1"/>
|
||||
<Button Margin="4,0,0,0" Click="NewTab" ToolTip="NEW PAGE" Width="24" Height="24" WindowChrome.IsHitTestVisibleInChrome="True">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}" BasedOn="{x:Null}">
|
||||
<Setter Property="Opacity" Value="1"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate>
|
||||
<Border x:Name="newTabBG" BorderThickness="0" Background="Transparent" CornerRadius="2">
|
||||
<Path Width="14" Height="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.NewTab}" Fill="{StaticResource Brush.FG}"/>
|
||||
</Border>
|
||||
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="newTabBG" Property="Background" Value="{StaticResource Brush.BG4}"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
|
@ -66,13 +90,11 @@
|
|||
</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>
|
||||
<converters:IntToRepoColor x:Key="IntToRepoColor"/>
|
||||
</TabControl.Resources>
|
||||
|
||||
<DataTemplate DataType="{x:Type local:Launcher+RepoTab}">
|
||||
<TabControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid x:Name="BG" MinWidth="80" Margin="8,0" Background="Transparent">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
|
@ -96,7 +118,7 @@
|
|||
Content="{Binding Title}"
|
||||
Foreground="{StaticResource Brush.FG2}" FontFamily="Consolas" FontWeight="Bold"/>
|
||||
|
||||
<Button Grid.Column="3" Click="CloseRepo" ToolTip="CLOSE">
|
||||
<Button Grid.Column="3" Click="CloseTab" ToolTip="CLOSE">
|
||||
<Path
|
||||
Width="8" Height="8"
|
||||
Fill="{StaticResource Brush.FG}"
|
||||
|
@ -109,10 +131,18 @@
|
|||
<DataTrigger Binding="{Binding IsActive}" Value="True">
|
||||
<Setter TargetName="Title" Property="Foreground" Value="{StaticResource Brush.FG}"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Color}" Value="0">
|
||||
<Setter TargetName="Icon" Property="Data" Value="{StaticResource Icon.Git}"/>
|
||||
<DataTrigger Binding="{Binding IsRepo}" Value="False">
|
||||
<Setter TargetName="Icon" Property="Data" Value="{StaticResource Icon.Home}"/>
|
||||
<Setter TargetName="Icon" Property="Fill" Value="{StaticResource Brush.FG}"/>
|
||||
</DataTrigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsRepo}" Value="True"/>
|
||||
<Condition Binding="{Binding Color}" Value="0"/>
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter TargetName="Icon" Property="Data" Value="{StaticResource Icon.Git}"/>
|
||||
<Setter TargetName="Icon" Property="Fill" Value="{StaticResource Brush.FG}"/>
|
||||
</MultiDataTrigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsActive}" Value="False"/>
|
||||
|
@ -122,11 +152,11 @@
|
|||
</MultiDataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</TabControl.Resources>
|
||||
</TabControl.ItemTemplate>
|
||||
|
||||
<TabControl.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type TabItem}">
|
||||
<Setter Property="AllowDrop" Value="{Binding IsRepo}"/>
|
||||
<Setter Property="AllowDrop" Value="True"/>
|
||||
<Setter Property="IsSelected" Value="{Binding IsActive, Mode=TwoWay}"/>
|
||||
<Setter Property="Margin" Value="0"/>
|
||||
<Setter Property="Padding" Value="0"/>
|
||||
|
@ -136,13 +166,6 @@
|
|||
<Grid SnapsToDevicePixels="True" WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="{Binding Tooltip}">
|
||||
<Border x:Name="BG" Margin="-1,0" SnapsToDevicePixels="True" Background="Transparent" CornerRadius="4,4,0,0"/>
|
||||
|
||||
<Rectangle
|
||||
x:Name="Splitter"
|
||||
HorizontalAlignment="Left"
|
||||
Width="1" Height="16"
|
||||
Fill="{StaticResource Brush.FG2}"
|
||||
Visibility="Hidden"/>
|
||||
|
||||
<Path
|
||||
x:Name="CornerLeft"
|
||||
Width="6"
|
||||
|
@ -168,6 +191,13 @@
|
|||
VerticalAlignment="Center"
|
||||
ContentSource="Header"
|
||||
RecognizesAccessKey="True"/>
|
||||
|
||||
<Rectangle
|
||||
x:Name="Splitter"
|
||||
HorizontalAlignment="Right"
|
||||
Width="1" Height="16"
|
||||
Fill="{StaticResource Brush.FG2}"
|
||||
Visibility="Hidden"/>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
|
@ -196,7 +226,6 @@
|
|||
<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>
|
||||
|
|
|
@ -22,14 +22,31 @@ namespace SourceGit.UI {
|
|||
/// </summary>
|
||||
public class Tab : INotifyPropertyChanged {
|
||||
private bool isActive = false;
|
||||
private Git.Repository repo = null;
|
||||
private object page = null;
|
||||
|
||||
public string Title { get; set; }
|
||||
public string Tooltip { get; set; }
|
||||
public Git.Repository Repo { get; set; }
|
||||
public object Page { get; set; }
|
||||
|
||||
public bool IsRepo {
|
||||
get { return Repo != null; }
|
||||
public Git.Repository Repo {
|
||||
get { return repo; }
|
||||
set {
|
||||
if (repo != value) {
|
||||
repo = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Repo"));
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Title"));
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Tooltip"));
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Color"));
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsRepo"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object Page {
|
||||
get { return page; }
|
||||
set {
|
||||
if (page != value) {
|
||||
page = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Page"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Color {
|
||||
|
@ -50,34 +67,24 @@ namespace SourceGit.UI {
|
|||
}
|
||||
}
|
||||
|
||||
public string Title {
|
||||
get {
|
||||
if (Repo == null) return "Repositories";
|
||||
return Repo.Parent == null ? Repo.Name : $"{Repo.Parent.Name} : {Repo.Name}";
|
||||
}
|
||||
}
|
||||
|
||||
public string Tooltip {
|
||||
get { return Repo == null ? "Repository Manager" : Repo.Path; }
|
||||
}
|
||||
|
||||
public bool IsRepo {
|
||||
get { return Repo != null; }
|
||||
}
|
||||
|
||||
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>
|
||||
/// Alerts.
|
||||
/// </summary>
|
||||
|
@ -92,9 +99,8 @@ namespace SourceGit.UI {
|
|||
/// Constructor
|
||||
/// </summary>
|
||||
public Launcher() {
|
||||
Tabs.Add(new ManagerTab());
|
||||
InitializeComponent();
|
||||
openedTabs.SelectedItem = Tabs[0];
|
||||
NewTab(null, null);
|
||||
if (App.Setting.CheckUpdate) Task.Run(CheckUpdate);
|
||||
}
|
||||
|
||||
|
@ -103,9 +109,8 @@ namespace SourceGit.UI {
|
|||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
public void Open(Git.Repository repo) {
|
||||
for (int i = 1; i < Tabs.Count; i++) {
|
||||
var opened = Tabs[i];
|
||||
if (opened.Repo.Path == repo.Path) {
|
||||
foreach (var opened in Tabs) {
|
||||
if (opened.IsRepo && opened.Repo.Path == repo.Path) {
|
||||
openedTabs.SelectedItem = opened;
|
||||
return;
|
||||
}
|
||||
|
@ -113,10 +118,17 @@ namespace SourceGit.UI {
|
|||
|
||||
repo.Open();
|
||||
var page = new Dashboard(repo);
|
||||
var tab = new RepoTab(repo, page);
|
||||
repo.SetPopupManager(page.popupManager);
|
||||
Tabs.Add(tab);
|
||||
openedTabs.SelectedItem = tab;
|
||||
|
||||
var selected = openedTabs.SelectedItem as Tab;
|
||||
if (selected != null && !selected.IsRepo) {
|
||||
selected.Repo = repo;
|
||||
selected.Page = page;
|
||||
} else {
|
||||
var tab = new Tab() { Repo = repo, Page = page };
|
||||
Tabs.Add(tab);
|
||||
openedTabs.SelectedItem = tab;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -148,23 +160,38 @@ namespace SourceGit.UI {
|
|||
|
||||
#region LAYOUT_CONTENT
|
||||
/// <summary>
|
||||
/// Close repository.
|
||||
/// Add new tab.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void CloseRepo(object sender, RoutedEventArgs e) {
|
||||
private void NewTab(object sender, RoutedEventArgs e) {
|
||||
var tab = new Tab() { Page = new Manager() };
|
||||
Tabs.Add(tab);
|
||||
openedTabs.SelectedItem = tab;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Close tab.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void CloseTab(object sender, RoutedEventArgs e) {
|
||||
var tab = (sender as Button).DataContext as Tab;
|
||||
if (tab == null || tab.Repo == null) {
|
||||
e.Handled = true;
|
||||
if (tab == null) return;
|
||||
|
||||
if (Tabs.Count == 1) {
|
||||
App.Current.Shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
Tabs.Remove(tab);
|
||||
|
||||
tab.Page = null;
|
||||
tab.Repo.RemovePopup();
|
||||
tab.Repo.Close();
|
||||
tab.Repo = null;
|
||||
if (tab.IsRepo) {
|
||||
tab.Repo.RemovePopup();
|
||||
tab.Repo.Close();
|
||||
tab.Repo = null;
|
||||
}
|
||||
|
||||
Tabs.Remove(tab);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -293,7 +320,7 @@ namespace SourceGit.UI {
|
|||
if (item == null) return;
|
||||
|
||||
var tab = item.DataContext as Tab;
|
||||
if (tab == null || tab.Repo == null) return;
|
||||
if (tab == null) return;
|
||||
|
||||
if (Mouse.LeftButton == MouseButtonState.Pressed) {
|
||||
DragDrop.DoDragDrop(item, item, DragDropEffects.All);
|
||||
|
@ -308,15 +335,10 @@ namespace SourceGit.UI {
|
|||
|
||||
var tabSrc = tabItemSrc.DataContext as Tab;
|
||||
var tabDst = tabItemDst.DataContext as Tab;
|
||||
if (tabDst.Repo == null) {
|
||||
Tabs.Remove(tabSrc);
|
||||
Tabs.Insert(1, tabSrc);
|
||||
} else {
|
||||
int dstIdx = Tabs.IndexOf(tabDst);
|
||||
int dstIdx = Tabs.IndexOf(tabDst);
|
||||
|
||||
Tabs.Remove(tabSrc);
|
||||
Tabs.Insert(dstIdx, tabSrc);
|
||||
}
|
||||
Tabs.Remove(tabSrc);
|
||||
Tabs.Insert(dstIdx, tabSrc);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
|
Loading…
Reference in a new issue