private static WizardWindow GetWindow(string uri) { WizardWindow wizardWindow; if (allWindows.TryGetValue(uri, out wizardWindow)) { wizardWindow.BringToFront(); } else { wizardWindow = new WizardWindow(); wizardWindow.Closed += (s, e) => allWindows.Remove(uri); allWindows[uri] = wizardWindow; } return(wizardWindow); }
// Called after every startup and at the completion of every authentication change public void UserChanged() { ProfileManager.ReloadActiveUser(); // Ensure SQLite printers are imported ProfileManager.Instance.EnsurePrintersImported(); var guest = ProfileManager.Load("guest"); // If profiles.json was created, run the import wizard to pull in any SQLite printers if (guest?.Profiles?.Any() == true && !ProfileManager.Instance.IsGuestProfile && !ProfileManager.Instance.PrintersImported) { // Show the import printers wizard WizardWindow.Show <CopyGuestProfilesToUser>("/CopyGuestProfiles", "Copy Printers"); } }
public static void Show <PanelType>(string uri, string title) where PanelType : WizardPage, new() { WizardWindow existingWindow; if (allWindows.TryGetValue(uri, out existingWindow)) { existingWindow.BringToFront(); } else { existingWindow = new WizardWindow(); existingWindow.Closed += (s, e) => allWindows.Remove(uri); allWindows[uri] = existingWindow; } existingWindow.Title = title; existingWindow.ChangeToPage <PanelType>(); }
public static void ShowPrinterSetup(bool userRequestedNewPrinter = false) { WizardWindow wizardWindow = GetWindow("PrinterSetup"); wizardWindow.Title = "Setup Wizard".Localize(); // Do the printer setup logic // Todo - detect wifi connectivity bool WifiDetected = MatterControlApplication.Instance.IsNetworkConnected(); if (!WifiDetected) { wizardWindow.ChangeToPage <SetupWizardWifi>(); } else { wizardWindow.ChangeToSetupPrinterForm(userRequestedNewPrinter); } }
private void exportButton_Click() { WizardWindow.Close(); switch (exportMode) { case "slic3r": ActiveSliceSettings.Instance.ExportAsSlic3rConfig(); break; case "cura": ActiveSliceSettings.Instance.ExportAsCuraConfig(); break; case "mattercontrol": ActiveSliceSettings.Instance.ExportAsMatterControlConfig(); break; } }
private void ImportSettingsFile(string settingsFilePath) { if (newPrinterButton.Checked) { ProfileManager.ImportFromExisting(settingsFilePath); WizardWindow.ChangeToPage(new ImportSucceeded(importPrinterSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath))) { WizardWindow = this.WizardWindow, }); } else if (mergeButton.Checked) { MergeSettings(settingsFilePath); } else if (newQualityPresetButton.Checked) { ImportToPreset(settingsFilePath); } else if (newMaterialPresetButton.Checked) { ImportToPreset(settingsFilePath); } }
public CopyGuestProfilesToUser() : base("Close", "Copy Printers to Account") { var scrollWindow = new ScrollableWidget() { AutoScroll = true, HAnchor = HAnchor.ParentLeftRight, VAnchor = VAnchor.ParentBottomTop, }; scrollWindow.ScrollArea.HAnchor = HAnchor.ParentLeftRight; contentRow.AddChild(scrollWindow); var container = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.ParentLeftRight, }; scrollWindow.AddChild(container); container.AddChild(new WrappedTextWidget(importMessage, textColor: ActiveTheme.Instance.PrimaryTextColor)); var byCheckbox = new Dictionary <CheckBox, PrinterInfo>(); var guest = ProfileManager.Load("guest"); if (guest?.Profiles.Count > 0) { container.AddChild(new TextWidget("Printers to Copy:".Localize()) { TextColor = ActiveTheme.Instance.PrimaryTextColor, Margin = new BorderDouble(0, 3, 0, 15), }); foreach (var printerInfo in guest.Profiles) { var checkBox = new CheckBox(printerInfo.Name) { TextColor = ActiveTheme.Instance.PrimaryTextColor, Margin = new BorderDouble(5, 0, 0, 0), HAnchor = HAnchor.ParentLeft, Checked = true, }; checkBoxes.Add(checkBox); container.AddChild(checkBox); byCheckbox[checkBox] = printerInfo; } } var syncButton = textImageButtonFactory.Generate("Copy".Localize()); syncButton.Name = "CopyProfilesButton"; syncButton.Click += (s, e) => { // do the import foreach (var checkBox in checkBoxes) { if (checkBox.Checked) { // import the printer var printerInfo = byCheckbox[checkBox]; string existingPath = guest.ProfilePath(printerInfo); // PrinterSettings files must actually be copied to the users profile directory if (File.Exists(existingPath)) { File.Copy(existingPath, printerInfo.ProfilePath); // Only add if copy succeeds ProfileManager.Instance.Profiles.Add(printerInfo); } } } guest.Save(); // Close the window and update the PrintersImported flag UiThread.RunOnIdle(() => { WizardWindow.Close(); ProfileManager.Instance.PrintersImported = true; ProfileManager.Instance.Save(); }); }; CheckBox rememberChoice = new CheckBox("Don't remind me again".Localize(), ActiveTheme.Instance.PrimaryTextColor); contentRow.AddChild(rememberChoice); syncButton.Visible = true; cancelButton.Visible = true; // Close the window and update the PrintersImported flag cancelButton.Click += (s, e) => UiThread.RunOnIdle(() => { WizardWindow.Close(); if (rememberChoice.Checked) { ProfileManager.Instance.PrintersImported = true; ProfileManager.Instance.Save(); } }); //Add buttons to buttonContainer footerRow.AddChild(syncButton); footerRow.AddChild(new HorizontalSpacer()); footerRow.AddChild(cancelButton); footerRow.Visible = true; }
public SelectPartsOfPrinterToImport(string settingsFilePath, PrinterSettingsLayer destinationLayer, string sectionName = null) : base(unlocalizedTextForTitle: "Import Wizard") { this.isMergeIntoUserLayer = destinationLayer == ActiveSliceSettings.Instance.UserLayer; this.destinationLayer = destinationLayer; this.sectionName = sectionName; // TODO: Need to handle load failures for import attempts settingsToImport = PrinterSettings.LoadFile(settingsFilePath); this.headerLabel.Text = "Select What to Import".Localize(); this.settingsFilePath = settingsFilePath; var scrollWindow = new ScrollableWidget() { AutoScroll = true, HAnchor = HAnchor.ParentLeftRight, VAnchor = VAnchor.ParentBottomTop, }; scrollWindow.ScrollArea.HAnchor = HAnchor.ParentLeftRight; contentRow.AddChild(scrollWindow); var container = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.ParentLeftRight, }; scrollWindow.AddChild(container); if (isMergeIntoUserLayer) { container.AddChild(new WrappedTextWidget(importMessage, textColor: ActiveTheme.Instance.PrimaryTextColor)); } // add in the check boxes to select what to import container.AddChild(new TextWidget("Main Settings:") { TextColor = ActiveTheme.Instance.PrimaryTextColor, Margin = new BorderDouble(0, 3, 0, isMergeIntoUserLayer ? 10 : 0), }); var mainProfileRadioButton = new RadioButton("Printer Profile") { TextColor = ActiveTheme.Instance.PrimaryTextColor, Margin = new BorderDouble(5, 0), HAnchor = HAnchor.ParentLeft, Checked = true, }; container.AddChild(mainProfileRadioButton); if (settingsToImport.QualityLayers.Count > 0) { container.AddChild(new TextWidget("Quality Presets:") { TextColor = ActiveTheme.Instance.PrimaryTextColor, Margin = new BorderDouble(0, 3, 0, 15), }); int buttonIndex = 0; foreach (var qualitySetting in settingsToImport.QualityLayers) { RadioButton qualityButton = new RadioButton(qualitySetting.Name) { TextColor = ActiveTheme.Instance.PrimaryTextColor, Margin = new BorderDouble(5, 0, 0, 0), HAnchor = HAnchor.ParentLeft, }; container.AddChild(qualityButton); int localButtonIndex = buttonIndex; qualityButton.CheckedStateChanged += (s, e) => { if (qualityButton.Checked) { selectedQuality = localButtonIndex; } else { selectedQuality = -1; } }; buttonIndex++; } } if (settingsToImport.MaterialLayers.Count > 0) { container.AddChild(new TextWidget("Material Presets:") { TextColor = ActiveTheme.Instance.PrimaryTextColor, Margin = new BorderDouble(0, 3, 0, 15), }); int buttonIndex = 0; foreach (var materialSetting in settingsToImport.MaterialLayers) { RadioButton materialButton = new RadioButton(materialSetting.Name) { TextColor = ActiveTheme.Instance.PrimaryTextColor, Margin = new BorderDouble(5, 0), HAnchor = HAnchor.ParentLeft, }; container.AddChild(materialButton); int localButtonIndex = buttonIndex; materialButton.CheckedStateChanged += (s, e) => { if (materialButton.Checked) { selectedMaterial = localButtonIndex; } else { selectedMaterial = -1; } }; buttonIndex++; } } var mergeButtonTitle = this.isMergeIntoUserLayer ? "Merge".Localize() : "Import".Localize(); var mergeButton = textImageButtonFactory.Generate(mergeButtonTitle); mergeButton.Name = "Merge Profile"; mergeButton.Click += (s, e) => UiThread.RunOnIdle(() => { bool copyName = false; PrinterSettingsLayer sourceLayer = null; if (selectedMaterial > -1) { sourceLayer = settingsToImport.MaterialLayers[selectedMaterial]; copyName = true; } else if (selectedQuality > -1) { sourceLayer = settingsToImport.QualityLayers[selectedQuality]; copyName = true; } List <PrinterSettingsLayer> sourceFilter; if (selectedQuality == -1 && selectedMaterial == -1) { sourceFilter = new List <PrinterSettingsLayer>() { settingsToImport.OemLayer, settingsToImport.UserLayer }; } else { sourceFilter = new List <PrinterSettingsLayer>() { sourceLayer }; } ActiveSliceSettings.Instance.Merge(destinationLayer, settingsToImport, sourceFilter, copyName); this.Parents <SystemWindow>().FirstOrDefault()?.CloseOnIdle(); }); footerRow.AddChild(mergeButton); footerRow.AddChild(new HorizontalSpacer()); footerRow.AddChild(cancelButton); if (settingsToImport.QualityLayers.Count == 0 && settingsToImport.MaterialLayers.Count == 0) { // Only main setting so don't ask what to merge just do it. UiThread.RunOnIdle(() => { var sourceFilter = new List <PrinterSettingsLayer>() { settingsToImport.OemLayer ?? new PrinterSettingsLayer(), settingsToImport.UserLayer ?? new PrinterSettingsLayer() }; ActiveSliceSettings.Instance.Merge(destinationLayer, settingsToImport, sourceFilter, false); UiThread.RunOnIdle(ApplicationController.Instance.ReloadAdvancedControlsPanel); string successMessage = importPrinterSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath)); if (!isMergeIntoUserLayer) { string sourceName = isMergeIntoUserLayer ? Path.GetFileNameWithoutExtension(settingsFilePath) : destinationLayer[SettingsKey.layer_name]; string importSettingSuccessMessage = "You have successfully imported a new {1} setting. You can find '{0}' in your list of {1} settings.".Localize(); successMessage = importSettingSuccessMessage.FormatWith(sourceName, sectionName); } WizardWindow.ChangeToPage(new ImportSucceeded(successMessage) { WizardWindow = this.WizardWindow, }); }); } }
private void ImportToPreset(string settingsFilePath) { if (!string.IsNullOrEmpty(settingsFilePath) && File.Exists(settingsFilePath)) { PrinterSettingsLayer newLayer; string sectionName = (newMaterialPresetButton.Checked) ? "Material".Localize() : "Quality".Localize(); string importType = Path.GetExtension(settingsFilePath).ToLower(); switch (importType) { case ProfileManager.ProfileExtension: newLayer = new PrinterSettingsLayer(); newLayer[SettingsKey.layer_name] = Path.GetFileNameWithoutExtension(settingsFilePath); if (newQualityPresetButton.Checked) { ActiveSliceSettings.Instance.QualityLayers.Add(newLayer); } else { // newMaterialPresetButton.Checked ActiveSliceSettings.Instance.MaterialLayers.Add(newLayer); } // open a wizard to ask what to import to the preset WizardWindow.ChangeToPage(new SelectPartsOfPrinterToImport(settingsFilePath, newLayer, sectionName)); break; case ".slice": // legacy presets file extension case ".ini": var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath); bool containsValidSetting = false; { newLayer = new PrinterSettingsLayer(); newLayer.Name = Path.GetFileNameWithoutExtension(settingsFilePath); // Only be the base and oem layers (not the user, quality or material layer) var baseAndOEMCascade = new List <PrinterSettingsLayer> { ActiveSliceSettings.Instance.OemLayer, ActiveSliceSettings.Instance.BaseLayer }; foreach (var keyName in PrinterSettings.KnownSettings) { if (ActiveSliceSettings.Instance.Contains(keyName)) { containsValidSetting = true; string currentValue = ActiveSliceSettings.Instance.GetValue(keyName, baseAndOEMCascade).Trim(); string newValue; // Compare the value to import to the layer cascade value and only set if different if (settingsToImport.TryGetValue(keyName, out newValue) && currentValue != newValue) { newLayer[keyName] = newValue; } } } if (containsValidSetting) { if (newMaterialPresetButton.Checked) { ActiveSliceSettings.Instance.MaterialLayers.Add(newLayer); } else { ActiveSliceSettings.Instance.QualityLayers.Add(newLayer); } ActiveSliceSettings.Instance.Save(); WizardWindow.ChangeToPage(new ImportSucceeded(importSettingSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath), sectionName)) { WizardWindow = this.WizardWindow, }); } else { displayFailedToImportMessage(settingsFilePath); } } break; default: // Did not figure out what this file is, let the user know we don't understand it StyledMessageBox.ShowMessageBox(null, "Oops! Unable to recognize settings file '{0}'.".Localize().FormatWith(Path.GetFileName(settingsFilePath)), "Unable to Import".Localize()); break; } } Invalidate(); }
public SetupAccountView(TextImageButtonFactory textImageButtonFactory) : base("My Account") { this.textImageButtonFactory = textImageButtonFactory; bool signedIn = true; string username = AuthenticationData.Instance.ActiveSessionUsername; if (username == null) { signedIn = false; username = "******"; } FlowLayoutWidget nameAndStatus = new FlowLayoutWidget(); nameAndStatus.AddChild(new TextWidget(username, pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)); connectionStatus = new TextWidget(AuthenticationString, pointSize: 8, textColor: ActiveTheme.Instance.SecondaryTextColor) { Margin = new BorderDouble(5, 0, 0, 0), AutoExpandBoundsToText = true, }; if (signedIn) { nameAndStatus.AddChild(connectionStatus); } mainContainer.AddChild(nameAndStatus); RefreshStatus(); FlowLayoutWidget buttonContainer = new FlowLayoutWidget(); buttonContainer.HAnchor = HAnchor.ParentLeftRight; buttonContainer.Margin = new BorderDouble(0, 14); signInButton = textImageButtonFactory.Generate("Sign In".Localize()); signInButton.Margin = new BorderDouble(left: 0); signInButton.VAnchor = VAnchor.ParentCenter; signInButton.Visible = !signedIn; signInButton.Click += (s, e) => { #if __ANDROID__ if (MatterControlApplication.Instance.IsNetworkConnected() && AuthenticationData.Instance.IsConnected) { UiThread.RunOnIdle(ApplicationController.Instance.StartSignIn); } else { WizardWindow.Show <NetworkTroubleshooting>("/networktroubleshooting", "Network Troubleshooting"); } #else UiThread.RunOnIdle(ApplicationController.Instance.StartSignIn); #endif }; buttonContainer.AddChild(signInButton); signOutButton = textImageButtonFactory.Generate("Sign Out".Localize()); signOutButton.Margin = new BorderDouble(left: 0); signOutButton.VAnchor = VAnchor.ParentCenter; signOutButton.Visible = signedIn; signOutButton.Click += (s, e) => UiThread.RunOnIdle(ApplicationController.Instance.StartSignOut); buttonContainer.AddChild(signOutButton); buttonContainer.AddChild(new HorizontalSpacer()); // the redeem design code button textImageButtonFactory.disabledTextColor = new RGBA_Bytes(textImageButtonFactory.normalTextColor, 100); 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) => { ApplicationController.Instance.RedeemDesignCode?.Invoke(); }; 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, 10, 0); redeemShareButton.Click += (sender, e) => { ApplicationController.Instance.EnterShareCode?.Invoke(); }; if (!signedIn) { redeemPurchaseButton.Enabled = false; redeemShareButton.Enabled = false; } buttonContainer.AddChild(redeemShareButton); statusMessage = new TextWidget("Please wait...", pointSize: 12, textColor: ActiveTheme.Instance.SecondaryAccentColor); statusMessage.Visible = false; buttonContainer.AddChild(statusMessage); mainContainer.AddChild(buttonContainer); ApplicationController.Instance.DoneReloadingAll.RegisterEvent(RemoveAndNewControl, ref unregisterEvents); }
public AndroidConnectDevicePage() { TextWidget printerNameLabel = new TextWidget("Connect Your Device".Localize() + ":", 0, 0, labelFontSize) { TextColor = ActiveTheme.Instance.PrimaryTextColor, Margin = new BorderDouble(bottom: 10) }; contentRow.AddChild(printerNameLabel); contentRow.AddChild(new TextWidget("Instructions:".Localize(), 0, 0, 12, textColor: ActiveTheme.Instance.PrimaryTextColor)); contentRow.AddChild(new TextWidget("1. Power on your 3D Printer.".Localize(), 0, 0, 12, textColor: ActiveTheme.Instance.PrimaryTextColor)); contentRow.AddChild(new TextWidget("2. Attach your 3D Printer via USB.".Localize(), 0, 0, 12, textColor: ActiveTheme.Instance.PrimaryTextColor)); contentRow.AddChild(new TextWidget("3. Press 'Connect'.".Localize(), 0, 0, 12, textColor: ActiveTheme.Instance.PrimaryTextColor)); //Add inputs to main container PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(communicationStateChanged, ref unregisterEvents); connectButtonContainer = new FlowLayoutWidget() { HAnchor = HAnchor.ParentLeftRight, Margin = new BorderDouble(0, 6) }; //Construct buttons connectButton = whiteImageButtonFactory.Generate("Connect".Localize(), centerText: true); connectButton.Margin = new BorderDouble(0, 0, 10, 0); connectButton.Click += new EventHandler(ConnectButton_Click); skipButton = whiteImageButtonFactory.Generate("Skip".Localize(), centerText: true); skipButton.Click += new EventHandler(NextButton_Click); connectButtonContainer.AddChild(connectButton); connectButtonContainer.AddChild(skipButton); connectButtonContainer.AddChild(new HorizontalSpacer()); contentRow.AddChild(connectButtonContainer); skipMessage = new TextWidget("(Press 'Skip' to setup connection later)".Localize(), 0, 0, 10, textColor: ActiveTheme.Instance.PrimaryTextColor); contentRow.AddChild(skipMessage); generalError = new TextWidget("", 0, 0, errorFontSize) { TextColor = ActiveTheme.Instance.SecondaryAccentColor, HAnchor = HAnchor.ParentLeftRight, Visible = false, Margin = new BorderDouble(top: 20), }; contentRow.AddChild(generalError); //Construct buttons retryButton = whiteImageButtonFactory.Generate("Retry".Localize(), centerText: true); retryButton.Click += ConnectButton_Click; retryButton.Margin = new BorderDouble(0, 0, 10, 0); //Construct buttons troubleshootButton = whiteImageButtonFactory.Generate("Troubleshoot".Localize(), centerText: true); troubleshootButton.Click += (s, e) => WizardWindow.ChangeToPage <SetupWizardTroubleshooting>(); retryButtonContainer = new FlowLayoutWidget() { HAnchor = HAnchor.ParentLeftRight, Margin = new BorderDouble(0, 6), Visible = false }; retryButtonContainer.AddChild(retryButton); retryButtonContainer.AddChild(troubleshootButton); retryButtonContainer.AddChild(new HorizontalSpacer()); contentRow.AddChild(retryButtonContainer); //Construct buttons nextButton = textImageButtonFactory.Generate("Continue".Localize()); nextButton.Click += NextButton_Click; nextButton.Visible = false; GuiWidget hSpacer = new GuiWidget(); hSpacer.HAnchor = HAnchor.ParentLeftRight; //Add buttons to buttonContainer footerRow.AddChild(nextButton); footerRow.AddChild(hSpacer); footerRow.AddChild(cancelButton); updateControls(true); }
public override void OnDraw(Graphics2D graphics2D) { totalDrawTime.Restart(); GuiWidget.DrawCount = 0; using (new PerformanceTimer("Draw Timer", "MC Draw")) { base.OnDraw(graphics2D); } totalDrawTime.Stop(); millisecondTimer.Update((int)totalDrawTime.ElapsedMilliseconds); if (ShowMemoryUsed) { long memory = GC.GetTotalMemory(false); this.Title = "Allocated = {0:n0} : {1:000}ms, d{2} Size = {3}x{4}, onIdle = {5:00}:{6:00}, widgetsDrawn = {7}".FormatWith(memory, millisecondTimer.GetAverage(), drawCount++, this.Width, this.Height, UiThread.CountExpired, UiThread.Count, GuiWidget.DrawCount); if (DoCGCollectEveryDraw) { GC.Collect(); } } if (firstDraw) { firstDraw = false; foreach (string arg in commandLineArgs) { string argExtension = Path.GetExtension(arg).ToUpper(); if (argExtension.Length > 1 && MeshFileIo.ValidFileExtensions().Contains(argExtension)) { QueueData.Instance.AddItem(new PrintItemWrapper(new PrintItem(Path.GetFileName(arg), Path.GetFullPath(arg)))); } } TerminalWindow.ShowIfLeftOpen(); #if false { SystemWindow releaseNotes = new SystemWindow(640, 480); string releaseNotesFile = Path.Combine("C:/Users/LarsBrubaker/Downloads", "test1.html"); string releaseNotesContent = StaticData.Instance.ReadAllText(releaseNotesFile); HtmlWidget content = new HtmlWidget(releaseNotesContent, RGBA_Bytes.Black); content.AddChild(new GuiWidget(HAnchor.AbsolutePosition, VAnchor.ParentBottomTop)); content.VAnchor |= VAnchor.ParentTop; content.BackgroundColor = RGBA_Bytes.White; releaseNotes.AddChild(content); releaseNotes.BackgroundColor = RGBA_Bytes.Cyan; UiThread.RunOnIdle((state) => { releaseNotes.ShowAsSystemWindow(); }, 1); } #endif AfterFirstDraw?.Invoke(); if (false && UserSettings.Instance.get("SoftwareLicenseAccepted") != "true") { UiThread.RunOnIdle(() => WizardWindow.Show <LicenseAgreementPage>("SoftwareLicense", "Software License Agreement")); } if (!ProfileManager.Instance.ActiveProfiles.Any()) { // Start the setup wizard if no profiles exist UiThread.RunOnIdle(() => WizardWindow.Show()); } } //msGraph.AddData("ms", totalDrawTime.ElapsedMilliseconds); //msGraph.Draw(MatterHackers.Agg.Transform.Affine.NewIdentity(), graphics2D); }
public CopyGuestProfilesToUser(Action afterProfilesImported) : base("Cancel", "Select Printers to Sync") { var scrollWindow = new ScrollableWidget() { AutoScroll = true, HAnchor = HAnchor.ParentLeftRight, VAnchor = VAnchor.ParentBottomTop, }; scrollWindow.ScrollArea.HAnchor = HAnchor.ParentLeftRight; contentRow.AddChild(scrollWindow); var container = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.ParentLeftRight, }; scrollWindow.AddChild(container); container.AddChild(new WrappedTextWidget(importMessage, textColor: ActiveTheme.Instance.PrimaryTextColor)); var byCheckbox = new Dictionary <CheckBox, PrinterInfo>(); var guestProfileManager = ProfileManager.LoadGuestDB(); if (guestProfileManager?.Profiles.Count > 0) { container.AddChild(new TextWidget("Printers to Sync:".Localize()) { TextColor = ActiveTheme.Instance.PrimaryTextColor, Margin = new BorderDouble(0, 3, 0, 15), }); foreach (var printerInfo in guestProfileManager.Profiles) { var checkBox = new CheckBox(printerInfo.Name) { TextColor = ActiveTheme.Instance.PrimaryTextColor, Margin = new BorderDouble(5, 0, 0, 0), HAnchor = HAnchor.ParentLeft, Checked = true, }; checkBoxes.Add(checkBox); container.AddChild(checkBox); byCheckbox[checkBox] = printerInfo; } } var syncButton = textImageButtonFactory.Generate("Sync".Localize()); syncButton.Click += (s, e) => { // do the import foreach (var checkBox in checkBoxes) { if (checkBox.Checked) { // import the printer var printerInfo = byCheckbox[checkBox]; ProfileManager.Instance.Profiles.Add(printerInfo); guestProfileManager.Profiles.Remove(printerInfo); } } guestProfileManager.Save(); // close the window UiThread.RunOnIdle(() => { WizardWindow.Close(); // Call back into the original source afterProfilesImported(); }); }; syncButton.Visible = true; cancelButton.Visible = true; cancelButton.Click += (s, e) => UiThread.RunOnIdle(WizardWindow.Close); //Add buttons to buttonContainer footerRow.AddChild(syncButton); footerRow.AddChild(new HorizontalSpacer()); footerRow.AddChild(cancelButton); footerRow.Visible = true; }
void Merge() { var activeSettings = ActiveSliceSettings.Instance; var layerCascade = new List <PrinterSettingsLayer> { ActiveSliceSettings.Instance.OemLayer, ActiveSliceSettings.Instance.BaseLayer, destinationLayer, }; PrinterSettingsLayer layerToImport = settingsToImport.BaseLayer; if (selectedMaterial > -1) { var material = settingsToImport.MaterialLayers[selectedMaterial]; foreach (var item in material) { if (!skipKeys.Contains(item.Key)) { destinationLayer[item.Key] = item.Value; } } if (!isMergeIntoUserLayer && material.ContainsKey(SettingsKey.layer_name)) { destinationLayer[SettingsKey.layer_name] = material[SettingsKey.layer_name]; } } else if (selectedQuality > -1) { var quality = settingsToImport.QualityLayers[selectedQuality]; foreach (var item in quality) { if (!skipKeys.Contains(item.Key)) { destinationLayer[item.Key] = item.Value; } } if (!isMergeIntoUserLayer && quality.ContainsKey(SettingsKey.layer_name)) { destinationLayer[SettingsKey.layer_name] = quality[SettingsKey.layer_name]; } } else { foreach (var item in layerToImport) { // Compare the value to import to the layer cascade value and only set if different string currentValue = activeSettings.GetValue(item.Key, layerCascade).Trim(); string importValue = settingsToImport.GetValue(item.Key, layerCascade).Trim(); if (currentValue != item.Value) { destinationLayer[item.Key] = item.Value; } } } activeSettings.Save(); UiThread.RunOnIdle(ApplicationController.Instance.ReloadAdvancedControlsPanel); string successMessage = importPrinterSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath)); if (!isMergeIntoUserLayer) { string sourceName = isMergeIntoUserLayer ? Path.GetFileNameWithoutExtension(settingsFilePath) : destinationLayer[SettingsKey.layer_name]; successMessage = ImportSettingsPage.importSettingSuccessMessage.FormatWith(sourceName, sectionName); } WizardWindow.ChangeToPage(new ImportSucceeded(successMessage) { WizardWindow = this.WizardWindow, }); }
private void ImportToPreset(string settingsFilePath) { if (!string.IsNullOrEmpty(settingsFilePath) && File.Exists(settingsFilePath)) { PrinterSettingsLayer newLayer; string sectionName = (newMaterialPresetButton.Checked) ? "Material".Localize() : "Quality".Localize(); string importType = Path.GetExtension(settingsFilePath).ToLower(); switch (importType) { case ".printer": newLayer = new PrinterSettingsLayer(); newLayer["layer_name"] = Path.GetFileNameWithoutExtension(settingsFilePath); if (newQualityPresetButton.Checked) { ActiveSliceSettings.Instance.QualityLayers.Add(newLayer); } else { // newMaterialPresetButton.Checked ActiveSliceSettings.Instance.MaterialLayers.Add(newLayer); } // open a wizard to ask what to import to the preset WizardWindow.ChangeToPage(new SelectPartsOfPrinterToImport(settingsFilePath, newLayer, sectionName)); break; case ".slice": // legacy presets file extension case ".ini": var settingsToImport = PrinterSettingsLayer.LoadFromIni(settingsFilePath); string layerHeight; bool isSlic3r = importType == ".slice" || settingsToImport.TryGetValue(SettingsKey.layer_height, out layerHeight); if (isSlic3r) { newLayer = new PrinterSettingsLayer(); newLayer.Name = Path.GetFileNameWithoutExtension(settingsFilePath); // Only be the base and oem layers (not the user, quality or material layer) var baseAndOEMCascade = new List <PrinterSettingsLayer> { ActiveSliceSettings.Instance.OemLayer, ActiveSliceSettings.Instance.BaseLayer }; foreach (var item in settingsToImport) { string currentValue = ActiveSliceSettings.Instance.GetValue(item.Key, baseAndOEMCascade).Trim(); // Compare the value to import to the layer cascade value and only set if different if (currentValue != item.Value) { newLayer[item.Key] = item.Value; } } if (newMaterialPresetButton.Checked) { ActiveSliceSettings.Instance.MaterialLayers.Add(newLayer); } else { ActiveSliceSettings.Instance.QualityLayers.Add(newLayer); } ActiveSliceSettings.Instance.SaveChanges(); WizardWindow.ChangeToPage(new ImportSucceeded(importSettingSuccessMessage.FormatWith(Path.GetFileNameWithoutExtension(settingsFilePath), sectionName)) { WizardWindow = this.WizardWindow, }); } else { // looks like a cura file #if DEBUG throw new NotImplementedException("need to import from 'cure.ini' files"); #endif } break; default: // Did not figure out what this file is, let the user know we don't understand it StyledMessageBox.ShowMessageBox(null, "Oops! Unable to recognize settings file '{0}'.".Localize().FormatWith(Path.GetFileName(settingsFilePath)), "Unable to Import".Localize()); break; } } Invalidate(); }