Skip to content

Commit

Permalink
Updates from analyzers and get ready for adding controls to hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
k3ldar committed Jan 10, 2024
1 parent c83f118 commit 690dd9c
Show file tree
Hide file tree
Showing 25 changed files with 124 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM600Pause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (m600Commands.Count == 0)
return;

if (m600Commands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
foreach (IGCodeCommand command in m600Commands)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM601Timeout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (m601Commands.Count == 0)
return;

if (m601Commands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
foreach (IGCodeCommand command in m601Commands)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM605PlaySounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (m605Commands.Count == 0)
return;

if (m605Commands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
if (!gCodeAnalyses.AnalysesOptions.HasFlag(AnalysesOptions.PlaySound))
codeAnalyses.AddOptions(AnalysesOptions.PlaySound);
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM630RunProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (m630Commands.Count == 0)
return;

if (m630Commands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
if (!gCodeAnalyses.AnalysesOptions.HasFlag(AnalysesOptions.RunProgram))
codeAnalyses.AddOptions(AnalysesOptions.RunProgram);
Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM630_1RunParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (mCommands.Count == 0)
return;

if (mCommands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
List<int> lineNumbers = [];

Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM631_1RunParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (mCommands.Count == 0)
return;

if (mCommands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
List<int> lineNumbers = [];

Expand Down
2 changes: 1 addition & 1 deletion src/GCAAnalyser/Analyzers/AnalyzeM631_2ReturnCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Analyze(string fileName, IGCodeAnalyses gCodeAnalyses)
if (mCommands.Count == 0)
return;

if (mCommands.Count > 0 && gCodeAnalyses is GCodeAnalyses codeAnalyses)
if (gCodeAnalyses is GCodeAnalyses codeAnalyses)
{
foreach (IGCodeCommand command in mCommands)
{
Expand Down
5 changes: 5 additions & 0 deletions src/GCATests/Mocks/MockEditorPluginHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public MockEditorPluginHost()

public IGSendContext GSendContext => throw new NotImplementedException();

public void AddControl(IPluginControl pluginControl)
{
throw new NotImplementedException();
}

public void AddMenu(IPluginMenu pluginMenu)
{
throw new NotImplementedException();
Expand Down
5 changes: 5 additions & 0 deletions src/GCATests/Mocks/MockSenderPluginHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public void SendMessage(string message)
Messages.Add(message);
}

public void AddControl(IPluginControl pluginControl)
{
throw new NotImplementedException();
}

public IGSendContext GSendContext => throw new NotImplementedException();
}
}
9 changes: 7 additions & 2 deletions src/GCSDesktop/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ public void UpdateOnlineStatus(bool isOnline, string server)
toolStripStatusConnected.Text = statusText;
}

#region ISenderPluginHost
#region IPluginHost

public PluginHosts Host => PluginHosts.SenderHost;

Expand Down Expand Up @@ -608,11 +608,16 @@ public void AddToolbar(IPluginToolbarButton toolbarButton)
_pluginHelper.AddToolbarButton(this, toolStripMain, toolbarButton);
}

public void AddControl(IPluginControl pluginControl)
{
// nothing to do here yet!
}

public void AddMessage(InformationType informationType, string message)
{
throw new InvalidOperationException();
}

#endregion ISenderPluginHost
#endregion IPluginHost
}
}
9 changes: 7 additions & 2 deletions src/GCSDesktop/Forms/FrmMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2654,7 +2654,7 @@ public List<IShortcut> GetShortcuts()

#endregion Shortcuts

#region ISenderPluginHost
#region IPluginHost

public PluginHosts Host => PluginHosts.Sender;

Expand Down Expand Up @@ -2714,6 +2714,11 @@ public void AddToolbar(IPluginToolbarButton toolbarButton)
_pluginsWithClientMessages.Add(toolbarButton);
}

public void AddControl(IPluginControl pluginControl)
{
// nothing to do here yet!
}

public void SendMessage(string message)
{
InternalSendMessage(message);
Expand All @@ -2735,6 +2740,6 @@ public void AddMessage(InformationType informationType, string message)

public IMachine GetMachine() => _machine;

#endregion ISenderPluginHost
#endregion IPluginHost
}
}
11 changes: 10 additions & 1 deletion src/GCSShared/Plugins/PluginEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public enum PluginOptions

