1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 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 |
|
---|
22 | using System;
|
---|
23 | using System.Windows;
|
---|
24 | using System.Windows.Controls;
|
---|
25 | using ICSharpCode.AvalonEdit.CodeCompletion;
|
---|
26 | using ICSharpCode.NRefactory.Completion;
|
---|
27 | using ICSharpCode.NRefactory.CSharp;
|
---|
28 | using ICSharpCode.NRefactory.TypeSystem;
|
---|
29 | using ICSharpCode.NRefactory.Xml;
|
---|
30 |
|
---|
31 | namespace 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 | }
|
---|