2015-04-08 15:20:10 -07:00
using MatterHackers.Agg ;
2014-12-09 15:16:08 -08:00
using MatterHackers.Agg.UI ;
using MatterHackers.Localizations ;
using MatterHackers.MatterControl.DataStorage ;
using MatterHackers.MatterControl.PrinterCommunication ;
using MatterHackers.MatterControl.PrinterControls.PrinterConnections ;
using MatterHackers.MatterControl.PrintQueue ;
2015-07-30 10:42:06 -07:00
using System.Collections.Generic ;
2014-12-09 15:16:08 -08:00
using MatterHackers.VectorMath ;
2015-04-08 15:20:10 -07:00
using System ;
using System.IO ;
2016-04-18 11:31:31 -07:00
using System.Linq ;
2016-08-05 11:44:22 -07:00
using MatterHackers.MatterControl.SlicerConfiguration ;
2017-01-19 11:58:19 -08:00
using MatterHackers.MatterControl.CustomWidgets ;
2014-12-09 15:16:08 -08:00
namespace MatterHackers.MatterControl
{
2015-05-20 17:34:55 -07:00
public class MenuOptionFile : MenuBase
2015-04-08 15:20:10 -07:00
{
2015-08-03 17:31:53 -07:00
public static MenuOptionFile CurrentMenuOptionFile = null ;
2015-04-08 15:20:10 -07:00
public MenuOptionFile ( )
2015-05-20 17:34:55 -07:00
: base ( "File" . Localize ( ) )
2015-04-08 15:20:10 -07:00
{
2015-08-20 10:24:28 -07:00
Name = "File Menu" ;
2015-08-03 17:31:53 -07:00
CurrentMenuOptionFile = this ;
2016-04-18 11:31:31 -07:00
2015-04-08 15:20:10 -07:00
}
2014-12-09 15:16:08 -08:00
2016-06-10 15:31:15 -07:00
protected override IEnumerable < MenuItemAction > GetMenuActions ( )
2015-04-08 15:20:10 -07:00
{
2016-02-13 11:49:09 -08:00
return new List < MenuItemAction >
{
2017-01-19 11:58:19 -08:00
// TODO: Helper while building printing window prototype... remove once finalized
new MenuItemAction ( "Printing Window..." . Localize ( ) , ( ) = > PrintingWindow . Show ( ( ) = > Console . WriteLine ( ) ) ) ,
new MenuItemAction ( "------------------------" , null ) ,
2016-08-22 15:03:31 -07:00
new MenuItemAction ( "Add Printer" . Localize ( ) , AddPrinter_Click ) ,
2016-08-05 11:44:22 -07:00
new MenuItemAction ( "Import Printer" . Localize ( ) , ImportPrinter ) ,
2016-04-18 11:31:31 -07:00
new MenuItemAction ( "Add File To Queue" . Localize ( ) , importFile_Click ) ,
2016-11-14 16:50:55 -08:00
new MenuItemAction ( "Redeem Design Code" . Localize ( ) , ( ) = > ApplicationController . Instance . RedeemDesignCode ? . Invoke ( ) ) ,
new MenuItemAction ( "Enter Share Code" . Localize ( ) , ( ) = > ApplicationController . Instance . EnterShareCode ? . Invoke ( ) ) ,
2016-02-13 11:49:09 -08:00
new MenuItemAction ( "------------------------" , null ) ,
2016-04-18 11:31:31 -07:00
new MenuItemAction ( "Exit" . Localize ( ) , ( ) = >
2015-08-03 17:31:53 -07:00
{
2016-04-18 11:31:31 -07:00
MatterControlApplication app = this . Parents < MatterControlApplication > ( ) . FirstOrDefault ( ) ;
app . RestartOnClose = false ;
app . Close ( ) ;
} )
} ;
2015-04-08 15:20:10 -07:00
}
2016-08-05 11:44:22 -07:00
private void ImportPrinter ( )
{
FileDialog . OpenFileDialog (
new OpenFileDialogParams ( "settings files|*.ini;*.printer;*.slice" ) ,
( dialogParams ) = >
{
if ( ! string . IsNullOrEmpty ( dialogParams . FileName ) )
{
ImportSettingsFile ( dialogParams . FileName ) ;
}
} ) ;
}
private void ImportSettingsFile ( string settingsFilePath )
{
2016-08-11 14:59:23 -07:00
if ( ! ProfileManager . ImportFromExisting ( settingsFilePath ) )
{
StyledMessageBox . ShowMessageBox ( null , "Oops! Settings file '{0}' did not contain any settings we could import." . Localize ( ) . FormatWith ( Path . GetFileName ( settingsFilePath ) ) , "Unable to Import" . Localize ( ) ) ;
}
2016-08-05 11:44:22 -07:00
}
2016-08-22 15:03:31 -07:00
private void AddPrinter_Click ( )
{
if ( PrinterConnectionAndCommunication . Instance . PrinterIsPrinting
| | PrinterConnectionAndCommunication . Instance . PrinterIsPaused )
{
UiThread . RunOnIdle ( ( ) = >
StyledMessageBox . ShowMessageBox ( null , "Please wait until the print has finished and try again." . Localize ( ) , "Can't add printers while printing" . Localize ( ) )
) ;
}
else
{
WizardWindow . ShowPrinterSetup ( true ) ;
}
}
2016-02-13 11:49:09 -08:00
private void importFile_Click ( )
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
FileDialog . OpenFileDialog (
new OpenFileDialogParams ( ApplicationSettings . OpenPrintableFileParams )
{
MultiSelect = true ,
ActionButtonLabel = "Add to Queue" ,
Title = "MatterControl: Select A File"
} ,
( openParams ) = >
{
if ( openParams . FileNames ! = null )
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
foreach ( string loadedFileName in openParams . FileNames )
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
if ( Path . GetExtension ( loadedFileName ) . ToUpper ( ) = = ".ZIP" )
{
ProjectFileHandler project = new ProjectFileHandler ( null ) ;
List < PrintItem > partFiles = project . ImportFromProjectArchive ( loadedFileName ) ;
if ( partFiles ! = null )
{
foreach ( PrintItem part in partFiles )
{
QueueData . Instance . AddItem ( new PrintItemWrapper ( new PrintItem ( part . Name , part . FileLocation ) ) ) ;
}
}
}
else
2015-04-08 15:20:10 -07:00
{
2016-04-18 11:31:31 -07:00
QueueData . Instance . AddItem ( new PrintItemWrapper ( new PrintItem ( Path . GetFileNameWithoutExtension ( loadedFileName ) , Path . GetFullPath ( loadedFileName ) ) ) ) ;
2015-04-08 15:20:10 -07:00
}
}
2016-04-18 11:31:31 -07:00
}
} ) ;
2015-04-08 15:20:10 -07:00
}
}
}