Skip to content

Commit

Permalink
Add hourglass when changing server and all server specific analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
k3ldar committed Dec 21, 2023
1 parent 6a4fdf4 commit 0fab7f7
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 9 deletions.
18 changes: 16 additions & 2 deletions src/GSendEditor/FrmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions src/GSendEditor/FrmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public partial class FrmMain : BaseForm, IShortcutImplementation, IEditorPluginH
private readonly object _updateSubprogramsLock = new();
private readonly IGSendContext _gSendContext;
private readonly IGSendApiWrapper _gsendApiWrapper;
private readonly ServerBasedSubPrograms _serverBasedSubPrograms;
private AnalyzerThread _analyzerThread = null;
private ISubprogram _subProgram;
private readonly RecentFiles _recentFiles;
Expand All @@ -54,8 +55,9 @@ public FrmMain(IGSendContext gSendContext)
_gsendApiWrapper.ServerUriChanged += GsendApiWrapper_ServerUriChanged;
_pluginHelper = _gSendContext.ServiceProvider.GetRequiredService<IPluginHelper>();
InitializeComponent();
_serverBasedSubPrograms = new ServerBasedSubPrograms(_gsendApiWrapper);
CreateAnalyzerThread(gSendContext.ServiceProvider.GetService<IGCodeParserFactory>(),
_gSendContext.ServiceProvider.GetRequiredService<ISubprograms>());
_serverBasedSubPrograms);
txtGCode.SyntaxHighlighter = new GCodeSyntaxHighLighter(txtGCode);

machine2dView1.UnloadGCode();
Expand Down Expand Up @@ -100,11 +102,17 @@ private void CreateAnalyzerThread(IGCodeParserFactory gCodeParserFactory, ISubpr
_analyzerThread.OnAddItem -= AnalyzerThread_OnAddItem;
_analyzerThread.OnRemoveItem -= AnalyzerThread_OnRemoveItem;
_analyzerThread.CancelThread();

while (ThreadManager.Exists(_analyzerThread.Name))
Thread.Sleep(20);
}

_analyzerThread = new AnalyzerThread(gCodeParserFactory, subprograms, txtGCode);
_analyzerThread.OnAddItem += AnalyzerThread_OnAddItem;
_analyzerThread.OnRemoveItem += AnalyzerThread_OnRemoveItem;

CreateAndRunAnalyzerThread();
_analyzerThread.AnalyzerUpdated();
}

public IGSendApiWrapper ApiWrapper => _gsendApiWrapper;
Expand Down Expand Up @@ -1003,10 +1011,13 @@ private void tmrUpdateSubprograms_Tick(object sender, EventArgs e)

private void GsendApiWrapper_ServerUriChanged()
{
_validationThread.ValidateConnection();
_analyzerThread.AnalyzerUpdated();
CreateAnalyzerThread(_gSendContext.ServiceProvider.GetService<IGCodeParserFactory>(),
_gSendContext.ServiceProvider.GetRequiredService<ISubprograms>());
using (MouseControl mc = MouseControl.ShowWaitCursor(this))
{
_validationThread.ValidateConnection();
_analyzerThread.AnalyzerUpdated();
CreateAnalyzerThread(_gSendContext.ServiceProvider.GetService<IGCodeParserFactory>(),
_serverBasedSubPrograms);
}
}

