2021-04-29 05:05:55 -07:00
|
|
|
|
using System;
|
2021-07-05 18:58:36 -07:00
|
|
|
|
using System.ComponentModel;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
2022-10-14 00:30:06 -07:00
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Controls.Primitives;
|
2021-06-02 02:46:19 -07:00
|
|
|
|
using System.Windows.Input;
|
2022-10-14 00:30:06 -07:00
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Shapes;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
|
|
|
|
namespace SourceGit.Views {
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 主窗体
|
|
|
|
|
/// </summary>
|
2021-06-17 18:26:19 -07:00
|
|
|
|
public partial class Launcher : Controls.Window {
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
|
|
|
|
public Launcher() {
|
|
|
|
|
Models.Watcher.Opened += OpenRepository;
|
|
|
|
|
InitializeComponent();
|
2021-06-15 02:35:37 -07:00
|
|
|
|
tabs.Add();
|
2021-08-18 17:58:41 -07:00
|
|
|
|
|
|
|
|
|
tabs.OnTabEdited += (t) => {
|
|
|
|
|
foreach (var tab in tabs.Tabs) {
|
2022-10-14 05:38:53 -07:00
|
|
|
|
if (tab.IsRepository) continue;
|
2021-08-18 17:58:41 -07:00
|
|
|
|
var page = container.Get(tab.Id) as Widgets.Welcome;
|
2022-10-14 05:38:53 -07:00
|
|
|
|
if (page != null) page.UpdateVisibles();
|
2021-08-18 17:58:41 -07:00
|
|
|
|
}
|
|
|
|
|
};
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-05 18:58:36 -07:00
|
|
|
|
private void OnClosing(object sender, CancelEventArgs e) {
|
|
|
|
|
var restore = Models.Preference.Instance.Restore;
|
|
|
|
|
if (!restore.IsEnabled) return;
|
|
|
|
|
|
|
|
|
|
restore.Opened.Clear();
|
2021-08-10 23:16:43 -07:00
|
|
|
|
restore.Actived = null;
|
2021-07-05 18:58:36 -07:00
|
|
|
|
|
|
|
|
|
foreach (var tab in tabs.Tabs) {
|
2022-10-14 05:38:53 -07:00
|
|
|
|
if (!tab.IsRepository) continue;
|
2021-07-05 18:58:36 -07:00
|
|
|
|
|
|
|
|
|
// 仅支持恢复加入管理的仓库页,Submodules等未加入管理的不支持
|
|
|
|
|
var repo = Models.Preference.Instance.FindRepository(tab.Id);
|
|
|
|
|
if (repo != null) restore.Opened.Add(tab.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (restore.Opened.Count > 0) {
|
|
|
|
|
if (restore.Opened.IndexOf(tabs.Current) >= 0) {
|
|
|
|
|
restore.Actived = tabs.Current;
|
|
|
|
|
} else {
|
|
|
|
|
restore.Actived = restore.Opened[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Models.Preference.Save();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-29 05:05:55 -07:00
|
|
|
|
#region OPEN_REPO
|
|
|
|
|
private void OpenRepository(Models.Repository repo) {
|
|
|
|
|
if (tabs.Goto(repo.Path)) return;
|
|
|
|
|
|
|
|
|
|
Task.Run(() => {
|
|
|
|
|
var cmd = new Commands.Config(repo.Path);
|
|
|
|
|
repo.GitFlow.Feature = cmd.Get("gitflow.prefix.feature");
|
|
|
|
|
repo.GitFlow.Release = cmd.Get("gitflow.prefix.release");
|
|
|
|
|
repo.GitFlow.Hotfix = cmd.Get("gitflow.prefix.hotfix");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Commands.AutoFetch.Start(repo.Path);
|
|
|
|
|
|
|
|
|
|
var page = new Widgets.Dashboard(repo);
|
|
|
|
|
container.Add(repo.Path, page);
|
|
|
|
|
Controls.PopupWidget.RegisterContainer(repo.Path, page);
|
|
|
|
|
|
|
|
|
|
var front = container.Get(tabs.Current);
|
|
|
|
|
if (front == null || front is Widgets.Dashboard) {
|
2021-06-15 02:35:37 -07:00
|
|
|
|
tabs.Add(repo.Name, repo.Path, repo.Bookmark);
|
2021-04-29 05:05:55 -07:00
|
|
|
|
} else {
|
2021-06-15 02:35:37 -07:00
|
|
|
|
tabs.Replace(tabs.Current, repo.Name, repo.Path, repo.Bookmark);
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2022-10-14 00:30:06 -07:00
|
|
|
|
#region OPERATIONS
|
|
|
|
|
private void FillMenu(ContextMenu menu, string icon, string header, RoutedEventHandler onClick) {
|
|
|
|
|
var iconMode = new Path();
|
|
|
|
|
iconMode.Width = 12;
|
|
|
|
|
iconMode.Height = 12;
|
|
|
|
|
iconMode.Data = FindResource(icon) as Geometry;
|
2022-10-14 05:49:02 -07:00
|
|
|
|
iconMode.SetResourceReference(Path.FillProperty, "Brush.FG1");
|
2022-10-14 00:30:06 -07:00
|
|
|
|
|
|
|
|
|
var item = new MenuItem();
|
|
|
|
|
item.Icon = iconMode;
|
|
|
|
|
item.Header = App.Text(header);
|
|
|
|
|
item.Click += onClick;
|
|
|
|
|
|
|
|
|
|
menu.Items.Add(item);
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-14 00:30:06 -07:00
|
|
|
|
private void ToggleMainMenu(object sender, RoutedEventArgs e) {
|
|
|
|
|
var btn = (sender as Button);
|
|
|
|
|
if (btn.ContextMenu != null) {
|
|
|
|
|
btn.ContextMenu.IsOpen = true;
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var menu = new ContextMenu();
|
|
|
|
|
menu.Placement = PlacementMode.Bottom;
|
|
|
|
|
menu.PlacementTarget = btn;
|
|
|
|
|
menu.StaysOpen = false;
|
|
|
|
|
menu.Focusable = true;
|
|
|
|
|
|
|
|
|
|
FillMenu(menu, "Icon.Preference", "Preference", (o, ev) => {
|
|
|
|
|
var dialog = new Preference() { Owner = this };
|
|
|
|
|
dialog.ShowDialog();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
FillMenu(menu, "Icon.Help", "About", (o, ev) => {
|
|
|
|
|
var dialog = new About() { Owner = this };
|
|
|
|
|
dialog.ShowDialog();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
btn.ContextMenu = menu;
|
|
|
|
|
btn.ContextMenu.IsOpen = true;
|
|
|
|
|
e.Handled = true;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Minimize(object sender, RoutedEventArgs e) {
|
|
|
|
|
SystemCommands.MinimizeWindow(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Quit(object sender, RoutedEventArgs e) {
|
|
|
|
|
Application.Current.Shutdown();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region TAB_OPERATION
|
2021-06-15 02:35:37 -07:00
|
|
|
|
private void OnTabAdding(object sender, Widgets.PageTabBar.TabEventArgs e) {
|
2021-04-29 05:05:55 -07:00
|
|
|
|
var page = new Widgets.Welcome();
|
2022-10-14 05:38:53 -07:00
|
|
|
|
page.OnBookmarkChanged += repo => tabs.Update(repo.Path, repo.Bookmark, repo.Name);
|
2021-06-15 02:35:37 -07:00
|
|
|
|
container.Add(e.TabId, page);
|
|
|
|
|
Controls.PopupWidget.RegisterContainer(e.TabId, page);
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTabSelected(object sender, Widgets.PageTabBar.TabEventArgs e) {
|
|
|
|
|
container.Goto(e.TabId);
|
|
|
|
|
Controls.PopupWidget.SetCurrentContainer(e.TabId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTabClosed(object sender, Widgets.PageTabBar.TabEventArgs e) {
|
2021-05-30 22:55:10 -07:00
|
|
|
|
Controls.PopupWidget.UnregisterContainer(e.TabId);
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Models.Watcher.Close(e.TabId);
|
|
|
|
|
Commands.AutoFetch.Stop(e.TabId);
|
|
|
|
|
container.Remove(e.TabId);
|
2021-05-30 22:55:10 -07:00
|
|
|
|
GC.Collect();
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
2021-06-02 02:46:19 -07:00
|
|
|
|
|
|
|
|
|
#region HOTKEYS
|
|
|
|
|
protected override void OnPreviewKeyDown(KeyEventArgs e) {
|
|
|
|
|
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) {
|
|
|
|
|
if (Keyboard.IsKeyDown(Key.Tab)) {
|
|
|
|
|
tabs.Next();
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Keyboard.IsKeyDown(Key.W)) {
|
|
|
|
|
tabs.CloseCurrent();
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Keyboard.IsKeyDown(Key.T)) {
|
2021-06-15 02:35:37 -07:00
|
|
|
|
tabs.Add();
|
2021-06-02 02:46:19 -07:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Keyboard.IsKeyDown(Key.F)) {
|
|
|
|
|
var dashboard = container.Get(tabs.Current) as Widgets.Dashboard;
|
|
|
|
|
if (dashboard != null) {
|
|
|
|
|
dashboard.OpenSearch(null, null);
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-02 03:06:21 -07:00
|
|
|
|
for (int i = 0; i < 9; i++) {
|
|
|
|
|
if (Keyboard.IsKeyDown(Key.D1 + i) || Keyboard.IsKeyDown(Key.NumPad1 + i)) {
|
2021-06-02 02:46:19 -07:00
|
|
|
|
if (tabs.Tabs.Count > i) {
|
|
|
|
|
tabs.Goto(tabs.Tabs[i].Id);
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Keyboard.IsKeyDown(Key.F5)) {
|
2021-06-15 02:35:37 -07:00
|
|
|
|
var dashboard = container.Get(tabs.Current) as Widgets.Dashboard;
|
2021-06-17 18:31:13 -07:00
|
|
|
|
if (dashboard != null) dashboard.Refresh();
|
2021-06-02 02:46:19 -07:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-09-17 03:00:18 -07:00
|
|
|
|
|
|
|
|
|
if (Keyboard.IsKeyDown(Key.Escape)) {
|
|
|
|
|
var page = container.Get(tabs.Current);
|
|
|
|
|
|
|
|
|
|
var popup = null as Widgets.PopupPanel;
|
|
|
|
|
if (page is Widgets.Dashboard) {
|
|
|
|
|
popup = (page as Widgets.Dashboard).popup;
|
|
|
|
|
} else if (page is Widgets.Welcome) {
|
|
|
|
|
popup = (page as Widgets.Welcome).popup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
popup?.CancelDirectly();
|
|
|
|
|
}
|
2021-06-02 02:46:19 -07:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
}
|