Ok that solution is really bad! injectManualCommand is required for side commands to be injected correctly to a print like M105 queries. Plus it is not handled as print job.
The host function
void LoadGCodeOrSTL(string file);
would load a new gcode named in file to editor and switch to preview tab.
But it gets even easier. Host function
IGCodeEditor GCodeEditor { get; }
gives you direct access to the editor content. That way you can also modify the code without reloading. See editor interface:
public interface IGCodeEditor
{
event EventHandler ShowModeChanged;
event EventHandler ShowMinLayerChanged;
event EventHandler ShowMaxLayerChanged;
event EventHandler MaxLayerChanged;
void AppendLine(string l);
void Clear();
void setFocus();
void setContent(string text);
List<GCodeShort> getContentArray();
string getContent();
/// <summary>
/// Visualization mode for gcode.
/// 0 = Show all layer, 1 = show one layer, 2 = show layer range
/// </summary>
int ShowMode { get; set; }
int ShowMinLayer {get; set;}
int ShowMaxLayer { get; set; }
int MaxLayer { get; }
string PreferredSaveName { get; set; }
}
For reload all you need is
editor.setContent(System.IO.File.ReadAllText(file));
but with getContent and setContent you can also postprocess the result internally.