From f34942558d06897d5db61bb6de4ff9fb22178948 Mon Sep 17 00:00:00 2001 From: Si Carter Date: Thu, 28 Dec 2023 08:11:42 +1100 Subject: [PATCH 1/2] Goto line menu --- src/.editorconfig | 1 + .../Analyzers/AnalyzeM62XComPorts.cs | 6 +- src/GCATests/Mocks/MockEditorPluginHost.cs | 60 ++++++++++++++++ src/GCATests/Mocks/MockITextEditor.cs | 22 ++++++ .../Plugins/SearchMenu/GotoMenuItemTests.cs | 64 +++++++++++++++++ .../SearchMenu/SearchMenuPluginTests.cs | 51 +++++++++++++ .../Controllers/MachinesController.cs | 5 +- src/GSend.Language/Resources.Designer.cs | 18 +++++ src/GSend.Language/Resources.resx | 6 ++ .../Abstractions/IEditorPluginHost.cs | 2 +- src/GSendControls/Abstractions/ITextEditor.cs | 12 ++++ src/GSendControls/Controls/BaseControl.cs | 5 +- src/GSendControls/GlobalSuppressions.cs | 1 + .../SearchMenu/GotoMenuItem.cs | 72 +++++++++++++++++++ .../SearchMenu/SearchMenuItem.cs | 62 ++++++++++++++++ .../SearchMenu/SearchMenuPlugin.cs | 54 ++++++++++++++ src/GSendEditor/FrmMain.cs | 8 ++- src/GSendEditor/Internal/TextEditorBridge.cs | 31 ++++++++ 18 files changed, 464 insertions(+), 16 deletions(-) create mode 100644 src/GCATests/Mocks/MockEditorPluginHost.cs create mode 100644 src/GCATests/Mocks/MockITextEditor.cs create mode 100644 src/GCATests/Plugins/SearchMenu/GotoMenuItemTests.cs create mode 100644 src/GCATests/Plugins/SearchMenu/SearchMenuPluginTests.cs create mode 100644 src/GSendControls/Abstractions/ITextEditor.cs create mode 100644 src/GSendControls/Plugins/InternalPlugins/SearchMenu/GotoMenuItem.cs create mode 100644 src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuItem.cs create mode 100644 src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuPlugin.cs create mode 100644 src/GSendEditor/Internal/TextEditorBridge.cs diff --git a/src/.editorconfig b/src/.editorconfig index 83e1d3a..11354e0 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -97,3 +97,4 @@ dotnet_style_prefer_inferred_tuple_names = true:suggestion dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion dotnet_style_prefer_compound_assignment = true:suggestion dotnet_style_prefer_simplified_interpolation = true:suggestion +dotnet_diagnostic.CA1859.severity = none diff --git a/src/GCAAnalyser/Analyzers/AnalyzeM62XComPorts.cs b/src/GCAAnalyser/Analyzers/AnalyzeM62XComPorts.cs index f7e894a..6a5c61f 100644 --- a/src/GCAAnalyser/Analyzers/AnalyzeM62XComPorts.cs +++ b/src/GCAAnalyser/Analyzers/AnalyzeM62XComPorts.cs @@ -61,10 +61,8 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses) } //open port - if (!comPortUsage.ContainsKey(comPort)) - { + if (!comPortUsage.TryGetValue(comPort, out bool _)) comPortUsage.Add(comPort, false); - } if ((command.PreviousCommand?.LineNumber == command.LineNumber || command.NextCommand?.LineNumber == command.LineNumber) && (command.PreviousCommand?.MasterLineNumber == command.MasterLineNumber || command.NextCommand?.MasterLineNumber == command.MasterLineNumber)) @@ -80,7 +78,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses) else if (command.CommandValue == Constants.MCode621) { // close port - if (!comPortUsage.ContainsKey(comPort)) + if (!comPortUsage.TryGetValue(comPort, out bool _)) codeAnalyses.AddError(GSend.Language.Resources.AnalyzeError4, command.LineNumber, comPort); else if (!comPortUsage[comPort]) codeAnalyses.AddError(GSend.Language.Resources.AnalyzeError5, command.LineNumber, comPort); diff --git a/src/GCATests/Mocks/MockEditorPluginHost.cs b/src/GCATests/Mocks/MockEditorPluginHost.cs new file mode 100644 index 0000000..32cf9b3 --- /dev/null +++ b/src/GCATests/Mocks/MockEditorPluginHost.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using GSendControls.Abstractions; + +using GSendShared; +using GSendShared.Plugins; + +namespace GSendTests.Mocks +{ + internal class MockEditorPluginHost : IEditorPluginHost + { + public MockEditorPluginHost() + { + Editor = new MockITextEditor(); + } + + public bool IsDirty => throw new NotImplementedException(); + + public bool IsSubprogram => throw new NotImplementedException(); + + public string FileName => throw new NotImplementedException(); + + public ITextEditor Editor { get; set; } + + public PluginHosts Host => throw new NotImplementedException(); + + public int MaximumMenuIndex => throw new NotImplementedException(); + + public IGSendContext GSendContext => throw new NotImplementedException(); + + public void AddMenu(IPluginMenu pluginMenu) + { + throw new NotImplementedException(); + } + + public void AddMessage(InformationType informationType, string message) + { + throw new NotImplementedException(); + } + + public void AddPlugin(IGSendPluginModule pluginModule) + { + throw new NotImplementedException(); + } + + public void AddToolbar(IPluginToolbarButton toolbarButton) + { + throw new NotImplementedException(); + } + + public IPluginMenu GetMenu(MenuParent menuParent) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/GCATests/Mocks/MockITextEditor.cs b/src/GCATests/Mocks/MockITextEditor.cs new file mode 100644 index 0000000..6e057e3 --- /dev/null +++ b/src/GCATests/Mocks/MockITextEditor.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using GSendControls.Abstractions; + +namespace GSendTests.Mocks +{ + internal class MockITextEditor : ITextEditor + { + public int LineCount { get; set; } = 23; + + public bool ShowGotoDialogCalled { get; private set; } + + public void ShowGoToDialog() + { + ShowGotoDialogCalled = true; + } + } +} diff --git a/src/GCATests/Plugins/SearchMenu/GotoMenuItemTests.cs b/src/GCATests/Plugins/SearchMenu/GotoMenuItemTests.cs new file mode 100644 index 0000000..0359958 --- /dev/null +++ b/src/GCATests/Plugins/SearchMenu/GotoMenuItemTests.cs @@ -0,0 +1,64 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +using GSendControls.Abstractions; +using GSendControls.Plugins.InternalPlugins.SearchMenu; + +using GSendShared.Plugins; + +using GSendTests.Mocks; + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using Moq; + +namespace GSendTests.Plugins.SearchMenu +{ + [TestClass] + [ExcludeFromCodeCoverage] + public class GotoMenuItemTests + { + [TestMethod] + public void Construct_GotoMenuItem_Success() + { + MockPluginMenu parentMenu = new MockPluginMenu("test", MenuType.MenuItem, null); + GotoMenuItem sut = new(parentMenu, new MockITextEditor()); + Assert.IsNotNull(sut); + Assert.IsNull(sut.MenuImage); + Assert.AreEqual(MenuType.MenuItem, sut.MenuType); + Assert.IsNotNull(sut.ParentMenu); + Assert.AreSame(parentMenu, sut.ParentMenu); + Assert.AreEqual("Goto", sut.Text); + Assert.AreEqual(0, sut.Index); + Assert.IsFalse(sut.ReceiveClientMessages); + Assert.IsFalse(sut.GetShortcut(out string grpName, out string shrtCutName)); + Assert.IsNull(grpName); + Assert.IsNull(shrtCutName); + Assert.IsFalse(sut.IsChecked()); + Assert.IsTrue(sut.IsEnabled()); + Assert.IsTrue(sut.IsVisible()); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentNullException))] + public void Construct_InvalidParam_ParentNull_Throws_ArgumentNullException() + { + new GotoMenuItem(null, new Mock().Object); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentNullException))] + public void Construct_InvalidParam_TextEditorNull_Throws_ArgumentNullException() + { + new GotoMenuItem(new MockPluginMenu("test", GSendShared.Plugins.MenuType.MenuItem, null), null); + } + + [TestMethod] + public void UpdateHost_DoesNotCrash_Success() + { + GotoMenuItem sut = new(new MockPluginMenu("test", MenuType.MenuItem, null), new MockITextEditor()); + Assert.IsNotNull(sut); + sut.UpdateHost(null); + } + } +} diff --git a/src/GCATests/Plugins/SearchMenu/SearchMenuPluginTests.cs b/src/GCATests/Plugins/SearchMenu/SearchMenuPluginTests.cs new file mode 100644 index 0000000..26f8f26 --- /dev/null +++ b/src/GCATests/Plugins/SearchMenu/SearchMenuPluginTests.cs @@ -0,0 +1,51 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +using GSendControls.Abstractions; +using GSendControls.Plugins.InternalPlugins.SearchMenu; + +using GSendShared.Plugins; + +using GSendTests.Mocks; + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using Moq; + +namespace GSendTests.Plugins.SearchMenu +{ + [TestClass] + [ExcludeFromCodeCoverage] + public class SearchMenuPluginTests + { + [TestMethod] + public void Construct_ValidInstance_Success() + { + SearchMenuPlugin sut = new(); + Assert.IsNotNull(sut); + sut.Initialize(new MockEditorPluginHost()); + Assert.AreEqual(1u, sut.Version); + Assert.AreEqual(PluginHosts.Editor, sut.Host); + Assert.AreEqual(PluginOptions.HasMenuItems, sut.Options); + Assert.IsNull(sut.ToolbarItems); + Assert.AreEqual(2, sut.MenuItems.Count); + } + + [TestMethod] + public void ClientMessageReceived_NullValue_DoesNotRaiseException() + { + SearchMenuPlugin sut = new(); + Assert.IsNotNull(sut); + sut.ClientMessageReceived(null); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentNullException))] + public void Initialize_NullValue_Throws_ArgumentNullException() + { + SearchMenuPlugin sut = new(); + Assert.IsNotNull(sut); + sut.Initialize(null); + } + } +} diff --git a/src/GCSService/Controllers/MachinesController.cs b/src/GCSService/Controllers/MachinesController.cs index aa35a59..6267000 100644 --- a/src/GCSService/Controllers/MachinesController.cs +++ b/src/GCSService/Controllers/MachinesController.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; -using System.ServiceProcess; using GSendService.Attributes; using GSendService.Models; @@ -310,7 +308,6 @@ public IActionResult Service(long machineId) } [HttpPost] - [Route("/Machines/Service/{machineId}/")] public IActionResult Service(ServiceMachineModel model) { IMachine machine = _gSendDataProvider.MachineGet(model.MachineId); @@ -340,7 +337,7 @@ public IActionResult Service(ServiceMachineModel model) _gSendDataProvider.ServiceAdd(new MachineServiceModel(-1, model.MachineId, DateTime.UtcNow, model.ServiceType, spindleTicks / TimeSpan.TicksPerHour, serviceItems)); - + return RedirectToAction(nameof(Index)); } diff --git a/src/GSend.Language/Resources.Designer.cs b/src/GSend.Language/Resources.Designer.cs index 8c6c091..9131adb 100644 --- a/src/GSend.Language/Resources.Designer.cs +++ b/src/GSend.Language/Resources.Designer.cs @@ -2436,6 +2436,15 @@ public static string Generate { } } + /// + /// Looks up a localized string similar to Goto. + /// + public static string GotoLineNumberMenu { + get { + return ResourceManager.GetString("GotoLineNumberMenu", resourceCulture); + } + } + /// /// Looks up a localized string similar to Available Blocks. /// @@ -3570,6 +3579,15 @@ public static string SaveSubProgram { } } + /// + /// Looks up a localized string similar to Search. + /// + public static string SearchMenu { + get { + return ResourceManager.GetString("SearchMenu", resourceCulture); + } + } + /// /// Looks up a localized string similar to Send. /// diff --git a/src/GSend.Language/Resources.resx b/src/GSend.Language/Resources.resx index 06120a3..7529147 100644 --- a/src/GSend.Language/Resources.resx +++ b/src/GSend.Language/Resources.resx @@ -2212,4 +2212,10 @@ There should be at least 100mm movement from the spindles position in both the X Validate the bit does not go below the spoilboard when using Z Bottom and having a negative Z value + + Search + + + Goto + \ No newline at end of file diff --git a/src/GSendControls/Abstractions/IEditorPluginHost.cs b/src/GSendControls/Abstractions/IEditorPluginHost.cs index 0bc2797..a425444 100644 --- a/src/GSendControls/Abstractions/IEditorPluginHost.cs +++ b/src/GSendControls/Abstractions/IEditorPluginHost.cs @@ -22,6 +22,6 @@ public interface IEditorPluginHost : IPluginHost /// /// In app editor /// - FastColoredTextBox Editor { get; } + ITextEditor Editor { get; } } } diff --git a/src/GSendControls/Abstractions/ITextEditor.cs b/src/GSendControls/Abstractions/ITextEditor.cs new file mode 100644 index 0000000..d082c26 --- /dev/null +++ b/src/GSendControls/Abstractions/ITextEditor.cs @@ -0,0 +1,12 @@ +namespace GSendControls.Abstractions +{ + /// + /// Text Editor interface + /// + public interface ITextEditor + { + void ShowGoToDialog(); + + int LineCount { get; } + } +} diff --git a/src/GSendControls/Controls/BaseControl.cs b/src/GSendControls/Controls/BaseControl.cs index 97229c3..527ad54 100644 --- a/src/GSendControls/Controls/BaseControl.cs +++ b/src/GSendControls/Controls/BaseControl.cs @@ -10,10 +10,7 @@ * */ using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Drawing; -using System.Data; using System.Globalization; using System.Text; using System.Threading; @@ -171,7 +168,7 @@ private void ctl_Enter(object sender, EventArgs e) /// /// /// - private string GetLocalizedControls(ControlCollection parent, string results) + private static string GetLocalizedControls(ControlCollection parent, string results) { if (parent == null) return results; diff --git a/src/GSendControls/GlobalSuppressions.cs b/src/GSendControls/GlobalSuppressions.cs index ec058a4..1ced59d 100644 --- a/src/GSendControls/GlobalSuppressions.cs +++ b/src/GSendControls/GlobalSuppressions.cs @@ -19,3 +19,4 @@ [assembly: SuppressMessage("Major Code Smell", "S1168:Empty arrays and collections should be returned instead of null", Justification = "expects null", Scope = "member", Target = "~P:GSendControls.Plugins.InternalPlugins.ServerMenu.ServerMenuPlugin.ToolbarItems")] [assembly: SuppressMessage("Major Code Smell", "S1168:Empty arrays and collections should be returned instead of null", Justification = "expects null", Scope = "member", Target = "~P:GSendControls.Plugins.InternalPlugins.HelpMenu.HelpMenuPlugin.ToolbarItems")] [assembly: SuppressMessage("Major Bug", "S2259:Null pointers should not be dereferenced", Justification = "", Scope = "member", Target = "~M:GSendControls.Plugins.PluginHelper.InitializeAllPlugins(GSendControls.Abstractions.IPluginHost)")] +[assembly: SuppressMessage("Major Code Smell", "S1168:Empty arrays and collections should be returned instead of null", Justification = "Null is fine", Scope = "member", Target = "~P:GSendControls.Plugins.InternalPlugins.SearchMenu.SearchMenuPlugin.ToolbarItems")] diff --git a/src/GSendControls/Plugins/InternalPlugins/SearchMenu/GotoMenuItem.cs b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/GotoMenuItem.cs new file mode 100644 index 0000000..551f8b6 --- /dev/null +++ b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/GotoMenuItem.cs @@ -0,0 +1,72 @@ +using System; +using System.Drawing; + +using FastColoredTextBoxNS; + +using GSendControls.Abstractions; + +using GSendShared; +using GSendShared.Plugins; + +namespace GSendControls.Plugins.InternalPlugins.SearchMenu +{ + public sealed class GotoMenuItem : IPluginMenu + { + private readonly ITextEditor _textEditor; + + public GotoMenuItem(IPluginMenu parentMenu, ITextEditor textBox) + { + ParentMenu = parentMenu ?? throw new ArgumentNullException(nameof(parentMenu)); + _textEditor = textBox ?? throw new ArgumentNullException(nameof(textBox)); + } + + public Image MenuImage => null; + + public MenuType MenuType => MenuType.MenuItem; + + public IPluginMenu ParentMenu { get; private set; } + + public string Text => GSend.Language.Resources.GotoLineNumberMenu; + + public int Index => 0; + + public bool ReceiveClientMessages => false; + + public void Clicked() + { + _textEditor?.ShowGoToDialog(); + } + + public void ClientMessageReceived(IClientBaseMessage clientMessage) + { + throw new NotImplementedException(); + } + + public bool GetShortcut(out string groupName, out string shortcutName) + { + groupName = null; + shortcutName = null; + return false; + } + + public bool IsChecked() + { + return false; + } + + public bool IsEnabled() + { + return _textEditor?.LineCount > 0; + } + + public bool IsVisible() + { + return true; + } + + public void UpdateHost(T senderPluginHost) + { + // from interface, not used in this context + } + } +} diff --git a/src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuItem.cs b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuItem.cs new file mode 100644 index 0000000..e712cce --- /dev/null +++ b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuItem.cs @@ -0,0 +1,62 @@ +using System; +using System.Drawing; + +using GSendControls.Abstractions; + +using GSendShared; +using GSendShared.Plugins; + +namespace GSendControls.Plugins.InternalPlugins.SearchMenu +{ + public sealed class SearchMenuItem : IPluginMenu + { + public Image MenuImage => null; + + public MenuType MenuType => MenuType.MenuItem; + + public IPluginMenu ParentMenu => null; + + public string Text => GSend.Language.Resources.SearchMenu; + + public int Index => 3; + + public bool ReceiveClientMessages => false; + + public void Clicked() + { + // from interface, not used in this context + } + + public void ClientMessageReceived(IClientBaseMessage clientMessage) + { + // from interface, not used in this context + } + + public bool GetShortcut(out string groupName, out string shortcutName) + { + groupName = null; + shortcutName = null; + return false; + } + + public bool IsChecked() + { + return false; + } + + public bool IsEnabled() + { + return true; + } + + public bool IsVisible() + { + return true; + } + + public void UpdateHost(T senderPluginHost) + { + // from interface, not used in this context + } + } +} diff --git a/src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuPlugin.cs b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuPlugin.cs new file mode 100644 index 0000000..ee57f0c --- /dev/null +++ b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuPlugin.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; + +using GSendControls.Abstractions; + +using GSendShared; +using GSendShared.Plugins; + +namespace GSendControls.Plugins.InternalPlugins.SearchMenu +{ + public sealed class SearchMenuPlugin : IGSendPluginModule + { + private IEditorPluginHost _pluginHost; + private List _pluginMenus; + + public string Name => "Search Menu"; + + public ushort Version => 1; + + public PluginHosts Host => PluginHosts.Editor; + + public PluginOptions Options => PluginOptions.HasMenuItems; + + public IReadOnlyList MenuItems + { + get + { + if (_pluginMenus == null) + { + SearchMenuItem searchMenuItem = new SearchMenuItem(); + + _pluginMenus = [ + searchMenuItem, + new GotoMenuItem(searchMenuItem, _pluginHost.Editor) + ]; + } + + return _pluginMenus; + } + } + + public IReadOnlyList ToolbarItems => null; + + public void ClientMessageReceived(IClientBaseMessage clientBaseMessage) + { + // from interface, not used in this context + } + + public void Initialize(IPluginHost pluginHost) + { + _pluginHost = pluginHost as IEditorPluginHost ?? throw new ArgumentNullException(nameof(pluginHost)); + } + } +} diff --git a/src/GSendEditor/FrmMain.cs b/src/GSendEditor/FrmMain.cs index c4c2848..88425b8 100644 --- a/src/GSendEditor/FrmMain.cs +++ b/src/GSendEditor/FrmMain.cs @@ -1,4 +1,3 @@ -using System.Runtime.InteropServices; using System.Text; using FastColoredTextBoxNS; @@ -12,6 +11,7 @@ using GSendControls.Abstractions; using GSendControls.Plugins; using GSendControls.Threads; + using GSendDesktop.Internal; using GSendEditor.Internal; @@ -47,6 +47,7 @@ public partial class FrmMain : BaseForm, IShortcutImplementation, IEditorPluginH private readonly IPluginHelper _pluginHelper; private bool _isSubprogram = false; private bool _isOnline; + private readonly TextEditorBridge _textEditorBridge; public FrmMain(IGSendContext gSendContext) { @@ -55,6 +56,7 @@ public FrmMain(IGSendContext gSendContext) _gsendApiWrapper.ServerUriChanged += GsendApiWrapper_ServerUriChanged; _pluginHelper = _gSendContext.ServiceProvider.GetRequiredService(); InitializeComponent(); + _textEditorBridge = new(txtGCode); _serverBasedSubPrograms = new ServerBasedSubPrograms(_gsendApiWrapper); CreateAnalyzerThread(gSendContext.ServiceProvider.GetService(), _serverBasedSubPrograms); @@ -1191,7 +1193,7 @@ public List GetShortcuts() #region ISenderPluginHost - public PluginHosts Host => PluginHosts.SenderHost; + public PluginHosts Host => PluginHosts.Editor; public int MaximumMenuIndex => menuStripMain.Items.IndexOf(mnuHelp); @@ -1262,7 +1264,7 @@ private set } } - public FastColoredTextBox Editor => txtGCode; + public ITextEditor Editor => _textEditorBridge; public IGSendContext GSendContext => _gSendContext; diff --git a/src/GSendEditor/Internal/TextEditorBridge.cs b/src/GSendEditor/Internal/TextEditorBridge.cs new file mode 100644 index 0000000..e16ccee --- /dev/null +++ b/src/GSendEditor/Internal/TextEditorBridge.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using GSendControls.Abstractions; + +namespace GSendEditor.Internal +{ + internal class TextEditorBridge : ITextEditor + { + private readonly FastColoredTextBoxNS.FastColoredTextBox _textBox; + + public TextEditorBridge(FastColoredTextBoxNS.FastColoredTextBox textBox) + { + _textBox = textBox ?? throw new ArgumentNullException(nameof(textBox)); + } + + #region ITextEditor + + public void ShowGoToDialog() + { + _textBox.ShowGoToDialog(); + } + + public int LineCount => _textBox.Lines.Count; + + #endregion ITextEditor + } +} From 4a0b31c7f9c9afd9993e6919271c64aa8a0cd17e Mon Sep 17 00:00:00 2001 From: Si Carter Date: Wed, 10 Jan 2024 14:46:25 +0100 Subject: [PATCH 2/2] Implement find/replace/goto line in editor --- Images/NextArrow.png | Bin 0 -> 184 bytes src/GCATests/Mocks/MockITextEditor.cs | 37 +++++- src/GCATests/Mocks/MockPluginMenu.cs | 3 +- .../Plugins/SearchMenu/FindMenuItemTests.cs | 74 +++++++++++ .../Plugins/SearchMenu/GotoMenuItemTests.cs | 27 +++- .../SearchMenu/ReplaceMenuItemTests.cs | 74 +++++++++++ .../SearchMenu/SearchMenuPluginTests.cs | 2 +- src/GCATests/Shared/Plugins/HelpMenuTests.cs | 9 +- .../Shared/Plugins/ServerMenuPluginTests.cs | 4 +- src/GSend.Language/Resources.Designer.cs | 45 +++++++ src/GSend.Language/Resources.resx | 15 +++ src/GSendControls/Abstractions/IPluginMenu.cs | 7 +- src/GSendControls/Abstractions/ITextEditor.cs | 25 +++- .../Controls/CollapsablePanel.cs | 20 +-- .../Controls/CollapsablePanel.resx | 120 ++++++++++++++++++ src/GSendControls/JogControl.cs | 18 +-- .../Plugins/InternalPluginMenu.cs | 3 +- .../HelpMenu/BugsAndIdeasMenu.cs | 5 +- .../InternalPlugins/HelpMenu/HelpMenuItem.cs | 5 +- .../InternalPlugins/HelpMenu/HomePageMenu.cs | 3 +- .../SearchMenu/FindMenuItem.cs | 74 +++++++++++ .../SearchMenu/GotoMenuItem.cs | 11 +- .../SearchMenu/ReplaceMenuItem.cs | 74 +++++++++++ .../SearchMenu/SearchMenuItem.cs | 4 +- .../SearchMenu/SearchMenuPlugin.cs | 5 +- .../ServerMenu/ConfigureServerMenuItem.cs | 3 +- .../ServerMenu/ServerRootMenuItem.cs | 5 +- .../ServerMenu/ServerSelectMenuItem.cs | 5 +- src/GSendControls/Plugins/PluginHelper.cs | 5 +- src/GSendControls/Plugins/SeperatorMenu.cs | 3 +- .../Properties/Resources.Designer.cs | 16 ++- src/GSendControls/Properties/Resources.resx | 15 ++- src/GSendControls/Resources/NextArrow.png | Bin 0 -> 184 bytes src/GSendEditor/FrmMain.cs | 6 +- src/GSendEditor/Internal/TextEditorBridge.cs | 39 ++++-- .../GrblTuning/TuningWizardMenuItem.cs | 3 +- wwwroot/Controllers/MCodesController.cs | 6 +- 37 files changed, 688 insertions(+), 82 deletions(-) create mode 100644 Images/NextArrow.png create mode 100644 src/GCATests/Plugins/SearchMenu/FindMenuItemTests.cs create mode 100644 src/GCATests/Plugins/SearchMenu/ReplaceMenuItemTests.cs create mode 100644 src/GSendControls/Controls/CollapsablePanel.resx create mode 100644 src/GSendControls/Plugins/InternalPlugins/SearchMenu/FindMenuItem.cs create mode 100644 src/GSendControls/Plugins/InternalPlugins/SearchMenu/ReplaceMenuItem.cs create mode 100644 src/GSendControls/Resources/NextArrow.png diff --git a/Images/NextArrow.png b/Images/NextArrow.png new file mode 100644 index 0000000000000000000000000000000000000000..1dc95e7bf89b625f08b7d60e041caf31415510c0 GIT binary patch literal 184 zcmeAS@N?(olHy`uVBq!ia0vp^;vmey1|%P7U0DF67>k44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h7I;J!GcfQS24TkI`72U@g1(+Ejv*f2Z_hb$F(`1j1ir7&JnZYyBfMhk zr^eYU@)z;@%FMC|>FWOQ{HaCs1)+YiH^KFW*2}N$=>7iuxui}`)T4<-b2N|UtMU2D a1jMdPta;Y5T+jh%FoUP7pUXO@geCw|YdpUI literal 0 HcmV?d00001 diff --git a/src/GCATests/Mocks/MockITextEditor.cs b/src/GCATests/Mocks/MockITextEditor.cs index 6e057e3..2d1f6b1 100644 --- a/src/GCATests/Mocks/MockITextEditor.cs +++ b/src/GCATests/Mocks/MockITextEditor.cs @@ -1,8 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Drawing; +using System.Security.Policy; +using System.Windows.Forms; using GSendControls.Abstractions; @@ -10,13 +9,43 @@ namespace GSendTests.Mocks { internal class MockITextEditor : ITextEditor { + public string Text { get; set; } = String.Empty; + public int LineCount { get; set; } = 23; public bool ShowGotoDialogCalled { get; private set; } + public bool ShowFindDialogCalled { get; private set; } + + public bool ShowReplaceDialogCalled { get; private set; } + + public IWin32Window Parent => throw new NotImplementedException(); + + public Rectangle ParentRectangle => throw new NotImplementedException(); + + public int SelectionStart => throw new NotImplementedException(); + + public int SelectionLength => throw new NotImplementedException(); + + public Rectangle Position => throw new NotImplementedException(); + + public Control ParentControl => throw new NotImplementedException(); + + public Point ParentDesktopLocation => throw new NotImplementedException(); + + public void ShowFindDialog() + { + ShowFindDialogCalled = true; + } + public void ShowGoToDialog() { ShowGotoDialogCalled = true; } + + public void ShowReplaceDialog() + { + ShowReplaceDialogCalled = true; + } } } diff --git a/src/GCATests/Mocks/MockPluginMenu.cs b/src/GCATests/Mocks/MockPluginMenu.cs index c664776..bdada53 100644 --- a/src/GCATests/Mocks/MockPluginMenu.cs +++ b/src/GCATests/Mocks/MockPluginMenu.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using GSendControls.Abstractions; @@ -65,7 +66,7 @@ public void UpdateHost(T senderPluginHost) _senderPluginHost = senderPluginHost as ISenderPluginHost; } - public bool GetShortcut(out string groupName, out string shortcutName) + public bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName) { throw new NotImplementedException(); } diff --git a/src/GCATests/Plugins/SearchMenu/FindMenuItemTests.cs b/src/GCATests/Plugins/SearchMenu/FindMenuItemTests.cs new file mode 100644 index 0000000..5933854 --- /dev/null +++ b/src/GCATests/Plugins/SearchMenu/FindMenuItemTests.cs @@ -0,0 +1,74 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +using GSendControls.Abstractions; +using GSendControls.Plugins.InternalPlugins.SearchMenu; + +using GSendShared.Plugins; + +using GSendTests.Mocks; + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using Moq; + +namespace GSendTests.Plugins.SearchMenu +{ + [TestClass] + [ExcludeFromCodeCoverage] + public class FindMenuItemTests + { + [TestMethod] + public void Construct_FindMenuItem_Success() + { + MockPluginMenu parentMenu = new MockPluginMenu("test", MenuType.MenuItem, null); + FindMenuItem sut = new(parentMenu, new MockITextEditor()); + Assert.IsNotNull(sut); + Assert.IsNull(sut.MenuImage); + Assert.AreEqual(MenuType.MenuItem, sut.MenuType); + Assert.IsNotNull(sut.ParentMenu); + Assert.AreSame(parentMenu, sut.ParentMenu); + Assert.AreEqual("Find", sut.Text); + Assert.AreEqual(0, sut.Index); + Assert.IsFalse(sut.ReceiveClientMessages); + Assert.IsTrue(sut.GetShortcut([], out string grpName, out string shrtCutName)); + Assert.AreEqual("Search Menu", grpName); + Assert.AreEqual("Find", shrtCutName); + Assert.IsFalse(sut.IsChecked()); + Assert.IsFalse(sut.IsEnabled()); + Assert.IsTrue(sut.IsVisible()); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentNullException))] + public void Construct_InvalidParam_ParentNull_Throws_ArgumentNullException() + { + new FindMenuItem(null, new Mock().Object); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentNullException))] + public void Construct_InvalidParam_TextEditorNull_Throws_ArgumentNullException() + { + new FindMenuItem(new MockPluginMenu("test", MenuType.MenuItem, null), null); + } + + [TestMethod] + public void UpdateHost_DoesNotCrash_Success() + { + FindMenuItem sut = new(new MockPluginMenu("test", MenuType.MenuItem, null), new MockITextEditor()); + Assert.IsNotNull(sut); + sut.UpdateHost(null); + } + + [TestMethod] + public void IsEnabled_HasText_ReturnsTrue() + { + MockITextEditor mockITextEditor = new(); + mockITextEditor.Text = "Some Text"; + MockPluginMenu parentMenu = new MockPluginMenu("test", MenuType.MenuItem, null); + FindMenuItem sut = new(parentMenu, mockITextEditor); + Assert.IsTrue(sut.IsEnabled()); + } + } +} diff --git a/src/GCATests/Plugins/SearchMenu/GotoMenuItemTests.cs b/src/GCATests/Plugins/SearchMenu/GotoMenuItemTests.cs index 0359958..7013592 100644 --- a/src/GCATests/Plugins/SearchMenu/GotoMenuItemTests.cs +++ b/src/GCATests/Plugins/SearchMenu/GotoMenuItemTests.cs @@ -29,9 +29,9 @@ public void Construct_GotoMenuItem_Success() Assert.IsNotNull(sut.ParentMenu); Assert.AreSame(parentMenu, sut.ParentMenu); Assert.AreEqual("Goto", sut.Text); - Assert.AreEqual(0, sut.Index); + Assert.AreEqual(20, sut.Index); Assert.IsFalse(sut.ReceiveClientMessages); - Assert.IsFalse(sut.GetShortcut(out string grpName, out string shrtCutName)); + Assert.IsFalse(sut.GetShortcut([], out string grpName, out string shrtCutName)); Assert.IsNull(grpName); Assert.IsNull(shrtCutName); Assert.IsFalse(sut.IsChecked()); @@ -50,7 +50,7 @@ public void Construct_InvalidParam_ParentNull_Throws_ArgumentNullException() [ExpectedException(typeof(ArgumentNullException))] public void Construct_InvalidParam_TextEditorNull_Throws_ArgumentNullException() { - new GotoMenuItem(new MockPluginMenu("test", GSendShared.Plugins.MenuType.MenuItem, null), null); + new GotoMenuItem(new MockPluginMenu("test", MenuType.MenuItem, null), null); } [TestMethod] @@ -60,5 +60,26 @@ public void UpdateHost_DoesNotCrash_Success() Assert.IsNotNull(sut); sut.UpdateHost(null); } + + [TestMethod] + public void IsEnabled_HasText_ReturnsTrue() + { + MockITextEditor mockITextEditor = new(); + mockITextEditor.Text = "Some Text"; + MockPluginMenu parentMenu = new MockPluginMenu("test", MenuType.MenuItem, null); + GotoMenuItem sut = new(parentMenu, mockITextEditor); + Assert.IsTrue(sut.IsEnabled()); + } + + [TestMethod] + public void IsEnabled_HasNoText_ReturnsFalse() + { + MockITextEditor mockITextEditor = new(); + mockITextEditor.Text = "Some Text"; + mockITextEditor.LineCount = 0; + MockPluginMenu parentMenu = new MockPluginMenu("test", MenuType.MenuItem, null); + GotoMenuItem sut = new(parentMenu, mockITextEditor); + Assert.IsFalse(sut.IsEnabled()); + } } } diff --git a/src/GCATests/Plugins/SearchMenu/ReplaceMenuItemTests.cs b/src/GCATests/Plugins/SearchMenu/ReplaceMenuItemTests.cs new file mode 100644 index 0000000..1972a1a --- /dev/null +++ b/src/GCATests/Plugins/SearchMenu/ReplaceMenuItemTests.cs @@ -0,0 +1,74 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +using GSendControls.Abstractions; +using GSendControls.Plugins.InternalPlugins.SearchMenu; + +using GSendShared.Plugins; + +using GSendTests.Mocks; + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using Moq; + +namespace GSendTests.Plugins.SearchMenu +{ + [TestClass] + [ExcludeFromCodeCoverage] + public class ReplaceMenuItemTests + { + [TestMethod] + public void Construct_ReplaceMenuItem_Success() + { + MockPluginMenu parentMenu = new MockPluginMenu("test", MenuType.MenuItem, null); + ReplaceMenuItem sut = new(parentMenu, new MockITextEditor()); + Assert.IsNotNull(sut); + Assert.IsNull(sut.MenuImage); + Assert.AreEqual(MenuType.MenuItem, sut.MenuType); + Assert.IsNotNull(sut.ParentMenu); + Assert.AreSame(parentMenu, sut.ParentMenu); + Assert.AreEqual("Replace", sut.Text); + Assert.AreEqual(1, sut.Index); + Assert.IsFalse(sut.ReceiveClientMessages); + Assert.IsTrue(sut.GetShortcut([], out string grpName, out string shrtCutName)); + Assert.AreEqual("Search Menu", grpName); + Assert.AreEqual("Replace", shrtCutName); + Assert.IsFalse(sut.IsChecked()); + Assert.IsFalse(sut.IsEnabled()); + Assert.IsTrue(sut.IsVisible()); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentNullException))] + public void Construct_InvalidParam_ParentNull_Throws_ArgumentNullException() + { + new ReplaceMenuItem(null, new Mock().Object); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentNullException))] + public void Construct_InvalidParam_TextEditorNull_Throws_ArgumentNullException() + { + new ReplaceMenuItem(new MockPluginMenu("test", MenuType.MenuItem, null), null); + } + + [TestMethod] + public void UpdateHost_DoesNotCrash_Success() + { + ReplaceMenuItem sut = new(new MockPluginMenu("test", MenuType.MenuItem, null), new MockITextEditor()); + Assert.IsNotNull(sut); + sut.UpdateHost(null); + } + + [TestMethod] + public void IsEnabled_HasText_ReturnsTrue() + { + MockITextEditor mockITextEditor = new(); + mockITextEditor.Text = "Some Text"; + MockPluginMenu parentMenu = new MockPluginMenu("test", MenuType.MenuItem, null); + ReplaceMenuItem sut = new(parentMenu, mockITextEditor); + Assert.IsTrue(sut.IsEnabled()); + } + } +} diff --git a/src/GCATests/Plugins/SearchMenu/SearchMenuPluginTests.cs b/src/GCATests/Plugins/SearchMenu/SearchMenuPluginTests.cs index 26f8f26..b1f6f61 100644 --- a/src/GCATests/Plugins/SearchMenu/SearchMenuPluginTests.cs +++ b/src/GCATests/Plugins/SearchMenu/SearchMenuPluginTests.cs @@ -28,7 +28,7 @@ public void Construct_ValidInstance_Success() Assert.AreEqual(PluginHosts.Editor, sut.Host); Assert.AreEqual(PluginOptions.HasMenuItems, sut.Options); Assert.IsNull(sut.ToolbarItems); - Assert.AreEqual(2, sut.MenuItems.Count); + Assert.AreEqual(5, sut.MenuItems.Count); } [TestMethod] diff --git a/src/GCATests/Shared/Plugins/HelpMenuTests.cs b/src/GCATests/Shared/Plugins/HelpMenuTests.cs index 3260894..d91c582 100644 --- a/src/GCATests/Shared/Plugins/HelpMenuTests.cs +++ b/src/GCATests/Shared/Plugins/HelpMenuTests.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; + using GSendControls.Abstractions; using GSendControls.Plugins; using GSendControls.Plugins.InternalPlugins.HelpMenu; @@ -49,7 +50,7 @@ public void HelpMenuItem_ConstructValidInstance_Success() Assert.AreEqual(0, sut.Index); Assert.AreEqual(MenuType.MenuItem, sut.MenuType); Assert.AreEqual(parent, sut.ParentMenu); - Assert.IsFalse(sut.GetShortcut(out string _, out string _)); + Assert.IsFalse(sut.GetShortcut([], out string _, out string _)); Assert.IsFalse(sut.IsChecked()); Assert.IsTrue(sut.IsEnabled()); @@ -68,7 +69,7 @@ public void SeperatorMenuItem_ConstructValidInstance_Success() Assert.AreEqual(3, sut.Index); Assert.AreEqual(MenuType.Seperator, sut.MenuType); Assert.AreEqual(parent, sut.ParentMenu); - Assert.IsFalse(sut.GetShortcut(out string _, out string _)); + Assert.IsFalse(sut.GetShortcut([], out string _, out string _)); Assert.IsFalse(sut.IsChecked()); Assert.IsTrue(sut.IsEnabled()); @@ -87,7 +88,7 @@ public void BugsAndIdeasMenuItem_ConstructValidInstance_Success() Assert.AreEqual(2, sut.Index); Assert.AreEqual(MenuType.MenuItem, sut.MenuType); Assert.AreEqual(parent, sut.ParentMenu); - Assert.IsFalse(sut.GetShortcut(out string _, out string _)); + Assert.IsFalse(sut.GetShortcut([], out string _, out string _)); Assert.IsFalse(sut.IsChecked()); Assert.IsTrue(sut.IsEnabled()); @@ -106,7 +107,7 @@ public void HomePageMenuItem_ConstructValidInstance_Success() Assert.AreEqual(4, sut.Index); Assert.AreEqual(MenuType.MenuItem, sut.MenuType); Assert.AreEqual(parent, sut.ParentMenu); - Assert.IsFalse(sut.GetShortcut(out string _, out string _)); + Assert.IsFalse(sut.GetShortcut([], out string _, out string _)); Assert.IsFalse(sut.IsChecked()); Assert.IsTrue(sut.IsEnabled()); diff --git a/src/GCATests/Shared/Plugins/ServerMenuPluginTests.cs b/src/GCATests/Shared/Plugins/ServerMenuPluginTests.cs index f93c815..c2d9ceb 100644 --- a/src/GCATests/Shared/Plugins/ServerMenuPluginTests.cs +++ b/src/GCATests/Shared/Plugins/ServerMenuPluginTests.cs @@ -52,7 +52,7 @@ public void SeperatorMenuItem_ConstructValidInstance_Success() Assert.AreEqual(3, sut.Index); Assert.AreEqual(MenuType.Seperator, sut.MenuType); Assert.AreEqual(parent, sut.ParentMenu); - Assert.IsFalse(sut.GetShortcut(out string _, out string _)); + Assert.IsFalse(sut.GetShortcut([], out string _, out string _)); Assert.IsFalse(sut.IsChecked()); Assert.IsTrue(sut.IsEnabled()); @@ -71,7 +71,7 @@ public void HomePageMenuItem_ConstructValidInstance_Success() Assert.AreEqual(4, sut.Index); Assert.AreEqual(MenuType.MenuItem, sut.MenuType); Assert.AreEqual(parent, sut.ParentMenu); - Assert.IsFalse(sut.GetShortcut(out string _, out string _)); + Assert.IsFalse(sut.GetShortcut([], out string _, out string _)); Assert.IsFalse(sut.IsChecked()); Assert.IsTrue(sut.IsEnabled()); diff --git a/src/GSend.Language/Resources.Designer.cs b/src/GSend.Language/Resources.Designer.cs index 9131adb..dec7a53 100644 --- a/src/GSend.Language/Resources.Designer.cs +++ b/src/GSend.Language/Resources.Designer.cs @@ -2013,6 +2013,42 @@ public static string FileName { } } + /// + /// Looks up a localized string similar to Find. + /// + public static string Find { + get { + return ResourceManager.GetString("Find", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Find. + /// + public static string FindMenu { + get { + return ResourceManager.GetString("FindMenu", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Find Next. + /// + public static string FindNextMenu { + get { + return ResourceManager.GetString("FindNextMenu", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Find Previous. + /// + public static string FindPreviousMenu { + get { + return ResourceManager.GetString("FindPreviousMenu", resourceCulture); + } + } + /// /// Looks up a localized string similar to Supports flood coolant. /// @@ -3489,6 +3525,15 @@ public static string RenameMachine { } } + /// + /// Looks up a localized string similar to Replace. + /// + public static string ReplaceMenu { + get { + return ResourceManager.GetString("ReplaceMenu", resourceCulture); + } + } + /// /// Looks up a localized string similar to Reset. /// diff --git a/src/GSend.Language/Resources.resx b/src/GSend.Language/Resources.resx index 7529147..7dfcc14 100644 --- a/src/GSend.Language/Resources.resx +++ b/src/GSend.Language/Resources.resx @@ -2215,7 +2215,22 @@ There should be at least 100mm movement from the spindles position in both the X Search + + Find + + + Find Next + + + Find Previous + Goto + + Find + + + Replace + \ No newline at end of file diff --git a/src/GSendControls/Abstractions/IPluginMenu.cs b/src/GSendControls/Abstractions/IPluginMenu.cs index 7194d22..3b3bc97 100644 --- a/src/GSendControls/Abstractions/IPluginMenu.cs +++ b/src/GSendControls/Abstractions/IPluginMenu.cs @@ -1,4 +1,6 @@ -using System.Drawing; +using System.Collections.Generic; +using System.Drawing; + using GSendShared.Plugins; namespace GSendControls.Abstractions @@ -38,9 +40,10 @@ public interface IPluginMenu : IPluginItemBase /// /// Shortcut that can be used by the menu /// + /// default keys for shortcut, if available /// /// /// - bool GetShortcut(out string groupName, out string shortcutName); + bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName); } } diff --git a/src/GSendControls/Abstractions/ITextEditor.cs b/src/GSendControls/Abstractions/ITextEditor.cs index d082c26..4e4af16 100644 --- a/src/GSendControls/Abstractions/ITextEditor.cs +++ b/src/GSendControls/Abstractions/ITextEditor.cs @@ -1,12 +1,35 @@ -namespace GSendControls.Abstractions +using System.Drawing; +using System.Windows.Forms; + +namespace GSendControls.Abstractions { /// /// Text Editor interface /// public interface ITextEditor { + IWin32Window Parent { get; } + + Control ParentControl { get; } + + Rectangle ParentRectangle { get; } + + Point ParentDesktopLocation { get; } + void ShowGoToDialog(); + void ShowFindDialog(); + + void ShowReplaceDialog(); + int LineCount { get; } + + string Text { get; set; } + + int SelectionStart { get; } + + int SelectionLength { get; } + + Rectangle Position { get; } } } diff --git a/src/GSendControls/Controls/CollapsablePanel.cs b/src/GSendControls/Controls/CollapsablePanel.cs index 2234b25..fd45c1d 100644 --- a/src/GSendControls/Controls/CollapsablePanel.cs +++ b/src/GSendControls/Controls/CollapsablePanel.cs @@ -93,8 +93,8 @@ public CollapsablePanel() CollapsedColorTo = Color.LightBlue; ExpandColorFrom = Color.LightBlue; ExpandColorTo = Color.DarkBlue; - ExpandImage = Resources.ExpandHorizontal; - CollapseImage = Resources.CollapseHorizonal; + ExpandImage = Properties.Resources.ExpandHorizontal; + CollapseImage = Properties.Resources.CollapseHorizonal; } #endregion Constructors @@ -134,13 +134,13 @@ public Orientation Orientation switch (Orientation) { case Orientation.Horizontal: - ExpandImage = Resources.ExpandHorizontal; - CollapseImage = Resources.CollapseHorizonal; + ExpandImage = Properties.Resources.ExpandHorizontal; + CollapseImage = Properties.Resources.CollapseHorizonal; break; case System.Windows.Forms.Orientation.Vertical: - ExpandImage = Resources.ExpandVertical; - CollapseImage = Resources.CollapseVertical; + ExpandImage = Properties.Resources.ExpandVertical; + CollapseImage = Properties.Resources.CollapseVertical; break; } } @@ -182,13 +182,13 @@ public bool CustomImages switch (Orientation) { case System.Windows.Forms.Orientation.Horizontal: - ExpandImage = Resources.ExpandHorizontal; - CollapseImage = Resources.CollapseHorizonal; + ExpandImage = Properties.Resources.ExpandHorizontal; + CollapseImage = Properties.Resources.CollapseHorizonal; break; case System.Windows.Forms.Orientation.Vertical: - ExpandImage = Resources.ExpandVertical; - CollapseImage = Resources.CollapseVertical; + ExpandImage = Properties.Resources.ExpandVertical; + CollapseImage = Properties.Resources.CollapseVertical; break; } } diff --git a/src/GSendControls/Controls/CollapsablePanel.resx b/src/GSendControls/Controls/CollapsablePanel.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/src/GSendControls/Controls/CollapsablePanel.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/src/GSendControls/JogControl.cs b/src/GSendControls/JogControl.cs index 9bd6115..df646f2 100644 --- a/src/GSendControls/JogControl.cs +++ b/src/GSendControls/JogControl.cs @@ -144,7 +144,7 @@ public List GetShortcuts() [(int)Keys.Control, (int)Keys.PageUp], (bool isKeyDown) => selectionFeed.Value += 100), new ShortcutModel(groupName, GSend.Language.Resources.ShortcutNameDecreaseFeedRate, - [(int) Keys.Control,(int) Keys.PageDown], + [(int)Keys.Control, (int)Keys.PageDown], (bool isKeyDown) => selectionFeed.Value -= 100), new ShortcutModel(groupName, GSend.Language.Resources.ShortcutNameDecreaseStepSize, [(int)Keys.PageDown], @@ -153,34 +153,34 @@ public List GetShortcuts() [(int)Keys.PageUp], (bool isKeyDown) => selectionSteps.Value++), new ShortcutModel(groupName, GSend.Language.Resources.ShortcutNameYplusXMinus, - [(int) Keys.Left,(int) Keys.Up], + [(int)Keys.Left, (int)Keys.Up], (bool isKeyDown) => JogFromKeypress(isKeyDown, JogDirection.XMinusYPlus)), new ShortcutModel(groupName, GSend.Language.Resources.ShortcutNameYPlus, [(int)Keys.Up], (bool isKeyDown) => JogFromKeypress(isKeyDown, JogDirection.YPlus)), new ShortcutModel(groupName, GSend.Language.Resources.ShortcutNameYPlusXPlus, - [(int) Keys.Up,(int) Keys.Right], + [(int)Keys.Up, (int)Keys.Right], (bool isKeyDown) => JogFromKeypress(isKeyDown, JogDirection.XPlusYPlus)), new ShortcutModel(groupName, GSend.Language.Resources.ShortcutNameXPlus, - [(int) Keys.Right], + [(int)Keys.Right], (bool isKeyDown) => JogFromKeypress(isKeyDown, JogDirection.XPlus)), new ShortcutModel(groupName, GSend.Language.Resources.ShortcutNameYMinusXPlus, - [(int) Keys.Down,(int) Keys.Right], + [(int)Keys.Down, (int)Keys.Right], (bool isKeyDown) => JogFromKeypress(isKeyDown, JogDirection.XPlusYMinus)), new ShortcutModel(groupName, GSend.Language.Resources.ShortcutNameYMinus, - [(int) Keys.Down], + [(int)Keys.Down], (bool isKeyDown) => JogFromKeypress(isKeyDown, JogDirection.YMinus)), new ShortcutModel(groupName, GSend.Language.Resources.ShortcutNameYMinusXMinus, - [(int) Keys.Down,(int) Keys.Left], + [(int)Keys.Down, (int)Keys.Left], (bool isKeyDown) => JogFromKeypress(isKeyDown, JogDirection.XMinusYMinus)), new ShortcutModel(groupName, GSend.Language.Resources.ShortcutNameXMinus, [(int)Keys.Left], (bool isKeyDown) => JogFromKeypress(isKeyDown, JogDirection.XMinus)), new ShortcutModel(groupName, GSend.Language.Resources.ShortcutNameZPlus, - [(int) Keys.Control,(int) Keys.Up], + [(int)Keys.Control, (int)Keys.Up], (bool isKeyDown) => JogFromKeypress(isKeyDown, JogDirection.ZPlus)), new ShortcutModel(groupName, GSend.Language.Resources.ShortcutNameZMinus, - [(int) Keys.Control,(int) Keys.Down], + [(int)Keys.Control, (int)Keys.Down], (bool isKeyDown) => JogFromKeypress(isKeyDown, JogDirection.ZMinus)), ]; diff --git a/src/GSendControls/Plugins/InternalPluginMenu.cs b/src/GSendControls/Plugins/InternalPluginMenu.cs index 832179b..93f282b 100644 --- a/src/GSendControls/Plugins/InternalPluginMenu.cs +++ b/src/GSendControls/Plugins/InternalPluginMenu.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using GSendControls.Abstractions; @@ -40,7 +41,7 @@ public void ClientMessageReceived(IClientBaseMessage clientMessage) // only required by interface } - public bool GetShortcut(out string groupName, out string shortcutName) + public bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName) { groupName = String.Empty; shortcutName = String.Empty; diff --git a/src/GSendControls/Plugins/InternalPlugins/HelpMenu/BugsAndIdeasMenu.cs b/src/GSendControls/Plugins/InternalPlugins/HelpMenu/BugsAndIdeasMenu.cs index 8de4661..8f1e503 100644 --- a/src/GSendControls/Plugins/InternalPlugins/HelpMenu/BugsAndIdeasMenu.cs +++ b/src/GSendControls/Plugins/InternalPlugins/HelpMenu/BugsAndIdeasMenu.cs @@ -1,7 +1,10 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.Drawing; + using GSendControls.Abstractions; + using GSendShared; using GSendShared.Plugins; @@ -39,7 +42,7 @@ public void Clicked() Process.Start(psi); } - public bool GetShortcut(out string groupName, out string shortcutName) + public bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName) { groupName = null; shortcutName = null; diff --git a/src/GSendControls/Plugins/InternalPlugins/HelpMenu/HelpMenuItem.cs b/src/GSendControls/Plugins/InternalPlugins/HelpMenu/HelpMenuItem.cs index 312a501..635ca20 100644 --- a/src/GSendControls/Plugins/InternalPlugins/HelpMenu/HelpMenuItem.cs +++ b/src/GSendControls/Plugins/InternalPlugins/HelpMenu/HelpMenuItem.cs @@ -1,7 +1,10 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.Drawing; + using GSendControls.Abstractions; + using GSendShared; using GSendShared.Plugins; @@ -37,7 +40,7 @@ public void Clicked() Process.Start(psi); } - public bool GetShortcut(out string groupName, out string shortcutName) + public bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName) { groupName = null; shortcutName = null; diff --git a/src/GSendControls/Plugins/InternalPlugins/HelpMenu/HomePageMenu.cs b/src/GSendControls/Plugins/InternalPlugins/HelpMenu/HomePageMenu.cs index 7e2f616..94316bb 100644 --- a/src/GSendControls/Plugins/InternalPlugins/HelpMenu/HomePageMenu.cs +++ b/src/GSendControls/Plugins/InternalPlugins/HelpMenu/HomePageMenu.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using GSendControls.Abstractions; @@ -39,7 +40,7 @@ public void Clicked() Process.Start(psi); } - public bool GetShortcut(out string groupName, out string shortcutName) + public bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName) { groupName = null; shortcutName = null; diff --git a/src/GSendControls/Plugins/InternalPlugins/SearchMenu/FindMenuItem.cs b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/FindMenuItem.cs new file mode 100644 index 0000000..97d45b0 --- /dev/null +++ b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/FindMenuItem.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; + +using GSendControls.Abstractions; + +using GSendShared; +using GSendShared.Plugins; + +namespace GSendControls.Plugins.InternalPlugins.SearchMenu +{ + internal class FindMenuItem : IPluginMenu + { + private readonly ITextEditor _textEditor; + + public FindMenuItem(IPluginMenu parentMenu, ITextEditor textBox) + { + ParentMenu = parentMenu ?? throw new ArgumentNullException(nameof(parentMenu)); + _textEditor = textBox ?? throw new ArgumentNullException(nameof(textBox)); + } + + public Image MenuImage => null; + + public MenuType MenuType => MenuType.MenuItem; + + public IPluginMenu ParentMenu { get; private set; } + + public string Text => GSend.Language.Resources.FindMenu; + + public int Index => 0; + + public bool ReceiveClientMessages => false; + + public void Clicked() + { + _textEditor.ShowFindDialog(); + } + + public void ClientMessageReceived(IClientBaseMessage clientMessage) + { + throw new NotImplementedException(); + } + + public bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName) + { + groupName = "Search Menu"; + shortcutName = "Find"; + defaultKeys.Add((int)Keys.Control); + defaultKeys.Add((int)Keys.F); + return true; + } + + public bool IsChecked() + { + return false; + } + + public bool IsEnabled() + { + return _textEditor.Text.Length > 0; + } + + public bool IsVisible() + { + return true; + } + + public void UpdateHost(T senderPluginHost) + { + // from interface, not used in this context + } + } +} diff --git a/src/GSendControls/Plugins/InternalPlugins/SearchMenu/GotoMenuItem.cs b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/GotoMenuItem.cs index 551f8b6..3da05f4 100644 --- a/src/GSendControls/Plugins/InternalPlugins/SearchMenu/GotoMenuItem.cs +++ b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/GotoMenuItem.cs @@ -1,8 +1,7 @@ using System; +using System.Collections.Generic; using System.Drawing; -using FastColoredTextBoxNS; - using GSendControls.Abstractions; using GSendShared; @@ -28,13 +27,13 @@ public GotoMenuItem(IPluginMenu parentMenu, ITextEditor textBox) public string Text => GSend.Language.Resources.GotoLineNumberMenu; - public int Index => 0; + public int Index => 20; public bool ReceiveClientMessages => false; public void Clicked() { - _textEditor?.ShowGoToDialog(); + _textEditor.ShowGoToDialog(); } public void ClientMessageReceived(IClientBaseMessage clientMessage) @@ -42,7 +41,7 @@ public void ClientMessageReceived(IClientBaseMessage clientMessage) throw new NotImplementedException(); } - public bool GetShortcut(out string groupName, out string shortcutName) + public bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName) { groupName = null; shortcutName = null; @@ -56,7 +55,7 @@ public bool IsChecked() public bool IsEnabled() { - return _textEditor?.LineCount > 0; + return _textEditor.LineCount > 0; } public bool IsVisible() diff --git a/src/GSendControls/Plugins/InternalPlugins/SearchMenu/ReplaceMenuItem.cs b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/ReplaceMenuItem.cs new file mode 100644 index 0000000..14236eb --- /dev/null +++ b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/ReplaceMenuItem.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; + +using GSendControls.Abstractions; + +using GSendShared; +using GSendShared.Plugins; + +namespace GSendControls.Plugins.InternalPlugins.SearchMenu +{ + internal class ReplaceMenuItem : IPluginMenu + { + private readonly ITextEditor _textEditor; + + public ReplaceMenuItem(IPluginMenu parentMenu, ITextEditor textBox) + { + ParentMenu = parentMenu ?? throw new ArgumentNullException(nameof(parentMenu)); + _textEditor = textBox ?? throw new ArgumentNullException(nameof(textBox)); + } + + public Image MenuImage => null; + + public MenuType MenuType => MenuType.MenuItem; + + public IPluginMenu ParentMenu { get; private set; } + + public string Text => GSend.Language.Resources.ReplaceMenu; + + public int Index => 1; + + public bool ReceiveClientMessages => false; + + public void Clicked() + { + _textEditor.ShowReplaceDialog(); + } + + public void ClientMessageReceived(IClientBaseMessage clientMessage) + { + throw new NotImplementedException(); + } + + public bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName) + { + groupName = "Search Menu"; + shortcutName = "Replace"; + defaultKeys.Add((int)Keys.Control); + defaultKeys.Add((int)Keys.R); + return true; + } + + public bool IsChecked() + { + return false; + } + + public bool IsEnabled() + { + return _textEditor.Text.Length > 0; + } + + public bool IsVisible() + { + return true; + } + + public void UpdateHost(T senderPluginHost) + { + // from interface, not used in this context + } + } +} diff --git a/src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuItem.cs b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuItem.cs index e712cce..1335046 100644 --- a/src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuItem.cs +++ b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuItem.cs @@ -1,4 +1,4 @@ -using System; +using System.Collections.Generic; using System.Drawing; using GSendControls.Abstractions; @@ -32,7 +32,7 @@ public void ClientMessageReceived(IClientBaseMessage clientMessage) // from interface, not used in this context } - public bool GetShortcut(out string groupName, out string shortcutName) + public bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName) { groupName = null; shortcutName = null; diff --git a/src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuPlugin.cs b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuPlugin.cs index ee57f0c..49c80e9 100644 --- a/src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuPlugin.cs +++ b/src/GSendControls/Plugins/InternalPlugins/SearchMenu/SearchMenuPlugin.cs @@ -27,10 +27,13 @@ public IReadOnlyList MenuItems { if (_pluginMenus == null) { - SearchMenuItem searchMenuItem = new SearchMenuItem(); + SearchMenuItem searchMenuItem = new(); _pluginMenus = [ searchMenuItem, + new FindMenuItem(searchMenuItem, _pluginHost.Editor), + new ReplaceMenuItem(searchMenuItem, _pluginHost.Editor), + new SeperatorMenu(searchMenuItem, 19), new GotoMenuItem(searchMenuItem, _pluginHost.Editor) ]; } diff --git a/src/GSendControls/Plugins/InternalPlugins/ServerMenu/ConfigureServerMenuItem.cs b/src/GSendControls/Plugins/InternalPlugins/ServerMenu/ConfigureServerMenuItem.cs index eef4d5c..61f131c 100644 --- a/src/GSendControls/Plugins/InternalPlugins/ServerMenu/ConfigureServerMenuItem.cs +++ b/src/GSendControls/Plugins/InternalPlugins/ServerMenu/ConfigureServerMenuItem.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using GSendControls.Abstractions; using GSendControls.Forms; @@ -42,7 +43,7 @@ public void ClientMessageReceived(IClientBaseMessage clientMessage) } - public bool GetShortcut(out string groupName, out string shortcutName) + public bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName) { groupName = String.Empty; shortcutName = String.Empty; diff --git a/src/GSendControls/Plugins/InternalPlugins/ServerMenu/ServerRootMenuItem.cs b/src/GSendControls/Plugins/InternalPlugins/ServerMenu/ServerRootMenuItem.cs index 75dc897..5d80d21 100644 --- a/src/GSendControls/Plugins/InternalPlugins/ServerMenu/ServerRootMenuItem.cs +++ b/src/GSendControls/Plugins/InternalPlugins/ServerMenu/ServerRootMenuItem.cs @@ -1,6 +1,9 @@ using System; +using System.Collections.Generic; using System.Drawing; + using GSendControls.Abstractions; + using GSendShared; using GSendShared.Plugins; @@ -30,7 +33,7 @@ public void ClientMessageReceived(IClientBaseMessage clientMessage) } - public bool GetShortcut(out string groupName, out string shortcutName) + public bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName) { groupName = String.Empty; shortcutName = String.Empty; diff --git a/src/GSendControls/Plugins/InternalPlugins/ServerMenu/ServerSelectMenuItem.cs b/src/GSendControls/Plugins/InternalPlugins/ServerMenu/ServerSelectMenuItem.cs index 1a7f189..a0d1f37 100644 --- a/src/GSendControls/Plugins/InternalPlugins/ServerMenu/ServerSelectMenuItem.cs +++ b/src/GSendControls/Plugins/InternalPlugins/ServerMenu/ServerSelectMenuItem.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using GSendApi; @@ -21,7 +22,7 @@ public ServerSelectMenuItem(IPluginMenu parentMenu, int index, IGSendApiWrapper ParentMenu = parentMenu ?? throw new ArgumentNullException(nameof(parentMenu)); Index = index; } - + public Image MenuImage => null; public MenuType MenuType => MenuType.MenuItem; @@ -44,7 +45,7 @@ public void ClientMessageReceived(IClientBaseMessage clientMessage) } - public bool GetShortcut(out string groupName, out string shortcutName) + public bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName) { groupName = String.Empty; shortcutName = String.Empty; diff --git a/src/GSendControls/Plugins/PluginHelper.cs b/src/GSendControls/Plugins/PluginHelper.cs index b9742d2..e998ba1 100644 --- a/src/GSendControls/Plugins/PluginHelper.cs +++ b/src/GSendControls/Plugins/PluginHelper.cs @@ -241,9 +241,10 @@ private void CreateStandardMenuItem(int maximumMenuIndex, IPluginMenu menu, Tool } }; - if (shortcuts != null && menu.GetShortcut(out string groupName, out string shortcutName)) + List defaultKeys = []; + if (shortcuts != null && menu.GetShortcut(defaultKeys, out string groupName, out string shortcutName)) { - shortcuts.Add(new ShortcutModel(groupName, shortcutName, [], + shortcuts.Add(new ShortcutModel(groupName, shortcutName, defaultKeys, (isKeyDown) => { if (isKeyDown && menu.IsEnabled()) menu.Clicked(); }, (List keys) => UpdateMenuShortCut(pluginMenu, keys))); } diff --git a/src/GSendControls/Plugins/SeperatorMenu.cs b/src/GSendControls/Plugins/SeperatorMenu.cs index 7f7a299..c8ea3d1 100644 --- a/src/GSendControls/Plugins/SeperatorMenu.cs +++ b/src/GSendControls/Plugins/SeperatorMenu.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using GSendControls.Abstractions; @@ -33,7 +34,7 @@ public void Clicked() throw new NotImplementedException(); } - public bool GetShortcut(out string groupName, out string shortcutName) + public bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName) { groupName = null; shortcutName = null; diff --git a/src/GSendControls/Properties/Resources.Designer.cs b/src/GSendControls/Properties/Resources.Designer.cs index 9facd12..8606ee1 100644 --- a/src/GSendControls/Properties/Resources.Designer.cs +++ b/src/GSendControls/Properties/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace GSendControls { +namespace GSendControls.Properties { using System; @@ -19,7 +19,7 @@ namespace GSendControls { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -39,7 +39,7 @@ internal Resources() { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SharedControls.Properties.Resources", typeof(Resources).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GSendControls.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; @@ -119,5 +119,15 @@ internal static System.Drawing.Bitmap fb1 { return ((System.Drawing.Bitmap)(obj)); } } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap NextArrow { + get { + object obj = ResourceManager.GetObject("NextArrow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } } } diff --git a/src/GSendControls/Properties/Resources.resx b/src/GSendControls/Properties/Resources.resx index 8dfc6d0..23ad573 100644 --- a/src/GSendControls/Properties/Resources.resx +++ b/src/GSendControls/Properties/Resources.resx @@ -121,19 +121,22 @@ ..\Resources\CollapseHorizonal.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\resources\fb1.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\CollapseVertical.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\ExpandHorizontal.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\resources\fb.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\ExpandVertical.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\resources\fb.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\ExpandHorizontal.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\resources\fb1.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\NextArrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/src/GSendControls/Resources/NextArrow.png b/src/GSendControls/Resources/NextArrow.png new file mode 100644 index 0000000000000000000000000000000000000000..1dc95e7bf89b625f08b7d60e041caf31415510c0 GIT binary patch literal 184 zcmeAS@N?(olHy`uVBq!ia0vp^;vmey1|%P7U0DF67>k44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h7I;J!GcfQS24TkI`72U@g1(+Ejv*f2Z_hb$F(`1j1ir7&JnZYyBfMhk zr^eYU@)z;@%FMC|>FWOQ{HaCs1)+YiH^KFW*2}N$=>7iuxui}`)T4<-b2N|UtMU2D a1jMdPta;Y5T+jh%FoUP7pUXO@geCw|YdpUI literal 0 HcmV?d00001 diff --git a/src/GSendEditor/FrmMain.cs b/src/GSendEditor/FrmMain.cs index 88425b8..6c9a236 100644 --- a/src/GSendEditor/FrmMain.cs +++ b/src/GSendEditor/FrmMain.cs @@ -1,7 +1,5 @@ using System.Text; -using FastColoredTextBoxNS; - using GSendApi; using GSendCommon; @@ -56,7 +54,7 @@ public FrmMain(IGSendContext gSendContext) _gsendApiWrapper.ServerUriChanged += GsendApiWrapper_ServerUriChanged; _pluginHelper = _gSendContext.ServiceProvider.GetRequiredService(); InitializeComponent(); - _textEditorBridge = new(txtGCode); + _textEditorBridge = new(this, txtGCode); _serverBasedSubPrograms = new ServerBasedSubPrograms(_gsendApiWrapper); CreateAnalyzerThread(gSendContext.ServiceProvider.GetService(), _serverBasedSubPrograms); @@ -1228,7 +1226,7 @@ public void AddPlugin(IGSendPluginModule pluginModule) public void AddMenu(IPluginMenu pluginMenu) { pluginMenu.UpdateHost(this as IEditorPluginHost); - _pluginHelper.AddMenu(this, menuStripMain, pluginMenu, null); + _pluginHelper.AddMenu(this, menuStripMain, pluginMenu, _shortcuts); } public void AddToolbar(IPluginToolbarButton toolbarButton) diff --git a/src/GSendEditor/Internal/TextEditorBridge.cs b/src/GSendEditor/Internal/TextEditorBridge.cs index e16ccee..8166135 100644 --- a/src/GSendEditor/Internal/TextEditorBridge.cs +++ b/src/GSendEditor/Internal/TextEditorBridge.cs @@ -1,19 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using GSendControls.Abstractions; +using GSendControls.Abstractions; namespace GSendEditor.Internal { internal class TextEditorBridge : ITextEditor { + private readonly Form _parentForm; private readonly FastColoredTextBoxNS.FastColoredTextBox _textBox; - public TextEditorBridge(FastColoredTextBoxNS.FastColoredTextBox textBox) + public TextEditorBridge(Form parentForm, FastColoredTextBoxNS.FastColoredTextBox textBox) { + _parentForm = parentForm ?? throw new ArgumentNullException(nameof(parentForm)); _textBox = textBox ?? throw new ArgumentNullException(nameof(textBox)); } @@ -22,10 +18,37 @@ public TextEditorBridge(FastColoredTextBoxNS.FastColoredTextBox textBox) public void ShowGoToDialog() { _textBox.ShowGoToDialog(); + _textBox.Focus(); + } + + public void ShowFindDialog() + { + _textBox.ShowFindDialog(); + } + + public void ShowReplaceDialog() + { + _textBox.ShowReplaceDialog(); } public int LineCount => _textBox.Lines.Count; + public string Text { get => _textBox.Text; set => _textBox.Text = value; } + + public int SelectionStart => _textBox.SelectionStart; + + public int SelectionLength => _textBox.SelectionLength; + + public Rectangle Position => new(_textBox.Location, _textBox.Size); + + public IWin32Window Parent => _textBox.Parent; + + public Rectangle ParentRectangle => _parentForm.ClientRectangle; + + public Point ParentDesktopLocation => _parentForm.PointToScreen(_parentForm.DesktopLocation); + + public Control ParentControl => _textBox.Parent; + #endregion ITextEditor } } diff --git a/src/Plugins/GrblTuning/TuningWizardMenuItem.cs b/src/Plugins/GrblTuning/TuningWizardMenuItem.cs index 8aa1278..a90ec11 100644 --- a/src/Plugins/GrblTuning/TuningWizardMenuItem.cs +++ b/src/Plugins/GrblTuning/TuningWizardMenuItem.cs @@ -2,6 +2,7 @@ using GSendControls; using GSendControls.Abstractions; + using GSendShared; using GSendShared.Models; using GSendShared.Plugins; @@ -132,7 +133,7 @@ public void UpdateHost(T senderPluginHost) _wizardSettings = new TuningWizardSettings(_senderPluginHost); } - public bool GetShortcut(out string groupName, out string shortcutName) + public bool GetShortcut(in List defaultKeys, out string groupName, out string shortcutName) { groupName = GSend.Language.Resources.ShortcutMenuTools; shortcutName = GSend.Language.Resources.TuneWizard; diff --git a/wwwroot/Controllers/MCodesController.cs b/wwwroot/Controllers/MCodesController.cs index 6e893ef..342fd15 100644 --- a/wwwroot/Controllers/MCodesController.cs +++ b/wwwroot/Controllers/MCodesController.cs @@ -14,9 +14,9 @@ public class MCodesController : BaseController { public const string MCodes = "MCodes"; - private static readonly string[] _validMCodes = { - "M600", "M601", "M602", "M605", "M620", "M621", - "M622", "M623", "M630", "M630.1", "M631", + private static readonly string[] _validMCodes = { + "M600", "M601", "M602", "M605", "M620", "M621", + "M622", "M623", "M630", "M630.1", "M631", "M631.1", "M631.2" }; private static readonly Dictionary _seeAlso = new()