HasToolbarButtons = 4,

MessageReceived = 8,
HasControls = 8,

MessageReceived = 8192,
}

/// <summary>
Expand Down Expand Up @@ -83,4 +85,11 @@ public enum ButtonType

Button
}

public enum ControlLocation
{
Primary,

Secondary,
}
}
8 changes: 8 additions & 0 deletions src/GSendControls/Abstractions/IGSendPluginModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,16 @@ public interface IGSendPluginModule
/// </summary>
IReadOnlyList<IPluginMenu> MenuItems { get; }

/// <summary>
/// Toolbar items to be displayed within the host
/// </summary>
IReadOnlyList<IPluginToolbarButton> ToolbarItems { get; }

/// <summary>
/// Controls to be displayed within host
/// </summary>
IReadOnlyList<IPluginControl> ControlItems { get; }

void ClientMessageReceived(IClientBaseMessage clientBaseMessage);
}
}
15 changes: 15 additions & 0 deletions src/GSendControls/Abstractions/IPluginControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using GSendControls.Controls;

using GSendShared.Plugins;

namespace GSendControls.Abstractions
{
public interface IPluginControl
{
string Name { get; }

PluginControl Control { get; }

ControlLocation Location { get; }
}
}
2 changes: 2 additions & 0 deletions src/GSendControls/Abstractions/IPluginHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface IPluginHost

void AddToolbar(IPluginToolbarButton toolbarButton);

void AddControl(IPluginControl pluginControl);

void AddMessage(InformationType informationType, string message);

void AddPlugin(IGSendPluginModule pluginModule);
Expand Down
13 changes: 13 additions & 0 deletions src/GSendControls/Controls/PluginControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GSendControls.Controls
{
public class PluginControl : BaseControl
{

}
}
5 changes: 4 additions & 1 deletion src/GSendControls/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
[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 = "<Pending>", 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")]
[assembly: SuppressMessage("Major Code Smell", "S1168:Empty arrays and collections should be returned instead of null", Justification = "Null is fine and by design", Scope = "member", Target = "~P:GSendControls.Plugins.InternalPlugins.SearchMenu.SearchMenuPlugin.ToolbarItems")]
[assembly: SuppressMessage("Major Code Smell", "S1168:Empty arrays and collections should be returned instead of null", Justification = "Null is fine and by design", Scope = "member", Target = "~P:GSendControls.Plugins.InternalPlugins.HelpMenu.HelpMenuPlugin.ControlItems")]
[assembly: SuppressMessage("Major Code Smell", "S1168:Empty arrays and collections should be returned instead of null", Justification = "Null is fine and by design", Scope = "member", Target = "~P:GSendControls.Plugins.InternalPlugins.SearchMenu.SearchMenuPlugin.ControlItems")]
[assembly: SuppressMessage("Major Code Smell", "S1168:Empty arrays and collections should be returned instead of null", Justification = "Null is fine and by design", Scope = "member", Target = "~P:GSendControls.Plugins.InternalPlugins.ServerMenu.ServerMenuPlugin.ControlItems")]
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public IReadOnlyList<IPluginMenu> MenuItems

public IReadOnlyList<IPluginToolbarButton> ToolbarItems => null;

public IReadOnlyList<IPluginControl> ControlItems => null;

public void ClientMessageReceived(IClientBaseMessage clientBaseMessage)
{
// from interface, not used in any context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public IReadOnlyList<IPluginMenu> MenuItems

public IReadOnlyList<IPluginToolbarButton> ToolbarItems => null;

public IReadOnlyList<IPluginControl> ControlItems => null;

public void ClientMessageReceived(IClientBaseMessage clientBaseMessage)
{
// from interface, not used in this context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public IReadOnlyList<IPluginMenu> MenuItems

public IReadOnlyList<IPluginToolbarButton> ToolbarItems => null;

public IReadOnlyList<IPluginControl> ControlItems => null;

public void ClientMessageReceived(IClientBaseMessage clientBaseMessage)
{
// from interface, not used in this context
Expand Down
14 changes: 14 additions & 0 deletions src/GSendControls/Plugins/PluginHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ public void InitializeAllPlugins(IPluginHost pluginHost)
}
}

if (plugin.Options.HasFlag(PluginOptions.HasControls))
{
if (plugin.ControlItems == null)
throw new InvalidOperationException("Controls can not be null if HasControls option is used");

foreach (IPluginControl pluginControl in plugin.ControlItems)
{
if (pluginControl == null)
continue;

pluginHost.AddControl(pluginControl);
}
}

pluginHost.AddPlugin(plugin);
_logger.AddToLog(PluginManager.LogLevel.PluginLoadSuccess, $"{plugin.Name} was loaded for host {pluginHost}");
}
Expand Down
9 changes: 7 additions & 2 deletions src/GSendEditor/FrmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ public List<IShortcut> GetShortcuts()

#endregion Shortcuts

#region ISenderPluginHost
#region IPluginHost

public PluginHosts Host => PluginHosts.Editor;

Expand Down Expand Up @@ -1235,12 +1235,17 @@ public void AddToolbar(IPluginToolbarButton toolbarButton)
_pluginHelper.AddToolbarButton(this, toolbarMain, toolbarButton);
}

