2016-04-21 18:02:02 -07:00
using MatterHackers.Agg ;
2016-04-04 17:58:33 -07:00
using MatterHackers.Agg.UI ;
using MatterHackers.Localizations ;
2016-06-09 14:58:39 -07:00
using MatterHackers.MatterControl.CustomWidgets ;
2016-07-13 13:39:11 -07:00
using MatterHackers.MatterControl.SetupWizard ;
2016-04-21 18:02:02 -07:00
using System ;
2016-06-09 19:28:21 -07:00
using System.Collections.Generic ;
2016-06-10 16:04:45 -07:00
using System.IO ;
2016-06-09 19:28:21 -07:00
using System.Linq ;
2016-04-04 17:58:33 -07:00
namespace MatterHackers.MatterControl.SlicerConfiguration
{
public class SliceSettingsDetailControl : FlowLayoutWidget
{
2016-04-26 15:10:51 -07:00
public DropDownMenu sliceOptionsMenuDropList ;
2016-04-04 17:58:33 -07:00
private const string SliceSettingsLevelEntry = "SliceSettingsLevel" ;
2016-04-26 15:10:51 -07:00
private const string SliceSettingsShowHelpEntry = "SliceSettingsShowHelp" ;
2016-06-03 18:11:51 -07:00
private DropDownList settingsDetailSelector ;
2016-04-26 15:10:51 -07:00
private CheckBox showHelpBox ;
2016-04-04 17:58:33 -07:00
private TupleList < string , Func < bool > > slicerOptionsMenuItems ;
2016-06-11 16:51:52 -07:00
private static string resetToDefaultsMessage = "Resetting to default values will remove your current overrides and restore your original printer settings.\nAre you sure you want to continue?" . Localize ( ) ;
2016-06-09 19:28:21 -07:00
private static string resetToDefaultsWindowTitle = "Revert Settings" . Localize ( ) ;
2016-07-20 15:16:00 -07:00
public SliceSettingsDetailControl ( List < PrinterSettingsLayer > layerCascade )
2016-04-04 17:58:33 -07:00
{
2016-07-20 15:16:00 -07:00
showHelpBox = new CheckBox ( 0 , 0 , "Show Help" . Localize ( ) , textSize : 10 )
{
VAnchor = VAnchor . ParentCenter ,
} ;
if ( layerCascade = = null )
{
// only turn of the help if in the main view and it is set to on
showHelpBox . Checked = UserSettings . Instance . get ( SliceSettingsShowHelpEntry ) = = "true" ;
}
2016-04-04 17:58:33 -07:00
// add in the ability to turn on and off help text
2016-04-26 15:10:51 -07:00
showHelpBox . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
showHelpBox . Margin = new BorderDouble ( right : 3 ) ;
showHelpBox . VAnchor = VAnchor . ParentCenter ;
showHelpBox . Cursor = Cursors . Hand ;
showHelpBox . CheckedStateChanged + = ( s , e ) = >
2016-04-04 17:58:33 -07:00
{
2016-07-20 15:16:00 -07:00
if ( layerCascade = = null )
{
// only save the help settings if in the main view
UserSettings . Instance . set ( SliceSettingsShowHelpEntry , showHelpBox . Checked . ToString ( ) . ToLower ( ) ) ;
}
2016-04-26 15:10:51 -07:00
ShowHelpChanged ? . Invoke ( this , null ) ;
} ;
2016-04-04 17:58:33 -07:00
2016-04-26 15:10:51 -07:00
this . AddChild ( showHelpBox ) ;
2016-04-04 17:58:33 -07:00
2016-06-03 18:11:51 -07:00
settingsDetailSelector = new DropDownList ( "Basic" , maxHeight : 200 ) ;
2016-04-04 17:58:33 -07:00
settingsDetailSelector . Name = "User Level Dropdown" ;
2016-04-22 17:30:34 -07:00
settingsDetailSelector . AddItem ( "Basic" . Localize ( ) , "Simple" ) ;
settingsDetailSelector . AddItem ( "Standard" . Localize ( ) , "Intermediate" ) ;
settingsDetailSelector . AddItem ( "Advanced" . Localize ( ) , "Advanced" ) ;
2016-07-20 15:16:00 -07:00
if ( layerCascade = = null )
2016-04-04 17:58:33 -07:00
{
2016-07-20 15:16:00 -07:00
// set to the user requested value when in default view
if ( UserSettings . Instance . get ( SliceSettingsLevelEntry ) ! = null
& & SliceSettingsOrganizer . Instance . UserLevels . ContainsKey ( UserSettings . Instance . get ( SliceSettingsLevelEntry ) ) )
{
settingsDetailSelector . SelectedValue = UserSettings . Instance . get ( SliceSettingsLevelEntry ) ;
}
}
else // in settings editor view
{
// set to advanced
settingsDetailSelector . SelectedValue = "Advanced" ;
2016-04-04 17:58:33 -07:00
}
2016-06-09 14:58:39 -07:00
settingsDetailSelector . SelectionChanged + = ( s , e ) = > RebuildSlicerSettings ( null , null ) ; ;
2016-04-04 17:58:33 -07:00
settingsDetailSelector . VAnchor = VAnchor . ParentCenter ;
settingsDetailSelector . Margin = new BorderDouble ( 5 , 3 ) ;
settingsDetailSelector . BorderColor = new RGBA_Bytes ( ActiveTheme . Instance . SecondaryTextColor , 100 ) ;
2016-07-20 15:16:00 -07:00
if ( layerCascade = = null )
{
// only add these in the default view
this . AddChild ( settingsDetailSelector ) ;
this . AddChild ( GetSliceOptionsMenuDropList ( ) ) ;
}
VAnchor = VAnchor . ParentCenter ;
2016-04-04 17:58:33 -07:00
}
2016-04-26 15:10:51 -07:00
public event EventHandler ShowHelpChanged ;
2016-06-09 14:58:39 -07:00
public string SelectedValue = > settingsDetailSelector . SelectedValue ;
2016-04-26 15:10:51 -07:00
2016-06-09 14:58:39 -07:00
public bool ShowingHelp = > showHelpBox . Checked ;
2016-04-26 15:10:51 -07:00
2016-04-04 17:58:33 -07:00
private DropDownMenu GetSliceOptionsMenuDropList ( )
{
if ( sliceOptionsMenuDropList = = null )
{
2016-06-09 14:58:39 -07:00
sliceOptionsMenuDropList = new DropDownMenu ( "Options" . Localize ( ) + "... " )
{
HoverColor = new RGBA_Bytes ( 0 , 0 , 0 , 50 ) ,
NormalColor = new RGBA_Bytes ( 0 , 0 , 0 , 0 ) ,
BorderColor = new RGBA_Bytes ( ActiveTheme . Instance . SecondaryTextColor , 100 ) ,
BackgroundColor = new RGBA_Bytes ( 0 , 0 , 0 , 0 ) ,
BorderWidth = 1 ,
2016-07-21 17:15:47 -07:00
MenuAsWideAsItems = false ,
AlignToRightEdge = true ,
2016-06-09 14:58:39 -07:00
} ;
2016-04-04 17:58:33 -07:00
sliceOptionsMenuDropList . VAnchor | = VAnchor . ParentCenter ;
sliceOptionsMenuDropList . SelectionChanged + = new EventHandler ( MenuDropList_SelectionChanged ) ;
2016-06-09 14:58:39 -07:00
//Set the name and callback function of the menu items
slicerOptionsMenuItems = new TupleList < string , Func < bool > >
{
{ "Import" . Localize ( ) , ImportSettingsMenu_Click } ,
2016-06-09 19:28:21 -07:00
{ "Export" . Localize ( ) , ( ) = > { WizardWindow . Show < ExportSettingsPage > ( "ExportSettingsPage" , "Export Settings" ) ; return true ; } } ,
2016-07-29 11:19:24 -07:00
{ "Settings History" . Localize ( ) , ( ) = > { WizardWindow . Show < PrinterProfileHistoryPage > ( "PrinterProfileHistory" , "Profile History" ) ; return true ; } } ,
2016-06-09 14:58:39 -07:00
{ "Reset to defaults" . Localize ( ) , ( ) = > { UiThread . RunOnIdle ( ResetToDefaults ) ; return true ; } } ,
} ;
//Add the menu items to the menu itself
foreach ( Tuple < string , Func < bool > > item in slicerOptionsMenuItems )
{
sliceOptionsMenuDropList . AddItem ( item . Item1 ) ;
}
2016-04-04 17:58:33 -07:00
}
return sliceOptionsMenuDropList ;
}
2016-04-26 15:10:51 -07:00
private bool ImportSettingsMenu_Click ( )
{
2016-06-11 16:24:30 -07:00
UiThread . RunOnIdle ( ( ) = > WizardWindow . Show < ImportSettingsPage > ( "ImportSettingsPage" , "Import Settings Page" ) ) ;
2016-04-26 15:10:51 -07:00
return true ;
}
2016-04-04 17:58:33 -07:00
private void MenuDropList_SelectionChanged ( object sender , EventArgs e )
{
string menuSelection = ( ( DropDownMenu ) sender ) . SelectedValue ;
foreach ( Tuple < string , Func < bool > > item in slicerOptionsMenuItems )
{
// if the menu we select is this one
if ( item . Item1 = = menuSelection )
{
// call its function
item . Item2 ( ) ;
}
}
}
2016-04-26 15:10:51 -07:00
private void RebuildSlicerSettings ( object sender , EventArgs e )
{
UserSettings . Instance . set ( SliceSettingsLevelEntry , settingsDetailSelector . SelectedValue ) ;
ApplicationController . Instance . ReloadAdvancedControlsPanel ( ) ;
}
2016-06-09 14:58:39 -07:00
private void ResetToDefaults ( )
2016-04-26 15:10:51 -07:00
{
2016-06-09 07:59:25 -07:00
StyledMessageBox . ShowMessageBox (
revertSettings = >
{
if ( revertSettings )
{
2016-06-11 16:24:30 -07:00
ActiveSliceSettings . Instance . ClearUserOverrides ( ) ;
2016-07-18 15:20:19 -07:00
ActiveSliceSettings . Instance . Save ( ) ;
2016-06-10 16:26:25 -07:00
ApplicationController . Instance . ReloadAdvancedControlsPanel ( ) ;
2016-06-10 16:04:45 -07:00
}
} ,
resetToDefaultsMessage ,
resetToDefaultsWindowTitle ,
StyledMessageBox . MessageType . YES_NO ) ;
}
2016-04-04 17:58:33 -07:00
}
2016-04-21 18:02:02 -07:00
}