Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.CodeEditor/3.4/LanguageFeatures/CodeCompletion/CSharp/CompletionData/EntityCompletionData.cs

Last change on this file was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 2.8 KB
RevLine 
[11700]1#region License Information
2/* HeuristicLab
[17181]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[11700]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;
[11804]23using System.Windows;
24using System.Windows.Controls;
[11700]25using ICSharpCode.AvalonEdit.CodeCompletion;
26using ICSharpCode.NRefactory.Completion;
27using ICSharpCode.NRefactory.CSharp;
28using ICSharpCode.NRefactory.TypeSystem;
[11804]29using ICSharpCode.NRefactory.Xml;
[11700]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;
[11802]45      CompletionText = DisplayText = entity.Name;
[11700]46      Image = CompletionImage.GetImage(entity);
47    }
48
[11804]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);
[11700]54
[11804]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);
[11700]61        }
62      }
63
[11804]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      };
[11700]71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.