#region Shortcuts
Expand Down
7 changes: 5 additions & 2 deletions src/GSendEditor/FrmMain.resx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
<metadata name="contextMenuStripEditor.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>640, 17</value>
</metadata>
<data name="txtGCode.Hotkeys" xml:space="preserve">
<value>Tab=IndentIncrease, Escape=ClearHints, PgUp=GoPageUp, PgDn=GoPageDown, End=GoEnd, Home=GoHome, Left=GoLeft, Up=GoUp, Right=GoRight, Down=GoDown, Insert=ReplaceMode, Del=DeleteCharRight, F3=FindNext, Shift+Tab=IndentDecrease, Shift+PgUp=GoPageUpWithSelection, Shift+PgDn=GoPageDownWithSelection, Shift+End=GoEndWithSelection, Shift+Home=GoHomeWithSelection, Shift+Left=GoLeftWithSelection, Shift+Up=GoUpWithSelection, Shift+Right=GoRightWithSelection, Shift+Down=GoDownWithSelection, Shift+Insert=Paste, Shift+Del=Cut, Ctrl+Back=ClearWordLeft, Ctrl+Space=AutocompleteMenu, Ctrl+End=GoLastLine, Ctrl+Home=GoFirstLine, Ctrl+Left=GoWordLeft, Ctrl+Up=ScrollUp, Ctrl+Right=GoWordRight, Ctrl+Down=ScrollDown, Ctrl+Insert=Copy, Ctrl+Del=ClearWordRight, Ctrl+0=ZoomNormal, Ctrl+A=SelectAll, Ctrl+B=BookmarkLine, Ctrl+C=Copy, Ctrl+E=MacroExecute, Ctrl+F=FindDialog, Ctrl+G=GoToDialog, Ctrl+H=ReplaceDialog, Ctrl+I=AutoIndentChars, Ctrl+M=MacroRecord, Ctrl+N=GoNextBookmark, Ctrl+R=Redo, Ctrl+U=UpperCase, Ctrl+V=Paste, Ctrl+X=Cut, Ctrl+Z=Undo, Ctrl+Add=ZoomIn, Ctrl+Subtract=ZoomOut, Ctrl+OemMinus=NavigateBackward, Ctrl+Shift+End=GoLastLineWithSelection, Ctrl+Shift+Home=GoFirstLineWithSelection, Ctrl+Shift+Left=GoWordLeftWithSelection, Ctrl+Shift+Right=GoWordRightWithSelection, Ctrl+Shift+B=UnbookmarkLine, Ctrl+Shift+C=CommentSelected, Ctrl+Shift+N=GoPrevBookmark, Ctrl+Shift+U=LowerCase, Ctrl+Shift+OemMinus=NavigateForward, Alt+Back=Undo, Alt+Up=MoveSelectedLinesUp, Alt+Down=MoveSelectedLinesDown, Alt+F=FindChar, Alt+Shift+Left=GoLeft_ColumnSelectionMode, Alt+Shift+Up=GoUp_ColumnSelectionMode, Alt+Shift+Right=GoRight_ColumnSelectionMode, Alt+Shift+Down=GoDown_ColumnSelectionMode</value>
</data>
<data name="txtGCode.ServiceColors" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAERGYXN0Q29sb3JlZFRleHRCb3gsIEN1bHR1cmU9bmV1dHJhbCwg
Expand All @@ -166,7 +169,7 @@
<data name="machine2dView1.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAQoAA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CAAH/ATMDAAFmAwABmQMAAcwCAAEzAwAC
Expand Down
88 changes: 88 additions & 0 deletions src/GSendEditor/Internal/ServerBasedSubPrograms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using GSendApi;

using GSendShared;

namespace GSendEditor.Internal
{
internal sealed class ServerBasedSubPrograms : ISubprograms
{
private List<ISubprogram> _subPrograms;
private readonly IGSendApiWrapper _gSendApiWrapper;

public ServerBasedSubPrograms(IGSendApiWrapper gSendApiWrapper)
{
_gSendApiWrapper = gSendApiWrapper ?? throw new ArgumentNullException(nameof(gSendApiWrapper));
_gSendApiWrapper.ServerUriChanged += GSendApiWrapper_ServerUriChanged;
}

public bool Delete(string name)
{
try
{
if (_subPrograms == null)
_ = GetAll();

return _gSendApiWrapper.SubprogramDelete(name);
}
catch
{
return false;
}
}

public bool Exists(string name)
{
try
{
if (_subPrograms == null)
_ = GetAll();

return _subPrograms?.Exists(s => s.Name.Equals(name)) ?? false;
}
catch
{
return false;
}
}

public ISubprogram Get(string name)
{
try
{
if (_subPrograms == null)
_ = GetAll();

return _subPrograms?.Find(s => s.Name.Equals(name));
}
catch
{
return null;
}
}

public List<ISubprogram> GetAll()
{
_subPrograms = _gSendApiWrapper.SubprogramGet();

return _subPrograms ?? new();
}

public bool Update(ISubprogram subProgram)
{
try
{
_subPrograms = null;
return _gSendApiWrapper.SubprogramUpdate(subProgram);
}
catch
{
return false;
}
}

private void GSendApiWrapper_ServerUriChanged()
{
_subPrograms = null;
}
}
}

0 comments on commit 0fab7f7

Please sign in to comment.