Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6550


Ignore:
Timestamp:
07/08/11 10:03:44 (13 years ago)
Author:
mkommend
Message:

#1555: Allowed editing of node on keypress (F2) and minor code clean up.

Location:
trunk/sources/HeuristicLab.Optimization.Views/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentTreeView.Designer.cs

    r6526 r6550  
    172172      this.treeView.BeforeLabelEdit += new System.Windows.Forms.NodeLabelEditEventHandler(treeView_BeforeLabelEdit);
    173173      this.treeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.optimizerTreeView_ItemDrag);
    174       this.treeView.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.optimizerTreeview_NodeMouseClick);
    175       this.treeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.optimizerTreeView_NodeMouseDoubleClick);
     174      this.treeView.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeview_NodeMouseClick);
     175      this.treeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView_NodeMouseDoubleClick);
    176176      this.treeView.DragDrop += new System.Windows.Forms.DragEventHandler(this.optimizerTreeView_DragDrop);
    177177      this.treeView.DragEnter += new System.Windows.Forms.DragEventHandler(this.optimizerTreeView_DragEnter);
    178178      this.treeView.DragOver += new System.Windows.Forms.DragEventHandler(this.optimizerTreeView_DragOver);
    179       this.treeView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.optimizerTreeView_KeyDown);
    180       this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.optimizerTreeView_MouseDown);
    181       this.treeView.RightClick += new System.EventHandler(optimizerTreeView_RightClick);
     179      this.treeView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.treeView_KeyDown);
     180      this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown);
     181      this.treeView.RightClick += new System.EventHandler(treeView_RightClick);
    182182      //
    183183      // imageList
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentTreeView.cs

    r6549 r6550  
    583583
    584584    #region control events
    585     private void optimizerTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
     585    private void treeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
    586586      if (rightClickOccured) return;
    587587      if (e.X < e.Node.Bounds.Left || e.X > e.Node.Bounds.Right) return;
     
    590590      MainFormManager.MainForm.ShowContent(optimizer);
    591591    }
    592     private void optimizerTreeview_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {
     592    private void treeview_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {
    593593      if (e.X < e.Node.Bounds.Left || e.X > e.Node.Bounds.Right) return;
    594594      treeView.SelectedNode = e.Node;
     
    596596      SetEnabledStateOfControls();
    597597    }
    598     private void optimizerTreeView_MouseDown(object sender, MouseEventArgs e) {
     598    private void treeView_MouseDown(object sender, MouseEventArgs e) {
    599599      // enables deselection of treeNodes
    600600      if (e.Button != MouseButtons.Right) rightClickOccured = false;
     
    610610
    611611
    612     private void optimizerTreeView_KeyDown(object sender, KeyEventArgs e) {
    613       if (ReadOnly) return;
    614       if (e.KeyCode != Keys.Delete) return;
     612    private void treeView_KeyDown(object sender, KeyEventArgs e) {
     613      if (Locked || ReadOnly) return;
    615614      if (treeView.SelectedNode == null) return;
    616       if (!(treeView.SelectedNode.Tag is IOptimizer)) return;
     615      if (!(treeView.SelectedNode.Tag is INamedItem)) return;
    617616
    618617      var treeNode = treeView.SelectedNode;
    619       var optimizer = (IOptimizer)treeNode.Tag;
    620 
    621       if (treeNode.Parent == null)
    622         Content.Optimizers.Remove(optimizer);
    623       else {
    624         var batchRun = treeNode.Parent.Tag as BatchRun;
    625         var experiment = treeNode.Parent.Tag as Experiment;
    626         if (batchRun != null) batchRun.Optimizer = null;
    627         else if (experiment != null) experiment.Optimizers.Remove(optimizer);
    628         else throw new NotSupportedException("Handling for specific type not implemented" + treeView.SelectedNode.Tag.GetType());
    629       }
    630       SetEnabledStateOfControls();
    631       UpdateDetailsViewHost();
    632       RebuildImageList();
     618      var namedItem = (NamedItem)treeNode.Tag;
     619      var optimizer = namedItem as IOptimizer;
     620
     621      if (e.KeyCode == Keys.F2 && !treeNode.IsEditing) {
     622        treeNode.BeginEdit();
     623        return;
     624      }
     625
     626      if (e.KeyCode == Keys.Delete && optimizer != null) {
     627        if (treeNode.Parent == null)
     628          Content.Optimizers.Remove(optimizer);
     629        else {
     630          var batchRun = treeNode.Parent.Tag as BatchRun;
     631          var experiment = treeNode.Parent.Tag as Experiment;
     632          if (batchRun != null) batchRun.Optimizer = null;
     633          else if (experiment != null) experiment.Optimizers.Remove(optimizer);
     634          else throw new NotSupportedException("Handling for specific type not implemented" + treeView.SelectedNode.Tag.GetType());
     635        }
     636        SetEnabledStateOfControls();
     637        UpdateDetailsViewHost();
     638        RebuildImageList();
     639      }
    633640    }
    634641
    635642    private bool rightClickOccured = true;
    636643    private TreeNode toolStripMenuNode = null;
    637     private void optimizerTreeView_RightClick(object sender, EventArgs e) {
     644    private void treeView_RightClick(object sender, EventArgs e) {
    638645      rightClickOccured = true;
    639646      Point coordinates = treeView.PointToClient(Cursor.Position);
     
    656663    }
    657664
    658     private void ExpandToolStripMenuItem_Click(object sender, EventArgs e) {
    659       if (toolStripMenuNode != null) toolStripMenuNode.ExpandAll();
    660     }
    661     private void CollapseToolStripMenuItem_Click(object sender, EventArgs e) {
    662       if (toolStripMenuNode != null) toolStripMenuNode.Collapse();
    663     }
    664     private void EditNodeLabelToolStripMenuItem_Click(object sender, EventArgs e) {
    665       if (toolStripMenuNode != null) {
    666         if (!toolStripMenuNode.IsEditing) toolStripMenuNode.BeginEdit();
    667       }
    668     }
    669 
    670 
    671665    private void treeView_BeforeLabelEdit(object sender, NodeLabelEditEventArgs e) {
    672666      if (Locked) e.CancelEdit = true;
    673667      if (ReadOnly) e.CancelEdit = true;
    674668      if (e.Node.Tag == null) e.CancelEdit = true;
    675       if (!(e.Node.Tag is NamedItem)) e.CancelEdit = true;
     669      var namedItem = e.Node.Tag as INamedItem;
     670      if (namedItem == null) e.CancelEdit = true;
     671      else if (!namedItem.CanChangeName) e.CancelEdit = true;
    676672    }
    677673    private void treeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) {
    678674      if (e.Label == null) return;
    679 
    680675      e.Node.EndEdit(false);
    681676      var namedItem = (INamedItem)e.Node.Tag;
    682677      namedItem.Name = e.Label;
     678    }
     679
     680    private void ExpandToolStripMenuItem_Click(object sender, EventArgs e) {
     681      if (toolStripMenuNode != null) toolStripMenuNode.ExpandAll();
     682    }
     683    private void CollapseToolStripMenuItem_Click(object sender, EventArgs e) {
     684      if (toolStripMenuNode != null) toolStripMenuNode.Collapse();
     685    }
     686    private void EditNodeLabelToolStripMenuItem_Click(object sender, EventArgs e) {
     687      if (toolStripMenuNode != null) {
     688        if (!toolStripMenuNode.IsEditing) toolStripMenuNode.BeginEdit();
     689      }
    683690    }
    684691
Note: See TracChangeset for help on using the changeset viewer.