Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/26/11 15:11:48 (13 years ago)
Author:
mkommend
Message:

#1479: Corrected handling of GroupSymbols.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.cs

    r6285 r6299  
    100100    private void RebuildSymbolsTreeView() {
    101101      symbolsTreeView.Nodes.Clear();
    102       var start = new TreeNode();
    103       var symbols = new DummySymbol("Symbols");
    104       start.Name = "Symbols";
    105       start.Text = "Symbols";
    106       start.Tag = symbols;
    107       start.Checked = true;
    108       symbolsTreeView.Nodes.Add(start);
     102      var symbols = Content.Symbols.ToList();
     103      var groupSymbols = symbols.OfType<GroupSymbol>().ToList();
     104      var topLevelSymbols = Content.Symbols.Where(s => !groupSymbols.Any(g => g.Symbols.Contains(s)));
     105      AddChildTreeNodes(symbolsTreeView.Nodes, topLevelSymbols);
    109106
    110       foreach (ISymbol symbol in Content.Symbols.Where(s => !(s is IReadOnlySymbol))) {
     107      RebuildImageList();
     108      symbolsTreeView.ExpandAll();
     109    }
     110
     111    private void AddChildTreeNodes(TreeNodeCollection collection, IEnumerable<ISymbol> symbols) {
     112      foreach (ISymbol symbol in symbols) {
    111113        var node = new TreeNode();
    112114        node.Name = symbol.Name;
    113115        node.Text = symbol.Name;
    114116        node.Tag = symbol;
    115         node.Checked = !symbol.InitialFrequency.IsAlmost(0.0);
    116         start.Nodes.Add(node);
     117        node.Checked = symbol.Enabled;
     118        collection.Add(node);
     119        var groupSymbol = symbol as GroupSymbol;
     120        if (groupSymbol != null) AddChildTreeNodes(node.Nodes, groupSymbol.Symbols);
    117121      }
    118       RebuildImageList();
    119       symbolsTreeView.ExpandAll();
    120122    }
    121123
     
    134136      if (e.Action != TreeViewAction.Unknown) {
    135137        DeregisterContentEvents();
    136         foreach (var symbol in IterateTreeNodes(e.Node).Select(n => n.Tag).OfType<ISymbol>()) {
    137           if (e.Node.Checked) symbol.InitialFrequency = 1.0;
    138           else symbol.InitialFrequency = 0.0;
    139         }
     138        var symbol = (ISymbol)e.Node.Tag;
     139        symbol.Enabled = e.Node.Checked;
    140140        RegisterContentEvents();
    141141        Content_Changed(Content, EventArgs.Empty);
     
    176176    protected virtual void RebuildImageList() {
    177177      symbolsTreeView.ImageList.Images.Clear();
    178       foreach (TreeNode treeNode in symbolsTreeView.Nodes) {
     178      foreach (TreeNode treeNode in IterateTreeNodes()) {
    179179        var symbol = (ISymbol)treeNode.Tag;
    180180        symbolsTreeView.ImageList.Images.Add(symbol == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : symbol.ItemImage);
     
    183183    }
    184184  }
     185    #endregion
    185186
    186187  [NonDiscoverableType]
     
    190191    public override IDeepCloneable Clone(Cloner cloner) { return new DummySymbol(this, cloner); }
    191192  }
    192 
    193     #endregion
    194193}
Note: See TracChangeset for help on using the changeset viewer.