Changeset 2952
- Timestamp:
- 03/07/10 03:10:38 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Core.Views/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core.Views/3.3/TypeSelector.Designer.cs
r2924 r2952 50 50 this.typesGroupBox = new System.Windows.Forms.GroupBox(); 51 51 this.splitContainer = new System.Windows.Forms.SplitContainer(); 52 this.searchLabel = new System.Windows.Forms.Label(); 53 this.searchTextBox = new System.Windows.Forms.TextBox(); 52 54 this.descriptionTextBox = new System.Windows.Forms.TextBox(); 55 this.toolTip = new System.Windows.Forms.ToolTip(this.components); 53 56 this.typesGroupBox.SuspendLayout(); 54 57 this.splitContainer.Panel1.SuspendLayout(); … … 65 68 this.typesTreeView.ImageIndex = 0; 66 69 this.typesTreeView.ImageList = this.imageList; 67 this.typesTreeView.Location = new System.Drawing.Point(3, 3);70 this.typesTreeView.Location = new System.Drawing.Point(3, 29); 68 71 this.typesTreeView.Name = "typesTreeView"; 69 72 this.typesTreeView.SelectedImageIndex = 0; 70 73 this.typesTreeView.ShowNodeToolTips = true; 71 this.typesTreeView.Size = new System.Drawing.Size(291, 192); 72 this.typesTreeView.TabIndex = 0; 74 this.typesTreeView.Size = new System.Drawing.Size(291, 166); 75 this.typesTreeView.TabIndex = 2; 76 this.typesTreeView.VisibleChanged += new System.EventHandler(this.typesTreeView_VisibleChanged); 73 77 this.typesTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.typesTreeView_AfterSelect); 74 78 this.typesTreeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.typesTreeView_ItemDrag); … … 100 104 // splitContainer.Panel1 101 105 // 106 this.splitContainer.Panel1.Controls.Add(this.searchLabel); 107 this.splitContainer.Panel1.Controls.Add(this.searchTextBox); 102 108 this.splitContainer.Panel1.Controls.Add(this.typesTreeView); 103 109 // … … 108 114 this.splitContainer.SplitterDistance = 198; 109 115 this.splitContainer.TabIndex = 2; 116 // 117 // searchLabel 118 // 119 this.searchLabel.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Zoom; 120 this.searchLabel.Location = new System.Drawing.Point(3, 3); 121 this.searchLabel.Name = "searchLabel"; 122 this.searchLabel.Size = new System.Drawing.Size(20, 20); 123 this.searchLabel.TabIndex = 0; 124 this.toolTip.SetToolTip(this.searchLabel, "Enter string to search for types"); 125 // 126 // searchTextBox 127 // 128 this.searchTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 129 | System.Windows.Forms.AnchorStyles.Right))); 130 this.searchTextBox.Location = new System.Drawing.Point(29, 3); 131 this.searchTextBox.Name = "searchTextBox"; 132 this.searchTextBox.Size = new System.Drawing.Size(265, 20); 133 this.searchTextBox.TabIndex = 1; 134 this.toolTip.SetToolTip(this.searchTextBox, "Enter string to search for types"); 135 this.searchTextBox.TextChanged += new System.EventHandler(this.searchTextBox_TextChanged); 110 136 // 111 137 // descriptionTextBox … … 132 158 this.typesGroupBox.ResumeLayout(false); 133 159 this.splitContainer.Panel1.ResumeLayout(false); 160 this.splitContainer.Panel1.PerformLayout(); 134 161 this.splitContainer.Panel2.ResumeLayout(false); 135 162 this.splitContainer.Panel2.PerformLayout(); … … 146 173 protected System.Windows.Forms.TreeView typesTreeView; 147 174 protected System.Windows.Forms.SplitContainer splitContainer; 175 protected System.Windows.Forms.Label searchLabel; 176 protected System.Windows.Forms.TextBox searchTextBox; 177 protected System.Windows.Forms.ToolTip toolTip; 148 178 149 179 } -
trunk/sources/HeuristicLab.Core.Views/3.3/TypeSelector.cs
r2818 r2952 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.PluginInfrastructure; 28 using System.Collections.Generic; 28 29 29 30 namespace HeuristicLab.Core.Views { 30 31 public partial class TypeSelector : UserControl { 32 protected List<TreeNode> treeNodes; 33 protected string currentSearchString; 34 31 35 protected Type baseType; 32 36 public Type BaseType { … … 66 70 public TypeSelector() { 67 71 InitializeComponent(); 72 treeNodes = new List<TreeNode>(); 73 currentSearchString = string.Empty; 68 74 selectedType = null; 69 75 } … … 78 84 this.showGenericTypes = showGenericTypes; 79 85 86 TreeNode selectedNode = typesTreeView.SelectedNode; 80 87 typesTreeView.Nodes.Clear(); 88 treeNodes.Clear(); 81 89 imageList.Images.Clear(); 82 90 imageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.Class); // default icon … … 86 94 imageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.Template); // generic types 87 95 88 TreeNode selectedNode = null;89 96 var plugins = from p in ApplicationManager.Manager.Plugins 90 97 orderby p.Name, p.Version ascending … … 126 133 typeNode.SelectedImageIndex = typeNode.ImageIndex; 127 134 typeNode.Tag = type; 128 if (type == SelectedType) selectedNode = typeNode;129 135 pluginNode.Nodes.Add(typeNode); 130 136 } 131 137 } 132 138 if (pluginNode.Nodes.Count > 0) 133 typesTreeView.Nodes.Add(pluginNode); 134 } 139 treeNodes.Add(pluginNode); 140 } 141 foreach (TreeNode node in treeNodes) 142 typesTreeView.Nodes.Add((TreeNode)node.Clone()); 143 RestoreSelectedNode(selectedNode); 144 Filter(searchTextBox.Text); 145 } 146 } 147 148 public virtual void Filter(string searchString) { 149 if (InvokeRequired) 150 Invoke(new Action<string>(Filter), searchString); 151 else { 152 searchString = searchString.ToLower(); 153 154 typesTreeView.BeginUpdate(); 155 if (!searchString.Contains(currentSearchString)) { 156 // expand search -> restore all tree nodes 157 TreeNode selectedNode = typesTreeView.SelectedNode; 158 typesTreeView.Nodes.Clear(); 159 foreach (TreeNode node in treeNodes) 160 typesTreeView.Nodes.Add((TreeNode)node.Clone()); 161 RestoreSelectedNode(selectedNode); 162 } 163 164 // remove nodes 165 int i = 0; 166 while (i < typesTreeView.Nodes.Count) { 167 int j = 0; 168 while (j < typesTreeView.Nodes[i].Nodes.Count) { 169 if (!typesTreeView.Nodes[i].Nodes[j].Text.ToLower().Contains(searchString)) 170 typesTreeView.Nodes[i].Nodes[j].Remove(); 171 else 172 j++; 173 } 174 if (typesTreeView.Nodes[i].Nodes.Count == 0) 175 typesTreeView.Nodes[i].Remove(); 176 else 177 i++; 178 } 179 currentSearchString = searchString; 180 181 // if there is just one type node left, select by default 182 if (typesTreeView.Nodes.Count == 1) { 183 if (typesTreeView.Nodes[0].Nodes.Count == 1) { 184 typesTreeView.SelectedNode = typesTreeView.Nodes[0].Nodes[0]; 185 } 186 } 187 135 188 if (typesTreeView.Nodes.Count == 0) { 136 typesTreeView.Nodes.Add("No types of base type \"" + BaseType.GetPrettyName() + "\" found");189 SelectedType = null; 137 190 typesTreeView.Enabled = false; 138 }139 if (selectedNode != null) {140 typesTreeView.SelectedNode = selectedNode;141 selectedNode.EnsureVisible();142 191 } else { 143 SelectedType = null; 144 } 192 SetTreeNodeVisibility(); 193 typesTreeView.Enabled = true; 194 } 195 UpdateDescription(); 196 typesTreeView.EndUpdate(); 145 197 } 146 198 } … … 178 230 descriptionTextBox.Text = description; 179 231 } 180 } 232 } else if (typesTreeView.Nodes.Count == 0) { 233 descriptionTextBox.Text = "No types found"; 234 } 235 } 236 237 protected virtual void searchTextBox_TextChanged(object sender, System.EventArgs e) { 238 Filter(searchTextBox.Text); 181 239 } 182 240 183 241 protected virtual void typesTreeView_AfterSelect(object sender, TreeViewEventArgs e) { 184 if (typesTreeView.SelectedNode != null) { 185 SelectedType = typesTreeView.SelectedNode.Tag as Type; 186 } 242 if (typesTreeView.SelectedNode == null) SelectedType = null; 243 else SelectedType = typesTreeView.SelectedNode.Tag as Type; 187 244 UpdateDescription(); 188 245 } … … 202 259 } 203 260 } 261 262 protected virtual void typesTreeView_VisibleChanged(object sender, EventArgs e) { 263 if (Visible) SetTreeNodeVisibility(); 264 } 265 266 #region Helpers 267 private void RestoreSelectedNode(TreeNode selectedNode) { 268 if (selectedNode != null) { 269 foreach (TreeNode node in typesTreeView.Nodes) { 270 if (node.Text.Equals(selectedNode.Text)) typesTreeView.SelectedNode = node; 271 foreach (TreeNode child in node.Nodes) { 272 if ((child.Text.Equals(selectedNode.Text)) && (child.Tag == selectedNode.Tag)) 273 typesTreeView.SelectedNode = child; 274 } 275 } 276 if (typesTreeView.SelectedNode == null) SelectedType = null; 277 } 278 } 279 private void SetTreeNodeVisibility() { 280 TreeNode selectedNode = typesTreeView.SelectedNode; 281 if (string.IsNullOrEmpty(currentSearchString)) { 282 typesTreeView.CollapseAll(); 283 if (selectedNode != null) typesTreeView.SelectedNode = selectedNode; 284 } else { 285 typesTreeView.ExpandAll(); 286 } 287 if (selectedNode != null) selectedNode.EnsureVisible(); 288 } 289 #endregion 204 290 } 205 291 }
Note: See TracChangeset
for help on using the changeset viewer.