Changeset 2143 for trunk/sources
- Timestamp:
- 07/07/09 02:24:34 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.AdvancedOptimizationFrontend/3.2/MainForm.cs
r2105 r2143 100 100 /// is neither a view nor an editor.</exception> 101 101 /// <param name="control">The control to display.</param> 102 delegate void ShowControlDelegate(IControl control);103 102 public void ShowControl(IControl control) { 104 103 if (InvokeRequired) Invoke((Action<IControl>)ShowControl,control); … … 183 182 else { 184 183 editor.Filename = task.filename; 184 editor.SaveFinished += new EventHandler(SaveFinished); 185 185 PluginManager.ControlManager.ShowControl(editor); 186 186 } … … 198 198 lock (locker) runningTasks++; 199 199 Cursor = Cursors.AppStarting; 200 ((Control)form.Editor).Enabled = false;201 200 EnableDisableItems(); 202 Task task = new Task(form.Editor.Filename, form.Editor.Item, form.Editor); 203 ThreadPool.QueueUserWorkItem(new WaitCallback(AsynchronousSave), task); 201 form.Editor.Save(); 204 202 } 205 203 } … … 210 208 } 211 209 } 212 private void AsynchronousSave(object state) { 213 Task task = (Task)state; 214 PersistenceManager.Save(task.storable, task.filename); 215 SaveFinished(task); 216 } 217 private void SaveFinished(Task task) { 210 private void SaveFinished(object sender, EventArgs e) { 218 211 if (InvokeRequired) 219 Invoke(new TaskFinishedDelegate(SaveFinished), task);212 Invoke(new EventHandler(SaveFinished), sender, e); 220 213 else { 221 ((Control)task.editor).Enabled = true;222 214 EnableDisableItems(); 223 215 lock (locker) { … … 246 238 MessageBox.Show("The selected item doesn't provide an editor.", "Editor Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 247 239 } else { 240 editor.SaveFinished += new EventHandler(SaveFinished); 248 241 PluginManager.ControlManager.ShowControl(editor); 249 242 EnableDisableItems(); -
trunk/sources/HeuristicLab.Core/3.2/EditorBase.cs
r1529 r2143 27 27 using System.Text; 28 28 using System.Windows.Forms; 29 using System.Threading; 29 30 30 31 namespace HeuristicLab.Core { … … 57 58 58 59 /// <summary> 60 /// Saves the contained item to a file. 61 /// </summary> 62 /// <remarks> 63 /// The filename to save the contained item to is given by <see cref="Filename"/>. 64 /// Save is an asynchronous method. After saving the contained item is finished, the 65 /// <see cref="SaveFinished"/> event is fired. 66 /// </remarks> 67 public void Save() { 68 Enabled = false; 69 ThreadPool.QueueUserWorkItem((o) => { 70 try { 71 PersistenceManager.Save(Item, Filename); 72 } 73 catch (Exception e) { 74 MessageBox.Show(String.Format( 75 "Sorry couldn't save file \"{0}\".\n The following exception occurred: {1}", 76 Filename, e.ToString()), 77 "Writer Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 78 } 79 finally { 80 Invoke(new Action(() => Enabled = true)); 81 OnSaveFinished(); 82 } 83 }); 84 } 85 86 /// <summary> 59 87 /// Updates all controls with the latest data of the model. 60 88 /// </summary> … … 79 107 FilenameChanged(this, new EventArgs()); 80 108 } 109 /// <summary> 110 /// Occurs when the filename was changed. 111 /// </summary> 112 public event EventHandler SaveFinished; 113 /// <summary> 114 /// Fires the <see cref="SaveFinished"/> event. 115 /// </summary> 116 protected virtual void OnSaveFinished() { 117 if (SaveFinished != null) 118 SaveFinished(this, new EventArgs()); 119 } 81 120 } 82 121 } -
trunk/sources/HeuristicLab.Core/3.2/HeuristicLab.Core-3.2.csproj
r1534 r2143 32 32 <UseApplicationTrust>false</UseApplicationTrust> 33 33 <BootstrapperEnabled>true</BootstrapperEnabled> 34 <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> 34 35 </PropertyGroup> 35 36 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> … … 90 91 <ItemGroup> 91 92 <Reference Include="System" /> 93 <Reference Include="System.Core"> 94 <RequiredTargetFramework>3.5</RequiredTargetFramework> 95 </Reference> 92 96 <Reference Include="System.Data" /> 93 97 <Reference Include="System.Drawing" /> -
trunk/sources/HeuristicLab.Core/3.2/Interfaces/IEditor.cs
r776 r2143 36 36 37 37 /// <summary> 38 /// Saves the contained item to a file. 39 /// </summary> 40 /// <remarks> 41 /// The filename to save the contained item to is given by <see cref="Filename"/>. 42 /// Save is an asynchronous method. After saving the contained item is finished, the 43 /// <see cref="SaveFinished"/> event is fired. 44 /// </remarks> 45 void Save(); 46 47 /// <summary> 38 48 /// Occurs when the filename was changed. 39 49 /// </summary> 40 50 event EventHandler FilenameChanged; 51 /// <summary> 52 /// Occurs after saving the contained object is finished. 53 /// </summary> 54 event EventHandler SaveFinished; 41 55 } 42 56 } -
trunk/sources/HeuristicLab.Core/3.2/PersistenceManager.cs
r1722 r2143 108 108 /// <param name="filename">The name of the file where the <paramref name="object"/> should be saved.</param> 109 109 public static void Save(IStorable instance, string filename) { 110 using(FileStream stream = File.Create(filename)) { 110 string tempfile = Path.GetTempFileName(); 111 using (FileStream stream = File.Create(tempfile)) { 111 112 Save(instance, stream); 112 113 stream.Close(); 113 114 } 115 File.Copy(tempfile, filename, true); 116 File.Delete(tempfile); 114 117 } 115 118 /// <summary>
Note: See TracChangeset
for help on using the changeset viewer.