feature<Manager>: add context menu to change bookmark of selected repository

This commit is contained in:
leo 2020-12-09 17:59:37 +08:00
parent 38aef83304
commit f592aeb3db
5 changed files with 135 additions and 13 deletions

View file

@ -15,6 +15,7 @@ namespace SourceGit.Converters {
/// All supported colors. /// All supported colors.
/// </summary> /// </summary>
public static Brush[] Colors = new Brush[] { public static Brush[] Colors = new Brush[] {
Brushes.Transparent,
Brushes.White, Brushes.White,
Brushes.Red, Brushes.Red,
Brushes.Orange, Brushes.Orange,

View file

@ -88,6 +88,7 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Path <Path
x:Name="Icon"
Grid.Column="0" Grid.Column="0"
Width="14" Height="14" Width="14" Height="14"
Fill="{Binding Color, Converter={StaticResource IntToRepoColor}}" Fill="{Binding Color, Converter={StaticResource IntToRepoColor}}"
@ -114,6 +115,10 @@
<DataTrigger Binding="{Binding IsActive}" Value="True"> <DataTrigger Binding="{Binding IsActive}" Value="True">
<Setter TargetName="Title" Property="Foreground" Value="{StaticResource Brush.FG}"/> <Setter TargetName="Title" Property="Foreground" Value="{StaticResource Brush.FG}"/>
</DataTrigger> </DataTrigger>
<DataTrigger Binding="{Binding Color}" Value="0">
<Setter TargetName="Icon" Property="Data" Value="{StaticResource Icon.Git}"/>
<Setter TargetName="Icon" Property="Fill" Value="{StaticResource Brush.FG}"/>
</DataTrigger>
</DataTemplate.Triggers> </DataTemplate.Triggers>
</DataTemplate> </DataTemplate>
</TabControl.Resources> </TabControl.Resources>

View file

@ -188,18 +188,19 @@ namespace SourceGit.UI {
e.Handled = true; e.Handled = true;
}; };
var iconBookmark = FindResource("Icon.Bookmark") as Geometry;
var bookmark = new MenuItem(); var bookmark = new MenuItem();
bookmark.Header = "Bookmark"; bookmark.Header = "Bookmark";
for (int i = 0; i < Converters.IntToRepoColor.Colors.Length; i++) { for (int i = 0; i < Converters.IntToRepoColor.Colors.Length; i++) {
var icon = new System.Windows.Shapes.Path(); var icon = new System.Windows.Shapes.Path();
icon.Style = FindResource("Style.Icon") as Style; icon.Style = FindResource("Style.Icon") as Style;
icon.Data = Geometry.Parse("M 0,0 A 180,180 180 1 1 1,1 Z"); icon.Data = iconBookmark;
icon.Fill = Converters.IntToRepoColor.Colors[i]; icon.Fill = Converters.IntToRepoColor.Colors[i];
icon.Width = 12; icon.Width = 8;
var mark = new MenuItem(); var mark = new MenuItem();
mark.Icon = icon; mark.Icon = icon;
mark.Header = $"{i + 1}"; mark.Header = $"{i}";
var refIdx = i; var refIdx = i;
mark.Click += (o, e) => { mark.Click += (o, e) => {

View file

@ -6,8 +6,15 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SourceGit.UI" xmlns:local="clr-namespace:SourceGit.UI"
xmlns:git="clr-namespace:SourceGit.Git" xmlns:git="clr-namespace:SourceGit.Git"
xmlns:converters="clr-namespace:SourceGit.Converters"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<converters:IntToRepoColor x:Key="IntToRepoColor"/>
<converters:BoolToCollapsed x:Key="BoolToCollapsed"/>
</UserControl.Resources>
<Grid> <Grid>
<!-- Main Body --> <!-- Main Body -->
<Grid> <Grid>
@ -48,11 +55,27 @@
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate DataType="{x:Type git:Repository}"> <DataTemplate DataType="{x:Type git:Repository}">
<StackPanel Orientation="Horizontal" Height="24"> <Grid Height="24">
<Path Height="12" Margin="16,0,0,0" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Git}"/> <Grid.ColumnDefinitions>
<TextBlock Margin="4,0" Text="{Binding Name}" VerticalAlignment="Center" Foreground="{StaticResource Brush.FG}"/> <ColumnDefinition Width="Auto"/>
<TextBlock FontSize="10" Text="{Binding Path}" VerticalAlignment="Center" Foreground="{StaticResource Brush.FG2}"/> <ColumnDefinition Width="*"/>
</StackPanel> <ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Path Grid.Column="0" Width="12" Margin="16,0,0,0" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Git}"/>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<TextBlock Margin="4,0" Text="{Binding Name}" VerticalAlignment="Center" Foreground="{StaticResource Brush.FG}"/>
<TextBlock FontSize="10" Text="{Binding Path}" VerticalAlignment="Center" Foreground="{StaticResource Brush.FG2}"/>
</StackPanel>
<Path
Grid.Column="2"
Width="12" Height="12" Margin="4,0"
Style="{StaticResource Style.Icon}"
Data="{StaticResource Icon.Bookmark}"
Fill="{Binding Color, Converter={StaticResource IntToRepoColor}}"/>
</Grid>
</DataTemplate> </DataTemplate>
</ListView.ItemTemplate> </ListView.ItemTemplate>
</ListView> </ListView>
@ -71,7 +94,7 @@
<Path Width="14" Height="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Pull}" Opacity=".8"/> <Path Width="14" Height="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Pull}" Opacity=".8"/>
</Button> </Button>
<Button Grid.Column="2" Click="OpenOrAddRepo" Style="{StaticResource Style.Button}" Margin="8,0,2,0" ToolTip="Open Local Repository"> <Button Grid.Column="2" Click="OpenOrAddRepo" Style="{StaticResource Style.Button}" Margin="8,0,4,0" ToolTip="Open Local Repository">
<Path Width="14" Height="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder.Open}" Opacity=".8"/> <Path Width="14" Height="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder.Open}" Opacity=".8"/>
</Button> </Button>
</Grid> </Grid>
@ -82,6 +105,7 @@
Padding="0" Padding="0"
AllowDrop="True" AllowDrop="True"
ContextMenuOpening="TreeContextMenuOpening" ContextMenuOpening="TreeContextMenuOpening"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Drop="TreeDrop" Drop="TreeDrop"
GotFocus="TreeGotFocus" GotFocus="TreeGotFocus"
MouseMove="TreeMouseMove"> MouseMove="TreeMouseMove">
@ -105,12 +129,44 @@
<HierarchicalDataTemplate ItemsSource="{Binding Children}"> <HierarchicalDataTemplate ItemsSource="{Binding Children}">
<Grid Height="26"> <Grid Height="26">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="16"/> <ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Path x:Name="icon" Grid.Column="0" Width="14" Height="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder.Fill}"/>
<TextBlock x:Name="name" Grid.Column="1" Margin="4,0,0,0" Text="{Binding Name}" Foreground="{StaticResource Brush.FG}" VerticalAlignment="Center"/> <Path
<TextBox x:Name="editName" Grid.Column="1" Margin="4,0,0,0" Text="{Binding Name}" Loaded="TreeNodeRenameStart" KeyDown="TreeNodeRenameKeyDown" LostFocus="TreeNodeRenameEnd"/> x:Name="icon"
Grid.Column="0"
Width="14" Height="14"
Style="{StaticResource Style.Icon}"
Data="{StaticResource Icon.Folder.Fill}"/>
<TextBlock
x:Name="name"
Grid.Column="1"
Margin="4,0,0,0"
Text="{Binding Name}"
Foreground="{StaticResource Brush.FG}"
VerticalAlignment="Center"/>
<TextBox
x:Name="editName"
Grid.Column="1"
Margin="4,0,0,0"
Text="{Binding Name}"
Loaded="TreeNodeRenameStart"
KeyDown="TreeNodeRenameKeyDown"
LostFocus="TreeNodeRenameEnd"/>
<Path
x:Name="bookmark"
Grid.Column="2"
Width="14" Height="14"
Margin="4,0"
Style="{StaticResource Style.Icon}"
Data="{StaticResource Icon.Bookmark}"
Fill="{Binding Color, Converter={StaticResource IntToRepoColor}}"
Visibility="{Binding IsRepo, Converter={StaticResource BoolToCollapsed}}"/>
</Grid> </Grid>
<HierarchicalDataTemplate.Triggers> <HierarchicalDataTemplate.Triggers>

View file

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
namespace SourceGit.UI { namespace SourceGit.UI {
@ -25,6 +26,7 @@ namespace SourceGit.UI {
public bool IsRepo { get; set; } public bool IsRepo { get; set; }
public bool IsExpended { get; set; } public bool IsExpended { get; set; }
public bool IsEditing { get; set; } public bool IsEditing { get; set; }
public int Color { get; set; }
public List<Node> Children { get; set; } = new List<Node>(); public List<Node> Children { get; set; } = new List<Node>();
} }
@ -100,6 +102,31 @@ namespace SourceGit.UI {
ev.Handled = true; ev.Handled = true;
}; };
var iconBookmark = FindResource("Icon.Bookmark") as Geometry;
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 = iconBookmark;
icon.Fill = Converters.IntToRepoColor.Colors[i];
icon.Width = 8;
var mark = new MenuItem();
mark.Icon = icon;
mark.Header = $"{i}";
var refIdx = i;
mark.Click += (o, e) => {
repo.Color = refIdx;
UpdateRecentOpened();
UpdateTree();
e.Handled = true;
};
bookmark.Items.Add(mark);
}
var delete = new MenuItem(); var delete = new MenuItem();
delete.Header = "Delete"; delete.Header = "Delete";
delete.Click += (o, ev) => { delete.Click += (o, ev) => {
@ -113,6 +140,7 @@ namespace SourceGit.UI {
var menu = new ContextMenu(); var menu = new ContextMenu();
menu.Items.Add(open); menu.Items.Add(open);
menu.Items.Add(explore); menu.Items.Add(explore);
menu.Items.Add(bookmark);
menu.Items.Add(delete); menu.Items.Add(delete);
menu.IsOpen = true; menu.IsOpen = true;
e.Handled = true; e.Handled = true;
@ -301,8 +329,37 @@ namespace SourceGit.UI {
ev.Handled = true; ev.Handled = true;
}; };
var iconBookmark = FindResource("Icon.Bookmark") as Geometry;
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 = iconBookmark;
icon.Fill = Converters.IntToRepoColor.Colors[i];
icon.Width = 8;
var mark = new MenuItem();
mark.Icon = icon;
mark.Header = $"{i}";
var refIdx = i;
mark.Click += (o, e) => {
var repo = App.Preference.FindRepository(node.Id);
if (repo != null) {
repo.Color = refIdx;
UpdateRecentOpened();
UpdateTree();
}
e.Handled = true;
};
bookmark.Items.Add(mark);
}
menu.Items.Add(open); menu.Items.Add(open);
menu.Items.Add(explore); menu.Items.Add(explore);
menu.Items.Add(bookmark);
} else { } else {
var addSubFolder = new MenuItem(); var addSubFolder = new MenuItem();
addSubFolder.Header = "Add Sub-Folder"; addSubFolder.Header = "Add Sub-Folder";
@ -463,6 +520,7 @@ namespace SourceGit.UI {
IsRepo = false, IsRepo = false,
IsExpended = group.IsExpended, IsExpended = group.IsExpended,
IsEditing = group.Id == editingNodeId, IsEditing = group.Id == editingNodeId,
Color = 0,
}; };
groupNodes.Add(node.Id, node); groupNodes.Add(node.Id, node);
@ -486,6 +544,7 @@ namespace SourceGit.UI {
IsRepo = true, IsRepo = true,
IsExpended = false, IsExpended = false,
IsEditing = repo.Path == editingNodeId, IsEditing = repo.Path == editingNodeId,
Color = repo.Color,
}; };
if (groupNodes.ContainsKey(repo.GroupId)) { if (groupNodes.ContainsKey(repo.GroupId)) {