Merge pull request #3429 from jlewin/design_tools
Migrate SlicePresetsWindow to DialogPage
This commit is contained in:
commit
8c50502c84
4 changed files with 69 additions and 95 deletions
|
|
@ -347,9 +347,9 @@ namespace MatterHackers.MatterControl
|
|||
public static Func<Task<OemProfileDictionary>> GetPublicProfileList;
|
||||
public static Func<string, Task<PrinterSettings>> DownloadPublicProfileAsync;
|
||||
|
||||
public SlicePresetsWindow EditMaterialPresetsWindow { get; set; }
|
||||
public SlicePresetsPage EditMaterialPresetsPage { get; set; }
|
||||
|
||||
public SlicePresetsWindow EditQualityPresetsWindow { get; set; }
|
||||
public SlicePresetsPage EditQualityPresetsWindow { get; set; }
|
||||
|
||||
public GuiWidget MainView;
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
protected FlowLayoutWidget headerRow;
|
||||
protected FlowLayoutWidget contentRow;
|
||||
private FlowLayoutWidget footerRow;
|
||||
protected FlowLayoutWidget footerRow;
|
||||
|
||||
private WrappedTextWidget headerLabel;
|
||||
private GuiWidget cancelButton;
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
{
|
||||
if (layerType == NamedSettingsLayers.Material)
|
||||
{
|
||||
if (ApplicationController.Instance.EditMaterialPresetsWindow == null)
|
||||
if (ApplicationController.Instance.EditMaterialPresetsPage == null)
|
||||
{
|
||||
string presetsID = printer.Settings.ActiveMaterialKey;
|
||||
if (string.IsNullOrEmpty(presetsID))
|
||||
|
|
@ -150,16 +150,18 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
};
|
||||
|
||||
ApplicationController.Instance.EditMaterialPresetsWindow = new SlicePresetsWindow(printer, presetsContext);
|
||||
ApplicationController.Instance.EditMaterialPresetsWindow.Closed += (s, e2) =>
|
||||
var editMaterialPresetsPage = new SlicePresetsPage(printer, presetsContext);
|
||||
editMaterialPresetsPage.Closed += (s, e2) =>
|
||||
{
|
||||
ApplicationController.Instance.EditMaterialPresetsWindow = null;
|
||||
ApplicationController.Instance.EditMaterialPresetsPage = null;
|
||||
};
|
||||
ApplicationController.Instance.EditMaterialPresetsWindow.ShowAsSystemWindow();
|
||||
|
||||
ApplicationController.Instance.EditMaterialPresetsPage = editMaterialPresetsPage;
|
||||
DialogWindow.Show(editMaterialPresetsPage);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplicationController.Instance.EditMaterialPresetsWindow.BringToFront();
|
||||
ApplicationController.Instance.EditMaterialPresetsPage.WizardWindow.BringToFront();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -187,16 +189,18 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
};
|
||||
|
||||
ApplicationController.Instance.EditQualityPresetsWindow = new SlicePresetsWindow(printer, presetsContext);
|
||||
ApplicationController.Instance.EditQualityPresetsWindow.Closed += (s, e2) =>
|
||||
var editQualityPresetsWindow = new SlicePresetsPage(printer, presetsContext);
|
||||
editQualityPresetsWindow.Closed += (s, e2) =>
|
||||
{
|
||||
ApplicationController.Instance.EditQualityPresetsWindow = null;
|
||||
};
|
||||
ApplicationController.Instance.EditQualityPresetsWindow.ShowAsSystemWindow();
|
||||
|
||||
ApplicationController.Instance.EditQualityPresetsWindow = editQualityPresetsWindow;
|
||||
DialogWindow.Show(editQualityPresetsWindow);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplicationController.Instance.EditQualityPresetsWindow.BringToFront();
|
||||
ApplicationController.Instance.EditQualityPresetsWindow.WizardWindow.BringToFront();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -59,58 +59,72 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
public class SlicePresetsWindow : SystemWindow
|
||||
public class SlicePresetsPage : DialogPage
|
||||
{
|
||||
private static Regex numberMatch = new Regex("\\s*\\(\\d+\\)", RegexOptions.Compiled);
|
||||
|
||||
private PresetsContext presetsContext;
|
||||
private PrinterConfig printer;
|
||||
private GuiWidget middleRow;
|
||||
private InlineTitleEdit inlineTitleEdit;
|
||||
|
||||
public SlicePresetsWindow(PrinterConfig printer, PresetsContext presetsContext)
|
||||
: base(641, 481)
|
||||
public SlicePresetsPage(PrinterConfig printer, PresetsContext presetsContext)
|
||||
{
|
||||
var theme = ApplicationController.Instance.Theme;
|
||||
this.presetsContext = presetsContext;
|
||||
this.printer = printer;
|
||||
this.AlwaysOnTopOfMain = true;
|
||||
this.Title = "Slice Presets Editor".Localize();
|
||||
this.MinimumSize = new Vector2(640, 480);
|
||||
|
||||
this.WindowTitle = "Slice Presets Editor".Localize();
|
||||
this.WindowSize = new Vector2(640, 480);
|
||||
this.AnchorAll();
|
||||
|
||||
var linkButtonFactory = new LinkButtonFactory()
|
||||
{
|
||||
fontSize = 8,
|
||||
textColor = ActiveTheme.Instance.PrimaryAccentColor
|
||||
};
|
||||
this.headerRow.Visible = false;
|
||||
this.contentRow.Padding = 0;
|
||||
|
||||
var buttonFactory = theme.ButtonFactory;
|
||||
contentRow.BackgroundColor = Color.Transparent;
|
||||
|
||||
FlowLayoutWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
||||
{
|
||||
Padding = new BorderDouble(3)
|
||||
};
|
||||
mainContainer.AnchorAll();
|
||||
|
||||
middleRow = new GuiWidget();
|
||||
middleRow.AnchorAll();
|
||||
middleRow.AddChild(CreateSliceSettingsWidget(printer, presetsContext.PersistenceLayer));
|
||||
|
||||
inlineTitleEdit = new InlineTitleEdit(presetsContext.PersistenceLayer.Name, theme, presetsContext.LayerType.ToString() + " Name", boldFont: true);
|
||||
var inlineTitleEdit = new InlineTitleEdit(presetsContext.PersistenceLayer.Name, theme, presetsContext.LayerType.ToString() + " Name", boldFont: true);
|
||||
inlineTitleEdit.TitleChanged += (s, e) =>
|
||||
{
|
||||
printer.Settings.SetValue(SettingsKey.layer_name, inlineTitleEdit.Text, presetsContext.PersistenceLayer);
|
||||
//ActiveSliceSettings.SettingChanged.CallEvents(null, new StringEventArgs(SettingsKey.layer_name));
|
||||
};
|
||||
mainContainer.AddChild(inlineTitleEdit);
|
||||
contentRow.AddChild(inlineTitleEdit);
|
||||
|
||||
mainContainer.AddChild(middleRow);
|
||||
mainContainer.AddChild(GetBottomRow(buttonFactory));
|
||||
var sliceSettingsWidget = CreateSliceSettingsWidget(printer, presetsContext.PersistenceLayer);
|
||||
contentRow.AddChild(sliceSettingsWidget);
|
||||
|
||||
this.AddChild(mainContainer);
|
||||
var duplicateButton = theme.CreateDialogButton("Duplicate".Localize());
|
||||
duplicateButton.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
string sanitizedName = numberMatch.Replace(inlineTitleEdit.Text, "").Trim();
|
||||
string newProfileName = agg_basics.GetNonCollidingName(sanitizedName, presetsContext.PresetLayers.Select(preset => preset.ValueOrDefault(SettingsKey.layer_name)));
|
||||
|
||||
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
||||
var clonedLayer = presetsContext.PersistenceLayer.Clone();
|
||||
clonedLayer.Name = newProfileName;
|
||||
presetsContext.PresetLayers.Add(clonedLayer);
|
||||
|
||||
presetsContext.SetAsActive(clonedLayer.LayerID);
|
||||
presetsContext.PersistenceLayer = clonedLayer;
|
||||
|
||||
sliceSettingsWidget.Close();
|
||||
sliceSettingsWidget = CreateSliceSettingsWidget(printer, clonedLayer);
|
||||
contentRow.AddChild(sliceSettingsWidget);
|
||||
|
||||
inlineTitleEdit.Text = newProfileName;
|
||||
});
|
||||
};
|
||||
this.AddPageAction(duplicateButton);
|
||||
|
||||
var deleteButton = theme.CreateDialogButton("Delete".Localize());
|
||||
deleteButton.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
presetsContext.DeleteLayer();
|
||||
this.WizardWindow.Close();
|
||||
});
|
||||
};
|
||||
this.AddPageAction(deleteButton);
|
||||
}
|
||||
|
||||
private GuiWidget CreateSliceSettingsWidget(PrinterConfig printer, PrinterSettingsLayer persistenceLayer)
|
||||
|
|
@ -131,58 +145,14 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
};
|
||||
}
|
||||
|
||||
private FlowLayoutWidget GetBottomRow(TextImageButtonFactory buttonFactory)
|
||||
public override void OnLoad(EventArgs args)
|
||||
{
|
||||
var container = new FlowLayoutWidget()
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
Margin = new BorderDouble(top: 3)
|
||||
};
|
||||
|
||||
Button duplicateButton = buttonFactory.Generate("Duplicate".Localize());
|
||||
duplicateButton.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
string sanitizedName = numberMatch.Replace(inlineTitleEdit.Text, "").Trim();
|
||||
string newProfileName = agg_basics.GetNonCollidingName(sanitizedName, presetsContext.PresetLayers.Select(preset => preset.ValueOrDefault(SettingsKey.layer_name)));
|
||||
|
||||
var clonedLayer = presetsContext.PersistenceLayer.Clone();
|
||||
clonedLayer.Name = newProfileName;
|
||||
presetsContext.PresetLayers.Add(clonedLayer);
|
||||
|
||||
presetsContext.SetAsActive(clonedLayer.LayerID);
|
||||
presetsContext.PersistenceLayer = clonedLayer;
|
||||
|
||||
middleRow.CloseAllChildren();
|
||||
middleRow.AddChild(CreateSliceSettingsWidget(printer, clonedLayer));
|
||||
|
||||
inlineTitleEdit.Text = newProfileName;
|
||||
});
|
||||
};
|
||||
|
||||
Button deleteButton = buttonFactory.Generate("Delete".Localize());
|
||||
deleteButton.Click += (s, e) =>
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
presetsContext.DeleteLayer();
|
||||
this.Close();
|
||||
});
|
||||
};
|
||||
|
||||
Button closeButton = buttonFactory.Generate("Close".Localize());
|
||||
closeButton.Click += (sender, e) =>
|
||||
{
|
||||
this.CloseOnIdle();
|
||||
};
|
||||
|
||||
container.AddChild(duplicateButton);
|
||||
container.AddChild(deleteButton);
|
||||
container.AddChild(new HorizontalSpacer());
|
||||
container.AddChild(closeButton);
|
||||
|
||||
return container;
|
||||
this.WizardWindow.Padding = 0;
|
||||
footerRow.Padding = theme.DefaultContainerPadding;
|
||||
footerRow.Margin = 0;
|
||||
footerRow.Border = new BorderDouble(top: 1);
|
||||
footerRow.BorderColor = theme.TabBarBackground;
|
||||
base.OnLoad(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue