2016-11-30 13:31:19 -08:00
using MatterHackers.Agg ;
using MatterHackers.Agg.UI ;
using MatterHackers.Localizations ;
using MatterHackers.MatterControl.ContactForm ;
using MatterHackers.MatterControl.AboutPage ;
using MatterHackers.VectorMath ;
using System ;
using System.Collections.Generic ;
2016-12-03 12:08:39 -08:00
using MatterHackers.MatterControl.SlicerConfiguration ;
using MatterHackers.MatterControl.PrinterControls ;
using MatterHackers.MatterControl.PrinterCommunication ;
2016-11-30 13:31:19 -08:00
namespace MatterHackers.MatterControl
{
public class MenuOptionMacros : MenuBase
{
2016-12-03 12:08:39 -08:00
private event EventHandler unregisterEvents ;
2016-11-30 13:31:19 -08:00
public MenuOptionMacros ( ) : base ( "Macros" . Localize ( ) )
{
Name = "Macro Menu" ;
2016-12-03 12:08:39 -08:00
ActiveSliceSettings . ActivePrinterChanged . RegisterEvent ( ( s , e ) = > SetEnabledState ( ) , ref unregisterEvents ) ;
}
public override void OnLoad ( EventArgs args )
{
SetEnabledState ( ) ;
base . OnLoad ( args ) ;
}
public override void OnClosed ( EventArgs e )
{
unregisterEvents ? . Invoke ( this , null ) ;
base . OnClosed ( e ) ;
}
private void SetEnabledState ( )
{
for ( int i = 0 ; i < MenuDropList . MenuItems . Count - 1 ; i + + )
{
MenuDropList . MenuItems [ i ] . Enabled = ActiveSliceSettings . Instance . PrinterSelected
& & PrinterConnectionAndCommunication . Instance . PrinterIsConnected
& & ! PrinterConnectionAndCommunication . Instance . PrinterIsPrinting ;
}
// and set the edit menu item
MenuDropList . MenuItems [ MenuDropList . MenuItems . Count - 1 ] . Enabled = ActiveSliceSettings . Instance . PrinterSelected ;
2016-11-30 13:31:19 -08:00
}
protected override IEnumerable < MenuItemAction > GetMenuActions ( )
{
2016-12-03 12:08:39 -08:00
var list = new List < MenuItemAction > ( ) ;
if ( ActiveSliceSettings . Instance . Macros . Count > 0 )
2016-11-30 13:31:19 -08:00
{
2016-12-03 12:08:39 -08:00
foreach ( GCodeMacro macro in ActiveSliceSettings . Instance . Macros )
{
list . Add ( new MenuItemAction ( MacroControls . FixMacroName ( macro . Name ) , macro . Run ) ) ;
}
}
list . Add ( new MenuItemAction (
//StaticData.Instance.LoadIcon("icon_plus.png", 32, 32),
"Edit Macros..." ,
( ) = >
{
if ( PrinterConnectionAndCommunication . Instance . PrinterIsPrinting )
{
UiThread . RunOnIdle ( ( ) = >
StyledMessageBox . ShowMessageBox ( null , "Please wait until the print has finished and try again." . Localize ( ) , "Can't edit macros while printing" . Localize ( ) )
) ;
}
else
{
UiThread . RunOnIdle ( ( ) = > EditMacrosWindow . Show ( ) ) ;
}
} ) ) ;
return list ;
2016-11-30 13:31:19 -08:00
}
}
}