Remove duplication in SetupConnectionWidgetBase
- Issue #846 - Move ActivePrinter to SetupConnectionWigetBase - Remove local theme variables - Allow subclass to set widget factory defaults
This commit is contained in:
parent
50593fe399
commit
8456924b9e
5 changed files with 85 additions and 156 deletions
|
|
@ -10,58 +10,58 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
|
|||
{
|
||||
public class SetupConnectionWidgetBase : WizardPanel
|
||||
{
|
||||
//private GuiWidget mainContainer;
|
||||
private PrinterInfo activePrinter;
|
||||
|
||||
protected FlowLayoutWidget headerRow;
|
||||
protected FlowLayoutWidget contentRow;
|
||||
protected FlowLayoutWidget footerRow;
|
||||
protected TextWidget headerLabel;
|
||||
protected Button cancelButton;
|
||||
protected TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
|
||||
protected LinkButtonFactory linkButtonFactory = new LinkButtonFactory();
|
||||
|
||||
public SetupConnectionWidgetBase(WizardWindow wizard) : base(wizard)
|
||||
public SetupConnectionWidgetBase(WizardWindow wizard)
|
||||
: base(
|
||||
wizard,
|
||||
"Cancel",
|
||||
new TextImageButtonFactory()
|
||||
{
|
||||
normalTextColor = ActiveTheme.Instance.PrimaryTextColor,
|
||||
hoverTextColor = ActiveTheme.Instance.PrimaryTextColor,
|
||||
disabledTextColor = ActiveTheme.Instance.PrimaryTextColor,
|
||||
pressedTextColor = ActiveTheme.Instance.PrimaryTextColor,
|
||||
borderWidth = 0
|
||||
})
|
||||
{
|
||||
SetDisplayAttributes();
|
||||
|
||||
cancelButton = textImageButtonFactory.Generate("Cancel".Localize());
|
||||
cancelButton.Name = "Setup Connection Cancel Button";
|
||||
cancelButton.Click += CancelButton_Click;
|
||||
linkButtonFactory.textColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
linkButtonFactory.fontSize = 10;
|
||||
|
||||
this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
|
||||
this.Padding = new BorderDouble(0); //To be re-enabled once native borders are turned off
|
||||
|
||||
cancelButton.Click += (s, e) => PrinterConnectionAndCommunication.Instance.HaltConnectionThread();
|
||||
|
||||
//Create the main container
|
||||
GuiWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
||||
mainContainer.AnchorAll();
|
||||
mainContainer.Padding = new BorderDouble(3, 5, 3, 5);
|
||||
mainContainer.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
||||
|
||||
//Create the header row for the widget
|
||||
headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);
|
||||
headerRow.Margin = new BorderDouble(0, 3, 0, 0);
|
||||
headerRow.Padding = new BorderDouble(0, 3, 0, 3);
|
||||
headerRow.HAnchor = HAnchor.ParentLeftRight;
|
||||
{
|
||||
headerLabel = new TextWidget("3D Printer Setup".Localize(), pointSize: 14);
|
||||
headerLabel.AutoExpandBoundsToText = true;
|
||||
headerLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
headerRow.AddChild(headerLabel);
|
||||
}
|
||||
|
||||
//Create the main control container
|
||||
contentRow = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
||||
headerLabel.PointSize = 14;
|
||||
headerLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
contentRow.Padding = new BorderDouble(5);
|
||||
contentRow.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
|
||||
contentRow.HAnchor = HAnchor.ParentLeftRight;
|
||||
contentRow.VAnchor = VAnchor.ParentBottomTop;
|
||||
|
||||
//Create the footer (button) container
|
||||
footerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);
|
||||
footerRow.HAnchor = HAnchor.ParentLeft | HAnchor.ParentRight;
|
||||
footerRow.Margin = new BorderDouble(0, 3);
|
||||
}
|
||||
|
||||
mainContainer.AddChild(headerRow);
|
||||
mainContainer.AddChild(contentRow);
|
||||
mainContainer.AddChild(footerRow);
|
||||
this.AddChild(mainContainer);
|
||||
public PrinterInfo ActivePrinter
|
||||
{
|
||||
get
|
||||
{
|
||||
if (activePrinter == null)
|
||||
{
|
||||
var settings = ActiveSliceSettings.Instance;
|
||||
activePrinter = new PrinterInfo
|
||||
{
|
||||
AutoConnect = settings.DoAutoConnect(),
|
||||
BaudRate = settings.BaudRate(),
|
||||
ComPort = settings.ComPort(),
|
||||
DriverType = settings.DriverType(),
|
||||
Id = settings.ID,
|
||||
Name = settings.Name()
|
||||
};
|
||||
}
|
||||
|
||||
return activePrinter;
|
||||
}
|
||||
}
|
||||
|
||||
protected void SaveAndExit()
|
||||
|
|
@ -77,27 +77,5 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
|
|||
|
||||
UiThread.RunOnIdle(wizardWindow.Close);
|
||||
}
|
||||
|
||||
private void SetDisplayAttributes()
|
||||
{
|
||||
textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
textImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
textImageButtonFactory.borderWidth = 0;
|
||||
|
||||
linkButtonFactory.textColor = ActiveTheme.Instance.PrimaryTextColor;
|
||||
linkButtonFactory.fontSize = 10;
|
||||
|
||||
this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
|
||||
this.AnchorAll();
|
||||
this.Padding = new BorderDouble(0); //To be re-enabled once native borders are turned off
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, EventArgs mouseEvent)
|
||||
{
|
||||
PrinterConnectionAndCommunication.Instance.HaltConnectionThread();
|
||||
UiThread.RunOnIdle(wizardWindow.Close);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue