public void CheckImportPrinterSettingsToPrinter()
		{
			StaticData.Instance = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
			MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

			var printerSettings = new PrinterSettings();
			printerSettings.SetValue(SettingsKey.cancel_gcode, "cancel gcode");
			printerSettings.SetValue(SettingsKey.start_gcode, "start gcode");

			string newValue = "----- cancel gcode ----";

			string notAnExistingKey = "NotAnExistingKey";

			var toImport = new PrinterSettings();
			toImport.SetValue(SettingsKey.cancel_gcode, newValue);
			toImport.SetValue(notAnExistingKey, "------------------");

			var sourceFilter = new List<PrinterSettingsLayer>()
			{
				toImport.UserLayer
			};

			printerSettings.Merge(printerSettings.UserLayer, toImport, sourceFilter);

			Assert.AreEqual(printerSettings.GetValue(SettingsKey.cancel_gcode), newValue, "Imported setting applied");
			Assert.IsEmpty(printerSettings.GetValue(notAnExistingKey), "Invalid settings keys should be skipped");
		}
		PrinterSettings GetProfile(string[] settings)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			for(int i=0; i<settings.Length; i+=2)
			{
				dictionary.Add(settings[i], settings[i + 1]);
			}
			var profile = new PrinterSettings()
			{
				OemLayer = new PrinterSettingsLayer(dictionary)
			};

			return profile;
		}
		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];
						successMessage = ImportSettingsPage.importSettingSuccessMessage.FormatWith(sourceName, sectionName);
					}

					WizardWindow.ChangeToPage(new ImportSucceeded(successMessage)
					{
						WizardWindow = this.WizardWindow,
					});
				});
			}
		}
        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(() =>
            {
                PrinterSettingsLayer sourceLayer = null;
                if (selectedMaterial > -1)
                {
                    sourceLayer = settingsToImport.MaterialLayers[selectedMaterial];
                }
                else if (selectedQuality > -1)
                {
                    sourceLayer = settingsToImport.QualityLayers[selectedQuality];
                }

                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);

                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);
                    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,
                    });
                });
            }
        }