- Timestamp:
- 08/17/10 16:42:58 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Common/3.3/Content/ContentManager.cs
r3500 r4245 60 60 public static void Save(IStorableContent content, string filename, bool compressed) { 61 61 if (instance == null) throw new InvalidOperationException("ContentManager is not initialized."); 62 instance.SaveContent( (IStorableContent)content.Clone(), filename, compressed);62 instance.SaveContent(content, filename, compressed); 63 63 content.Filename = filename; 64 64 } 65 65 public static void SaveAsync(IStorableContent content, string filename, bool compressed, Action<IStorableContent, Exception> savingCompletedCallback) { 66 66 if (instance == null) throw new InvalidOperationException("ContentManager is not initialized."); 67 var action = new Action<IStorableContent, string, bool>(instance.SaveContent); 68 action.BeginInvoke(content, filename, compressed, delegate(IAsyncResult result) { 69 Exception error = null; 70 try { 71 action.EndInvoke(result); 72 content.Filename = filename; 73 } 74 catch (Exception ex) { 75 error = ex; 76 } 77 savingCompletedCallback(content, error); 78 }, null); 67 79 68 IStorableContent clone = null;69 try {70 clone = (IStorableContent)content.Clone();71 }72 catch (Exception ex) {73 savingCompletedCallback(content, ex);74 }75 76 if (clone != null) {77 var action = new Action<IStorableContent, string, bool>(instance.SaveContent);78 action.BeginInvoke(clone, filename, compressed, delegate(IAsyncResult result) {79 Exception error = null;80 try {81 action.EndInvoke(result);82 content.Filename = filename;83 }84 catch (Exception ex) {85 error = ex;86 }87 savingCompletedCallback(content, error);88 }, null);89 }90 80 } 91 81 protected abstract void SaveContent(IStorableContent content, string filename, bool compressed); -
trunk/sources/HeuristicLab.Optimizer/3.3/FileManager.cs
r4068 r4245 21 21 22 22 using System; 23 using System.Linq; 23 24 using System.Windows.Forms; 24 25 using HeuristicLab.Common; … … 42 43 if (newItemDialog.ShowDialog() == DialogResult.OK) { 43 44 IView view = MainFormManager.MainForm.ShowContent(newItemDialog.Item); 44 if (view == null) MessageBox.Show("There is no view for the new item. It cannot be displayed.", "No View Available", MessageBoxButtons.OK, MessageBoxIcon.Error); 45 if (view == null) 46 ErrorHandling.ShowErrorDialog("There is no view for the new item. It cannot be displayed.", new InvalidOperationException("No View Available")); 45 47 } 46 48 } … … 66 68 try { 67 69 if (error != null) throw error; 68 Invoke(delegate() { 69 IView view = MainFormManager.MainForm.ShowContent(content); 70 if (view == null) MessageBox.Show("There is no view for the loaded item. It cannot be displayed.", "No View Available", MessageBoxButtons.OK, MessageBoxIcon.Error); 71 }); 70 IView view = MainFormManager.MainForm.ShowContent(content); 71 if (view == null) 72 ErrorHandling.ShowErrorDialog("There is no view for the loaded item. It cannot be displayed.", new InvalidOperationException("No View Available")); 72 73 } 73 74 catch (Exception ex) { … … 87 88 private static void Save(IContentView view) { 88 89 IStorableContent content = view.Content as IStorableContent; 89 if (!view.Locked && (content != null)) {90 if (!view.Locked && content != null) { 90 91 if (string.IsNullOrEmpty(content.Filename)) 91 92 SaveAs(view); 92 93 else { 93 94 ((OptimizerMainForm)MainFormManager.MainForm).SetAppStartingCursor(); 95 var views = MainFormManager.MainForm.Views.OfType<IContentView>().Where(v => v.Content == content).ToList(); 96 views.ForEach(v => v.ReadOnly = true); 97 views.ForEach(v => v.Locked = true); 94 98 ContentManager.SaveAsync(content, content.Filename, true, SavingCompleted); 95 99 } … … 104 108 public static void SaveAs(IContentView view) { 105 109 IStorableContent content = view.Content as IStorableContent; 106 if (!view.Locked && (content != null)) {110 if (!view.Locked && content != null) { 107 111 if (saveFileDialog == null) { 108 112 saveFileDialog = new SaveFileDialog(); … … 116 120 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 117 121 ((OptimizerMainForm)MainFormManager.MainForm).SetAppStartingCursor(); 122 var views = MainFormManager.MainForm.Views.OfType<IContentView>().Where(v => v.Content == content).ToList(); 123 views.ForEach(v => v.ReadOnly = true); 124 views.ForEach(v => v.Locked = true); 118 125 if (saveFileDialog.FilterIndex == 1) { 119 126 ContentManager.SaveAsync(content, saveFileDialog.FileName, false, SavingCompleted); … … 126 133 private static void SavingCompleted(IStorableContent content, Exception error) { 127 134 try { 135 var views = MainFormManager.MainForm.Views.OfType<IContentView>().Where(v => v.Content == content).ToList(); 136 views.ForEach(v => v.ReadOnly = false); 137 views.ForEach(v => v.Locked = false); 128 138 if (error != null) throw error; 129 Invoke(delegate() { 130 ((OptimizerMainForm)MainFormManager.MainForm).UpdateTitle(); 131 }); 139 MainFormManager.GetMainForm<OptimizerMainForm>().UpdateTitle(); 132 140 } 133 141 catch (Exception ex) { … … 138 146 } 139 147 } 140 141 private static void Invoke(Action a) {142 Form form = MainFormManager.MainForm as Form;143 if (form.InvokeRequired)144 form.Invoke(a);145 else146 a.Invoke();147 }148 148 } 149 149 }
Note: See TracChangeset
for help on using the changeset viewer.