Changeset 12184 for branches/NewItemDialog/HeuristicLab.Optimizer
- Timestamp:
- 03/10/15 16:20:03 (10 years ago)
- Location:
- branches/NewItemDialog/HeuristicLab.Optimizer/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/NewItemDialog/HeuristicLab.Optimizer/3.3/NewItemDialog.Designer.cs
r12012 r12184 46 46 private void InitializeComponent() { 47 47 this.components = new System.ComponentModel.Container(); 48 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NewItemDialog)); 48 49 this.okButton = new System.Windows.Forms.Button(); 49 50 this.cancelButton = new System.Windows.Forms.Button(); 50 this.itemsListView = new System.Windows.Forms.ListView();51 this.nameColumnHeader = new System.Windows.Forms.ColumnHeader();52 this.descriptioncolumnHeader = new System.Windows.Forms.ColumnHeader();53 51 this.toolTip = new System.Windows.Forms.ToolTip(this.components); 54 this.versionColumnHeader = new System.Windows.Forms.ColumnHeader(); 52 this.searchLabel = new System.Windows.Forms.Label(); 53 this.splitContainer = new System.Windows.Forms.SplitContainer(); 54 this.searchTextBox = new System.Windows.Forms.TextBox(); 55 this.typesTreeView = new System.Windows.Forms.TreeView(); 56 this.imageList = new System.Windows.Forms.ImageList(this.components); 57 this.descriptionTextBox = new System.Windows.Forms.TextBox(); 58 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 59 this.splitContainer.Panel1.SuspendLayout(); 60 this.splitContainer.Panel2.SuspendLayout(); 61 this.splitContainer.SuspendLayout(); 55 62 this.SuspendLayout(); 56 63 // … … 79 86 this.cancelButton.UseVisualStyleBackColor = true; 80 87 // 81 // itemsListView 82 // 83 this.itemsListView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 84 | System.Windows.Forms.AnchorStyles.Left) 85 | System.Windows.Forms.AnchorStyles.Right))); 86 this.itemsListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 87 this.nameColumnHeader, 88 this.versionColumnHeader, 89 this.descriptioncolumnHeader}); 90 this.itemsListView.FullRowSelect = true; 91 this.itemsListView.HideSelection = false; 92 this.itemsListView.Location = new System.Drawing.Point(12, 12); 93 this.itemsListView.MultiSelect = false; 94 this.itemsListView.Name = "itemsListView"; 95 this.itemsListView.Size = new System.Drawing.Size(600, 391); 96 this.itemsListView.TabIndex = 1; 97 this.itemsListView.UseCompatibleStateImageBehavior = false; 98 this.itemsListView.View = System.Windows.Forms.View.Details; 99 this.itemsListView.SelectedIndexChanged += new System.EventHandler(this.itemTypesListView_SelectedIndexChanged); 100 this.itemsListView.DoubleClick += new System.EventHandler(this.itemTypesListView_DoubleClick); 101 // 102 // nameColumnHeader 103 // 104 this.nameColumnHeader.DisplayIndex = 0; 105 this.nameColumnHeader.Text = "Name"; 106 this.nameColumnHeader.Width = 91; 107 // 108 // descriptioncolumnHeader 109 // 110 this.descriptioncolumnHeader.DisplayIndex = 2; 111 this.descriptioncolumnHeader.Text = "Description"; 112 this.descriptioncolumnHeader.Width = 190; 113 // 114 // versionColumnHeader 115 // 116 this.versionColumnHeader.DisplayIndex = 1; 117 this.versionColumnHeader.Text = "Version"; 88 // searchLabel 89 // 90 this.searchLabel.Image = ((System.Drawing.Image)(resources.GetObject("searchLabel.Image"))); 91 this.searchLabel.Location = new System.Drawing.Point(3, 3); 92 this.searchLabel.Name = "searchLabel"; 93 this.searchLabel.Size = new System.Drawing.Size(20, 20); 94 this.searchLabel.TabIndex = 1; 95 this.toolTip.SetToolTip(this.searchLabel, "Enter string to search for items"); 96 // 97 // splitContainer 98 // 99 this.splitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 100 | System.Windows.Forms.AnchorStyles.Left) 101 | System.Windows.Forms.AnchorStyles.Right))); 102 this.splitContainer.Location = new System.Drawing.Point(12, 12); 103 this.splitContainer.Name = "splitContainer"; 104 this.splitContainer.Orientation = System.Windows.Forms.Orientation.Horizontal; 105 // 106 // splitContainer.Panel1 107 // 108 this.splitContainer.Panel1.Controls.Add(this.searchLabel); 109 this.splitContainer.Panel1.Controls.Add(this.searchTextBox); 110 this.splitContainer.Panel1.Controls.Add(this.typesTreeView); 111 // 112 // splitContainer.Panel2 113 // 114 this.splitContainer.Panel2.Controls.Add(this.descriptionTextBox); 115 this.splitContainer.Size = new System.Drawing.Size(600, 391); 116 this.splitContainer.SplitterDistance = 292; 117 this.splitContainer.TabIndex = 4; 118 // 119 // searchTextBox 120 // 121 this.searchTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 122 | System.Windows.Forms.AnchorStyles.Right))); 123 this.searchTextBox.Location = new System.Drawing.Point(29, 3); 124 this.searchTextBox.Name = "searchTextBox"; 125 this.searchTextBox.Size = new System.Drawing.Size(568, 20); 126 this.searchTextBox.TabIndex = 1; 127 this.searchTextBox.TextChanged += new System.EventHandler(this.searchTextBox_TextChanged); 128 // 129 // typesTreeView 130 // 131 this.typesTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 132 | System.Windows.Forms.AnchorStyles.Left) 133 | System.Windows.Forms.AnchorStyles.Right))); 134 this.typesTreeView.HideSelection = false; 135 this.typesTreeView.ImageIndex = 0; 136 this.typesTreeView.ImageList = this.imageList; 137 this.typesTreeView.Location = new System.Drawing.Point(3, 29); 138 this.typesTreeView.Name = "typesTreeView"; 139 this.typesTreeView.SelectedImageIndex = 0; 140 this.typesTreeView.ShowNodeToolTips = true; 141 this.typesTreeView.Size = new System.Drawing.Size(594, 260); 142 this.typesTreeView.TabIndex = 2; 143 this.typesTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.itemsTreeView_AfterSelect); 144 this.typesTreeView.VisibleChanged += new System.EventHandler(this.itemsTreeView_VisibleChanged); 145 this.typesTreeView.DoubleClick += new System.EventHandler(this.itemTreeView_DoubleClick); 146 // 147 // imageList 148 // 149 this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit; 150 this.imageList.ImageSize = new System.Drawing.Size(16, 16); 151 this.imageList.TransparentColor = System.Drawing.Color.Transparent; 152 // 153 // descriptionTextBox 154 // 155 this.descriptionTextBox.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 156 this.descriptionTextBox.Location = new System.Drawing.Point(3, 3); 157 this.descriptionTextBox.Multiline = true; 158 this.descriptionTextBox.Name = "descriptionTextBox"; 159 this.descriptionTextBox.ReadOnly = true; 160 this.descriptionTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; 161 this.descriptionTextBox.Size = new System.Drawing.Size(594, 89); 162 this.descriptionTextBox.TabIndex = 0; 118 163 // 119 164 // NewItemDialog 120 165 // 121 166 this.AcceptButton = this.okButton; 122 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);123 167 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 124 168 this.CancelButton = this.cancelButton; 125 169 this.ClientSize = new System.Drawing.Size(624, 444); 126 this.Controls.Add(this. itemsListView);170 this.Controls.Add(this.splitContainer); 127 171 this.Controls.Add(this.cancelButton); 128 172 this.Controls.Add(this.okButton); … … 137 181 this.Load += new System.EventHandler(this.NewItemDialog_Load); 138 182 this.Shown += new System.EventHandler(this.NewItemDialog_Shown); 183 this.splitContainer.Panel1.ResumeLayout(false); 184 this.splitContainer.Panel1.PerformLayout(); 185 this.splitContainer.Panel2.ResumeLayout(false); 186 this.splitContainer.Panel2.PerformLayout(); 187 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); 188 this.splitContainer.ResumeLayout(false); 139 189 this.ResumeLayout(false); 140 190 … … 145 195 private System.Windows.Forms.Button okButton; 146 196 private System.Windows.Forms.Button cancelButton; 147 private System.Windows.Forms.ListView itemsListView;148 197 private System.Windows.Forms.ToolTip toolTip; 149 private System.Windows.Forms.ColumnHeader nameColumnHeader; 150 private System.Windows.Forms.ColumnHeader descriptioncolumnHeader; 151 private System.Windows.Forms.ColumnHeader versionColumnHeader; 198 private System.Windows.Forms.SplitContainer splitContainer; 199 private System.Windows.Forms.TextBox descriptionTextBox; 200 private System.Windows.Forms.Label searchLabel; 201 private System.Windows.Forms.TextBox searchTextBox; 202 private System.Windows.Forms.TreeView typesTreeView; 203 private System.Windows.Forms.ImageList imageList; 152 204 } 153 205 } -
branches/NewItemDialog/HeuristicLab.Optimizer/3.3/NewItemDialog.cs
r12012 r12184 21 21 22 22 using System; 23 using System. Drawing;23 using System.Collections.Generic; 24 24 using System.Linq; 25 25 using System.Windows.Forms; … … 29 29 namespace HeuristicLab.Optimizer { 30 30 internal partial class NewItemDialog : Form { 31 private bool initialized; 31 private List<TreeNode> treeNodes; 32 private string currentSearchString; 33 34 private Type selectedType; 35 public Type SelectedType { 36 get { return selectedType; } 37 private set { 38 if (value != selectedType) { 39 selectedType = value; 40 OnSelectedTypeChanged(); 41 } 42 } 43 } 32 44 33 45 private IItem item; … … 37 49 38 50 public NewItemDialog() { 39 initialized = false; 51 InitializeComponent(); 52 treeNodes = new List<TreeNode>(); 53 currentSearchString = string.Empty; 40 54 item = null; 41 InitializeComponent(); 42 } 55 SelectedTypeChanged += this_SelectedTypeChanged; 56 } 57 43 58 44 59 private void NewItemDialog_Load(object sender, EventArgs e) { 45 if (!initialized) { 46 var categories = from t in ApplicationManager.Manager.GetTypes(typeof(IItem)) 47 where CreatableAttribute.IsCreatable(t) 48 orderby CreatableAttribute.GetCategory(t), ItemAttribute.GetName(t), ItemAttribute.GetVersion(t) ascending 49 group t by CreatableAttribute.GetCategory(t) into c 50 select c; 51 52 itemsListView.SmallImageList = new ImageList(); 53 itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Class); // default icon 54 foreach (var category in categories) { 55 ListViewGroup group = new ListViewGroup(category.Key); 56 itemsListView.Groups.Add(group); 57 foreach (var creatable in category) { 58 string name = ItemAttribute.GetName(creatable); 59 string version = ItemAttribute.GetVersion(creatable).ToString(); 60 string description = ItemAttribute.GetDescription(creatable); 61 ListViewItem item = new ListViewItem(new string[] { name, version, description }, group); 62 item.ImageIndex = 0; 63 Image image = ItemAttribute.GetImage(creatable); 64 if (image != null) { 65 itemsListView.SmallImageList.Images.Add(image); 66 item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1; 60 var categories = 61 from t in ApplicationManager.Manager.GetTypes(typeof(IItem)) 62 where CreatableAttribute.IsCreatable(t) 63 orderby CreatableAttribute.GetCategory(t), ItemAttribute.GetName(t), ItemAttribute.GetVersion(t) ascending 64 group t by CreatableAttribute.GetCategory(t) into c 65 select c; 66 67 imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Class); // default icon 68 imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Namespace); // plugins 69 imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Interface); // interfacesitemsListView.SmallImageList = new ImageList(); 70 imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Template); // generic typesitemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Class); // default icon 71 72 foreach (var category in categories) { 73 var categoryNode = new TreeNode(category.Key) { 74 ImageIndex = 1, 75 Tag = category.Key, 76 }; 77 categoryNode.SelectedImageIndex = categoryNode.ImageIndex; 78 79 foreach (var creatable in category) { 80 string name = ItemAttribute.GetName(creatable); 81 string version = ItemAttribute.GetVersion(creatable).ToString(); 82 string description = ItemAttribute.GetDescription(creatable); 83 84 var itemNode = new TreeNode(name) { 85 ImageIndex = 0, 86 Tag = creatable 87 }; 88 itemNode.SelectedImageIndex = itemNode.ImageIndex; 89 categoryNode.Nodes.Add(itemNode); 90 91 /* 92 ListViewItem item = new ListViewItem(new string[] { name, version, description }, group); 93 item.ImageIndex = 0; 94 Image image = ItemAttribute.GetImage(creatable); 95 if (image != null) { 96 itemsListView.SmallImageList.Images.Add(image); 97 item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1; 98 } 99 item.Tag = creatable; 100 itemsListView.Items.Add(item);*/ 101 } 102 if (categoryNode.Nodes.Count > 0) 103 treeNodes.Add(categoryNode); 104 } 105 foreach (var node in treeNodes) 106 typesTreeView.Nodes.Add((TreeNode)node.Clone()); 107 //for (int i = 0; i < itemsListView.Columns.Count; i++) 108 // itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 109 } 110 111 private void NewItemDialog_Shown(object sender, EventArgs e) { 112 SelectedType = null; 113 } 114 115 public virtual void Filter(string searchString) { 116 if (InvokeRequired) { 117 Invoke(new Action<string>(Filter), searchString); 118 } else { 119 searchString = searchString.ToLower(); 120 121 if (!searchString.Contains(currentSearchString)) { 122 typesTreeView.BeginUpdate(); 123 // expand saerch -> restore all tree nodes 124 var selectedNode = typesTreeView.SelectedNode; 125 typesTreeView.Nodes.Clear(); 126 foreach (TreeNode node in treeNodes) 127 typesTreeView.Nodes.Add((TreeNode)node.Clone()); 128 RestoreSelectedNode(selectedNode); 129 typesTreeView.EndUpdate(); 130 // remove nodes 131 typesTreeView.BeginUpdate(); 132 int i = 0; 133 while (i < typesTreeView.Nodes.Count) { 134 int j = 0; 135 while (j < typesTreeView.Nodes[i].Nodes.Count) { 136 if (!typesTreeView.Nodes[i].Nodes[j].Text.ToLower().Contains(searchString)) { 137 if ((typesTreeView.Nodes[i].Nodes[j].Tag as Type).Equals(SelectedType)) 138 SelectedType = null; 139 typesTreeView.Nodes[i].Nodes[j].Remove(); 140 } else 141 j++; 67 142 } 68 item.Tag = creatable; 69 itemsListView.Items.Add(item); 70 } 71 } 72 for (int i = 0; i < itemsListView.Columns.Count; i++) 73 itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 74 initialized = true; 75 } 76 } 77 78 private void NewItemDialog_Shown(object sender, EventArgs e) { 79 item = null; 80 } 81 82 private void itemTypesListView_SelectedIndexChanged(object sender, EventArgs e) { 83 okButton.Enabled = itemsListView.SelectedItems.Count == 1; 84 } 143 if (typesTreeView.Nodes[i].Nodes.Count == 0) 144 typesTreeView.Nodes[i].Remove(); 145 else 146 i++; 147 } 148 typesTreeView.EndUpdate(); 149 currentSearchString = searchString; 150 151 // if there is just one type node left, select by default 152 if (typesTreeView.Nodes.Count == 1) { 153 if (typesTreeView.Nodes[0].Nodes.Count == 1) { 154 typesTreeView.SelectedNode = typesTreeView.Nodes[0].Nodes[0]; 155 } 156 } 157 158 if (typesTreeView.Nodes.Count == 0) { 159 SelectedType = null; 160 typesTreeView.Enabled = false; 161 } else { 162 SetTreeNodeVisibility(); 163 typesTreeView.Enabled = true; 164 } 165 UpdateDescription(); 166 } 167 } 168 } 169 170 protected virtual void UpdateDescription() { 171 descriptionTextBox.Text = string.Empty; 172 173 if (typesTreeView.SelectedNode != null) { 174 string category = typesTreeView.SelectedNode.Tag as string; 175 if (category != null) { 176 descriptionTextBox.Text = category; 177 } 178 Type type = typesTreeView.SelectedNode.Tag as Type; 179 if (type != null) { 180 string description = ItemAttribute.GetDescription(type); 181 if (description != null) 182 descriptionTextBox.Text = description; 183 } 184 } else if (typesTreeView.Nodes.Count == 0) { 185 descriptionTextBox.Text = "No types found"; 186 } 187 } 188 189 #region Events 190 public event EventHandler SelectedTypeChanged; 191 protected virtual void OnSelectedTypeChanged() { 192 if (SelectedTypeChanged != null) 193 SelectedTypeChanged(this, EventArgs.Empty); 194 } 195 #endregion 196 197 #region Control Events 198 protected virtual void searchTextBox_TextChanged(object sender, System.EventArgs e) { 199 Filter(searchTextBox.Text); 200 } 201 202 protected virtual void itemsTreeView_AfterSelect(object sender, TreeViewEventArgs e) { 203 if (typesTreeView.SelectedNode == null) SelectedType = null; 204 else SelectedType = typesTreeView.SelectedNode.Tag as Type; 205 UpdateDescription(); 206 } 207 208 protected virtual void itemsTreeView_VisibleChanged(object sender, EventArgs e) { 209 if (Visible) SetTreeNodeVisibility(); 210 } 211 #endregion 212 213 #region Helpers 214 private void RestoreSelectedNode(TreeNode selectedNode) { 215 if (selectedNode != null) { 216 foreach (TreeNode node in typesTreeView.Nodes) { 217 if (node.Text.Equals(selectedNode.Text)) typesTreeView.SelectedNode = node; 218 foreach (TreeNode child in node.Nodes) { 219 if ((child.Text.Equals(selectedNode.Text)) && (child.Tag == selectedNode.Tag)) 220 typesTreeView.SelectedNode = child; 221 } 222 } 223 if (typesTreeView.SelectedNode == null) SelectedType = null; 224 } 225 } 226 private void SetTreeNodeVisibility() { 227 TreeNode selectedNode = typesTreeView.SelectedNode; 228 if (string.IsNullOrEmpty(currentSearchString) && (typesTreeView.Nodes.Count > 1)) { 229 typesTreeView.CollapseAll(); 230 if (selectedNode != null) typesTreeView.SelectedNode = selectedNode; 231 } else { 232 typesTreeView.ExpandAll(); 233 } 234 if (selectedNode != null) selectedNode.EnsureVisible(); 235 } 236 #endregion 85 237 86 238 private void okButton_Click(object sender, EventArgs e) { 87 if ( itemsListView.SelectedItems.Count == 1) {88 item = (IItem)Activator.CreateInstance( (Type)itemsListView.SelectedItems[0].Tag);239 if (SelectedType != null) { 240 item = (IItem)Activator.CreateInstance(SelectedType); 89 241 DialogResult = DialogResult.OK; 90 242 Close(); 91 243 } 92 244 } 93 private void itemT ypesListView_DoubleClick(object sender, EventArgs e) {94 if ( itemsListView.SelectedItems.Count == 1) {95 item = (IItem)Activator.CreateInstance( (Type)itemsListView.SelectedItems[0].Tag);245 private void itemTreeView_DoubleClick(object sender, EventArgs e) { 246 if (SelectedType != null) { 247 item = (IItem)Activator.CreateInstance(SelectedType); 96 248 DialogResult = DialogResult.OK; 97 249 Close(); 98 250 } 99 251 } 252 private void this_SelectedTypeChanged(object sender, EventArgs e) { 253 okButton.Enabled = SelectedType != null; 254 } 100 255 } 101 256 }
Note: See TracChangeset
for help on using the changeset viewer.