mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
optimize<*>: remove PageTabItem
This commit is contained in:
parent
dbf7b225c6
commit
0377326363
10 changed files with 83 additions and 147 deletions
|
@ -104,17 +104,6 @@ namespace SourceGit.Models {
|
|||
Navigate?.Invoke(commit);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 强制刷新
|
||||
/// </summary>
|
||||
public void Refresh() {
|
||||
updateWC = 1;
|
||||
updateBranch = 1;
|
||||
updateSubmodules = 1;
|
||||
updateStashes = 1;
|
||||
updateTags = 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 仅强制更新本地变化
|
||||
/// </summary>
|
||||
|
|
|
@ -115,6 +115,8 @@
|
|||
<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.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.Tip">Search Commit</sys:String>
|
||||
<sys:String x:Key="Text.Dashboard.Configure.Tip">Configure this repository</sys:String>
|
||||
|
|
|
@ -115,6 +115,8 @@
|
|||
<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.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.Tip">查找提交</sys:String>
|
||||
<sys:String x:Key="Text.Dashboard.Configure.Tip">配置本仓库</sys:String>
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace SourceGit.Views {
|
|||
public Launcher() {
|
||||
Models.Watcher.Opened += OpenRepository;
|
||||
InitializeComponent();
|
||||
OnTabAdding(null, null);
|
||||
tabs.Add();
|
||||
}
|
||||
|
||||
#region OPEN_REPO
|
||||
|
@ -30,15 +30,14 @@ namespace SourceGit.Views {
|
|||
Commands.AutoFetch.Start(repo.Path);
|
||||
|
||||
var page = new Widgets.Dashboard(repo);
|
||||
var tab = new Widgets.PageTabItem(repo.Name, false, repo.Bookmark, repo.Path);
|
||||
container.Add(repo.Path, page);
|
||||
Controls.PopupWidget.RegisterContainer(repo.Path, page);
|
||||
|
||||
var front = container.Get(tabs.Current);
|
||||
if (front == null || front is Widgets.Dashboard) {
|
||||
tabs.Add(repo.Path, tab);
|
||||
tabs.Add(repo.Name, repo.Path, repo.Bookmark);
|
||||
} else {
|
||||
tabs.Replace(tabs.Current, repo.Path, tab);
|
||||
tabs.Replace(tabs.Current, repo.Name, repo.Path, repo.Bookmark);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
@ -72,14 +71,10 @@ namespace SourceGit.Views {
|
|||
#endregion
|
||||
|
||||
#region TAB_OPERATION
|
||||
private void OnTabAdding(object sender, RoutedEventArgs e) {
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var tab = new Widgets.PageTabItem(App.Text("PageSwitcher.Welcome.Title"), true, 0, App.Text("PageSwitcher.Welcome.Tip"));
|
||||
private void OnTabAdding(object sender, Widgets.PageTabBar.TabEventArgs e) {
|
||||
var page = new Widgets.Welcome();
|
||||
|
||||
container.Add(id, page);
|
||||
tabs.Add(id, tab);
|
||||
Controls.PopupWidget.RegisterContainer(id, page);
|
||||
container.Add(e.TabId, page);
|
||||
Controls.PopupWidget.RegisterContainer(e.TabId, page);
|
||||
}
|
||||
|
||||
private void OnTabSelected(object sender, Widgets.PageTabBar.TabEventArgs e) {
|
||||
|
@ -112,7 +107,7 @@ namespace SourceGit.Views {
|
|||
}
|
||||
|
||||
if (Keyboard.IsKeyDown(Key.T)) {
|
||||
OnTabAdding(null, null);
|
||||
tabs.Add();
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
@ -138,7 +133,8 @@ namespace SourceGit.Views {
|
|||
}
|
||||
|
||||
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;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
<TextBlock Margin="4,0" FontFamily="Consolas,Microsoft YaHei UI" FontWeight="Bold" Text="{StaticResource Text.Dashboard.Explore}"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<Button Click="Terminal" Margin="6,0" ToolTip="{StaticResource Text.Dashboard.Terminal.Tip}" BorderThickness="0">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<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}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<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>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
|
|
@ -289,6 +289,15 @@ namespace SourceGit.Views.Widgets {
|
|||
e.Handled = true;
|
||||
}
|
||||
|
||||
public void Refresh(object sender, RoutedEventArgs e) {
|
||||
UpdateBraches();
|
||||
UpdateWorkingCopy();
|
||||
UpdateStashes();
|
||||
UpdateTags();
|
||||
UpdateSubmodules();
|
||||
UpdateSubTrees();
|
||||
}
|
||||
|
||||
private void OpenFetch(object sender, RoutedEventArgs e) {
|
||||
if (repo.Remotes.Count == 0) {
|
||||
Models.Exception.Raise("No remotes added to this repository!!!");
|
||||
|
|
|
@ -54,8 +54,19 @@
|
|||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ListBoxItem}">
|
||||
<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">
|
||||
<ContentPresenter VerticalAlignment="Center" Content="{Binding Control}"/>
|
||||
<StackPanel Margin="8,0" x:Name="Contents" Orientation="Horizontal" VerticalAlignment="Center" Opacity=".5" ToolTip="{Binding Tooltip}">
|
||||
<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
|
||||
Click="CloseTab"
|
||||
|
|
|
@ -16,8 +16,10 @@ namespace SourceGit.Views.Widgets {
|
|||
/// </summary>
|
||||
public class Tab {
|
||||
public string Id { get; set; }
|
||||
public UserControl Control { get; set; }
|
||||
public Tab(string id, UserControl ctrl) { Id = id; Control = ctrl; }
|
||||
public bool IsWelcomePage { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Tooltip { get; set; }
|
||||
public int Bookmark { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -31,7 +33,7 @@ namespace SourceGit.Views.Widgets {
|
|||
public static readonly RoutedEvent TabAddEvent = EventManager.RegisterRoutedEvent(
|
||||
"TabAdd",
|
||||
RoutingStrategy.Bubble,
|
||||
typeof(RoutedEventHandler),
|
||||
typeof(EventHandler<TabEventArgs>),
|
||||
typeof(PageTabBar));
|
||||
|
||||
public event RoutedEventHandler TabAdd {
|
||||
|
@ -75,18 +77,29 @@ namespace SourceGit.Views.Widgets {
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void Add(string id, UserControl element) {
|
||||
var tab = new Tab(id, element);
|
||||
public void Add() {
|
||||
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);
|
||||
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 curTab = container.SelectedItem as Tab;
|
||||
|
||||
foreach (var one in Tabs) {
|
||||
if (one.Id == oldId) {
|
||||
if (one.Id == id) {
|
||||
tab = one;
|
||||
break;
|
||||
}
|
||||
|
@ -98,9 +111,16 @@ namespace SourceGit.Views.Widgets {
|
|||
Tabs.RemoveAt(idx);
|
||||
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);
|
||||
if (curTab.Id == oldId) container.SelectedItem = replaced;
|
||||
if (curTab.Id == id) container.SelectedItem = replaced;
|
||||
}
|
||||
|
||||
public bool Goto(string id) {
|
||||
|
@ -145,7 +165,18 @@ namespace SourceGit.Views.Widgets {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -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>
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue