From 0a59cdcd281c9ac8e62ad0c4671d8be83634bfd5 Mon Sep 17 00:00:00 2001 From: factubsio <65080026+factubsio@users.noreply.github.com> Date: Sat, 19 Mar 2022 16:15:38 +0000 Subject: [PATCH] navigation and !bp_ --- BlueprintExplorer/BlueprintControl.cs | 35 +++++++++++++++++ BlueprintExplorer/BlueprintDB.cs | 12 +++++- BlueprintExplorer/BlueprintViewer.cs | 38 ++++++++++++++++++ BlueprintExplorer/Form1.cs | 53 ++++++++++++++++++++++---- BlueprintExplorer/Helpers/Helpers.cs | 14 +++++++ BlueprintExplorer/MatchQuery.cs | 9 +++++ BlueprintExplorer/help.rtf | Bin 4368 -> 5206 bytes 7 files changed, 151 insertions(+), 10 deletions(-) diff --git a/BlueprintExplorer/BlueprintControl.cs b/BlueprintExplorer/BlueprintControl.cs index acfbfd9..3b9b8f0 100644 --- a/BlueprintExplorer/BlueprintControl.cs +++ b/BlueprintExplorer/BlueprintControl.cs @@ -15,7 +15,9 @@ public class BlueprintControl : ScrollableControl public delegate void LinkClickedDelegate(string link, bool newTab); public delegate void PathDelegate(string path); public delegate void FilterChangedDelegate(string filter); + public delegate void NavigateDelegate(NavigateTo to); + public event NavigateDelegate OnNavigate; public event LinkClickedDelegate OnLinkClicked; public event PathDelegate OnPathHovered; public event FilterChangedDelegate OnFilterChanged; @@ -676,6 +678,17 @@ protected override void OnMouseDoubleClick(MouseEventArgs e) Toggle(elem); } } + protected override void OnMouseDown(MouseEventArgs e) + { + if (e.Button == MouseButtons.XButton1) + { + OnNavigate?.Invoke(NavigateTo.RelativeBackOne); + } + else if (e.Button == MouseButtons.XButton2) + { + OnNavigate?.Invoke(NavigateTo.RelativeForwardOne); + } + } protected override void OnMouseClick(MouseEventArgs e) { @@ -691,12 +704,27 @@ protected override void OnMouseClick(MouseEventArgs e) OnLinkClicked?.Invoke(elem.link, ModifierKeys.HasFlag(Keys.Control)); } } + else if (e.Button == MouseButtons.Middle && valid && elem.HasLink) + { + OnLinkClicked?.Invoke(elem.link, true); + } else if (e.Button == MouseButtons.Right && valid) { string value = elem.value; value ??= elem.ValueStyled?.Raw; + bool jbpCompatible = ModifierKeys.HasFlag(Keys.Shift); + + if (elem.HasLink) + { value = elem.link; + if (jbpCompatible) + value = "!bp_" + value; + } + + if (jbpCompatible && elem.key == "Blueprint ID") { + value = "!bp_" + value; + } if (string.IsNullOrWhiteSpace(value)) return; Clipboard.SetText(value); @@ -850,4 +878,11 @@ public class DrawParams public Graphics Graphics; } } + public enum NavigateTo + { + RelativeBackOne, + RelativeForwardOne, + AbsoluteFirst, + AbsoluteLast, + } } diff --git a/BlueprintExplorer/BlueprintDB.cs b/BlueprintExplorer/BlueprintDB.cs index 9fcdba1..5d3ecbd 100644 --- a/BlueprintExplorer/BlueprintDB.cs +++ b/BlueprintExplorer/BlueprintDB.cs @@ -701,8 +701,16 @@ public List SearchBlueprints(string searchText, int matchBuffer Console.WriteLine($" after: {toSearch.Count}"); break; case '!': - string[] path = special.Split('/', StringSplitOptions.RemoveEmptyEntries); - toSearch = toSearch.Where(b => EntryIsNotNull(b, path)).ToList(); + if (special.StartsWith("bp_")) + { + + toSearch = toSearch.Where(b => b.GuidText.Contains(special.Substring(3), StringComparison.OrdinalIgnoreCase)).ToList(); + } + else + { + //string[] path = special.Split('/', StringSplitOptions.RemoveEmptyEntries); + //toSearch = toSearch.Where(b => EntryIsNotNull(b, path)).ToList(); + } break; default: remove = false; diff --git a/BlueprintExplorer/BlueprintViewer.cs b/BlueprintExplorer/BlueprintViewer.cs index ffa7b2e..bc46f1b 100644 --- a/BlueprintExplorer/BlueprintViewer.cs +++ b/BlueprintExplorer/BlueprintViewer.cs @@ -18,6 +18,33 @@ public partial class BlueprintViewer : UserControl public event BlueprintHandleDelegate OnOpenExternally; public event Action OnClose; + public bool CanClose + { + set + { + this.close.Enabled = value; + } + } + + public void Navigate(NavigateTo to) + { + int target = to switch + { + NavigateTo.RelativeBackOne => ActiveHistoryIndex - 1, + NavigateTo.RelativeForwardOne => ActiveHistoryIndex + 1, + NavigateTo.AbsoluteFirst => 0, + NavigateTo.AbsoluteLast => history.Count - 1, + _ => throw new NotImplementedException(), + }; + + if (target >= 0 && target < history.Count) + { + ActiveHistoryIndex = target; + ShowBlueprint(history[target], 0); + InvalidateHistory(); + } + } + public BlueprintViewer() { InitializeComponent(); @@ -43,6 +70,8 @@ public BlueprintViewer() filter.Text = filterValue; }; + view.OnNavigate += Navigate; + filter.TextChanged += (sender, e) => view.Filter = filter.Text; if (Form1.Dark) { @@ -53,6 +82,15 @@ public BlueprintViewer() references.CellClick += (sender, e) => ShowReferenceSelected(); openExternal.Click += (sender, e) => OnOpenExternally?.Invoke(View.Blueprint as BlueprintHandle); + + this.AddMouseClickRecursively(HandleXbuttons); + } + private void HandleXbuttons(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.XButton1) + Navigate(NavigateTo.RelativeBackOne); + else if (e.Button == MouseButtons.XButton2) + Navigate(NavigateTo.RelativeForwardOne); } public void ShowBlueprint(BlueprintHandle handle, ShowFlags flags) diff --git a/BlueprintExplorer/Form1.cs b/BlueprintExplorer/Form1.cs index a6c57cf..808568c 100644 --- a/BlueprintExplorer/Form1.cs +++ b/BlueprintExplorer/Form1.cs @@ -53,11 +53,22 @@ public BlueprintViewer NewBlueprintViewer(int index = -1) { if (blueprintViews.TabCount > 1) blueprintViews.TabPages.Remove(page); + for (int i =0; i < blueprintViews.TabCount; i++) + { + (blueprintViews.TabPages[i].Controls[0] as BlueprintViewer).CanClose = blueprintViews.TabCount > 1; + } }; page.Controls.Add(viewer); viewer.Dock = DockStyle.Fill; blueprintViews.TabPages.Add(page); + + for (int i =0; i < blueprintViews.TabCount; i++) + { + (blueprintViews.TabPages[i].Controls[0] as BlueprintViewer).CanClose = blueprintViews.TabCount > 1; + } + + return viewer; } @@ -103,7 +114,8 @@ private static long ParseVersion(string v) return int.Parse(c[0]) * 65536 + int.Parse(c[1]) * 256 + int.Parse(c[2]); } - public Form1() { + public Form1() + { var env = Environment.GetEnvironmentVariable("BubbleprintsTheme"); Dark = env?.Equals("dark") ?? false; Dark |= BubblePrints.Settings.DarkMode; @@ -138,10 +150,14 @@ public Form1() { } InitializeComponent(); + + this.AddMouseClickRecursively(HandleXbuttons); + NewBlueprintViewer(); omniSearch.TextChanged += OmniSearch_TextChanged; resultsGrid.CellClick += ResultsGrid_CellClick; + InstallReadline(omniSearch); controlBar.ColumnStyles[^1].Width = 0; @@ -221,7 +237,8 @@ public Form1() { var progress = new BlueprintDB.ConnectionProgress(); initialize = Task.Run(() => BlueprintDB.Instance.TryConnect(progress)); - initialize.ContinueWith(b => { + initialize.ContinueWith(b => + { omniSearch.Enabled = true; resultsGrid.Enabled = true; omniSearch.Text = ""; @@ -235,18 +252,24 @@ public Form1() { }, TaskScheduler.FromCurrentSynchronizationContext()); - new Thread(() => { + new Thread(() => + { string plane = $"{loadString}-🛬"; const int frames = 90; - while (true) { - for (int frame = 0; frame < frames; frame++) { + while (true) + { + for (int frame = 0; frame < frames; frame++) + { if (Good) return; - if (omniSearch.Visible) { - omniSearch.Invoke(new Action(() => { - if (!Good) { + if (omniSearch.Visible) + { + omniSearch.Invoke(new Action(() => + { + if (!Good) + { omniSearch.Text = plane.PadLeft(plane.Length + frame) + $"{progress.Status}"; } })); @@ -258,6 +281,20 @@ public Form1() { } + + private void HandleXbuttons(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.XButton1) + (blueprintViews.SelectedTab.Controls[0] as BlueprintViewer).Navigate(NavigateTo.RelativeBackOne); + else if (e.Button == MouseButtons.XButton2) + (blueprintViews.SelectedTab.Controls[0] as BlueprintViewer).Navigate(NavigateTo.RelativeForwardOne); + } + + private void ResultsGrid_MouseDown(object sender, MouseEventArgs e) + { + throw new NotImplementedException(); + } + private void BlueprintView_OnLinkClicked(string link) { throw new NotImplementedException(); diff --git a/BlueprintExplorer/Helpers/Helpers.cs b/BlueprintExplorer/Helpers/Helpers.cs index aba1f09..4fc47f3 100644 --- a/BlueprintExplorer/Helpers/Helpers.cs +++ b/BlueprintExplorer/Helpers/Helpers.cs @@ -14,6 +14,20 @@ 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) + { + Queue frontier = new(); + frontier.Enqueue(root); + + while (frontier.Count > 0) + { + var c = frontier.Dequeue(); + c.MouseClick += handler; + for (int i = 0; i < c.Controls.Count; i++) + frontier.Enqueue(c.Controls[i]); + } + } } } diff --git a/BlueprintExplorer/MatchQuery.cs b/BlueprintExplorer/MatchQuery.cs index c25b8b3..dfe2df5 100644 --- a/BlueprintExplorer/MatchQuery.cs +++ b/BlueprintExplorer/MatchQuery.cs @@ -194,6 +194,15 @@ public MatchQuery(string queryText, MatchProvider provider) { foreach (var term in terms) { if (term.Contains(':')) { var pair = term.Split(':'); + if (pair[1].Length == 0) continue; + if (pair[1][0] == '!') + { + int underscore = pair[1].IndexOf('_'); + if (underscore != -1 && underscore != pair[1].Length - 1) + { + pair[1] = pair[1].Substring(underscore + 1); + } + } StrictSearchTexts[pair[0]] = pair[1]; } else diff --git a/BlueprintExplorer/help.rtf b/BlueprintExplorer/help.rtf index ad2250730c2b849451779c4f6d533ff69037193d..242e5df34b9f208d321e256f2ff3d628c32f92a2 100644 GIT binary patch delta 968 zcmZ9L!EVz)5Qb%fpr!2#z-8J~E7A~JkfI1gQ;0$@p`rnSWC`usV|$g2*VFuXelTOP0p>o4dQveRJ69KRf96{K)L=!1VmaHz)bLv|gUAKzY7&H1sp3*KYaT z-Dts}vwzfHgqkzee$KhXOpDYSFnN|KO@~n~t;i&TW!%&OS&)E=phyHA0+vE3OeWa` z7#O4)%woB>`rvq=KxLRxIK{$=VWRR%5LhkYE=Y{*b|6JC1f_vbU?jp&;v(dfQlvu= z?!;w2bJkdx_677`47xsV`l1PK*bH*5F|~416?#S1Qf2@55DJZfyAx?O0-GRcG}NJi zvA|;MGJ8d--+6t|>kKZqw#!eo`f=AGa1ABQkhP6O7_0PT;}Xk-TT^*S*cd6l5f;Nb z7%>u(Y4Ttd$qVGbwJHqi2E1J$N|Z8$TtUjlA||GUdG7qUl4TmlLgj|i%rjpyaxg2f zB8@>%Z-hnDfNa(9-0n7KdJ*EvTEanNbwo^{5z{$}0R=`>2kAadilyPh`R_>Sg6R-= zPU6%+A*2K*%@xnY2j6D|9K-U%()yh%8++94ynOonAF}tRXUl)QsM^zm$dS{uQcM$V zj|UT?o~jE`|beF2eHE+bZGa@^oeOk#~JC z$*??GdwdwTd-M_L*^JvzovXe?oGOiOC6R@$gmX~`(ZB`~20?!q7F7ca6~t}#)rq$# L>67W{+FtE1f_6{u delta 212 zcmcbnF+pj=E=ES9$-5cf0Lc|hPZ^Ci_c6OOix|b^B<7_X8W{Y zwiBdyC5PhV70harUvmUGM&_3)Bq!!6BxmI37pE$ek zmMfGbCMhIUDkPT_YP zGHPsQ