From 11d081519dd41532b2763a69b22159fc6d2f5ad1 Mon Sep 17 00:00:00 2001 From: Amadeo Alex <68441479+amadeo-alex@users.noreply.github.com> Date: Sat, 15 Jul 2023 00:01:46 +0200 Subject: [PATCH 01/11] poc (up/down/left/right) --- .../Forms/QuickActions/QuickActions.cs | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs index a2381add..5a42dc94 100644 --- a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs +++ b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs @@ -12,7 +12,7 @@ namespace HASS.Agent.Forms.QuickActions public partial class QuickActions : MetroForm { public event EventHandler ClearFocus; - + private readonly List _quickActions = new(); private readonly List _quickActionPanelControls = new(); @@ -73,7 +73,7 @@ private void BuildLayout() _columns = columns; _rows = rows; - + // prepare our panel PnlActions.AutoSize = true; @@ -84,7 +84,7 @@ private void BuildLayout() PnlActions.RowCount = _rows; PnlActions.CellBorderStyle = TableLayoutPanelCellBorderStyle.None; - + // resize window Width = 152 * columns + 20; Height = 255 * rows + 30; @@ -111,7 +111,7 @@ private void BuildLayout() // store position if (!_rowColumnCounts.ContainsKey(currentRow)) _rowColumnCounts.Add(currentRow, currentColumn); else _rowColumnCounts[currentRow] = currentColumn; - + // add to the panel PnlActions.Controls.Add(quickAction, currentColumn, currentRow); @@ -242,7 +242,14 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) if (keyData == Keys.Down) { // is there a next row? - if (_selectedRow == _rows - 1) return true; + if (_selectedRow == _rows - 1) + { + var nextControl = _quickActionPanelControls.Find(x => x.Row == 0 && x.Column == _selectedColumn); + + nextControl.QuickActionControl.OnFocus(); + _selectedRow = 0; + return true; + } // jep, select the control below (or the last) _selectedRow++; @@ -264,7 +271,14 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { // is there a next column? var maxColumnsForRow = _rowColumnCounts[_selectedRow]; - if (_selectedColumn == maxColumnsForRow) return true; + if (_selectedColumn == maxColumnsForRow) + { + var nextControl = _quickActionPanelControls.Find(x => x.Row == _selectedRow && x.Column == 0); + + nextControl.QuickActionControl.OnFocus(); + _selectedColumn = 0; + return true; + } // jep, select the control to the right _selectedColumn++; @@ -276,7 +290,15 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) if (keyData == Keys.Left) { // is there a previous column? - if (_selectedColumn == 0) return true; + if (_selectedColumn == 0) + { + var maxColumnsForRow = _rowColumnCounts[_selectedRow]; + var nextControl = _quickActionPanelControls.Find(x => x.Row == _selectedRow && x.Column == maxColumnsForRow); + + nextControl.QuickActionControl.OnFocus(); + _selectedColumn = maxColumnsForRow; + return true; + } // jep, select the control to the left _selectedColumn--; @@ -288,7 +310,15 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) if (keyData == Keys.Up) { // is there a previous row? - if (_selectedRow == 0) return true; + if (_selectedRow == 0) + { + var nextRow = _rows - 1; + var nextControl = _quickActionPanelControls.Find(x => x.Row == nextRow && x.Column == _selectedColumn); + + nextControl.QuickActionControl.OnFocus(); + _selectedRow = nextRow; + return true; + } // jep, select the control above (or the last) _selectedRow--; From a2abba28330099ae84fa24722ee83a3fb86cad33 Mon Sep 17 00:00:00 2001 From: Amadeo Alex <68441479+amadeo-alex@users.noreply.github.com> Date: Sun, 16 Jul 2023 19:01:30 +0200 Subject: [PATCH 02/11] added GetForm function --- src/HASS.Agent.Staging/HASS.Agent/Functions/HelperFunctions.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/HASS.Agent.Staging/HASS.Agent/Functions/HelperFunctions.cs b/src/HASS.Agent.Staging/HASS.Agent/Functions/HelperFunctions.cs index e41bfe44..791ba495 100644 --- a/src/HASS.Agent.Staging/HASS.Agent/Functions/HelperFunctions.cs +++ b/src/HASS.Agent.Staging/HASS.Agent/Functions/HelperFunctions.cs @@ -364,6 +364,8 @@ internal static void OpenLocalFolder(string path) /// internal static bool CheckIfFormIsOpen(string formname) => Application.OpenForms.Cast
().Any(form => form?.Name == formname); + internal static Form GetForm(string formName) => Application.OpenForms.Cast().FirstOrDefault(x => x.Name == formName); + /// /// Launches the url with the user's custom browser if provided, or the system's default /// From 5310deb5d12c40a7169e21ae89a925721fac407d Mon Sep 17 00:00:00 2001 From: Amadeo Alex <68441479+amadeo-alex@users.noreply.github.com> Date: Sun, 16 Jul 2023 19:02:11 +0200 Subject: [PATCH 03/11] unified "formName" variable --- .../HASS.Agent/Functions/HelperFunctions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/HASS.Agent.Staging/HASS.Agent/Functions/HelperFunctions.cs b/src/HASS.Agent.Staging/HASS.Agent/Functions/HelperFunctions.cs index 791ba495..a63ce8a0 100644 --- a/src/HASS.Agent.Staging/HASS.Agent/Functions/HelperFunctions.cs +++ b/src/HASS.Agent.Staging/HASS.Agent/Functions/HelperFunctions.cs @@ -360,9 +360,9 @@ internal static void OpenLocalFolder(string path) /// /// Checks whether the provided form is already opened /// - /// + /// /// - internal static bool CheckIfFormIsOpen(string formname) => Application.OpenForms.Cast().Any(form => form?.Name == formname); + internal static bool CheckIfFormIsOpen(string formName) => Application.OpenForms.Cast().Any(form => form?.Name == formName); internal static Form GetForm(string formName) => Application.OpenForms.Cast().FirstOrDefault(x => x.Name == formName); From aa0f155c8e14e23c2394f589446e06fe346caec6 Mon Sep 17 00:00:00 2001 From: Amadeo Alex <68441479+amadeo-alex@users.noreply.github.com> Date: Sun, 16 Jul 2023 19:05:11 +0200 Subject: [PATCH 04/11] added TryBringToFront accepting Form object --- .../HASS.Agent/Functions/HelperFunctions.cs | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/HASS.Agent.Staging/HASS.Agent/Functions/HelperFunctions.cs b/src/HASS.Agent.Staging/HASS.Agent/Functions/HelperFunctions.cs index a63ce8a0..f8f7b359 100644 --- a/src/HASS.Agent.Staging/HASS.Agent/Functions/HelperFunctions.cs +++ b/src/HASS.Agent.Staging/HASS.Agent/Functions/HelperFunctions.cs @@ -488,7 +488,7 @@ internal static void LaunchTrayIconWebView(WebViewInfo webViewInfo) // show a new webview from within the UI thread LaunchTrayIconCustomWebView(webViewInfo); } - + private static void LaunchTrayIconBackgroundLoadedWebView() { Variables.MainForm.Invoke(new MethodInvoker(delegate @@ -568,14 +568,12 @@ internal static bool InputLanguageCheckDiffers(out bool knownToCollide, out stri /// /// Attempts to bring the provided form to the foreground if it's open /// - /// + /// /// - internal static async Task TryBringToFront(string formName) + internal static async Task TryBringToFront(Form form) { try { - // is it open? - var form = Application.OpenForms.Cast().FirstOrDefault(x => x.Name == formName); if (form == null) return false; // yep, check if we need to undo minimized @@ -596,6 +594,25 @@ internal static async Task TryBringToFront(string formName) } } + /// + /// Attempts to bring the provided form to the foreground if it's open + /// + /// + /// + internal static async Task TryBringToFront(string formName) + { + try + { + var form = GetForm(formName); + return await TryBringToFront(form); + } + catch (Exception ex) + { + Log.Fatal(ex, ex.Message); + return false; + } + } + /// /// Checks the local file to see if it has the right signature /// @@ -644,16 +661,16 @@ internal static bool ConfirmCertificate(string localFile) return false; } } - + /// /// Returns the configured device name, or a safe version of the machinename if nothing's stored /// /// internal static string GetConfiguredDeviceName() => - string.IsNullOrEmpty(Variables.AppSettings?.DeviceName) - ? SharedHelperFunctions.GetSafeDeviceName() + string.IsNullOrEmpty(Variables.AppSettings?.DeviceName) + ? SharedHelperFunctions.GetSafeDeviceName() : SharedHelperFunctions.GetSafeValue(Variables.AppSettings.DeviceName); - + /// /// Checks whether the process is currently running under the current user, by default ignoring the current process /// From 45967014f5113ca7d5247103fbc59b573bb7628b Mon Sep 17 00:00:00 2001 From: Amadeo Alex <68441479+amadeo-alex@users.noreply.github.com> Date: Sun, 16 Jul 2023 19:31:26 +0200 Subject: [PATCH 05/11] added carousel behavior when quick actions button is pressed after quick actions window is opened --- .../HASS.Agent/Forms/Main.cs | 7 ++++- .../Forms/QuickActions/QuickActions.cs | 30 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/HASS.Agent.Staging/HASS.Agent/Forms/Main.cs b/src/HASS.Agent.Staging/HASS.Agent/Forms/Main.cs index 26881537..4340f0a8 100644 --- a/src/HASS.Agent.Staging/HASS.Agent/Forms/Main.cs +++ b/src/HASS.Agent.Staging/HASS.Agent/Forms/Main.cs @@ -347,10 +347,15 @@ private async void ShowMain() /// private async void ShowQuickActions() { + // check if quickactions aren't already open, and if there are any actions if (HelperFunctions.CheckIfFormIsOpen("QuickActions")) { - await HelperFunctions.TryBringToFront("QuickActions"); + var quickActionsForm = HelperFunctions.GetForm("QuickActions") as QuickActions.QuickActions; + var result = await HelperFunctions.TryBringToFront(quickActionsForm); + if (result) + quickActionsForm.SelectNextQuickActionItem(); + return; } diff --git a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs index 5a42dc94..7abcc048 100644 --- a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs +++ b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs @@ -56,6 +56,9 @@ private async void QuickActions_Load(object sender, EventArgs e) // check hass status var hass = await CheckHassManagerAsync(); if (!hass) CloseWindow(); + + // select first item + _quickActionPanelControls.Find(x => x.Row == 0 && x.Column == 0)?.QuickActionControl.OnFocus(); } /// @@ -345,6 +348,33 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) return base.ProcessCmdKey(ref msg, keyData); } + /// + /// Selects next Quick Action item following right->down->up pattern + /// + public void SelectNextQuickActionItem() + { + var maxColumnsForRow = _rowColumnCounts[_selectedRow]; + + // are we at the end of the row? + if (_selectedColumn == maxColumnsForRow) + { + // wrap up to first row if there is nothing below + if (_selectedRow == (_rows - 1)) { _selectedRow = 0; } else { _selectedRow++; } + + var nextControl = _quickActionPanelControls.Find(x => x.Row == _selectedRow && x.Column == 0); + + nextControl.QuickActionControl.OnFocus(); + _selectedColumn = 0; + return; + } + + // select the control to the right + _selectedColumn++; + var control = _quickActionPanelControls.Find(x => x.Row == _selectedRow && x.Column == _selectedColumn); + control?.QuickActionControl.OnFocus(); + return; + } + /// /// Triggers clearing the focus of all controls /// From 834a62d5caa3066182ad509c3f31db24d73b9834 Mon Sep 17 00:00:00 2001 From: Amadeo Alex <68441479+amadeo-alex@users.noreply.github.com> Date: Sun, 16 Jul 2023 19:58:14 +0200 Subject: [PATCH 06/11] internal position is now synced when mouse hovers over item --- .../Forms/QuickActions/QuickActions.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs index 7abcc048..aae68d5b 100644 --- a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs +++ b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs @@ -108,6 +108,9 @@ private void BuildLayout() Row = currentRow }; + // update position when item is selected by mouse cursor + panelControl.QuickActionControl.MouseEnter += QuickActionItemMouseEnter; + // add to list _quickActionPanelControls.Add(panelControl); @@ -129,6 +132,19 @@ private void BuildLayout() } } + private void QuickActionControl_MouseEnter(object sender, EventArgs e) + { + throw new NotImplementedException(); + } + + private void QuickActionItemMouseEnter(object sender, EventArgs e) + { + var position = PnlActions.GetPositionFromControl(sender as QuickActionControl); + _selectedColumn = position.Column; + _selectedRow = position.Row; + return; + } + /// /// Tries to close the window /// From 0136bd45d672088a51c1789b06869041a906f4e3 Mon Sep 17 00:00:00 2001 From: Amadeo Alex <68441479+amadeo-alex@users.noreply.github.com> Date: Sun, 16 Jul 2023 20:12:09 +0200 Subject: [PATCH 07/11] fixed first item not being selected when quick actions window is opened --- .../HASS.Agent/Forms/QuickActions/QuickActions.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs index aae68d5b..ec5baec7 100644 --- a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs +++ b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs @@ -58,7 +58,13 @@ private async void QuickActions_Load(object sender, EventArgs e) if (!hass) CloseWindow(); // select first item - _quickActionPanelControls.Find(x => x.Row == 0 && x.Column == 0)?.QuickActionControl.OnFocus(); + var control = _quickActionPanelControls.Find(x => x.Row == 0 && x.Column == 0); + if(control != null) + { + control.QuickActionControl.OnFocus(); + _selectedColumn = 0; + _selectedRow = 0; + } } /// From ef9f89ac8624be32e5339dbdf27db451ef250ab7 Mon Sep 17 00:00:00 2001 From: Amadeo Alex <68441479+amadeo-alex@users.noreply.github.com> Date: Sun, 16 Jul 2023 20:14:24 +0200 Subject: [PATCH 08/11] removed function added by accident --- .../HASS.Agent/Forms/QuickActions/QuickActions.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs index ec5baec7..86606f24 100644 --- a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs +++ b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs @@ -138,11 +138,6 @@ private void BuildLayout() } } - private void QuickActionControl_MouseEnter(object sender, EventArgs e) - { - throw new NotImplementedException(); - } - private void QuickActionItemMouseEnter(object sender, EventArgs e) { var position = PnlActions.GetPositionFromControl(sender as QuickActionControl); From 8d724033d0e117d9fd453e82e9c9fe594719130e Mon Sep 17 00:00:00 2001 From: Amadeo Alex <68441479+amadeo-alex@users.noreply.github.com> Date: Sun, 16 Jul 2023 21:05:57 +0200 Subject: [PATCH 09/11] cleanup --- .../Forms/QuickActions/QuickActions.cs | 177 +++++++++--------- 1 file changed, 92 insertions(+), 85 deletions(-) diff --git a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs index 86606f24..1183c204 100644 --- a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs +++ b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs @@ -26,7 +26,10 @@ public partial class QuickActions : MetroForm public QuickActions(List quickActions) { - foreach (var quickAction in quickActions) _quickActions.Add(quickAction); + foreach (var quickAction in quickActions) + { + _quickActions.Add(quickAction); + } InitializeComponent(); } @@ -55,16 +58,11 @@ private async void QuickActions_Load(object sender, EventArgs e) // check hass status var hass = await CheckHassManagerAsync(); - if (!hass) CloseWindow(); + if (!hass) + CloseWindow(); // select first item - var control = _quickActionPanelControls.Find(x => x.Row == 0 && x.Column == 0); - if(control != null) - { - control.QuickActionControl.OnFocus(); - _selectedColumn = 0; - _selectedRow = 0; - } + SelectQuickActionItem(0, 0); } /// @@ -86,20 +84,29 @@ private void BuildLayout() // prepare our panel PnlActions.AutoSize = true; - for (var c = 0; c <= _columns; c++) PnlActions.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 152)); PnlActions.ColumnCount = _columns; - - for (var r = 0; r <= _columns; r++) PnlActions.RowStyles.Add(new RowStyle(SizeType.Absolute, 255)); PnlActions.RowCount = _rows; PnlActions.CellBorderStyle = TableLayoutPanelCellBorderStyle.None; + for (var c = 0; c <= _columns; c++) + { + PnlActions.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 152)); + } + + for (var r = 0; r <= _columns; r++) + { + PnlActions.RowStyles.Add(new RowStyle(SizeType.Absolute, 255)); + } + // resize window Width = 152 * columns + 20; Height = 255 * rows + 30; - if (columns > 1) Width += 5 * (columns - 1); - if (rows > 1) Height += 5 * (rows - 1); + if (columns > 1) + Width += 5 * (columns - 1); + if (rows > 1) + Height += 5 * (rows - 1); // add the quickactions as controls var currentColumn = 0; @@ -121,19 +128,29 @@ private void BuildLayout() _quickActionPanelControls.Add(panelControl); // store position - if (!_rowColumnCounts.ContainsKey(currentRow)) _rowColumnCounts.Add(currentRow, currentColumn); - else _rowColumnCounts[currentRow] = currentColumn; + if (!_rowColumnCounts.ContainsKey(currentRow)) + { + _rowColumnCounts.Add(currentRow, currentColumn); + } + else + { + _rowColumnCounts[currentRow] = currentColumn; + } // add to the panel PnlActions.Controls.Add(quickAction, currentColumn, currentRow); // set next column & row - if (currentColumn < columns - 1) currentColumn++; + if (currentColumn < columns - 1) + { + currentColumn++; + } else { // on to the next row (if there is one) currentColumn = 0; - if (currentRow < rows - 1) currentRow++; + if (currentRow < rows - 1) + currentRow++; } } } @@ -151,8 +168,10 @@ private void QuickActionItemMouseEnter(object sender, EventArgs e) /// internal void CloseWindow() { - if (!IsHandleCreated) return; - if (IsDisposed) return; + if (!IsHandleCreated) + return; + if (IsDisposed) + return; Invoke(new MethodInvoker(delegate { @@ -204,8 +223,10 @@ private async Task CheckHassManagerAsync() /// private void SetGuiLoading(bool loading) { - if (!IsHandleCreated) return; - if (IsDisposed) return; + if (!IsHandleCreated) + return; + if (IsDisposed) + return; Invoke(new MethodInvoker(delegate { @@ -236,6 +257,25 @@ private void QuickActions_FormClosing(object sender, FormClosingEventArgs e) } } + /// + /// Selects QuickAction item at given position + /// + /// + /// + /// + private bool SelectQuickActionItem(int row, int column) + { + var control = _quickActionPanelControls.Find(x => x.Row == row && x.Column == column); + if (control == null) + return false; + + control.QuickActionControl.OnFocus(); + _selectedColumn = column; + _selectedRow = row; + + return true; + } + /// /// Intercepts and processes the arrow keys /// @@ -246,113 +286,81 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { try { - // if never pressed before .. + // should not happen, but select first item if nothing is selected if (_selectedColumn == -1) { - // .. always select first one - var control = _quickActionPanelControls.Find(x => x.Row == 0 && x.Column == 0); - if (control == null) return true; + SelectQuickActionItem(0, 0); - control.QuickActionControl.OnFocus(); - _selectedColumn = 0; - _selectedRow = 0; return true; } if (keyData == Keys.Down) { - // is there a next row? + // wrap up if we're at the last row if (_selectedRow == _rows - 1) { - var nextControl = _quickActionPanelControls.Find(x => x.Row == 0 && x.Column == _selectedColumn); + SelectQuickActionItem(0, _selectedColumn); - nextControl.QuickActionControl.OnFocus(); - _selectedRow = 0; return true; } - // jep, select the control below (or the last) - _selectedRow++; - var control = _quickActionPanelControls.Find(x => x.Row == _selectedRow && x.Column == _selectedColumn); - if (control == null) + var selected = SelectQuickActionItem(_selectedRow + 1, _selectedColumn); + if (!selected) { - // none found with same column, get the last - _selectedColumn = _rowColumnCounts[_selectedRow]; - control = _quickActionPanelControls.Find(x => x.Row == _selectedRow && x.Column == _selectedColumn); - control?.QuickActionControl.OnFocus(); - return true; + SelectQuickActionItem(_selectedRow + 1, _rowColumnCounts[_selectedRow + 1]); } - control.QuickActionControl.OnFocus(); return true; } if (keyData == Keys.Right) { - // is there a next column? + // wrap up to left is we're at the last column var maxColumnsForRow = _rowColumnCounts[_selectedRow]; if (_selectedColumn == maxColumnsForRow) { - var nextControl = _quickActionPanelControls.Find(x => x.Row == _selectedRow && x.Column == 0); + SelectQuickActionItem(_selectedRow, 0); - nextControl.QuickActionControl.OnFocus(); - _selectedColumn = 0; return true; } - // jep, select the control to the right - _selectedColumn++; - var control = _quickActionPanelControls.Find(x => x.Row == _selectedRow && x.Column == _selectedColumn); - control?.QuickActionControl.OnFocus(); + SelectQuickActionItem(_selectedRow, _selectedColumn + 1); + return true; } if (keyData == Keys.Left) { - // is there a previous column? + // wrap up to right is we're at the first column if (_selectedColumn == 0) { var maxColumnsForRow = _rowColumnCounts[_selectedRow]; - var nextControl = _quickActionPanelControls.Find(x => x.Row == _selectedRow && x.Column == maxColumnsForRow); + SelectQuickActionItem(_selectedRow, maxColumnsForRow); - nextControl.QuickActionControl.OnFocus(); - _selectedColumn = maxColumnsForRow; return true; } - // jep, select the control to the left - _selectedColumn--; - var control = _quickActionPanelControls.Find(x => x.Row == _selectedRow && x.Column == _selectedColumn); - control?.QuickActionControl.OnFocus(); + SelectQuickActionItem(_selectedRow, _selectedColumn - 1); + return true; } if (keyData == Keys.Up) { - // is there a previous row? + // wrap down if we're at the last row if (_selectedRow == 0) { - var nextRow = _rows - 1; - var nextControl = _quickActionPanelControls.Find(x => x.Row == nextRow && x.Column == _selectedColumn); + SelectQuickActionItem(_rows - 1, _rowColumnCounts[_rows - 1]); - nextControl.QuickActionControl.OnFocus(); - _selectedRow = nextRow; return true; } - // jep, select the control above (or the last) - _selectedRow--; - var control = _quickActionPanelControls.Find(x => x.Row == _selectedRow && x.Column == _selectedColumn); - if (control == null) + var selected = SelectQuickActionItem(_selectedRow - 1, _selectedColumn); + if (!selected) { - // none found with same column, get the first - _selectedColumn = 0; - control = _quickActionPanelControls.Find(x => x.Row == _selectedRow && x.Column == _selectedColumn); - control?.QuickActionControl.OnFocus(); - return true; + SelectQuickActionItem(_selectedRow - 1, _rowColumnCounts[_selectedRow - 1]); } - control.QuickActionControl.OnFocus(); return true; } } @@ -376,19 +384,15 @@ public void SelectNextQuickActionItem() if (_selectedColumn == maxColumnsForRow) { // wrap up to first row if there is nothing below - if (_selectedRow == (_rows - 1)) { _selectedRow = 0; } else { _selectedRow++; } + var nextRow = _selectedRow == (_rows - 1) ? 0 : _selectedRow + 1; + SelectQuickActionItem(nextRow, 0); - var nextControl = _quickActionPanelControls.Find(x => x.Row == _selectedRow && x.Column == 0); - - nextControl.QuickActionControl.OnFocus(); - _selectedColumn = 0; return; } // select the control to the right - _selectedColumn++; - var control = _quickActionPanelControls.Find(x => x.Row == _selectedRow && x.Column == _selectedColumn); - control?.QuickActionControl.OnFocus(); + SelectQuickActionItem(_selectedRow, _selectedColumn + 1); + return; } @@ -400,9 +404,12 @@ public void SelectNextQuickActionItem() private void QuickActions_ResizeEnd(object sender, EventArgs e) { - if (Variables.ShuttingDown) return; - if (!IsHandleCreated) return; - if (IsDisposed) return; + if (Variables.ShuttingDown) + return; + if (!IsHandleCreated) + return; + if (IsDisposed) + return; try { From 3c893e56266bcd782a6f0a642005083e6838ae2d Mon Sep 17 00:00:00 2001 From: Amadeo Alex <68441479+amadeo-alex@users.noreply.github.com> Date: Mon, 17 Jul 2023 15:05:40 +0200 Subject: [PATCH 10/11] changed how left and right arrow keypress behaves (wraps to the next/previous row) --- .../Forms/QuickActions/QuickActions.cs | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs index 1183c204..068555e2 100644 --- a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs +++ b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs @@ -315,11 +315,13 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) if (keyData == Keys.Right) { - // wrap up to left is we're at the last column var maxColumnsForRow = _rowColumnCounts[_selectedRow]; + + // wrap up to first row if there is nothing below if (_selectedColumn == maxColumnsForRow) { - SelectQuickActionItem(_selectedRow, 0); + var nextRow = _selectedRow == (_rows - 1) ? 0 : _selectedRow + 1; + SelectQuickActionItem(nextRow, 0); return true; } @@ -331,11 +333,11 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) if (keyData == Keys.Left) { - // wrap up to right is we're at the first column + // wrap up to last row if there is nothing above if (_selectedColumn == 0) { - var maxColumnsForRow = _rowColumnCounts[_selectedRow]; - SelectQuickActionItem(_selectedRow, maxColumnsForRow); + var nextRow = _selectedRow == 0 ? _rows - 1 : _selectedRow - 1; + SelectQuickActionItem(nextRow, _rowColumnCounts[nextRow]); return true; } @@ -343,6 +345,13 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) SelectQuickActionItem(_selectedRow, _selectedColumn - 1); return true; + /* // wrap up to bottom is we're at the first column + + var nextRow = _selectedColumn == 0 ? _selectedRow - 1 : _selectedRow; + var nextColumn = _selectedColumn == 0 ? _rowColumnCounts[nextRow] : _selectedColumn - 1; + SelectQuickActionItem(nextRow, nextColumn); + + return true;*/ } if (keyData == Keys.Up) @@ -380,17 +389,15 @@ public void SelectNextQuickActionItem() { var maxColumnsForRow = _rowColumnCounts[_selectedRow]; - // are we at the end of the row? + // are we at the end of the row / wrap up to first row if there is nothing below if (_selectedColumn == maxColumnsForRow) { - // wrap up to first row if there is nothing below var nextRow = _selectedRow == (_rows - 1) ? 0 : _selectedRow + 1; SelectQuickActionItem(nextRow, 0); return; } - // select the control to the right SelectQuickActionItem(_selectedRow, _selectedColumn + 1); return; From 5ec80d81b2ef3bd9d241d8150794ed605e647cd4 Mon Sep 17 00:00:00 2001 From: Amadeo Alex <68441479+amadeo-alex@users.noreply.github.com> Date: Mon, 17 Jul 2023 15:23:58 +0200 Subject: [PATCH 11/11] fixed up arrow not wrapping up correctly --- .../Forms/QuickActions/QuickActions.cs | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs index 068555e2..0c54706b 100644 --- a/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs +++ b/src/HASS.Agent.Staging/HASS.Agent/Forms/QuickActions/QuickActions.cs @@ -304,10 +304,11 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) return true; } - var selected = SelectQuickActionItem(_selectedRow + 1, _selectedColumn); + var nextRow = _selectedRow + 1; + var selected = SelectQuickActionItem(nextRow, _selectedColumn); if (!selected) { - SelectQuickActionItem(_selectedRow + 1, _rowColumnCounts[_selectedRow + 1]); + SelectQuickActionItem(nextRow, _rowColumnCounts[nextRow]); } return true; @@ -345,29 +346,27 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData) SelectQuickActionItem(_selectedRow, _selectedColumn - 1); return true; - /* // wrap up to bottom is we're at the first column - - var nextRow = _selectedColumn == 0 ? _selectedRow - 1 : _selectedRow; - var nextColumn = _selectedColumn == 0 ? _rowColumnCounts[nextRow] : _selectedColumn - 1; - SelectQuickActionItem(nextRow, nextColumn); - - return true;*/ } if (keyData == Keys.Up) { - // wrap down if we're at the last row + var nextRow = _selectedRow - 1; + + // wrap down if we're at the first row if (_selectedRow == 0) { - SelectQuickActionItem(_rows - 1, _rowColumnCounts[_rows - 1]); + nextRow = _rows - 1; + var maxColumnsForNextRow = _rowColumnCounts[nextRow]; + var nextColumn = maxColumnsForNextRow < _selectedColumn ? maxColumnsForNextRow : _selectedColumn; + SelectQuickActionItem(nextRow, nextColumn); return true; } - var selected = SelectQuickActionItem(_selectedRow - 1, _selectedColumn); + var selected = SelectQuickActionItem(nextRow, _selectedColumn); if (!selected) { - SelectQuickActionItem(_selectedRow - 1, _rowColumnCounts[_selectedRow - 1]); + SelectQuickActionItem(nextRow, _rowColumnCounts[nextRow]); } return true;