Continue merge of Android and Desktop panels

- Add ChangeToPanel implementation that takes panel type param
 - Remove WizardPanel constructors that take WizardWindow params
 - Use initializer syntax
 - Remove dead code
 - Remove problematic ReloadAll calls
This commit is contained in:
John Lewin 2016-06-07 15:45:50 -07:00
parent 12c26bd453
commit 6d827a238a
15 changed files with 148 additions and 269 deletions

View file

@ -33,8 +33,7 @@ namespace MatterHackers.MatterControl
FlowLayoutWidget retryButtonContainer;
FlowLayoutWidget connectButtonContainer;
public SetupWizardConnect(WizardWindow windowController)
: base(windowController)
public SetupWizardConnect()
{
string printerNameLabelTxt = LocalizedString.Get("Connect Your Device");
string printerNameLabelTxtFull = string.Format ("{0}:", printerNameLabelTxt);
@ -125,7 +124,7 @@ namespace MatterHackers.MatterControl
void TroubleshootButton_Click(object sender, EventArgs mouseEvent)
{
wizardWindow.ChangeToTroubleshooting();
WizardWindow.ChangeToTroubleshooting();
}
void NextButton_Click(object sender, EventArgs mouseEvent)
@ -133,7 +132,7 @@ namespace MatterHackers.MatterControl
this.generalError.Text = "Please wait...";
this.generalError.Visible = true;
nextButton.Visible = false;
UiThread.RunOnIdle(this.wizardWindow.Close);
UiThread.RunOnIdle(this.WizardWindow.Close);
}
private void communicationStateChanged(object sender, EventArgs args)

View file

