mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
feature<Manager>: add context menu to change bookmark of selected repository
This commit is contained in:
parent
38aef83304
commit
f592aeb3db
5 changed files with 135 additions and 13 deletions
|
@ -15,6 +15,7 @@ namespace SourceGit.Converters {
|
|||
/// All supported colors.
|
||||
/// </summary>
|
||||
public static Brush[] Colors = new Brush[] {
|
||||
Brushes.Transparent,
|
||||
Brushes.White,
|
||||
Brushes.Red,
|
||||
Brushes.Orange,
|
||||
|
|
|
@ -88,6 +88,7 @@
|
|||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Path
|
||||
x:Name="Icon"
|
||||
Grid.Column="0"
|
||||
Width="14" Height="14"
|
||||
Fill="{Binding Color, Converter={StaticResource IntToRepoColor}}"
|
||||
|
@ -114,6 +115,10 @@
|
|||
<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}"/>
|
||||
<Setter TargetName="Icon" Property="Fill" Value="{StaticResource Brush.FG}"/>
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</TabControl.Resources>
|
||||
|
|
|
@ -188,18 +188,19 @@ namespace SourceGit.UI {
|
|||
e.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 = Geometry.Parse("M 0,0 A 180,180 180 1 1 1,1 Z");
|
||||
icon.Data = iconBookmark;
|
||||
icon.Fill = Converters.IntToRepoColor.Colors[i];
|
||||
icon.Width = 12;
|
||||
icon.Width = 8;
|
||||
|
||||
var mark = new MenuItem();
|
||||
mark.Icon = icon;
|
||||
mark.Header = $"{i + 1}";
|
||||
mark.Header = $"{i}";
|
||||
|
||||
var refIdx = i;
|
||||
mark.Click += (o, e) => {
|
||||
|
|
|
@ -6,8 +6,15 @@
|
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SourceGit.UI"
|
||||
xmlns:git="clr-namespace:SourceGit.Git"
|
||||
xmlns:converters="clr-namespace:SourceGit.Converters"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
|
||||
<UserControl.Resources>
|
||||
<converters:IntToRepoColor x:Key="IntToRepoColor"/>
|
||||
<converters:BoolToCollapsed x:Key="BoolToCollapsed"/>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Grid>
|
||||
<!-- Main Body -->
|
||||
<Grid>
|
||||
|
@ -48,11 +55,27 @@
|
|||
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type git:Repository}">
|
||||
<StackPanel Orientation="Horizontal" Height="24">
|
||||
<Path Height="12" Margin="16,0,0,0" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Git}"/>
|
||||
<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>
|
||||
<Grid Height="24">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<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>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
|
@ -71,7 +94,7 @@
|
|||
<Path Width="14" Height="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Pull}" Opacity=".8"/>
|
||||
</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"/>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
@ -82,6 +105,7 @@
|
|||
Padding="0"
|
||||
AllowDrop="True"
|
||||
ContextMenuOpening="TreeContextMenuOpening"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
Drop="TreeDrop"
|
||||
GotFocus="TreeGotFocus"
|
||||
MouseMove="TreeMouseMove">
|
||||
|
@ -105,12 +129,44 @@
|
|||
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
|
||||
<Grid Height="26">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="16"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</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"/>
|
||||
<TextBox x:Name="editName" Grid.Column="1" Margin="4,0,0,0" Text="{Binding Name}" Loaded="TreeNodeRenameStart" KeyDown="TreeNodeRenameKeyDown" LostFocus="TreeNodeRenameEnd"/>
|
||||
|
||||
<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"/>
|
||||
|
||||
<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>
|
||||
|
||||
<HierarchicalDataTemplate.Triggers>
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
|||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace SourceGit.UI {
|
||||
|
||||
|
@ -25,6 +26,7 @@ namespace SourceGit.UI {
|
|||
public bool IsRepo { get; set; }
|
||||
public bool IsExpended { get; set; }
|
||||
public bool IsEditing { get; set; }
|
||||
public int Color { get; set; }
|
||||
public List<Node> Children { get; set; } = new List<Node>();
|
||||
}
|
||||
|
||||
|
@ -100,6 +102,31 @@ namespace SourceGit.UI {
|
|||
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();
|
||||
delete.Header = "Delete";
|
||||
delete.Click += (o, ev) => {
|
||||
|
@ -113,6 +140,7 @@ namespace SourceGit.UI {
|
|||
var menu = new ContextMenu();
|
||||
menu.Items.Add(open);
|
||||
menu.Items.Add(explore);
|
||||
menu.Items.Add(bookmark);
|
||||
menu.Items.Add(delete);
|
||||
menu.IsOpen = true;
|
||||
e.Handled = true;
|
||||
|
@ -301,8 +329,37 @@ namespace SourceGit.UI {
|
|||
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(explore);
|
||||
menu.Items.Add(bookmark);
|
||||
} else {
|
||||
var addSubFolder = new MenuItem();
|
||||
addSubFolder.Header = "Add Sub-Folder";
|
||||
|
@ -463,6 +520,7 @@ namespace SourceGit.UI {
|
|||
IsRepo = false,
|
||||
IsExpended = group.IsExpended,
|
||||
IsEditing = group.Id == editingNodeId,
|
||||
Color = 0,
|
||||
};
|
||||
|
||||
groupNodes.Add(node.Id, node);
|
||||
|
@ -486,6 +544,7 @@ namespace SourceGit.UI {
|
|||
IsRepo = true,
|
||||
IsExpended = false,
|
||||
IsEditing = repo.Path == editingNodeId,
|
||||
Color = repo.Color,
|
||||
};
|
||||
|
||||
if (groupNodes.ContainsKey(repo.GroupId)) {
|
||||
|
|
Loading…
Reference in a new issue