Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12305 for trunk/sources


Ignore:
Timestamp:
04/13/15 16:58:58 (10 years ago)
Author:
mkommend
Message:

#2025: Merged changes from the NewItemDialog branch into the trunk.

Location:
trunk/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/HLScript/HeuristicLab.Coremergedeligible
      /branches/NewItemDialog/HeuristicLab.Coremergedeligible
      /stable/HeuristicLab.Coremergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.Core10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.Core5516-5520
      /branches/Benchmarking/sources/HeuristicLab.Core6917-7005
      /branches/CloningRefactoring/HeuristicLab.Core4656-4721
      /branches/CodeEditor/HeuristicLab.Core11700-11806
      /branches/DataAnalysis Refactoring/HeuristicLab.Core5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Core5815-6180
      /branches/DataAnalysis/HeuristicLab.Core4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Core10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.Core6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Core5060
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Core6123-9799
      /branches/LogResidualEvaluator/HeuristicLab.Core10202-10483
      /branches/NET40/sources/HeuristicLab.Core5138-5162
      /branches/NSGA-II Changes/HeuristicLab.Core12033-12122
      /branches/ParallelEngine/HeuristicLab.Core5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Core7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Core6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Core6828
      /branches/RuntimeOptimizer/HeuristicLab.Core8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.Core7787-8333
      /branches/SlaveShutdown/HeuristicLab.Core8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Core10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Core5370-5682
      /branches/Trunk/HeuristicLab.Core6829-6865
      /branches/UnloadJobs/HeuristicLab.Core9168-9215
      /branches/VNS/HeuristicLab.Core5594-5752
      /branches/histogram/HeuristicLab.Core5959-6341
  • trunk/sources/HeuristicLab.Core/3.3/Attributes/CreatableAttribute.cs

    r12012 r12305  
    3636    }
    3737
     38    public int Priority { get; set; }
     39
     40
    3841    public CreatableAttribute() {
    3942      Category = "Other Items";
     43      Priority = int.MaxValue;
    4044    }
    4145    public CreatableAttribute(string category)
     
    5357      else return null;
    5458    }
     59
     60    public static int GetPriority(Type type) {
     61      var attribs = type.GetCustomAttributes(typeof(CreatableAttribute), false);
     62      if (attribs.Length > 0) return ((CreatableAttribute)attribs[0]).Priority;
     63      else return int.MaxValue;
     64    }
    5565  }
    5666}
  • trunk/sources/HeuristicLab.Optimizer

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/HLScript/HeuristicLab.Optimizermergedeligible
      /branches/NewItemDialog/HeuristicLab.Optimizermergedeligible
      /stable/HeuristicLab.Optimizermergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.Optimizer10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.Optimizer5516-5520
      /branches/Benchmarking/sources/HeuristicLab.Optimizer6917-7005
      /branches/CloningRefactoring/HeuristicLab.Optimizer4656-4721
      /branches/CodeEditor/HeuristicLab.Optimizer11700-11806
      /branches/DataAnalysis Refactoring/HeuristicLab.Optimizer5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Optimizer5815-6180
      /branches/DataAnalysis/HeuristicLab.Optimizer4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Optimizer10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.Optimizer6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Optimizer5060
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.Optimizer6123-9799
      /branches/LogResidualEvaluator/HeuristicLab.Optimizer10202-10483
      /branches/NET40/sources/HeuristicLab.Optimizer5138-5162
      /branches/NSGA-II Changes/HeuristicLab.Optimizer12033-12122
      /branches/ParallelEngine/HeuristicLab.Optimizer5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Optimizer7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Optimizer6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Optimizer6828
      /branches/RuntimeOptimizer/HeuristicLab.Optimizer8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.Optimizer7787-8333
      /branches/SlaveShutdown/HeuristicLab.Optimizer8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Optimizer10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Optimizer5370-5682
      /branches/Trunk/HeuristicLab.Optimizer6829-6865
      /branches/UnloadJobs/HeuristicLab.Optimizer9168-9215
      /branches/VNS/HeuristicLab.Optimizer5594-5752
      /branches/histogram/HeuristicLab.Optimizer5959-6341
  • trunk/sources/HeuristicLab.Optimizer/3.3/NewItemDialog.Designer.cs

    r12012 r12305  
    4646    private void InitializeComponent() {
    4747      this.components = new System.ComponentModel.Container();
     48      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NewItemDialog));
    4849      this.okButton = new System.Windows.Forms.Button();
    4950      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();
    5351      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.expandAllButton = new System.Windows.Forms.Button();
     54      this.collapseAllButton = new System.Windows.Forms.Button();
     55      this.searchTextBox = new System.Windows.Forms.TextBox();
     56      this.clearSearchButton = new System.Windows.Forms.Button();
     57      this.splitContainer = new System.Windows.Forms.SplitContainer();
     58      this.availableItemsGroupBox = new System.Windows.Forms.GroupBox();
     59      this.typesTreeView = new System.Windows.Forms.TreeView();
     60      this.imageList = new System.Windows.Forms.ImageList(this.components);
     61      this.itemGroupBox = new System.Windows.Forms.GroupBox();
     62      this.itemDescriptionTextBox = new System.Windows.Forms.TextBox();
     63      this.pluginDescriptionGroupBox = new System.Windows.Forms.GroupBox();
     64      this.versionTextBox = new System.Windows.Forms.TextBox();
     65      this.pluginTextBox = new System.Windows.Forms.TextBox();
     66      this.pluginDescriptionTextBox = new System.Windows.Forms.TextBox();
     67      this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
     68      this.expandToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     69      this.expandAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     70      this.collapseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     71      this.collapseAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     72      this.descriptionSplitContainer = new System.Windows.Forms.SplitContainer();
     73      this.searchTextBox.SuspendLayout();
     74      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
     75      this.splitContainer.Panel1.SuspendLayout();
     76      this.splitContainer.Panel2.SuspendLayout();
     77      this.splitContainer.SuspendLayout();
     78      this.availableItemsGroupBox.SuspendLayout();
     79      this.itemGroupBox.SuspendLayout();
     80      this.pluginDescriptionGroupBox.SuspendLayout();
     81      this.contextMenuStrip.SuspendLayout();
     82      ((System.ComponentModel.ISupportInitialize)(this.descriptionSplitContainer)).BeginInit();
     83      this.descriptionSplitContainer.Panel1.SuspendLayout();
     84      this.descriptionSplitContainer.Panel2.SuspendLayout();
     85      this.descriptionSplitContainer.SuspendLayout();
    5586      this.SuspendLayout();
    5687      //
     
    6091      this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
    6192      this.okButton.Enabled = false;
    62       this.okButton.Location = new System.Drawing.Point(456, 409);
     93      this.okButton.Location = new System.Drawing.Point(456, 587);
    6394      this.okButton.Name = "okButton";
    6495      this.okButton.Size = new System.Drawing.Size(75, 23);
    65       this.okButton.TabIndex = 2;
     96      this.okButton.TabIndex = 1;
    6697      this.okButton.Text = "&OK";
    6798      this.okButton.UseVisualStyleBackColor = true;
     
    72103      this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    73104      this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
    74       this.cancelButton.Location = new System.Drawing.Point(537, 409);
     105      this.cancelButton.Location = new System.Drawing.Point(537, 587);
    75106      this.cancelButton.Name = "cancelButton";
    76107      this.cancelButton.Size = new System.Drawing.Size(75, 23);
    77       this.cancelButton.TabIndex = 3;
     108      this.cancelButton.TabIndex = 2;
    78109      this.cancelButton.Text = "&Cancel";
    79110      this.cancelButton.UseVisualStyleBackColor = true;
    80111      //
    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";
     112      // searchLabel
     113      //
     114      this.searchLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Zoom;
     115      this.searchLabel.Location = new System.Drawing.Point(6, 17);
     116      this.searchLabel.Name = "searchLabel";
     117      this.searchLabel.Size = new System.Drawing.Size(20, 20);
     118      this.searchLabel.TabIndex = 0;
     119      this.toolTip.SetToolTip(this.searchLabel, "Enter string to search for items");
     120      //
     121      // expandAllButton
     122      //
     123      this.expandAllButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     124      this.expandAllButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.ZoomIn;
     125      this.expandAllButton.Location = new System.Drawing.Point(12, 587);
     126      this.expandAllButton.Name = "expandAllButton";
     127      this.expandAllButton.Size = new System.Drawing.Size(23, 23);
     128      this.expandAllButton.TabIndex = 0;
     129      this.expandAllButton.TabStop = false;
     130      this.toolTip.SetToolTip(this.expandAllButton, "Expand all nodes.");
     131      this.expandAllButton.UseVisualStyleBackColor = true;
     132      this.expandAllButton.Click += new System.EventHandler(this.expandAllButton_Click);
     133      //
     134      // collapseAllButton
     135      //
     136      this.collapseAllButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     137      this.collapseAllButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.ZoomOut;
     138      this.collapseAllButton.Location = new System.Drawing.Point(41, 587);
     139      this.collapseAllButton.Name = "collapseAllButton";
     140      this.collapseAllButton.Size = new System.Drawing.Size(23, 23);
     141      this.collapseAllButton.TabIndex = 0;
     142      this.collapseAllButton.TabStop = false;
     143      this.toolTip.SetToolTip(this.collapseAllButton, "Collapse all nodes.");
     144      this.collapseAllButton.UseVisualStyleBackColor = true;
     145      this.collapseAllButton.Click += new System.EventHandler(this.collapseAllButton_Click);
     146      //
     147      // searchTextBox
     148      //
     149      this.searchTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     150            | System.Windows.Forms.AnchorStyles.Left)
     151            | System.Windows.Forms.AnchorStyles.Right)));
     152      this.searchTextBox.Controls.Add(this.clearSearchButton);
     153      this.searchTextBox.Location = new System.Drawing.Point(32, 17);
     154      this.searchTextBox.Name = "searchTextBox";
     155      this.searchTextBox.Size = new System.Drawing.Size(562, 20);
     156      this.searchTextBox.TabIndex = 1;
     157      this.toolTip.SetToolTip(this.searchTextBox, "Filters the available Items.\r\nThe search term is tokenized by space and a name ha" +
     158        "s to contain all tokens to be displayed.\r\n(E.g. \"Sym Reg\" matches \"Symbolic Regr" +
     159        "ession\")");
     160      this.searchTextBox.TextChanged += new System.EventHandler(this.searchTextBox_TextChanged);
     161      this.searchTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.searchTextBox_KeyDown);
     162      //
     163      // clearSearchButton
     164      //
     165      this.clearSearchButton.BackColor = System.Drawing.Color.Transparent;
     166      this.clearSearchButton.Cursor = System.Windows.Forms.Cursors.Default;
     167      this.clearSearchButton.Dock = System.Windows.Forms.DockStyle.Right;
     168      this.clearSearchButton.FlatAppearance.BorderSize = 0;
     169      this.clearSearchButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
     170      this.clearSearchButton.ForeColor = System.Drawing.Color.Transparent;
     171      this.clearSearchButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Delete;
     172      this.clearSearchButton.Location = new System.Drawing.Point(543, 0);
     173      this.clearSearchButton.Margin = new System.Windows.Forms.Padding(0);
     174      this.clearSearchButton.Name = "clearSearchButton";
     175      this.clearSearchButton.Size = new System.Drawing.Size(15, 16);
     176      this.clearSearchButton.TabIndex = 0;
     177      this.clearSearchButton.TabStop = false;
     178      this.clearSearchButton.UseVisualStyleBackColor = false;
     179      this.clearSearchButton.Click += new System.EventHandler(this.clearSearchButton_Click);
     180      //
     181      // splitContainer
     182      //
     183      this.splitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     184            | System.Windows.Forms.AnchorStyles.Left)
     185            | System.Windows.Forms.AnchorStyles.Right)));
     186      this.splitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel2;
     187      this.splitContainer.Location = new System.Drawing.Point(12, 12);
     188      this.splitContainer.Name = "splitContainer";
     189      this.splitContainer.Orientation = System.Windows.Forms.Orientation.Horizontal;
     190      //
     191      // splitContainer.Panel1
     192      //
     193      this.splitContainer.Panel1.Controls.Add(this.availableItemsGroupBox);
     194      //
     195      // splitContainer.Panel2
     196      //
     197      this.splitContainer.Panel2.Controls.Add(this.descriptionSplitContainer);
     198      this.splitContainer.Size = new System.Drawing.Size(600, 569);
     199      this.splitContainer.SplitterDistance = 373;
     200      this.splitContainer.TabIndex = 0;
     201      this.splitContainer.TabStop = false;
     202      //
     203      // availableItemsGroupBox
     204      //
     205      this.availableItemsGroupBox.Controls.Add(this.searchLabel);
     206      this.availableItemsGroupBox.Controls.Add(this.searchTextBox);
     207      this.availableItemsGroupBox.Controls.Add(this.typesTreeView);
     208      this.availableItemsGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
     209      this.availableItemsGroupBox.Location = new System.Drawing.Point(0, 0);
     210      this.availableItemsGroupBox.Name = "availableItemsGroupBox";
     211      this.availableItemsGroupBox.Padding = new System.Windows.Forms.Padding(3, 15, 3, 3);
     212      this.availableItemsGroupBox.Size = new System.Drawing.Size(600, 373);
     213      this.availableItemsGroupBox.TabIndex = 5;
     214      this.availableItemsGroupBox.TabStop = false;
     215      this.availableItemsGroupBox.Text = "Available Items";
     216      //
     217      // typesTreeView
     218      //
     219      this.typesTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     220            | System.Windows.Forms.AnchorStyles.Left)
     221            | System.Windows.Forms.AnchorStyles.Right)));
     222      this.typesTreeView.HideSelection = false;
     223      this.typesTreeView.ImageIndex = 0;
     224      this.typesTreeView.ImageList = this.imageList;
     225      this.typesTreeView.Location = new System.Drawing.Point(6, 41);
     226      this.typesTreeView.Name = "typesTreeView";
     227      this.typesTreeView.SelectedImageIndex = 0;
     228      this.typesTreeView.ShowNodeToolTips = true;
     229      this.typesTreeView.Size = new System.Drawing.Size(588, 326);
     230      this.typesTreeView.TabIndex = 2;
     231      this.typesTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.itemsTreeView_AfterSelect);
     232      this.typesTreeView.VisibleChanged += new System.EventHandler(this.itemsTreeView_VisibleChanged);
     233      this.typesTreeView.DoubleClick += new System.EventHandler(this.itemTreeView_DoubleClick);
     234      this.typesTreeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.typesTreeView_MouseDown);
     235      //
     236      // imageList
     237      //
     238      this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
     239      this.imageList.ImageSize = new System.Drawing.Size(16, 16);
     240      this.imageList.TransparentColor = System.Drawing.Color.Transparent;
     241      //
     242      // itemGroupBox
     243      //
     244      this.itemGroupBox.Controls.Add(this.itemDescriptionTextBox);
     245      this.itemGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
     246      this.itemGroupBox.Location = new System.Drawing.Point(0, 0);
     247      this.itemGroupBox.Name = "itemGroupBox";
     248      this.itemGroupBox.Size = new System.Drawing.Size(600, 81);
     249      this.itemGroupBox.TabIndex = 1;
     250      this.itemGroupBox.TabStop = false;
     251      this.itemGroupBox.Text = "Item";
     252      //
     253      // itemDescriptionTextBox
     254      //
     255      this.itemDescriptionTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     256            | System.Windows.Forms.AnchorStyles.Left)
     257            | System.Windows.Forms.AnchorStyles.Right)));
     258      this.itemDescriptionTextBox.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     259      this.itemDescriptionTextBox.Location = new System.Drawing.Point(6, 19);
     260      this.itemDescriptionTextBox.Multiline = true;
     261      this.itemDescriptionTextBox.Name = "itemDescriptionTextBox";
     262      this.itemDescriptionTextBox.ReadOnly = true;
     263      this.itemDescriptionTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
     264      this.itemDescriptionTextBox.Size = new System.Drawing.Size(588, 56);
     265      this.itemDescriptionTextBox.TabIndex = 0;
     266      this.itemDescriptionTextBox.TabStop = false;
     267      //
     268      // pluginDescriptionGroupBox
     269      //
     270      this.pluginDescriptionGroupBox.Controls.Add(this.versionTextBox);
     271      this.pluginDescriptionGroupBox.Controls.Add(this.pluginTextBox);
     272      this.pluginDescriptionGroupBox.Controls.Add(this.pluginDescriptionTextBox);
     273      this.pluginDescriptionGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
     274      this.pluginDescriptionGroupBox.Location = new System.Drawing.Point(0, 0);
     275      this.pluginDescriptionGroupBox.Name = "pluginDescriptionGroupBox";
     276      this.pluginDescriptionGroupBox.Size = new System.Drawing.Size(600, 107);
     277      this.pluginDescriptionGroupBox.TabIndex = 1;
     278      this.pluginDescriptionGroupBox.TabStop = false;
     279      this.pluginDescriptionGroupBox.Text = "Plugin";
     280      //
     281      // versionTextBox
     282      //
     283      this.versionTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     284      this.versionTextBox.Location = new System.Drawing.Point(444, 20);
     285      this.versionTextBox.Name = "versionTextBox";
     286      this.versionTextBox.ReadOnly = true;
     287      this.versionTextBox.Size = new System.Drawing.Size(150, 20);
     288      this.versionTextBox.TabIndex = 0;
     289      this.versionTextBox.TabStop = false;
     290      //
     291      // pluginTextBox
     292      //
     293      this.pluginTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     294            | System.Windows.Forms.AnchorStyles.Right)));
     295      this.pluginTextBox.Location = new System.Drawing.Point(6, 20);
     296      this.pluginTextBox.Name = "pluginTextBox";
     297      this.pluginTextBox.ReadOnly = true;
     298      this.pluginTextBox.Size = new System.Drawing.Size(432, 20);
     299      this.pluginTextBox.TabIndex = 0;
     300      this.pluginTextBox.TabStop = false;
     301      //
     302      // pluginDescriptionTextBox
     303      //
     304      this.pluginDescriptionTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     305            | System.Windows.Forms.AnchorStyles.Left)
     306            | System.Windows.Forms.AnchorStyles.Right)));
     307      this.pluginDescriptionTextBox.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     308      this.pluginDescriptionTextBox.Location = new System.Drawing.Point(6, 46);
     309      this.pluginDescriptionTextBox.Multiline = true;
     310      this.pluginDescriptionTextBox.Name = "pluginDescriptionTextBox";
     311      this.pluginDescriptionTextBox.ReadOnly = true;
     312      this.pluginDescriptionTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
     313      this.pluginDescriptionTextBox.Size = new System.Drawing.Size(588, 55);
     314      this.pluginDescriptionTextBox.TabIndex = 0;
     315      this.pluginDescriptionTextBox.TabStop = false;
     316      //
     317      // contextMenuStrip
     318      //
     319      this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
     320            this.expandToolStripMenuItem,
     321            this.expandAllToolStripMenuItem,
     322            this.collapseToolStripMenuItem,
     323            this.collapseAllToolStripMenuItem});
     324      this.contextMenuStrip.Name = "contextMenuStrip";
     325      this.contextMenuStrip.Size = new System.Drawing.Size(137, 92);
     326      //
     327      // expandToolStripMenuItem
     328      //
     329      this.expandToolStripMenuItem.Name = "expandToolStripMenuItem";
     330      this.expandToolStripMenuItem.Size = new System.Drawing.Size(136, 22);
     331      this.expandToolStripMenuItem.Text = "Expand";
     332      this.expandToolStripMenuItem.Click += new System.EventHandler(this.expandToolStripMenuItem_Click);
     333      //
     334      // expandAllToolStripMenuItem
     335      //
     336      this.expandAllToolStripMenuItem.Name = "expandAllToolStripMenuItem";
     337      this.expandAllToolStripMenuItem.Size = new System.Drawing.Size(136, 22);
     338      this.expandAllToolStripMenuItem.Text = "Expand All";
     339      this.expandAllToolStripMenuItem.Click += new System.EventHandler(this.expandAllToolStripMenuItem_Click);
     340      //
     341      // collapseToolStripMenuItem
     342      //
     343      this.collapseToolStripMenuItem.Name = "collapseToolStripMenuItem";
     344      this.collapseToolStripMenuItem.Size = new System.Drawing.Size(136, 22);
     345      this.collapseToolStripMenuItem.Text = "Collapse";
     346      this.collapseToolStripMenuItem.Click += new System.EventHandler(this.collapseToolStripMenuItem_Click);
     347      //
     348      // collapseAllToolStripMenuItem
     349      //
     350      this.collapseAllToolStripMenuItem.Name = "collapseAllToolStripMenuItem";
     351      this.collapseAllToolStripMenuItem.Size = new System.Drawing.Size(136, 22);
     352      this.collapseAllToolStripMenuItem.Text = "Collapse All";
     353      this.collapseAllToolStripMenuItem.Click += new System.EventHandler(this.collapseAllToolStripMenuItem_Click);
     354      //
     355      // descriptionSplitContainer
     356      //
     357      this.descriptionSplitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
     358      this.descriptionSplitContainer.Location = new System.Drawing.Point(0, 0);
     359      this.descriptionSplitContainer.Name = "descriptionSplitContainer";
     360      this.descriptionSplitContainer.Orientation = System.Windows.Forms.Orientation.Horizontal;
     361      //
     362      // descriptionSplitContainer.Panel1
     363      //
     364      this.descriptionSplitContainer.Panel1.Controls.Add(this.itemGroupBox);
     365      //
     366      // descriptionSplitContainer.Panel2
     367      //
     368      this.descriptionSplitContainer.Panel2.Controls.Add(this.pluginDescriptionGroupBox);
     369      this.descriptionSplitContainer.Size = new System.Drawing.Size(600, 192);
     370      this.descriptionSplitContainer.SplitterDistance = 81;
     371      this.descriptionSplitContainer.TabIndex = 1;
     372      this.descriptionSplitContainer.TabStop = false;
    118373      //
    119374      // NewItemDialog
    120375      //
    121376      this.AcceptButton = this.okButton;
    122       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    123377      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    124378      this.CancelButton = this.cancelButton;
    125       this.ClientSize = new System.Drawing.Size(624, 444);
    126       this.Controls.Add(this.itemsListView);
     379      this.ClientSize = new System.Drawing.Size(624, 622);
     380      this.Controls.Add(this.splitContainer);
    127381      this.Controls.Add(this.cancelButton);
    128382      this.Controls.Add(this.okButton);
     383      this.Controls.Add(this.expandAllButton);
     384      this.Controls.Add(this.collapseAllButton);
    129385      this.MaximizeBox = false;
    130386      this.MinimizeBox = false;
     
    137393      this.Load += new System.EventHandler(this.NewItemDialog_Load);
    138394      this.Shown += new System.EventHandler(this.NewItemDialog_Shown);
     395      this.searchTextBox.ResumeLayout(false);
     396      this.splitContainer.Panel1.ResumeLayout(false);
     397      this.splitContainer.Panel2.ResumeLayout(false);
     398      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
     399      this.splitContainer.ResumeLayout(false);
     400      this.availableItemsGroupBox.ResumeLayout(false);
     401      this.availableItemsGroupBox.PerformLayout();
     402      this.itemGroupBox.ResumeLayout(false);
     403      this.itemGroupBox.PerformLayout();
     404      this.pluginDescriptionGroupBox.ResumeLayout(false);
     405      this.pluginDescriptionGroupBox.PerformLayout();
     406      this.contextMenuStrip.ResumeLayout(false);
     407      this.descriptionSplitContainer.Panel1.ResumeLayout(false);
     408      this.descriptionSplitContainer.Panel2.ResumeLayout(false);
     409      ((System.ComponentModel.ISupportInitialize)(this.descriptionSplitContainer)).EndInit();
     410      this.descriptionSplitContainer.ResumeLayout(false);
    139411      this.ResumeLayout(false);
    140412
     
    145417    private System.Windows.Forms.Button okButton;
    146418    private System.Windows.Forms.Button cancelButton;
    147     private System.Windows.Forms.ListView itemsListView;
    148419    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;
     420    private System.Windows.Forms.SplitContainer splitContainer;
     421    private System.Windows.Forms.TextBox pluginDescriptionTextBox;
     422    private System.Windows.Forms.Label searchLabel;
     423    private System.Windows.Forms.TextBox searchTextBox;
     424    private System.Windows.Forms.TreeView typesTreeView;
     425    private System.Windows.Forms.ImageList imageList;
     426    private System.Windows.Forms.Button expandAllButton;
     427    private System.Windows.Forms.Button collapseAllButton;
     428    private System.Windows.Forms.GroupBox availableItemsGroupBox;
     429    private System.Windows.Forms.GroupBox pluginDescriptionGroupBox;
     430    private System.Windows.Forms.TextBox versionTextBox;
     431    private System.Windows.Forms.TextBox pluginTextBox;
     432    private System.Windows.Forms.ContextMenuStrip contextMenuStrip;
     433    private System.Windows.Forms.ToolStripMenuItem expandToolStripMenuItem;
     434    private System.Windows.Forms.ToolStripMenuItem expandAllToolStripMenuItem;
     435    private System.Windows.Forms.ToolStripMenuItem collapseToolStripMenuItem;
     436    private System.Windows.Forms.ToolStripMenuItem collapseAllToolStripMenuItem;
     437    private System.Windows.Forms.Button clearSearchButton;
     438    private System.Windows.Forms.GroupBox itemGroupBox;
     439    private System.Windows.Forms.TextBox itemDescriptionTextBox;
     440    private System.Windows.Forms.SplitContainer descriptionSplitContainer;
    152441  }
    153442}
  • trunk/sources/HeuristicLab.Optimizer/3.3/NewItemDialog.cs

    r12012 r12305  
    2121
    2222using System;
     23using System.Collections;
     24using System.Collections.Generic;
    2325using System.Drawing;
    2426using System.Linq;
     
    2931namespace HeuristicLab.Optimizer {
    3032  internal partial class NewItemDialog : Form {
    31     private bool initialized;
     33    private bool isInitialized;
     34
     35    private readonly List<TreeNode> treeNodes;
     36    private string currentSearchString;
     37
     38    private Type selectedType;
     39    public Type SelectedType {
     40      get { return selectedType; }
     41      private set {
     42        if (value != selectedType) {
     43          selectedType = value;
     44          OnSelectedTypeChanged();
     45        }
     46      }
     47    }
    3248
    3349    private IItem item;
     
    3753
    3854    public NewItemDialog() {
    39       initialized = false;
     55      InitializeComponent();
     56      treeNodes = new List<TreeNode>();
     57      currentSearchString = string.Empty;
    4058      item = null;
    41       InitializeComponent();
     59      SelectedTypeChanged += this_SelectedTypeChanged;
    4260    }
    4361
    4462    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;
    67             }
    68             item.Tag = creatable;
    69             itemsListView.Items.Add(item);
     63      if (isInitialized) return;
     64
     65      var categories =
     66        from type in ApplicationManager.Manager.GetTypes(typeof(IItem))
     67        let category = CreatableAttribute.GetCategory(type)
     68        let name = ItemAttribute.GetName(type)
     69        let priority = CreatableAttribute.GetPriority(type)
     70        let version = ItemAttribute.GetVersion(type)
     71        where CreatableAttribute.IsCreatable(type)
     72        orderby category, priority, name, version ascending
     73        group type by category into categoryGroup
     74        select categoryGroup;
     75
     76      var rootNode = CreateCategoryTree(categories);
     77      CreateItemNodes(rootNode, categories);
     78
     79      foreach (TreeNode topNode in rootNode.Nodes)
     80        treeNodes.Add(topNode);
     81      foreach (var node in treeNodes)
     82        typesTreeView.Nodes.Add((TreeNode)node.Clone());
     83
     84      typesTreeView.TreeViewNodeSorter = new ItemTreeNodeComparer();
     85      typesTreeView.Sort();
     86
     87      isInitialized = true;
     88    }
     89
     90    private TreeNode CreateCategoryTree(IEnumerable<IGrouping<string, Type>> categories) {
     91      imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Class);      // default icon
     92      imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Namespace);  // plugins
     93
     94      var rootNode = new TreeNode();
     95
     96      foreach (var category in categories) {
     97        var fullName = category.Key;
     98        var tokens = fullName.Split('#');
     99        var name = tokens.Last();
     100        var parents = tokens.Take(tokens.Length - 1);
     101
     102        var categoryNode = new TreeNode(name, imageIndex: 1, selectedImageIndex: 1) {
     103          Name = fullName,
     104          Tag = fullName
     105        };
     106
     107        var parentNode = FindOrCreateParentNode(rootNode, parents);
     108        if (parentNode != null)
     109          parentNode.Nodes.Add(categoryNode);
     110        else
     111          rootNode.Nodes.Add(categoryNode);
     112      }
     113
     114      return rootNode;
     115    }
     116    private TreeNode FindOrCreateParentNode(TreeNode node, IEnumerable<string> parentCategories) {
     117      TreeNode parentNode = null;
     118      string fullName = null;
     119      foreach (string parentCategory in parentCategories) {
     120        fullName = fullName == null ? parentCategory : fullName + "#" + parentCategory;
     121        parentNode = node.Nodes.Find(fullName, searchAllChildren: false).SingleOrDefault();
     122        if (parentNode == null) {
     123          parentNode = new TreeNode(parentCategory, imageIndex: 1, selectedImageIndex: 1) {
     124            Name = fullName,
     125            Tag = fullName
     126          };
     127          node.Nodes.Add(parentNode);
     128        }
     129        node = parentNode;
     130      }
     131      return parentNode;
     132    }
     133    private void CreateItemNodes(TreeNode node, IEnumerable<IGrouping<string, Type>> categories) {
     134      foreach (var category in categories) {
     135        var categoryNode = node.Nodes.Find(category.Key, searchAllChildren: true).Single();
     136        foreach (var creatable in category) {
     137          var itemNode = CreateItemNode(creatable);
     138          itemNode.Name = itemNode.Name + ":" + category.Key;
     139          categoryNode.Nodes.Add(itemNode);
     140        }
     141      }
     142    }
     143    private TreeNode CreateItemNode(Type creatable) {
     144      string name = ItemAttribute.GetName(creatable);
     145
     146      var itemNode = new TreeNode(name) {
     147        ImageIndex = 0,
     148        Tag = creatable,
     149        Name = name
     150      };
     151
     152      var image = ItemAttribute.GetImage(creatable);
     153      if (image != null) {
     154        imageList.Images.Add(image);
     155        itemNode.ImageIndex = imageList.Images.Count - 1;
     156      }
     157      itemNode.SelectedImageIndex = itemNode.ImageIndex;
     158
     159      return itemNode;
     160    }
     161
     162    private void NewItemDialog_Shown(object sender, EventArgs e) {
     163      searchTextBox.Text = string.Empty;
     164      searchTextBox.Focus();
     165      SelectedType = null;
     166      typesTreeView.SelectedNode = null;
     167      typesTreeView.CollapseAll();
     168      UpdateDescription();
     169    }
     170
     171    public virtual void Filter(string searchString) {
     172      if (InvokeRequired) {
     173        Invoke(new Action<string>(Filter), searchString);
     174      } else {
     175        searchString = searchString.ToLower();
     176
     177        if (!searchString.Contains(currentSearchString)) {
     178          typesTreeView.BeginUpdate();
     179          // expand search -> restore all tree nodes
     180          var selectedNode = typesTreeView.SelectedNode;
     181          typesTreeView.Nodes.Clear();
     182          foreach (TreeNode node in treeNodes)
     183            typesTreeView.Nodes.Add((TreeNode)node.Clone());
     184          RestoreSelectedNode(selectedNode);
     185          typesTreeView.EndUpdate();
     186        }
     187
     188        // remove nodes
     189        typesTreeView.BeginUpdate();
     190        var searchTokens = searchString.Split(' ');
     191
     192        int i = 0;
     193        while (i < typesTreeView.Nodes.Count) {
     194          var categoryNode = typesTreeView.Nodes[i];
     195          bool remove = FilterNode(categoryNode, searchTokens);
     196          if (remove)
     197            typesTreeView.Nodes.RemoveAt(i);
     198          else i++;
     199        }
     200        typesTreeView.EndUpdate();
     201        currentSearchString = searchString;
     202
     203        // select first item
     204        var firstNode = FirstVisibleNode;
     205        while (firstNode != null && !(firstNode.Tag is Type))
     206          firstNode = firstNode.NextVisibleNode;
     207        if (firstNode != null)
     208          typesTreeView.SelectedNode = firstNode;
     209
     210        if (typesTreeView.Nodes.Count == 0) {
     211          SelectedType = null;
     212          typesTreeView.Enabled = false;
     213        } else {
     214          SetTreeNodeVisibility();
     215          typesTreeView.Enabled = true;
     216        }
     217        UpdateDescription();
     218      }
     219    }
     220
     221    private bool FilterNode(TreeNode node, string[] searchTokens) {
     222      if (node.Tag is string) { // Category node
     223        int i = 0;
     224        while (i < node.Nodes.Count) {
     225          bool remove = FilterNode(node.Nodes[i], searchTokens);
     226          if (remove)
     227            node.Nodes.RemoveAt(i);
     228          else i++;
     229        }
     230        return node.Nodes.Count == 0;
     231      } if (node.Tag is Type) { // Type node
     232        var text = node.Text;
     233        if (searchTokens.Any(searchToken => !text.ToLower().Contains(searchToken))) {
     234          var typeTag = (Type)node.Tag;
     235          if (typeTag == SelectedType) {
     236            SelectedType = null;
     237            typesTreeView.SelectedNode = null;
    70238          }
    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     }
     239          return true;
     240        }
     241        return false;
     242      }
     243      throw new InvalidOperationException("Encountered neither a category nor a creatable node during tree traversal.");
     244    }
     245
     246    protected virtual void UpdateDescription() {
     247      itemDescriptionTextBox.Text = string.Empty;
     248      pluginDescriptionTextBox.Text = string.Empty;
     249      pluginTextBox.Text = string.Empty;
     250      versionTextBox.Text = string.Empty;
     251
     252      if (typesTreeView.SelectedNode != null) {
     253        string category = typesTreeView.SelectedNode.Tag as string;
     254        if (category != null) {
     255          itemDescriptionTextBox.Text = category;
     256        }
     257        Type type = typesTreeView.SelectedNode.Tag as Type;
     258        if (type != null) {
     259          string description = ItemAttribute.GetDescription(type);
     260          var version = ItemAttribute.GetVersion(type);
     261          var plugin = ApplicationManager.Manager.GetDeclaringPlugin(type);
     262          if (description != null)
     263            itemDescriptionTextBox.Text = description;
     264          if (plugin != null) {
     265            pluginTextBox.Text = plugin.Name;
     266            pluginDescriptionTextBox.Text = plugin.Description;
     267          }
     268          if (version != null)
     269            versionTextBox.Text = version.ToString();
     270        }
     271      } else if (typesTreeView.Nodes.Count == 0) {
     272        itemDescriptionTextBox.Text = "No types found";
     273      }
     274    }
     275
     276    #region Events
     277    public event EventHandler SelectedTypeChanged;
     278    protected virtual void OnSelectedTypeChanged() {
     279      if (SelectedTypeChanged != null)
     280        SelectedTypeChanged(this, EventArgs.Empty);
     281    }
     282    #endregion
     283
     284    #region Control Events
     285    protected virtual void searchTextBox_TextChanged(object sender, EventArgs e) {
     286      Filter(searchTextBox.Text);
     287    }
     288
     289    protected virtual void itemsTreeView_AfterSelect(object sender, TreeViewEventArgs e) {
     290      if (typesTreeView.SelectedNode == null) SelectedType = null;
     291      else SelectedType = typesTreeView.SelectedNode.Tag as Type;
     292      UpdateDescription();
     293    }
     294
     295    protected virtual void itemsTreeView_VisibleChanged(object sender, EventArgs e) {
     296      if (Visible) SetTreeNodeVisibility();
     297    }
     298    #endregion
     299
     300    #region Helpers
     301    private void RestoreSelectedNode(TreeNode selectedNode) {
     302      if (selectedNode != null) {
     303        var node = typesTreeView.Nodes.Find(selectedNode.Name, searchAllChildren: true).SingleOrDefault();
     304        typesTreeView.SelectedNode = node;
     305        if (typesTreeView.SelectedNode == null) SelectedType = null;
     306      }
     307    }
     308    private void SetTreeNodeVisibility() {
     309      TreeNode selectedNode = typesTreeView.SelectedNode;
     310      if (string.IsNullOrEmpty(currentSearchString) && (typesTreeView.Nodes.Count > 1)) {
     311        typesTreeView.CollapseAll();
     312        if (selectedNode != null) typesTreeView.SelectedNode = selectedNode;
     313      } else {
     314        typesTreeView.ExpandAll();
     315      }
     316      if (selectedNode != null) selectedNode.EnsureVisible();
     317    }
     318    #endregion
    85319
    86320    private void okButton_Click(object sender, EventArgs e) {
    87       if (itemsListView.SelectedItems.Count == 1) {
    88         item = (IItem)Activator.CreateInstance((Type)itemsListView.SelectedItems[0].Tag);
     321      if (SelectedType != null) {
     322        item = (IItem)Activator.CreateInstance(SelectedType);
    89323        DialogResult = DialogResult.OK;
    90324        Close();
    91325      }
    92326    }
    93     private void itemTypesListView_DoubleClick(object sender, EventArgs e) {
    94       if (itemsListView.SelectedItems.Count == 1) {
    95         item = (IItem)Activator.CreateInstance((Type)itemsListView.SelectedItems[0].Tag);
     327    private void itemTreeView_DoubleClick(object sender, EventArgs e) {
     328      if (SelectedType != null) {
     329        item = (IItem)Activator.CreateInstance(SelectedType);
    96330        DialogResult = DialogResult.OK;
    97331        Close();
    98332      }
    99333    }
     334    private void this_SelectedTypeChanged(object sender, EventArgs e) {
     335      okButton.Enabled = SelectedType != null;
     336    }
     337
     338    private void expandAllButton_Click(object sender, EventArgs e) {
     339      typesTreeView.ExpandAll();
     340    }
     341    private void collapseAllButton_Click(object sender, EventArgs e) {
     342      typesTreeView.CollapseAll();
     343    }
     344
     345    private TreeNode toolStripMenuNode = null;
     346    private void typesTreeView_MouseDown(object sender, MouseEventArgs e) {
     347      if (e.Button == MouseButtons.Right) {
     348        Point coordinates = typesTreeView.PointToClient(Cursor.Position);
     349        toolStripMenuNode = typesTreeView.GetNodeAt(coordinates);
     350
     351        if (toolStripMenuNode != null && coordinates.X >= toolStripMenuNode.Bounds.Left &&
     352            coordinates.X <= toolStripMenuNode.Bounds.Right) {
     353          typesTreeView.SelectedNode = toolStripMenuNode;
     354
     355          expandToolStripMenuItem.Enabled =
     356            expandToolStripMenuItem.Visible = !toolStripMenuNode.IsExpanded && toolStripMenuNode.Nodes.Count > 0;
     357          collapseToolStripMenuItem.Enabled = collapseToolStripMenuItem.Visible = toolStripMenuNode.IsExpanded;
     358        } else {
     359          expandToolStripMenuItem.Enabled = expandToolStripMenuItem.Visible = false;
     360          collapseToolStripMenuItem.Enabled = collapseToolStripMenuItem.Visible = false;
     361        }
     362        expandAllToolStripMenuItem.Enabled =
     363          expandAllToolStripMenuItem.Visible =
     364            !typesTreeView.Nodes.OfType<TreeNode>().All(x => TreeNodeIsFullyExpanded(x));
     365        collapseAllToolStripMenuItem.Enabled =
     366          collapseAllToolStripMenuItem.Visible = typesTreeView.Nodes.OfType<TreeNode>().Any(x => x.IsExpanded);
     367        if (contextMenuStrip.Items.Cast<ToolStripMenuItem>().Any(item => item.Enabled))
     368          contextMenuStrip.Show(Cursor.Position);
     369      }
     370    }
     371    private bool TreeNodeIsFullyExpanded(TreeNode node) {
     372      return (node.Nodes.Count == 0) || (node.IsExpanded && node.Nodes.OfType<TreeNode>().All(x => TreeNodeIsFullyExpanded(x)));
     373    }
     374
     375    private void expandToolStripMenuItem_Click(object sender, EventArgs e) {
     376      if (toolStripMenuNode != null) toolStripMenuNode.ExpandAll();
     377    }
     378    private void expandAllToolStripMenuItem_Click(object sender, EventArgs e) {
     379      typesTreeView.ExpandAll();
     380    }
     381    private void collapseToolStripMenuItem_Click(object sender, EventArgs e) {
     382      if (toolStripMenuNode != null) toolStripMenuNode.Collapse();
     383    }
     384    private void collapseAllToolStripMenuItem_Click(object sender, EventArgs e) {
     385      typesTreeView.CollapseAll();
     386    }
     387
     388    private void clearSearchButton_Click(object sender, EventArgs e) {
     389      searchTextBox.Text = string.Empty;
     390      searchTextBox.Focus();
     391    }
     392
     393    private void searchTextBox_KeyDown(object sender, KeyEventArgs e) {
     394      if (typesTreeView.Nodes.Count == 0)
     395        return;
     396
     397      if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down) {
     398        var selectedNode = typesTreeView.SelectedNode;
     399
     400        if (selectedNode == null) { // nothing selected => select first or last
     401          if (e.KeyCode == Keys.Down) typesTreeView.SelectedNode = FirstVisibleNode;
     402          if (e.KeyCode == Keys.Up) typesTreeView.SelectedNode = LastVisibleNode;
     403        } else {
     404          if (e.KeyCode == Keys.Down)
     405            typesTreeView.SelectedNode = selectedNode.NextVisibleNode ?? FirstVisibleNode; // select next or cycle to first
     406          if (e.KeyCode == Keys.Up)
     407            typesTreeView.SelectedNode = selectedNode.PrevVisibleNode ?? LastVisibleNode; // select prev or cycle to last
     408        }
     409        e.Handled = true;
     410      }
     411    }
     412
     413    private TreeNode FirstVisibleNode {
     414      get {
     415        return typesTreeView.Nodes.Count > 0 ? typesTreeView.Nodes[0] : null;
     416      }
     417    }
     418    private TreeNode LastVisibleNode {
     419      get {
     420        var node = FirstVisibleNode;
     421        while (node != null && node.NextVisibleNode != null) node = node.NextVisibleNode;
     422        return node;
     423      }
     424    }
     425
     426    private class ItemTreeNodeComparer : IComparer {
     427      public int Compare(object x, object y) {
     428        var lhs = (TreeNode)x;
     429        var rhs = (TreeNode)y;
     430
     431        if (lhs.Tag is string && rhs.Tag is string) {
     432          return lhs.Name.CompareTo(rhs.Name);
     433        } else if (lhs.Tag is string) {
     434          return -1;
     435        } else
     436          return 1;
     437      }
     438    }
    100439  }
    101440}
Note: See TracChangeset for help on using the changeset viewer.