Changeset 17068 for stable/HeuristicLab.Optimizer
- Timestamp:
- 07/04/19 15:26:27 (6 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Optimizer
- Property svn:mergeinfo changed
/branches/2965_CancelablePersistence/HeuristicLab.Optimizer (added) merged: 16325,16433 /trunk/HeuristicLab.Optimizer reverse-merged: 16117,16356,16389 /trunk/sources/HeuristicLab.Optimizer reverse-merged: 15581,15583,15589,15591
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Optimizer/3.3/FileManager.cs
r17062 r17068 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; … … 98 99 else { 99 100 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().SetAppStartingCursor(); 100 SetSaveOperationProgressInContentViews(content, true); 101 ContentManager.SaveAsync(content, content.Filename, true, SavingCompleted); 101 var cancellationTokenSource = new CancellationTokenSource(); 102 AddProgressInContentViews(content, cancellationTokenSource); 103 ContentManager.SaveAsync(content, content.Filename, true, SavingCompleted, cancellationTokenSource.Token); 102 104 } 103 105 } … … 130 132 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 131 133 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().SetAppStartingCursor(); 132 SetSaveOperationProgressInContentViews(content, true, saveFileDialog.FileName); 133 if (saveFileDialog.FilterIndex == 1) { 134 ContentManager.SaveAsync(content, saveFileDialog.FileName, false, SavingCompleted); 135 } else { 136 ContentManager.SaveAsync(content, saveFileDialog.FileName, true, SavingCompleted); 137 } 134 bool compressed = saveFileDialog.FilterIndex != 1; 135 var cancellationTokenSource = new CancellationTokenSource(); 136 AddProgressInContentViews(content, cancellationTokenSource, saveFileDialog.FileName); 137 138 ContentManager.SaveAsync(content, saveFileDialog.FileName, compressed, SavingCompleted, cancellationTokenSource.Token); 138 139 } 139 140 } … … 143 144 if (error != null) throw error; 144 145 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().UpdateTitle(); 146 } catch (OperationCanceledException) { // do nothing if canceled 145 147 } catch (Exception ex) { 146 148 ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, "Cannot save file.", ex); 147 149 } finally { 148 SetSaveOperationProgressInContentViews(content, false);150 Progress.Hide(content); 149 151 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().ResetAppStartingCursor(); 150 152 } 151 153 } 152 154 153 private static void SetSaveOperationProgressInContentViews(IStorableContent content, bool showProgress, string fileName = null) { 154 HeuristicLab.MainForm.WindowsForms.MainForm mainForm = MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>(); 155 #region Mono Compatibility 156 // removed the InvokeRequired check because of Mono 157 mainForm.Invoke((Action)delegate { 158 if (showProgress) { 159 Progress.Show(content, string.Format("Saving to file \"{0}\"...", Path.GetFileName(fileName ?? content.Filename))); 160 } else 161 Progress.Hide(content); 162 }); 163 #endregion 155 private static void AddProgressInContentViews(IStorableContent content, CancellationTokenSource cancellationTokenSource, string fileName = null) { 156 string message = string.Format("Saving to file \"{0}\"...", Path.GetFileName(fileName ?? content.Filename)); 157 Progress.Show(content, message, ProgressMode.Indeterminate, cancelRequestHandler: () => cancellationTokenSource.Cancel()); 164 158 } 165 159 }
Note: See TracChangeset
for help on using the changeset viewer.