Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/30/09 16:03:32 (15 years ago)
Author:
gkronber
Message:

Quick-fix for #822.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.OptimizationFrontend/3.2/MainForm.cs

    r1530 r2576  
    6363      Type[] creatables = discoveryService.GetTypes(typeof(IEditable));
    6464      string[] names = new string[creatables.Length];
    65       for(int i = 0; i < creatables.Length; i++)
     65      for (int i = 0; i < creatables.Length; i++)
    6666        names[i] = creatables[i].Name;
    6767      Array.Sort(names, creatables);
    68       foreach(Type type in creatables) {
    69         if(!type.IsAbstract) {
     68      foreach (Type type in creatables) {
     69        if (!type.IsAbstract) {
    7070          ToolStripMenuItem item = new ToolStripMenuItem();
    7171          item.Tag = type;
     
    8585    #region IControlManager Members
    8686    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        }
    97100      }
    98101    }
     
    111114      tileVerticallyToolStripMenuItem.Enabled = false;
    112115
    113       if(ActiveMdiChild != null) {
     116      if (ActiveMdiChild != null) {
    114117        closeToolStripMenuItem.Enabled = true;
    115118        closeAllToolStripMenuItem.Enabled = true;
     
    120123        tileVerticallyToolStripMenuItem.Enabled = true;
    121124        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) {
    124127            saveToolStripMenuItem.Enabled = true;
    125128            saveToolStripButton.Enabled = true;
     
    135138    #region Open and Save Methods
    136139    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++;
    139142        Cursor = Cursors.AppStarting;
    140143        Task task = new Task(openFileDialog.FileName, null, null);
     
    146149      try {
    147150        task.storable = PersistenceManager.Load(task.filename);
    148       } catch(FileNotFoundException ex) {
     151      }
     152      catch (FileNotFoundException ex) {
    149153        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.",
    150154          "Reader Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    151       } catch(TypeLoadException typeLoadEx) {
     155      }
     156      catch (TypeLoadException typeLoadEx) {
    152157        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.",
    153158          "Reader Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     
    158163    private delegate void TaskFinishedDelegate(Task task);
    159164    private void LoadFinished(Task task) {
    160       if(InvokeRequired)
     165      if (InvokeRequired)
    161166        Invoke(new TaskFinishedDelegate(LoadFinished), task);
    162167      else {
    163168        IEditor editor = null;
    164         if(task.storable != null) {
     169        if (task.storable != null) {
    165170          IEditable editable = task.storable as IEditable;
    166           if(editable != null)
     171          if (editable != null)
    167172            editor = editable.CreateEditor();
    168173        }
    169         if(editor == null)
     174        if (editor == null)
    170175          MessageBox.Show("Could not open item. The selected item doesn't provide an editor.", "Editor Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    171176        else {
     
    173178          PluginManager.ControlManager.ShowControl(editor);
    174179        }
    175         lock(locker) {
     180        lock (locker) {
    176181          runningTasks--;
    177           if(runningTasks == 0)
     182          if (runningTasks == 0)
    178183            Cursor = Cursors.Default;
    179184        }
     
    181186    }
    182187    private void Save(EditorForm form) {
    183       if(form.Editor.Filename == null)
     188      if (form.Editor.Filename == null)
    184189        SaveAs(form);
    185190      else {
    186         lock(locker) runningTasks++;
     191        lock (locker) runningTasks++;
    187192        Cursor = Cursors.AppStarting;
    188193        ((Control)form.Editor).Enabled = false;
     
    193198    }
    194199    private void SaveAs(EditorForm form) {
    195       if(saveFileDialog.ShowDialog(this) == DialogResult.OK) {
     200      if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {
    196201        form.Editor.Filename = saveFileDialog.FileName;
    197202        Save(form);
     
    204209    }
    205210    private void SaveFinished(Task task) {
    206       if(InvokeRequired)
     211      if (InvokeRequired)
    207212        Invoke(new TaskFinishedDelegate(SaveFinished), task);
    208213      else {
    209214        ((Control)task.editor).Enabled = true;
    210215        EnableDisableItems();
    211         lock(locker) {
     216        lock (locker) {
    212217          runningTasks--;
    213           if(runningTasks == 0)
     218          if (runningTasks == 0)
    214219            Cursor = Cursors.Default;
    215220        }
     
    227232      Type type = (Type)item.Tag;
    228233      IEditable editable = (IEditable)Activator.CreateInstance(type);
    229       if(editable == null) {
     234      if (editable == null) {
    230235        MessageBox.Show("The selected item is not editable.", "Editable Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    231236      } else {
    232237        IEditor editor = editable.CreateEditor();
    233         if(editor == null) {
     238        if (editor == null) {
    234239          MessageBox.Show("The selected item doesn't provide an editor.", "Editor Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    235240        } else {
     
    251256    }
    252257    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++) {
    254259        EditorForm form = MdiChildren[i] as EditorForm;
    255         if(((Control)form.Editor).Enabled) Save(form);
     260        if (((Control)form.Editor).Enabled) Save(form);
    256261      }
    257262    }
     
    261266    }
    262267    private void closeAllToolStripMenuItem_Click(object sender, EventArgs e) {
    263       while(MdiChildren.Length > 0)
     268      while (MdiChildren.Length > 0)
    264269        MdiChildren[0].Close();
    265270      EnableDisableItems();
     
    301306    }
    302307    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++) {
    304309        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);
    306311      }
    307312    }
Note: See TracChangeset for help on using the changeset viewer.