Skip to content

Commit

Permalink
navigation and !bp_
Browse files Browse the repository at this point in the history
  • Loading branch information
factubsio committed Mar 19, 2022
1 parent 46089ca commit 0a59cdc
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 10 deletions.
35 changes: 35 additions & 0 deletions BlueprintExplorer/BlueprintControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -850,4 +878,11 @@ public class DrawParams
public Graphics Graphics;
}
}
public enum NavigateTo
{
RelativeBackOne,
RelativeForwardOne,
AbsoluteFirst,
AbsoluteLast,
}
}
12 changes: 10 additions & 2 deletions BlueprintExplorer/BlueprintDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,16 @@ public List<BlueprintHandle> 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;
Expand Down
38 changes: 38 additions & 0 deletions BlueprintExplorer/BlueprintViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -43,6 +70,8 @@ public BlueprintViewer()
filter.Text = filterValue;
};

view.OnNavigate += Navigate;

filter.TextChanged += (sender, e) => view.Filter = filter.Text;
if (Form1.Dark)
{
Expand All @@ -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)
Expand Down
53 changes: 45 additions & 8 deletions BlueprintExplorer/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = "";
Expand All @@ -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}";
}
}));
Expand All @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions BlueprintExplorer/Helpers/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Control> 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]);
}
}
}

}
9 changes: 9 additions & 0 deletions BlueprintExplorer/MatchQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified BlueprintExplorer/help.rtf
Binary file not shown.

0 comments on commit 0a59cdc

Please sign in to comment.