├── .gitattributes
├── Documentation
├── icons
│ └── Help.png
├── Media
│ ├── VisualTree.png
│ ├── RenderingPipeline.png
│ ├── WelcomeScreenshot.png
│ └── NamespaceDependencies.png
├── ICSharpCode.AvalonEdit.content
├── License.html
└── Architecture.aml
├── global.json
├── ICSharpCode.AvalonEdit
├── Search
│ ├── next.png
│ ├── prev.png
│ └── Localization.cs
├── themes
│ ├── RightArrow.cur
│ └── generic.xaml
├── ICSharpCode.AvalonEdit.snk
├── AvalonEditNuGetPackageIcon.png
├── Highlighting
│ ├── Resources
│ │ ├── ASPX.xshd
│ │ ├── Patch-Mode.xshd
│ │ ├── MarkDown-Mode.xshd
│ │ ├── CSS-Mode.xshd
│ │ ├── XmlDoc.xshd
│ │ ├── Json.xshd
│ │ ├── XML-Mode.xshd
│ │ └── MarkDownWithFontSize-Mode.xshd
│ ├── IHighlightingDefinitionReferenceResolver.cs
│ ├── Xshd
│ │ ├── XshdImport.cs
│ │ ├── XshdElement.cs
│ │ ├── XshdProperty.cs
│ │ ├── XshdRule.cs
│ │ ├── IXshdVisitor.cs
│ │ ├── XshdKeywords.cs
│ │ ├── XshdSyntaxDefinition.cs
│ │ └── XshdRuleSet.cs
│ ├── HighlightingRule.cs
│ ├── HighlightedSection.cs
│ ├── HighlightingRuleSet.cs
│ ├── RichTextColorizer.cs
│ ├── HighlightingDefinitionInvalidException.cs
│ ├── IHighlightingDefinition.cs
│ └── HtmlOptions.cs
├── Properties
│ └── CodeAnalysisDictionary.xml
├── Utils
│ ├── Constants.cs
│ ├── Empty.cs
│ ├── Boxes.cs
│ ├── PropertyChangedWeakEventManager.cs
│ ├── NullSafeCollection.cs
│ ├── DelayedEvents.cs
│ └── ThrowUtil.cs
├── Rendering
│ ├── IVisualLineTransformer.cs
│ ├── ITextViewConnect.cs
│ ├── IBackgroundRenderer.cs
│ ├── VisualLineConstructionStartEventArgs.cs
│ ├── Layer.cs
│ ├── SimpleTextSource.cs
│ ├── GlobalTextRunProperties.cs
│ ├── VisualLineTextParagraphProperties.cs
│ ├── HeightTreeLineNode.cs
│ ├── VisualLinesInvalidException.cs
│ ├── TextViewCachedElements.cs
│ ├── VisualYPosition.cs
│ ├── ITextRunConstructionContext.cs
│ └── ColumnRulerRenderer.cs
├── Snippets
│ ├── SnippetElement.cs
│ ├── SnippetTextElement.cs
│ ├── IActiveElement.cs
│ ├── SnippetContainerElement.cs
│ ├── SnippetSelectionElement.cs
│ ├── SnippetEventArgs.cs
│ ├── Snippet.cs
│ └── SnippetCaretElement.cs
├── Document
│ ├── IUndoableOperation.cs
│ ├── DocumentChangeOperation.cs
│ └── UndoOperationGroup.cs
├── Indentation
│ ├── IIndentationStrategy.cs
│ └── DefaultIndentationStrategy.cs
├── CodeCompletion
│ ├── IOverloadProvider.cs
│ ├── CompletionList.xaml
│ └── OverloadInsightWindow.cs
├── Editing
│ ├── CaretWeakEventHandler.cs
│ ├── MouseSelectionMode.cs
│ ├── IReadOnlySectionProvider.cs
│ ├── DragDropException.cs
│ ├── DottedLineMargin.cs
│ ├── NoReadOnlySections.cs
│ └── SelectionLayer.cs
├── TextEditorComponent.cs
├── TextEditorWeakEventManager.cs
└── Folding
│ └── NewFolding.cs
├── ICSharpCode.AvalonEdit.Sample
├── Images
│ ├── Cut.png
│ ├── Copy.png
│ ├── Delete.png
│ ├── Open.png
│ ├── Paste.png
│ ├── Redo.png
│ ├── Save.png
│ ├── Undo.png
│ └── WordWrap.png
├── AvalonEdit
│ ├── folding.png
│ ├── snoop.png
│ ├── dependencies.png
│ ├── screenshot.png
│ └── renderingPipeline.png
├── RenderingPipeline.pptx
├── app.net35.config
├── app.config
├── App.xaml
├── Properties
│ ├── AssemblyInfo.cs
│ └── WPFAssemblyInfo.cs
├── CustomHighlighting.xshd
├── App.xaml.cs
├── ICSharpCode.AvalonEdit.Sample.csproj
├── MyCompletionData.cs
└── ColorizeAvalonEdit.cs
├── ICSharpCode.AvalonEdit.Tests
├── ICSharpCode.AvalonEdit.Tests.PartCover.Settings
├── Highlighting
│ ├── DeserializationTests.cs
│ ├── RichTextTests.cs
│ └── HtmlClipboardTests.cs
├── Properties
│ └── AssemblyInfo.cs
├── ICSharpCode.AvalonEdit.Tests.csproj
├── Utils
│ ├── ExtensionMethodsTests.cs
│ └── IndentationStringTests.cs
└── MultipleUIThreads.cs
├── BuildTools
└── tidy.py
├── ThirdParty-Highlightings
├── README.md
└── CLLE.xshd
├── LICENSE
├── ICSharpCode.AvalonEdit.Documentation.sln
├── README.md
├── .github
└── workflows
│ └── dotnet.yml
└── ICSharpCode.AvalonEdit.sln
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.cs text diff=csharp
2 | *.sln text eol=crlf
3 | *.csproj text eol=crlf
4 |
--------------------------------------------------------------------------------
/Documentation/icons/Help.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/Documentation/icons/Help.png
--------------------------------------------------------------------------------
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "sdk": {
3 | "version": "5.0.100",
4 | "rollForward": "latestFeature"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/Documentation/Media/VisualTree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/Documentation/Media/VisualTree.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Search/next.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit/Search/next.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Search/prev.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit/Search/prev.png
--------------------------------------------------------------------------------
/Documentation/Media/RenderingPipeline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/Documentation/Media/RenderingPipeline.png
--------------------------------------------------------------------------------
/Documentation/Media/WelcomeScreenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/Documentation/Media/WelcomeScreenshot.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/Images/Cut.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Cut.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/themes/RightArrow.cur:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit/themes/RightArrow.cur
--------------------------------------------------------------------------------
/Documentation/Media/NamespaceDependencies.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/Documentation/Media/NamespaceDependencies.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/Images/Copy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Copy.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/Images/Delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Delete.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/Images/Open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Open.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/Images/Paste.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Paste.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/Images/Redo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Redo.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/Images/Save.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Save.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/Images/Undo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/Images/Undo.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/Images/WordWrap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/Images/WordWrap.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.snk
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/AvalonEdit/folding.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/AvalonEdit/folding.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/AvalonEdit/snoop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/AvalonEdit/snoop.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/RenderingPipeline.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/RenderingPipeline.pptx
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/AvalonEditNuGetPackageIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit/AvalonEditNuGetPackageIcon.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/AvalonEdit/dependencies.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/AvalonEdit/dependencies.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/AvalonEdit/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/AvalonEdit/screenshot.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Tests/ICSharpCode.AvalonEdit.Tests.PartCover.Settings:
--------------------------------------------------------------------------------
1 |
2 | +[ICSharpCode.AvalonEdit]*
3 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/AvalonEdit/renderingPipeline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dorisoy/AvalonEdit/HEAD/ICSharpCode.AvalonEdit.Sample/AvalonEdit/renderingPipeline.png
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/app.net35.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/App.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | #region Using directives
2 |
3 | using System;
4 | using System.Reflection;
5 | using System.Runtime.InteropServices;
6 |
7 | #endregion
8 |
9 | // This sets the default COM visibility of types in the assembly to invisible.
10 | // If you need to expose a type to COM, use [ComVisible(true)] on that type.
11 | [assembly: ComVisible(false)]
12 |
--------------------------------------------------------------------------------
/Documentation/ICSharpCode.AvalonEdit.content:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Resources/ASPX.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | <%
9 | %>
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/BuildTools/tidy.py:
--------------------------------------------------------------------------------
1 | import os, sys
2 |
3 | def check(filename):
4 | ok = True
5 | with open(filename, 'r') as f:
6 | for i, line in enumerate(f):
7 | if line.startswith(' '):
8 | print('{}:{}: Line starting with spaces. Use tabs for indentation instead!'.format(filename, i+1))
9 | ok = False
10 | return ok
11 |
12 | def main():
13 | dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
14 | ok = True
15 | for root, dirs, files in os.walk(dir):
16 | if '\\obj\\' in root:
17 | continue
18 | for filename in files:
19 | if filename.lower().endswith('.cs') or filename.lower().endswith('.xaml'):
20 | if not check(os.path.join(root, filename)):
21 | ok = False
22 | print('Tidy check: {}'.format('successful' if ok else 'failed'))
23 | return 0 if ok else 1
24 |
25 | if __name__ == '__main__':
26 | sys.exit(main())
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Tests/Highlighting/DeserializationTests.cs:
--------------------------------------------------------------------------------
1 | using ICSharpCode.AvalonEdit.Document;
2 | using ICSharpCode.AvalonEdit.Highlighting;
3 | using Newtonsoft.Json;
4 | using NUnit.Framework;
5 |
6 |
7 | namespace ICSharpCode.AvalonEdit.Tests.Highlighting
8 | {
9 | [TestFixture]
10 | public class DeserializationTests
11 | {
12 | TextDocument document;
13 | DocumentHighlighter highlighter;
14 |
15 | [SetUp]
16 | public void SetUp()
17 | {
18 | document = new TextDocument("using System.Text;\n\tstring text = SomeMethod();");
19 | highlighter = new DocumentHighlighter(document, HighlightingManager.Instance.GetDefinition("C#"));
20 | }
21 |
22 | [Test]
23 | public void TestRoundTripColor()
24 | {
25 | HighlightingColor color = highlighter.GetNamedColor("Comment");
26 | string jsonString = JsonConvert.SerializeObject(color);
27 |
28 | HighlightingColor color2 = JsonConvert.DeserializeObject(jsonString);
29 | Assert.AreEqual(color, color2);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/themes/generic.xaml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
--------------------------------------------------------------------------------
/ThirdParty-Highlightings/README.md:
--------------------------------------------------------------------------------
1 | Third-Party Highlighting Definitions for AvalonEdit
2 | ==================================================
3 |
4 | These custom highlighting definitions have been provided by the community.
5 | We are sharing them here, because we cannot include every possible language in the AvalonEdit bundle.
6 |
7 | If you want your highlighting included, please open a pull request.
8 |
9 | * [RPG](https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/rbam6/rbam6clmain.htm) see RPGLE.xshd (provided by @worksofliam in #144)
10 | * [CLLE](https://www.ibm.com/developerworks/ibmi/library/i-ibmi-rpg-support/index.html) see CLLE.xshd (provided by @worksofliam in #144)
11 |
12 | Highlighting Definitions found in other locations
13 | ------------------------------------------------
14 |
15 | * Assembler highlighting (shipping with ILSpy): https://github.com/icsharpcode/ILSpy/blob/master/ILSpy/TextView/Asm-Mode.xshd
16 | * MSIL highlighting (shipping with ILSpy): https://github.com/icsharpcode/ILSpy/blob/master/ILSpy/TextView/ILAsm-Mode.xshd
17 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Properties/CodeAnalysisDictionary.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uncollapse
7 | Foldings
8 | Xshd
9 | Utils
10 | Deque
11 | Colorizer
12 | Renderer
13 | Renderers
14 | Deletable
15 |
16 | y
17 |
18 |
19 |
20 | Lineup
21 |
22 |
23 |
24 | Bestest
25 |
26 |
27 |
28 |
29 |
30 | WiX
31 |
32 |
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) AvalonEdit Contributors
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/Properties/WPFAssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | #region Using directives
2 |
3 | using System.Resources;
4 | using System.Windows;
5 |
6 | #endregion
7 |
8 |
9 |
10 | //In order to begin building localizable applications, set
11 | //CultureYouAreCodingWith in your .csproj file
12 | //inside a . For example, if you are using US english
13 | //in your source files, set the to en-US. Then uncomment
14 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
15 | //the line below to match the UICulture setting in the project file.
16 |
17 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
18 |
19 |
20 | [assembly: ThemeInfo(
21 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
22 | //(used if a resource is not found in the page,
23 | // or application resource dictionaries)
24 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
25 | //(used if a resource is not found in the page,
26 | // app, or any theme specific resource dictionaries)
27 | )]
28 |
--------------------------------------------------------------------------------
/ThirdParty-Highlightings/CLLE.xshd:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | '
12 | '
13 |
14 |
15 |
16 | /\*
17 | \*/
18 |
19 |
20 |
21 |
22 | \b0[xX][0-9a-fA-F]+ # hex number
23 | | \b
24 | ( \d+(\.[0-9]+)? #number with optional floating point
25 | | \.[0-9]+ #or just starting with floating point
26 | )
27 | ([eE][+-]?[0-9]+)? # optional exponent
28 |
29 |
30 |
31 | (\w+)
32 |
33 |
34 |
35 | \B[\%\&]\w+
36 |
37 |
38 |
39 |
40 | \B\*\w+
41 |
42 |
43 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Resources/Patch-Mode.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Index:\s
12 |
13 |
14 | ==
15 |
16 |
17 | ---
18 |
19 |
20 | \+\+\+
21 |
22 |
23 | @@
24 |
25 |
26 | -
27 |
28 |
29 | \+
30 |
31 |
32 | \s
33 |
34 |
35 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/CustomHighlighting.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | "
13 | "
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | if
22 | else
23 |
24 |
25 |
26 |
27 | AvalonEdit
28 |
29 |
30 |
31 |
32 | \b0[xX][0-9a-fA-F]+ # hex number
33 | | \b
34 | ( \d+(\.[0-9]+)? #number with optional floating point
35 | | \.[0-9]+ #or just starting with floating point
36 | )
37 | ([eE][+-]?[0-9]+)? # optional exponent
38 |
39 |
40 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Utils/Constants.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.AvalonEdit.Utils
20 | {
21 | static class Constants
22 | {
23 | ///
24 | /// Multiply with this constant to convert from points to device-independent pixels.
25 | ///
26 | public const double PixelPerPoint = 4 / 3.0;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Documentation/License.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | License
5 |
6 |
7 |
8 |
9 |
10 |
The MIT License (MIT)
11 |
12 |
13 | Permission is hereby granted, free of charge, to any person obtaining a copy
14 | of this software and associated documentation files (the "Software"), to deal
15 | in the Software without restriction, including without limitation the rights
16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 | copies of the Software, and to permit persons to whom the Software is
18 | furnished to do so, subject to the following conditions:
19 |
20 |
21 | The above copyright notice and this permission notice shall be included in
22 | all copies or substantial portions of the Software.
23 |
24 |
25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31 | THE SOFTWARE.
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Utils/Empty.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.AvalonEdit.Utils
20 | {
21 | ///
22 | /// Provides immutable empty list instances.
23 | ///
24 | static class Empty
25 | {
26 | public static readonly T[] Array = new T[0];
27 | //public static readonly ReadOnlyCollection ReadOnlyCollection = new ReadOnlyCollection(Array);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/App.xaml.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2009 Daniel Grunwald
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Windows;
21 | using System.Data;
22 | using System.Xml;
23 | using System.Configuration;
24 |
25 | namespace ICSharpCode.AvalonEdit.Sample
26 | {
27 | ///
28 | /// Interaction logic for App.xaml
29 | ///
30 | public partial class App : Application
31 | {
32 | public App()
33 | {
34 | InitializeComponent();
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Utils/Boxes.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.AvalonEdit.Utils
20 | {
21 | ///
22 | /// Reuse the same instances for boxed booleans.
23 | ///
24 | static class Boxes
25 | {
26 | public static readonly object True = true;
27 | public static readonly object False = false;
28 |
29 | public static object Box(bool value)
30 | {
31 | return value ? True : False;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Reflection;
21 | using System.Runtime.InteropServices;
22 | using System.Threading;
23 | using NUnit.Framework;
24 |
25 | // This sets the default COM visibility of types in the assembly to invisible.
26 | // If you need to expose a type to COM, use [ComVisible(true)] on that type.
27 | [assembly: ComVisible(false)]
28 |
29 | #if !NETCOREAPP
30 | // Run unit tests on STA thread.
31 | [assembly: Apartment(ApartmentState.STA)]
32 | #endif
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/IHighlightingDefinitionReferenceResolver.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.AvalonEdit.Highlighting
20 | {
21 | ///
22 | /// Interface for resolvers that can solve cross-definition references.
23 | ///
24 | public interface IHighlightingDefinitionReferenceResolver
25 | {
26 | ///
27 | /// Gets the highlighting definition by name, or null if it is not found.
28 | ///
29 | IHighlightingDefinition GetDefinition(string name);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Rendering/IVisualLineTransformer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Collections.Generic;
20 |
21 | namespace ICSharpCode.AvalonEdit.Rendering
22 | {
23 | ///
24 | /// Allows transforming visual line elements.
25 | ///
26 | public interface IVisualLineTransformer
27 | {
28 | ///
29 | /// Applies the transformation to the specified list of visual line elements.
30 | ///
31 | void Transform(ITextRunConstructionContext context, IList elements);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Tests/ICSharpCode.AvalonEdit.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Library
4 | net5.0-windows;netcoreapp3.1;net40;net45
5 | true
6 | true
7 | TRACE
8 | true
9 | ..\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.snk
10 | ic#code
11 | 2000-2021 AlphaSierraPapa for the SharpDevelop Team
12 | Tests for WPF-based extensible text editor
13 | false
14 |
15 |
16 |
17 | TRACE
18 |
19 |
20 | TRACE
21 |
22 |
23 | TRACE
24 |
25 |
26 | TRACE
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdImport.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
22 | {
23 | ///
24 | /// <Import> element.
25 | ///
26 | [Serializable]
27 | public class XshdImport : XshdElement
28 | {
29 | ///
30 | /// Gets/sets the referenced rule set.
31 | ///
32 | public XshdReference RuleSetReference { get; set; }
33 |
34 | ///
35 | public override object AcceptVisitor(IXshdVisitor visitor)
36 | {
37 | return visitor.VisitImport(this);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Documentation.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.28714.193
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.AvalonEdit", "ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj", "{417F2A81-E1C2-4366-B24B-C5DC8F958844}"
7 | EndProject
8 | Project("{7CF6DF6D-3B04-46F8-A40B-537D21BCA0B4}") = "ICSharpCode.AvalonEdit.Documentation", "Documentation\ICSharpCode.AvalonEdit.Documentation.shfbproj", "{850B6602-0A7F-413A-864A-E816B98D7407}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {850B6602-0A7F-413A-864A-E816B98D7407}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {850B6602-0A7F-413A-864A-E816B98D7407}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {850B6602-0A7F-413A-864A-E816B98D7407}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {850B6602-0A7F-413A-864A-E816B98D7407}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {919F9316-235F-49C8-868A-F0C8B9063F56}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Snippets/SnippetElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Windows.Documents;
21 |
22 | namespace ICSharpCode.AvalonEdit.Snippets
23 | {
24 | ///
25 | /// An element inside a snippet.
26 | ///
27 | [Serializable]
28 | public abstract class SnippetElement
29 | {
30 | ///
31 | /// Performs insertion of the snippet.
32 | ///
33 | public abstract void Insert(InsertionContext context);
34 |
35 | ///
36 | /// Converts the snippet to text, with replaceable fields in italic.
37 | ///
38 | public virtual Inline ToTextRun()
39 | {
40 | return null;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Document/IUndoableOperation.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.AvalonEdit.Document
20 | {
21 | ///
22 | /// This Interface describes a the basic Undo/Redo operation
23 | /// all Undo Operations must implement this interface.
24 | ///
25 | public interface IUndoableOperation
26 | {
27 | ///
28 | /// Undo the last operation
29 | ///
30 | void Undo();
31 |
32 | ///
33 | /// Redo the last operation
34 | ///
35 | void Redo();
36 | }
37 |
38 | interface IUndoableOperationWithContext : IUndoableOperation
39 | {
40 | void Undo(UndoStack stack);
41 | void Redo(UndoStack stack);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Rendering/ITextViewConnect.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.AvalonEdit.Rendering
20 | {
21 | ///
22 | /// Allows s, s and
23 | /// s to be notified when they are added or removed from a text view.
24 | ///
25 | public interface ITextViewConnect
26 | {
27 | ///
28 | /// Called when added to a text view.
29 | ///
30 | void AddToTextView(TextView textView);
31 |
32 | ///
33 | /// Called when removed from a text view.
34 | ///
35 | void RemoveFromTextView(TextView textView);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/ICSharpCode.AvalonEdit.Sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | WinExe
4 | net5.0-windows;netcoreapp3.1;net472
5 | true
6 | true
7 | TRACE
8 | true
9 | ..\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.snk
10 | AvalonEdit.Sample
11 | ic#code
12 | 2000-2021 AlphaSierraPapa for the SharpDevelop Team
13 | Sample for WPF-based extensible text editor
14 | false
15 |
16 |
17 |
18 | TRACE
19 |
20 |
21 | TRACE
22 |
23 |
24 | TRACE
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
22 | {
23 | ///
24 | /// An element in a XSHD rule set.
25 | ///
26 | [Serializable]
27 | public abstract class XshdElement
28 | {
29 | ///
30 | /// Gets the line number in the .xshd file.
31 | ///
32 | public int LineNumber { get; set; }
33 |
34 | ///
35 | /// Gets the column number in the .xshd file.
36 | ///
37 | public int ColumnNumber { get; set; }
38 |
39 | ///
40 | /// Applies the visitor to this element.
41 | ///
42 | public abstract object AcceptVisitor(IXshdVisitor visitor);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/HighlightingRule.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Text.RegularExpressions;
21 |
22 | namespace ICSharpCode.AvalonEdit.Highlighting
23 | {
24 | ///
25 | /// A highlighting rule.
26 | ///
27 | [Serializable]
28 | public class HighlightingRule
29 | {
30 | ///
31 | /// Gets/Sets the regular expression for the rule.
32 | ///
33 | public Regex Regex { get; set; }
34 |
35 | ///
36 | /// Gets/Sets the highlighting color.
37 | ///
38 | public HighlightingColor Color { get; set; }
39 |
40 | ///
41 | public override string ToString()
42 | {
43 | return "[" + GetType().Name + " " + Regex + "]";
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Indentation/IIndentationStrategy.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using ICSharpCode.AvalonEdit.Document;
20 |
21 | namespace ICSharpCode.AvalonEdit.Indentation
22 | {
23 | ///
24 | /// Strategy how the text editor handles indentation when new lines are inserted.
25 | ///
26 | public interface IIndentationStrategy
27 | {
28 | ///
29 | /// Sets the indentation for the specified line.
30 | /// Usually this is constructed from the indentation of the previous line.
31 | ///
32 | void IndentLine(TextDocument document, DocumentLine line);
33 |
34 | ///
35 | /// Reindents a set of lines.
36 | ///
37 | void IndentLines(TextDocument document, int beginLine, int endLine);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Utils/PropertyChangedWeakEventManager.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.ComponentModel;
20 |
21 | namespace ICSharpCode.AvalonEdit.Utils
22 | {
23 | ///
24 | /// WeakEventManager for INotifyPropertyChanged.PropertyChanged.
25 | ///
26 | public sealed class PropertyChangedWeakEventManager : WeakEventManagerBase
27 | {
28 | ///
29 | protected override void StartListening(INotifyPropertyChanged source)
30 | {
31 | source.PropertyChanged += DeliverEvent;
32 | }
33 |
34 | ///
35 | protected override void StopListening(INotifyPropertyChanged source)
36 | {
37 | source.PropertyChanged -= DeliverEvent;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Tests/Utils/ExtensionMethodsTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using NUnit.Framework;
21 |
22 | namespace ICSharpCode.AvalonEdit.Utils
23 | {
24 | [TestFixture]
25 | public class ExtensionMethodsTests
26 | {
27 | [Test]
28 | public void ZeroIsNotCloseToOne()
29 | {
30 | Assert.IsFalse(0.0.IsClose(1));
31 | }
32 |
33 | [Test]
34 | public void ZeroIsCloseToZero()
35 | {
36 | Assert.IsTrue(0.0.IsClose(0));
37 | }
38 |
39 | [Test]
40 | public void InfinityIsCloseToInfinity()
41 | {
42 | Assert.IsTrue(double.PositiveInfinity.IsClose(double.PositiveInfinity));
43 | }
44 |
45 | [Test]
46 | public void NaNIsNotCloseToNaN()
47 | {
48 | Assert.IsFalse(double.NaN.IsClose(double.NaN));
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Rendering/IBackgroundRenderer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Windows.Media;
20 |
21 | namespace ICSharpCode.AvalonEdit.Rendering
22 | {
23 | ///
24 | /// Background renderers draw in the background of a known layer.
25 | /// You can use background renderers to draw non-interactive elements on the TextView
26 | /// without introducing new UIElements.
27 | ///
28 | public interface IBackgroundRenderer
29 | {
30 | ///
31 | /// Gets the layer on which this background renderer should draw.
32 | ///
33 | KnownLayer Layer { get; }
34 |
35 | ///
36 | /// Causes the background renderer to draw.
37 | ///
38 | void Draw(TextView textView, DrawingContext drawingContext);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Resources/MarkDown-Mode.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | ^\#.*
15 |
16 |
17 | \*\*.*\*\*
18 |
19 |
20 | __.*__
21 |
22 |
23 | \*(?![ ]).*\*
24 |
25 |
26 | _.*_
27 |
28 |
29 | `.*`
30 |
31 |
32 | ^\t
33 | ^(?!\t)
34 |
35 |
36 | ^[ ]{4}
37 | ^(?![ ]{4})
38 |
39 |
40 | ^>
41 | ^(?!>)
42 |
43 |
44 | \!\[.*\]\[.*\]
45 |
46 |
47 | \[.*\]\(.*\)
48 |
49 |
50 | \[.*\]\[.*\]
51 |
52 |
53 | [ ]{2}$
54 |
55 |
56 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Utils/NullSafeCollection.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Collections.ObjectModel;
21 |
22 | namespace ICSharpCode.AvalonEdit.Utils
23 | {
24 | ///
25 | /// A collection that cannot contain null values.
26 | ///
27 | [Serializable]
28 | public class NullSafeCollection : Collection where T : class
29 | {
30 | ///
31 | protected override void InsertItem(int index, T item)
32 | {
33 | if (item == null)
34 | throw new ArgumentNullException("item");
35 | base.InsertItem(index, item);
36 | }
37 |
38 | ///
39 | protected override void SetItem(int index, T item)
40 | {
41 | if (item == null)
42 | throw new ArgumentNullException("item");
43 | base.SetItem(index, item);
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Documentation/Architecture.aml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
14 |
15 |
16 | As you can see in this dependency graph, AvalonEdit consists of a few
17 | sub-namespaces that have cleanly separated jobs.
18 | Most of the namespaces have a kind of 'main' class.
19 | Here is the visual tree of the TextEditor control:
20 |
21 | It's important to understand that AvalonEdit is a composite control
22 | with the three layers:
23 | T:ICSharpCode.AvalonEdit.TextEditor (main control),
24 | T:ICSharpCode.AvalonEdit.Editing.TextArea (editing),
25 | T:ICSharpCode.AvalonEdit.Rendering.TextView (rendering).
26 |
27 | While the main control provides some convenience methods for common tasks,
28 | for most advanced features you have to work directly with the inner controls.
29 | You can access them using textEditor.TextArea or
30 | textEditor.TextArea.TextView.
31 |
32 |
33 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Resources/CSS-Mode.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | /\*
13 | \*/
14 |
15 |
19 | \{
20 | \}
21 |
22 |
23 | \#
24 | \s
25 |
26 | [\d\w]
27 |
28 |
29 |
30 |
31 | /\*
32 | \*/
33 |
34 |
35 | \:
36 | \;|(?=\})
37 |
38 |
39 | "
40 | "
41 |
42 |
43 |
44 |
45 |
46 | '
47 | '
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Snippets/SnippetTextElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Windows.Documents;
21 |
22 | namespace ICSharpCode.AvalonEdit.Snippets
23 | {
24 | ///
25 | /// Represents a text element in a snippet.
26 | ///
27 | [Serializable]
28 | public class SnippetTextElement : SnippetElement
29 | {
30 | string text;
31 |
32 | ///
33 | /// The text to be inserted.
34 | ///
35 | public string Text {
36 | get { return text; }
37 | set { text = value; }
38 | }
39 |
40 | ///
41 | public override void Insert(InsertionContext context)
42 | {
43 | if (text != null)
44 | context.InsertText(text);
45 | }
46 |
47 | ///
48 | public override Inline ToTextRun()
49 | {
50 | return new Run(text ?? string.Empty);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdProperty.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
22 | {
23 | ///
24 | /// A property in an Xshd file.
25 | ///
26 | [Serializable]
27 | public class XshdProperty : XshdElement
28 | {
29 | ///
30 | /// Gets/sets the name.
31 | ///
32 | public string Name { get; set; }
33 |
34 | ///
35 | /// Gets/sets the value.
36 | ///
37 | public string Value { get; set; }
38 |
39 | ///
40 | /// Creates a new XshdColor instance.
41 | ///
42 | public XshdProperty()
43 | {
44 | }
45 |
46 | ///
47 | public override object AcceptVisitor(IXshdVisitor visitor)
48 | {
49 | return null;
50 | // return visitor.VisitProperty(this);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdRule.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
22 | {
23 | ///
24 | /// <Rule> element.
25 | ///
26 | [Serializable]
27 | public class XshdRule : XshdElement
28 | {
29 | ///
30 | /// Gets/sets the rule regex.
31 | ///
32 | public string Regex { get; set; }
33 |
34 | ///
35 | /// Gets/sets the rule regex type.
36 | ///
37 | public XshdRegexType RegexType { get; set; }
38 |
39 | ///
40 | /// Gets/sets the color reference.
41 | ///
42 | public XshdReference ColorReference { get; set; }
43 |
44 | ///
45 | public override object AcceptVisitor(IXshdVisitor visitor)
46 | {
47 | return visitor.VisitRule(this);
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Xshd/IXshdVisitor.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
20 | {
21 | ///
22 | /// A visitor over the XSHD element tree.
23 | ///
24 | public interface IXshdVisitor
25 | {
26 | /// Visit method for XshdRuleSet
27 | object VisitRuleSet(XshdRuleSet ruleSet);
28 |
29 | /// Visit method for XshdColor
30 | object VisitColor(XshdColor color);
31 |
32 | /// Visit method for XshdKeywords
33 | object VisitKeywords(XshdKeywords keywords);
34 |
35 | /// Visit method for XshdSpan
36 | object VisitSpan(XshdSpan span);
37 |
38 | /// Visit method for XshdImport
39 | object VisitImport(XshdImport import);
40 |
41 | /// Visit method for XshdRule
42 | object VisitRule(XshdRule rule);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Resources/XmlDoc.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | <
11 | >
12 |
13 |
14 | "
15 | "
16 |
17 |
18 | /
19 | |
20 | =
21 |
22 |
23 | c
24 | code
25 | example
26 | exception
27 | list
28 | para
29 | param
30 | paramref
31 | permission
32 | remarks
33 | returns
34 | see
35 | seealso
36 | summary
37 | value
38 |
39 | type
40 | name
41 | cref
42 | item
43 | term
44 | description
45 | listheader
46 | typeparam
47 | typeparamref
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdKeywords.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Collections.Generic;
21 |
22 | using ICSharpCode.AvalonEdit.Utils;
23 |
24 | namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
25 | {
26 | ///
27 | /// A list of keywords.
28 | ///
29 | [Serializable]
30 | public class XshdKeywords : XshdElement
31 | {
32 | ///
33 | /// The color.
34 | ///
35 | public XshdReference ColorReference { get; set; }
36 |
37 | readonly NullSafeCollection words = new NullSafeCollection();
38 |
39 | ///
40 | /// Gets the list of key words.
41 | ///
42 | public IList Words {
43 | get { return words; }
44 | }
45 |
46 | ///
47 | public override object AcceptVisitor(IXshdVisitor visitor)
48 | {
49 | return visitor.VisitKeywords(this);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/CodeCompletion/IOverloadProvider.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.ComponentModel;
20 |
21 | namespace ICSharpCode.AvalonEdit.CodeCompletion
22 | {
23 | ///
24 | /// Provides the items for the OverloadViewer.
25 | ///
26 | public interface IOverloadProvider : INotifyPropertyChanged
27 | {
28 | ///
29 | /// Gets/Sets the selected index.
30 | ///
31 | int SelectedIndex { get; set; }
32 |
33 | ///
34 | /// Gets the number of overloads.
35 | ///
36 | int Count { get; }
37 |
38 | ///
39 | /// Gets the text 'SelectedIndex of Count'.
40 | ///
41 | string CurrentIndexText { get; }
42 |
43 | ///
44 | /// Gets the current header.
45 | ///
46 | object CurrentHeader { get; }
47 |
48 | ///
49 | /// Gets the current content.
50 | ///
51 | object CurrentContent { get; }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Rendering/VisualLineConstructionStartEventArgs.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | using ICSharpCode.AvalonEdit.Document;
22 |
23 | namespace ICSharpCode.AvalonEdit.Rendering
24 | {
25 | ///
26 | /// EventArgs for the event.
27 | ///
28 | public class VisualLineConstructionStartEventArgs : EventArgs
29 | {
30 | ///
31 | /// Gets/Sets the first line that is visible in the TextView.
32 | ///
33 | public DocumentLine FirstLineInView { get; private set; }
34 |
35 | ///
36 | /// Creates a new VisualLineConstructionStartEventArgs instance.
37 | ///
38 | public VisualLineConstructionStartEventArgs(DocumentLine firstLineInView)
39 | {
40 | if (firstLineInView == null)
41 | throw new ArgumentNullException("firstLineInView");
42 | this.FirstLineInView = firstLineInView;
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Editing/CaretWeakEventHandler.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using ICSharpCode.AvalonEdit.Utils;
20 |
21 | namespace ICSharpCode.AvalonEdit.Editing
22 | {
23 | ///
24 | /// Contains classes for handling weak events on the Caret class.
25 | ///
26 | public static class CaretWeakEventManager
27 | {
28 | ///
29 | /// Handles the Caret.PositionChanged event.
30 | ///
31 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
32 | public sealed class PositionChanged : WeakEventManagerBase
33 | {
34 | ///
35 | protected override void StartListening(Caret source)
36 | {
37 | source.PositionChanged += DeliverEvent;
38 | }
39 |
40 | ///
41 | protected override void StopListening(Caret source)
42 | {
43 | source.PositionChanged -= DeliverEvent;
44 | }
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Snippets/IActiveElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using ICSharpCode.AvalonEdit.Document;
20 |
21 | namespace ICSharpCode.AvalonEdit.Snippets
22 | {
23 | ///
24 | /// Represents an active element that allows the snippet to stay interactive after insertion.
25 | ///
26 | public interface IActiveElement
27 | {
28 | ///
29 | /// Called when the all snippet elements have been inserted.
30 | ///
31 | void OnInsertionCompleted();
32 |
33 | ///
34 | /// Called when the interactive mode is deactivated.
35 | ///
36 | void Deactivate(SnippetEventArgs e);
37 |
38 | ///
39 | /// Gets whether this element is editable (the user will be able to select it with Tab).
40 | ///
41 | bool IsEditable { get; }
42 |
43 | ///
44 | /// Gets the segment associated with this element. May be null.
45 | ///
46 | ISegment Segment { get; }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Tests/Highlighting/RichTextTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using NUnit.Framework;
20 |
21 | namespace ICSharpCode.AvalonEdit.Highlighting
22 | {
23 | [TestFixture]
24 | public class RichTextTests
25 | {
26 | [Test]
27 | public void ConcatTest()
28 | {
29 | var textModel = new RichTextModel();
30 | textModel.SetHighlighting(0, 5, new HighlightingColor { Name = "text1" });
31 | var text1 = new RichText("text1", textModel);
32 |
33 | var textModel2 = new RichTextModel();
34 | textModel2.SetHighlighting(0, 5, new HighlightingColor { Name = "text2" });
35 | var text2 = new RichText("text2", textModel2);
36 |
37 | RichText text3 = RichText.Concat(text1, RichText.Empty, text2);
38 | Assert.AreEqual(text1.GetHighlightingAt(0), text3.GetHighlightingAt(0));
39 | Assert.AreNotEqual(text1.GetHighlightingAt(0), text3.GetHighlightingAt(5));
40 | Assert.AreEqual(text2.GetHighlightingAt(0), text3.GetHighlightingAt(5));
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AvalonEdit [](https://nuget.org/packages/AvalonEdit) [](https://github.com/icsharpcode/AvalonEdit/actions/workflows/dotnet.yml)
2 |
3 |
4 | AvalonEdit is the name of the WPF-based text editor in SharpDevelop 4.x "Mirador" and beyond. It is also being used in ILSpy and many other projects.
5 |
6 | Downloads
7 | -------
8 |
9 | AvalonEdit is available as [NuGet package](https://www.nuget.org/packages/AvalonEdit). Usage details, documentation and more
10 | can be found on the [AvalonEdit homepage](http://avalonedit.net/)
11 |
12 | How to build
13 | -------
14 |
15 | AvalonEdit is targeting net5.0-windows, netcoreapp3.1, net40 and net45 TFMs. Because of net5.0-windows you must have the .NET 5.0 SDK installed
16 | on your machine. Visual Studio 2019 16.8 and up is required for working with the solution (global.json will select the proper SDK to use for building for you).
17 |
18 |
19 | Documentation
20 | -------
21 |
22 | Check out the [official documentation](http://avalonedit.net/documentation/) and the [samples and articles wiki page](https://github.com/icsharpcode/AvalonEdit/wiki/Samples-and-Articles)
23 |
24 | To build the Documentation you need to install Sandcastle from https://github.com/EWSoftware/SHFB/releases (currently validated tooling is
25 | v2021.4.9.0)
26 |
27 | The build of the Documentation can take very long, please be patient.
28 |
29 | License
30 | -------
31 |
32 | AvalonEdit is distributed under the [MIT License](http://opensource.org/licenses/MIT).
33 |
34 | Projects using AvalonEdit
35 | -------
36 |
37 | A good place to start are the "top 10" listed under **GitHub Usage** for the [AvalonEdit package](https://www.nuget.org/packages/AvalonEdit) on NuGet.
38 |
39 | * https://github.com/icsharpcode/ILSpy/ ILSpy .NET decompiler
40 | * https://github.com/KirillOsenkov/MSBuildStructuredLog A logger for MSBuild
41 | * https://github.com/aelij/RoslynPad RoslynPad
42 | * https://github.com/huangjia2107/XamlViewer LightWeight Xaml Editor
43 |
44 | Note: if your project is not listed here, let us know! :)
45 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Tests/MultipleUIThreads.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Threading;
21 | using System.Windows;
22 | using NUnit.Framework;
23 |
24 | namespace ICSharpCode.AvalonEdit
25 | {
26 | [TestFixture]
27 | public class MultipleUIThreads
28 | {
29 | Exception error;
30 |
31 | [Test]
32 | public void CreateEditorInstancesOnMultipleUIThreads()
33 | {
34 | Thread t1 = new Thread(new ThreadStart(Run));
35 | Thread t2 = new Thread(new ThreadStart(Run));
36 | t1.SetApartmentState(ApartmentState.STA);
37 | t2.SetApartmentState(ApartmentState.STA);
38 | t1.Start();
39 | t2.Start();
40 | t1.Join();
41 | t2.Join();
42 | if (error != null)
43 | throw new InvalidOperationException(error.Message, error);
44 | }
45 |
46 | [STAThread]
47 | void Run()
48 | {
49 | try {
50 | var window = new Window();
51 | window.Content = new TextEditor();
52 | window.ShowActivated = false;
53 | window.Show();
54 | } catch (Exception ex) {
55 | error = ex;
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/.github/workflows/dotnet.yml:
--------------------------------------------------------------------------------
1 | name: Build AvalonEdit
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 |
9 | jobs:
10 | build:
11 |
12 | runs-on: windows-latest
13 | strategy:
14 | matrix:
15 | Configuration: [ Debug, Release ]
16 | env:
17 | Solution: '**/ICSharpCode.AvalonEdit.sln'
18 | BuildPlatform: 'Any CPU'
19 | BuildVersion: '6.1.2'
20 | steps:
21 | - uses: actions/checkout@v2
22 | - name: Update project version
23 | uses: roryprimrose/set-vs-sdk-project-version@v1
24 | with:
25 | projectFilter: '**/ICSharpCode.AvalonEdit.csproj'
26 | version: ${{ env.BuildVersion }}.${{ github.run_number }}
27 | assemblyVersion: ${{ env.BuildVersion }}.${{ github.run_number }}
28 | fileVersion: ${{ env.BuildVersion }}.${{ github.run_number }}
29 | - name: Setup .NET
30 | uses: actions/setup-dotnet@v1
31 | with:
32 | dotnet-version: 5.0.x
33 | - name: Setup NuGet.exe
34 | uses: nuget/setup-nuget@v1
35 | - run: nuget restore ICSharpCode.AvalonEdit.sln
36 | - name: Build
37 | run: dotnet build ICSharpCode.AvalonEdit.sln --no-restore -c ${{ matrix.configuration }}
38 | - name: Test
39 | run: dotnet test ICSharpCode.AvalonEdit.sln --no-build --verbosity normal -c ${{ matrix.configuration }}
40 | - name: Style - tab check
41 | run: python BuildTools\tidy.py
42 | - name: Pack
43 | run: dotnet pack ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj -c ${{ matrix.configuration }}
44 | - name: Upload NuGet
45 | if: matrix.configuration == 'release'
46 | uses: actions/upload-artifact@v2
47 | with:
48 | name: AvalonEdit NuGet Package (${{ matrix.configuration }})
49 | path: ICSharpCode.AvalonEdit/bin/Release/AvalonEdit*.nupkg
50 | if-no-files-found: error
51 | - name: Publish NuGet
52 | if: github.ref == 'refs/heads/master' && matrix.configuration == 'release'
53 | run: |
54 | dotnet nuget push "ICSharpCode.AvalonEdit\bin\Release\AvalonEdit*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/${{ github.repository_owner }}
55 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Editing/MouseSelectionMode.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.AvalonEdit.Editing
20 | {
21 | ///
22 | /// Enumeration of possible states of mouse selection.
23 | ///
24 | public enum MouseSelectionMode
25 | {
26 | ///
27 | /// no selection (no mouse button down)
28 | ///
29 | None,
30 | ///
31 | /// left mouse button down on selection, might be normal click
32 | /// or might be drag'n'drop
33 | ///
34 | PossibleDragStart,
35 | ///
36 | /// dragging text
37 | ///
38 | Drag,
39 | ///
40 | /// normal selection (click+drag)
41 | ///
42 | Normal,
43 | ///
44 | /// whole-word selection (double click+drag or ctrl+click+drag)
45 | ///
46 | WholeWord,
47 | ///
48 | /// whole-line selection (triple click+drag)
49 | ///
50 | WholeLine,
51 | ///
52 | /// rectangular selection (alt+click+drag)
53 | ///
54 | Rectangular
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/HighlightedSection.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using ICSharpCode.AvalonEdit.Document;
20 |
21 | namespace ICSharpCode.AvalonEdit.Highlighting
22 | {
23 | ///
24 | /// A text section with syntax highlighting information.
25 | ///
26 | public class HighlightedSection : ISegment
27 | {
28 | ///
29 | /// Gets/sets the document offset of the section.
30 | ///
31 | public int Offset { get; set; }
32 |
33 | ///
34 | /// Gets/sets the length of the section.
35 | ///
36 | public int Length { get; set; }
37 |
38 | int ISegment.EndOffset {
39 | get { return this.Offset + this.Length; }
40 | }
41 |
42 | ///
43 | /// Gets the highlighting color associated with the highlighted section.
44 | ///
45 | public HighlightingColor Color { get; set; }
46 |
47 | ///
48 | public override string ToString()
49 | {
50 | return string.Format("[HighlightedSection ({0}-{1})={2}]", Offset, Offset + Length, Color);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Resources/Json.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | "
19 | "
20 |
21 |
22 | '
23 | '
24 |
25 |
26 | :
27 |
28 |
29 | ,
30 |
31 |
32 |
33 |
34 |
35 |
36 | ,
37 |
38 |
39 |
40 |
41 |
42 | true
43 | false
44 |
45 |
46 | null
47 |
48 |
49 | "
50 | "
51 |
52 |
53 | '
54 | '
55 |
56 |
57 | \{
58 | \}
59 |
60 |
61 | \[
62 | \]
63 |
64 |
65 | \b0[xX][0-9a-fA-F]+|(\b\d+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Utils/DelayedEvents.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Collections.Generic;
21 |
22 | namespace ICSharpCode.AvalonEdit.Utils
23 | {
24 | ///
25 | /// Maintains a list of delayed events to raise.
26 | ///
27 | sealed class DelayedEvents
28 | {
29 | struct EventCall
30 | {
31 | EventHandler handler;
32 | object sender;
33 | EventArgs e;
34 |
35 | public EventCall(EventHandler handler, object sender, EventArgs e)
36 | {
37 | this.handler = handler;
38 | this.sender = sender;
39 | this.e = e;
40 | }
41 |
42 | public void Call()
43 | {
44 | handler(sender, e);
45 | }
46 | }
47 |
48 | Queue eventCalls = new Queue();
49 |
50 | public void DelayedRaise(EventHandler handler, object sender, EventArgs e)
51 | {
52 | if (handler != null) {
53 | eventCalls.Enqueue(new EventCall(handler, sender, e));
54 | }
55 | }
56 |
57 | public void RaiseEvents()
58 | {
59 | while (eventCalls.Count > 0)
60 | eventCalls.Dequeue().Call();
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Rendering/Layer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Diagnostics;
20 | using System.Windows;
21 | using System.Windows.Media;
22 |
23 | namespace ICSharpCode.AvalonEdit.Rendering
24 | {
25 | ///
26 | /// Base class for known layers.
27 | ///
28 | class Layer : UIElement
29 | {
30 | protected readonly TextView textView;
31 | protected readonly KnownLayer knownLayer;
32 |
33 | public Layer(TextView textView, KnownLayer knownLayer)
34 | {
35 | Debug.Assert(textView != null);
36 | this.textView = textView;
37 | this.knownLayer = knownLayer;
38 | this.Focusable = false;
39 | }
40 |
41 | protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
42 | {
43 | return null;
44 | }
45 |
46 | protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters)
47 | {
48 | return null;
49 | }
50 |
51 | protected override void OnRender(DrawingContext drawingContext)
52 | {
53 | base.OnRender(drawingContext);
54 | textView.RenderBackground(drawingContext, knownLayer);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Editing/IReadOnlySectionProvider.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Collections.Generic;
20 |
21 | using ICSharpCode.AvalonEdit.Document;
22 |
23 | namespace ICSharpCode.AvalonEdit.Editing
24 | {
25 | ///
26 | /// Determines whether the document can be modified.
27 | ///
28 | public interface IReadOnlySectionProvider
29 | {
30 | ///
31 | /// Gets whether insertion is possible at the specified offset.
32 | ///
33 | bool CanInsert(int offset);
34 |
35 | ///
36 | /// Gets the deletable segments inside the given segment.
37 | ///
38 | ///
39 | /// All segments in the result must be within the given segment, and they must be returned in order
40 | /// (e.g. if two segments are returned, EndOffset of first segment must be less than StartOffset of second segment).
41 | ///
42 | /// For replacements, the last segment being returned will be replaced with the new text. If an empty list is returned,
43 | /// no replacement will be done.
44 | ///
45 | IEnumerable GetDeletableSegments(ISegment segment);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Rendering/SimpleTextSource.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Windows.Media.TextFormatting;
21 |
22 | namespace ICSharpCode.AvalonEdit.Rendering
23 | {
24 | sealed class SimpleTextSource : TextSource
25 | {
26 | readonly string text;
27 | readonly TextRunProperties properties;
28 |
29 | public SimpleTextSource(string text, TextRunProperties properties)
30 | {
31 | this.text = text;
32 | this.properties = properties;
33 | }
34 |
35 | public override TextRun GetTextRun(int textSourceCharacterIndex)
36 | {
37 | if (textSourceCharacterIndex < text.Length)
38 | return new TextCharacters(text, textSourceCharacterIndex, text.Length - textSourceCharacterIndex, properties);
39 | else
40 | return new TextEndOfParagraph(1);
41 | }
42 |
43 | public override int GetTextEffectCharacterIndexFromTextSourceCharacterIndex(int textSourceCharacterIndex)
44 | {
45 | throw new NotImplementedException();
46 | }
47 |
48 | public override TextSpan GetPrecedingText(int textSourceCharacterIndexLimit)
49 | {
50 | throw new NotImplementedException();
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Rendering/GlobalTextRunProperties.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Windows;
20 | using System.Windows.Media;
21 | using System.Windows.Media.TextFormatting;
22 |
23 | namespace ICSharpCode.AvalonEdit.Rendering
24 | {
25 | sealed class GlobalTextRunProperties : TextRunProperties
26 | {
27 | internal Typeface typeface;
28 | internal double fontRenderingEmSize;
29 | internal Brush foregroundBrush;
30 | internal Brush backgroundBrush;
31 | internal System.Globalization.CultureInfo cultureInfo;
32 |
33 | public override Typeface Typeface { get { return typeface; } }
34 | public override double FontRenderingEmSize { get { return fontRenderingEmSize; } }
35 | public override double FontHintingEmSize { get { return fontRenderingEmSize; } }
36 | public override TextDecorationCollection TextDecorations { get { return null; } }
37 | public override Brush ForegroundBrush { get { return foregroundBrush; } }
38 | public override Brush BackgroundBrush { get { return backgroundBrush; } }
39 | public override System.Globalization.CultureInfo CultureInfo { get { return cultureInfo; } }
40 | public override TextEffectCollection TextEffects { get { return null; } }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.28714.193
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.AvalonEdit", "ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj", "{417F2A81-E1C2-4366-B24B-C5DC8F958844}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.AvalonEdit.Sample", "ICSharpCode.AvalonEdit.Sample\ICSharpCode.AvalonEdit.Sample.csproj", "{E506196C-A5E8-4D24-B889-6BA401C0B2B9}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ICSharpCode.AvalonEdit.Tests", "ICSharpCode.AvalonEdit.Tests\ICSharpCode.AvalonEdit.Tests.csproj", "{37CAC89C-C38C-4126-A4A0-91A240A474D7}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {417F2A81-E1C2-4366-B24B-C5DC8F958844}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {E506196C-A5E8-4D24-B889-6BA401C0B2B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {E506196C-A5E8-4D24-B889-6BA401C0B2B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {E506196C-A5E8-4D24-B889-6BA401C0B2B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {E506196C-A5E8-4D24-B889-6BA401C0B2B9}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {37CAC89C-C38C-4126-A4A0-91A240A474D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {37CAC89C-C38C-4126-A4A0-91A240A474D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {37CAC89C-C38C-4126-A4A0-91A240A474D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {37CAC89C-C38C-4126-A4A0-91A240A474D7}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {919F9316-235F-49C8-868A-F0C8B9063F56}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Snippets/SnippetContainerElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Windows.Documents;
22 |
23 | using ICSharpCode.AvalonEdit.Utils;
24 |
25 | namespace ICSharpCode.AvalonEdit.Snippets
26 | {
27 | ///
28 | /// A snippet element that has sub-elements.
29 | ///
30 | [Serializable]
31 | public class SnippetContainerElement : SnippetElement
32 | {
33 | NullSafeCollection elements = new NullSafeCollection();
34 |
35 | ///
36 | /// Gets the list of child elements.
37 | ///
38 | public IList Elements {
39 | get { return elements; }
40 | }
41 |
42 | ///
43 | public override void Insert(InsertionContext context)
44 | {
45 | foreach (SnippetElement e in this.Elements) {
46 | e.Insert(context);
47 | }
48 | }
49 |
50 | ///
51 | public override Inline ToTextRun()
52 | {
53 | Span span = new Span();
54 | foreach (SnippetElement e in this.Elements) {
55 | Inline r = e.ToTextRun();
56 | if (r != null)
57 | span.Inlines.Add(r);
58 | }
59 | return span;
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/MyCompletionData.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2009 Daniel Grunwald
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using ICSharpCode.AvalonEdit.CodeCompletion;
21 | using ICSharpCode.AvalonEdit.Document;
22 | using ICSharpCode.AvalonEdit.Editing;
23 |
24 | namespace ICSharpCode.AvalonEdit.Sample
25 | {
26 | ///
27 | /// Implements AvalonEdit ICompletionData interface to provide the entries in the completion drop down.
28 | ///
29 | public class MyCompletionData : ICompletionData
30 | {
31 | public MyCompletionData(string text)
32 | {
33 | this.Text = text;
34 | }
35 |
36 | public System.Windows.Media.ImageSource Image {
37 | get { return null; }
38 | }
39 |
40 | public string Text { get; private set; }
41 |
42 | // Use this property if you want to show a fancy UIElement in the drop down list.
43 | public object Content {
44 | get { return this.Text; }
45 | }
46 |
47 | public object Description {
48 | get { return "Description for " + this.Text; }
49 | }
50 |
51 | public double Priority { get { return 0; } }
52 |
53 | public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs)
54 | {
55 | textArea.Document.Replace(completionSegment, this.Text);
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Snippets/SnippetSelectionElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Text;
21 |
22 | namespace ICSharpCode.AvalonEdit.Snippets
23 | {
24 | ///
25 | /// Inserts the previously selected text at the selection marker.
26 | ///
27 | [Serializable]
28 | public class SnippetSelectionElement : SnippetElement
29 | {
30 | ///
31 | /// Gets/Sets the new indentation of the selected text.
32 | ///
33 | public int Indentation { get; set; }
34 |
35 | ///
36 | public override void Insert(InsertionContext context)
37 | {
38 | StringBuilder tabString = new StringBuilder();
39 |
40 | for (int i = 0; i < Indentation; i++) {
41 | tabString.Append(context.Tab);
42 | }
43 |
44 | string indent = tabString.ToString();
45 |
46 | string text = context.SelectedText.TrimStart(' ', '\t');
47 |
48 | text = text.Replace(context.LineTerminator,
49 | context.LineTerminator + indent);
50 |
51 | context.Document.Insert(context.InsertionPosition, text);
52 | context.InsertionPosition += text.Length;
53 |
54 | if (string.IsNullOrEmpty(context.SelectedText))
55 | SnippetCaretElement.SetCaret(context);
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/TextEditorComponent.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.ComponentModel;
21 |
22 | using ICSharpCode.AvalonEdit.Document;
23 | using ICSharpCode.AvalonEdit.Editing;
24 | using ICSharpCode.AvalonEdit.Rendering;
25 |
26 | namespace ICSharpCode.AvalonEdit
27 | {
28 | ///
29 | /// Represents a text editor control (,
30 | /// or ).
31 | ///
32 | public interface ITextEditorComponent : IServiceProvider
33 | {
34 | ///
35 | /// Gets the document being edited.
36 | ///
37 | TextDocument Document { get; }
38 |
39 | ///
40 | /// Occurs when the Document property changes (when the text editor is connected to another
41 | /// document - not when the document content changes).
42 | ///
43 | event EventHandler DocumentChanged;
44 |
45 | ///
46 | /// Gets the options of the text editor.
47 | ///
48 | TextEditorOptions Options { get; }
49 |
50 | ///
51 | /// Occurs when the Options property changes, or when an option inside the current option list
52 | /// changes.
53 | ///
54 | event PropertyChangedEventHandler OptionChanged;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Editing/DragDropException.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Runtime.Serialization;
21 |
22 | namespace ICSharpCode.AvalonEdit.Editing
23 | {
24 | ///
25 | /// Wraps exceptions that occur during drag'n'drop.
26 | /// Exceptions during drag'n'drop might
27 | /// get swallowed by WPF/COM, so AvalonEdit catches them and re-throws them later
28 | /// wrapped in a DragDropException.
29 | ///
30 | [Serializable()]
31 | public class DragDropException : Exception
32 | {
33 | ///
34 | /// Creates a new DragDropException.
35 | ///
36 | public DragDropException() : base()
37 | {
38 | }
39 |
40 | ///
41 | /// Creates a new DragDropException.
42 | ///
43 | public DragDropException(string message) : base(message)
44 | {
45 | }
46 |
47 | ///
48 | /// Creates a new DragDropException.
49 | ///
50 | public DragDropException(string message, Exception innerException) : base(message, innerException)
51 | {
52 | }
53 |
54 | ///
55 | /// Deserializes a DragDropException.
56 | ///
57 | protected DragDropException(SerializationInfo info, StreamingContext context) : base(info, context)
58 | {
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/HighlightingRuleSet.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Collections.Generic;
21 |
22 | using ICSharpCode.AvalonEdit.Utils;
23 |
24 | namespace ICSharpCode.AvalonEdit.Highlighting
25 | {
26 | ///
27 | /// A highlighting rule set describes a set of spans that are valid at a given code location.
28 | ///
29 | [Serializable]
30 | public class HighlightingRuleSet
31 | {
32 | ///
33 | /// Creates a new RuleSet instance.
34 | ///
35 | public HighlightingRuleSet()
36 | {
37 | this.Spans = new NullSafeCollection();
38 | this.Rules = new NullSafeCollection();
39 | }
40 |
41 | ///
42 | /// Gets/Sets the name of the rule set.
43 | ///
44 | public string Name { get; set; }
45 |
46 | ///
47 | /// Gets the list of spans.
48 | ///
49 | public IList Spans { get; private set; }
50 |
51 | ///
52 | /// Gets the list of rules.
53 | ///
54 | public IList Rules { get; private set; }
55 |
56 | ///
57 | public override string ToString()
58 | {
59 | return "[" + GetType().Name + " " + Name + "]";
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Rendering/VisualLineTextParagraphProperties.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Windows;
20 | using System.Windows.Media.TextFormatting;
21 |
22 | namespace ICSharpCode.AvalonEdit.Rendering
23 | {
24 | sealed class VisualLineTextParagraphProperties : TextParagraphProperties
25 | {
26 | internal TextRunProperties defaultTextRunProperties;
27 | internal TextWrapping textWrapping;
28 | internal double tabSize;
29 | internal double indent;
30 | internal bool firstLineInParagraph;
31 |
32 | public override double DefaultIncrementalTab {
33 | get { return tabSize; }
34 | }
35 |
36 | public override FlowDirection FlowDirection { get { return FlowDirection.LeftToRight; } }
37 | public override TextAlignment TextAlignment { get { return TextAlignment.Left; } }
38 | public override double LineHeight { get { return double.NaN; } }
39 | public override bool FirstLineInParagraph { get { return firstLineInParagraph; } }
40 | public override TextRunProperties DefaultTextRunProperties { get { return defaultTextRunProperties; } }
41 | public override TextWrapping TextWrapping { get { return textWrapping; } }
42 | public override TextMarkerProperties TextMarkerProperties { get { return null; } }
43 | public override double Indent { get { return indent; } }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Editing/DottedLineMargin.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Windows;
20 | using System.Windows.Media;
21 | using System.Windows.Shapes;
22 |
23 | namespace ICSharpCode.AvalonEdit.Editing
24 | {
25 | ///
26 | /// Margin for use with the text area.
27 | /// A vertical dotted line to separate the line numbers from the text view.
28 | ///
29 | public static class DottedLineMargin
30 | {
31 | static readonly object tag = new object();
32 |
33 | ///
34 | /// Creates a vertical dotted line to separate the line numbers from the text view.
35 | ///
36 | public static UIElement Create()
37 | {
38 | Line line = new Line {
39 | X1 = 0,
40 | Y1 = 0,
41 | X2 = 0,
42 | Y2 = 1,
43 | StrokeDashArray = { 0, 2 },
44 | Stretch = Stretch.Fill,
45 | StrokeThickness = 1,
46 | StrokeDashCap = PenLineCap.Round,
47 | Margin = new Thickness(2, 0, 2, 0),
48 | Tag = tag
49 | };
50 |
51 | return line;
52 | }
53 |
54 | ///
55 | /// Gets whether the specified UIElement is the result of a DottedLineMargin.Create call.
56 | ///
57 | public static bool IsDottedLineMargin(UIElement element)
58 | {
59 | Line l = element as Line;
60 | return l != null && l.Tag == tag;
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Tests/Utils/IndentationStringTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using NUnit.Framework;
21 |
22 | namespace ICSharpCode.AvalonEdit.Utils
23 | {
24 | [TestFixture]
25 | public class IndentationStringTests
26 | {
27 | [Test]
28 | public void IndentWithSingleTab()
29 | {
30 | var options = new TextEditorOptions { IndentationSize = 4, ConvertTabsToSpaces = false };
31 | Assert.AreEqual("\t", options.IndentationString);
32 | Assert.AreEqual("\t", options.GetIndentationString(2));
33 | Assert.AreEqual("\t", options.GetIndentationString(3));
34 | Assert.AreEqual("\t", options.GetIndentationString(4));
35 | Assert.AreEqual("\t", options.GetIndentationString(5));
36 | Assert.AreEqual("\t", options.GetIndentationString(6));
37 | }
38 |
39 | [Test]
40 | public void IndentWith4Spaces()
41 | {
42 | var options = new TextEditorOptions { IndentationSize = 4, ConvertTabsToSpaces = true };
43 | Assert.AreEqual(" ", options.IndentationString);
44 | Assert.AreEqual(" ", options.GetIndentationString(2));
45 | Assert.AreEqual(" ", options.GetIndentationString(3));
46 | Assert.AreEqual(" ", options.GetIndentationString(4));
47 | Assert.AreEqual(" ", options.GetIndentationString(5));
48 | Assert.AreEqual(" ", options.GetIndentationString(6));
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Rendering/HeightTreeLineNode.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Collections.Generic;
20 | using System.Diagnostics;
21 |
22 | namespace ICSharpCode.AvalonEdit.Rendering
23 | {
24 | struct HeightTreeLineNode
25 | {
26 | internal HeightTreeLineNode(double height)
27 | {
28 | this.collapsedSections = null;
29 | this.height = height;
30 | }
31 |
32 | internal double height;
33 | internal List collapsedSections;
34 |
35 | internal bool IsDirectlyCollapsed {
36 | get { return collapsedSections != null; }
37 | }
38 |
39 | internal void AddDirectlyCollapsed(CollapsedLineSection section)
40 | {
41 | if (collapsedSections == null)
42 | collapsedSections = new List();
43 | collapsedSections.Add(section);
44 | }
45 |
46 | internal void RemoveDirectlyCollapsed(CollapsedLineSection section)
47 | {
48 | Debug.Assert(collapsedSections.Contains(section));
49 | collapsedSections.Remove(section);
50 | if (collapsedSections.Count == 0)
51 | collapsedSections = null;
52 | }
53 |
54 | ///
55 | /// Returns 0 if the line is directly collapsed, otherwise, returns .
56 | ///
57 | internal double TotalHeight {
58 | get {
59 | return IsDirectlyCollapsed ? 0 : height;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/RichTextColorizer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | using ICSharpCode.AvalonEdit.Document;
22 | using ICSharpCode.AvalonEdit.Rendering;
23 |
24 | namespace ICSharpCode.AvalonEdit.Highlighting
25 | {
26 | ///
27 | /// A colorizer that applies the highlighting from a to the editor.
28 | ///
29 | public class RichTextColorizer : DocumentColorizingTransformer
30 | {
31 | readonly RichTextModel richTextModel;
32 |
33 | ///
34 | /// Creates a new RichTextColorizer instance.
35 | ///
36 | public RichTextColorizer(RichTextModel richTextModel)
37 | {
38 | if (richTextModel == null)
39 | throw new ArgumentNullException("richTextModel");
40 | this.richTextModel = richTextModel;
41 | }
42 |
43 | ///
44 | protected override void ColorizeLine(DocumentLine line)
45 | {
46 | var sections = richTextModel.GetHighlightedSections(line.Offset, line.Length);
47 | foreach (HighlightedSection section in sections) {
48 | if (HighlightingColorizer.IsEmptyColor(section.Color))
49 | continue;
50 | ChangeLinePart(section.Offset, section.Offset + section.Length,
51 | visualLineElement => HighlightingColorizer.ApplyColorToElement(visualLineElement, section.Color, CurrentContext));
52 | }
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Rendering/VisualLinesInvalidException.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Runtime.Serialization;
21 |
22 | namespace ICSharpCode.AvalonEdit.Rendering
23 | {
24 | ///
25 | /// A VisualLinesInvalidException indicates that you accessed the property
26 | /// of the while the visual lines were invalid.
27 | ///
28 | [Serializable]
29 | public class VisualLinesInvalidException : Exception
30 | {
31 | ///
32 | /// Creates a new VisualLinesInvalidException instance.
33 | ///
34 | public VisualLinesInvalidException() : base()
35 | {
36 | }
37 |
38 | ///
39 | /// Creates a new VisualLinesInvalidException instance.
40 | ///
41 | public VisualLinesInvalidException(string message) : base(message)
42 | {
43 | }
44 |
45 | ///
46 | /// Creates a new VisualLinesInvalidException instance.
47 | ///
48 | public VisualLinesInvalidException(string message, Exception innerException) : base(message, innerException)
49 | {
50 | }
51 |
52 | ///
53 | /// Creates a new VisualLinesInvalidException instance.
54 | ///
55 | protected VisualLinesInvalidException(SerializationInfo info, StreamingContext context) : base(info, context)
56 | {
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdSyntaxDefinition.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Collections.Generic;
21 |
22 | using ICSharpCode.AvalonEdit.Utils;
23 |
24 | namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
25 | {
26 | ///
27 | /// A <SyntaxDefinition> element.
28 | ///
29 | [Serializable]
30 | public class XshdSyntaxDefinition
31 | {
32 | ///
33 | /// Creates a new XshdSyntaxDefinition object.
34 | ///
35 | public XshdSyntaxDefinition()
36 | {
37 | this.Elements = new NullSafeCollection();
38 | this.Extensions = new NullSafeCollection();
39 | }
40 |
41 | ///
42 | /// Gets/sets the definition name
43 | ///
44 | public string Name { get; set; }
45 |
46 | ///
47 | /// Gets the associated extensions.
48 | ///
49 | public IList Extensions { get; private set; }
50 |
51 | ///
52 | /// Gets the collection of elements.
53 | ///
54 | public IList Elements { get; private set; }
55 |
56 | ///
57 | /// Applies the visitor to all elements.
58 | ///
59 | public void AcceptElements(IXshdVisitor visitor)
60 | {
61 | foreach (XshdElement element in Elements) {
62 | element.AcceptVisitor(visitor);
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/HighlightingDefinitionInvalidException.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Runtime.Serialization;
21 |
22 | namespace ICSharpCode.AvalonEdit.Highlighting
23 | {
24 | ///
25 | /// Indicates that the highlighting definition that was tried to load was invalid.
26 | ///
27 | [Serializable()]
28 | public class HighlightingDefinitionInvalidException : Exception
29 | {
30 | ///
31 | /// Creates a new HighlightingDefinitionInvalidException instance.
32 | ///
33 | public HighlightingDefinitionInvalidException() : base()
34 | {
35 | }
36 |
37 | ///
38 | /// Creates a new HighlightingDefinitionInvalidException instance.
39 | ///
40 | public HighlightingDefinitionInvalidException(string message) : base(message)
41 | {
42 | }
43 |
44 | ///
45 | /// Creates a new HighlightingDefinitionInvalidException instance.
46 | ///
47 | public HighlightingDefinitionInvalidException(string message, Exception innerException) : base(message, innerException)
48 | {
49 | }
50 |
51 | ///
52 | /// Creates a new HighlightingDefinitionInvalidException instance.
53 | ///
54 | protected HighlightingDefinitionInvalidException(SerializationInfo info, StreamingContext context) : base(info, context)
55 | {
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdRuleSet.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Collections.Generic;
21 |
22 | using ICSharpCode.AvalonEdit.Utils;
23 |
24 | namespace ICSharpCode.AvalonEdit.Highlighting.Xshd
25 | {
26 | ///
27 | /// A rule set in a XSHD file.
28 | ///
29 | [Serializable]
30 | public class XshdRuleSet : XshdElement
31 | {
32 | ///
33 | /// Gets/Sets the name of the rule set.
34 | ///
35 | public string Name { get; set; }
36 |
37 | ///
38 | /// Gets/sets whether the case is ignored in expressions inside this rule set.
39 | ///
40 | public bool? IgnoreCase { get; set; }
41 |
42 | readonly NullSafeCollection elements = new NullSafeCollection();
43 |
44 | ///
45 | /// Gets the collection of elements.
46 | ///
47 | public IList Elements {
48 | get { return elements; }
49 | }
50 |
51 | ///
52 | /// Applies the visitor to all elements.
53 | ///
54 | public void AcceptElements(IXshdVisitor visitor)
55 | {
56 | foreach (XshdElement element in Elements) {
57 | element.AcceptVisitor(visitor);
58 | }
59 | }
60 |
61 | ///
62 | public override object AcceptVisitor(IXshdVisitor visitor)
63 | {
64 | return visitor.VisitRuleSet(this);
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/CodeCompletion/CompletionList.xaml:
--------------------------------------------------------------------------------
1 |
4 |
34 |
35 |
56 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/IHighlightingDefinition.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Collections.Generic;
20 | using System.ComponentModel;
21 |
22 | namespace ICSharpCode.AvalonEdit.Highlighting
23 | {
24 | ///
25 | /// A highlighting definition.
26 | ///
27 | [TypeConverter(typeof(HighlightingDefinitionTypeConverter))]
28 | public interface IHighlightingDefinition
29 | {
30 | ///
31 | /// Gets the name of the highlighting definition.
32 | ///
33 | string Name { get; }
34 |
35 | ///
36 | /// Gets the main rule set.
37 | ///
38 | HighlightingRuleSet MainRuleSet { get; }
39 |
40 | ///
41 | /// Gets a rule set by name.
42 | ///
43 | /// The rule set, or null if it is not found.
44 | HighlightingRuleSet GetNamedRuleSet(string name);
45 |
46 | ///
47 | /// Gets a named highlighting color.
48 | ///
49 | /// The highlighting color, or null if it is not found.
50 | HighlightingColor GetNamedColor(string name);
51 |
52 | ///
53 | /// Gets the list of named highlighting colors.
54 | ///
55 | IEnumerable NamedHighlightingColors { get; }
56 |
57 | ///
58 | /// Gets the list of properties.
59 | ///
60 | IDictionary Properties { get; }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Sample/ColorizeAvalonEdit.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2009 Daniel Grunwald
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Windows;
21 | using System.Windows.Media;
22 |
23 | using ICSharpCode.AvalonEdit.Document;
24 | using ICSharpCode.AvalonEdit.Rendering;
25 |
26 | namespace AvalonEdit.Sample
27 | {
28 | ///
29 | /// Finds the word 'AvalonEdit' and makes it bold and italic.
30 | ///
31 | public class ColorizeAvalonEdit : DocumentColorizingTransformer
32 | {
33 | protected override void ColorizeLine(DocumentLine line)
34 | {
35 | int lineStartOffset = line.Offset;
36 | string text = CurrentContext.Document.GetText(line);
37 | int start = 0;
38 | int index;
39 | while ((index = text.IndexOf("AvalonEdit", start)) >= 0) {
40 | base.ChangeLinePart(
41 | lineStartOffset + index, // startOffset
42 | lineStartOffset + index + 10, // endOffset
43 | (VisualLineElement element) => {
44 | // This lambda gets called once for every VisualLineElement
45 | // between the specified offsets.
46 | Typeface tf = element.TextRunProperties.Typeface;
47 | // Replace the typeface with a modified version of
48 | // the same typeface
49 | element.TextRunProperties.SetTypeface(new Typeface(
50 | tf.FontFamily,
51 | FontStyles.Italic,
52 | FontWeights.Bold,
53 | tf.Stretch
54 | ));
55 | });
56 | start = index + 1; // search for next occurrence
57 | }
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Rendering/TextViewCachedElements.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Windows.Media.TextFormatting;
22 |
23 | using ICSharpCode.AvalonEdit.Utils;
24 |
25 | namespace ICSharpCode.AvalonEdit.Rendering
26 | {
27 | sealed class TextViewCachedElements : IDisposable
28 | {
29 | TextFormatter formatter;
30 | Dictionary nonPrintableCharacterTexts;
31 |
32 | public TextLine GetTextForNonPrintableCharacter(string text, ITextRunConstructionContext context)
33 | {
34 | if (nonPrintableCharacterTexts == null)
35 | nonPrintableCharacterTexts = new Dictionary();
36 | TextLine textLine;
37 | if (!nonPrintableCharacterTexts.TryGetValue(text, out textLine)) {
38 | var p = new VisualLineElementTextRunProperties(context.GlobalTextRunProperties);
39 | p.SetForegroundBrush(context.TextView.NonPrintableCharacterBrush);
40 | if (formatter == null)
41 | formatter = TextFormatterFactory.Create(context.TextView);
42 | textLine = FormattedTextElement.PrepareText(formatter, text, p);
43 | nonPrintableCharacterTexts[text] = textLine;
44 | }
45 | return textLine;
46 | }
47 |
48 | public void Dispose()
49 | {
50 | if (nonPrintableCharacterTexts != null) {
51 | foreach (TextLine line in nonPrintableCharacterTexts.Values)
52 | line.Dispose();
53 | }
54 | if (formatter != null)
55 | formatter.Dispose();
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Editing/NoReadOnlySections.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Collections.Generic;
21 | using System.Linq;
22 |
23 | using ICSharpCode.AvalonEdit.Document;
24 | using ICSharpCode.AvalonEdit.Utils;
25 |
26 | namespace ICSharpCode.AvalonEdit.Editing
27 | {
28 | ///
29 | /// that has no read-only sections; all text is editable.
30 | ///
31 | sealed class NoReadOnlySections : IReadOnlySectionProvider
32 | {
33 | public static readonly NoReadOnlySections Instance = new NoReadOnlySections();
34 |
35 | public bool CanInsert(int offset)
36 | {
37 | return true;
38 | }
39 |
40 | public IEnumerable GetDeletableSegments(ISegment segment)
41 | {
42 | if (segment == null)
43 | throw new ArgumentNullException("segment");
44 | // the segment is always deletable
45 | return ExtensionMethods.Sequence(segment);
46 | }
47 | }
48 |
49 | ///
50 | /// that completely disables editing.
51 | ///
52 | sealed class ReadOnlySectionDocument : IReadOnlySectionProvider
53 | {
54 | public static readonly ReadOnlySectionDocument Instance = new ReadOnlySectionDocument();
55 |
56 | public bool CanInsert(int offset)
57 | {
58 | return false;
59 | }
60 |
61 | public IEnumerable GetDeletableSegments(ISegment segment)
62 | {
63 | return Enumerable.Empty();
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Rendering/VisualYPosition.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.AvalonEdit.Rendering
20 | {
21 | ///
22 | /// An enum that specifies the possible Y positions that can be returned by VisualLine.GetVisualPosition.
23 | ///
24 | public enum VisualYPosition
25 | {
26 | ///
27 | /// Returns the top of the TextLine.
28 | ///
29 | LineTop,
30 | ///
31 | /// Returns the top of the text.
32 | /// If the line contains inline UI elements larger than the text, TextTop may be below LineTop.
33 | /// For a line containing regular text (all in the editor's main font), this will be equal to LineTop.
34 | ///
35 | TextTop,
36 | ///
37 | /// Returns the bottom of the TextLine.
38 | ///
39 | LineBottom,
40 | ///
41 | /// The middle between LineTop and LineBottom.
42 | ///
43 | LineMiddle,
44 | ///
45 | /// Returns the bottom of the text.
46 | /// If the line contains inline UI elements larger than the text, TextBottom might be above LineBottom.
47 | /// For a line containing regular text (all in the editor's main font), this will be equal to LineBottom.
48 | ///
49 | TextBottom,
50 | ///
51 | /// The middle between TextTop and TextBottom.
52 | ///
53 | TextMiddle,
54 | ///
55 | /// Returns the baseline of the text.
56 | ///
57 | Baseline
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Snippets/SnippetEventArgs.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | namespace ICSharpCode.AvalonEdit.Snippets
22 | {
23 | ///
24 | /// Provides information about the event that occured during use of snippets.
25 | ///
26 | public class SnippetEventArgs : EventArgs
27 | {
28 | ///
29 | /// Gets the reason for deactivation.
30 | ///
31 | public DeactivateReason Reason { get; private set; }
32 |
33 | ///
34 | /// Creates a new SnippetEventArgs object, with a DeactivateReason.
35 | ///
36 | public SnippetEventArgs(DeactivateReason reason)
37 | {
38 | this.Reason = reason;
39 | }
40 | }
41 |
42 | ///
43 | /// Describes the reason for deactivation of a .
44 | ///
45 | public enum DeactivateReason
46 | {
47 | ///
48 | /// Unknown reason.
49 | ///
50 | Unknown,
51 | ///
52 | /// Snippet was deleted.
53 | ///
54 | Deleted,
55 | ///
56 | /// There are no active elements in the snippet.
57 | ///
58 | NoActiveElements,
59 | ///
60 | /// The SnippetInputHandler was detached.
61 | ///
62 | InputHandlerDetached,
63 | ///
64 | /// Return was pressed by the user.
65 | ///
66 | ReturnPressed,
67 | ///
68 | /// Escape was pressed by the user.
69 | ///
70 | EscapePressed
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Resources/XML-Mode.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | <!--
15 | -->
16 |
17 |
18 | <!\[CDATA\[
19 | ]]>
20 |
21 |
22 | <!DOCTYPE
23 | >
24 |
25 |
26 | <\?
27 | \?>
28 |
29 |
30 | <
31 | >
32 |
33 |
35 |
36 | "
37 | "|(?=<)
38 |
39 |
40 | '
41 | '|(?=<)
42 |
43 | [\d\w_\-\.]+(?=(\s*=))
44 | =
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | &
53 | [\w\d\#]+
54 | ;
55 |
56 |
57 |
58 | &
59 | [\w\d\#]*
60 | #missing ;
61 |
62 |
63 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Snippets/Snippet.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | using ICSharpCode.AvalonEdit.Document;
22 | using ICSharpCode.AvalonEdit.Editing;
23 |
24 | namespace ICSharpCode.AvalonEdit.Snippets
25 | {
26 | ///
27 | /// A code snippet that can be inserted into the text editor.
28 | ///
29 | [Serializable]
30 | public class Snippet : SnippetContainerElement
31 | {
32 | ///
33 | /// Inserts the snippet into the text area.
34 | ///
35 | public void Insert(TextArea textArea)
36 | {
37 | if (textArea == null)
38 | throw new ArgumentNullException("textArea");
39 |
40 | ISegment selection = textArea.Selection.SurroundingSegment;
41 | int insertionPosition = textArea.Caret.Offset;
42 |
43 | if (selection != null) // if something is selected
44 | // use selection start instead of caret position,
45 | // because caret could be at end of selection or anywhere inside.
46 | // Removal of the selected text causes the caret position to be invalid.
47 | insertionPosition = selection.Offset + TextUtilities.GetWhitespaceAfter(textArea.Document, selection.Offset).Length;
48 |
49 | InsertionContext context = new InsertionContext(textArea, insertionPosition);
50 |
51 | using (context.Document.RunUpdate()) {
52 | if (selection != null)
53 | textArea.Document.Remove(insertionPosition, selection.EndOffset - insertionPosition);
54 | Insert(context);
55 | context.RaiseInsertionCompleted(EventArgs.Empty);
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/CodeCompletion/OverloadInsightWindow.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Windows;
20 | using System.Windows.Input;
21 |
22 | using ICSharpCode.AvalonEdit.Editing;
23 |
24 | namespace ICSharpCode.AvalonEdit.CodeCompletion
25 | {
26 | ///
27 | /// Insight window that shows an OverloadViewer.
28 | ///
29 | public class OverloadInsightWindow : InsightWindow
30 | {
31 | OverloadViewer overloadViewer = new OverloadViewer();
32 |
33 | ///
34 | /// Creates a new OverloadInsightWindow.
35 | ///
36 | public OverloadInsightWindow(TextArea textArea) : base(textArea)
37 | {
38 | overloadViewer.Margin = new Thickness(2, 0, 0, 0);
39 | this.Content = overloadViewer;
40 | }
41 |
42 | ///
43 | /// Gets/Sets the item provider.
44 | ///
45 | public IOverloadProvider Provider {
46 | get { return overloadViewer.Provider; }
47 | set { overloadViewer.Provider = value; }
48 | }
49 |
50 | ///
51 | protected override void OnKeyDown(KeyEventArgs e)
52 | {
53 | base.OnKeyDown(e);
54 | if (!e.Handled && this.Provider != null && this.Provider.Count > 1) {
55 | switch (e.Key) {
56 | case Key.Up:
57 | e.Handled = true;
58 | overloadViewer.ChangeIndex(-1);
59 | break;
60 | case Key.Down:
61 | e.Handled = true;
62 | overloadViewer.ChangeIndex(+1);
63 | break;
64 | }
65 | if (e.Handled) {
66 | UpdateLayout();
67 | UpdatePosition();
68 | }
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Document/DocumentChangeOperation.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Diagnostics;
20 |
21 | namespace ICSharpCode.AvalonEdit.Document
22 | {
23 | ///
24 | /// Describes a change to a TextDocument.
25 | ///
26 | sealed class DocumentChangeOperation : IUndoableOperationWithContext
27 | {
28 | TextDocument document;
29 | DocumentChangeEventArgs change;
30 |
31 | public DocumentChangeOperation(TextDocument document, DocumentChangeEventArgs change)
32 | {
33 | this.document = document;
34 | this.change = change;
35 | }
36 |
37 | public void Undo(UndoStack stack)
38 | {
39 | Debug.Assert(stack.state == UndoStack.StatePlayback);
40 | stack.RegisterAffectedDocument(document);
41 | stack.state = UndoStack.StatePlaybackModifyDocument;
42 | this.Undo();
43 | stack.state = UndoStack.StatePlayback;
44 | }
45 |
46 | public void Redo(UndoStack stack)
47 | {
48 | Debug.Assert(stack.state == UndoStack.StatePlayback);
49 | stack.RegisterAffectedDocument(document);
50 | stack.state = UndoStack.StatePlaybackModifyDocument;
51 | this.Redo();
52 | stack.state = UndoStack.StatePlayback;
53 | }
54 |
55 | public void Undo()
56 | {
57 | OffsetChangeMap map = change.OffsetChangeMapOrNull;
58 | document.Replace(change.Offset, change.InsertionLength, change.RemovedText, map != null ? map.Invert() : null);
59 | }
60 |
61 | public void Redo()
62 | {
63 | document.Replace(change.Offset, change.RemovalLength, change.InsertedText, change.OffsetChangeMapOrNull);
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Document/UndoOperationGroup.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Diagnostics;
21 |
22 | using ICSharpCode.AvalonEdit.Utils;
23 |
24 | namespace ICSharpCode.AvalonEdit.Document
25 | {
26 | ///
27 | /// This class stacks the last x operations from the undostack and makes
28 | /// one undo/redo operation from it.
29 | ///
30 | sealed class UndoOperationGroup : IUndoableOperationWithContext
31 | {
32 | IUndoableOperation[] undolist;
33 |
34 | public UndoOperationGroup(Deque stack, int numops)
35 | {
36 | if (stack == null) {
37 | throw new ArgumentNullException("stack");
38 | }
39 |
40 | Debug.Assert(numops > 0, "UndoOperationGroup : numops should be > 0");
41 | Debug.Assert(numops <= stack.Count);
42 |
43 | undolist = new IUndoableOperation[numops];
44 | for (int i = 0; i < numops; ++i) {
45 | undolist[i] = stack.PopBack();
46 | }
47 | }
48 |
49 | public void Undo()
50 | {
51 | for (int i = 0; i < undolist.Length; ++i) {
52 | undolist[i].Undo();
53 | }
54 | }
55 |
56 | public void Undo(UndoStack stack)
57 | {
58 | for (int i = 0; i < undolist.Length; ++i) {
59 | stack.RunUndo(undolist[i]);
60 | }
61 | }
62 |
63 | public void Redo()
64 | {
65 | for (int i = undolist.Length - 1; i >= 0; --i) {
66 | undolist[i].Redo();
67 | }
68 | }
69 |
70 | public void Redo(UndoStack stack)
71 | {
72 | for (int i = undolist.Length - 1; i >= 0; --i) {
73 | stack.RunRedo(undolist[i]);
74 | }
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Search/Localization.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | namespace ICSharpCode.AvalonEdit.Search
20 | {
21 | ///
22 | /// Holds default texts for buttons and labels in the SearchPanel. Override properties to add other languages.
23 | ///
24 | public class Localization
25 | {
26 | ///
27 | /// Default: 'Match case'
28 | ///
29 | public virtual string MatchCaseText {
30 | get { return "Match case"; }
31 | }
32 |
33 | ///
34 | /// Default: 'Match whole words'
35 | ///
36 | public virtual string MatchWholeWordsText {
37 | get { return "Match whole words"; }
38 | }
39 |
40 |
41 | ///
42 | /// Default: 'Use regular expressions'
43 | ///
44 | public virtual string UseRegexText {
45 | get { return "Use regular expressions"; }
46 | }
47 |
48 | ///
49 | /// Default: 'Find next (F3)'
50 | ///
51 | public virtual string FindNextText {
52 | get { return "Find next (F3)"; }
53 | }
54 |
55 | ///
56 | /// Default: 'Find previous (Shift+F3)'
57 | ///
58 | public virtual string FindPreviousText {
59 | get { return "Find previous (Shift+F3)"; }
60 | }
61 |
62 | ///
63 | /// Default: 'Error: '
64 | ///
65 | public virtual string ErrorText {
66 | get { return "Error: "; }
67 | }
68 |
69 | ///
70 | /// Default: 'No matches found!'
71 | ///
72 | public virtual string NoMatchesFoundText {
73 | get { return "No matches found!"; }
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Rendering/ITextRunConstructionContext.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System.Windows.Media.TextFormatting;
20 |
21 | using ICSharpCode.AvalonEdit.Document;
22 | using ICSharpCode.AvalonEdit.Utils;
23 |
24 | namespace ICSharpCode.AvalonEdit.Rendering
25 | {
26 | ///
27 | /// Contains information relevant for text run creation.
28 | ///
29 | public interface ITextRunConstructionContext
30 | {
31 | ///
32 | /// Gets the text document.
33 | ///
34 | TextDocument Document { get; }
35 |
36 | ///
37 | /// Gets the text view for which the construction runs.
38 | ///
39 | TextView TextView { get; }
40 |
41 | ///
42 | /// Gets the visual line that is currently being constructed.
43 | ///
44 | VisualLine VisualLine { get; }
45 |
46 | ///
47 | /// Gets the global text run properties.
48 | ///
49 | TextRunProperties GlobalTextRunProperties { get; }
50 |
51 | ///
52 | /// Gets a piece of text from the document.
53 | ///
54 | ///
55 | /// This method is allowed to return a larger string than requested.
56 | /// It does this by returning a that describes the requested segment within the returned string.
57 | /// This method should be the preferred text access method in the text transformation pipeline, as it can avoid repeatedly allocating string instances
58 | /// for text within the same line.
59 | ///
60 | StringSegment GetText(int offset, int length);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit.Tests/Highlighting/HtmlClipboardTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Windows;
21 | using ICSharpCode.AvalonEdit.Document;
22 | using NUnit.Framework;
23 |
24 | namespace ICSharpCode.AvalonEdit.Highlighting
25 | {
26 | [TestFixture]
27 | public class HtmlClipboardTests
28 | {
29 | TextDocument document;
30 | DocumentHighlighter highlighter;
31 |
32 | public HtmlClipboardTests()
33 | {
34 | document = new TextDocument("using System.Text;\n\tstring text = SomeMethod();");
35 | highlighter = new DocumentHighlighter(document, HighlightingManager.Instance.GetDefinition("C#"));
36 | }
37 |
38 | [Test]
39 | public void FullDocumentTest()
40 | {
41 | var segment = new TextSegment { StartOffset = 0, Length = document.TextLength };
42 | string html = HtmlClipboard.CreateHtmlFragment(document, highlighter, segment, new HtmlOptions());
43 | Assert.AreEqual("using System.Text; " + Environment.NewLine +
44 | " string " +
45 | "text = SomeMethod();", html);
46 | }
47 |
48 | [Test]
49 | public void PartOfHighlightedWordTest()
50 | {
51 | var segment = new TextSegment { StartOffset = 1, Length = 3 };
52 | string html = HtmlClipboard.CreateHtmlFragment(document, highlighter, segment, new HtmlOptions());
53 | Assert.AreEqual("sin", html);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Indentation/DefaultIndentationStrategy.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | using ICSharpCode.AvalonEdit.Document;
22 |
23 | namespace ICSharpCode.AvalonEdit.Indentation
24 | {
25 | ///
26 | /// Handles indentation by copying the indentation from the previous line.
27 | /// Does not support indenting multiple lines.
28 | ///
29 | public class DefaultIndentationStrategy : IIndentationStrategy
30 | {
31 | ///
32 | public virtual void IndentLine(TextDocument document, DocumentLine line)
33 | {
34 | if (document == null)
35 | throw new ArgumentNullException("document");
36 | if (line == null)
37 | throw new ArgumentNullException("line");
38 | DocumentLine previousLine = line.PreviousLine;
39 | if (previousLine != null) {
40 | ISegment indentationSegment = TextUtilities.GetWhitespaceAfter(document, previousLine.Offset);
41 | string indentation = document.GetText(indentationSegment);
42 | // copy indentation to line
43 | indentationSegment = TextUtilities.GetWhitespaceAfter(document, line.Offset);
44 | document.Replace(indentationSegment.Offset, indentationSegment.Length, indentation,
45 | OffsetChangeMappingType.RemoveAndInsert);
46 | // OffsetChangeMappingType.RemoveAndInsert guarantees the caret moves behind the new indentation.
47 | }
48 | }
49 |
50 | ///
51 | /// Does nothing: indenting multiple lines is useless without a smart indentation strategy.
52 | ///
53 | public virtual void IndentLines(TextDocument document, int beginLine, int endLine)
54 | {
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/TextEditorWeakEventManager.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using ICSharpCode.AvalonEdit.Utils;
20 |
21 | namespace ICSharpCode.AvalonEdit
22 | {
23 | ///
24 | /// Contains weak event managers for .
25 | ///
26 | public static class TextEditorWeakEventManager
27 | {
28 | ///
29 | /// Weak event manager for the event.
30 | ///
31 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
32 | public sealed class DocumentChanged : WeakEventManagerBase
33 | {
34 | ///
35 | protected override void StartListening(ITextEditorComponent source)
36 | {
37 | source.DocumentChanged += DeliverEvent;
38 | }
39 |
40 | ///
41 | protected override void StopListening(ITextEditorComponent source)
42 | {
43 | source.DocumentChanged -= DeliverEvent;
44 | }
45 | }
46 |
47 | ///
48 | /// Weak event manager for the event.
49 | ///
50 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
51 | public sealed class OptionChanged : WeakEventManagerBase
52 | {
53 | ///
54 | protected override void StartListening(ITextEditorComponent source)
55 | {
56 | source.OptionChanged += DeliverEvent;
57 | }
58 |
59 | ///
60 | protected override void StopListening(ITextEditorComponent source)
61 | {
62 | source.OptionChanged -= DeliverEvent;
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/Resources/MarkDownWithFontSize-Mode.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | ^[#]{1}[ ]{1}.*
20 |
21 |
22 | ^[#]{2}[ ]{1}.*
23 |
24 |
25 | ^[#]{3}[ ]{1}.*
26 |
27 |
28 | ^[#]{4}[ ]{1}.*
29 |
30 |
31 | ^[#]{5}[ ]{1}.*
32 |
33 |
34 | ^[#]{6}[ ]{1}.*
35 |
36 |
37 | \*\*.*\*\*
38 |
39 |
40 | __.*__
41 |
42 |
43 | \*(?![ ]).*\*
44 |
45 |
46 | _.*_
47 |
48 |
49 | `.*`
50 |
51 |
52 | ^\t
53 | ^(?!\t)
54 |
55 |
56 | ^[ ]{4}
57 | ^(?![ ]{4})
58 |
59 |
60 | ^>
61 | ^(?!>)
62 |
63 |
64 | \!\[.*\]\[.*\]
65 |
66 |
67 | \[.*\]\(.*\)
68 |
69 |
70 | \[.*\]\[.*\]
71 |
72 |
73 | [ ]{2}$
74 |
75 |
76 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Folding/NewFolding.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 |
21 | using ICSharpCode.AvalonEdit.Document;
22 |
23 | namespace ICSharpCode.AvalonEdit.Folding
24 | {
25 | ///
26 | /// Helper class used for .
27 | ///
28 | public class NewFolding : ISegment
29 | {
30 | ///
31 | /// Gets/Sets the start offset.
32 | ///
33 | public int StartOffset { get; set; }
34 |
35 | ///
36 | /// Gets/Sets the end offset.
37 | ///
38 | public int EndOffset { get; set; }
39 |
40 | ///
41 | /// Gets/Sets the name displayed for the folding.
42 | ///
43 | public string Name { get; set; }
44 |
45 | ///
46 | /// Gets/Sets whether the folding is closed by default.
47 | ///
48 | public bool DefaultClosed { get; set; }
49 |
50 | ///
51 | /// Gets/Sets whether the folding is considered to be a definition.
52 | /// This has an effect on the 'Show Definitions only' command.
53 | ///
54 | public bool IsDefinition { get; set; }
55 |
56 | ///
57 | /// Creates a new NewFolding instance.
58 | ///
59 | public NewFolding()
60 | {
61 | }
62 |
63 | ///
64 | /// Creates a new NewFolding instance.
65 | ///
66 | public NewFolding(int start, int end)
67 | {
68 | if (!(start <= end))
69 | throw new ArgumentException("'start' must be less than 'end'");
70 | this.StartOffset = start;
71 | this.EndOffset = end;
72 | this.Name = null;
73 | this.DefaultClosed = false;
74 | }
75 |
76 | int ISegment.Offset {
77 | get { return this.StartOffset; }
78 | }
79 |
80 | int ISegment.Length {
81 | get { return this.EndOffset - this.StartOffset; }
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Highlighting/HtmlOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.IO;
21 | using System.Net;
22 |
23 | namespace ICSharpCode.AvalonEdit.Highlighting
24 | {
25 | ///
26 | /// Holds options for converting text to HTML.
27 | ///
28 | public class HtmlOptions
29 | {
30 | ///
31 | /// Creates a default HtmlOptions instance.
32 | ///
33 | public HtmlOptions()
34 | {
35 | this.TabSize = 4;
36 | }
37 |
38 | ///
39 | /// Creates a new HtmlOptions instance that copies applicable options from the .
40 | ///
41 | public HtmlOptions(TextEditorOptions options) : this()
42 | {
43 | if (options == null)
44 | throw new ArgumentNullException("options");
45 | this.TabSize = options.IndentationSize;
46 | }
47 |
48 | ///
49 | /// The amount of spaces a tab gets converted to.
50 | ///
51 | public int TabSize { get; set; }
52 |
53 | ///
54 | /// Writes the HTML attribute for the style to the text writer.
55 | ///
56 | public virtual void WriteStyleAttributeForColor(TextWriter writer, HighlightingColor color)
57 | {
58 | if (writer == null)
59 | throw new ArgumentNullException("writer");
60 | if (color == null)
61 | throw new ArgumentNullException("color");
62 | writer.Write(" style=\"");
63 | WebUtility.HtmlEncode(color.ToCss(), writer);
64 | writer.Write('"');
65 | }
66 |
67 | ///
68 | /// Gets whether the color needs to be written out to HTML.
69 | ///
70 | public virtual bool ColorNeedsSpanForStyling(HighlightingColor color)
71 | {
72 | if (color == null)
73 | throw new ArgumentNullException("color");
74 | return !string.IsNullOrEmpty(color.ToCss());
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Snippets/SnippetCaretElement.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Runtime.Serialization;
21 |
22 | using ICSharpCode.AvalonEdit.Document;
23 |
24 | namespace ICSharpCode.AvalonEdit.Snippets
25 | {
26 | ///
27 | /// Sets the caret position after interactive mode has finished.
28 | ///
29 | [Serializable]
30 | public class SnippetCaretElement : SnippetElement
31 | {
32 | [OptionalField]
33 | bool setCaretOnlyIfTextIsSelected;
34 |
35 | ///
36 | /// Creates a new SnippetCaretElement.
37 | ///
38 | public SnippetCaretElement()
39 | {
40 | }
41 |
42 | ///
43 | /// Creates a new SnippetCaretElement.
44 | ///
45 | ///
46 | /// If set to true, the caret is set only when some text was selected.
47 | /// This is useful when both SnippetCaretElement and SnippetSelectionElement are used in the same snippet.
48 | ///
49 | public SnippetCaretElement(bool setCaretOnlyIfTextIsSelected)
50 | {
51 | this.setCaretOnlyIfTextIsSelected = setCaretOnlyIfTextIsSelected;
52 | }
53 |
54 | ///
55 | public override void Insert(InsertionContext context)
56 | {
57 | if (!setCaretOnlyIfTextIsSelected || !string.IsNullOrEmpty(context.SelectedText))
58 | SetCaret(context);
59 | }
60 |
61 | internal static void SetCaret(InsertionContext context)
62 | {
63 | TextAnchor pos = context.Document.CreateAnchor(context.InsertionPosition);
64 | pos.MovementType = AnchorMovementType.BeforeInsertion;
65 | pos.SurviveDeletion = true;
66 | context.Deactivated += (sender, e) => {
67 | if (e.Reason == DeactivateReason.ReturnPressed || e.Reason == DeactivateReason.NoActiveElements) {
68 | context.TextArea.Caret.Offset = pos.Offset;
69 | }
70 | };
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Rendering/ColumnRulerRenderer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Windows;
21 | using System.Windows.Media;
22 |
23 | using ICSharpCode.AvalonEdit.Utils;
24 |
25 | namespace ICSharpCode.AvalonEdit.Rendering
26 | {
27 | ///
28 | /// Renders a ruler at a certain column.
29 | ///
30 | sealed class ColumnRulerRenderer : IBackgroundRenderer
31 | {
32 | Pen pen;
33 | int column;
34 | TextView textView;
35 |
36 | public static readonly Color DefaultForeground = Colors.LightGray;
37 |
38 | public ColumnRulerRenderer(TextView textView)
39 | {
40 | if (textView == null)
41 | throw new ArgumentNullException("textView");
42 |
43 | this.pen = new Pen(new SolidColorBrush(DefaultForeground), 1);
44 | this.pen.Freeze();
45 | this.textView = textView;
46 | this.textView.BackgroundRenderers.Add(this);
47 | }
48 |
49 | public KnownLayer Layer {
50 | get { return KnownLayer.Background; }
51 | }
52 |
53 | public void SetRuler(int column, Pen pen)
54 | {
55 | if (this.column != column) {
56 | this.column = column;
57 | textView.InvalidateLayer(this.Layer);
58 | }
59 | if (this.pen != pen) {
60 | this.pen = pen;
61 | textView.InvalidateLayer(this.Layer);
62 | }
63 | }
64 |
65 | public void Draw(TextView textView, System.Windows.Media.DrawingContext drawingContext)
66 | {
67 | if (column < 1) return;
68 | double offset = textView.WideSpaceWidth * column;
69 | Size pixelSize = PixelSnapHelpers.GetPixelSize(textView);
70 | double markerXPos = PixelSnapHelpers.PixelAlign(offset, pixelSize.Width);
71 | markerXPos -= textView.ScrollOffset.X;
72 | Point start = new Point(markerXPos, 0);
73 | Point end = new Point(markerXPos, Math.Max(textView.DocumentHeight, textView.ActualHeight));
74 |
75 | drawingContext.DrawLine(pen, start, end);
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Utils/ThrowUtil.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Globalization;
21 |
22 | namespace ICSharpCode.AvalonEdit.Utils
23 | {
24 | ///
25 | /// Contains exception-throwing helper methods.
26 | ///
27 | static class ThrowUtil
28 | {
29 | ///
30 | /// Throws an ArgumentNullException if is null; otherwise
31 | /// returns val.
32 | ///
33 | ///
34 | /// Use this method to throw an ArgumentNullException when using parameters for base
35 | /// constructor calls.
36 | ///
37 | /// public VisualLineText(string text) : base(ThrowUtil.CheckNotNull(text, "text").Length)
38 | ///
39 | ///
40 | public static T CheckNotNull(T val, string parameterName) where T : class
41 | {
42 | if (val == null)
43 | throw new ArgumentNullException(parameterName);
44 | return val;
45 | }
46 |
47 | public static int CheckNotNegative(int val, string parameterName)
48 | {
49 | if (val < 0)
50 | throw new ArgumentOutOfRangeException(parameterName, val, "value must not be negative");
51 | return val;
52 | }
53 |
54 | public static int CheckInRangeInclusive(int val, string parameterName, int lower, int upper)
55 | {
56 | if (val < lower || val > upper)
57 | throw new ArgumentOutOfRangeException(parameterName, val, "Expected: " + lower.ToString(CultureInfo.InvariantCulture) + " <= " + parameterName + " <= " + upper.ToString(CultureInfo.InvariantCulture));
58 | return val;
59 | }
60 |
61 | public static InvalidOperationException NoDocumentAssigned()
62 | {
63 | return new InvalidOperationException("Document is null");
64 | }
65 |
66 | public static InvalidOperationException NoValidCaretPosition()
67 | {
68 | return new InvalidOperationException("Could not find a valid caret position in the line");
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/ICSharpCode.AvalonEdit/Editing/SelectionLayer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2 | //
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
4 | // software and associated documentation files (the "Software"), to deal in the Software
5 | // without restriction, including without limitation the rights to use, copy, modify, merge,
6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7 | // to whom the Software is furnished to do so, subject to the following conditions:
8 | //
9 | // The above copyright notice and this permission notice shall be included in all copies or
10 | // substantial portions of the Software.
11 | //
12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 | // DEALINGS IN THE SOFTWARE.
18 |
19 | using System;
20 | using System.Windows;
21 | using System.Windows.Media;
22 |
23 | using ICSharpCode.AvalonEdit.Rendering;
24 |
25 | namespace ICSharpCode.AvalonEdit.Editing
26 | {
27 | sealed class SelectionLayer : Layer, IWeakEventListener
28 | {
29 | readonly TextArea textArea;
30 |
31 | public SelectionLayer(TextArea textArea) : base(textArea.TextView, KnownLayer.Selection)
32 | {
33 | this.IsHitTestVisible = false;
34 |
35 | this.textArea = textArea;
36 | TextViewWeakEventManager.VisualLinesChanged.AddListener(textView, this);
37 | TextViewWeakEventManager.ScrollOffsetChanged.AddListener(textView, this);
38 | }
39 |
40 | bool IWeakEventListener.ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
41 | {
42 | if (managerType == typeof(TextViewWeakEventManager.VisualLinesChanged)
43 | || managerType == typeof(TextViewWeakEventManager.ScrollOffsetChanged)) {
44 | InvalidateVisual();
45 | return true;
46 | }
47 | return false;
48 | }
49 |
50 | protected override void OnRender(DrawingContext drawingContext)
51 | {
52 | base.OnRender(drawingContext);
53 |
54 | var selectionBorder = textArea.SelectionBorder;
55 |
56 | BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder();
57 | geoBuilder.AlignToWholePixels = true;
58 | geoBuilder.BorderThickness = selectionBorder != null ? selectionBorder.Thickness : 0;
59 | geoBuilder.ExtendToFullWidthAtLineEnd = textArea.Selection.EnableVirtualSpace;
60 | geoBuilder.CornerRadius = textArea.SelectionCornerRadius;
61 | foreach (var segment in textArea.Selection.Segments) {
62 | geoBuilder.AddSegment(textView, segment);
63 | }
64 | Geometry geometry = geoBuilder.CreateGeometry();
65 | if (geometry != null) {
66 | drawingContext.DrawGeometry(textArea.SelectionBrush, selectionBorder, geometry);
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------