Changeset 16520 for branches/2947_ConfigurableIndexedDataTable/HeuristicLab.Optimizer/3.3/FileManager.cs
- Timestamp:
- 01/08/19 15:39:49 (6 years ago)
- Location:
- branches/2947_ConfigurableIndexedDataTable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2947_ConfigurableIndexedDataTable
- Property svn:mergeinfo changed
-
branches/2947_ConfigurableIndexedDataTable/HeuristicLab.Optimizer
- Property svn:mergeinfo changed
/branches/2839_HiveProjectManagement/HeuristicLab.Optimizer (added) merged: 16057 /branches/2892_LR-prediction-intervals/HeuristicLab.Optimizer (added) merged: 16388 /branches/2915-AbsoluteSymbol/HeuristicLab.Optimizer (added) merged: 16240 /branches/2965_CancelablePersistence/HeuristicLab.Optimizer (added) merged: 16325,16433 /branches/2972_PDPRowSelect/HeuristicLab.Optimizer (added) merged: 16518 /branches/HiveProjectManagement/HeuristicLab.Optimizer (added) merged: 15401 /trunk/HeuristicLab.Optimizer (added) merged: 16117,16356,16389,16430,16440,16506,16519
- Property svn:mergeinfo changed
-
branches/2947_ConfigurableIndexedDataTable/HeuristicLab.Optimizer/3.3/FileManager.cs
r15583 r16520 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(); 102 SetSaveOperationProgressInContentViews(content, true); 103 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); 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 AddProgressInContentViews(content, cancellationTokenSource, 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 (OperationCanceledException) { // do nothing if canceled 147 } catch (Exception ex) { 149 148 ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, "Cannot save file.", ex); 150 } 151 finally { 152 SetSaveOperationProgressInContentViews(content, false); 149 } finally { 150 Progress.Hide(content); 153 151 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().ResetAppStartingCursor(); 154 152 } 155 153 } 156 154 157 private static void SetSaveOperationProgressInContentViews(IStorableContent content, bool showProgress, string fileName = null) { 158 HeuristicLab.MainForm.WindowsForms.MainForm mainForm = MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>(); 159 #region Mono Compatibility 160 // removed the InvokeRequired check because of Mono 161 mainForm.Invoke((Action)delegate { 162 if (showProgress) { 163 mainForm.AddOperationProgressToContent(content, string.Format("Saving to file \"{0}\"...", Path.GetFileName(fileName ?? content.Filename))); 164 } else 165 mainForm.RemoveOperationProgressFromContent(content); 166 }); 167 #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()); 168 158 } 169 159 }
Note: See TracChangeset
for help on using the changeset viewer.