optimize<*>: remove PageTabItem

This commit is contained in:
leo 2021-06-15 17:35:37 +08:00
parent dbf7b225c6
commit 0377326363
10 changed files with 83 additions and 147 deletions

View file

@ -104,17 +104,6 @@ namespace SourceGit.Models {
Navigate?.Invoke(commit); Navigate?.Invoke(commit);
} }
/// <summary>
/// 强制刷新
/// </summary>
public void Refresh() {
updateWC = 1;
updateBranch = 1;
updateSubmodules = 1;
updateStashes = 1;
updateTags = 1;
}
/// <summary> /// <summary>
/// 仅强制更新本地变化 /// 仅强制更新本地变化
/// </summary> /// </summary>

View file

@ -115,6 +115,8 @@
<sys:String x:Key="Text.Dashboard.Explore.Tip">Open In File Browser</sys:String> <sys:String x:Key="Text.Dashboard.Explore.Tip">Open In File Browser</sys:String>
<sys:String x:Key="Text.Dashboard.Terminal">Terminal</sys:String> <sys:String x:Key="Text.Dashboard.Terminal">Terminal</sys:String>
<sys:String x:Key="Text.Dashboard.Terminal.Tip">Open Git Bash</sys:String> <sys:String x:Key="Text.Dashboard.Terminal.Tip">Open Git Bash</sys:String>
<sys:String x:Key="Text.Dashboard.Refresh">Refresh</sys:String>
<sys:String x:Key="Text.Dashboard.Refresh.Tip">Refresh Repositoy</sys:String>
<sys:String x:Key="Text.Dashboard.Search">Search</sys:String> <sys:String x:Key="Text.Dashboard.Search">Search</sys:String>
<sys:String x:Key="Text.Dashboard.Search.Tip">Search Commit</sys:String> <sys:String x:Key="Text.Dashboard.Search.Tip">Search Commit</sys:String>
<sys:String x:Key="Text.Dashboard.Configure.Tip">Configure this repository</sys:String> <sys:String x:Key="Text.Dashboard.Configure.Tip">Configure this repository</sys:String>

View file

@ -115,6 +115,8 @@
<sys:String x:Key="Text.Dashboard.Explore.Tip">在文件浏览器中打开</sys:String> <sys:String x:Key="Text.Dashboard.Explore.Tip">在文件浏览器中打开</sys:String>
<sys:String x:Key="Text.Dashboard.Terminal">终端</sys:String> <sys:String x:Key="Text.Dashboard.Terminal">终端</sys:String>
<sys:String x:Key="Text.Dashboard.Terminal.Tip">打开GIT终端</sys:String> <sys:String x:Key="Text.Dashboard.Terminal.Tip">打开GIT终端</sys:String>
<sys:String x:Key="Text.Dashboard.Refresh">刷新</sys:String>
<sys:String x:Key="Text.Dashboard.Refresh.Tip">刷新仓库数据</sys:String>
<sys:String x:Key="Text.Dashboard.Search">查找</sys:String> <sys:String x:Key="Text.Dashboard.Search">查找</sys:String>
<sys:String x:Key="Text.Dashboard.Search.Tip">查找提交</sys:String> <sys:String x:Key="Text.Dashboard.Search.Tip">查找提交</sys:String>
<sys:String x:Key="Text.Dashboard.Configure.Tip">配置本仓库</sys:String> <sys:String x:Key="Text.Dashboard.Configure.Tip">配置本仓库</sys:String>

View file