@ -17,22 +17,17 @@ using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl
{
//Normally step one of the setup process
public class SetupWizardHome : WizardPanel
{
TextImageButtonFactory setupButtonFactory = new TextImageButtonFactory();
public SetupWizardHome(WizardWindow windowController)
: base(windowController, unlocalizedTextForCancelButton: "Done")
{
public SetupWizardHome()
: base(unlocalizedTextForCancelButton: "Done")
{
headerLabel.Text = "Setup Options".Localize();
SetButtonAttributes();
contentRow.AddChild(new SetupPrinterView(this.wizardWindow));
contentRow.AddChild(new SetupAccountView(this.wizardWindow));
contentRow.AddChild(new EnterCodesView(this.wizardWindow));
contentRow.AddChild(new SetupPrinterView() { WizardWindow = this.WizardWindow });
contentRow.AddChild(new SetupAccountView() { WizardWindow = this.WizardWindow });
contentRow.AddChild(new EnterCodesView() { WizardWindow = this.WizardWindow });
GuiWidget hSpacer = new GuiWidget();
hSpacer.HAnchor = HAnchor.ParentLeftRight;
@ -43,18 +38,6 @@ namespace MatterHackers.MatterControl
cancelButton.Text = "Back".Localize();
}
private void SetButtonAttributes()
{
setupButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor;
setupButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
setupButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
setupButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;
setupButtonFactory.normalFillColor = ActiveTheme.Instance.PrimaryBackgroundColor;
setupButtonFactory.fontSize = 16;
setupButtonFactory.FixedWidth = 420;
setupButtonFactory.ImageSpacing = 20;
}
}
public class EnterCodesView : SetupViewBase
@ -62,71 +45,61 @@ namespace MatterHackers.MatterControl
public static EventHandler RedeemDesignCode;
public static EventHandler EnterShareCode;
public EnterCodesView(WizardWindow windowController)
: base("", windowController)
public EnterCodesView() : base("")
{
FlowLayoutWidget buttonContainer = new FlowLayoutWidget();
buttonContainer.HAnchor = HAnchor.ParentLeftRight;
buttonContainer.Margin = new BorderDouble(0, 14);
FlowLayoutWidget buttonContainer = new FlowLayoutWidget()
{
HAnchor = HAnchor.ParentLeftRight,
Margin = new BorderDouble(0, 14)
};
mainContainer.AddChild(buttonContainer);
if (UserSettings.Instance.IsTouchScreen)
{
// the redeem design code button
Button redeemPurchaseButton = textImageButtonFactory.Generate("Redeem Purchase".Localize());
redeemPurchaseButton.Enabled = true; // The library selector (the first library selected) is protected so we can't add to it.
redeemPurchaseButton.Name = "Redeem Code Button";
redeemPurchaseButton.Margin = new BorderDouble(0, 0, 10, 0);
redeemPurchaseButton.Click += (sender, e) =>
{
Button redeemPurchaseButton = textImageButtonFactory.Generate("Redeem Purchase".Localize());
redeemPurchaseButton.Enabled = true; // The library selector (the first library selected) is protected so we can't add to it.
redeemPurchaseButton.Name = "Redeem Code Button";
buttonContainer.AddChild(redeemPurchaseButton);
redeemPurchaseButton.Margin = new BorderDouble(0, 0, 10, 0);
redeemPurchaseButton.Click += (sender, e) =>
{
if (RedeemDesignCode != null)
{
RedeemDesignCode(this, null);
}
};
}
RedeemDesignCode?.Invoke(this, null);
};
buttonContainer.AddChild(redeemPurchaseButton);
// the redeem a share code button
Button redeemShareButton = textImageButtonFactory.Generate("Enter Share Code".Localize());
redeemShareButton.Enabled = true; // The library selector (the first library selected) is protected so we can't add to it.
redeemShareButton.Name = "Enter Share Code";
redeemShareButton.Margin = new BorderDouble(0, 0, 3, 0);
redeemShareButton.Click += (sender, e) =>
{
Button redeemShareButton = textImageButtonFactory.Generate("Enter Share Code".Localize());
redeemShareButton.Enabled = true; // The library selector (the first library selected) is protected so we can't add to it.
redeemShareButton.Name = "Enter Share Code";
buttonContainer.AddChild(redeemShareButton);
redeemShareButton.Margin = new BorderDouble(0, 0, 3, 0);
redeemShareButton.Click += (sender, e) =>
{
if (EnterShareCode != null)
{
EnterShareCode(this, null);
}
};
}
EnterShareCode?.Invoke(this, null);
};
buttonContainer.AddChild(redeemShareButton);
}
}
}
public class SetupPrinterView : SetupViewBase
{
Button disconnectButton;
private Button disconnectButton;
private TextWidget connectionStatus;
private event EventHandler unregisterEvents;
TextWidget connectionStatus;
event EventHandler unregisterEvents;
public SetupPrinterView(WizardWindow windowController)
: base("Printer Profile", windowController)
public SetupPrinterView()
: base("Printer Profile")
{
var buttonContainer = new FlowLayoutWidget()
{
HAnchor = HAnchor.ParentLeftRight,
Margin = new BorderDouble (0, 14)
};
mainContainer.AddChild(buttonContainer);
var printerSelector = new PrinterSelector();
printerSelector.AddPrinter += (s, e) => this.windowController.ChangeToSetupPrinterForm();
printerSelector.AddPrinter += (s, e) => WizardWindow.ChangeToSetupPrinterForm();
FlowLayoutWidget printerSelectorAndEditButton = new FlowLayoutWidget()
{
HAnchor = HAnchor.ParentLeftRight,
@ -144,12 +117,10 @@ namespace MatterHackers.MatterControl
disconnectButton.Click += (sender, e) =>
{
PrinterConnectionAndCommunication.Instance.Disable();
windowController.ChangeToHome();
WizardWindow.ChangeToHome();
};
buttonContainer.AddChild(disconnectButton);
mainContainer.AddChild(buttonContainer);
connectionStatus = new TextWidget("Status:", pointSize: 12, textColor: ActiveTheme.Instance.PrimaryTextColor)
{
HAnchor = HAnchor.ParentLeftRight
@ -178,13 +149,12 @@ namespace MatterHackers.MatterControl
public class SetupAccountView : SetupViewBase
{
Button signInButton;
Button signOutButton;
event EventHandler unregisterEvents;
TextWidget statusMessage;
private Button signInButton;
private Button signOutButton;
private TextWidget statusMessage;
public SetupAccountView(WizardWindow windowController)
: base("My Account", windowController)
public SetupAccountView()
: base("My Account")
{
bool signedIn = true;
string username = ApplicationController.Instance.GetSessionUsername();
@ -195,7 +165,6 @@ namespace MatterHackers.MatterControl
}
mainContainer.AddChild(new TextWidget(username, pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor));
//mainContainer.AddChild(new TextWidget(statusDescription, pointSize: 12, textColor: ActiveTheme.Instance.PrimaryTextColor));
FlowLayoutWidget buttonContainer = new FlowLayoutWidget();
buttonContainer.HAnchor = HAnchor.ParentLeftRight;
@ -213,23 +182,13 @@ namespace MatterHackers.MatterControl
signOutButton.VAnchor = VAnchor.ParentCenter;
signOutButton.Click += new EventHandler(signOutButton_Click);
signOutButton.Visible = signedIn;
buttonContainer.AddChild(signOutButton);
statusMessage = new TextWidget("Please wait...", pointSize: 12, textColor: ActiveTheme.Instance.SecondaryAccentColor);
statusMessage.Visible = false;
buttonContainer.AddChild(statusMessage);
mainContainer.AddChild(buttonContainer);
ApplicationController.Instance.DoneReloadingAll.RegisterEvent(onDoneReloading, ref unregisterEvents);
}
void onDoneReloading(object sender, EventArgs e)
{
this.windowController.ChangeToHome();
}
void signInButton_Click(object sender, EventArgs e)
@ -258,44 +217,37 @@ namespace MatterHackers.MatterControl
public class SetupViewBase : AltGroupBox
{
protected readonly int TallButtonHeight = 28;
protected TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
protected LinkButtonFactory linkButtonFactory = new LinkButtonFactory();
protected RGBA_Bytes separatorLineColor;
protected TextImageButtonFactory textImageButtonFactory;
protected FlowLayoutWidget mainContainer;
protected WizardWindow windowController;
public SetupViewBase(string title,WizardWindow windowController)
internal WizardWindow WizardWindow { get; set; }
public SetupViewBase(string title)
: base(title != "" ? new TextWidget(title, pointSize: 18, textColor: ActiveTheme.Instance.SecondaryAccentColor) : null)
{
this.windowController = windowController;
this.Margin = new BorderDouble(2, 10, 2, 0);
SetDisplayAttributes();
mainContainer = new FlowLayoutWidget(Agg.UI.FlowDirection.TopToBottom);
mainContainer.HAnchor = HAnchor.ParentLeftRight;
mainContainer.Margin = new BorderDouble(6,0,0,6);
textImageButtonFactory = new TextImageButtonFactory()
{
normalFillColor = RGBA_Bytes.Transparent,
disabledFillColor = RGBA_Bytes.White,
FixedHeight = TallButtonHeight,
fontSize = 16,
borderWidth = 1,
normalBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200),
hoverBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200),
disabledTextColor = RGBA_Bytes.DarkGray,
hoverTextColor = ActiveTheme.Instance.PrimaryTextColor,
normalTextColor = ActiveTheme.Instance.SecondaryTextColor,
pressedTextColor = ActiveTheme.Instance.PrimaryTextColor,
};
mainContainer = new FlowLayoutWidget(Agg.UI.FlowDirection.TopToBottom)
{
HAnchor = HAnchor.ParentLeftRight,
Margin = new BorderDouble(6, 0, 0, 6)
};
AddChild(mainContainer);
}
private void SetDisplayAttributes()
{
//this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
this.separatorLineColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 100);
this.Margin = new BorderDouble(2, 10, 2, 0);
this.textImageButtonFactory.normalFillColor = RGBA_Bytes.Transparent;
this.textImageButtonFactory.disabledFillColor = RGBA_Bytes.White;
this.textImageButtonFactory.FixedHeight = TallButtonHeight;
this.textImageButtonFactory.fontSize = 16;
this.textImageButtonFactory.borderWidth = 1;
this.textImageButtonFactory.normalBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
this.textImageButtonFactory.hoverBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
this.textImageButtonFactory.disabledTextColor = RGBA_Bytes.DarkGray;
this.textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
this.textImageButtonFactory.normalTextColor = ActiveTheme.Instance.SecondaryTextColor;
this.textImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;
this.linkButtonFactory.fontSize = 11;
}
}
}

