feature<Repository>: supports modify display name of repository

This commit is contained in:
leo 2024-01-17 11:02:08 +08:00
parent 22416812a0
commit 4e40018a78
8 changed files with 160 additions and 1 deletions

View file

@ -24,7 +24,16 @@ namespace SourceGit.Models {
public class Repository { public class Repository {
#region PROPERTIES_SAVED #region PROPERTIES_SAVED
public string Name { get; set; } = ""; public string Name {
get => name;
set {
if (name != value) {
name = value;
Watcher.NotifyDisplayNameChanged(this);
}
}
}
public string Path { get; set; } = ""; public string Path { get; set; } = "";
public string GitDir { get; set; } = ""; public string GitDir { get; set; } = "";
public long LastOpenTime { get; set; } = 0; public long LastOpenTime { get; set; } = 0;
@ -131,6 +140,7 @@ namespace SourceGit.Models {
} }
private readonly object updateFilterLock = new object(); private readonly object updateFilterLock = new object();
private string name = string.Empty;
private int bookmark = 0; private int bookmark = 0;
} }
} }

View file

@ -14,6 +14,11 @@ namespace SourceGit.Models {
/// </summary> /// </summary>
public static event Action<Repository> Opened; public static event Action<Repository> Opened;
/// <summary>
/// 仓库的显示名变化了
/// </summary>
public static event Action<string, string> DisplayNameChanged;
/// <summary> /// <summary>
/// 仓库的书签变化了 /// 仓库的书签变化了
/// </summary> /// </summary>
@ -102,6 +107,14 @@ namespace SourceGit.Models {
} }
} }
/// <summary>
/// 通知仓库显示名变化
/// </summary>
/// <param name="repo"></param>
public static void NotifyDisplayNameChanged(Repository repo) {
DisplayNameChanged?.Invoke(repo.Path, repo.Name);
}
/// <summary> /// <summary>
/// 通知仓库标签变化 /// 通知仓库标签变化
/// </summary> /// </summary>

View file

@ -305,6 +305,8 @@
<sys:String x:Key="Text.Welcome.Search">Search Repositories ...</sys:String> <sys:String x:Key="Text.Welcome.Search">Search Repositories ...</sys:String>
<sys:String x:Key="Text.Welcome.Sort">Sort</sys:String> <sys:String x:Key="Text.Welcome.Sort">Sort</sys:String>
<sys:String x:Key="Text.Welcome.DragDropTip">DRAG &amp; DROP FOLDER HERE</sys:String> <sys:String x:Key="Text.Welcome.DragDropTip">DRAG &amp; DROP FOLDER HERE</sys:String>
<sys:String x:Key="Text.Welcome.Rename">Edit Display Name</sys:String>
<sys:String x:Key="Text.Welcome.NewName">Display Name :</sys:String>
<sys:String x:Key="Text.Pull">Pull</sys:String> <sys:String x:Key="Text.Pull">Pull</sys:String>
<sys:String x:Key="Text.Pull.Title">Pull (Fetch &amp; Merge)</sys:String> <sys:String x:Key="Text.Pull.Title">Pull (Fetch &amp; Merge)</sys:String>

View file

@ -304,6 +304,8 @@
<sys:String x:Key="Text.Welcome.Search">快速查找仓库</sys:String> <sys:String x:Key="Text.Welcome.Search">快速查找仓库</sys:String>
<sys:String x:Key="Text.Welcome.Sort">排序</sys:String> <sys:String x:Key="Text.Welcome.Sort">排序</sys:String>
<sys:String x:Key="Text.Welcome.DragDropTip">支持拖放目录添加</sys:String> <sys:String x:Key="Text.Welcome.DragDropTip">支持拖放目录添加</sys:String>
<sys:String x:Key="Text.Welcome.Rename">修改显示名称</sys:String>
<sys:String x:Key="Text.Welcome.NewName">显示名称 </sys:String>
<sys:String x:Key="Text.Pull">拉回</sys:String> <sys:String x:Key="Text.Pull">拉回</sys:String>
<sys:String x:Key="Text.Pull.Title">拉回(拉取并合并)</sys:String> <sys:String x:Key="Text.Pull.Title">拉回(拉取并合并)</sys:String>

View file

