diff --git a/BlueprintExplorer/BlueprintViewer.cs b/BlueprintExplorer/BlueprintViewer.cs index de9a0ce..e8259c2 100644 --- a/BlueprintExplorer/BlueprintViewer.cs +++ b/BlueprintExplorer/BlueprintViewer.cs @@ -120,6 +120,11 @@ public BlueprintViewer() openExternal.Click += (sender, e) => OnOpenExternally?.Invoke(View.Blueprint as BlueprintHandle); this.AddMouseClickRecursively(HandleXbuttons); + + Load += (sender, e) => + { + this.AddKeyDownRecursively((FindForm() as Form1).HandleGlobalKeys); + }; } private void BubblePrints_OnTemplatesChanged(int oldCount, int newCount) diff --git a/BlueprintExplorer/CtrlP.Designer.cs b/BlueprintExplorer/CtrlP.Designer.cs new file mode 100644 index 0000000..e8070fb --- /dev/null +++ b/BlueprintExplorer/CtrlP.Designer.cs @@ -0,0 +1,96 @@ +namespace BlueprintExplorer +{ + partial class CtrlP + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.rootTable = new System.Windows.Forms.TableLayoutPanel(); + this.input = new System.Windows.Forms.TextBox(); + this.root = new System.Windows.Forms.DataGridView(); + this.rootTable.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.root)).BeginInit(); + this.SuspendLayout(); + // + // rootTable + // + this.rootTable.ColumnCount = 1; + this.rootTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.rootTable.Controls.Add(this.input, 0, 0); + this.rootTable.Controls.Add(this.root, 0, 1); + this.rootTable.Dock = System.Windows.Forms.DockStyle.Fill; + this.rootTable.Location = new System.Drawing.Point(0, 0); + this.rootTable.Name = "rootTable"; + this.rootTable.RowCount = 2; + this.rootTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 75F)); + this.rootTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.rootTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.rootTable.Size = new System.Drawing.Size(1719, 664); + this.rootTable.TabIndex = 0; + // + // input + // + this.input.Dock = System.Windows.Forms.DockStyle.Fill; + this.input.Font = new System.Drawing.Font("Segoe UI", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.input.Location = new System.Drawing.Point(3, 3); + this.input.Name = "input"; + this.input.Size = new System.Drawing.Size(1713, 71); + this.input.TabIndex = 1; + // + // root + // + this.root.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.root.Dock = System.Windows.Forms.DockStyle.Fill; + this.root.Location = new System.Drawing.Point(3, 78); + this.root.Name = "root"; + this.root.RowHeadersWidth = 62; + this.root.RowTemplate.Height = 33; + this.root.Size = new System.Drawing.Size(1713, 583); + this.root.TabIndex = 2; + // + // CtrlP + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1719, 664); + this.Controls.Add(this.rootTable); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "CtrlP"; + this.Text = "CtrlP"; + this.rootTable.ResumeLayout(false); + this.rootTable.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.root)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel rootTable; + public System.Windows.Forms.TextBox input; + private System.Windows.Forms.DataGridView root; + } +} \ No newline at end of file diff --git a/BlueprintExplorer/CtrlP.cs b/BlueprintExplorer/CtrlP.cs new file mode 100644 index 0000000..47e6ca9 --- /dev/null +++ b/BlueprintExplorer/CtrlP.cs @@ -0,0 +1,125 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BlueprintExplorer +{ + public partial class CtrlP : Form + { + public CtrlP() + { + InitializeComponent(); + Form1.InstallReadline(input); + input.KeyDown += Input_KeyDown; + root.KeyDown += Input_KeyDown; + input.TextChanged += Input_TextChanged; + + root.ReadOnly = true; + root.Cursor = Cursors.Arrow; + + root.AutoGenerateColumns = false; + root.Columns.Add("Name", "Name"); + root.Columns.Add("Type", "Type"); + root.Columns.Add("Guid", "Guid"); + root.Columns[0].Width = 800; + root.Columns[0].DataPropertyName = "Name"; + root.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + root.Columns[1].Width = 600; + root.Columns[1].DataPropertyName = "Type"; + + root.Columns[2].Width = 450; + root.Columns[2].DataPropertyName = "GuidText"; + + root.RowHeadersVisible = false; + root.ColumnHeadersVisible = false; + root.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + root.MultiSelect = false; + root.AllowUserToResizeRows = false; + + if (Form1.Dark) + { + BubbleTheme.DarkenControls(input, root); + BubbleTheme.DarkenStyles(root.DefaultCellStyle, root.ColumnHeadersDefaultCellStyle); + } + + } + + public Form1 Daddy; + + private void Input_TextChanged(object sender, EventArgs e) + { + if (input.Text.Length > 0) + { + Daddy.InvalidateResults(input.Text); + } + } + + public void SetResults(List results) + { + root.DataSource = results; + int neededHeight = root.Rows.GetRowsHeight(DataGridViewElementStates.None); + if (neededHeight < 640) + { + Height = neededHeight + 82; + } + else + { + Height = 640 + 82; + } + } + + private void Input_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + { + Close(); + } + if (e.KeyCode == Keys.Up || (e.KeyCode == Keys.P && ModifierKeys.HasFlag(Keys.Control))) + { + e.Handled = true; + e.SuppressKeyPress = true; + + int current = root.SelectedRow(); + if (current > 0) + { + root.Rows[current - 1].Selected = true; + } + } + if (e.KeyCode == Keys.Down || (e.KeyCode == Keys.N && ModifierKeys.HasFlag(Keys.Control))) + { + e.Handled = true; + e.SuppressKeyPress = true; + + int current = root.SelectedRow(); + if (current < (root.Rows.Count - 1)) + { + root.Rows[current + 1].Selected = true; + } + } + + if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) + { + + e.Handled = true; + e.SuppressKeyPress = true; + + Daddy.ShowBlueprint(root.SelectedRow()); + + Close(); + } + } + + protected override void OnShown(EventArgs e) + { + base.OnShown(e); + input.Focus(); + } + } +} diff --git a/BlueprintExplorer/CtrlP.resx b/BlueprintExplorer/CtrlP.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BlueprintExplorer/CtrlP.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BlueprintExplorer/Form1.Designer.cs b/BlueprintExplorer/Form1.Designer.cs index 5b5fe8e..9528052 100644 --- a/BlueprintExplorer/Form1.Designer.cs +++ b/BlueprintExplorer/Form1.Designer.cs @@ -35,27 +35,13 @@ private void InitializeComponent() this.controlBar = new System.Windows.Forms.TableLayoutPanel(); this.helpButton = new System.Windows.Forms.Button(); this.settingsButton = new System.Windows.Forms.Button(); - this.omniSearch = new System.Windows.Forms.TextBox(); - this.SearchLabel = new System.Windows.Forms.Label(); this.availableVersions = new System.Windows.Forms.ComboBox(); this.notifications = new System.Windows.Forms.Button(); - this.splitContainer1 = new System.Windows.Forms.SplitContainer(); - this.resultsGrid = new System.Windows.Forms.DataGridView(); - this.BPName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.BPType = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.BPNamespace = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Score = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.BPGuid = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.blueprintDock = new Krypton.Docking.KryptonDockableWorkspace(); this.kDockManager = new Krypton.Docking.KryptonDockingManager(); this.kGlobalManager = new Krypton.Toolkit.KryptonManager(this.components); this.panel1.SuspendLayout(); this.controlBar.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); - this.splitContainer1.Panel1.SuspendLayout(); - this.splitContainer1.Panel2.SuspendLayout(); - this.splitContainer1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.resultsGrid)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.blueprintDock)).BeginInit(); this.SuspendLayout(); // @@ -80,8 +66,6 @@ private void InitializeComponent() this.controlBar.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 64F)); this.controlBar.Controls.Add(this.helpButton, 4, 0); this.controlBar.Controls.Add(this.settingsButton, 3, 0); - this.controlBar.Controls.Add(this.omniSearch, 1, 0); - this.controlBar.Controls.Add(this.SearchLabel, 0, 0); this.controlBar.Controls.Add(this.availableVersions, 2, 0); this.controlBar.Controls.Add(this.notifications, 5, 0); this.controlBar.Dock = System.Windows.Forms.DockStyle.Fill; @@ -113,32 +97,6 @@ private void InitializeComponent() this.settingsButton.Text = "Settings"; this.settingsButton.UseVisualStyleBackColor = true; // - // omniSearch - // - this.omniSearch.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.omniSearch.Dock = System.Windows.Forms.DockStyle.Fill; - this.omniSearch.Font = new System.Drawing.Font("Segoe UI", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.omniSearch.Location = new System.Drawing.Point(192, 8); - this.omniSearch.Margin = new System.Windows.Forms.Padding(9, 8, 9, 8); - this.omniSearch.Name = "omniSearch"; - this.omniSearch.PlaceholderText = "enter search text..."; - this.omniSearch.Size = new System.Drawing.Size(1757, 54); - this.omniSearch.TabIndex = 0; - this.omniSearch.TextChanged += new System.EventHandler(this.omniSearch_TextChanged_1); - this.omniSearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.omniSearch_KeyDown); - // - // SearchLabel - // - this.SearchLabel.AutoSize = true; - this.SearchLabel.Font = new System.Drawing.Font("Segoe UI", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.SearchLabel.Location = new System.Drawing.Point(2, 0); - this.SearchLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); - this.SearchLabel.Name = "SearchLabel"; - this.SearchLabel.Size = new System.Drawing.Size(179, 65); - this.SearchLabel.TabIndex = 1; - this.SearchLabel.Text = "Search:"; - this.SearchLabel.Click += new System.EventHandler(this.label1_Click); - // // availableVersions // this.availableVersions.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -168,93 +126,6 @@ private void InitializeComponent() this.notifications.Text = "1"; this.notifications.UseVisualStyleBackColor = true; // - // splitContainer1 - // - this.splitContainer1.BackColor = System.Drawing.SystemColors.ControlLight; - this.splitContainer1.Cursor = System.Windows.Forms.Cursors.HSplit; - this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer1.Location = new System.Drawing.Point(0, 82); - this.splitContainer1.Name = "splitContainer1"; - this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; - // - // splitContainer1.Panel1 - // - this.splitContainer1.Panel1.Controls.Add(this.resultsGrid); - // - // splitContainer1.Panel2 - // - this.splitContainer1.Panel2.Controls.Add(this.blueprintDock); - this.splitContainer1.Panel2.Cursor = System.Windows.Forms.Cursors.Default; - this.splitContainer1.Size = new System.Drawing.Size(2440, 1166); - this.splitContainer1.SplitterDistance = 297; - this.splitContainer1.SplitterWidth = 16; - this.splitContainer1.TabIndex = 3; - // - // resultsGrid - // - this.resultsGrid.AllowUserToAddRows = false; - this.resultsGrid.AllowUserToDeleteRows = false; - this.resultsGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.resultsGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.BPName, - this.BPType, - this.BPNamespace, - this.Score, - this.BPGuid}); - this.resultsGrid.Dock = System.Windows.Forms.DockStyle.Fill; - this.resultsGrid.Location = new System.Drawing.Point(0, 0); - this.resultsGrid.MultiSelect = false; - this.resultsGrid.Name = "resultsGrid"; - this.resultsGrid.ReadOnly = true; - this.resultsGrid.RowHeadersWidth = 62; - this.resultsGrid.RowTemplate.Height = 33; - this.resultsGrid.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.resultsGrid.Size = new System.Drawing.Size(2440, 297); - this.resultsGrid.TabIndex = 2; - this.resultsGrid.VirtualMode = true; - this.resultsGrid.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.resultsGrid_CellContentClick); - this.resultsGrid.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.dataGridView1_CellValueNeeded); - // - // BPName - // - this.BPName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.BPName.HeaderText = "Name"; - this.BPName.MinimumWidth = 8; - this.BPName.Name = "BPName"; - this.BPName.ReadOnly = true; - // - // BPType - // - this.BPType.HeaderText = "Type"; - this.BPType.MinimumWidth = 8; - this.BPType.Name = "BPType"; - this.BPType.ReadOnly = true; - this.BPType.Width = 600; - // - // BPNamespace - // - this.BPNamespace.HeaderText = "Namespace"; - this.BPNamespace.MinimumWidth = 500; - this.BPNamespace.Name = "BPNamespace"; - this.BPNamespace.ReadOnly = true; - this.BPNamespace.Width = 500; - // - // Score - // - this.Score.HeaderText = "Score"; - this.Score.MinimumWidth = 11; - this.Score.Name = "Score"; - this.Score.ReadOnly = true; - this.Score.Width = 225; - // - // BPGuid - // - this.BPGuid.HeaderText = "Guid"; - this.BPGuid.MinimumWidth = 240; - this.BPGuid.Name = "BPGuid"; - this.BPGuid.ReadOnly = true; - this.BPGuid.Width = 240; - // // blueprintDock // this.blueprintDock.ActivePage = null; @@ -263,7 +134,7 @@ private void InitializeComponent() | Krypton.Workspace.CompactFlags.PromoteLeafs))); this.blueprintDock.ContainerBackStyle = Krypton.Toolkit.PaletteBackStyle.FormCustom1; this.blueprintDock.Dock = System.Windows.Forms.DockStyle.Fill; - this.blueprintDock.Location = new System.Drawing.Point(0, 0); + this.blueprintDock.Location = new System.Drawing.Point(0, 82); this.blueprintDock.Name = "blueprintDock"; // // @@ -272,7 +143,7 @@ private void InitializeComponent() this.blueprintDock.Root.WorkspaceControl = this.blueprintDock; this.blueprintDock.SeparatorStyle = Krypton.Toolkit.SeparatorStyle.LowProfile; this.blueprintDock.ShowMaximizeButton = false; - this.blueprintDock.Size = new System.Drawing.Size(2440, 853); + this.blueprintDock.Size = new System.Drawing.Size(2440, 1166); this.blueprintDock.SplitterWidth = 5; this.blueprintDock.TabIndex = 0; this.blueprintDock.TabStop = true; @@ -291,7 +162,7 @@ private void InitializeComponent() this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.BlueprintFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); this.ClientSize = new System.Drawing.Size(2440, 1248); - this.Controls.Add(this.splitContainer1); + this.Controls.Add(this.blueprintDock); this.Controls.Add(this.panel1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.LinkFont = new System.Drawing.Font("Consolas", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); @@ -299,12 +170,6 @@ private void InitializeComponent() this.Text = "BlueprintDB"; this.panel1.ResumeLayout(false); this.controlBar.ResumeLayout(false); - this.controlBar.PerformLayout(); - this.splitContainer1.Panel1.ResumeLayout(false); - this.splitContainer1.Panel2.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); - this.splitContainer1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.resultsGrid)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.blueprintDock)).EndInit(); this.ResumeLayout(false); @@ -312,16 +177,7 @@ private void InitializeComponent() #endregion private System.Windows.Forms.Panel panel1; - private System.Windows.Forms.SplitContainer splitContainer1; - private System.Windows.Forms.DataGridView resultsGrid; - private System.Windows.Forms.DataGridViewTextBoxColumn BPName; - private System.Windows.Forms.DataGridViewTextBoxColumn BPType; - private System.Windows.Forms.DataGridViewTextBoxColumn BPNamespace; - private System.Windows.Forms.DataGridViewTextBoxColumn Score; - private System.Windows.Forms.DataGridViewTextBoxColumn BPGuid; private System.Windows.Forms.TableLayoutPanel controlBar; - private System.Windows.Forms.TextBox omniSearch; - private System.Windows.Forms.Label SearchLabel; private System.Windows.Forms.Button settingsButton; private System.Windows.Forms.ComboBox availableVersions; private System.Windows.Forms.Button helpButton; diff --git a/BlueprintExplorer/Form1.cs b/BlueprintExplorer/Form1.cs index 6cb304f..56eb9ee 100644 --- a/BlueprintExplorer/Form1.cs +++ b/BlueprintExplorer/Form1.cs @@ -187,6 +187,9 @@ public Form1() } InitializeComponent(); + + + Text = "BubblePrints - " + Application.ProductVersion; Load += (sender, e) => @@ -257,17 +260,10 @@ public Form1() this.AddMouseClickRecursively(HandleXbuttons); - omniSearch.TextChanged += OmniSearch_TextChanged; - resultsGrid.CellClick += ResultsGrid_CellClick; - - - InstallReadline(omniSearch); + this.AddKeyDownRecursively(HandleGlobalKeys); controlBar.ColumnStyles[^1].Width = 0; - Color bgColor = omniSearch.BackColor; - resultsGrid.RowHeadersVisible = false; - availableVersions.Enabled = false; notifications.Click += (sender, evt) => @@ -289,8 +285,6 @@ public Form1() BubblePrints.Wrath = Assembly.LoadFrom(Path.Combine(wrathPath, "Wrath_Data", "Managed", "Assembly-CSharp.dll")); } - resultsGrid.AllowUserToResizeRows = false; - //blueprintViews.DrawMode = TabDrawMode.OwnerDrawFixed; //blueprintViews.DrawItem += (sender, e) => //{ @@ -305,27 +299,18 @@ public Form1() // g.DrawString(title, Font, new SolidBrush(resultsGrid.ForeColor), textBounds); //}; - resultsGrid.Cursor = Cursors.Arrow; if (Dark) { - resultsGrid.EnableHeadersVisualStyles = false; - BubbleTheme.DarkenControls(omniSearch, resultsGrid, splitContainer1, panel1, settingsButton, helpButton); - BubbleTheme.DarkenStyles(resultsGrid.ColumnHeadersDefaultCellStyle, resultsGrid.DefaultCellStyle); - + BubbleTheme.DarkenControls( panel1, settingsButton, helpButton); Invalidate(); } - omniSearch.Enabled = false; - resultsGrid.Enabled = false; - if (SeasonalOverlay.InSeason) { - BubbleTheme.SeasonControls(omniSearch, panel1, settingsButton, resultsGrid, helpButton); - BubbleTheme.SeasonStyles(resultsGrid.ColumnHeadersDefaultCellStyle, resultsGrid.DefaultCellStyle); - SeasonalOverlay.Install(resultsGrid); + BubbleTheme.SeasonControls(panel1, settingsButton, helpButton); } var loadType = BlueprintDB.Instance.GetLoadType(); @@ -344,10 +329,6 @@ public Form1() initialize = Task.Run(() => BlueprintDB.Instance.TryConnect(progress)); initialize.ContinueWith(b => { - omniSearch.Enabled = true; - resultsGrid.Enabled = true; - omniSearch.Text = ""; - omniSearch.Select(); ShowBlueprint(BlueprintDB.Instance.Blueprints.Values.First(), ShowFlags.F_UpdateHistory); foreach (var v in BlueprintDB.Instance.Available) @@ -369,16 +350,16 @@ public Form1() if (Good) return; - if (omniSearch.Visible) - { - omniSearch.Invoke(new Action(() => - { - if (!Good) - { - omniSearch.Text = plane.PadLeft(plane.Length + frame) + $"{progress.Status}"; - } - })); - } + //if (omniSearch.Visible) + //{ + // omniSearch.Invoke(new Action(() => + // { + // if (!Good) + // { + // omniSearch.Text = plane.PadLeft(plane.Length + frame) + $"{progress.Status}"; + // } + // })); + //} Thread.Sleep(33); } } @@ -386,13 +367,33 @@ public Form1() } - - private void HandleXbuttons(object sender, MouseEventArgs e) + public void HandleGlobalKeys(object sender, KeyEventArgs e) { + if (!Good) return; + + if (e.KeyCode == Keys.P && ModifierKeys.HasFlag(Keys.Control)) + { + ctrlP ??= new CtrlP(); + ctrlP.Daddy = this; + ctrlP.StartPosition = FormStartPosition.Manual; + var search = PointToScreen(new Point(1, 1)); + ctrlP.Location = new Point(search.X, search.Y); + ctrlP.Size = new Size(ClientSize.Width - 2, 80); + ctrlP.input.Focus(); + ctrlP.ShowDialog(this); + } //if (e.Button == MouseButtons.XButton1) - // (blueprintViews.SelectedTab.Controls[0] as BlueprintViewer).Navigate(NavigateTo.RelativeBackOne); + // (blueprintDock.ActivePage.Controls[0] as BlueprintViewer).Navigate(NavigateTo.RelativeBackOne); //else if (e.Button == MouseButtons.XButton2) - // (blueprintViews.SelectedTab.Controls[0] as BlueprintViewer).Navigate(NavigateTo.RelativeForwardOne); + // (blueprintDock.ActivePage.Controls[0] as BlueprintViewer).Navigate(NavigateTo.RelativeForwardOne); + } + + private void HandleXbuttons(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.XButton1) + (blueprintDock.ActivePage.Controls[0] as BlueprintViewer).Navigate(NavigateTo.RelativeBackOne); + else if (e.Button == MouseButtons.XButton2) + (blueprintDock.ActivePage.Controls[0] as BlueprintViewer).Navigate(NavigateTo.RelativeForwardOne); } private void ResultsGrid_MouseDown(object sender, MouseEventArgs e) @@ -438,9 +439,9 @@ private void DoOpenInEditor(BlueprintHandle blueprint) Process.Start(editor, args); } - private void ResultsGrid_CellClick(object sender, DataGridViewCellEventArgs e) + public void omniSearch_KeyDown(object sender, KeyEventArgs e) { - ShowSelected(); + } private DateTime lastChange = DateTime.MinValue; @@ -466,20 +467,21 @@ private void SetResults(List results, CancellationTokenSource c lastCompleted = sequenceNumber; resultsCache = results; - var oldRowCount = resultsGrid.Rows.Count; - var newRowCount = resultsCache.Count; - if (newRowCount > oldRowCount) - resultsGrid.Rows.Add(newRowCount - oldRowCount); - else - { - resultsGrid.Rows.Clear(); - if (newRowCount > 0) - resultsGrid.Rows.Add(newRowCount); - } - resultsGrid.Invalidate(); + ctrlP?.SetResults(results); + //var oldRowCount = resultsGrid.Rows.Count; + //var newRowCount = resultsCache.Count; + //if (newRowCount > oldRowCount) + // resultsGrid.Rows.Add(newRowCount - oldRowCount); + //else + //{ + // resultsGrid.Rows.Clear(); + // if (newRowCount > 0) + // resultsGrid.Rows.Add(newRowCount); + //} + //resultsGrid.Invalidate(); } - private void InvalidateResults() + public void InvalidateResults(string searchTerm) { CancellationTokenSource cancellation = new(); @@ -511,12 +513,12 @@ private void InvalidateResults() if (matchBuffer == 1) { - overlappedSearch = db.SearchBlueprintsAsync(Search, cancellation.Token, matchBuffer); + overlappedSearch = db.SearchBlueprintsAsync(searchTerm, cancellation.Token, matchBuffer); search = overlappedSearch; } else { - search = db.SearchBlueprintsAsync(Search, cancellation.Token, matchBuffer); + search = db.SearchBlueprintsAsync(searchTerm, cancellation.Token, matchBuffer); } search.ContinueWith(task => @@ -526,14 +528,8 @@ private void InvalidateResults() }); } - private void OmniSearch_TextChanged(object sender, EventArgs e) - { - if (!Good) - return; - InvalidateResults(); - } - private string Search => omniSearch.Text; + CtrlP ctrlP; public static bool Dark { get => dark; set => dark = value; } @@ -665,65 +661,55 @@ public static void InstallReadline(TextBox box) }; } - private void omniSearch_KeyDown(object sender, KeyEventArgs e) + //private void omniSearch_KeyDown(object sender, KeyEventArgs e) + //{ + // if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter) + // { + // if (resultsCache.Count > 0) + // { + // ShowSelected(); + // } + // } + // else if (e.KeyCode == Keys.Up) + // { + // if (resultsCache.Count > 1) + // { + // int row = resultsGrid.SelectedRow() - 1; + // if (row >= 0 && row < resultsCache.Count) + // { + // resultsGrid.Rows[row].Selected = true; + // resultsGrid.CurrentCell = resultsGrid[0, row]; + // resultsGrid.CurrentCell.ToolTipText = ""; + // } + // } + // e.Handled = true; + // e.SuppressKeyPress = true; + // } + // else if (e.KeyCode == Keys.Down) + // { + // if (resultsCache.Count > 1) + // { + // int row = resultsGrid.SelectedRow() + 1; + // if (row < resultsCache.Count) + // { + // resultsGrid.Rows[row].Selected = true; + // resultsGrid.CurrentCell = resultsGrid[0, row]; + // resultsGrid.CurrentCell.ToolTipText = ""; + // } + // } + // e.Handled = true; + // e.SuppressKeyPress = true; + // } + + //} + + public void ShowBlueprint(int row) { - if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter) - { - if (resultsCache.Count > 0) - { - ShowSelected(); - } - } - else if (e.KeyCode == Keys.Up) - { - if (resultsCache.Count > 1) - { - int row = resultsGrid.SelectedRow() - 1; - if (row >= 0 && row < resultsCache.Count) - { - resultsGrid.Rows[row].Selected = true; - resultsGrid.CurrentCell = resultsGrid[0, row]; - resultsGrid.CurrentCell.ToolTipText = ""; - } - } - e.Handled = true; - e.SuppressKeyPress = true; - } - else if (e.KeyCode == Keys.Down) - { - if (resultsCache.Count > 1) - { - int row = resultsGrid.SelectedRow() + 1; - if (row < resultsCache.Count) - { - resultsGrid.Rows[row].Selected = true; - resultsGrid.CurrentCell = resultsGrid[0, row]; - resultsGrid.CurrentCell.ToolTipText = ""; - } - } - e.Handled = true; - e.SuppressKeyPress = true; - } - - } - - private void ShowSelected() - { - if (TryGetSelected(out var row)) - { + if (row >= 0 && row < resultsCache.Count) ShowBlueprint(resultsCache[row], ShowFlags.F_ClearHistory | ShowFlags.F_UpdateHistory); - } - } - - - private bool TryGetSelected(out int row) - { - row = resultsGrid.SelectedRow(); - return row >= 0 && row < resultsCache.Count; } - private void ShowBlueprint(BlueprintHandle bp, ShowFlags flags) { if (flags.UpdateHistory() && BubblePrints.Settings.AlwaysOpenInEditor) diff --git a/BlueprintExplorer/Form1.resx b/BlueprintExplorer/Form1.resx index d242080..12de360 100644 --- a/BlueprintExplorer/Form1.resx +++ b/BlueprintExplorer/Form1.resx @@ -57,21 +57,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - - - True - - - True - - - True - - - True - 17, 17 diff --git a/BlueprintExplorer/Helpers/Helpers.cs b/BlueprintExplorer/Helpers/Helpers.cs index 4fc47f3..a1e7602 100644 --- a/BlueprintExplorer/Helpers/Helpers.cs +++ b/BlueprintExplorer/Helpers/Helpers.cs @@ -15,7 +15,7 @@ public static string Truncate(this string obj, int length) return obj.Substring(0, Math.Min(length, obj.Length)); } - public static void AddMouseClickRecursively(this Control root, MouseEventHandler handler) + public static void ForEachControl(this Control root, Action act) { Queue frontier = new(); frontier.Enqueue(root); @@ -23,11 +23,16 @@ public static void AddMouseClickRecursively(this Control root, MouseEventHandler while (frontier.Count > 0) { var c = frontier.Dequeue(); - c.MouseClick += handler; + act(c); for (int i = 0; i < c.Controls.Count; i++) frontier.Enqueue(c.Controls[i]); } + + } + + public static void AddMouseClickRecursively(this Control root, MouseEventHandler handler) => ForEachControl(root, c => c.MouseClick += handler); + public static void AddKeyDownRecursively(this Control root, KeyEventHandler handler) => ForEachControl(root, c => c.KeyDown += handler); } }