Changeset 2576 for trunk/sources/HeuristicLab.OptimizationFrontend
- Timestamp:
- 12/30/09 16:03:32 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.OptimizationFrontend/3.2/MainForm.cs
r1530 r2576 63 63 Type[] creatables = discoveryService.GetTypes(typeof(IEditable)); 64 64 string[] names = new string[creatables.Length]; 65 for (int i = 0; i < creatables.Length; i++)65 for (int i = 0; i < creatables.Length; i++) 66 66 names[i] = creatables[i].Name; 67 67 Array.Sort(names, creatables); 68 foreach (Type type in creatables) {69 if (!type.IsAbstract) {68 foreach (Type type in creatables) { 69 if (!type.IsAbstract) { 70 70 ToolStripMenuItem item = new ToolStripMenuItem(); 71 71 item.Tag = type; … … 85 85 #region IControlManager Members 86 86 public void ShowControl(IControl control) { 87 if(control is IEditor) { 88 EditorForm form = new EditorForm((IEditor)control); 89 form.MdiParent = this; 90 form.Show(); 91 } else if(control is IView) { 92 ViewForm form = new ViewForm((IView)control); 93 form.MdiParent = this; 94 form.Show(); 95 } else { 96 throw new InvalidOperationException("Control is neither a view nor an editor."); 87 if (InvokeRequired) Invoke((Action<IControl>)ShowControl, control); 88 else { 89 if (control is IEditor) { 90 EditorForm form = new EditorForm((IEditor)control); 91 form.MdiParent = this; 92 form.Show(); 93 } else if (control is IView) { 94 ViewForm form = new ViewForm((IView)control); 95 form.MdiParent = this; 96 form.Show(); 97 } else { 98 throw new InvalidOperationException("Control is neither a view nor an editor."); 99 } 97 100 } 98 101 } … … 111 114 tileVerticallyToolStripMenuItem.Enabled = false; 112 115 113 if (ActiveMdiChild != null) {116 if (ActiveMdiChild != null) { 114 117 closeToolStripMenuItem.Enabled = true; 115 118 closeAllToolStripMenuItem.Enabled = true; … … 120 123 tileVerticallyToolStripMenuItem.Enabled = true; 121 124 EditorForm form = ActiveMdiChild as EditorForm; 122 if (form != null) {123 if (((Control)form.Editor).Enabled) {125 if (form != null) { 126 if (((Control)form.Editor).Enabled) { 124 127 saveToolStripMenuItem.Enabled = true; 125 128 saveToolStripButton.Enabled = true; … … 135 138 #region Open and Save Methods 136 139 private void Open() { 137 if (openFileDialog.ShowDialog(this) == DialogResult.OK) {138 lock (locker) runningTasks++;140 if (openFileDialog.ShowDialog(this) == DialogResult.OK) { 141 lock (locker) runningTasks++; 139 142 Cursor = Cursors.AppStarting; 140 143 Task task = new Task(openFileDialog.FileName, null, null); … … 146 149 try { 147 150 task.storable = PersistenceManager.Load(task.filename); 148 } catch(FileNotFoundException ex) { 151 } 152 catch (FileNotFoundException ex) { 149 153 MessageBox.Show("Sorry couldn't open file \"" + task.filename + "\".\nThe file or plugin \"" + ex.FileName + "\" is not available.\nPlease make sure you have all necessary plugins installed.", 150 154 "Reader Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 151 } catch(TypeLoadException typeLoadEx) { 155 } 156 catch (TypeLoadException typeLoadEx) { 152 157 MessageBox.Show("Sorry couldn't open file \"" + task.filename + "\".\nThe type \"" + typeLoadEx.TypeName + "\" is not available.\nPlease make sure that you have the correct version the plugin installed.", 153 158 "Reader Error", MessageBoxButtons.OK, MessageBoxIcon.Error); … … 158 163 private delegate void TaskFinishedDelegate(Task task); 159 164 private void LoadFinished(Task task) { 160 if (InvokeRequired)165 if (InvokeRequired) 161 166 Invoke(new TaskFinishedDelegate(LoadFinished), task); 162 167 else { 163 168 IEditor editor = null; 164 if (task.storable != null) {169 if (task.storable != null) { 165 170 IEditable editable = task.storable as IEditable; 166 if (editable != null)171 if (editable != null) 167 172 editor = editable.CreateEditor(); 168 173 } 169 if (editor == null)174 if (editor == null) 170 175 MessageBox.Show("Could not open item. The selected item doesn't provide an editor.", "Editor Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 171 176 else { … … 173 178 PluginManager.ControlManager.ShowControl(editor); 174 179 } 175 lock (locker) {180 lock (locker) { 176 181 runningTasks--; 177 if (runningTasks == 0)182 if (runningTasks == 0) 178 183 Cursor = Cursors.Default; 179 184 } … … 181 186 } 182 187 private void Save(EditorForm form) { 183 if (form.Editor.Filename == null)188 if (form.Editor.Filename == null) 184 189 SaveAs(form); 185 190 else { 186 lock (locker) runningTasks++;191 lock (locker) runningTasks++; 187 192 Cursor = Cursors.AppStarting; 188 193 ((Control)form.Editor).Enabled = false; … … 193 198 } 194 199 private void SaveAs(EditorForm form) { 195 if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {200 if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { 196 201 form.Editor.Filename = saveFileDialog.FileName; 197 202 Save(form); … … 204 209 } 205 210 private void SaveFinished(Task task) { 206 if (InvokeRequired)211 if (InvokeRequired) 207 212 Invoke(new TaskFinishedDelegate(SaveFinished), task); 208 213 else { 209 214 ((Control)task.editor).Enabled = true; 210 215 EnableDisableItems(); 211 lock (locker) {216 lock (locker) { 212 217 runningTasks--; 213 if (runningTasks == 0)218 if (runningTasks == 0) 214 219 Cursor = Cursors.Default; 215 220 } … … 227 232 Type type = (Type)item.Tag; 228 233 IEditable editable = (IEditable)Activator.CreateInstance(type); 229 if (editable == null) {234 if (editable == null) { 230 235 MessageBox.Show("The selected item is not editable.", "Editable Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 231 236 } else { 232 237 IEditor editor = editable.CreateEditor(); 233 if (editor == null) {238 if (editor == null) { 234 239 MessageBox.Show("The selected item doesn't provide an editor.", "Editor Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 235 240 } else { … … 251 256 } 252 257 private void saveAllToolStripMenuItem_Click(object sender, EventArgs e) { 253 for (int i = 0; i < MdiChildren.Length; i++) {258 for (int i = 0; i < MdiChildren.Length; i++) { 254 259 EditorForm form = MdiChildren[i] as EditorForm; 255 if (((Control)form.Editor).Enabled) Save(form);260 if (((Control)form.Editor).Enabled) Save(form); 256 261 } 257 262 } … … 261 266 } 262 267 private void closeAllToolStripMenuItem_Click(object sender, EventArgs e) { 263 while (MdiChildren.Length > 0)268 while (MdiChildren.Length > 0) 264 269 MdiChildren[0].Close(); 265 270 EnableDisableItems(); … … 301 306 } 302 307 private void saveAllToolStripButton_Click(object sender, EventArgs e) { 303 for (int i = 0; i < MdiChildren.Length; i++) {308 for (int i = 0; i < MdiChildren.Length; i++) { 304 309 EditorForm form = MdiChildren[i] as EditorForm; 305 if (form != null && ((Control)form.Editor).Enabled) Save(form);310 if (form != null && ((Control)form.Editor).Enabled) Save(form); 306 311 } 307 312 }
Note: See TracChangeset
for help on using the changeset viewer.