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-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-04-04 17:58:33 -07:00
public SliceSettingsDetailControl ( )
{
2016-04-22 17:30:34 -07:00
showHelpBox = new CheckBox ( 0 , 0 , "Show Help" . Localize ( ) , textSize : 10 ) ;
2016-04-04 17:58:33 -07:00
showHelpBox . Checked = UserSettings . Instance . get ( SliceSettingsShowHelpEntry ) = = "true" ;
// 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-04-26 15:10:51 -07:00
UserSettings . Instance . set ( SliceSettingsShowHelpEntry , showHelpBox . Checked . ToString ( ) . ToLower ( ) ) ;
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-04-04 17:58:33 -07:00
if ( UserSettings . Instance . get ( SliceSettingsLevelEntry ) ! = null
& & SliceSettingsOrganizer . Instance . UserLevels . ContainsKey ( UserSettings . Instance . get ( SliceSettingsLevelEntry ) ) )
{
settingsDetailSelector . SelectedValue = UserSettings . Instance . get ( SliceSettingsLevelEntry ) ;
}
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 ) ;
this . AddChild ( settingsDetailSelector ) ;
this . AddChild ( GetSliceOptionsMenuDropList ( ) ) ;
}
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-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-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-06-10 16:26:25 -07:00
ActiveSliceSettings . Instance . SaveChanges ( ) ;
ApplicationController . Instance . ReloadAdvancedControlsPanel ( ) ;
2016-06-10 16:04:45 -07:00
}
} ,
resetToDefaultsMessage ,
resetToDefaultsWindowTitle ,
StyledMessageBox . MessageType . YES_NO ) ;
}
2016-06-09 19:28:21 -07:00
2016-04-04 17:58:33 -07:00
}
2016-04-21 18:02:02 -07:00
}