mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
Merge pull request !22 from Jai/feature/add-tab-menu
This commit is contained in:
commit
26489a28f2
6 changed files with 107 additions and 1 deletions
|
@ -284,6 +284,10 @@
|
||||||
<sys:String x:Key="Text.PageTabBar.New">NEW PAGE</sys:String>
|
<sys:String x:Key="Text.PageTabBar.New">NEW PAGE</sys:String>
|
||||||
<sys:String x:Key="Text.PageTabBar.Welcome.Title">*Repositories</sys:String>
|
<sys:String x:Key="Text.PageTabBar.Welcome.Title">*Repositories</sys:String>
|
||||||
<sys:String x:Key="Text.PageTabBar.Welcome.Tip">WELCOME PAGE</sys:String>
|
<sys:String x:Key="Text.PageTabBar.Welcome.Tip">WELCOME PAGE</sys:String>
|
||||||
|
<sys:String x:Key="Text.PageTabBar.Tab.Close">Close Tab</sys:String>
|
||||||
|
<sys:String x:Key="Text.PageTabBar.Tab.CloseOther">Close Other Tabs</sys:String>
|
||||||
|
<sys:String x:Key="Text.PageTabBar.Tab.CloseRight">Close Tabs to the Right</sys:String>
|
||||||
|
<sys:String x:Key="Text.PageTabBar.Tab.Bookmark">Bookmark</sys:String>
|
||||||
|
|
||||||
<sys:String x:Key="Text.Merge">Merge Branch</sys:String>
|
<sys:String x:Key="Text.Merge">Merge Branch</sys:String>
|
||||||
<sys:String x:Key="Text.Merge.Source">Source Branch :</sys:String>
|
<sys:String x:Key="Text.Merge.Source">Source Branch :</sys:String>
|
||||||
|
|
|
@ -283,6 +283,10 @@
|
||||||
<sys:String x:Key="Text.PageTabBar.New">新建空白页</sys:String>
|
<sys:String x:Key="Text.PageTabBar.New">新建空白页</sys:String>
|
||||||
<sys:String x:Key="Text.PageTabBar.Welcome.Title">新标签页</sys:String>
|
<sys:String x:Key="Text.PageTabBar.Welcome.Title">新标签页</sys:String>
|
||||||
<sys:String x:Key="Text.PageTabBar.Welcome.Tip">起始页</sys:String>
|
<sys:String x:Key="Text.PageTabBar.Welcome.Tip">起始页</sys:String>
|
||||||
|
<sys:String x:Key="Text.PageTabBar.Tab.Close">关闭标签页</sys:String>
|
||||||
|
<sys:String x:Key="Text.PageTabBar.Tab.CloseOther">关闭其他标签页</sys:String>
|
||||||
|
<sys:String x:Key="Text.PageTabBar.Tab.CloseRight">关闭右侧标签页</sys:String>
|
||||||
|
<sys:String x:Key="Text.PageTabBar.Tab.Bookmark">设置书签</sys:String>
|
||||||
|
|
||||||
<sys:String x:Key="Text.Merge">合并分支</sys:String>
|
<sys:String x:Key="Text.Merge">合并分支</sys:String>
|
||||||
<sys:String x:Key="Text.Merge.Source">合并分支 :</sys:String>
|
<sys:String x:Key="Text.Merge.Source">合并分支 :</sys:String>
|
||||||
|
|
|
@ -15,6 +15,14 @@ namespace SourceGit.Views {
|
||||||
Models.Watcher.Opened += OpenRepository;
|
Models.Watcher.Opened += OpenRepository;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
tabs.Add();
|
tabs.Add();
|
||||||
|
|
||||||
|
tabs.OnTabEdited += (t) => {
|
||||||
|
foreach (var tab in tabs.Tabs) {
|
||||||
|
if (!tab.IsWelcomePage) continue;
|
||||||
|
var page = container.Get(tab.Id) as Widgets.Welcome;
|
||||||
|
if (page != null) page.UpdateNodes(t.Id, t.Bookmark);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClosing(object sender, CancelEventArgs e) {
|
private void OnClosing(object sender, CancelEventArgs e) {
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
|
|
||||||
<ListBox.ItemContainerStyle>
|
<ListBox.ItemContainerStyle>
|
||||||
<Style TargetType="{x:Type ListBoxItem}">
|
<Style TargetType="{x:Type ListBoxItem}">
|
||||||
|
<EventSetter Event="ContextMenuOpening" Handler="OnTabContextMenuOpening" />
|
||||||
<Setter Property="AllowDrop" Value="True"/>
|
<Setter Property="AllowDrop" Value="True"/>
|
||||||
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
|
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
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.Views.Widgets {
|
namespace SourceGit.Views.Widgets {
|
||||||
|
|
||||||
|
@ -33,6 +35,11 @@ namespace SourceGit.Views.Widgets {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 仓库标签页编辑事件参数
|
||||||
|
/// </summary>
|
||||||
|
public event Action<Tab> OnTabEdited;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 标签相关事件参数
|
/// 标签相关事件参数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -216,7 +223,10 @@ namespace SourceGit.Views.Widgets {
|
||||||
private void CloseTab(object sender, RoutedEventArgs e) {
|
private void CloseTab(object sender, RoutedEventArgs e) {
|
||||||
var tab = (sender as Button).DataContext as Tab;
|
var tab = (sender as Button).DataContext as Tab;
|
||||||
if (tab == null) return;
|
if (tab == null) return;
|
||||||
|
CloseTab(tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CloseTab(Tab tab) {
|
||||||
var curTab = container.SelectedItem as Tab;
|
var curTab = container.SelectedItem as Tab;
|
||||||
if (curTab != null && tab.Id == curTab.Id) {
|
if (curTab != null && tab.Id == curTab.Id) {
|
||||||
var idx = Tabs.IndexOf(tab);
|
var idx = Tabs.IndexOf(tab);
|
||||||
|
@ -234,7 +244,6 @@ namespace SourceGit.Views.Widgets {
|
||||||
} else {
|
} else {
|
||||||
Tabs.Remove(tab);
|
Tabs.Remove(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
RaiseEvent(new TabEventArgs(TabClosedEvent, this, tab.Id));
|
RaiseEvent(new TabEventArgs(TabClosedEvent, this, tab.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,5 +274,69 @@ namespace SourceGit.Views.Widgets {
|
||||||
container.SelectedItem = tabSrc;
|
container.SelectedItem = tabSrc;
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnTabContextMenuOpening(object sender, ContextMenuEventArgs e) {
|
||||||
|
var tab = (sender as ListBoxItem).DataContext as Tab;
|
||||||
|
if (tab == null) return;
|
||||||
|
|
||||||
|
var menu = new ContextMenu();
|
||||||
|
|
||||||
|
var close = new MenuItem();
|
||||||
|
close.Header = App.Text("PageTabBar.Tab.Close");
|
||||||
|
close.Click += (_, __) => {
|
||||||
|
CloseTab(tab);
|
||||||
|
};
|
||||||
|
|
||||||
|
var closeOther = new MenuItem();
|
||||||
|
closeOther.Header = App.Text("PageTabBar.Tab.CloseOther");
|
||||||
|
closeOther.Click += (_, __) => {
|
||||||
|
Tabs.ToList().ForEach(t => { if (tab != t) CloseTab(t); });
|
||||||
|
};
|
||||||
|
|
||||||
|
var closeRight = new MenuItem();
|
||||||
|
closeRight.Header = App.Text("PageTabBar.Tab.CloseRight");
|
||||||
|
closeRight.Click += (_, __) => {
|
||||||
|
var tabs = Tabs.ToList();
|
||||||
|
tabs.RemoveRange(0, tabs.IndexOf(tab) + 1);
|
||||||
|
tabs.ForEach(t => CloseTab(t));
|
||||||
|
};
|
||||||
|
|
||||||
|
menu.Items.Add(close);
|
||||||
|
menu.Items.Add(closeOther);
|
||||||
|
menu.Items.Add(closeRight);
|
||||||
|
|
||||||
|
if (!tab.IsWelcomePage) {
|
||||||
|
var iconBookmark = FindResource("Icon.Bookmark") as Geometry;
|
||||||
|
var bookmark = new MenuItem();
|
||||||
|
bookmark.Header = App.Text("PageTabBar.Tab.Bookmark");
|
||||||
|
for (int i = 0; i < Controls.Bookmark.COLORS.Length; i++) {
|
||||||
|
var icon = new System.Windows.Shapes.Path();
|
||||||
|
icon.Data = iconBookmark;
|
||||||
|
icon.Fill = Controls.Bookmark.COLORS[i];
|
||||||
|
icon.Width = 8;
|
||||||
|
|
||||||
|
var mark = new MenuItem();
|
||||||
|
mark.Icon = icon;
|
||||||
|
mark.Header = $"{i}";
|
||||||
|
|
||||||
|
var refIdx = i;
|
||||||
|
mark.Click += (o, ev) => {
|
||||||
|
var repo = Models.Preference.Instance.FindRepository(tab.Id);
|
||||||
|
if (repo != null) {
|
||||||
|
repo.Bookmark = refIdx;
|
||||||
|
tab.Bookmark = refIdx;
|
||||||
|
OnTabEdited?.Invoke(tab);
|
||||||
|
}
|
||||||
|
ev.Handled = true;
|
||||||
|
};
|
||||||
|
bookmark.Items.Add(mark);
|
||||||
|
}
|
||||||
|
menu.Items.Add(new Separator());
|
||||||
|
menu.Items.Add(bookmark);
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.IsOpen = true;
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
@ -368,6 +369,21 @@ namespace SourceGit.Views.Widgets {
|
||||||
var repo = Models.Preference.Instance.AddRepository(root, gitDir, "");
|
var repo = Models.Preference.Instance.AddRepository(root, gitDir, "");
|
||||||
Models.Watcher.Open(repo);
|
Models.Watcher.Open(repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateNodes(string id, int bookmark, IEnumerable<Node> nodes = null) {
|
||||||
|
if (nodes == null) nodes = tree.ItemsSource.OfType<Node>();
|
||||||
|
foreach (var node in nodes) {
|
||||||
|
if (!node.IsGroup) {
|
||||||
|
if (node.Id == id) {
|
||||||
|
node.Bookmark = bookmark;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (node.Children.Count > 0) {
|
||||||
|
UpdateNodes(id, bookmark, node.Children);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region RENAME_NODES
|
#region RENAME_NODES
|
||||||
|
|
Loading…
Reference in a new issue