From 79283f403943ca77c02d62b0aa908f9bb7d499ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=B1=E5=82=91?= Date: Sat, 21 Oct 2023 09:42:00 +0800 Subject: [PATCH] Optimize navigation framework --- .../Forms/FormMain.Designer.cs | 34 ++++-------- Source/GrasscutterTools/Forms/FormMain.cs | 52 ++++++++++++++----- Source/GrasscutterTools/Forms/FormMain.resx | 35 +------------ 3 files changed, 49 insertions(+), 72 deletions(-) diff --git a/Source/GrasscutterTools/Forms/FormMain.Designer.cs b/Source/GrasscutterTools/Forms/FormMain.Designer.cs index c865c5f3..41c3764f 100644 --- a/Source/GrasscutterTools/Forms/FormMain.Designer.cs +++ b/Source/GrasscutterTools/Forms/FormMain.Designer.cs @@ -32,17 +32,15 @@ private void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); this.NavContainer = new System.Windows.Forms.SplitContainer(); this.ListPages = new System.Windows.Forms.ListBox(); - this.TCMain = new System.Windows.Forms.TabControl(); this.CmbCommand = new System.Windows.Forms.ComboBox(); this.BtnCopy = new System.Windows.Forms.Button(); this.ChkAutoCopy = new System.Windows.Forms.CheckBox(); this.GrpCommand = new System.Windows.Forms.GroupBox(); + this.LblClearFilter = new System.Windows.Forms.Label(); this.BtnInvokeOpenCommand = new System.Windows.Forms.Button(); this.MenuSpawnEntityFilter = new System.Windows.Forms.ContextMenuStrip(this.components); - this.LblClearFilter = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.NavContainer)).BeginInit(); this.NavContainer.Panel1.SuspendLayout(); - this.NavContainer.Panel2.SuspendLayout(); this.NavContainer.SuspendLayout(); this.GrpCommand.SuspendLayout(); this.SuspendLayout(); @@ -56,10 +54,6 @@ private void InitializeComponent() // this.NavContainer.Panel1.Controls.Add(this.ListPages); // - // NavContainer.Panel2 - // - this.NavContainer.Panel2.Controls.Add(this.TCMain); - // // ListPages // this.ListPages.BackColor = System.Drawing.Color.WhiteSmoke; @@ -72,14 +66,6 @@ private void InitializeComponent() this.ListPages.SelectedIndexChanged += new System.EventHandler(this.ListPages_SelectedIndexChanged); this.ListPages.SizeChanged += new System.EventHandler(this.ListPages_SizeChanged); // - // TCMain - // - resources.ApplyResources(this.TCMain, "TCMain"); - this.TCMain.Multiline = true; - this.TCMain.Name = "TCMain"; - this.TCMain.SelectedIndex = 0; - this.TCMain.SizeMode = System.Windows.Forms.TabSizeMode.Fixed; - // // CmbCommand // resources.ApplyResources(this.CmbCommand, "CmbCommand"); @@ -113,6 +99,14 @@ private void InitializeComponent() this.GrpCommand.Name = "GrpCommand"; this.GrpCommand.TabStop = false; // + // LblClearFilter + // + resources.ApplyResources(this.LblClearFilter, "LblClearFilter"); + this.LblClearFilter.BackColor = System.Drawing.Color.White; + this.LblClearFilter.Cursor = System.Windows.Forms.Cursors.Hand; + this.LblClearFilter.Name = "LblClearFilter"; + this.LblClearFilter.Click += new System.EventHandler(this.LblClearFilter_Click); + // // BtnInvokeOpenCommand // resources.ApplyResources(this.BtnInvokeOpenCommand, "BtnInvokeOpenCommand"); @@ -125,14 +119,6 @@ private void InitializeComponent() this.MenuSpawnEntityFilter.Name = "MenuSpawnEntityFilter"; resources.ApplyResources(this.MenuSpawnEntityFilter, "MenuSpawnEntityFilter"); // - // LblClearFilter - // - resources.ApplyResources(this.LblClearFilter, "LblClearFilter"); - this.LblClearFilter.BackColor = System.Drawing.Color.White; - this.LblClearFilter.Cursor = System.Windows.Forms.Cursors.Hand; - this.LblClearFilter.Name = "LblClearFilter"; - this.LblClearFilter.Click += new System.EventHandler(this.LblClearFilter_Click); - // // FormMain // resources.ApplyResources(this, "$this"); @@ -145,7 +131,6 @@ private void InitializeComponent() this.Load += new System.EventHandler(this.FormMain_Load); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormMain_KeyDown); this.NavContainer.Panel1.ResumeLayout(false); - this.NavContainer.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.NavContainer)).EndInit(); this.NavContainer.ResumeLayout(false); this.GrpCommand.ResumeLayout(false); @@ -161,7 +146,6 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox ChkAutoCopy; private System.Windows.Forms.GroupBox GrpCommand; private System.Windows.Forms.Button BtnInvokeOpenCommand; - private System.Windows.Forms.TabControl TCMain; private System.Windows.Forms.ContextMenuStrip MenuSpawnEntityFilter; private System.Windows.Forms.ListBox ListPages; private System.Windows.Forms.SplitContainer NavContainer; diff --git a/Source/GrasscutterTools/Forms/FormMain.cs b/Source/GrasscutterTools/Forms/FormMain.cs index 22f9f5f2..d5ac3e94 100644 --- a/Source/GrasscutterTools/Forms/FormMain.cs +++ b/Source/GrasscutterTools/Forms/FormMain.cs @@ -148,6 +148,10 @@ private void FormMain_Load(object sender, EventArgs e) Logger.I(TAG, $"{page.Name} OnLoad completed"); } + // 默认选中首页 + if (ListPages.SelectedIndex == -1) + ListPages.SelectedIndex = 0; + Logger.I(TAG, "FormMain_Load completed"); } @@ -207,7 +211,6 @@ private void InitPages() { Logger.I(TAG, "InitPages enter"); Pages = new Dictionary(32); - TCMain.SuspendLayout(); CreatePage(); var poc = CreatePage(); poc.ShowTipInRunButton = msg => ShowTip(msg, BtnInvokeOpenCommand); @@ -233,7 +236,6 @@ private void InitPages() #if DEBUG CreatePage(); #endif - TCMain.ResumeLayout(); Logger.I(TAG, "InitPages completed"); } @@ -377,7 +379,19 @@ private void ListPages_SelectedIndexChanged(object sender, EventArgs e) .ElementAt(ListPages.SelectedIndex) .Item1; // 通过Key找到页面的父节点也就是TabPage,设置为选中项 - TCMain.SelectedTab = Pages[key].Parent as TabPage; + ShowPage(Pages[key]); + } + + /// + /// 展示页面 + /// + /// 页面实例 + private void ShowPage(BasePage page) + { + NavContainer.Panel2.SuspendLayout(); + NavContainer.Panel2.Controls.Clear(); + NavContainer.Panel2.Controls.Add(page); + NavContainer.Panel2.ResumeLayout(); } /// @@ -422,9 +436,6 @@ private void ListPages_SizeChanged(object sender, EventArgs e) Name = typeof(T).Name, }; Pages.Add(page.Name, page); - var tp = new TabPage(); - TCMain.TabPages.Add(tp); - tp.Controls.Add(page); return page; } @@ -698,13 +709,18 @@ private void FormMain_KeyDown(object sender, KeyEventArgs e) // F5 为执行命令 OnOpenCommandInvoke(); } - else if (e.Alt && e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) + else if ((e.Alt || e.Control) && e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) { - // Alt+数字键 = 跳转到对应页面 + // Alt|Ctrl+数字键 = 跳转到对应页面 var i = e.KeyCode == Keys.D0 ? 9 : e.KeyCode - Keys.D1; if (i < ListPages.Items.Count) ListPages.SelectedIndex = i; } + else if (e.Control && e.KeyCode == Keys.Tab) + { + // 切换到下一个页面 + ListPages.SelectedIndex = (ListPages.SelectedIndex + 1) % ListPages.Items.Count; + } else if (Common.KeyGo.IsEnabled == false) { foreach (var hotkeyItem in Common.KeyGo.Items) @@ -755,13 +771,23 @@ private void ShowTip(string message, Control control) /// 导航到目标页面并返回该页面实例 /// /// 页面类型 - /// 如果导航到了则返回页面实例,否则返回空 public TPage NavigateTo() where TPage : BasePage { - ListPages.SelectedIndex = -1; - var page = Pages[typeof(TPage).Name]; - TCMain.SelectedTab = page.Parent as TabPage; - return page as TPage; + var key = typeof(TPage).Name; + var page = Pages[key] as TPage; + var i = 0; + foreach (var it in PageTabOrders.Where(it => it.Item2)) + { + if (it.Item1 == key) + { + ListPages.SelectedIndex = i; + return page; + } + i++; + } + + ShowPage(page); + return page; } #endregion - 通用 General - diff --git a/Source/GrasscutterTools/Forms/FormMain.resx b/Source/GrasscutterTools/Forms/FormMain.resx index 3803d46a..e250650b 100644 --- a/Source/GrasscutterTools/Forms/FormMain.resx +++ b/Source/GrasscutterTools/Forms/FormMain.resx @@ -133,7 +133,7 @@ - 22 + 25 0, 0 @@ -171,39 +171,6 @@ 80 - - FlatButtons - - - Fill - - - 0, 1 - - - 0, 0 - - - 610, 275 - - - 656, 275 - - - 4 - - - TCMain - - - System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - NavContainer.Panel2 - - - 0 - NavContainer.Panel2