Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2922-DataCompletenessChartPerf/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CompletionData/EntityCompletionData.cs @ 18242

Last change on this file since 18242 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 2.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Windows;
24using System.Windows.Controls;
25using ICSharpCode.AvalonEdit.CodeCompletion;
26using ICSharpCode.NRefactory.Completion;
27using ICSharpCode.NRefactory.CSharp;
28using ICSharpCode.NRefactory.TypeSystem;
29using ICSharpCode.NRefactory.Xml;
30
31namespace HeuristicLab.CodeEditor {
32  internal class EntityCompletionData : CompletionData, IEntityCompletionData {
33    private static readonly CSharpAmbience Ambience = new CSharpAmbience();
34
35    #region IEntityCompletionData Members
36    public IEntity Entity { get; private set; }
37    #endregion
38
39    public EntityCompletionData(IEntity entity)
40      : base() {
41      if (entity == null) throw new ArgumentException("entity");
42
43      Entity = entity;
44      Ambience.ConversionFlags = entity is ITypeDefinition ? ConversionFlags.ShowTypeParameterList : ConversionFlags.None;
45      CompletionText = DisplayText = entity.Name;
46      Image = CompletionImage.GetImage(entity);
47    }
48
49    protected override object CreateFancyDescription() {
50      var ambience = new CSharpAmbience();
51      ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowDeclaringType;
52      string header = ambience.ConvertSymbol(Entity);
53      var documentation = XmlDocumentationElement.Get(Entity);
54
55      ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList;
56      var b = new CSharpDocumentationBuilder(ambience);
57      b.AddCodeBlock(header, keepLargeMargin: true);
58      if (documentation != null) {
59        foreach (var child in documentation.Children) {
60          b.AddDocumentationElement(child);
61        }
62      }
63
64      var flowDocument = b.CreateFlowDocument();
65      flowDocument.PagePadding = new Thickness(0); // default is NOT Thickness(0), but Thickness(Auto), which adds unnecessary space
66
67      return new FlowDocumentScrollViewer {
68        Document = flowDocument,
69        VerticalScrollBarVisibility = ScrollBarVisibility.Auto
70      };
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.