Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/23/15 10:01:26 (10 years ago)
Author:
pfleck
Message:

#2025 Enabled selecting nodes with arrow-up and -down while focusing the search box.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/NewItemDialog/HeuristicLab.Optimizer/3.3/NewItemDialog.cs

    r12217 r12234  
    130130      return parentNode;
    131131    }
    132 
    133132    private void CreateItemNodes(TreeNode node, IEnumerable<IGrouping<string, Type>> categories) {
    134133      foreach (var category in categories) {
     
    141140      }
    142141    }
    143 
    144142    private TreeNode CreateItemNode(Type creatable) {
    145143      string name = ItemAttribute.GetName(creatable);
     
    387385
    388386    private void searchTextBox_KeyDown(object sender, KeyEventArgs e) {
     387      if (typesTreeView.Nodes.Count == 0)
     388        return;
     389
    389390      if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down) {
    390 
    391         int? idx = typesTreeView.SelectedNode != null
    392           ? (int?)typesTreeView.SelectedNode.Index
    393           : null;
    394 
    395         TreeNode newNode = null;
    396         if (e.KeyCode == Keys.Down) {
    397           if (idx.HasValue && idx < typesTreeView.Nodes.Count - 1) {
    398             newNode = typesTreeView.Nodes[idx.Value + 1];
    399           } else if (typesTreeView.Nodes.Count > 0) {
    400             newNode = typesTreeView.Nodes[0];
    401           }
    402         } else if (e.KeyCode == Keys.Up && idx.HasValue && idx > 0) {
    403           newNode = typesTreeView.Nodes[idx.Value - 1];
    404         }
    405 
    406         if (newNode != null)
    407           typesTreeView.SelectedNode = newNode;
     391        var selectedNode = typesTreeView.SelectedNode;
     392
     393        if (selectedNode == null) { // nothing selected => select first or last
     394          if (e.KeyCode == Keys.Down) typesTreeView.SelectedNode = FirstVisibleNode;
     395          if (e.KeyCode == Keys.Up) typesTreeView.SelectedNode = LastVisibleNode;
     396        } else {
     397          if (e.KeyCode == Keys.Down)
     398            typesTreeView.SelectedNode = selectedNode.NextVisibleNode ?? FirstVisibleNode; // select next or cycle to first
     399          if (e.KeyCode == Keys.Up)
     400            typesTreeView.SelectedNode = selectedNode.PrevVisibleNode ?? LastVisibleNode; // select prev or cycle to last
     401        }
    408402        e.Handled = true;
     403      }
     404    }
     405
     406    private TreeNode FirstVisibleNode {
     407      get {
     408        return typesTreeView.Nodes[0];
     409      }
     410    }
     411    private TreeNode LastVisibleNode {
     412      get {
     413        var node = FirstVisibleNode;
     414        while (node.NextVisibleNode != null) node = node.NextVisibleNode;
     415        return node;
    409416      }
    410417    }
Note: See TracChangeset for help on using the changeset viewer.