- Timestamp:
- 05/03/10 03:31:12 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core.Views/3.3/TypeSelector.cs
r3528 r3588 32 32 protected List<TreeNode> treeNodes; 33 33 protected string currentSearchString; 34 protected TypeSelectorDialog typeSelectorDialog; 34 35 35 36 protected Type baseType; … … 83 84 this.showNotInstantiableTypes = showNotInstantiableTypes; 84 85 this.showGenericTypes = showGenericTypes; 86 87 typeParametersSplitContainer.Panel2Collapsed = !showGenericTypes; 85 88 86 89 TreeNode selectedNode = typesTreeView.SelectedNode; … … 140 143 RestoreSelectedNode(selectedNode); 141 144 Filter(searchTextBox.Text); 145 146 UpdateTypeParameters(); 142 147 } 143 148 } … … 201 206 } 202 207 203 public event EventHandler SelectedTypeChanged; 204 protected virtual void OnSelectedTypeChanged() { 205 if (SelectedTypeChanged != null) 206 SelectedTypeChanged(this, EventArgs.Empty); 208 protected virtual void UpdateTypeParameters() { 209 typeParametersListView.Items.Clear(); 210 if ((SelectedType == null) || !SelectedType.ContainsGenericParameters) { 211 typeParametersGroupBox.Enabled = false; 212 typeParametersSplitContainer.Panel2Collapsed = true; 213 } else { 214 typeParametersGroupBox.Enabled = true; 215 typeParametersSplitContainer.Panel2Collapsed = false; 216 setTypeParameterButton.Enabled = false; 217 218 foreach (Type param in SelectedType.GetGenericArguments()) { 219 if (param.IsGenericParameter) { 220 ListViewItem item = new ListViewItem(); 221 item.Text = param.Name; 222 223 item.ToolTipText = "Constraints:"; 224 Type[] constraints = param.GetGenericParameterConstraints(); 225 if (constraints.Length == 0) { 226 item.ToolTipText += " none"; 227 } else { 228 foreach (Type constraint in constraints) 229 item.ToolTipText += " " + constraint.GetPrettyName(); 230 } 231 232 item.Tag = param; 233 typeParametersListView.Items.Add(item); 234 } 235 } 236 typeParametersListView.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 237 } 238 } 239 240 protected virtual void SetTypeParameter() { 241 if (typeSelectorDialog == null) { 242 typeSelectorDialog = new TypeSelectorDialog(); 243 typeSelectorDialog.Caption = "Select Type of Generic Type Parameter"; 244 } 245 Type param = typeParametersListView.SelectedItems[0].Tag as Type; 246 Type[] contraints = param.GetGenericParameterConstraints(); 247 typeSelectorDialog.TypeSelector.Configure(typeof(IItem), true, true); 248 249 if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) { 250 Type selected = typeSelectorDialog.TypeSelector.SelectedType; 251 Type[] parameters = SelectedType.GetGenericArguments(); 252 parameters[param.GenericParameterPosition] = selected; 253 SelectedType = SelectedType.GetGenericTypeDefinition().MakeGenericType(parameters); 254 255 typeParametersListView.SelectedItems[0].Text = param.Name + ": " + selected.GetPrettyName(); 256 typeParametersListView.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 257 } 207 258 } 208 259 … … 229 280 } 230 281 282 #region Events 283 public event EventHandler SelectedTypeChanged; 284 protected virtual void OnSelectedTypeChanged() { 285 if (SelectedTypeChanged != null) 286 SelectedTypeChanged(this, EventArgs.Empty); 287 } 288 #endregion 289 290 #region Control Events 231 291 protected virtual void searchTextBox_TextChanged(object sender, System.EventArgs e) { 232 292 Filter(searchTextBox.Text); … … 236 296 if (typesTreeView.SelectedNode == null) SelectedType = null; 237 297 else SelectedType = typesTreeView.SelectedNode.Tag as Type; 298 UpdateTypeParameters(); 238 299 UpdateDescription(); 239 300 } 240 241 301 protected virtual void typesTreeView_ItemDrag(object sender, ItemDragEventArgs e) { 242 302 TreeNode node = (TreeNode)e.Item; … … 250 310 } 251 311 } 252 253 312 protected virtual void typesTreeView_VisibleChanged(object sender, EventArgs e) { 254 313 if (Visible) SetTreeNodeVisibility(); 255 314 } 315 316 protected virtual void typeParametersListView_SelectedIndexChanged(object sender, EventArgs e) { 317 setTypeParameterButton.Enabled = typeParametersListView.SelectedItems.Count == 1; 318 } 319 protected virtual void typeParametersListView_DoubleClick(object sender, EventArgs e) { 320 if (typeParametersListView.SelectedItems.Count == 1) 321 SetTypeParameter(); 322 } 323 324 protected virtual void setTypeParameterButton_Click(object sender, EventArgs e) { 325 SetTypeParameter(); 326 } 327 #endregion 256 328 257 329 #region Helpers
Note: See TracChangeset
for help on using the changeset viewer.