- Timestamp:
- 10/19/08 00:43:25 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/sources/HeuristicLab.OptimizationFrontend/MainForm.cs
r662 r690 63 63 Type[] creatables = discoveryService.GetTypes(typeof(IEditable)); 64 64 string[] names = new string[creatables.Length]; 65 for 65 for(int i = 0; i < creatables.Length; i++) 66 66 names[i] = creatables[i].Name; 67 67 Array.Sort(names, creatables); 68 foreach 69 if 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 87 if(control is IEditor) { 88 88 EditorForm form = new EditorForm((IEditor)control); 89 89 form.MdiParent = this; 90 90 form.Show(); 91 } else if 91 } else if(control is IView) { 92 92 ViewForm form = new ViewForm((IView)control); 93 93 form.MdiParent = this; … … 111 111 tileVerticallyToolStripMenuItem.Enabled = false; 112 112 113 if 113 if(ActiveMdiChild != null) { 114 114 closeToolStripMenuItem.Enabled = true; 115 115 closeAllToolStripMenuItem.Enabled = true; … … 120 120 tileVerticallyToolStripMenuItem.Enabled = true; 121 121 EditorForm form = ActiveMdiChild as EditorForm; 122 if (form != null){123 if 122 if(form != null) { 123 if(((Control)form.Editor).Enabled) { 124 124 saveToolStripMenuItem.Enabled = true; 125 125 saveToolStripButton.Enabled = true; … … 135 135 #region Open and Save Methods 136 136 private void Open() { 137 if 138 lock 137 if(openFileDialog.ShowDialog(this) == DialogResult.OK) { 138 lock(locker) runningTasks++; 139 139 Cursor = Cursors.AppStarting; 140 140 Task task = new Task(openFileDialog.FileName, null, null); … … 149 149 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 150 "Reader Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 151 } 151 } catch(TypeLoadException typeLoadEx) { 152 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 "Reader Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 154 } 155 152 156 LoadFinished(task); 153 157 } 154 158 private delegate void TaskFinishedDelegate(Task task); 155 159 private void LoadFinished(Task task) { 156 if 160 if(InvokeRequired) 157 161 Invoke(new TaskFinishedDelegate(LoadFinished), task); 158 162 else { 159 163 IEditor editor = null; 160 if 164 if(task.storable != null) { 161 165 IEditable editable = task.storable as IEditable; 162 if 166 if(editable != null) 163 167 editor = editable.CreateEditor(); 164 168 } 165 if 169 if(editor == null) 166 170 MessageBox.Show("Could not open item. The selected item doesn't provide an editor.", "Editor Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 167 171 else { … … 169 173 PluginManager.ControlManager.ShowControl(editor); 170 174 } 171 lock 175 lock(locker) { 172 176 runningTasks--; 173 if 177 if(runningTasks == 0) 174 178 Cursor = Cursors.Default; 175 179 } … … 177 181 } 178 182 private void Save(EditorForm form) { 179 if 183 if(form.Editor.Filename == null) 180 184 SaveAs(form); 181 185 else { 182 lock 186 lock(locker) runningTasks++; 183 187 Cursor = Cursors.AppStarting; 184 188 ((Control)form.Editor).Enabled = false; … … 189 193 } 190 194 private void SaveAs(EditorForm form) { 191 if 195 if(saveFileDialog.ShowDialog(this) == DialogResult.OK) { 192 196 form.Editor.Filename = saveFileDialog.FileName; 193 197 Save(form); … … 200 204 } 201 205 private void SaveFinished(Task task) { 202 if 206 if(InvokeRequired) 203 207 Invoke(new TaskFinishedDelegate(SaveFinished), task); 204 208 else { 205 209 ((Control)task.editor).Enabled = true; 206 210 EnableDisableItems(); 207 lock 211 lock(locker) { 208 212 runningTasks--; 209 if 213 if(runningTasks == 0) 210 214 Cursor = Cursors.Default; 211 215 } … … 223 227 Type type = (Type)item.Tag; 224 228 IEditable editable = (IEditable)Activator.CreateInstance(type); 225 if 229 if(editable == null) { 226 230 MessageBox.Show("The selected item is not editable.", "Editable Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 227 231 } else { 228 232 IEditor editor = editable.CreateEditor(); 229 if 233 if(editor == null) { 230 234 MessageBox.Show("The selected item doesn't provide an editor.", "Editor Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 231 235 } else { … … 247 251 } 248 252 private void saveAllToolStripMenuItem_Click(object sender, EventArgs e) { 249 for 253 for(int i = 0; i < MdiChildren.Length; i++) { 250 254 EditorForm form = MdiChildren[i] as EditorForm; 251 if 255 if(((Control)form.Editor).Enabled) Save(form); 252 256 } 253 257 } … … 257 261 } 258 262 private void closeAllToolStripMenuItem_Click(object sender, EventArgs e) { 259 while 263 while(MdiChildren.Length > 0) 260 264 MdiChildren[0].Close(); 261 265 EnableDisableItems(); … … 297 301 } 298 302 private void saveAllToolStripButton_Click(object sender, EventArgs e) { 299 for 303 for(int i = 0; i < MdiChildren.Length; i++) { 300 304 EditorForm form = MdiChildren[i] as EditorForm; 301 if (((Control)form.Editor).Enabled) Save(form);305 if(form != null && ((Control)form.Editor).Enabled) Save(form); 302 306 } 303 307 }
Note: See TracChangeset
for help on using the changeset viewer.