@ -0,0 +1,77 @@
<controls:Window
x:Class="SourceGit.Views.EditRepositoryDisplayName"
x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
mc:Ignorable="d"
Title="{DynamicResource Text.Welcome.Rename}"
WindowStartupLocation="CenterOwner"
ResizeMode="NoResize"
Width="500" SizeToContent="Height">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="28"/>
<RowDefinition Height="1"/>
<RowDefinition Height="*"/>
<RowDefinition Height="48"/>
</Grid.RowDefinitions>
<!-- Title bar -->
<Grid Grid.Row="0" Background="{DynamicResource Brush.TitleBar}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- Icon -->
<Path Grid.Column="0" Margin="6,0" Width="12" Height="12" Data="{StaticResource Icon.Preference}"/>
<!-- Title -->
<TextBlock Grid.Column="1" Text="{DynamicResource Text.Welcome.Rename}"/>
<!-- Close -->
<controls:IconButton
Grid.Column="3"
Click="OnCancel"
Width="28"
IconSize="10"
Icon="{StaticResource Icon.Close}"
HoverBackground="Red"
WindowChrome.IsHitTestVisibleInChrome="True"/>
</Grid>
<Rectangle
Grid.Row="1"
Height="1"
HorizontalAlignment="Stretch"
Fill="{DynamicResource Brush.Border0}"/>
<Grid Grid.Row="2" Margin="16,24,16,8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Margin="0,0,8,0" Text="{DynamicResource Text.Welcome.NewName}"/>
<controls:TextEdit Grid.Column="1" x:Name="txtName" Height="24">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="NewName" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:Required/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
</Grid>
<StackPanel Grid.Row="3" Height="32" Margin="16,0" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
<Button Click="OnSure" Width="80" Content="{DynamicResource Text.Sure}" BorderBrush="{DynamicResource Brush.FG1}" Background="{DynamicResource Brush.Accent1}" FontWeight="Bold"/>
<Button Click="OnCancel" Width="80" Margin="8,0,0,0" Content="{DynamicResource Text.Cancel}" FontWeight="Bold"/>
</StackPanel>
</Grid>
</controls:Window>

View file

@ -0,0 +1,35 @@
using System.Windows;
using System.Windows.Controls;
namespace SourceGit.Views {
/// <summary>
/// 修改仓库显示名称
/// </summary>
public partial class EditRepositoryDisplayName : Controls.Window {
private Models.Repository repository = null;
public string NewName {
get;
set;
}
public EditRepositoryDisplayName(Models.Repository repository) {
this.repository = repository;
NewName = repository.Name;
InitializeComponent();
}
private void OnSure(object s, RoutedEventArgs e) {
txtName.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtName)) return;
repository.Name = NewName;
DialogResult = true;
Close();
}
private void OnCancel(object s, RoutedEventArgs e) {
DialogResult = false;
Close();
}
}
}

View file

@ -105,6 +105,15 @@ namespace SourceGit.Views.Widgets {
Tabs = new ObservableCollection<Tab>(); Tabs = new ObservableCollection<Tab>();
InitializeComponent(); InitializeComponent();
Models.Watcher.DisplayNameChanged += (repoPath, repoName) => {
foreach (var tab in Tabs) {
if (tab.Id == repoPath) {
tab.Title = repoName;
break;
}
}
};
Models.Watcher.BookmarkChanged += (repoPath, bookmark) => { Models.Watcher.BookmarkChanged += (repoPath, bookmark) => {
foreach (var tab in Tabs) { foreach (var tab in Tabs) {
if (tab.Id == repoPath) { if (tab.Id == repoPath) {

View file

@ -133,6 +133,17 @@ namespace SourceGit.Views.Widgets {
menu.Items.Add(open); menu.Items.Add(open);
menu.Items.Add(new Separator()); menu.Items.Add(new Separator());
var rename = new MenuItem();
rename.Header = App.Text("Welcome.Rename");
rename.Click += (o, ev) => {
var dialog = new EditRepositoryDisplayName(repo);
dialog.Owner = App.Current.MainWindow;
if (dialog.ShowDialog() == true) {
UpdateVisibles();
}
};
menu.Items.Add(rename);
var bookmark = new MenuItem(); var bookmark = new MenuItem();
bookmark.Header = App.Text("PageTabBar.Tab.Bookmark"); bookmark.Header = App.Text("PageTabBar.Tab.Bookmark");
for (int i = 0; i < Converters.IntToBookmarkBrush.COLORS.Length; i++) { for (int i = 0; i < Converters.IntToBookmarkBrush.COLORS.Length; i++) {