diff --git a/src/Views/Controls/BindableBase.cs b/src/Views/Controls/BindableBase.cs
new file mode 100644
index 00000000..6570a8fe
--- /dev/null
+++ b/src/Views/Controls/BindableBase.cs
@@ -0,0 +1,54 @@
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
+
+namespace SourceGit.Views.Controls {
+
+ ///
+ /// Implementation of to simplify models.
+ ///
+ public abstract class BindableBase : INotifyPropertyChanged {
+ ///
+ /// Multicast event for property change notifications.
+ ///
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ ///
+ /// Checks if a property already matches a desired value. Sets the property and
+ /// notifies listeners only when necessary.
+ ///
+ /// Type of the property.
+ /// Reference to a property with both getter and setter.
+ /// Desired value for the property.
+ ///
+ /// Name of the property used to notify listeners. This
+ /// value is optional and can be provided automatically when invoked from compilers that
+ /// support CallerMemberName.
+ ///
+ ///
+ /// True if the value was changed, false if the existing value matched the
+ /// desired value.
+ ///
+ protected bool SetProperty(ref T storage, T value, [CallerMemberName] string propertyName = null) {
+ if (Equals(storage, value)) {
+ return false;
+ }
+
+ storage = value;
+ this.OnPropertyChanged(propertyName);
+ return true;
+ }
+
+ ///
+ /// Notifies listeners that a property value has changed.
+ ///
+ ///
+ /// Name of the property used to notify listeners. This
+ /// value is optional and can be provided automatically when invoked from compilers
+ /// that support .
+ ///
+ protected void OnPropertyChanged([CallerMemberName] string propertyName = null) {
+ this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+
+}
diff --git a/src/Views/Widgets/PageTabBar.xaml.cs b/src/Views/Widgets/PageTabBar.xaml.cs
index 0da67004..4eec98e4 100644
--- a/src/Views/Widgets/PageTabBar.xaml.cs
+++ b/src/Views/Widgets/PageTabBar.xaml.cs
@@ -14,12 +14,23 @@ namespace SourceGit.Views.Widgets {
///
/// 标签数据
///
- public class Tab {
+ public class Tab : Controls.BindableBase {
public string Id { get; set; }
public bool IsWelcomePage { get; set; }
- public string Title { get; set; }
+
+ private string title;
+ public string Title {
+ get => title;
+ set => SetProperty(ref title, value);
+ }
+
public string Tooltip { get; set; }
- public int Bookmark { get; set; }
+
+ private int bookmark = 0;
+ public int Bookmark {
+ get => bookmark;
+ set => SetProperty(ref bookmark, value);
+ }
}
///
@@ -123,6 +134,16 @@ namespace SourceGit.Views.Widgets {
if (curTab.Id == id) container.SelectedItem = replaced;
}
+ public void Update(string id, int bookmark, string title) {
+ foreach (var one in Tabs) {
+ if (one.Id == id) {
+ one.Bookmark = bookmark;
+ one.Title = title;
+ break;
+ }
+ }
+ }
+
public bool Goto(string id) {
foreach (var tab in Tabs) {
if (tab.Id == id) {
diff --git a/src/Views/Widgets/Welcome.xaml b/src/Views/Widgets/Welcome.xaml
index efdf954d..cd2a6eeb 100644
--- a/src/Views/Widgets/Welcome.xaml
+++ b/src/Views/Widgets/Welcome.xaml
@@ -127,6 +127,16 @@
+
+
@@ -145,12 +155,6 @@
IsHitTestVisible="True"
Visibility="Collapsed"/>
-
@@ -158,6 +162,10 @@
+
+
+
+
diff --git a/src/Views/Widgets/Welcome.xaml.cs b/src/Views/Widgets/Welcome.xaml.cs
index 4451858f..bd5977aa 100644
--- a/src/Views/Widgets/Welcome.xaml.cs
+++ b/src/Views/Widgets/Welcome.xaml.cs
@@ -15,14 +15,32 @@ namespace SourceGit.Views.Widgets {
///
/// 树节点数据
///
- public class Node {
+ public class Node : Controls.BindableBase {
public string Id { get; set; }
public string ParentId { get; set; }
- public string Name { get; set; }
+
+ private string name;
+ public string Name {
+ get => name;
+ set => SetProperty(ref name, value);
+ }
+
public bool IsGroup { get; set; }
- public bool IsEditing { get; set; }
+
+ private bool isEditing = false;
+ public bool IsEditing {
+ get => isEditing;
+ set => SetProperty(ref isEditing, value);
+ }
+
public bool IsExpanded { get; set; }
- public int Bookmark { get; set; }
+
+ private int bookmark = 0;
+ public int Bookmark {
+ get => bookmark;
+ set => SetProperty(ref bookmark, value);
+ }
+
public List Children { get; set; }
}
@@ -125,7 +143,8 @@ namespace SourceGit.Views.Widgets {
var repo = Models.Preference.Instance.FindRepository(node.Id);
if (repo != null) {
repo.Bookmark = refIdx;
- UpdateTree();
+ node.Bookmark = refIdx;
+ (Application.Current.MainWindow as Launcher)?.tabs.Update(node.Id, refIdx, node.Name);
}
ev.Handled = true;
};
@@ -375,13 +394,14 @@ namespace SourceGit.Views.Widgets {
var node = edit.DataContext as Node;
if (node != null) {
+ node.Name = edit.Text;
+ node.IsEditing = false;
if (node.IsGroup) {
Models.Preference.Instance.RenameGroup(node.Id, edit.Text);
} else {
- Models.Preference.Instance.RenameRepository(node.Id, edit.Text);
+ Models.Preference.Instance.RenameRepository(node.Id, node.Name);
+ (Application.Current.MainWindow as Launcher)?.tabs.Update(node.Id, node.Bookmark, edit.Text);
}
-
- UpdateTree();
e.Handled = false;
}
}