- Timestamp:
- 11/23/18 15:37:24 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2965_CancelablePersistence/HeuristicLab.Optimizer/3.3/FileManager.cs
r15583 r16325 23 23 using System.Collections.Generic; 24 24 using System.IO; 25 using System.Threading; 25 26 using System.Windows.Forms; 26 27 using HeuristicLab.Common; … … 78 79 if (view == null) 79 80 ErrorHandling.ShowErrorDialog("There is no view for the loaded item. It cannot be displayed.", new InvalidOperationException("No View Available")); 80 } 81 catch (Exception ex) { 81 } catch (Exception ex) { 82 82 ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, "Cannot open file.", ex); 83 } 84 finally { 83 } finally { 85 84 ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).ResetAppStartingCursor(); 86 85 } … … 100 99 else { 101 100 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().SetAppStartingCursor(); 101 var cancellationTokenSource = new CancellationTokenSource(); 102 102 SetSaveOperationProgressInContentViews(content, true); 103 ContentManager.SaveAsync(content, content.Filename, true, SavingCompleted );103 ContentManager.SaveAsync(content, content.Filename, true, SavingCompleted, cancellationTokenSource.Token); 104 104 } 105 105 } … … 132 132 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 133 133 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().SetAppStartingCursor(); 134 SetSaveOperationProgressInContentViews(content, true, saveFileDialog.FileName); 135 if (saveFileDialog.FilterIndex == 1) { 136 ContentManager.SaveAsync(content, saveFileDialog.FileName, false, SavingCompleted); 137 } else { 138 ContentManager.SaveAsync(content, saveFileDialog.FileName, true, SavingCompleted); 139 } 134 bool compressed = saveFileDialog.FilterIndex != 1; 135 var cancellationTokenSource = new CancellationTokenSource(); 136 SetSaveOperationProgressInContentViews(content, compressed, saveFileDialog.FileName); 137 138 ContentManager.SaveAsync(content, saveFileDialog.FileName, compressed, SavingCompleted, cancellationTokenSource.Token); 140 139 } 141 140 } … … 145 144 if (error != null) throw error; 146 145 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().UpdateTitle(); 147 } 148 catch (Exception ex) { 146 } catch (Exception ex) { 149 147 ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, "Cannot save file.", ex); 150 } 151 finally { 148 } finally { 152 149 SetSaveOperationProgressInContentViews(content, false); 153 150 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().ResetAppStartingCursor(); … … 167 164 #endregion 168 165 } 166 167 /* For later merge with #2845 168 private static void AddProgressInContentViews(IStorableContent content, CancellationTokenSource cancellationTokenSource, string fileName = null) { 169 string message = string.Format("Saving to file \"{0}\"...", Path.GetFileName(fileName ?? content.Filename)); 170 Progress.Show(content, message, ProgressMode.Indeterminate, cancelRequestHandler: () => cancellationTokenSource.Cancel()); 171 }*/ 169 172 } 170 173 }
Note: See TracChangeset
for help on using the changeset viewer.