Skip to content

Commit

Permalink
fix mouse capture
Browse files Browse the repository at this point in the history
  • Loading branch information
factubsio committed Mar 26, 2022
1 parent 85cd144 commit e1e565f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 26 deletions.
23 changes: 12 additions & 11 deletions BlueprintExplorer/BlueprintControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,20 +701,21 @@ 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 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)
{
base.OnMouseClick(e);
bool valid = GetCurrent(out var elem);
if (e.Button == MouseButtons.Left && valid)
{
Expand Down
2 changes: 2 additions & 0 deletions BlueprintExplorer/BlueprintViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ private void HandleXbuttons(object sender, MouseEventArgs e)
Navigate(NavigateTo.RelativeBackOne);
else if (e.Button == MouseButtons.XButton2)
Navigate(NavigateTo.RelativeForwardOne);

(ParentForm as Form1)?.HideCtrlP();
}

public void ShowBlueprint(BlueprintHandle handle, ShowFlags flags)
Expand Down
19 changes: 11 additions & 8 deletions BlueprintExplorer/CtrlP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ public CtrlP()
root.ShowCellToolTips = false;

rootPanel.BorderStyle = BorderStyle.FixedSingle;
root.TabStop = false;

DoubleBuffered = true;
}
protected override void OnClick(EventArgs e)
{
Console.WriteLine("HELLO");
}

private void Root_MouseClick(object sender, MouseEventArgs e)
{
Expand All @@ -68,7 +73,7 @@ private void Root_MouseClick(object sender, MouseEventArgs e)
{
root.Rows[row].Selected = true;
Daddy.ShowBlueprint(row, ModifierKeys.HasFlag(Keys.Control) || e.Button == MouseButtons.Middle);
Close();
Hide();
}
}
}
Expand Down Expand Up @@ -120,7 +125,7 @@ private void Input_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
Close();
Hide();
}
if (e.KeyCode == Keys.Up || (e.KeyCode == Keys.P && ModifierKeys.HasFlag(Keys.Control)))
{
Expand Down Expand Up @@ -161,28 +166,26 @@ private void Input_KeyDown(object sender, KeyEventArgs e)

Daddy.ShowBlueprint(root.SelectedRow(), ModifierKeys.HasFlag(Keys.Control));

Close();
Hide();
}
}

protected override void OnClosed(EventArgs e)
protected override void OnDeactivate(EventArgs e)
{
base.OnClosed(e);
savedVerticalScroll = root.FirstDisplayedScrollingRowIndex;
}

private int savedVerticalScroll = -1;

protected override void OnShown(EventArgs e)
protected override void OnActivated(EventArgs e)
{
base.OnShown(e);
Capture = true;
UpdateSize();
if (savedVerticalScroll != -1)
{
root.FirstDisplayedScrollingRowIndex = savedVerticalScroll;
}
input.Focus();
base.OnActivated(e);
}
}
}
69 changes: 62 additions & 7 deletions BlueprintExplorer/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,18 @@ public Form1()
kGlobalManager.GlobalPaletteMode = Krypton.Toolkit.PaletteModeManager.SparkleOrange;
};


this.AddMouseClickRecursively(HandleXbuttons);

this.AddKeyDownRecursively(HandleGlobalKeys);

header.MouseClick -= HandleXbuttons;

header.MouseClick += (sender, e) =>
{
ShowCtrlP();
};

controlBar.ColumnStyles[^1].Width = 0;

availableVersions.Enabled = false;
Expand All @@ -288,6 +296,7 @@ public Form1()

settingsButton.Click += (sender, evt) =>
{
HideCtrlP();
new SettingsView().ShowDialog();
};

Expand Down Expand Up @@ -339,14 +348,15 @@ public Form1()

var progress = new BlueprintDB.ConnectionProgress();
header.Marquee = true;
header.Dock = DockStyle.Fill;

initialize = Task.Run(() => BlueprintDB.Instance.TryConnect(progress));
initialize.ContinueWith(b =>
{
ShowBlueprint(BlueprintDB.Instance.Blueprints.Values.First(), ShowFlags.F_UpdateHistory);

header.Marquee = false;
header.Text = "Press @{key.ctrl}-@{key.P} to search";
header.Text = "Press @{key.ctrl}-@{key.P} to search (or click here)";

foreach (var v in BlueprintDB.Instance.Available)
availableVersions.Items.Add(v);
Expand Down Expand Up @@ -386,21 +396,57 @@ public Form1()

}

protected override void OnMove(EventArgs e)
{
base.OnMove(e);

if (ctrlP?.Visible == true)
{
var search = PointToScreen(new Point(100, 1));
ctrlP.Location = new Point(search.X, search.Y);
}
}


private int CtrlPWidth => ClientSize.Width - 375;

protected override void OnResize(EventArgs e)
{
base.OnResize(e);

if (ctrlP?.Visible == true)
{
ctrlP.Size = new Size(CtrlPWidth, 80);
}
}


public void ShowCtrlP()
{
if (!Good) return;
if (!Good || ctrlP?.Visible == true) return;

header.OverrideText = "";

ctrlP ??= new CtrlP();
ctrlP.Daddy = this;
if (ctrlP == null)
{
ctrlP = new();
ctrlP.Daddy = this;
ctrlP.VisibleChanged += CtrlP_VisibleChanged;

}

ctrlP.StartPosition = FormStartPosition.Manual;
var search = PointToScreen(new Point(100, 1));
ctrlP.Location = new Point(search.X, search.Y);
ctrlP.Size = new Size(ClientSize.Width - 200, 80);
ctrlP.Size = new Size(CtrlPWidth, 80);
ctrlP.input.Focus();
ctrlP.ShowDialog(this);
ctrlP.Show(this);

}

private void CtrlP_VisibleChanged(object sender, EventArgs e)
{
if (ctrlP.Visible) return;

if (ctrlP.input.Text.Length > 0)
header.Text2 = " --- current: " + ctrlP.input.Text;
Expand All @@ -409,7 +455,6 @@ public void ShowCtrlP()
header.OverrideText = null;
}


public void HandleGlobalKeys(object sender, KeyEventArgs e)
{

Expand All @@ -427,12 +472,22 @@ public void HandleGlobalKeys(object sender, KeyEventArgs e)
// (blueprintDock.ActivePage.Controls[0] as BlueprintViewer).Navigate(NavigateTo.RelativeForwardOne);
}

public void HideCtrlP()
{
if (ctrlP.Visible)
{
ctrlP.Hide();
}
}

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);

HideCtrlP();
}

private void ResultsGrid_MouseDown(object sender, MouseEventArgs e)
Expand Down
1 change: 1 addition & 0 deletions BlueprintExplorer/Helpers/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static void ForEachControl(this Control root, Action<Control> act)
}

public static void AddMouseClickRecursively(this Control root, MouseEventHandler handler) => ForEachControl(root, c => c.MouseClick += handler);
public static void AddMouseDownRecursively(this Control root, MouseEventHandler handler) => ForEachControl(root, c => c.MouseDown += handler);
public static void AddKeyDownRecursively(this Control root, KeyEventHandler handler) => ForEachControl(root, c => c.KeyDown += handler);
}

Expand Down

0 comments on commit e1e565f

Please sign in to comment.