From cc9dc694136c9155ee1a01ef1d0de4f366f4ac02 Mon Sep 17 00:00:00 2001 From: jlewin Date: Tue, 4 Jun 2019 17:12:53 -0700 Subject: [PATCH] Simplify --- .../CustomWidgets/ExportPrintItemPage.cs | 27 ++++++------------- .../View3D/PrinterBar/PrintPopupMenu.cs | 24 ++++++++++++----- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs b/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs index 930df6675..1b9bff7b3 100644 --- a/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs +++ b/MatterControlLib/CustomWidgets/ExportPrintItemPage.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2018, Lars Brubaker, John Lewin +Copyright (c) 2019, Lars Brubaker, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -31,7 +31,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Threading.Tasks; using MatterHackers.Agg; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; @@ -48,18 +47,13 @@ namespace MatterHackers.MatterControl private CheckBox showInFolderAfterSave; private Dictionary exportPluginButtons; - private IEnumerable libraryItems; - private bool centerOnBed; private FlowLayoutWidget validationPanel; public ExportPrintItemPage(IEnumerable libraryItems, bool centerOnBed, PrinterConfig printer) { - this.centerOnBed = centerOnBed; this.WindowTitle = "Export File".Localize(); this.HeaderText = "Export selection to".Localize() + ":"; - - this.libraryItems = libraryItems; this.Name = "Export Item Window"; var commonMargin = new BorderDouble(4, 2); @@ -160,7 +154,6 @@ namespace MatterHackers.MatterControl } } - exportPluginButtons.Add(pluginButton, plugin); } @@ -211,11 +204,7 @@ namespace MatterHackers.MatterControl public static void DoExport(IEnumerable libraryItems, PrinterConfig printer, IExportPlugin exportPlugin, bool centerOnBed = false, bool showFile = false) { - string fileTypeFilter = ""; - string targetExtension = ""; - - fileTypeFilter = exportPlugin.ExtensionFilter; - targetExtension = exportPlugin.FileExtension; + string targetExtension = exportPlugin.FileExtension; if (exportPlugin is FolderExport) { @@ -247,7 +236,7 @@ namespace MatterHackers.MatterControl string title = ApplicationController.Instance.ProductName + " - " + "Export File".Localize(); string workspaceName = "Workspace " + DateTime.Now.ToString("yyyy-MM-dd HH_mm_ss"); AggContext.FileDialogs.SaveFileDialog( - new SaveFileDialogParams(fileTypeFilter) + new SaveFileDialogParams(exportPlugin.ExtensionFilter) { Title = title, ActionButtonLabel = "Export".Localize(), @@ -297,11 +286,11 @@ namespace MatterHackers.MatterControl { bool showGenerateErrors = !(exportPlugin is GCodeExport); - // Only show errors in Generate if not GCodeExport - GCodeExport shows validation errors before Generate call - if (showGenerateErrors) - { - ApplicationController.Instance.ShowValidationErrors("Export Error".Localize(), exportErrors); - } + // Only show errors in Generate if not GCodeExport - GCodeExport shows validation errors before Generate call + if (showGenerateErrors) + { + ApplicationController.Instance.ShowValidationErrors("Export Error".Localize(), exportErrors); + } } }); } diff --git a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs index a1c68d984..4f07806e3 100644 --- a/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs +++ b/MatterControlLib/PartPreviewWindow/View3D/PrinterBar/PrintPopupMenu.cs @@ -201,13 +201,18 @@ namespace MatterHackers.MatterControl.PartPreviewWindow foreach (IExportPlugin plugin in PluginFinder.CreateInstancesOf()) { - if (printer.Settings.GetValue("enable_sailfish_communication")) { - if (plugin is X3GExport) { + if (printer.Settings.GetValue("enable_sailfish_communication")) + { + if (plugin is X3GExport) + { exportPlugin = (GCodeExport)plugin; exportButtonText = "Export X3G".Localize(); } - } else { - if (plugin is GCodeExport & !(plugin is X3GExport)) { + } + else + { + if (plugin is GCodeExport & !(plugin is X3GExport)) + { exportPlugin = (GCodeExport)plugin; } } @@ -215,13 +220,20 @@ namespace MatterHackers.MatterControl.PartPreviewWindow exportPlugin.Initialize(printer); - var exportGcodeButton = new TextButton(exportButtonText, menuTheme) { + var exportGcodeButton = new TextButton(exportButtonText, menuTheme) + { Name = "Export Gcode Button", Enabled = exportPlugin.Enabled, ToolTipText = exportPlugin.DisabledReason, }; - exportGcodeButton.Click += (s, e) => ExportPrintItemPage.DoExport(new[] { new InMemoryLibraryItem(printer.Bed.Scene) }, printer, exportPlugin ); + exportGcodeButton.Click += (s, e) => + { + ExportPrintItemPage.DoExport( + new[] { new InMemoryLibraryItem(printer.Bed.Scene) }, + printer, + exportPlugin); + }; var hasErrors = errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Error); var hasWarnings = errors.Any(e => e.ErrorLevel == ValidationErrorLevel.Warning