@ -13,7 +13,7 @@ namespace SourceGit.Views {
public Launcher() { public Launcher() {
Models.Watcher.Opened += OpenRepository; Models.Watcher.Opened += OpenRepository;
InitializeComponent(); InitializeComponent();
OnTabAdding(null, null); tabs.Add();
} }
#region OPEN_REPO #region OPEN_REPO
@ -30,15 +30,14 @@ namespace SourceGit.Views {
Commands.AutoFetch.Start(repo.Path); Commands.AutoFetch.Start(repo.Path);
var page = new Widgets.Dashboard(repo); var page = new Widgets.Dashboard(repo);
var tab = new Widgets.PageTabItem(repo.Name, false, repo.Bookmark, repo.Path);
container.Add(repo.Path, page); container.Add(repo.Path, page);
Controls.PopupWidget.RegisterContainer(repo.Path, page); Controls.PopupWidget.RegisterContainer(repo.Path, page);
var front = container.Get(tabs.Current); var front = container.Get(tabs.Current);
if (front == null || front is Widgets.Dashboard) { if (front == null || front is Widgets.Dashboard) {
tabs.Add(repo.Path, tab); tabs.Add(repo.Name, repo.Path, repo.Bookmark);
} else { } else {
tabs.Replace(tabs.Current, repo.Path, tab); tabs.Replace(tabs.Current, repo.Name, repo.Path, repo.Bookmark);
} }
} }
#endregion #endregion
@ -72,14 +71,10 @@ namespace SourceGit.Views {
#endregion #endregion
#region TAB_OPERATION #region TAB_OPERATION
private void OnTabAdding(object sender, RoutedEventArgs e) { private void OnTabAdding(object sender, Widgets.PageTabBar.TabEventArgs e) {
var id = Guid.NewGuid().ToString();
var tab = new Widgets.PageTabItem(App.Text("PageSwitcher.Welcome.Title"), true, 0, App.Text("PageSwitcher.Welcome.Tip"));
var page = new Widgets.Welcome(); var page = new Widgets.Welcome();
container.Add(e.TabId, page);
container.Add(id, page); Controls.PopupWidget.RegisterContainer(e.TabId, page);
tabs.Add(id, tab);
Controls.PopupWidget.RegisterContainer(id, page);
} }
private void OnTabSelected(object sender, Widgets.PageTabBar.TabEventArgs e) { private void OnTabSelected(object sender, Widgets.PageTabBar.TabEventArgs e) {
@ -112,7 +107,7 @@ namespace SourceGit.Views {
} }
if (Keyboard.IsKeyDown(Key.T)) { if (Keyboard.IsKeyDown(Key.T)) {
OnTabAdding(null, null); tabs.Add();
e.Handled = true; e.Handled = true;
return; return;
} }
@ -138,7 +133,8 @@ namespace SourceGit.Views {
} }
if (Keyboard.IsKeyDown(Key.F5)) { if (Keyboard.IsKeyDown(Key.F5)) {
Models.Watcher.Get(tabs.Current)?.Refresh(); var dashboard = container.Get(tabs.Current) as Widgets.Dashboard;
if (dashboard != null) dashboard.Refresh(null, null);
e.Handled = true; e.Handled = true;
return; return;
} }

View file

@ -30,7 +30,6 @@
<TextBlock Margin="4,0" FontFamily="Consolas,Microsoft YaHei UI" FontWeight="Bold" Text="{StaticResource Text.Dashboard.Explore}"/> <TextBlock Margin="4,0" FontFamily="Consolas,Microsoft YaHei UI" FontWeight="Bold" Text="{StaticResource Text.Dashboard.Explore}"/>
</StackPanel> </StackPanel>
</Button> </Button>
<Button Click="Terminal" Margin="6,0" ToolTip="{StaticResource Text.Dashboard.Terminal.Tip}" BorderThickness="0"> <Button Click="Terminal" Margin="6,0" ToolTip="{StaticResource Text.Dashboard.Terminal.Tip}" BorderThickness="0">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Path Width="13" Height="13" Data="{StaticResource Icon.Terminal}"/> <Path Width="13" Height="13" Data="{StaticResource Icon.Terminal}"/>
@ -82,7 +81,13 @@
<Button Click="OpenConfigure" Margin="6,0" BorderThickness="0" ToolTip="{StaticResource Text.Dashboard.Configure.Tip}"> <Button Click="OpenConfigure" Margin="6,0" BorderThickness="0" ToolTip="{StaticResource Text.Dashboard.Configure.Tip}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Path Width="14" Height="14" Data="{StaticResource Icon.Setting}"/> <Path Width="14" Height="14" Data="{StaticResource Icon.Setting}"/>
<TextBlock Margin="4,0" FontFamily="Consolas,Microsoft YaHei UI" FontWeight="Bold" Text="{StaticResource Text.Configure}"/> <TextBlock Margin="4,0,0,0" FontFamily="Consolas,Microsoft YaHei UI" FontWeight="Bold" Text="{StaticResource Text.Configure}"/>
</StackPanel>
</Button>
<Button Click="Refresh" Margin="6,0" BorderThickness="0" ToolTip="{StaticResource Text.Dashboard.Refresh.Tip}">
<StackPanel Orientation="Horizontal">
<Path Width="13" Height="13" Data="{StaticResource Icon.Loading}"/>
<TextBlock Margin="4,0" FontFamily="Consolas,Microsoft YaHei UI" FontWeight="Bold" Text="{StaticResource Text.Dashboard.Refresh}"/>
</StackPanel> </StackPanel>
</Button> </Button>
</StackPanel> </StackPanel>

View file

@ -289,6 +289,15 @@ namespace SourceGit.Views.Widgets {
e.Handled = true; e.Handled = true;
} }
public void Refresh(object sender, RoutedEventArgs e) {
UpdateBraches();
UpdateWorkingCopy();
UpdateStashes();
UpdateTags();
UpdateSubmodules();
UpdateSubTrees();
}
private void OpenFetch(object sender, RoutedEventArgs e) { private void OpenFetch(object sender, RoutedEventArgs e) {
if (repo.Remotes.Count == 0) { if (repo.Remotes.Count == 0) {
Models.Exception.Raise("No remotes added to this repository!!!"); Models.Exception.Raise("No remotes added to this repository!!!");

View file

@ -54,8 +54,19 @@
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}"> <ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="Border" Background="Transparent" BorderBrush="{StaticResource Brush.Border0}" BorderThickness="0,0,1,0"> <Border x:Name="Border" Background="Transparent" BorderBrush="{StaticResource Brush.Border0}" BorderThickness="0,0,1,0">
<StackPanel Margin="8,0" x:Name="Contents" Orientation="Horizontal" Opacity=".5"> <StackPanel Margin="8,0" x:Name="Contents" Orientation="Horizontal" VerticalAlignment="Center" Opacity=".5" ToolTip="{Binding Tooltip}">
<ContentPresenter VerticalAlignment="Center" Content="{Binding Control}"/> <controls:Bookmark
Width="14" Height="14"
IsNewPage="{Binding IsWelcomePage}"
Color="{Binding Bookmark}"
HideOnZero="False"/>
<TextBlock
Grid.Column="1"
Margin="4,0"
FontFamily="Consolas"
FontWeight="Bold"
Text="{Binding Title}"/>
<controls:IconButton <controls:IconButton
Click="CloseTab" Click="CloseTab"

View file

@ -16,8 +16,10 @@ namespace SourceGit.Views.Widgets {
/// </summary> /// </summary>
public class Tab { public class Tab {
public string Id { get; set; } public string Id { get; set; }
public UserControl Control { get; set; } public bool IsWelcomePage { get; set; }
public Tab(string id, UserControl ctrl) { Id = id; Control = ctrl; } public string Title { get; set; }
public string Tooltip { get; set; }
public int Bookmark { get; set; }
} }
/// <summary> /// <summary>
@ -31,7 +33,7 @@ namespace SourceGit.Views.Widgets {
public static readonly RoutedEvent TabAddEvent = EventManager.RegisterRoutedEvent( public static readonly RoutedEvent TabAddEvent = EventManager.RegisterRoutedEvent(
"TabAdd", "TabAdd",
RoutingStrategy.Bubble, RoutingStrategy.Bubble,
typeof(RoutedEventHandler), typeof(EventHandler<TabEventArgs>),
typeof(PageTabBar)); typeof(PageTabBar));
public event RoutedEventHandler TabAdd { public event RoutedEventHandler TabAdd {
@ -75,18 +77,29 @@ namespace SourceGit.Views.Widgets {
InitializeComponent(); InitializeComponent();
} }
public void Add(string id, UserControl element) { public void Add() {
var tab = new Tab(id, element); NewTab(null, null);
}
public void Add(string title, string repo, int bookmark) {
var tab = new Tab() {
Id = repo,
IsWelcomePage = false,
Title = title,
Tooltip = repo,
Bookmark = bookmark,
};
Tabs.Add(tab); Tabs.Add(tab);
container.SelectedItem = tab; container.SelectedItem = tab;
} }
public void Replace(string oldId, string newId, UserControl element) { public void Replace(string id, string title, string repo, int bookmark) {
var tab = null as Tab; var tab = null as Tab;
var curTab = container.SelectedItem as Tab; var curTab = container.SelectedItem as Tab;
foreach (var one in Tabs) { foreach (var one in Tabs) {
if (one.Id == oldId) { if (one.Id == id) {
tab = one; tab = one;
break; break;
} }
@ -98,9 +111,16 @@ namespace SourceGit.Views.Widgets {
Tabs.RemoveAt(idx); Tabs.RemoveAt(idx);
RaiseEvent(new TabEventArgs(TabClosedEvent, this, tab.Id)); RaiseEvent(new TabEventArgs(TabClosedEvent, this, tab.Id));
var replaced = new Tab(newId, element); var replaced = new Tab() {
Id = repo,
IsWelcomePage = false,
Title = title,
Tooltip = repo,
Bookmark = bookmark,
};
Tabs.Insert(idx, replaced); Tabs.Insert(idx, replaced);
if (curTab.Id == oldId) container.SelectedItem = replaced; if (curTab.Id == id) container.SelectedItem = replaced;
} }
public bool Goto(string id) { public bool Goto(string id) {
@ -145,7 +165,18 @@ namespace SourceGit.Views.Widgets {
} }
private void NewTab(object sender, RoutedEventArgs e) { private void NewTab(object sender, RoutedEventArgs e) {
RaiseEvent(new RoutedEventArgs(TabAddEvent)); var id = Guid.NewGuid().ToString();
var tab = new Tab() {
Id = id,
IsWelcomePage = true,
Title = App.Text("PageSwitcher.Welcome.Title"),
Tooltip = App.Text("PageSwitcher.Welcome.Tip"),
Bookmark = 0,
};
Tabs.Add(tab);
RaiseEvent(new TabEventArgs(TabAddEvent, this, id));
container.SelectedItem = tab;
} }
private void ScrollLeft(object sender, RoutedEventArgs e) { private void ScrollLeft(object sender, RoutedEventArgs e) {

View file

@ -1,31 +0,0 @@
<UserControl x:Class="SourceGit.Views.Widgets.PageTabItem"
x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<StackPanel
Background="Transparent"
Orientation="Horizontal"
ToolTip="{Binding Tip, ElementName=me}"
ContextMenuOpening="OnContextMenuOpening">
<controls:Bookmark
Grid.Column="0"
x:Name="ctrlBookmark"
Width="14" Height="14"
IsNewPage="{Binding IsWelcomePage, ElementName=me}"
Color="{Binding Bookmark, ElementName=me}"
HideOnZero="False"/>
<TextBlock
Grid.Column="1"
Margin="4,0"
FontFamily="Consolas"
FontWeight="Bold"
Text="{Binding Title, ElementName=me}"/>
</StackPanel>
</UserControl>

View file

@ -1,78 +0,0 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace SourceGit.Views.Widgets {
/// <summary>
/// 主界面标题栏中的页面标签
/// </summary>
public partial class PageTabItem : UserControl {
public string Title { get; private set; }
public bool IsWelcomePage { get; private set; }
public int Bookmark { get; private set; }
public string Tip { get; private set; }
public PageTabItem(string title, bool isWelcomePage, int bookmark, string tip) {
Title = title;
IsWelcomePage = isWelcomePage;
Bookmark = bookmark;
Tip = tip;
InitializeComponent();
}
private void OnContextMenuOpening(object sender, ContextMenuEventArgs ev) {
if (IsWelcomePage) return;
var refresh = new MenuItem();
refresh.Header = App.Text("RepoCM.Refresh");
refresh.Click += (o, e) => {
Models.Watcher.Get(Tip)?.Refresh();
e.Handled = true;
};
var iconBookmark = FindResource("Icon.Bookmark") as Geometry;
var bookmark = new MenuItem();
bookmark.Header = App.Text("RepoCM.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, e) => {
var repo = Models.Preference.Instance.FindRepository(Tip);
if (repo == null) return;
repo.Bookmark = refIdx;
Bookmark = refIdx;
ctrlBookmark.GetBindingExpression(Controls.Bookmark.ColorProperty).UpdateTarget();
e.Handled = true;
};
bookmark.Items.Add(mark);
}
var copyPath = new MenuItem();
copyPath.Header = App.Text("RepoCM.CopyPath");
copyPath.Click += (o, e) => {
Clipboard.SetText(Tip);
e.Handled = true;
};
var menu = new ContextMenu();
menu.Items.Add(refresh);
menu.Items.Add(bookmark);
menu.Items.Add(copyPath);
menu.IsOpen = true;
ev.Handled = true;
}
}
}