public void AddControl(IPluginControl pluginControl)
{
// nothing to do here yet!
}

public void AddMessage(InformationType informationType, string message)
{
throw new InvalidOperationException();
}

#endregion ISenderPluginHost
#endregion IPluginHost

#region IEditorPluginHost

Expand Down
3 changes: 2 additions & 1 deletion src/Plugins/GrblTuning/GSendProTuningWizardPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ public IReadOnlyList<IPluginMenu> MenuItems
}
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S1168:Empty arrays and collections should be returned instead of null", Justification = "Expecting null if non available")]
public IReadOnlyList<IPluginToolbarButton> ToolbarItems => null;

public IReadOnlyList<IPluginControl> ControlItems => null;

public void ClientMessageReceived(IClientBaseMessage clientBaseMessage)
{

Expand Down
9 changes: 9 additions & 0 deletions src/Plugins/GrblTuning/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Major Code Smell", "S1168:Empty arrays and collections should be returned instead of null", Justification = "Null is fine and by design", Scope = "member", Target = "~P:GrblTuningWizard.GSendProTuningWizardPlugin.ControlItems")]
[assembly: SuppressMessage("Major Code Smell", "S1168:Empty arrays and collections should be returned instead of null", Justification = "Null is fine and by design", Scope = "member", Target = "~P:GrblTuningWizard.GSendProTuningWizardPlugin.ToolbarItems")]
6 changes: 3 additions & 3 deletions wwwroot/Controllers/MCodesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public class MCodesController : BaseController
{
public const string MCodes = "MCodes";

private static readonly string[] _validMCodes = {
private static readonly string[] _validMCodes = [
"M600", "M601", "M602", "M605", "M620", "M621",
"M622", "M623", "M630", "M630.1", "M631",
"M631.1", "M631.2" };
"M631.1", "M631.2" ];

private static readonly Dictionary<string, decimal[]> _seeAlso = new()
{
Expand Down Expand Up @@ -52,7 +52,7 @@ public IActionResult MCode(string mCode)

bool seeAlsoExists = _seeAlso.TryGetValue(mCode, out _);
MCodeModel mCodeModel = new(GetModelData(), mCode, menuData,
seeAlsoExists ? _seeAlso[mCode] : Array.Empty<decimal>());
seeAlsoExists ? _seeAlso[mCode] : []);
mCodeModel.Breadcrumbs.Add(new BreadcrumbItem(GSend.Language.Resources.BreadcrumbMCodes, "/MCodes/Index", false));
mCodeModel.Breadcrumbs.Add(new BreadcrumbItem(mCode, $"/MCodes/{mCode}/", false));

Expand Down

0 comments on commit 690dd9c

Please sign in to comment.