View file

@ -35,21 +35,17 @@ namespace MatterHackers.MatterControl
}
#endif
public SetupWizardTroubleshooting(WizardWindow windowController)
: base(windowController)
public SetupWizardTroubleshooting()
{
RefreshStatus();
//Construct buttons
cancelButton = whiteImageButtonFactory.Generate(LocalizedString.Get("Cancel"), centerText:true);
cancelButton.Click += (sender, e) =>
{
this.wizardWindow.ChangeToPanel(new SetupWizardConnect(windowController));
};
cancelButton = whiteImageButtonFactory.Generate("Cancel".Localize(), centerText:true);
cancelButton.Click += (s, e) => this.WizardWindow.ChangeToConnectForm();
//Construct buttons
nextButton = textImageButtonFactory.Generate(LocalizedString.Get("Continue"));
nextButton.Click += (sender, e) => UiThread.RunOnIdle(this.wizardWindow.Close);
nextButton = textImageButtonFactory.Generate("Continue".Localize());
nextButton.Click += (sender, e) => UiThread.RunOnIdle(this.WizardWindow.Close);
nextButton.Visible = false;
//Add buttons to buttonContainer

View file

@ -37,8 +37,7 @@ namespace MatterHackers.MatterControl
//Normally step one of the setup process
public class SetupWizardWifi : WizardPanel
{
public SetupWizardWifi(WizardWindow windowController)
: base(windowController)
public SetupWizardWifi()
{
contentRow.AddChild(new TextWidget("Wifi Setup".Localize() + ":", 0, 0, labelFontSize)
{
@ -57,10 +56,10 @@ namespace MatterHackers.MatterControl
//Construct buttons
Button skipButton = whiteImageButtonFactory.Generate("Skip".Localize(), centerText: true);
skipButton.Click += (s, e) => this.wizardWindow.ChangeToSetupPrinterForm();
skipButton.Click += (s, e) => this.WizardWindow.ChangeToSetupPrinterForm();
Button nextButton = textImageButtonFactory.Generate("Continue".Localize());
nextButton.Click += (s, e) => this.wizardWindow.ChangeToSetupPrinterForm();
nextButton.Click += (s, e) => this.WizardWindow.ChangeToSetupPrinterForm();
nextButton.Visible = false;
Button configureButton = whiteImageButtonFactory.Generate(LocalizedString.Get("Configure"), centerText: true);

View file

@ -1,16 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using MatterHackers.Agg;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl
{
@ -30,15 +21,12 @@ namespace MatterHackers.MatterControl
protected double labelFontSize = 12 * GuiWidget.DeviceScale;
protected double errorFontSize = 10 * GuiWidget.DeviceScale;
protected WizardWindow wizardWindow;
internal WizardWindow WizardWindow;
protected GuiWidget mainContainer;
public WizardPanel(WizardWindow wizardWindow, string unlocalizedTextForCancelButton = "Cancel", TextImageButtonFactory textButtonFactory = null)
: base()
public WizardPanel(string unlocalizedTextForCancelButton = "Cancel", TextImageButtonFactory textButtonFactory = null)
{
this.wizardWindow = wizardWindow;
whiteImageButtonFactory = new TextImageButtonFactory()
{
normalFillColor = RGBA_Bytes.White,
@ -80,7 +68,7 @@ namespace MatterHackers.MatterControl
cancelButton.Name = unlocalizedTextForCancelButton;
cancelButton.Click += (s, e) =>
{
UiThread.RunOnIdle(() => this.wizardWindow?.Close());
UiThread.RunOnIdle(() => WizardWindow?.Close());
};
// Create the main container

View file

@ -12,9 +12,14 @@ namespace MatterHackers.MatterControl
{
public class WizardWindow : SystemWindow
{
private bool editMode = false;
public static Func<bool> ShouldShowAuthPanel { get; set; }
public static Action ShowAuthDialog;
private static WizardWindow wizardWindow = null;
private static bool connectionWindowIsOpen = false;
protected PrinterInfo activePrinter;
private bool editMode = false;
public WizardWindow(bool openToHome = false)
: base(500 * GuiWidget.DeviceScale, 500 * GuiWidget.DeviceScale)
{
@ -27,150 +32,80 @@ namespace MatterHackers.MatterControl
}
else
{
//Todo - detect wifi connectivity
// Todo - detect wifi connectivity
bool WifiDetected = MatterControlApplication.Instance.IsNetworkConnected();
if (!WifiDetected)
{
ChangeToWifiForm();
}
else if (GetPrinterRecordCount() > 0)
{
ChangeToSetupPrinterForm();
}
else
{
ChangeToSetupPrinterForm();
}
}
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
this.Padding = new BorderDouble(8);
this.ShowAsSystemWindow();
MinimumSize = new Vector2(350 * GuiWidget.DeviceScale, 400 * GuiWidget.DeviceScale);
}
private static WizardWindow setupWizardWindow = null;
private static bool connectionWindowIsOpen = false;
public static Func<bool> ShouldShowAuthPanel { get; set; }
public static Action ShowAuthDialog;
public static void Show(bool openToHome = false)
{
if (connectionWindowIsOpen == false)
{
setupWizardWindow = new WizardWindow(openToHome);
wizardWindow = new WizardWindow(openToHome);
connectionWindowIsOpen = true;
setupWizardWindow.Closed += (parentSender, e) =>
wizardWindow.Closed += (parentSender, e) =>
{
connectionWindowIsOpen = false;
setupWizardWindow = null;
wizardWindow = null;
};
}
else
{
if (setupWizardWindow != null)
if (wizardWindow != null)
{
setupWizardWindow.BringToFront();
wizardWindow.BringToFront();
}
}
}
public override void OnMouseUp(MouseEventArgs mouseEvent)
{
base.OnMouseUp(mouseEvent);
}
private void DoNotChangeWindow()
{
//Empty function used as default callback for changeToWindowCallback
}
public void ChangeToSetupPrinterForm()
{
bool showAuthPanel = ShouldShowAuthPanel?.Invoke() ?? false;
if (showAuthPanel)
{
UiThread.RunOnIdle(ChangeToAuthPanel);
ChangeToAuthPanel();
}
else
{
UiThread.RunOnIdle(ChangeToAddPrinter);
ChangeToAddPrinter();
}
}
public void ChangeToConnectForm(bool editMode = false)
{
this.editMode = editMode;
UiThread.RunOnIdle(DoChangeToConnectForm);
}
public void DoChangeToConnectForm()
{
GuiWidget chooseConnectionWidget = new SetupWizardConnect(this);
this.RemoveAllChildren();
this.AddChild(chooseConnectionWidget);
this.Invalidate();
ChangeToPanel<SetupWizardConnect>();
}
public void ChangeToTroubleshooting()
{
UiThread.RunOnIdle(() =>
{
GuiWidget wizardForm = new SetupWizardTroubleshooting(this);
this.RemoveAllChildren();
this.AddChild(wizardForm);
this.Invalidate();
});
ChangeToPanel<SetupWizardTroubleshooting>();
}
public void ChangeToWifiForm(bool editMode = false)
{
this.editMode = editMode;
UiThread.RunOnIdle(DoChangeToWifiForm, null);
}
public void ChangeToPanel(WizardPanel panelToChangeTo)
{
this.RemoveAllChildren();
this.AddChild(panelToChangeTo);
this.Invalidate();
}
public void DoChangeToWifiForm(object state)
{
GuiWidget chooseConnectionWidget = new SetupWizardWifi(this);
this.RemoveAllChildren();
this.AddChild(chooseConnectionWidget);
this.Invalidate();
ChangeToPanel<SetupWizardWifi>();
}
public void ChangeToHome()
{
UiThread.RunOnIdle(DoChangeToHome, null);
ChangeToPanel<SetupWizardHome>();
}
public void DoChangeToHome(object state)
{
GuiWidget homeWidget = new SetupWizardHome(this);
this.RemoveAllChildren();
this.AddChild(homeWidget);
this.Invalidate();
}
private int GetPrinterRecordCount()
{
return Datastore.Instance.RecordCount("Printer");
}
internal void ChangeToAddPrinter()
{
this.activePrinter = null;
ChangeToStep(new SetupStepMakeModelName(this));
}
private void ChangeToStep(GuiWidget nextStep)
{
UiThread.RunOnIdle(() =>
@ -181,29 +116,47 @@ namespace MatterHackers.MatterControl
});
}
internal void ChangeToAddPrinter()
{
this.activePrinter = null;
ChangeToPanel<SetupStepMakeModelName>();
}
internal void ChangeToPanel<T>() where T : WizardPanel, new()
{
var panel = new T();
panel.WizardWindow = this;
ChangeToStep(panel);
}
internal void ChangeToSetupBaudRate()
{
ChangeToStep(new SetupStepBaudRate(this));
ChangeToPanel<SetupStepBaudRate>();
}
internal void ChangeToInstallDriver()
{
ChangeToStep(new SetupStepInstallDriver(this));
ChangeToPanel<SetupStepInstallDriver>();
}
internal void ChangeToSetupComPortOne()
{
ChangeToStep(new SetupStepComPortOne(this));
ChangeToPanel<SetupStepComPortOne>();
}
internal void ChangeToSetupCompPortTwo()
{
ChangeToStep(new SetupStepComPortTwo(this));
ChangeToPanel<SetupStepComPortTwo>();
}
internal void ChangeToSetupComPortManual()
{
ChangeToStep(new SetupStepComPortManual(this));
ChangeToPanel<SetupStepComPortManual>();
}
internal void ChangeToAuthPanel()
{
ChangeToPanel<ShowAuthPanel>();
}
internal void ChangeToInstallDriverOrComPortOne()
@ -229,10 +182,5 @@ namespace MatterHackers.MatterControl
ChangeToSetupComPortOne();
}
}
internal void ChangeToAuthPanel()
{
ChangeToStep(new ShowAuthPanel(this));
}
}
}