Changeset 2547
- Timestamp:
- 12/08/09 02:35:40 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core.Views/3.3/IItemView.cs
r2546 r2547 40 40 /// </summary> 41 41 event EventHandler ItemChanged; 42 43 event EventHandler Closed; 42 44 } 43 45 } -
trunk/sources/HeuristicLab.Core.Views/3.3/ItemViewBase.cs
r2546 r2547 56 56 } 57 57 } 58 private string myCaption;59 /// <summary>60 /// Gets or sets the caption of the current instance.61 /// </summary>62 /// <remarks>Call <see cref="OnCaptionChanged"/> in the setter if a new item is set.</remarks>63 public string Caption {64 get { return myCaption; }65 set {66 if (value != myCaption) {67 myCaption = value;68 OnCaptionChanged();69 }70 }71 }72 58 73 59 /// <summary> … … 97 83 public override void Refresh() { 98 84 if (InvokeRequired) { 99 Invoke(new MethodInvoker(Refresh));85 Invoke(new Action(Refresh)); 100 86 } else { 101 87 UpdateControls(); … … 110 96 Caption = "View"; 111 97 else 112 Caption = "View (" + Item.GetType().Name + ")";98 Caption = Item.Name; 113 99 114 100 } … … 125 111 ItemChanged(this, new EventArgs()); 126 112 } 127 /// <summary> 128 /// Occurs when the current caption was changed. 129 /// </summary> 130 public event EventHandler CaptionChanged; 131 /// <summary> 132 /// Fires a new <c>CaptionChanged</c> event. 133 /// </summary> 134 protected virtual void OnCaptionChanged() { 135 if (CaptionChanged != null) 136 CaptionChanged(this, new EventArgs()); 113 114 public event EventHandler Closed; 115 public override void OnClosed(object sender, EventArgs e) { 116 base.OnClosed(sender, e); 117 if (Closed != null) 118 Closed(this, e); 137 119 } 138 120 -
trunk/sources/HeuristicLab.Optimizer/3.3/FileManager.cs
r2546 r2547 3 3 using System.Linq; 4 4 using System.Text; 5 using System.Threading; 6 using System.IO; 5 7 using System.Windows.Forms; 6 8 using HeuristicLab.MainForm; … … 12 14 internal static class FileManager { 13 15 16 #region Private Class FileInfo 14 17 private class FileInfo { 15 18 public string Filename { get; set; } … … 27 30 } 28 31 } 29 30 private static Dictionary<IItem, FileInfo> files = new Dictionary<IItem, FileInfo>(); 31 private static NewItemDialog newItemDialog = null; 32 private static OpenFileDialog openFileDialog = null; 33 private static SaveFileDialog saveFileDialog = null; 32 #endregion 33 34 private static Dictionary<IItemView, FileInfo> files; 35 private static NewItemDialog newItemDialog; 36 private static OpenFileDialog openFileDialog; 37 private static SaveFileDialog saveFileDialog; 38 private static int waitingCursors; 39 private static int newDocumentsCounter; 40 41 static FileManager() { 42 files = new Dictionary<IItemView, FileInfo>(); 43 newItemDialog = null; 44 openFileDialog = null; 45 saveFileDialog = null; 46 waitingCursors = 0; 47 newDocumentsCounter = 1; 48 } 34 49 35 50 public static void New() { 36 51 if (newItemDialog == null) newItemDialog = new NewItemDialog(); 37 52 if (newItemDialog.ShowDialog() == DialogResult.OK) { 38 MainFormManager.MainForm.ShowView(MainFormManager.CreateDefaultView(newItemDialog.Item)); 39 files.Add(newItemDialog.Item, new FileInfo()); 53 IItemView view = MainFormManager.CreateDefaultView(newItemDialog.Item) as IItemView; 54 if (view != null) { 55 view.Closed += new EventHandler(ViewClosed); 56 view.Caption = "Item" + newDocumentsCounter.ToString() + ".hl"; 57 newDocumentsCounter++; 58 MainFormManager.MainForm.ShowView(view); 59 } 40 60 } 41 61 } … … 52 72 53 73 if (openFileDialog.ShowDialog() == DialogResult.OK) { 54 foreach (string file in openFileDialog.FileNames) { 55 IItem item = (IItem)XmlParser.Deserialize(file); 56 MainFormManager.MainForm.ShowView(MainFormManager.CreateDefaultView(item)); 57 files.Add(item, new FileInfo(file)); 58 } 74 foreach (string filename in openFileDialog.FileNames) 75 LoadItemAsync(filename); 59 76 } 60 77 } … … 63 80 IItemView activeView = MainFormManager.MainForm.ActiveView as IItemView; 64 81 if ((activeView != null) && (CreatableAttribute.IsCreatable(activeView.Item.GetType()))) { 65 Save(activeView.Item); 66 } 67 } 68 private static void Save(IItem item) { 69 if (files[item].Filename != string.Empty) { 70 if (files[item].Compressed) 71 XmlGenerator.Serialize(item, saveFileDialog.FileName, 9); 82 Save(activeView); 83 } 84 } 85 private static void Save(IItemView view) { 86 if (!files.ContainsKey(view)) { 87 SaveAs(view); 88 } else { 89 if (files[view].Compressed) 90 SaveItemAsync(view, files[view].Filename, 9); 72 91 else 73 XmlGenerator.Serialize(item, saveFileDialog.FileName, 0); 74 } else { 75 SaveAs(item); 92 SaveItemAsync(view, files[view].Filename, 0); 76 93 } 77 94 } … … 80 97 IItemView activeView = MainFormManager.MainForm.ActiveView as IItemView; 81 98 if ((activeView != null) && (CreatableAttribute.IsCreatable(activeView.Item.GetType()))) { 82 SaveAs(activeView .Item);83 } 84 } 85 public static void SaveAs(IItem item) {99 SaveAs(activeView); 100 } 101 } 102 public static void SaveAs(IItemView view) { 86 103 if (saveFileDialog == null) { 87 104 saveFileDialog = new SaveFileDialog(); … … 92 109 } 93 110 94 saveFileDialog.FileName = files[item].Filename; 95 if (saveFileDialog.FileName == string.Empty) saveFileDialog.FileName = "Item"; 96 if (! files[item].Compressed) 111 if (!files.ContainsKey(view)) { 112 files.Add(view, new FileInfo()); 113 saveFileDialog.FileName = view.Caption; 114 } else { 115 saveFileDialog.FileName = files[view].Filename; 116 } 117 if (! files[view].Compressed) 97 118 saveFileDialog.FilterIndex = 1; 98 119 else … … 101 122 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 102 123 if (saveFileDialog.FilterIndex == 1) { 103 XmlGenerator.Serialize(item, saveFileDialog.FileName, 0);124 SaveItemAsync(view, saveFileDialog.FileName, 0); 104 125 } else { 105 XmlGenerator.Serialize(item, saveFileDialog.FileName, 9);126 SaveItemAsync(view, saveFileDialog.FileName, 9); 106 127 } 107 files[item].Filename = saveFileDialog.FileName;108 files[item].Compressed = saveFileDialog.FilterIndex != 1;109 128 } 110 129 } … … 117 136 118 137 foreach (IItemView view in views) { 119 Save(view.Item); 120 } 121 } 138 Save(view); 139 } 140 } 141 142 private static void ViewClosed(object sender, EventArgs e) { 143 IItemView view = (IItemView)sender; 144 view.Closed -= new EventHandler(ViewClosed); 145 files.Remove(view); 146 } 147 148 #region Asynchronous Save/Load Operations 149 private static void Invoke(Action a) { 150 Form form = MainFormManager.MainForm as Form; 151 if (form.InvokeRequired) 152 form.Invoke(a); 153 else 154 a.Invoke(); 155 } 156 157 private static void SaveItemAsync(IItemView view, string filename, int compression) { 158 ThreadPool.QueueUserWorkItem( 159 new WaitCallback( 160 delegate(object arg) { 161 try { 162 SetWaitingCursor(); 163 XmlGenerator.Serialize(view.Item, filename, compression); 164 Invoke(delegate() { 165 view.Caption = Path.GetFileName(filename); 166 files[view].Filename = filename; 167 files[view].Compressed = compression > 0; 168 }); 169 } 170 catch (Exception ex) { 171 Auxiliary.ShowErrorMessageBox(ex); 172 } finally { 173 ResetWaitingCursor(); 174 } 175 } 176 ) 177 ); 178 } 179 private static void LoadItemAsync(string filename) { 180 ThreadPool.QueueUserWorkItem( 181 new WaitCallback( 182 delegate(object arg) { 183 try { 184 SetWaitingCursor(); 185 IItem item = (IItem)XmlParser.Deserialize(filename); 186 Invoke(delegate() { 187 IItemView view = MainFormManager.CreateDefaultView(item) as IItemView; 188 if (view != null) { 189 view.Closed += new EventHandler(ViewClosed); 190 view.Caption = Path.GetFileName(filename); 191 files.Add(view, new FileInfo(filename)); 192 MainFormManager.MainForm.ShowView(view); 193 } 194 }); 195 } catch (Exception ex) { 196 Auxiliary.ShowErrorMessageBox(ex); 197 } finally { 198 ResetWaitingCursor(); 199 } 200 } 201 ) 202 ); 203 } 204 205 private static void SetWaitingCursor() { 206 Invoke(delegate() { 207 waitingCursors++; 208 ((Form)MainFormManager.MainForm).Cursor = Cursors.AppStarting; 209 }); 210 } 211 private static void ResetWaitingCursor() { 212 Invoke(delegate() { 213 waitingCursors--; 214 if (waitingCursors == 0) ((Form)MainFormManager.MainForm).Cursor = Cursors.Default; 215 }); 216 } 217 #endregion 122 218 } 123 219 } -
trunk/sources/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj
r2546 r2547 70 70 <DependentUpon>NewItemDialog.cs</DependentUpon> 71 71 </Compile> 72 <Compile Include="OptimizerMainForm.cs"> 73 <SubType>Form</SubType> 74 </Compile> 75 <Compile Include="OptimizerMainForm.Designer.cs"> 76 <DependentUpon>OptimizerMainForm.cs</DependentUpon> 77 </Compile> 72 78 <Compile Include="Properties\AssemblyInfo.cs" /> 73 79 <Compile Include="Properties\Resources.Designer.cs"> … … 119 125 <DependentUpon>NewItemDialog.cs</DependentUpon> 120 126 </EmbeddedResource> 127 <EmbeddedResource Include="OptimizerMainForm.resx"> 128 <DependentUpon>OptimizerMainForm.cs</DependentUpon> 129 </EmbeddedResource> 121 130 <EmbeddedResource Include="Properties\Resources.resx"> 122 131 <Generator>ResXFileCodeGenerator</Generator> -
trunk/sources/HeuristicLab.Optimizer/3.3/HeuristicLabOptimizerApplication.cs
r2546 r2547 33 33 internal class HeuristicLabOptimizerApplication : ApplicationBase { 34 34 public override void Run() { 35 DockingMainForm mainForm = new DockingMainForm(typeof(IOptimizerUserInterfaceItemProvider)); 36 mainForm.Title = "HeuristicLab Optimizer " + Assembly.GetExecutingAssembly().GetName().Version.ToString(); 37 mainForm.Icon = Resources.HeuristicLabIcon; 38 mainForm.Width = 800; 39 mainForm.Height = 600; 35 OptimizerMainForm mainForm = new OptimizerMainForm(typeof(IOptimizerUserInterfaceItemProvider)); 40 36 Application.Run(mainForm); 41 37 }
Note: See TracChangeset
for help on using the changeset viewer.