diff --git a/CustomWidgets/ExportPrintItemWindow.cs b/CustomWidgets/ExportPrintItemWindow.cs index a854bf1f7..f69edb7f0 100644 --- a/CustomWidgets/ExportPrintItemWindow.cs +++ b/CustomWidgets/ExportPrintItemWindow.cs @@ -304,32 +304,35 @@ namespace MatterHackers.MatterControl saveParams.Title = "MatterControl: Export File"; saveParams.ActionButtonLabel = "Export"; - System.IO.Stream streamToSaveTo = FileDialog.SaveFileDialog(ref saveParams); - if (streamToSaveTo != null) - { - streamToSaveTo.Close (); + FileDialog.SaveFileDialog(saveParams, onExportGcodeFileSelected); - gcodePathAndFilenameToSave = saveParams.FileName; - string extension = Path.GetExtension(gcodePathAndFilenameToSave); + } + + void onExportGcodeFileSelected(SaveFileDialogParams saveParams) + { + if (saveParams.FileName != null) + { + gcodePathAndFilenameToSave = saveParams.FileName; + string extension = Path.GetExtension(gcodePathAndFilenameToSave); if(extension == "") { - File.Delete(gcodePathAndFilenameToSave); - gcodePathAndFilenameToSave += ".gcode"; + File.Delete(gcodePathAndFilenameToSave); + gcodePathAndFilenameToSave += ".gcode"; } - if (Path.GetExtension(printItemWrapper.FileLocation).ToUpper() == ".STL") - { - Close(); - SlicingQueue.Instance.QueuePartForSlicing(printItemWrapper); - printItemWrapper.SlicingDone.RegisterEvent(sliceItem_Done, ref unregisterEvents); - } - else if (partIsGCode) - { - Close(); - SaveGCodeToNewLocation(printItemWrapper.FileLocation, gcodePathAndFilenameToSave); - } - } - } + if (Path.GetExtension(printItemWrapper.FileLocation).ToUpper() == ".STL") + { + Close(); + SlicingQueue.Instance.QueuePartForSlicing(printItemWrapper); + printItemWrapper.SlicingDone.RegisterEvent(sliceItem_Done, ref unregisterEvents); + } + else if (partIsGCode) + { + Close(); + SaveGCodeToNewLocation(printItemWrapper.FileLocation, gcodePathAndFilenameToSave); + } + } + } void ExportX3G_Click(object state) @@ -338,11 +341,13 @@ namespace MatterHackers.MatterControl saveParams.Title = "MatterControl: Export File"; saveParams.ActionButtonLabel = "Export"; - System.IO.Stream streamToSaveTo = FileDialog.SaveFileDialog(ref saveParams); - if (streamToSaveTo != null) - { - streamToSaveTo.Close (); + FileDialog.SaveFileDialog(saveParams, onExportX3gFileSelected); + } + void onExportX3gFileSelected(SaveFileDialogParams saveParams) + { + if (saveParams.FileName != null) + { x3gPathAndFilenameToSave = saveParams.FileName; string extension = Path.GetExtension(x3gPathAndFilenameToSave); if(extension == "") @@ -455,28 +460,30 @@ namespace MatterHackers.MatterControl saveParams.ActionButtonLabel = "Export"; saveParams.FileName = printItemWrapper.Name; - System.IO.Stream streamToSaveTo = FileDialog.SaveFileDialog(ref saveParams); + FileDialog.SaveFileDialog(saveParams, onExportStlFileSelected); - if (streamToSaveTo != null) - { - streamToSaveTo.Close (); - Close(); - } - - string filePathToSave = saveParams.FileName; - if (filePathToSave != null && filePathToSave != "") - { - string extension = Path.GetExtension(filePathToSave); - if (extension == "") - { - File.Delete(filePathToSave); - filePathToSave += ".stl"; - } - File.Copy(printItemWrapper.FileLocation, filePathToSave, true); - ShowFileIfRequested(filePathToSave); - } } + void onExportStlFileSelected(SaveFileDialogParams saveParams) + { + Close(); + if (saveParams.FileName != null) + { + string filePathToSave = saveParams.FileName; + if (filePathToSave != null && filePathToSave != "") + { + string extension = Path.GetExtension(filePathToSave); + if (extension == "") + { + File.Delete(filePathToSave); + filePathToSave += ".stl"; + } + File.Copy(printItemWrapper.FileLocation, filePathToSave, true); + ShowFileIfRequested(filePathToSave); + } + } + } + void sliceItem_Done(object sender, EventArgs e) { PrintItemWrapper sliceItem = (PrintItemWrapper)sender; diff --git a/SlicerConfiguration/SlicePresetsWindow/SlicePresetDetailWidget.cs b/SlicerConfiguration/SlicePresetsWindow/SlicePresetDetailWidget.cs index d6214585f..8581d44b1 100644 --- a/SlicerConfiguration/SlicePresetsWindow/SlicePresetDetailWidget.cs +++ b/SlicerConfiguration/SlicePresetsWindow/SlicePresetDetailWidget.cs @@ -948,14 +948,18 @@ namespace MatterHackers.MatterControl.SlicerConfiguration SaveFileDialogParams saveParams = new SaveFileDialogParams("Save Slice Preset|*." + configFileExtension, documentsPath); saveParams.FileName = presetNameInput.Text; - System.IO.Stream streamToSaveTo = FileDialog.SaveFileDialog(ref saveParams); - if (streamToSaveTo != null) - { - streamToSaveTo.Close(); - GenerateConfigFile(saveParams.FileName); - } + FileDialog.SaveFileDialog(saveParams, onSaveFileSelected); + } + void onSaveFileSelected(SaveFileDialogParams saveParams) + { + if (saveParams.FileName != null) + { + GenerateConfigFile(saveParams.FileName); + } + } + public void GenerateConfigFile(string fileName) { List configFileAsList = new List(); diff --git a/Utilities/ManifestFileHandler.cs b/Utilities/ManifestFileHandler.cs index fba2a1914..512a972ef 100644 --- a/Utilities/ManifestFileHandler.cs +++ b/Utilities/ManifestFileHandler.cs @@ -116,14 +116,18 @@ namespace MatterHackers.MatterControl string documentsPath = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal); SaveFileDialogParams saveParams = new SaveFileDialogParams("Save Project|*.mcp", initialDirectory: documentsPath); - System.IO.Stream streamToSaveTo = FileDialog.SaveFileDialog(ref saveParams); - if (streamToSaveTo != null) - { - streamToSaveTo.Close(); - ExportToJson(saveParams.FileName); - } + FileDialog.SaveFileDialog(saveParams, onSaveFileSelected); + } + void onSaveFileSelected(SaveFileDialogParams saveParams) + { + if (saveParams.FileName != null) + { + ExportToJson(saveParams.FileName); + } + } + static string applicationDataPath = ApplicationDataStorage.Instance.ApplicationUserDataPath; static string defaultPathAndFileName = applicationDataPath + "/data/default.mcp"; public void ExportToJson(string savedFileName = null) diff --git a/Utilities/ProjectFileHandler.cs b/Utilities/ProjectFileHandler.cs index 772b8e34b..ad0d41023 100644 --- a/Utilities/ProjectFileHandler.cs +++ b/Utilities/ProjectFileHandler.cs @@ -155,14 +155,17 @@ namespace MatterHackers.MatterControl string documentsPath = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal); SaveFileDialogParams saveParams = new SaveFileDialogParams("Save Project|*.zip", initialDirectory: documentsPath); - System.IO.Stream streamToSaveTo = FileDialog.SaveFileDialog(ref saveParams); - if (streamToSaveTo != null) - { - streamToSaveTo.Close(); - ExportToProjectArchive(saveParams.FileName); - } + FileDialog.SaveFileDialog(saveParams, onSaveFileSelected); } + void onSaveFileSelected(SaveFileDialogParams saveParams) + { + if (saveParams.FileName != null) + { + ExportToProjectArchive(saveParams.FileName); + } + } + static string applicationDataPath = ApplicationDataStorage.Instance.ApplicationUserDataPath; static string defaultManifestPathAndFileName = Path.Combine(applicationDataPath, "data", "temp", "project-assembly", "manifest.json"); static string defaultProjectPathAndFileName = Path.Combine(applicationDataPath, "data", "default.zip");