├── .editorconfig
├── .github
└── FUNDING.yml
├── .gitignore
├── Directory.Build.props
├── GitExtensions.settings
├── ICSharpCode.TextEditor.Sample
├── ICSharpCode.TextEditor.Sample.csproj
├── Program.cs
├── SampleForm.Designer.cs
├── SampleForm.cs
├── SampleForm.resx
└── app.config
├── ICSharpCode.TextEditor.sln
├── Project
├── ICSharpCode.TextEditor.csproj
├── Resources
│ ├── ANTLR.xshd
│ ├── ASPX.xshd
│ ├── ActionScript.xshd
│ ├── Ada.xshd
│ ├── Assembly.xshd
│ ├── AutoHotkey.xshd
│ ├── Batch.xshd
│ ├── Boo.xshd
│ ├── C#.xshd
│ ├── C++.xshd
│ ├── C.xshd
│ ├── CSS.xshd
│ ├── Ceylon.xshd
│ ├── ChucK.xshd
│ ├── Clojure.xshd
│ ├── Cocoa.xshd
│ ├── CoffeeScript.xshd
│ ├── Cool.xshd
│ ├── D.xshd
│ ├── Dart.xshd
│ ├── Delphi.xshd
│ ├── Eiffel.xshd
│ ├── Elixir.xshd
│ ├── Erlang.xshd
│ ├── F#.xshd
│ ├── Falcon.xshd
│ ├── Fantom.xshd
│ ├── Fortran95.xshd
│ ├── GherkinFeature.xshd
│ ├── Go.xshd
│ ├── Groovy.xshd
│ ├── Gui4Cli.xshd
│ ├── HTML.xshd
│ ├── Haskell.xshd
│ ├── Haxe.xshd
│ ├── ICSharpCode.TextEditor.snk
│ ├── ILYC.xshd
│ ├── INI.xshd
│ ├── Icon.xshd
│ ├── Io.xshd
│ ├── JSON.xshd
│ ├── Java.xshd
│ ├── JavaScript.xshd
│ ├── Julia.xshd
│ ├── Just BASIC.xshd
│ ├── KiXtart.xshd
│ ├── Kotlin.xshd
│ ├── Lean.xshd
│ ├── Lisp.xshd
│ ├── Lua.xshd
│ ├── Markdown.xshd
│ ├── Mode.xsd
│ ├── Nemerle.xshd
│ ├── Nim.xshd
│ ├── OCaml.xshd
│ ├── Objective-C.xshd
│ ├── PHP.xshd
│ ├── ParaSail.xshd
│ ├── Pascal.xshd
│ ├── Patch-Mode.xshd
│ ├── Pike.xshd
│ ├── PowerShell.xshd
│ ├── Prolog.xshd
│ ├── PureScript.xshd
│ ├── Python.xshd
│ ├── R.xshd
│ ├── Registry.xshd
│ ├── Resource.xshd
│ ├── Rexx.xshd
│ ├── RightArrow.cur
│ ├── Rust.xshd
│ ├── SQF.xshd
│ ├── SQL.xshd
│ ├── Scala.xshd
│ ├── Scheme.xshd
│ ├── Solidity.xshd
│ ├── Spike.xshd
│ ├── Swift.xshd
│ ├── SyntaxModes.xml
│ ├── TCL.xshd
│ ├── Tex-Mode.xshd
│ ├── TextEditorControl.bmp
│ ├── Thrift.xshd
│ ├── TypeScript.xshd
│ ├── VB.NET.xshd
│ ├── VBScript.xshd
│ ├── VHDL.xshd
│ ├── VS Solution.xshd
│ ├── Vala.xshd
│ ├── Verilog.xshd
│ ├── Volt.xshd
│ ├── X10.xshd
│ ├── XC.xshd
│ ├── XML.xshd
│ ├── Xtend.xshd
│ └── Yaml.xshd
└── Src
│ ├── Actions
│ ├── BookmarkActions.cs
│ ├── CaretActions.cs
│ ├── ClipBoardActions.cs
│ ├── FoldActions.cs
│ ├── FormatActions.cs
│ ├── HomeEndActions.cs
│ ├── IEditAction.cs
│ ├── MiscActions.cs
│ └── SelectionActions.cs
│ ├── Document
│ ├── AbstractSegment.cs
│ ├── BookmarkManager
│ │ ├── Bookmark.cs
│ │ ├── BookmarkEventHandler.cs
│ │ ├── BookmarkManager.cs
│ │ └── BookmarkManagerMemento.cs
│ ├── DefaultDocument.cs
│ ├── DefaultTextEditorProperties.cs
│ ├── DocumentEventArgs.cs
│ ├── DocumentFactory.cs
│ ├── EolMarkerStyle.cs
│ ├── FoldingStrategy
│ │ ├── FoldMarker.cs
│ │ ├── FoldingManager.cs
│ │ ├── IFoldingStrategy.cs
│ │ └── IndentFoldingStrategy.cs
│ ├── FormattingStrategy
│ │ ├── DefaultFormattingStrategy.cs
│ │ └── IFormattingStrategy.cs
│ ├── HighlightingStrategy
│ │ ├── DefaultHighlightingStrategy.cs
│ │ ├── FontContainer.cs
│ │ ├── HighlightBackground.cs
│ │ ├── HighlightColor.cs
│ │ ├── HighlightInfo.cs
│ │ ├── HighlightRuleSet.cs
│ │ ├── HighlightingColorNotFoundException.cs
│ │ ├── HighlightingDefinitionInvalidException.cs
│ │ ├── HighlightingDefinitionParser.cs
│ │ ├── HighlightingManager.cs
│ │ ├── HighlightingStrategyFactory.cs
│ │ ├── IHighlightingStrategy.cs
│ │ ├── NextMarker.cs
│ │ ├── PrevMarker.cs
│ │ ├── Span.cs
│ │ ├── SpanStack.cs
│ │ ├── SyntaxModes
│ │ │ ├── FileSyntaxModeProvider.cs
│ │ │ ├── ISyntaxModeFileProvider.cs
│ │ │ ├── ResourceSyntaxModeProvider.cs
│ │ │ └── SyntaxMode.cs
│ │ └── TextWord.cs
│ ├── IDocument.cs
│ ├── ISegment.cs
│ ├── ITextEditorProperties.cs
│ ├── LineManager
│ │ ├── DeferredEventList.cs
│ │ ├── EolMarker.cs
│ │ ├── LineManager.cs
│ │ ├── LineManagerEventArgs.cs
│ │ ├── LineSegment.cs
│ │ └── LineSegmentTree.cs
│ ├── MarkerStrategy
│ │ ├── MarkerStrategy.cs
│ │ └── TextMarker.cs
│ ├── Selection
│ │ ├── ColumnRange.cs
│ │ ├── DefaultSelection.cs
│ │ ├── ISelection.cs
│ │ └── SelectionManager.cs
│ ├── TextAnchor.cs
│ ├── TextBufferStrategy
│ │ ├── GapTextBufferStrategy.cs
│ │ ├── ITextBufferStrategy.cs
│ │ └── StringTextBufferStrategy.cs
│ ├── TextLocation.cs
│ └── TextUtilities.cs
│ ├── Gui
│ ├── AbstractMargin.cs
│ ├── BracketHighlighter.cs
│ ├── BrushRegistry.cs
│ ├── Caret.cs
│ ├── CompletionWindow
│ │ ├── AbstractCompletionWindow.cs
│ │ ├── CodeCompletionListView.cs
│ │ ├── CodeCompletionWindow.cs
│ │ ├── DeclarationViewWindow.cs
│ │ ├── ICompletionData.cs
│ │ └── ICompletionDataProvider.cs
│ ├── DrawableLine.cs
│ ├── FoldMargin.cs
│ ├── GutterMargin.cs
│ ├── HRuler.cs
│ ├── IconBarMargin.cs
│ ├── Ime.cs
│ ├── InsightWindow
│ │ ├── IInsightDataProvider.cs
│ │ └── InsightWindow.cs
│ ├── TextArea.cs
│ ├── TextAreaClipboardHandler.cs
│ ├── TextAreaControl.cs
│ ├── TextAreaDragDropHandler.cs
│ ├── TextAreaMouseHandler.cs
│ ├── TextAreaUpdate.cs
│ ├── TextEditorControl.cs
│ ├── TextEditorControlBase.cs
│ ├── TextView.cs
│ └── ToolTipRequestEventArgs.cs
│ ├── Undo
│ ├── IUndoableOperation.cs
│ ├── UndoQueue.cs
│ ├── UndoStack.cs
│ ├── UndoableDelete.cs
│ ├── UndoableInsert.cs
│ └── UndoableReplace.cs
│ └── Util
│ ├── AugmentableRedBlackTree.cs
│ ├── CheckedList.cs
│ ├── FileReader.cs
│ ├── LoggingService.cs
│ ├── LookupTable.cs
│ ├── MouseWheelHandler.cs
│ ├── RedBlackTreeIterator.cs
│ ├── RtfWriter.cs
│ ├── TextUtility.cs
│ ├── TipPainter.cs
│ ├── TipPainterTools.cs
│ ├── TipSection.cs
│ ├── TipSpacer.cs
│ ├── TipSplitter.cs
│ ├── TipText.cs
│ ├── WeakCollection.cs
│ └── Win32Util.cs
├── README.md
├── Sample.md
├── Test
├── BlockCommentTests.cs
├── DocumentTests.cs
├── FoldingManagerTests.cs
├── HighlightingManagerTests.cs
├── ICSharpCode.TextEditor.Tests.csproj
├── TextMarkerTests.cs
├── bin
│ └── UnitTests
│ │ └── nunit.framework.xml
└── packages.config
└── appveyor.yml
/.editorconfig:
--------------------------------------------------------------------------------
1 | ; Visual Studio Extension : http://visualstudiogallery.msdn.microsoft.com/c8bccfe2-650c-4b42-bc5c-845e21f96328
2 | ; See http://editorconfig.org/ for more informations
3 | ; Top-most EditorConfig file
4 | root = false
5 |
6 | # Additions for AppVeyor tests, use Git Extensions settings by default
7 |
8 | [*.cs]
9 | # WFO1000: A property should determine its property content serialization with the DesignerSerializationVisibilityAttribute, DefaultValueAttribute or the ShouldSerializeProperty method
10 | # Silent for now, see https://github.com/dotnet/winforms/issues/12476
11 | dotnet_diagnostic.WFO1000.severity = silent
12 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 |
2 | # You can add one username per supported platform and one custom link
3 | open_collective: gitextensions
4 | custom: https://github.com/gitextensions/gitextensions/wiki
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.user
2 | *.suo
3 | _ReSharper.*/
4 | bin/
5 | obj/
6 | TestResults/
7 | *.vsp
8 | /.vs/
9 | /.idea/
10 |
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | net9.0-windows
6 | true
7 | false
8 |
9 |
10 |
11 | Copyright © 2000-2010 AlphaSierraPapa // Copyright © 2019 Git Extensions
12 | This is a GitExtensions fork of SharpDevelop .NET text editor control
13 | 4.0.2.6466
14 | Git Extensions
15 | Git Extensions
16 | ic#code // Git Extensions
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/ICSharpCode.TextEditor.Sample/ICSharpCode.TextEditor.Sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WinExe
5 | net9.0-windows
6 | true
7 |
8 |
9 |
10 |
11 | {2d18be89-d210-49eb-a9dd-2246fbb3df6d}
12 | ICSharpCode.TextEditor
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/ICSharpCode.TextEditor.Sample/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace ICSharpCode.TextEditor.Sample
5 | {
6 | internal static class Program
7 | {
8 | [STAThread]
9 | private static void Main()
10 | {
11 | Application.EnableVisualStyles();
12 | Application.SetCompatibleTextRenderingDefault(defaultValue: false);
13 | Application.Run(new SampleForm());
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/ICSharpCode.TextEditor.Sample/SampleForm.Designer.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 |
3 | namespace ICSharpCode.TextEditor.Sample
4 | {
5 | partial class SampleForm
6 | {
7 | private IContainer components = null;
8 |
9 | protected override void Dispose(bool disposing)
10 | {
11 | if (disposing)
12 | {
13 | components?.Dispose();
14 | }
15 |
16 | base.Dispose(disposing);
17 | }
18 |
19 | #region Windows Form Designer generated code
20 |
21 | private void InitializeComponent()
22 | {
23 | this.textEditor = new ICSharpCode.TextEditor.TextEditorControl();
24 | this.SuspendLayout();
25 | //
26 | // textEditor
27 | //
28 | this.textEditor.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
29 | | System.Windows.Forms.AnchorStyles.Left)
30 | | System.Windows.Forms.AnchorStyles.Right)));
31 | this.textEditor.IsReadOnly = false;
32 | this.textEditor.Location = new System.Drawing.Point(0, 0);
33 | this.textEditor.Name = "textEditor";
34 | this.textEditor.Size = new System.Drawing.Size(989, 628);
35 | this.textEditor.TabIndex = 0;
36 | //
37 | // Form1
38 | //
39 | this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F);
40 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
41 | this.ClientSize = new System.Drawing.Size(989, 628);
42 | this.Controls.Add(this.textEditor);
43 | this.Name = "SampleForm";
44 | this.Text = "ICSharpCode.TextEditor Sample";
45 | this.ResumeLayout(false);
46 |
47 | }
48 |
49 | #endregion
50 |
51 | private TextEditorControl textEditor;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/ICSharpCode.TextEditor.Sample/SampleForm.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Forms;
2 |
3 | namespace ICSharpCode.TextEditor.Sample
4 | {
5 | public sealed partial class SampleForm : Form
6 | {
7 | public SampleForm()
8 | {
9 | InitializeComponent();
10 |
11 | textEditor.Document.TextEditorProperties.EnableFolding = false;
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/ICSharpCode.TextEditor.Sample/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/ICSharpCode.TextEditor.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio 15
3 | VisualStudioVersion = 15.0.27703.2035
4 | MinimumVisualStudioVersion = 10.0.40219.1
5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.TextEditor.Tests", "Test\ICSharpCode.TextEditor.Tests.csproj", "{6259D767-BA7C-484D-9472-68F350A20086}"
6 | EndProject
7 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.TextEditor", "Project\ICSharpCode.TextEditor.csproj", "{2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}"
8 | EndProject
9 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.TextEditor.Sample", "ICSharpCode.TextEditor.Sample\ICSharpCode.TextEditor.Sample.csproj", "{7A53A84D-78B1-40B8-8D26-4724D829A756}"
10 | EndProject
11 | Global
12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
13 | Debug|Any CPU = Debug|Any CPU
14 | Release|Any CPU = Release|Any CPU
15 | EndGlobalSection
16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
17 | {6259D767-BA7C-484D-9472-68F350A20086}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18 | {6259D767-BA7C-484D-9472-68F350A20086}.Debug|Any CPU.Build.0 = Debug|Any CPU
19 | {6259D767-BA7C-484D-9472-68F350A20086}.Release|Any CPU.ActiveCfg = Release|Any CPU
20 | {6259D767-BA7C-484D-9472-68F350A20086}.Release|Any CPU.Build.0 = Release|Any CPU
21 | {2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 | {2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 | {2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
24 | {2D18BE89-D210-49EB-A9DD-2246FBB3DF6D}.Release|Any CPU.Build.0 = Release|Any CPU
25 | {7A53A84D-78B1-40B8-8D26-4724D829A756}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26 | {7A53A84D-78B1-40B8-8D26-4724D829A756}.Debug|Any CPU.Build.0 = Debug|Any CPU
27 | {7A53A84D-78B1-40B8-8D26-4724D829A756}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {7A53A84D-78B1-40B8-8D26-4724D829A756}.Release|Any CPU.Build.0 = Release|Any CPU
29 | EndGlobalSection
30 | GlobalSection(SolutionProperties) = preSolution
31 | HideSolutionNode = FALSE
32 | EndGlobalSection
33 | GlobalSection(ExtensibilityGlobals) = postSolution
34 | SolutionGuid = {FCCE1227-2613-4717-ACA6-A0A6C916D7F5}
35 | EndGlobalSection
36 | EndGlobal
37 |
--------------------------------------------------------------------------------
/Project/ICSharpCode.TextEditor.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Library
5 | net9.0-windows
6 | true
7 | false
8 | true
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Project/Resources/ASPX.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | <%
7 | %>
8 |
9 |
10 |
11 |
12 |
13 | //
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Project/Resources/ChucK.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
43 |
44 |
45 | '
46 | '
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/Project/Resources/Cocoa.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 | COMPILER
33 | TOKENNAMES
34 |
35 |
36 |
37 | "
38 | "
39 |
40 |
41 |
42 | '
43 | '
44 |
45 |
46 |
47 | <
48 | >
49 |
50 |
51 |
52 | (.
53 | .)
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/Project/Resources/Cool.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
43 |
44 | class
45 | inherits
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/Project/Resources/Erlang.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/Project/Resources/GherkinFeature.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 | @@
43 |
44 |
45 |
46 | |
47 |
48 |
49 |
50 | '
51 | '
52 |
53 |
54 |
55 | """
56 | """
57 |
58 |
59 |
60 | "
61 | "
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/Project/Resources/HTML.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | <!--
30 | -->
31 |
32 |
33 |
34 | <script>
35 | </script>
36 |
37 |
38 |
39 | <
40 | >
41 |
42 |
43 |
44 | &
45 | ;
46 |
47 |
48 |
49 |
50 |
51 |
52 | /=
53 |
54 |
55 | "
56 | "
57 |
58 |
59 |
60 | '
61 | '
62 |
63 |
64 | =
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/Project/Resources/ICSharpCode.TextEditor.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gitextensions/ICSharpCode.TextEditor/02a2aca8c9794c08ee184457c9330a4b9813c608/Project/Resources/ICSharpCode.TextEditor.snk
--------------------------------------------------------------------------------
/Project/Resources/ILYC.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/Project/Resources/INI.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | [
43 | ]
44 |
45 |
46 | =
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/Project/Resources/Io.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
43 |
44 |
45 | """
46 | """
47 |
48 |
49 |
50 | #
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | &<>~$!@%^*()-+=|\#/{}[]:;"' , .?
86 |
87 |
88 | #{
89 | }
90 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/Project/Resources/JSON.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/Project/Resources/ParaSail.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
43 |
44 | void
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
--------------------------------------------------------------------------------
/Project/Resources/Patch-Mode.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | ~!%^*()-+=|\#/{}[]:;"'<> , .?
9 |
10 |
11 | Index:
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 |
--------------------------------------------------------------------------------
/Project/Resources/Pike.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
43 |
44 |
45 | '
46 | '
47 |
48 |
49 |
50 | #
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/Project/Resources/PureScript.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
43 |
44 |
45 | "
46 | "
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | &<>~!@%^*()-+=|\#/{}[]:;"' , .?
81 |
82 |
83 | {-
84 | -}
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/Project/Resources/Registry.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/Project/Resources/Rexx.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 | &<>~!@%^*()-+=|\#/{}[]:;"' , .?
97 |
98 |
99 | /*
100 | */
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/Project/Resources/RightArrow.cur:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gitextensions/ICSharpCode.TextEditor/02a2aca8c9794c08ee184457c9330a4b9813c608/Project/Resources/RightArrow.cur
--------------------------------------------------------------------------------
/Project/Resources/Spike.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
43 |
44 |
45 | #!
46 |
47 |
48 | :
49 | class
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/Project/Resources/Tex-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 |
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 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | &~!@%^*()-+=|\#/{}[]:;"'<> , .?
67 |
68 |
69 |
70 | %
71 |
72 |
73 |
74 | \
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/Project/Resources/TextEditorControl.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gitextensions/ICSharpCode.TextEditor/02a2aca8c9794c08ee184457c9330a4b9813c608/Project/Resources/TextEditorControl.bmp
--------------------------------------------------------------------------------
/Project/Resources/VS Solution.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/Project/Resources/XC.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | #include
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/Project/Resources/XML.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | <!--
29 | -->
30 |
31 |
32 |
33 | <![CDATA[
34 | ]]>
35 |
36 |
37 |
38 | <!DOCTYPE
39 | >
40 |
41 |
42 |
43 | <?
44 | ?>
45 |
46 |
47 |
48 | <
49 | >
50 |
51 |
52 |
53 | &
54 | ;
55 |
56 |
57 |
58 |
59 | /=
60 |
61 |
62 | "
63 | "
64 |
65 |
66 |
67 | '
68 | '
69 |
70 |
71 | =
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/Project/Resources/Yaml.xshd:
--------------------------------------------------------------------------------
1 |
2 |
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 |
--------------------------------------------------------------------------------
/Project/Src/Actions/BookmarkActions.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using ICSharpCode.TextEditor.Document;
10 |
11 | namespace ICSharpCode.TextEditor.Actions
12 | {
13 | public class ToggleBookmark : AbstractEditAction
14 | {
15 | public override void Execute(TextArea textArea)
16 | {
17 | textArea.Document.BookmarkManager.ToggleMarkAt(textArea.Caret.Position);
18 | textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, textArea.Caret.Line));
19 | textArea.Document.CommitUpdate();
20 | }
21 | }
22 |
23 | public class GotoPrevBookmark : AbstractEditAction
24 | {
25 | private readonly Predicate predicate;
26 |
27 | public GotoPrevBookmark(Predicate predicate)
28 | {
29 | this.predicate = predicate;
30 | }
31 |
32 | public override void Execute(TextArea textArea)
33 | {
34 | var mark = textArea.Document.BookmarkManager.GetPrevMark(textArea.Caret.Line, predicate);
35 | if (mark != null)
36 | {
37 | textArea.Caret.Position = mark.Location;
38 | textArea.SelectionManager.ClearSelection();
39 | textArea.SetDesiredColumn();
40 | }
41 | }
42 | }
43 |
44 | public class GotoNextBookmark : AbstractEditAction
45 | {
46 | private readonly Predicate predicate;
47 |
48 | public GotoNextBookmark(Predicate predicate)
49 | {
50 | this.predicate = predicate;
51 | }
52 |
53 | public override void Execute(TextArea textArea)
54 | {
55 | var mark = textArea.Document.BookmarkManager.GetNextMark(textArea.Caret.Line, predicate);
56 | if (mark != null)
57 | {
58 | textArea.Caret.Position = mark.Location;
59 | textArea.SelectionManager.ClearSelection();
60 | textArea.SetDesiredColumn();
61 | }
62 | }
63 | }
64 |
65 | public class ClearAllBookmarks : AbstractEditAction
66 | {
67 | private readonly Predicate predicate;
68 |
69 | public ClearAllBookmarks(Predicate predicate)
70 | {
71 | this.predicate = predicate;
72 | }
73 |
74 | public override void Execute(TextArea textArea)
75 | {
76 | textArea.Document.BookmarkManager.RemoveMarks(predicate);
77 | textArea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
78 | textArea.Document.CommitUpdate();
79 | }
80 | }
81 | }
--------------------------------------------------------------------------------
/Project/Src/Actions/ClipBoardActions.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | namespace ICSharpCode.TextEditor.Actions
9 | {
10 | public class Cut : AbstractEditAction
11 | {
12 | public override void Execute(TextArea textArea)
13 | {
14 | if (textArea.Document.ReadOnly)
15 | return;
16 | textArea.ClipboardHandler.Cut(sender: null, e: null);
17 | }
18 | }
19 |
20 | public class Copy : AbstractEditAction
21 | {
22 | public override void Execute(TextArea textArea)
23 | {
24 | textArea.AutoClearSelection = false;
25 | textArea.ClipboardHandler.Copy(sender: null, e: null);
26 | }
27 | }
28 |
29 | public class Paste : AbstractEditAction
30 | {
31 | public override void Execute(TextArea textArea)
32 | {
33 | if (textArea.Document.ReadOnly)
34 | return;
35 | textArea.ClipboardHandler.Paste(sender: null, e: null);
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/Project/Src/Actions/FoldActions.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using ICSharpCode.TextEditor.Document;
10 |
11 | namespace ICSharpCode.TextEditor.Actions
12 | {
13 | public class ToggleFolding : AbstractEditAction
14 | {
15 | public override void Execute(TextArea textArea)
16 | {
17 | var foldMarkers = textArea.Document.FoldingManager.GetFoldingsWithStart(textArea.Caret.Line);
18 | if (foldMarkers.Count != 0)
19 | {
20 | foreach (var fm in foldMarkers)
21 | fm.IsFolded = !fm.IsFolded;
22 | }
23 | else
24 | {
25 | foldMarkers = textArea.Document.FoldingManager.GetFoldingsContainsLineNumber(textArea.Caret.Line);
26 | if (foldMarkers.Count != 0)
27 | {
28 | var innerMost = foldMarkers[index: 0];
29 | for (var i = 1; i < foldMarkers.Count; i++)
30 | if (new TextLocation(foldMarkers[i].StartColumn, foldMarkers[i].StartLine) >
31 | new TextLocation(innerMost.StartColumn, innerMost.StartLine))
32 | innerMost = foldMarkers[i];
33 | innerMost.IsFolded = !innerMost.IsFolded;
34 | }
35 | }
36 |
37 | textArea.Document.FoldingManager.NotifyFoldingsChanged(EventArgs.Empty);
38 | }
39 | }
40 |
41 | public class ToggleAllFoldings : AbstractEditAction
42 | {
43 | public override void Execute(TextArea textArea)
44 | {
45 | var doFold = true;
46 | foreach (var fm in textArea.Document.FoldingManager.FoldMarker)
47 | if (fm.IsFolded)
48 | {
49 | doFold = false;
50 | break;
51 | }
52 |
53 | foreach (var fm in textArea.Document.FoldingManager.FoldMarker)
54 | fm.IsFolded = doFold;
55 | textArea.Document.FoldingManager.NotifyFoldingsChanged(EventArgs.Empty);
56 | }
57 | }
58 |
59 | public class ShowDefinitionsOnly : AbstractEditAction
60 | {
61 | public override void Execute(TextArea textArea)
62 | {
63 | foreach (var fm in textArea.Document.FoldingManager.FoldMarker)
64 | fm.IsFolded = fm.FoldType == FoldType.MemberBody || fm.FoldType == FoldType.Region;
65 | textArea.Document.FoldingManager.NotifyFoldingsChanged(EventArgs.Empty);
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/Project/Src/Actions/IEditAction.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Windows.Forms;
9 |
10 | namespace ICSharpCode.TextEditor.Actions
11 | {
12 | ///
13 | /// To define a new key for the textarea, you must write a class which
14 | /// implements this interface.
15 | ///
16 | public interface IEditAction
17 | {
18 | ///
19 | /// An array of keys on which this edit action occurs.
20 | ///
21 | Keys[] Keys { get; set; }
22 |
23 | ///
24 | /// When the key which is defined per XML is pressed, this method will be launched.
25 | ///
26 | void Execute(TextArea textArea);
27 | }
28 |
29 | ///
30 | /// To define a new key for the textarea, you must write a class which
31 | /// implements this interface.
32 | ///
33 | public abstract class AbstractEditAction : IEditAction
34 | {
35 | ///
36 | /// An array of keys on which this edit action occurs.
37 | ///
38 | public Keys[] Keys { get; set; } = null;
39 |
40 | ///
41 | /// When the key which is defined per XML is pressed, this method will be launched.
42 | ///
43 | public abstract void Execute(TextArea textArea);
44 | }
45 | }
--------------------------------------------------------------------------------
/Project/Src/Document/AbstractSegment.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 |
10 | namespace ICSharpCode.TextEditor.Document
11 | {
12 | ///
13 | /// This interface is used to describe a span inside a text sequence
14 | ///
15 | public class AbstractSegment : ISegment
16 | {
17 | protected int length = -1;
18 |
19 | protected int offset = -1;
20 |
21 | public override string ToString()
22 | {
23 | return string.Format(
24 | "[AbstractSegment: Offset = {0}, Length = {1}]",
25 | Offset,
26 | Length);
27 | }
28 |
29 | #region ICSharpCode.TextEditor.Document.ISegment interface implementation
30 |
31 | public virtual int Offset
32 | {
33 | get => offset;
34 | set => offset = value;
35 | }
36 |
37 | public virtual int Length
38 | {
39 | get => length;
40 | set => length = value;
41 | }
42 |
43 | #endregion
44 | }
45 | }
--------------------------------------------------------------------------------
/Project/Src/Document/BookmarkManager/BookmarkEventHandler.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 |
10 | namespace ICSharpCode.TextEditor.Document
11 | {
12 | public delegate void BookmarkEventHandler(object sender, BookmarkEventArgs e);
13 |
14 | ///
15 | /// Description of BookmarkEventHandler.
16 | ///
17 | public class BookmarkEventArgs : EventArgs
18 | {
19 | public BookmarkEventArgs(Bookmark bookmark)
20 | {
21 | Bookmark = bookmark;
22 | }
23 |
24 | public Bookmark Bookmark { get; }
25 | }
26 | }
--------------------------------------------------------------------------------
/Project/Src/Document/BookmarkManager/BookmarkManagerMemento.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Collections.Generic;
9 | using System.Xml;
10 |
11 | namespace ICSharpCode.TextEditor.Document
12 | {
13 | ///
14 | /// This class is used for storing the state of a bookmark manager
15 | ///
16 | public class BookmarkManagerMemento
17 | {
18 | ///
19 | /// Creates a new instance of
20 | ///
21 | public BookmarkManagerMemento()
22 | {
23 | }
24 |
25 | ///
26 | /// Creates a new instance of
27 | ///
28 | public BookmarkManagerMemento(XmlElement element)
29 | {
30 | foreach (XmlElement el in element.ChildNodes)
31 | Bookmarks.Add(int.Parse(el.Attributes["line"].InnerText));
32 | }
33 |
34 | ///
35 | /// Creates a new instance of
36 | ///
37 | public BookmarkManagerMemento(List bookmarks)
38 | {
39 | Bookmarks = bookmarks;
40 | }
41 |
42 | ///
43 | /// Contains all bookmarks as int values
44 | ///
45 | public List Bookmarks { get; set; } = new List();
46 |
47 | ///
48 | /// Validates all bookmarks if they're in range of the document.
49 | /// (removing all bookmarks < 0 and bookmarks > max. line number
50 | ///
51 | public void CheckMemento(IDocument document)
52 | {
53 | for (var i = 0; i < Bookmarks.Count; ++i)
54 | {
55 | var mark = Bookmarks[i];
56 | if (mark < 0 || mark >= document.TotalNumberOfLines)
57 | {
58 | Bookmarks.RemoveAt(i);
59 | --i;
60 | }
61 | }
62 | }
63 |
64 | ///
65 | /// Converts a xml element to a object
66 | ///
67 | public object FromXmlElement(XmlElement element)
68 | {
69 | return new BookmarkManagerMemento(element);
70 | }
71 |
72 | ///
73 | /// Converts this to a xml element
74 | ///
75 | public XmlElement ToXmlElement(XmlDocument doc)
76 | {
77 | var bookmarknode = doc.CreateElement("Bookmarks");
78 |
79 | foreach (var line in Bookmarks)
80 | {
81 | var markNode = doc.CreateElement("Mark");
82 |
83 | var lineAttr = doc.CreateAttribute("line");
84 | lineAttr.InnerText = line.ToString();
85 | markNode.Attributes.Append(lineAttr);
86 |
87 | bookmarknode.AppendChild(markNode);
88 | }
89 |
90 | return bookmarknode;
91 | }
92 | }
93 | }
--------------------------------------------------------------------------------
/Project/Src/Document/DefaultTextEditorProperties.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Drawing;
9 | using System.Drawing.Text;
10 | using System.Text;
11 |
12 | namespace ICSharpCode.TextEditor.Document
13 | {
14 | public enum BracketMatchingStyle
15 | {
16 | Before,
17 | After
18 | }
19 |
20 | public class DefaultTextEditorProperties : ITextEditorProperties
21 | {
22 | private static Font DefaultFont;
23 |
24 | public DefaultTextEditorProperties()
25 | {
26 | if (DefaultFont == null)
27 | DefaultFont = new Font("Courier New", emSize: 10);
28 | FontContainer = new FontContainer(DefaultFont);
29 | }
30 |
31 | public int TabIndent { get; set; } = 4;
32 |
33 | public int IndentationSize { get; set; } = 4;
34 |
35 | public IndentStyle IndentStyle { get; set; } = IndentStyle.Smart;
36 |
37 | public bool CaretLine { get; set; } = false;
38 |
39 | public DocumentSelectionMode DocumentSelectionMode { get; set; } = DocumentSelectionMode.Normal;
40 |
41 | public bool AllowCaretBeyondEOL { get; set; } = false;
42 |
43 | public bool ShowMatchingBracket { get; set; } = true;
44 |
45 | public bool ShowLineNumbers { get; set; } = true;
46 |
47 | public bool ShowSpaces { get; set; } = false;
48 |
49 | public bool ShowTabs { get; set; } = false;
50 |
51 | public EolMarkerStyle EolMarkerStyle { get; set; } = EolMarkerStyle.None;
52 |
53 | public bool ShowInvalidLines { get; set; } = false;
54 |
55 | public bool IsIconBarVisible { get; set; } = false;
56 |
57 | public bool EnableFolding { get; set; } = true;
58 |
59 | public bool ShowHorizontalRuler { get; set; } = false;
60 |
61 | public bool ShowVerticalRuler { get; set; } = true;
62 |
63 | public bool ConvertTabsToSpaces { get; set; } = false;
64 |
65 | public TextRenderingHint TextRenderingHint { get; set; } = TextRenderingHint.SystemDefault;
66 |
67 | public bool MouseWheelScrollDown { get; set; } = true;
68 |
69 | public bool MouseWheelTextZoom { get; set; } = true;
70 |
71 | public bool HideMouseCursor { get; set; } = false;
72 |
73 | public bool CutCopyWholeLine { get; set; } = true;
74 |
75 | public Encoding Encoding { get; set; } = Encoding.UTF8;
76 |
77 | public int VerticalRulerRow { get; set; } = 80;
78 |
79 | public LineViewerStyle LineViewerStyle { get; set; } = LineViewerStyle.None;
80 |
81 | public string LineTerminator { get; set; } = "\r\n";
82 |
83 | public bool AutoInsertCurlyBracket { get; set; } = true;
84 |
85 | public Font Font
86 | {
87 | get => FontContainer.DefaultFont;
88 | set => FontContainer.DefaultFont = value;
89 | }
90 |
91 | public FontContainer FontContainer { get; }
92 |
93 | public BracketMatchingStyle BracketMatchingStyle { get; set; } = BracketMatchingStyle.After;
94 |
95 | public bool SupportReadOnlySegments { get; set; } = false;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/Project/Src/Document/DocumentEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 |
10 | namespace ICSharpCode.TextEditor.Document
11 | {
12 | ///
13 | /// This delegate is used for document events.
14 | ///
15 | public delegate void DocumentEventHandler(object sender, DocumentEventArgs e);
16 |
17 | ///
18 | /// This class contains more information on a document event
19 | ///
20 | public class DocumentEventArgs : EventArgs
21 | {
22 | ///
23 | /// Creates a new instance off
24 | ///
25 | public DocumentEventArgs(IDocument document) : this(document, offset: -1, length: -1, text: null)
26 | {
27 | }
28 |
29 | ///
30 | /// Creates a new instance off
31 | ///
32 | public DocumentEventArgs(IDocument document, int offset) : this(document, offset, length: -1, text: null)
33 | {
34 | }
35 |
36 | ///
37 | /// Creates a new instance off
38 | ///
39 | public DocumentEventArgs(IDocument document, int offset, int length) : this(document, offset, length, text: null)
40 | {
41 | }
42 |
43 | ///
44 | /// Creates a new instance off
45 | ///
46 | public DocumentEventArgs(IDocument document, int offset, int length, string text)
47 | {
48 | Document = document;
49 | Offset = offset;
50 | Length = length;
51 | Text = text;
52 | }
53 |
54 | ///
55 | /// always a valid Document which is related to the Event.
56 | ///
57 | public IDocument Document { get; }
58 |
59 | ///
60 | /// -1 if no offset was specified for this event
61 | ///
62 | public int Offset { get; }
63 |
64 | ///
65 | /// null if no text was specified for this event
66 | ///
67 | public string Text { get; }
68 |
69 | ///
70 | /// -1 if no length was specified for this event
71 | ///
72 | public int Length { get; }
73 |
74 | public override string ToString()
75 | {
76 | return string.Format(
77 | "[DocumentEventArgs: Document = {0}, Offset = {1}, Text = {2}, Length = {3}]",
78 | Document,
79 | Offset,
80 | Text,
81 | Length);
82 | }
83 | }
84 | }
--------------------------------------------------------------------------------
/Project/Src/Document/DocumentFactory.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Text;
9 | using ICSharpCode.TextEditor.Util;
10 |
11 | namespace ICSharpCode.TextEditor.Document
12 | {
13 | ///
14 | /// This interface represents a container which holds a text sequence and
15 | /// all necessary information about it. It is used as the base for a text editor.
16 | ///
17 | public class DocumentFactory
18 | {
19 | ///
20 | /// Creates a new object. Only create
21 | /// with this method.
22 | ///
23 | public IDocument CreateDocument()
24 | {
25 | var doc = new DefaultDocument();
26 | doc.TextBufferStrategy = new GapTextBufferStrategy();
27 | doc.FormattingStrategy = new DefaultFormattingStrategy();
28 | doc.LineManager = new LineManager(doc, highlightingStrategy: null);
29 | doc.FoldingManager = new FoldingManager(doc);
30 | doc.FoldingManager.FoldingStrategy = null; //new ParserFoldingStrategy();
31 | doc.MarkerStrategy = new MarkerStrategy(doc);
32 | doc.BookmarkManager = new BookmarkManager(doc);
33 | return doc;
34 | }
35 |
36 | ///
37 | /// Creates a new document and loads the given file
38 | ///
39 | public IDocument CreateFromTextBuffer(ITextBufferStrategy textBuffer)
40 | {
41 | var doc = (DefaultDocument)CreateDocument();
42 | doc.TextContent = textBuffer.GetText(offset: 0, textBuffer.Length);
43 | doc.TextBufferStrategy = textBuffer;
44 | return doc;
45 | }
46 |
47 | ///
48 | /// Creates a new document and loads the given file
49 | ///
50 | public IDocument CreateFromFile(string fileName)
51 | {
52 | var document = CreateDocument();
53 | document.TextContent = FileReader.ReadFileContent(fileName, Encoding.Default);
54 | return document;
55 | }
56 | }
57 | }
--------------------------------------------------------------------------------
/Project/Src/Document/EolMarkerStyle.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | namespace ICSharpCode.TextEditor.Document
9 | {
10 | public enum EolMarkerStyle
11 | {
12 | None,
13 | Glyph,
14 | Text
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Project/Src/Document/FoldingStrategy/IFoldingStrategy.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Collections.Generic;
9 |
10 | namespace ICSharpCode.TextEditor.Document
11 | {
12 | ///
13 | /// This interface is used for the folding capabilities
14 | /// of the textarea.
15 | ///
16 | public interface IFoldingStrategy
17 | {
18 | ///
19 | /// Calculates the fold level of a specific line.
20 | ///
21 | List GenerateFoldMarkers(IDocument document, string fileName, object parseInformation);
22 | }
23 | }
--------------------------------------------------------------------------------
/Project/Src/Document/FoldingStrategy/IndentFoldingStrategy.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Collections.Generic;
9 |
10 | namespace ICSharpCode.TextEditor.Document
11 | {
12 | ///
13 | /// A simple folding strategy which calculates the folding level
14 | /// using the indent level of the line.
15 | ///
16 | public class IndentFoldingStrategy : IFoldingStrategy
17 | {
18 | public List GenerateFoldMarkers(IDocument document, string fileName, object parseInformation)
19 | {
20 | var l = new List();
21 | // var offsetStack = new Stack();
22 | // var textStack = new Stack();
23 | //int level = 0;
24 | //foreach (LineSegment segment in document.LineSegmentCollection) {
25 | //
26 | //}
27 | return l;
28 | }
29 |
30 | private int GetLevel(IDocument document, int offset)
31 | {
32 | var level = 0;
33 | var spaces = 0;
34 | for (var i = offset; i < document.TextLength; ++i)
35 | {
36 | var c = document.GetCharAt(i);
37 | if (c == '\t' || c == ' ' && ++spaces == 4)
38 | {
39 | spaces = 0;
40 | ++level;
41 | }
42 | else
43 | {
44 | break;
45 | }
46 | }
47 |
48 | return level;
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/Project/Src/Document/FormattingStrategy/IFormattingStrategy.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | namespace ICSharpCode.TextEditor.Document
9 | {
10 | ///
11 | /// This interface handles the auto and smart indenting and formating
12 | /// in the document while you type. Language bindings could overwrite this
13 | /// interface and define their own indentation/formating.
14 | ///
15 | public interface IFormattingStrategy
16 | {
17 | ///
18 | /// This function formats a specific line after ch
is pressed.
19 | ///
20 | void FormatLine(TextArea textArea, int line, int caretOffset, char charTyped);
21 |
22 | ///
23 | /// This function sets the indentation level in a specific line
24 | ///
25 | ///
26 | /// The target caret position (length of new indentation).
27 | ///
28 | int IndentLine(TextArea textArea, int line);
29 |
30 | ///
31 | /// This function sets the indentlevel in a range of lines.
32 | ///
33 | void IndentLines(TextArea textArea, int begin, int end);
34 |
35 | ///
36 | /// Finds the offset of the opening bracket in the block defined by offset skipping
37 | /// brackets in strings and comments.
38 | ///
39 | /// The document to search in.
40 | /// The offset of an position in the block or the offset of the closing bracket.
41 | /// The character for the opening bracket.
42 | /// The character for the closing bracket.
43 | /// Returns the offset of the opening bracket or -1 if no matching bracket was found.
44 | int SearchBracketBackward(IDocument document, int offset, char openBracket, char closingBracket);
45 |
46 | ///
47 | /// Finds the offset of the closing bracket in the block defined by offset skipping
48 | /// brackets in strings and comments.
49 | ///
50 | /// The document to search in.
51 | /// The offset of an position in the block or the offset of the opening bracket.
52 | /// The character for the opening bracket.
53 | /// The character for the closing bracket.
54 | /// Returns the offset of the closing bracket or -1 if no matching bracket was found.
55 | int SearchBracketForward(IDocument document, int offset, char openBracket, char closingBracket);
56 | }
57 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/FontContainer.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Drawing;
10 |
11 | namespace ICSharpCode.TextEditor.Document
12 | {
13 | ///
14 | /// This class is used to generate bold, italic and bold/italic fonts out
15 | /// of a base font.
16 | ///
17 | public class FontContainer
18 | {
19 | private static float twipsPerPixelY;
20 | private Font defaultFont;
21 |
22 | public FontContainer(Font defaultFont)
23 | {
24 | DefaultFont = defaultFont;
25 | }
26 |
27 | ///
28 | /// The scaled, regular version of the base font
29 | ///
30 | public Font RegularFont { get; private set; }
31 |
32 | ///
33 | /// The scaled, bold version of the base font
34 | ///
35 | public Font BoldFont { get; private set; }
36 |
37 | ///
38 | /// The scaled, italic version of the base font
39 | ///
40 | public Font ItalicFont { get; private set; }
41 |
42 | ///
43 | /// The scaled, bold/italic version of the base font
44 | ///
45 | public Font BoldItalicFont { get; private set; }
46 |
47 | public static float TwipsPerPixelY
48 | {
49 | get
50 | {
51 | if (twipsPerPixelY == 0)
52 | using (var bmp = new Bitmap(width: 1, height: 1))
53 | {
54 | using (var g = Graphics.FromImage(bmp))
55 | {
56 | twipsPerPixelY = 1440/g.DpiY;
57 | }
58 | }
59 |
60 | return twipsPerPixelY;
61 | }
62 | }
63 |
64 | ///
65 | /// The base font
66 | ///
67 | public Font DefaultFont
68 | {
69 | get => defaultFont;
70 | set
71 | {
72 | // 1440 twips is one inch
73 | var pixelSize = (float)Math.Round(value.SizeInPoints*20/TwipsPerPixelY);
74 |
75 | defaultFont = value;
76 | RegularFont = new Font(value.FontFamily, pixelSize*TwipsPerPixelY/20f, FontStyle.Regular);
77 | BoldFont = new Font(RegularFont, FontStyle.Bold);
78 | ItalicFont = new Font(RegularFont, FontStyle.Italic);
79 | BoldItalicFont = new Font(RegularFont, FontStyle.Bold | FontStyle.Italic);
80 | }
81 | }
82 |
83 | public static Font ParseFont(string font)
84 | {
85 | var descr = font.Split(',', '=');
86 | return new Font(descr[1], float.Parse(descr[3]));
87 | }
88 | }
89 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/HighlightBackground.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Drawing;
9 | using System.Xml;
10 |
11 | namespace ICSharpCode.TextEditor.Document
12 | {
13 | ///
14 | /// Extens the highlighting color with a background image.
15 | ///
16 | public class HighlightBackground : HighlightColor
17 | {
18 | ///
19 | /// Creates a new instance of
20 | ///
21 | public HighlightBackground(XmlElement el) : base(el)
22 | {
23 | if (el.Attributes["image"] != null)
24 | BackgroundImage = new Bitmap(el.Attributes["image"].InnerText);
25 | }
26 |
27 | ///
28 | /// Creates a new instance of
29 | ///
30 | public HighlightBackground(string systemColor, string systemBackgroundColor, bool bold, bool italic) : base(systemColor, systemBackgroundColor, bold, italic)
31 | {
32 | }
33 |
34 | ///
35 | /// The image used as background
36 | ///
37 | public Image BackgroundImage { get; }
38 | }
39 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/HighlightInfo.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | namespace ICSharpCode.TextEditor.Document
9 | {
10 | public class HighlightInfo
11 | {
12 | public bool BlockSpanOn;
13 | public Span CurSpan;
14 | public bool Span;
15 |
16 | public HighlightInfo(Span curSpan, bool span, bool blockSpanOn)
17 | {
18 | CurSpan = curSpan;
19 | Span = span;
20 | BlockSpanOn = blockSpanOn;
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/HighlightingColorNotFoundException.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Runtime.Serialization;
10 |
11 | namespace ICSharpCode.TextEditor.Document
12 | {
13 | public class HighlightingColorNotFoundException : Exception
14 | {
15 | public HighlightingColorNotFoundException()
16 | {
17 | }
18 |
19 | public HighlightingColorNotFoundException(string message) : base(message)
20 | {
21 | }
22 |
23 | public HighlightingColorNotFoundException(string message, Exception innerException) : base(message, innerException)
24 | {
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/HighlightingDefinitionInvalidException.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Runtime.Serialization;
10 |
11 | namespace ICSharpCode.TextEditor.Document
12 | {
13 | ///
14 | /// Indicates that the highlighting definition that was tried to load was invalid.
15 | /// You get this exception only once per highlighting definition, after that the definition
16 | /// is replaced with the default highlighter.
17 | ///
18 | public class HighlightingDefinitionInvalidException : Exception
19 | {
20 | public HighlightingDefinitionInvalidException()
21 | {
22 | }
23 |
24 | public HighlightingDefinitionInvalidException(string message) : base(message)
25 | {
26 | }
27 |
28 | public HighlightingDefinitionInvalidException(string message, Exception innerException) : base(message, innerException)
29 | {
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/HighlightingStrategyFactory.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | namespace ICSharpCode.TextEditor.Document
9 | {
10 | public class HighlightingStrategyFactory
11 | {
12 | public static IHighlightingStrategy CreateHighlightingStrategy()
13 | {
14 | return (IHighlightingStrategy)HighlightingManager.Manager.HighlightingDefinitions["Default"];
15 | }
16 |
17 | public static IHighlightingStrategy CreateHighlightingStrategy(string name)
18 | {
19 | var highlightingStrategy = HighlightingManager.Manager.FindHighlighter(name);
20 |
21 | if (highlightingStrategy == null)
22 | return CreateHighlightingStrategy();
23 | return highlightingStrategy;
24 | }
25 |
26 | public static IHighlightingStrategy CreateHighlightingStrategyForFile(string fileName)
27 | {
28 | var highlightingStrategy = HighlightingManager.Manager.FindHighlighterForFile(fileName);
29 | if (highlightingStrategy == null)
30 | return CreateHighlightingStrategy();
31 | return highlightingStrategy;
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/IHighlightingStrategy.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Collections.Generic;
9 |
10 | namespace ICSharpCode.TextEditor.Document
11 | {
12 | ///
13 | /// A highlighting strategy for a buffer.
14 | ///
15 | public interface IHighlightingStrategy
16 | {
17 | ///
18 | /// The name of the highlighting strategy, must be unique
19 | ///
20 | string Name { get; }
21 |
22 | ///
23 | /// The file extenstions on which this highlighting strategy gets
24 | /// used
25 | ///
26 | string[] Extensions { get; }
27 |
28 | Dictionary Properties { get; }
29 |
30 | // returns special color. (BackGround Color, Cursor Color and so on)
31 |
32 | ///
33 | /// Gets the color of an Environment element.
34 | ///
35 | HighlightColor GetColorFor(string name);
36 |
37 | ///
38 | /// Used internally, do not call
39 | ///
40 | void MarkTokens(IDocument document, List lines);
41 |
42 | ///
43 | /// Used internally, do not call
44 | ///
45 | void MarkTokens(IDocument document);
46 | }
47 |
48 | public interface IHighlightingStrategyUsingRuleSets : IHighlightingStrategy
49 | {
50 | ///
51 | /// Used internally, do not call
52 | ///
53 | HighlightRuleSet GetRuleSet(Span span);
54 |
55 | ///
56 | /// Used internally, do not call
57 | ///
58 | HighlightColor GetColor(IDocument document, LineSegment keyWord, int index, int length);
59 | }
60 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/NextMarker.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Xml;
9 |
10 | namespace ICSharpCode.TextEditor.Document
11 | {
12 | ///
13 | /// Used for mark next token
14 | ///
15 | public class NextMarker
16 | {
17 | ///
18 | /// Creates a new instance of
19 | ///
20 | public NextMarker(XmlElement mark)
21 | {
22 | Color = new HighlightColor(mark);
23 | What = mark.InnerText;
24 | if (mark.Attributes["markmarker"] != null)
25 | MarkMarker = bool.Parse(mark.Attributes["markmarker"].InnerText);
26 | }
27 |
28 | ///
29 | /// String value to indicate to mark next token
30 | ///
31 | public string What { get; }
32 |
33 | ///
34 | /// Color for marking next token
35 | ///
36 | public HighlightColor Color { get; }
37 |
38 | ///
39 | /// If true the indication text will be marked with the same color
40 | /// too
41 | ///
42 | public bool MarkMarker { get; }
43 | }
44 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/PrevMarker.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Xml;
9 |
10 | namespace ICSharpCode.TextEditor.Document
11 | {
12 | ///
13 | /// Used for mark previous token
14 | ///
15 | public class PrevMarker
16 | {
17 | ///
18 | /// Creates a new instance of
19 | ///
20 | public PrevMarker(XmlElement mark)
21 | {
22 | Color = new HighlightColor(mark);
23 | What = mark.InnerText;
24 | if (mark.Attributes["markmarker"] != null)
25 | MarkMarker = bool.Parse(mark.Attributes["markmarker"].InnerText);
26 | }
27 |
28 | ///
29 | /// String value to indicate to mark previous token
30 | ///
31 | public string What { get; }
32 |
33 | ///
34 | /// Color for marking previous token
35 | ///
36 | public HighlightColor Color { get; }
37 |
38 | ///
39 | /// If true the indication text will be marked with the same color
40 | /// too
41 | ///
42 | public bool MarkMarker { get; }
43 | }
44 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/Span.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Xml;
9 |
10 | namespace ICSharpCode.TextEditor.Document
11 | {
12 | public sealed class Span
13 | {
14 | private readonly HighlightColor beginColor;
15 | private readonly HighlightColor endColor;
16 |
17 | public Span(XmlElement span)
18 | {
19 | Color = new HighlightColor(span);
20 |
21 | if (span.HasAttribute("rule"))
22 | Rule = span.GetAttribute("rule");
23 |
24 | if (span.HasAttribute("escapecharacter"))
25 | EscapeCharacter = span.GetAttribute("escapecharacter")[index: 0];
26 |
27 | Name = span.GetAttribute("name");
28 | if (span.HasAttribute("stopateol"))
29 | StopEOL = bool.Parse(span.GetAttribute("stopateol"));
30 |
31 | Begin = span["Begin"].InnerText.ToCharArray();
32 | beginColor = new HighlightColor(span["Begin"], Color);
33 |
34 | if (span["Begin"].HasAttribute("singleword"))
35 | IsBeginSingleWord = bool.Parse(span["Begin"].GetAttribute("singleword"));
36 | if (span["Begin"].HasAttribute("startofline"))
37 | IsBeginStartOfLine = bool.Parse(span["Begin"].GetAttribute("startofline"));
38 |
39 | if (span["End"] != null)
40 | {
41 | End = span["End"].InnerText.ToCharArray();
42 | endColor = new HighlightColor(span["End"], Color);
43 | if (span["End"].HasAttribute("singleword"))
44 | IsEndSingleWord = bool.Parse(span["End"].GetAttribute("singleword"));
45 | }
46 | }
47 |
48 | internal HighlightRuleSet RuleSet { get; set; }
49 |
50 | public bool IgnoreCase { get; set; }
51 |
52 | public bool StopEOL { get; }
53 |
54 | public bool? IsBeginStartOfLine { get; }
55 |
56 | public bool IsBeginSingleWord { get; }
57 |
58 | public bool IsEndSingleWord { get; }
59 |
60 | public HighlightColor Color { get; }
61 |
62 | public HighlightColor BeginColor
63 | {
64 | get
65 | {
66 | if (beginColor != null)
67 | return beginColor;
68 |
69 | return Color;
70 | }
71 | }
72 |
73 | public HighlightColor EndColor => endColor ?? Color;
74 |
75 | public char[] Begin { get; }
76 |
77 | public char[] End { get; }
78 |
79 | public string Name { get; }
80 |
81 | public string Rule { get; }
82 |
83 | ///
84 | /// Gets the escape character of the span. The escape character is a character that can be used in front
85 | /// of the span end to make it not end the span. The escape character followed by another escape character
86 | /// means the escape character was escaped like in @"a "" b" literals in C#.
87 | /// The default value '\0' means no escape character is allowed.
88 | ///
89 | public char EscapeCharacter { get; }
90 | }
91 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/SpanStack.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Collections;
10 | using System.Collections.Generic;
11 |
12 | namespace ICSharpCode.TextEditor.Document
13 | {
14 | ///
15 | /// A stack of Span instances. Works like Stack<Span>, but can be cloned quickly
16 | /// because it is implemented as linked list.
17 | ///
18 | public sealed class SpanStack : ICloneable, IEnumerable
19 | {
20 | private StackNode top;
21 |
22 | public bool IsEmpty => top == null;
23 |
24 | object ICloneable.Clone()
25 | {
26 | return Clone();
27 | }
28 |
29 | IEnumerator IEnumerable.GetEnumerator()
30 | {
31 | return GetEnumerator();
32 | }
33 |
34 | IEnumerator IEnumerable.GetEnumerator()
35 | {
36 | return GetEnumerator();
37 | }
38 |
39 | public Span Pop()
40 | {
41 | var s = top.Data;
42 | top = top.Previous;
43 | return s;
44 | }
45 |
46 | public Span Peek()
47 | {
48 | return top.Data;
49 | }
50 |
51 | public void Push(Span s)
52 | {
53 | top = new StackNode(top, s);
54 | }
55 |
56 | public SpanStack Clone()
57 | {
58 | var n = new SpanStack();
59 | n.top = top;
60 | return n;
61 | }
62 |
63 | public Enumerator GetEnumerator()
64 | {
65 | return new Enumerator(new StackNode(top, data: null));
66 | }
67 |
68 | internal sealed class StackNode
69 | {
70 | public readonly Span Data;
71 | public readonly StackNode Previous;
72 |
73 | public StackNode(StackNode previous, Span data)
74 | {
75 | Previous = previous;
76 | Data = data;
77 | }
78 | }
79 |
80 | public struct Enumerator : IEnumerator
81 | {
82 | private StackNode c;
83 |
84 | internal Enumerator(StackNode node)
85 | {
86 | c = node;
87 | }
88 |
89 | public Span Current => c.Data;
90 |
91 | object IEnumerator.Current => c.Data;
92 |
93 | public void Dispose()
94 | {
95 | c = null;
96 | }
97 |
98 | public bool MoveNext()
99 | {
100 | c = c.Previous;
101 | return c != null;
102 | }
103 |
104 | public void Reset()
105 | {
106 | throw new NotSupportedException();
107 | }
108 | }
109 | }
110 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/SyntaxModes/FileSyntaxModeProvider.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Collections.Generic;
10 | using System.IO;
11 | using System.Xml;
12 |
13 | namespace ICSharpCode.TextEditor.Document
14 | {
15 | public class FileSyntaxModeProvider : ISyntaxModeFileProvider
16 | {
17 | private readonly string directory;
18 | private List syntaxModes;
19 |
20 | public FileSyntaxModeProvider(string directory)
21 | {
22 | this.directory = directory;
23 | UpdateSyntaxModeList();
24 | }
25 |
26 | public ICollection SyntaxModes => syntaxModes;
27 |
28 | public void UpdateSyntaxModeList()
29 | {
30 | var syntaxModeFile = Path.Combine(directory, "SyntaxModes.xml");
31 |
32 | if (File.Exists(syntaxModeFile))
33 | {
34 | using (var s = File.OpenRead(syntaxModeFile))
35 | {
36 | syntaxModes = SyntaxMode.GetSyntaxModes(s);
37 | }
38 | }
39 | else
40 | {
41 | syntaxModes = ScanDirectory(directory);
42 | }
43 | }
44 |
45 | public XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode)
46 | {
47 | var syntaxModeFile = Path.Combine(directory, syntaxMode.FileName);
48 | if (!File.Exists(syntaxModeFile))
49 | throw new HighlightingDefinitionInvalidException("Can't load highlighting definition " + syntaxModeFile + " (file not found)!");
50 | return new XmlTextReader(File.OpenRead(syntaxModeFile));
51 | }
52 |
53 | private static List ScanDirectory(string directory)
54 | {
55 | var files = Directory.GetFiles(directory);
56 | var modes = new List();
57 | foreach (var file in files)
58 | if (Path.GetExtension(file).Equals(".XSHD", StringComparison.OrdinalIgnoreCase))
59 | {
60 | var reader = new XmlTextReader(file);
61 | while (reader.Read())
62 | if (reader.NodeType == XmlNodeType.Element)
63 | switch (reader.Name)
64 | {
65 | case "SyntaxDefinition":
66 | var name = reader.GetAttribute("name");
67 | var extensions = reader.GetAttribute("extensions");
68 | modes.Add(
69 | new SyntaxMode(
70 | Path.GetFileName(file),
71 | name,
72 | extensions));
73 | goto bailout;
74 | default:
75 | throw new HighlightingDefinitionInvalidException("Unknown root node in syntax highlighting file :" + reader.Name);
76 | }
77 | bailout:
78 | reader.Close();
79 | }
80 |
81 | return modes;
82 | }
83 | }
84 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/SyntaxModes/ISyntaxModeFileProvider.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Collections.Generic;
9 | using System.Xml;
10 |
11 | namespace ICSharpCode.TextEditor.Document
12 | {
13 | public interface ISyntaxModeFileProvider
14 | {
15 | ICollection SyntaxModes { get; }
16 |
17 | XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode);
18 | void UpdateSyntaxModeList();
19 | }
20 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/SyntaxModes/ResourceSyntaxModeProvider.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Collections.Generic;
9 | using System.Xml;
10 |
11 | namespace ICSharpCode.TextEditor.Document
12 | {
13 | public class ResourceSyntaxModeProvider : ISyntaxModeFileProvider
14 | {
15 | private readonly List syntaxModes;
16 |
17 | public ResourceSyntaxModeProvider()
18 | {
19 | var assembly = typeof(SyntaxMode).Assembly;
20 | var syntaxModeStream = assembly.GetManifestResourceStream("ICSharpCode.TextEditor.Resources.SyntaxModes.xml");
21 | if (syntaxModeStream != null)
22 | syntaxModes = SyntaxMode.GetSyntaxModes(syntaxModeStream);
23 | else
24 | syntaxModes = new List();
25 | }
26 |
27 | public ICollection SyntaxModes => syntaxModes;
28 |
29 | public XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode)
30 | {
31 | var assembly = typeof(SyntaxMode).Assembly;
32 | var stream = assembly.GetManifestResourceStream($"ICSharpCode.TextEditor.Resources.{syntaxMode.FileName}");
33 | return new XmlTextReader(stream);
34 | }
35 |
36 | public void UpdateSyntaxModeList()
37 | {
38 | // resources don't change during runtime
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/Project/Src/Document/HighlightingStrategy/SyntaxModes/SyntaxMode.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Collections.Generic;
9 | using System.IO;
10 | using System.Xml;
11 |
12 | namespace ICSharpCode.TextEditor.Document
13 | {
14 | public class SyntaxMode
15 | {
16 | public SyntaxMode(string fileName, string name, string extensions)
17 | {
18 | FileName = fileName;
19 | Name = name;
20 | Extensions = extensions.Split(';', '|', ',');
21 | }
22 |
23 | public SyntaxMode(string fileName, string name, string[] extensions)
24 | {
25 | FileName = fileName;
26 | Name = name;
27 | Extensions = extensions;
28 | }
29 |
30 | public string FileName { get; }
31 | public string Name { get; }
32 | public string[] Extensions { get; }
33 |
34 | public static List GetSyntaxModes(Stream xmlSyntaxModeStream)
35 | {
36 | using (var reader = new XmlTextReader(xmlSyntaxModeStream))
37 | {
38 | var syntaxModes = new List();
39 |
40 | while (reader.Read())
41 | {
42 | switch (reader.NodeType)
43 | {
44 | case XmlNodeType.Element:
45 | switch (reader.Name)
46 | {
47 | case "SyntaxModes":
48 | var version = reader.GetAttribute("version");
49 | if (version != "1.0")
50 | throw new HighlightingDefinitionInvalidException("Unknown syntax mode file defininition with version " + version);
51 | break;
52 | case "Mode":
53 | syntaxModes.Add(
54 | new SyntaxMode(
55 | reader.GetAttribute("file"),
56 | reader.GetAttribute("name"),
57 | reader.GetAttribute("extensions")));
58 | break;
59 | default:
60 | throw new HighlightingDefinitionInvalidException("Unknown node in syntax mode file :" + reader.Name);
61 | }
62 |
63 | break;
64 | }
65 | }
66 |
67 | return syntaxModes;
68 | }
69 | }
70 |
71 | public override string ToString()
72 | {
73 | return string.Format("[SyntaxMode: FileName={0}, Name={1}, Extensions=({2})]", FileName, Name, string.Join(",", Extensions));
74 | }
75 | }
76 | }
--------------------------------------------------------------------------------
/Project/Src/Document/ISegment.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Collections.Generic;
9 |
10 | namespace ICSharpCode.TextEditor.Document
11 | {
12 | ///
13 | /// This interface is used to describe a span inside a text sequence
14 | ///
15 | public interface ISegment
16 | {
17 | ///
18 | /// The offset where the span begins
19 | ///
20 | int Offset { get; set; }
21 |
22 | ///
23 | /// The length of the span
24 | ///
25 | int Length { get; set; }
26 | }
27 |
28 | public class SegmentComparer : IComparer
29 | {
30 | public int Compare(ISegment x, ISegment y)
31 | {
32 | if (x == null)
33 | {
34 | if (y == null)
35 | return 0;
36 |
37 | // If x is null and y is not null, y
38 | // is greater.
39 | return -1;
40 | }
41 |
42 | // If x is not null and y is null, x is greater.
43 | if (y == null)
44 | return 1;
45 |
46 | var retval = x.Offset.CompareTo(y.Offset);
47 | if (retval != 0)
48 | return retval;
49 |
50 | return x.Length.CompareTo(y.Length);
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/Project/Src/Document/LineManager/DeferredEventList.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Collections.Generic;
9 |
10 | namespace ICSharpCode.TextEditor.Document
11 | {
12 | ///
13 | /// A list of events that are fired after the line manager has finished working.
14 | ///
15 | internal struct DeferredEventList
16 | {
17 | internal List removedLines;
18 | internal List textAnchor;
19 |
20 | public void AddRemovedLine(LineSegment line)
21 | {
22 | if (removedLines == null)
23 | removedLines = new List();
24 | removedLines.Add(line);
25 | }
26 |
27 | public void AddDeletedAnchor(TextAnchor anchor)
28 | {
29 | if (textAnchor == null)
30 | textAnchor = new List();
31 | textAnchor.Add(anchor);
32 | }
33 |
34 | public void RaiseEvents()
35 | {
36 | // removedLines is raised by the LineManager
37 | if (textAnchor != null)
38 | foreach (var a in textAnchor)
39 | a.RaiseDeleted();
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/Project/Src/Document/LineManager/EolMarker.cs:
--------------------------------------------------------------------------------
1 | namespace ICSharpCode.TextEditor.Document
2 | {
3 | public enum EolMarker
4 | {
5 | None,
6 | Cr, // "\r"
7 | CrLf, // "\r\n"
8 | Lf // "\n"
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Project/Src/Document/LineManager/LineManagerEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 |
10 | namespace ICSharpCode.TextEditor.Document
11 | {
12 | public class LineCountChangeEventArgs : EventArgs
13 | {
14 | public LineCountChangeEventArgs(IDocument document, int lineStart, int linesMoved)
15 | {
16 | Document = document;
17 | LineStart = lineStart;
18 | LinesMoved = linesMoved;
19 | }
20 |
21 | ///
22 | /// always a valid Document which is related to the Event.
23 | ///
24 | public IDocument Document { get; }
25 |
26 | ///
27 | /// -1 if no offset was specified for this event
28 | ///
29 | public int LineStart { get; }
30 |
31 | ///
32 | /// -1 if no length was specified for this event
33 | ///
34 | public int LinesMoved { get; }
35 | }
36 |
37 | public class LineEventArgs : EventArgs
38 | {
39 | public LineEventArgs(IDocument document, LineSegment lineSegment)
40 | {
41 | Document = document;
42 | LineSegment = lineSegment;
43 | }
44 |
45 | public IDocument Document { get; }
46 |
47 | public LineSegment LineSegment { get; }
48 |
49 | public override string ToString()
50 | {
51 | return string.Format("[LineEventArgs Document={0} LineSegment={1}]", Document, LineSegment);
52 | }
53 | }
54 |
55 | public class LineLengthChangeEventArgs : LineEventArgs
56 | {
57 | public LineLengthChangeEventArgs(IDocument document, LineSegment lineSegment, int moved)
58 | : base(document, lineSegment)
59 | {
60 | LengthDelta = moved;
61 | }
62 |
63 | public int LengthDelta { get; }
64 |
65 | public override string ToString()
66 | {
67 | return string.Format("[LineLengthEventArgs Document={0} LineSegment={1} LengthDelta={2}]", Document, LineSegment, LengthDelta);
68 | }
69 | }
70 | }
--------------------------------------------------------------------------------
/Project/Src/Document/MarkerStrategy/TextMarker.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Drawing;
10 |
11 | namespace ICSharpCode.TextEditor.Document
12 | {
13 | public enum TextMarkerType
14 | {
15 | SolidBlock,
16 | Underlined,
17 | WaveLine,
18 | InterChar
19 | }
20 |
21 | ///
22 | /// Marks a part of a document.
23 | ///
24 | public class TextMarker : ISegment
25 | {
26 | protected int length = -1;
27 |
28 | protected int offset = -1;
29 |
30 | public TextMarker(int offset, int length, TextMarkerType textMarkerType) : this(offset, length, textMarkerType, Color.Red)
31 | {
32 | }
33 |
34 | public TextMarker(int offset, int length, TextMarkerType textMarkerType, Color color)
35 | {
36 | if (length < 1) length = 1;
37 | this.offset = offset;
38 | this.length = length;
39 | TextMarkerType = textMarkerType;
40 | Color = color;
41 | }
42 |
43 | public TextMarker(int offset, int length, TextMarkerType textMarkerType, Color color, Color foreColor)
44 | {
45 | if (length < 1) length = 1;
46 | this.offset = offset;
47 | this.length = length;
48 | TextMarkerType = textMarkerType;
49 | Color = color;
50 | ForeColor = foreColor;
51 | OverrideForeColor = true;
52 | }
53 |
54 | public TextMarkerType TextMarkerType { get; }
55 |
56 | public Color Color { get; }
57 |
58 | public Color ForeColor { get; }
59 |
60 | public bool OverrideForeColor { get; }
61 |
62 | ///
63 | /// Marks the text segment as read-only.
64 | ///
65 | public bool IsReadOnly { get; set; }
66 |
67 | public string ToolTip { get; set; } = null;
68 |
69 | ///
70 | /// Gets the last offset that is inside the marker region.
71 | ///
72 | public int EndOffset => offset + length - 1;
73 |
74 | public override string ToString()
75 | {
76 | return string.Format(
77 | "[TextMarker: Offset = {0}, Length = {1}, Type = {2}]",
78 | offset,
79 | length,
80 | TextMarkerType);
81 | }
82 |
83 | #region ICSharpCode.TextEditor.Document.ISegment interface implementation
84 |
85 | public int Offset
86 | {
87 | get => offset;
88 | set => offset = value;
89 | }
90 |
91 | public int Length
92 | {
93 | get => length;
94 | set => length = value;
95 | }
96 |
97 | #endregion
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/Project/Src/Document/Selection/ColumnRange.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | namespace ICSharpCode.TextEditor.Document
9 | {
10 | public class ColumnRange
11 | {
12 | public static readonly ColumnRange NoColumn = new ColumnRange(startColumn: -2, endColumn: -2);
13 | public static readonly ColumnRange WholeColumn = new ColumnRange(startColumn: -1, endColumn: -1);
14 |
15 | public ColumnRange(int startColumn, int endColumn)
16 | {
17 | StartColumn = startColumn;
18 | EndColumn = endColumn;
19 | }
20 |
21 | public int StartColumn { get; set; }
22 |
23 | public int EndColumn { get; set; }
24 |
25 | public override int GetHashCode()
26 | {
27 | return StartColumn + (EndColumn << 16);
28 | }
29 |
30 | public override bool Equals(object obj)
31 | {
32 | if (obj is ColumnRange range)
33 | return range.StartColumn == StartColumn &&
34 | range.EndColumn == EndColumn;
35 | return false;
36 | }
37 |
38 | public override string ToString()
39 | {
40 | return string.Format("[ColumnRange: StartColumn={0}, EndColumn={1}]", StartColumn, EndColumn);
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/Project/Src/Document/Selection/DefaultSelection.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Diagnostics;
9 |
10 | namespace ICSharpCode.TextEditor.Document
11 | {
12 | ///
13 | /// Default implementation of the interface.
14 | ///
15 | public class DefaultSelection : ISelection
16 | {
17 | private readonly IDocument document;
18 | private TextLocation endPosition;
19 | private TextLocation startPosition;
20 |
21 | ///
22 | /// Creates a new instance of
23 | ///
24 | public DefaultSelection(IDocument document, TextLocation startPosition, TextLocation endPosition)
25 | {
26 | DefaultDocument.ValidatePosition(document, startPosition);
27 | DefaultDocument.ValidatePosition(document, endPosition);
28 | Debug.Assert(startPosition <= endPosition);
29 | this.document = document;
30 | this.startPosition = startPosition;
31 | this.endPosition = endPosition;
32 | }
33 |
34 | public TextLocation StartPosition
35 | {
36 | get => startPosition;
37 | set
38 | {
39 | DefaultDocument.ValidatePosition(document, value);
40 | startPosition = value;
41 | }
42 | }
43 |
44 | public TextLocation EndPosition
45 | {
46 | get => endPosition;
47 | set
48 | {
49 | DefaultDocument.ValidatePosition(document, value);
50 | endPosition = value;
51 | }
52 | }
53 |
54 | public int Offset => document.PositionToOffset(startPosition);
55 |
56 | public int EndOffset => document.PositionToOffset(endPosition);
57 |
58 | public int Length => EndOffset - Offset;
59 |
60 | ///
61 | /// Returns true, if the selection is empty
62 | ///
63 | public bool IsEmpty => startPosition == endPosition;
64 |
65 | ///
66 | /// Returns true, if the selection is rectangular
67 | ///
68 | // TODO : make this unused property used.
69 | public bool IsRectangularSelection { get; set; }
70 |
71 | ///
72 | /// The text which is selected by this selection.
73 | ///
74 | public string SelectedText
75 | {
76 | get
77 | {
78 | if (document != null)
79 | {
80 | if (Length < 0)
81 | return null;
82 | return document.GetText(Offset, Length);
83 | }
84 |
85 | return null;
86 | }
87 | }
88 |
89 | public bool ContainsPosition(TextLocation position)
90 | {
91 | if (IsEmpty)
92 | return false;
93 | return startPosition.Y < position.Y && position.Y < endPosition.Y ||
94 | startPosition.Y == position.Y && startPosition.X <= position.X && (startPosition.Y != endPosition.Y || position.X <= endPosition.X) ||
95 | endPosition.Y == position.Y && startPosition.Y != endPosition.Y && position.X <= endPosition.X;
96 | }
97 |
98 | public bool ContainsOffset(int offset)
99 | {
100 | return Offset <= offset && offset <= EndOffset;
101 | }
102 |
103 | ///
104 | /// Converts a instance to string (for debug purposes)
105 | ///
106 | public override string ToString()
107 | {
108 | return string.Format("[DefaultSelection : StartPosition={0}, EndPosition={1}]", startPosition, endPosition);
109 | }
110 | }
111 | }
--------------------------------------------------------------------------------
/Project/Src/Document/Selection/ISelection.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | namespace ICSharpCode.TextEditor.Document
9 | {
10 | ///
11 | /// An interface representing a portion of the current selection.
12 | ///
13 | public interface ISelection
14 | {
15 | TextLocation StartPosition { get; set; }
16 |
17 | TextLocation EndPosition { get; set; }
18 |
19 | int Offset { get; }
20 |
21 | int EndOffset { get; }
22 |
23 | int Length { get; }
24 |
25 | ///
26 | /// Returns true, if the selection is rectangular
27 | ///
28 | bool IsRectangularSelection { get; }
29 |
30 | ///
31 | /// Returns true, if the selection is empty
32 | ///
33 | bool IsEmpty { get; }
34 |
35 | ///
36 | /// The text which is selected by this selection.
37 | ///
38 | string SelectedText { get; }
39 |
40 | bool ContainsOffset(int offset);
41 |
42 | bool ContainsPosition(TextLocation position);
43 | }
44 | }
--------------------------------------------------------------------------------
/Project/Src/Document/TextAnchor.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 |
10 | namespace ICSharpCode.TextEditor.Document
11 | {
12 | public enum AnchorMovementType
13 | {
14 | ///
15 | /// Behaves like a start marker - when text is inserted at the anchor position, the anchor will stay
16 | /// before the inserted text.
17 | ///
18 | BeforeInsertion,
19 |
20 | ///
21 | /// Behave like an end marker - when text is insered at the anchor position, the anchor will move
22 | /// after the inserted text.
23 | ///
24 | AfterInsertion
25 | }
26 |
27 | ///
28 | /// An anchor that can be put into a document and moves around when the document is changed.
29 | ///
30 | public sealed class TextAnchor
31 | {
32 | private int columnNumber;
33 |
34 | private LineSegment lineSegment;
35 |
36 | internal TextAnchor(LineSegment lineSegment, int columnNumber)
37 | {
38 | this.lineSegment = lineSegment;
39 | this.columnNumber = columnNumber;
40 | }
41 |
42 | public LineSegment Line
43 | {
44 | get
45 | {
46 | if (lineSegment == null) throw AnchorDeletedError();
47 | return lineSegment;
48 | }
49 | internal set => lineSegment = value;
50 | }
51 |
52 | public bool IsDeleted => lineSegment == null;
53 |
54 | public int LineNumber => Line.LineNumber;
55 |
56 | public int ColumnNumber
57 | {
58 | get
59 | {
60 | if (lineSegment == null) throw AnchorDeletedError();
61 | return columnNumber;
62 | }
63 | internal set => columnNumber = value;
64 | }
65 |
66 | public TextLocation Location => new TextLocation(ColumnNumber, LineNumber);
67 |
68 | public int Offset => Line.Offset + columnNumber;
69 |
70 | ///
71 | /// Controls how the anchor moves.
72 | ///
73 | public AnchorMovementType MovementType { get; set; }
74 |
75 | private static Exception AnchorDeletedError()
76 | {
77 | return new InvalidOperationException("The text containing the anchor was deleted");
78 | }
79 |
80 | public event EventHandler Deleted;
81 |
82 | internal void Delete(ref DeferredEventList deferredEventList)
83 | {
84 | // we cannot fire an event here because this method is called while the LineManager adjusts the
85 | // lineCollection, so an event handler could see inconsistent state
86 | lineSegment = null;
87 | deferredEventList.AddDeletedAnchor(this);
88 | }
89 |
90 | internal void RaiseDeleted()
91 | {
92 | Deleted?.Invoke(this, EventArgs.Empty);
93 | }
94 |
95 | public override string ToString()
96 | {
97 | if (IsDeleted)
98 | return "[TextAnchor (deleted)]";
99 | return "[TextAnchor " + Location + "]";
100 | }
101 | }
102 | }
--------------------------------------------------------------------------------
/Project/Src/Document/TextBufferStrategy/ITextBufferStrategy.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | namespace ICSharpCode.TextEditor.Document
9 | {
10 | ///
11 | /// Interface to describe a sequence of characters that can be edited.
12 | ///
13 | public interface ITextBufferStrategy
14 | {
15 | ///
16 | /// The current length of the sequence of characters that can be edited.
17 | ///
18 | int Length { get; }
19 |
20 | ///
21 | /// Inserts a string of characters into the sequence.
22 | ///
23 | ///
24 | /// offset where to insert the string.
25 | ///
26 | ///
27 | /// text to be inserted.
28 | ///
29 | void Insert(int offset, string text);
30 |
31 | ///
32 | /// Removes some portion of the sequence.
33 | ///
34 | ///
35 | /// offset of the remove.
36 | ///
37 | ///
38 | /// number of characters to remove.
39 | ///
40 | void Remove(int offset, int length);
41 |
42 | ///
43 | /// Replace some portion of the sequence.
44 | ///
45 | ///
46 | /// offset.
47 | ///
48 | ///
49 | /// number of characters to replace.
50 | ///
51 | ///
52 | /// text to be replaced with.
53 | ///
54 | void Replace(int offset, int length, string text);
55 |
56 | ///
57 | /// Fetches a string of characters contained in the sequence.
58 | ///
59 | ///
60 | /// Offset into the sequence to fetch
61 | ///
62 | ///
63 | /// number of characters to copy.
64 | ///
65 | string GetText(int offset, int length);
66 |
67 | ///
68 | /// Returns a specific char of the sequence.
69 | ///
70 | ///
71 | /// Offset of the char to get.
72 | ///
73 | char GetCharAt(int offset);
74 |
75 | ///
76 | /// This method sets the stored content.
77 | ///
78 | ///
79 | /// The string that represents the character sequence.
80 | ///
81 | void SetContent(string text);
82 | }
83 | }
--------------------------------------------------------------------------------
/Project/Src/Document/TextBufferStrategy/StringTextBufferStrategy.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.IO;
10 | using System.Text;
11 | using ICSharpCode.TextEditor.Util;
12 |
13 | namespace ICSharpCode.TextEditor.Document
14 | {
15 | ///
16 | /// Simple implementation of the ITextBuffer interface implemented using a
17 | /// string.
18 | /// Only for fall-back purposes.
19 | ///
20 | public class StringTextBufferStrategy : ITextBufferStrategy
21 | {
22 | private string storedText = "";
23 |
24 | public int Length => storedText.Length;
25 |
26 | public void Insert(int offset, string text)
27 | {
28 | if (text != null)
29 | storedText = storedText.Insert(offset, text);
30 | }
31 |
32 | public void Remove(int offset, int length)
33 | {
34 | storedText = storedText.Remove(offset, length);
35 | }
36 |
37 | public void Replace(int offset, int length, string text)
38 | {
39 | Remove(offset, length);
40 | Insert(offset, text);
41 | }
42 |
43 | public string GetText(int offset, int length)
44 | {
45 | if (length == 0)
46 | return "";
47 | if (offset == 0 && length >= storedText.Length)
48 | return storedText;
49 | return storedText.Substring(offset, Math.Min(length, storedText.Length - offset));
50 | }
51 |
52 | public char GetCharAt(int offset)
53 | {
54 | if (offset == Length)
55 | return '\0';
56 | return storedText[offset];
57 | }
58 |
59 | public void SetContent(string text)
60 | {
61 | storedText = text;
62 | }
63 |
64 | public static ITextBufferStrategy CreateTextBufferFromFile(string fileName)
65 | {
66 | if (!File.Exists(fileName))
67 | throw new FileNotFoundException(fileName);
68 | var s = new StringTextBufferStrategy();
69 | s.SetContent(FileReader.ReadFileContent(fileName, Encoding.Default));
70 | return s;
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/Project/Src/Document/TextLocation.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision: 2658$
6 | //
7 |
8 | using System;
9 |
10 | namespace ICSharpCode.TextEditor
11 | {
12 | ///
13 | /// A line/column position.
14 | /// Text editor lines/columns are counting from zero.
15 | ///
16 | public struct TextLocation : IComparable, IEquatable
17 | {
18 | ///
19 | /// Represents no text location (-1, -1).
20 | ///
21 | public static readonly TextLocation Empty = new TextLocation(column: -1, line: -1);
22 |
23 | public TextLocation(int column, int line)
24 | {
25 | X = column;
26 | Y = line;
27 | }
28 |
29 | public int X { get; set; }
30 |
31 | public int Y { get; set; }
32 |
33 | public int Line
34 | {
35 | get => Y;
36 | set => Y = value;
37 | }
38 |
39 | public int Column
40 | {
41 | get => X;
42 | set => X = value;
43 | }
44 |
45 | public bool IsEmpty => X <= 0 && Y <= 0;
46 |
47 | public override string ToString()
48 | {
49 | return string.Format("(Line {1}, Col {0})", X, Y);
50 | }
51 |
52 | public override int GetHashCode()
53 | {
54 | return unchecked((87*X.GetHashCode()) ^ Y.GetHashCode());
55 | }
56 |
57 | public override bool Equals(object obj)
58 | {
59 | if (!(obj is TextLocation)) return false;
60 | return (TextLocation)obj == this;
61 | }
62 |
63 | public bool Equals(TextLocation other)
64 | {
65 | return this == other;
66 | }
67 |
68 | public static bool operator ==(TextLocation a, TextLocation b)
69 | {
70 | return a.X == b.X && a.Y == b.Y;
71 | }
72 |
73 | public static bool operator !=(TextLocation a, TextLocation b)
74 | {
75 | return a.X != b.X || a.Y != b.Y;
76 | }
77 |
78 | public static bool operator <(TextLocation a, TextLocation b)
79 | {
80 | if (a.Y < b.Y)
81 | return true;
82 | if (a.Y == b.Y)
83 | return a.X < b.X;
84 | return false;
85 | }
86 |
87 | public static bool operator >(TextLocation a, TextLocation b)
88 | {
89 | if (a.Y > b.Y)
90 | return true;
91 | if (a.Y == b.Y)
92 | return a.X > b.X;
93 | return false;
94 | }
95 |
96 | public static bool operator <=(TextLocation a, TextLocation b)
97 | {
98 | return !(a > b);
99 | }
100 |
101 | public static bool operator >=(TextLocation a, TextLocation b)
102 | {
103 | return !(a < b);
104 | }
105 |
106 | public int CompareTo(TextLocation other)
107 | {
108 | if (this == other)
109 | return 0;
110 | if (this < other)
111 | return -1;
112 | return 1;
113 | }
114 | }
115 | }
--------------------------------------------------------------------------------
/Project/Src/Gui/AbstractMargin.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Drawing;
10 | using System.Windows.Forms;
11 | using ICSharpCode.TextEditor.Document;
12 |
13 | namespace ICSharpCode.TextEditor
14 | {
15 | public delegate void MarginMouseEventHandler(AbstractMargin sender, Point mousepos, MouseButtons mouseButtons);
16 |
17 | public delegate void MarginPaintEventHandler(AbstractMargin sender, Graphics g, Rectangle rect);
18 |
19 | ///
20 | /// This class views the line numbers and folding markers.
21 | ///
22 | public abstract class AbstractMargin
23 | {
24 | private int _caretLine = -1;
25 |
26 | protected Rectangle drawingPosition = new Rectangle(x: 0, y: 0, width: 0, height: 0);
27 |
28 | protected TextArea textArea;
29 |
30 | protected AbstractMargin(TextArea textArea)
31 | {
32 | this.textArea = textArea;
33 | }
34 |
35 | public Rectangle DrawingPosition
36 | {
37 | get => drawingPosition;
38 | set => drawingPosition = value;
39 | }
40 |
41 | public TextArea TextArea => textArea;
42 |
43 | public IDocument Document => textArea.Document;
44 |
45 | public ITextEditorProperties TextEditorProperties => textArea.Document.TextEditorProperties;
46 |
47 | public bool MarkSelectedLine { get; set; } = true;
48 |
49 | public virtual Cursor Cursor { get; set; } = Cursors.Default;
50 |
51 | public virtual int Width => -1;
52 |
53 | public virtual bool IsVisible => true;
54 |
55 | public virtual void HandleMouseDown(Point mousepos, MouseButtons mouseButtons)
56 | {
57 | MouseDown?.Invoke(this, mousepos, mouseButtons);
58 | }
59 |
60 | public virtual void HandleMouseMove(Point mousepos, MouseButtons mouseButtons)
61 | {
62 | MouseMove?.Invoke(this, mousepos, mouseButtons);
63 | }
64 |
65 | public virtual void HandleMouseLeave(EventArgs e)
66 | {
67 | MouseLeave?.Invoke(this, e);
68 | }
69 |
70 | public virtual void SelectedLineChanged(int line)
71 | {
72 | if (!IsVisible || _caretLine == line || !MarkSelectedLine)
73 | {
74 | return;
75 | }
76 |
77 | _caretLine = line;
78 | textArea.Invalidate();
79 | }
80 |
81 | public virtual void Paint(Graphics g, Rectangle rect)
82 | {
83 | Painted?.Invoke(this, g, rect);
84 | }
85 |
86 | public event MarginPaintEventHandler Painted;
87 | public event MarginMouseEventHandler MouseDown;
88 | public event MarginMouseEventHandler MouseMove;
89 | public event EventHandler MouseLeave;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/Project/Src/Gui/BracketHighlighter.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using ICSharpCode.TextEditor.Document;
10 |
11 | namespace ICSharpCode.TextEditor
12 | {
13 | public class Highlight
14 | {
15 | public Highlight(TextLocation openBrace, TextLocation closeBrace)
16 | {
17 | OpenBrace = openBrace;
18 | CloseBrace = closeBrace;
19 | }
20 |
21 | public TextLocation OpenBrace { get; set; }
22 | public TextLocation CloseBrace { get; set; }
23 | }
24 |
25 | public class BracketHighlightingSheme
26 | {
27 | public BracketHighlightingSheme(char opentag, char closingtag)
28 | {
29 | OpenTag = opentag;
30 | ClosingTag = closingtag;
31 | }
32 |
33 | public char OpenTag { get; set; }
34 |
35 | public char ClosingTag { get; set; }
36 |
37 | public Highlight GetHighlight(IDocument document, int offset)
38 | {
39 | int searchOffset;
40 | if (document.TextEditorProperties.BracketMatchingStyle == BracketMatchingStyle.After)
41 | searchOffset = offset;
42 | else
43 | searchOffset = offset + 1;
44 | var word = document.GetCharAt(Math.Max(val1: 0, Math.Min(document.TextLength - 1, searchOffset)));
45 |
46 | var endP = document.OffsetToPosition(searchOffset);
47 | if (word == OpenTag)
48 | {
49 | if (searchOffset < document.TextLength)
50 | {
51 | var bracketOffset = TextUtilities.SearchBracketForward(document, searchOffset + 1, OpenTag, ClosingTag);
52 | if (bracketOffset >= 0)
53 | {
54 | var p = document.OffsetToPosition(bracketOffset);
55 | return new Highlight(p, endP);
56 | }
57 | }
58 | }
59 | else if (word == ClosingTag)
60 | {
61 | if (searchOffset > 0)
62 | {
63 | var bracketOffset = TextUtilities.SearchBracketBackward(document, searchOffset - 1, OpenTag, ClosingTag);
64 | if (bracketOffset >= 0)
65 | {
66 | var p = document.OffsetToPosition(bracketOffset);
67 | return new Highlight(p, endP);
68 | }
69 | }
70 | }
71 |
72 | return null;
73 | }
74 | }
75 | }
--------------------------------------------------------------------------------
/Project/Src/Gui/BrushRegistry.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Collections.Generic;
9 | using System.Drawing;
10 |
11 | namespace ICSharpCode.TextEditor
12 | {
13 | ///
14 | /// Contains brushes/pens for the text editor to speed up drawing. Re-Creation of brushes and pens
15 | /// seems too costly.
16 | ///
17 | public class BrushRegistry
18 | {
19 | private static readonly Dictionary brushes = new Dictionary();
20 | private static readonly Dictionary pens = new Dictionary();
21 | private static readonly Dictionary dotPens = new Dictionary();
22 |
23 | private static readonly float[] dotPattern = {1, 1, 1, 1};
24 |
25 | public static Brush GetBrush(Color color)
26 | {
27 | lock (brushes)
28 | {
29 | if (!brushes.TryGetValue(color, out var brush))
30 | {
31 | brush = new SolidBrush(color);
32 | brushes.Add(color, brush);
33 | }
34 |
35 | return brush;
36 | }
37 | }
38 |
39 | public static Pen GetPen(Color color)
40 | {
41 | lock (pens)
42 | {
43 | if (!pens.TryGetValue(color, out var pen))
44 | {
45 | pen = new Pen(color);
46 | pens.Add(color, pen);
47 | }
48 |
49 | return pen;
50 | }
51 | }
52 |
53 | public static Pen GetDotPen(Color color)
54 | {
55 | lock (dotPens)
56 | {
57 | Pen pen;
58 | if (!dotPens.TryGetValue(color, out pen))
59 | {
60 | pen = new Pen(color);
61 | pen.DashPattern = dotPattern;
62 | dotPens.Add(color, pen);
63 | }
64 |
65 | return pen;
66 | }
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/Project/Src/Gui/CompletionWindow/DeclarationViewWindow.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Drawing;
10 | using System.Windows.Forms;
11 | using ICSharpCode.TextEditor.Util;
12 |
13 | namespace ICSharpCode.TextEditor.Gui.CompletionWindow
14 | {
15 | public interface IDeclarationViewWindow
16 | {
17 | string Description { get; set; }
18 |
19 | void ShowDeclarationViewWindow();
20 | void CloseDeclarationViewWindow();
21 | }
22 |
23 | public class DeclarationViewWindow : Form, IDeclarationViewWindow
24 | {
25 | private string description = string.Empty;
26 |
27 | public bool HideOnClick;
28 |
29 | public DeclarationViewWindow(Form parent)
30 | {
31 | SetStyle(ControlStyles.Selectable, value: false);
32 | StartPosition = FormStartPosition.Manual;
33 | FormBorderStyle = FormBorderStyle.None;
34 | Owner = parent;
35 | ShowInTaskbar = false;
36 | Size = new Size(width: 0, height: 0);
37 | CreateHandle();
38 | }
39 |
40 | public bool FixedWidth { get; set; }
41 |
42 | protected override CreateParams CreateParams
43 | {
44 | get
45 | {
46 | var p = base.CreateParams;
47 | AbstractCompletionWindow.AddShadowToWindow(p);
48 | return p;
49 | }
50 | }
51 |
52 | protected override bool ShowWithoutActivation => true;
53 |
54 | public string Description
55 | {
56 | get => description;
57 | set
58 | {
59 | description = value;
60 | if (value == null && Visible)
61 | {
62 | Visible = false;
63 | }
64 | else if (value != null)
65 | {
66 | if (!Visible) ShowDeclarationViewWindow();
67 | Refresh();
68 | }
69 | }
70 | }
71 |
72 | public void ShowDeclarationViewWindow()
73 | {
74 | Show();
75 | }
76 |
77 | public void CloseDeclarationViewWindow()
78 | {
79 | Close();
80 | Dispose();
81 | }
82 |
83 | public int GetRequiredLeftHandSideWidth(Point p)
84 | {
85 | if (!string.IsNullOrEmpty(description))
86 | using (var g = CreateGraphics())
87 | {
88 | var s = TipPainterTools.GetLeftHandSideDrawingSizeHelpTipFromCombinedDescription(this, g, Font, countMessage: null, description, p);
89 | return s.Width;
90 | }
91 |
92 | return 0;
93 | }
94 |
95 | protected override void OnClick(EventArgs e)
96 | {
97 | base.OnClick(e);
98 | if (HideOnClick) Hide();
99 | }
100 |
101 | protected override void OnPaint(PaintEventArgs pe)
102 | {
103 | if (!string.IsNullOrEmpty(description))
104 | {
105 | if (FixedWidth)
106 | TipPainterTools.DrawFixedWidthHelpTipFromCombinedDescription(this, pe.Graphics, Font, countMessage: null, description);
107 | else
108 | TipPainterTools.DrawHelpTipFromCombinedDescription(this, pe.Graphics, Font, countMessage: null, description);
109 | }
110 | }
111 |
112 | protected override void OnPaintBackground(PaintEventArgs pe)
113 | {
114 | pe.Graphics.FillRectangle(SystemBrushes.Info, pe.ClipRectangle);
115 | }
116 | }
117 | }
--------------------------------------------------------------------------------
/Project/Src/Gui/CompletionWindow/ICompletionData.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 |
10 | namespace ICSharpCode.TextEditor.Gui.CompletionWindow
11 | {
12 | public interface ICompletionData
13 | {
14 | int ImageIndex { get; }
15 |
16 | string Text { get; set; }
17 |
18 | string Description { get; }
19 |
20 | ///
21 | /// Gets a priority value for the completion data item.
22 | /// When selecting items by their start characters, the item with the highest
23 | /// priority is selected first.
24 | ///
25 | double Priority { get; }
26 |
27 | ///
28 | /// Insert the element represented by the completion data into the text
29 | /// editor.
30 | ///
31 | /// TextArea to insert the completion data in.
32 | ///
33 | /// Character that should be inserted after the completion data.
34 | /// \0 when no character should be inserted.
35 | ///
36 | ///
37 | /// Returns true when the insert action has processed the character
38 | /// ; false when the character was not processed.
39 | ///
40 | bool InsertAction(TextArea textArea, char ch);
41 | }
42 |
43 | public class DefaultCompletionData : ICompletionData
44 | {
45 | public DefaultCompletionData(string text, int imageIndex)
46 | {
47 | Text = text;
48 | ImageIndex = imageIndex;
49 | }
50 |
51 | public DefaultCompletionData(string text, string description, int imageIndex)
52 | {
53 | Text = text;
54 | Description = description;
55 | ImageIndex = imageIndex;
56 | }
57 |
58 | public int ImageIndex { get; }
59 |
60 | public string Text { get; set; }
61 |
62 | public virtual string Description { get; }
63 |
64 | public double Priority { get; set; }
65 |
66 | public virtual bool InsertAction(TextArea textArea, char ch)
67 | {
68 | textArea.InsertString(Text);
69 | return false;
70 | }
71 |
72 | public static int Compare(ICompletionData a, ICompletionData b)
73 | {
74 | if (a == null)
75 | throw new ArgumentNullException(nameof(a));
76 | if (b == null)
77 | throw new ArgumentNullException(nameof(b));
78 | return string.Compare(a.Text, b.Text, StringComparison.InvariantCultureIgnoreCase);
79 | }
80 | }
81 | }
--------------------------------------------------------------------------------
/Project/Src/Gui/CompletionWindow/ICompletionDataProvider.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Windows.Forms;
9 |
10 | namespace ICSharpCode.TextEditor.Gui.CompletionWindow
11 | {
12 | public interface ICompletionDataProvider
13 | {
14 | ImageList ImageList { get; }
15 |
16 | string PreSelection { get; }
17 |
18 | ///
19 | /// Gets the index of the element in the list that is chosen by default.
20 | ///
21 | int DefaultIndex { get; }
22 |
23 | ///
24 | /// Processes a keypress. Returns the action to be run with the key.
25 | ///
26 | CompletionDataProviderKeyResult ProcessKey(char key);
27 |
28 | ///
29 | /// Executes the insertion. The provider should set the caret position and then
30 | /// call data.InsertAction.
31 | ///
32 | bool InsertAction(ICompletionData data, TextArea textArea, int insertionOffset, char key);
33 |
34 | ///
35 | /// Generates the completion data. This method is called by the text editor control.
36 | ///
37 | ICompletionData[] GenerateCompletionData(string fileName, TextArea textArea, char charTyped);
38 | }
39 |
40 | public enum CompletionDataProviderKeyResult
41 | {
42 | ///
43 | /// Normal key, used to choose an entry from the completion list
44 | ///
45 | NormalKey,
46 |
47 | ///
48 | /// This key triggers insertion of the completed expression
49 | ///
50 | InsertionKey,
51 |
52 | ///
53 | /// Increment both start and end offset of completion region when inserting this
54 | /// key. Can be used to insert whitespace (or other characters) in front of the expression
55 | /// while the completion window is open.
56 | ///
57 | BeforeStartKey
58 | }
59 | }
--------------------------------------------------------------------------------
/Project/Src/Gui/HRuler.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Drawing;
9 | using System.Windows.Forms;
10 |
11 | namespace ICSharpCode.TextEditor
12 | {
13 | ///
14 | /// Horizontal ruler - text column measuring ruler at the top of the text area.
15 | ///
16 | public class HRuler : Control
17 | {
18 | private readonly TextArea textArea;
19 |
20 | public HRuler(TextArea textArea)
21 | {
22 | this.textArea = textArea;
23 | }
24 |
25 | protected override void OnPaint(PaintEventArgs e)
26 | {
27 | var g = e.Graphics;
28 | var num = 0;
29 | for (float x = textArea.TextView.DrawingPosition.Left; x < textArea.TextView.DrawingPosition.Right; x += textArea.TextView.WideSpaceWidth)
30 | {
31 | var offset = Height*2/3;
32 | if (num%5 == 0)
33 | offset = Height*4/5;
34 |
35 | if (num%10 == 0)
36 | offset = 1;
37 | ++num;
38 | g.DrawLine(
39 | Pens.Black,
40 | (int)x, offset, (int)x, Height - offset);
41 | }
42 | }
43 |
44 | protected override void OnPaintBackground(PaintEventArgs e)
45 | {
46 | e.Graphics.FillRectangle(
47 | Brushes.White,
48 | new Rectangle(
49 | x: 0,
50 | y: 0,
51 | Width,
52 | Height));
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/Project/Src/Gui/InsightWindow/IInsightDataProvider.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | namespace ICSharpCode.TextEditor.Gui.InsightWindow
9 | {
10 | public interface IInsightDataProvider
11 | {
12 | ///
13 | /// Gets the number of available insight entries, e.g. the number of available
14 | /// overloads to call.
15 | ///
16 | int InsightDataCount { get; }
17 |
18 | ///
19 | /// Gets the index of the entry to initially select.
20 | ///
21 | int DefaultIndex { get; }
22 |
23 | ///
24 | /// Tells the insight provider to prepare its data.
25 | ///
26 | /// The name of the edited file
27 | /// The text area in which the file is being edited
28 | void SetupDataProvider(string fileName, TextArea textArea);
29 |
30 | ///
31 | /// Notifies the insight provider that the caret offset has changed.
32 | ///
33 | ///
34 | /// Return true to close the insight window (e.g. when the
35 | /// caret was moved outside the region where insight is displayed for).
36 | /// Return false to keep the window open.
37 | ///
38 | bool CaretOffsetChanged();
39 |
40 | ///
41 | /// Gets the text to display in the insight window.
42 | ///
43 | ///
44 | /// The number of the active insight entry.
45 | /// Multiple insight entries might be multiple overloads of the same method.
46 | ///
47 | ///
48 | /// The text to display, e.g. a multi-line string where
49 | /// the first line is the method definition, followed by a description.
50 | ///
51 | string GetInsightData(int number);
52 | }
53 | }
--------------------------------------------------------------------------------
/Project/Src/Gui/TextAreaUpdate.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | namespace ICSharpCode.TextEditor
9 | {
10 | ///
11 | /// This enum describes all implemented request types
12 | ///
13 | public enum TextAreaUpdateType
14 | {
15 | WholeTextArea,
16 | SingleLine,
17 | SinglePosition,
18 | PositionToLineEnd,
19 | PositionToEnd,
20 | LinesBetween
21 | }
22 |
23 | ///
24 | /// This class is used to request an update of the textarea
25 | ///
26 | public class TextAreaUpdate
27 | {
28 | ///
29 | /// Creates a new instance of
30 | ///
31 | public TextAreaUpdate(TextAreaUpdateType type)
32 | {
33 | TextAreaUpdateType = type;
34 | }
35 |
36 | ///
37 | /// Creates a new instance of
38 | ///
39 | public TextAreaUpdate(TextAreaUpdateType type, TextLocation position)
40 | {
41 | TextAreaUpdateType = type;
42 | Position = position;
43 | }
44 |
45 | ///
46 | /// Creates a new instance of
47 | ///
48 | public TextAreaUpdate(TextAreaUpdateType type, int startLine, int endLine)
49 | {
50 | TextAreaUpdateType = type;
51 | Position = new TextLocation(startLine, endLine);
52 | }
53 |
54 | ///
55 | /// Creates a new instance of
56 | ///
57 | public TextAreaUpdate(TextAreaUpdateType type, int singleLine)
58 | {
59 | TextAreaUpdateType = type;
60 | Position = new TextLocation(column: 0, singleLine);
61 | }
62 |
63 | public TextAreaUpdateType TextAreaUpdateType { get; }
64 |
65 | public TextLocation Position { get; }
66 |
67 | public override string ToString()
68 | {
69 | return string.Format("[TextAreaUpdate: Type={0}, Position={1}]", TextAreaUpdateType, Position);
70 | }
71 | }
72 | }
--------------------------------------------------------------------------------
/Project/Src/Gui/ToolTipRequestEventArgs.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System.Drawing;
9 |
10 | namespace ICSharpCode.TextEditor
11 | {
12 | public delegate void ToolTipRequestEventHandler(object sender, ToolTipRequestEventArgs e);
13 |
14 | public class ToolTipRequestEventArgs
15 | {
16 | internal string toolTipText;
17 |
18 | public ToolTipRequestEventArgs(Point mousePosition, TextLocation logicalPosition, bool inDocument)
19 | {
20 | MousePosition = mousePosition;
21 | LogicalPosition = logicalPosition;
22 | InDocument = inDocument;
23 | }
24 |
25 | public Point MousePosition { get; }
26 |
27 | public TextLocation LogicalPosition { get; }
28 |
29 | public bool InDocument { get; }
30 |
31 | ///
32 | /// Gets if some client handling the event has already shown a tool tip.
33 | ///
34 | public bool ToolTipShown => toolTipText != null;
35 |
36 | public void ShowToolTip(string text)
37 | {
38 | toolTipText = text;
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/Project/Src/Undo/IUndoableOperation.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | namespace ICSharpCode.TextEditor.Undo
9 | {
10 | ///
11 | /// This Interface describes a the basic Undo/Redo operation
12 | /// all Undo Operations must implement this interface.
13 | ///
14 | public interface IUndoableOperation
15 | {
16 | ///
17 | /// Undo the last operation
18 | ///
19 | void Undo();
20 |
21 | ///
22 | /// Redo the last operation
23 | ///
24 | void Redo();
25 | }
26 | }
--------------------------------------------------------------------------------
/Project/Src/Undo/UndoQueue.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Collections.Generic;
10 | using System.Diagnostics;
11 |
12 | namespace ICSharpCode.TextEditor.Undo
13 | {
14 | ///
15 | /// This class stacks the last x operations from the undostack and makes
16 | /// one undo/redo operation from it.
17 | ///
18 | internal sealed class UndoQueue : IUndoableOperation
19 | {
20 | private readonly List undolist = new List();
21 |
22 | ///
23 | ///
24 | public UndoQueue(Stack stack, int numops)
25 | {
26 | if (stack == null)
27 | throw new ArgumentNullException(nameof(stack));
28 |
29 | Debug.Assert(numops > 0, "ICSharpCode.TextEditor.Undo.UndoQueue : numops should be > 0");
30 | if (numops > stack.Count)
31 | numops = stack.Count;
32 |
33 | for (var i = 0; i < numops; ++i)
34 | undolist.Add(stack.Pop());
35 | }
36 |
37 | public void Undo()
38 | {
39 | for (var i = 0; i < undolist.Count; ++i)
40 | undolist[i].Undo();
41 | }
42 |
43 | public void Redo()
44 | {
45 | for (var i = undolist.Count - 1; i >= 0; --i)
46 | undolist[i].Redo();
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/Project/Src/Undo/UndoableDelete.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Diagnostics;
10 | using ICSharpCode.TextEditor.Document;
11 |
12 | namespace ICSharpCode.TextEditor.Undo
13 | {
14 | ///
15 | /// This class is for the undo of Document insert operations
16 | ///
17 | public class UndoableDelete : IUndoableOperation
18 | {
19 | private readonly IDocument document;
20 |
21 | // int oldCaretPos;
22 | private readonly int offset;
23 | private readonly string text;
24 |
25 | ///
26 | /// Creates a new instance of
27 | ///
28 | public UndoableDelete(IDocument document, int offset, string text)
29 | {
30 | if (document == null)
31 | throw new ArgumentNullException(nameof(document));
32 | if (offset < 0 || offset > document.TextLength)
33 | throw new ArgumentOutOfRangeException(nameof(offset));
34 |
35 | Debug.Assert(text != null, "text can't be null");
36 | // oldCaretPos = document.Caret.Offset;
37 | this.document = document;
38 | this.offset = offset;
39 | this.text = text;
40 | }
41 |
42 | ///
43 | /// Undo last operation
44 | ///
45 | public void Undo()
46 | {
47 | // we clear all selection direct, because the redraw
48 | // is done per refresh at the end of the action
49 | // textArea.SelectionManager.SelectionCollection.Clear();
50 | document.UndoStack.AcceptChanges = false;
51 | document.Insert(offset, text);
52 | // document.Caret.Offset = Math.Min(document.TextLength, Math.Max(0, oldCaretPos));
53 | document.UndoStack.AcceptChanges = true;
54 | }
55 |
56 | ///
57 | /// Redo last undone operation
58 | ///
59 | public void Redo()
60 | {
61 | // we clear all selection direct, because the redraw
62 | // is done per refresh at the end of the action
63 | // textArea.SelectionManager.SelectionCollection.Clear();
64 |
65 | document.UndoStack.AcceptChanges = false;
66 | document.Remove(offset, text.Length);
67 | // document.Caret.Offset = Math.Min(document.TextLength, Math.Max(0, document.Caret.Offset));
68 | document.UndoStack.AcceptChanges = true;
69 | }
70 | }
71 | }
--------------------------------------------------------------------------------
/Project/Src/Undo/UndoableInsert.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Diagnostics;
10 | using ICSharpCode.TextEditor.Document;
11 |
12 | namespace ICSharpCode.TextEditor.Undo
13 | {
14 | ///
15 | /// This class is for the undo of Document insert operations
16 | ///
17 | public class UndoableInsert : IUndoableOperation
18 | {
19 | private readonly IDocument document;
20 |
21 | // int oldCaretPos;
22 | private readonly int offset;
23 | private readonly string text;
24 |
25 | ///
26 | /// Creates a new instance of
27 | ///
28 | public UndoableInsert(IDocument document, int offset, string text)
29 | {
30 | if (document == null)
31 | throw new ArgumentNullException(nameof(document));
32 | if (offset < 0 || offset > document.TextLength)
33 | throw new ArgumentOutOfRangeException(nameof(offset));
34 |
35 | Debug.Assert(text != null, "text can't be null");
36 | // oldCaretPos = document.Caret.Offset;
37 | this.document = document;
38 | this.offset = offset;
39 | this.text = text;
40 | }
41 |
42 | ///
43 | /// Undo last operation
44 | ///
45 | public void Undo()
46 | {
47 | // we clear all selection direct, because the redraw
48 | // is done per refresh at the end of the action
49 | // document.SelectionCollection.Clear();
50 |
51 | document.UndoStack.AcceptChanges = false;
52 | document.Remove(offset, text.Length);
53 | // document.Caret.Offset = Math.Min(document.TextLength, Math.Max(0, oldCaretPos));
54 | document.UndoStack.AcceptChanges = true;
55 | }
56 |
57 | ///
58 | /// Redo last undone operation
59 | ///
60 | public void Redo()
61 | {
62 | // we clear all selection direct, because the redraw
63 | // is done per refresh at the end of the action
64 | // document.SelectionCollection.Clear();
65 |
66 | document.UndoStack.AcceptChanges = false;
67 | document.Insert(offset, text);
68 | // document.Caret.Offset = Math.Min(document.TextLength, Math.Max(0, document.Caret.Offset));
69 | document.UndoStack.AcceptChanges = true;
70 | }
71 | }
72 | }
--------------------------------------------------------------------------------
/Project/Src/Undo/UndoableReplace.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Diagnostics;
10 | using ICSharpCode.TextEditor.Document;
11 |
12 | namespace ICSharpCode.TextEditor.Undo
13 | {
14 | ///
15 | /// This class is for the undo of Document insert operations
16 | ///
17 | public class UndoableReplace : IUndoableOperation
18 | {
19 | private readonly IDocument document;
20 |
21 | // int oldCaretPos;
22 | private readonly int offset;
23 | private readonly string origText;
24 | private readonly string text;
25 |
26 | ///
27 | /// Creates a new instance of
28 | ///
29 | public UndoableReplace(IDocument document, int offset, string origText, string text)
30 | {
31 | if (document == null)
32 | throw new ArgumentNullException(nameof(document));
33 | if (offset < 0 || offset > document.TextLength)
34 | throw new ArgumentOutOfRangeException(nameof(offset));
35 |
36 | Debug.Assert(text != null, "text can't be null");
37 | // oldCaretPos = document.Caret.Offset;
38 | this.document = document;
39 | this.offset = offset;
40 | this.text = text;
41 | this.origText = origText;
42 | }
43 |
44 | ///
45 | /// Undo last operation
46 | ///
47 | public void Undo()
48 | {
49 | // we clear all selection direct, because the redraw
50 | // is done per refresh at the end of the action
51 | // document.SelectionCollection.Clear();
52 |
53 | document.UndoStack.AcceptChanges = false;
54 | document.Replace(offset, text.Length, origText);
55 | // document.Caret.Offset = Math.Min(document.TextLength, Math.Max(0, oldCaretPos));
56 | document.UndoStack.AcceptChanges = true;
57 | }
58 |
59 | ///
60 | /// Redo last undone operation
61 | ///
62 | public void Redo()
63 | {
64 | // we clear all selection direct, because the redraw
65 | // is done per refresh at the end of the action
66 | // document.SelectionCollection.Clear();
67 |
68 | document.UndoStack.AcceptChanges = false;
69 | document.Replace(offset, origText.Length, text);
70 | // document.Caret.Offset = Math.Min(document.TextLength, Math.Max(0, document.Caret.Offset));
71 | document.UndoStack.AcceptChanges = true;
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/Project/Src/Util/LoggingService.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 |
10 | namespace ICSharpCode.TextEditor.Util
11 | {
12 | ///
13 | /// Central location for logging calls in the text editor.
14 | ///
15 | internal static class LoggingService
16 | {
17 | public static void Debug(string text)
18 | {
19 | #if DEBUG
20 | Console.WriteLine(text);
21 | #endif
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/Project/Src/Util/MouseWheelHandler.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Windows.Forms;
10 |
11 | namespace ICSharpCode.TextEditor.Util
12 | {
13 | ///
14 | /// Accumulates mouse wheel deltas and reports the actual number of lines to scroll.
15 | ///
16 | internal class MouseWheelHandler
17 | {
18 | // CODE DUPLICATION: See ICSharpCode.SharpDevelop.Widgets.MouseWheelHandler
19 |
20 | private const int WHEEL_DELTA = 120;
21 |
22 | private int mouseWheelDelta;
23 |
24 | public int GetScrollAmount(MouseEventArgs e)
25 | {
26 | // accumulate the delta to support high-resolution mice
27 | mouseWheelDelta += e.Delta;
28 |
29 | var linesPerClick = Math.Max(SystemInformation.MouseWheelScrollLines, val2: 1);
30 |
31 | var scrollDistance = mouseWheelDelta*linesPerClick/WHEEL_DELTA;
32 | mouseWheelDelta %= Math.Max(val1: 1, WHEEL_DELTA/linesPerClick);
33 | return scrollDistance;
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/Project/Src/Util/RedBlackTreeIterator.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Collections;
10 | using System.Collections.Generic;
11 |
12 | namespace ICSharpCode.TextEditor.Util
13 | {
14 | internal struct RedBlackTreeIterator : IEnumerator
15 | {
16 | internal RedBlackTreeNode node;
17 |
18 | internal RedBlackTreeIterator(RedBlackTreeNode node)
19 | {
20 | this.node = node;
21 | }
22 |
23 | public bool IsValid => node != null;
24 |
25 | public T Current
26 | {
27 | get
28 | {
29 | if (node != null)
30 | return node.val;
31 | throw new InvalidOperationException();
32 | }
33 | }
34 |
35 | object IEnumerator.Current => Current;
36 |
37 | void IDisposable.Dispose()
38 | {
39 | }
40 |
41 | void IEnumerator.Reset()
42 | {
43 | throw new NotSupportedException();
44 | }
45 |
46 | public bool MoveNext()
47 | {
48 | if (node == null)
49 | return false;
50 | if (node.right != null)
51 | {
52 | node = node.right.LeftMost;
53 | }
54 | else
55 | {
56 | RedBlackTreeNode oldNode;
57 | do
58 | {
59 | oldNode = node;
60 | node = node.parent;
61 | // we are on the way up from the right part, don't output node again
62 | } while (node != null && node.right == oldNode);
63 | }
64 |
65 | return node != null;
66 | }
67 |
68 | public bool MoveBack()
69 | {
70 | if (node == null)
71 | return false;
72 | if (node.left != null)
73 | {
74 | node = node.left.RightMost;
75 | }
76 | else
77 | {
78 | RedBlackTreeNode oldNode;
79 | do
80 | {
81 | oldNode = node;
82 | node = node.parent;
83 | // we are on the way up from the left part, don't output node again
84 | } while (node != null && node.left == oldNode);
85 | }
86 |
87 | return node != null;
88 | }
89 | }
90 | }
--------------------------------------------------------------------------------
/Project/Src/Util/TextUtility.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using ICSharpCode.TextEditor.Document;
9 |
10 | namespace ICSharpCode.TextEditor.Util
11 | {
12 | public class TextUtility
13 | {
14 | public static bool RegionMatches(IDocument document, int offset, int length, string word)
15 | {
16 | if (length != word.Length || document.TextLength < offset + length)
17 | return false;
18 |
19 | for (var i = 0; i < length; ++i)
20 | if (document.GetCharAt(offset + i) != word[i])
21 | return false;
22 | return true;
23 | }
24 |
25 | public static bool RegionMatches(IDocument document, bool casesensitive, int offset, int length, string word)
26 | {
27 | if (casesensitive)
28 | return RegionMatches(document, offset, length, word);
29 |
30 | if (length != word.Length || document.TextLength < offset + length)
31 | return false;
32 |
33 | for (var i = 0; i < length; ++i)
34 | if (char.ToUpper(document.GetCharAt(offset + i)) != char.ToUpper(word[i]))
35 | return false;
36 | return true;
37 | }
38 |
39 | public static bool RegionMatches(IDocument document, int offset, int length, char[] word)
40 | {
41 | if (length != word.Length || document.TextLength < offset + length)
42 | return false;
43 |
44 | for (var i = 0; i < length; ++i)
45 | if (document.GetCharAt(offset + i) != word[i])
46 | return false;
47 | return true;
48 | }
49 |
50 | public static bool RegionMatches(IDocument document, bool casesensitive, int offset, int length, char[] word)
51 | {
52 | if (casesensitive)
53 | return RegionMatches(document, offset, length, word);
54 |
55 | if (length != word.Length || document.TextLength < offset + length)
56 | return false;
57 |
58 | for (var i = 0; i < length; ++i)
59 | if (char.ToUpper(document.GetCharAt(offset + i)) != char.ToUpper(word[i]))
60 | return false;
61 | return true;
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/Project/Src/Util/TipSection.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Diagnostics;
10 | using System.Drawing;
11 |
12 | namespace ICSharpCode.TextEditor.Util
13 | {
14 | internal abstract class TipSection
15 | {
16 | private SizeF tipRequiredSize;
17 |
18 | protected TipSection(Graphics graphics)
19 | {
20 | Graphics = graphics;
21 | }
22 |
23 | protected Graphics Graphics { get; }
24 |
25 | protected SizeF AllocatedSize { get; private set; }
26 |
27 | protected SizeF MaximumSize { get; private set; }
28 |
29 | public abstract void Draw(PointF location);
30 |
31 | public SizeF GetRequiredSize()
32 | {
33 | return tipRequiredSize;
34 | }
35 |
36 | public void SetAllocatedSize(SizeF allocatedSize)
37 | {
38 | Debug.Assert(
39 | allocatedSize.Width >= tipRequiredSize.Width &&
40 | allocatedSize.Height >= tipRequiredSize.Height);
41 |
42 | AllocatedSize = allocatedSize;
43 | OnAllocatedSizeChanged();
44 | }
45 |
46 | public void SetMaximumSize(SizeF maximumSize)
47 | {
48 | MaximumSize = maximumSize;
49 | OnMaximumSizeChanged();
50 | }
51 |
52 | protected virtual void OnAllocatedSizeChanged()
53 | {
54 | }
55 |
56 | protected virtual void OnMaximumSizeChanged()
57 | {
58 | }
59 |
60 | protected void SetRequiredSize(SizeF requiredSize)
61 | {
62 | requiredSize.Width = Math.Max(val1: 0, requiredSize.Width);
63 | requiredSize.Height = Math.Max(val1: 0, requiredSize.Height);
64 | requiredSize.Width = Math.Min(MaximumSize.Width, requiredSize.Width);
65 | requiredSize.Height = Math.Min(MaximumSize.Height, requiredSize.Height);
66 |
67 | tipRequiredSize = requiredSize;
68 | }
69 | }
70 | }
--------------------------------------------------------------------------------
/Project/Src/Util/TipSpacer.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Drawing;
10 |
11 | namespace ICSharpCode.TextEditor.Util
12 | {
13 | internal class TipSpacer : TipSection
14 | {
15 | private readonly SizeF spacerSize;
16 |
17 | public TipSpacer(Graphics graphics, SizeF size) : base(graphics)
18 | {
19 | spacerSize = size;
20 | }
21 |
22 | public override void Draw(PointF location)
23 | {
24 | }
25 |
26 | protected override void OnMaximumSizeChanged()
27 | {
28 | base.OnMaximumSizeChanged();
29 |
30 | SetRequiredSize(
31 | new SizeF
32 | (
33 | Math.Min(MaximumSize.Width, spacerSize.Width),
34 | Math.Min(MaximumSize.Height, spacerSize.Height)));
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/Project/Src/Util/TipSplitter.cs:
--------------------------------------------------------------------------------
1 | //
2 | //
3 | //
4 | //
5 | // $Revision$
6 | //
7 |
8 | using System;
9 | using System.Diagnostics;
10 | using System.Drawing;
11 |
12 | namespace ICSharpCode.TextEditor.Util
13 | {
14 | internal class TipSplitter : TipSection
15 | {
16 | private readonly bool isHorizontal;
17 | private readonly float[] offsets;
18 | private readonly TipSection[] tipSections;
19 |
20 | public TipSplitter(Graphics graphics, bool horizontal, params TipSection[] sections) : base(graphics)
21 | {
22 | Debug.Assert(sections != null);
23 |
24 | isHorizontal = horizontal;
25 | offsets = new float[sections.Length];
26 | tipSections = (TipSection[])sections.Clone();
27 | }
28 |
29 | public override void Draw(PointF location)
30 | {
31 | if (isHorizontal)
32 | for (var i = 0; i < tipSections.Length; i++)
33 | tipSections[i].Draw
34 | (new PointF(location.X + offsets[i], location.Y));
35 | else
36 | for (var i = 0; i < tipSections.Length; i++)
37 | tipSections[i].Draw
38 | (new PointF(location.X, location.Y + offsets[i]));
39 | }
40 |
41 | protected override void OnMaximumSizeChanged()
42 | {
43 | base.OnMaximumSizeChanged();
44 |
45 | float currentDim = 0;
46 | float otherDim = 0;
47 | var availableArea = MaximumSize;
48 |
49 | for (var i = 0; i < tipSections.Length; i++)
50 | {
51 | var section = tipSections[i];
52 |
53 | section.SetMaximumSize(availableArea);
54 |
55 | var requiredArea = section.GetRequiredSize();
56 | offsets[i] = currentDim;
57 |
58 | // It's best to start on pixel borders, so this will
59 | // round up to the nearest pixel. Otherwise there are
60 | // weird cutoff artifacts.
61 | float pixelsUsed;
62 |
63 | if (isHorizontal)
64 | {
65 | pixelsUsed = (float)Math.Ceiling(requiredArea.Width);
66 | currentDim += pixelsUsed;
67 |
68 | availableArea.Width = Math.Max
69 | (val1: 0, availableArea.Width - pixelsUsed);
70 |
71 | otherDim = Math.Max(otherDim, requiredArea.Height);
72 | }
73 | else
74 | {
75 | pixelsUsed = (float)Math.Ceiling(requiredArea.Height);
76 | currentDim += pixelsUsed;
77 |
78 | availableArea.Height = Math.Max
79 | (val1: 0, availableArea.Height - pixelsUsed);
80 |
81 | otherDim = Math.Max(otherDim, requiredArea.Width);
82 | }
83 | }
84 |
85 | foreach (var section in tipSections)
86 | if (isHorizontal)
87 | section.SetAllocatedSize(new SizeF(section.GetRequiredSize().Width, otherDim));
88 | else
89 | section.SetAllocatedSize(new SizeF(otherDim, section.GetRequiredSize().Height));
90 |
91 | if (isHorizontal)
92 | SetRequiredSize(new SizeF(currentDim, otherDim));
93 | else
94 | SetRequiredSize(new SizeF(otherDim, currentDim));
95 | }
96 | }
97 | }
--------------------------------------------------------------------------------
/Project/Src/Util/Win32Util.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 |
4 | namespace ICSharpCode.TextEditor.Util
5 | {
6 | public static class Win32Util
7 | {
8 | public static Point ToPoint(this IntPtr lparam) =>
9 | new Point(unchecked((int)lparam.ToInt64()));
10 |
11 | public static int SignedLOWORD(nint n)
12 | => SignedLOWORD(unchecked((int)n));
13 |
14 | public static int SignedHIWORD(nint n)
15 | => SignedHIWORD(unchecked((int)n));
16 |
17 | public static int SignedHIWORD(int n)
18 | => (int)(short)HIWORD(n);
19 |
20 | public static int HIWORD(int n)
21 | => (n >> 16) & 0xffff;
22 |
23 | public static int LOWORD(int n)
24 | => n & 0xffff;
25 |
26 | public static int SignedLOWORD(int n)
27 | => (int)(short)LOWORD(n);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ICSharpCode.TextEditor
2 | ICSharpCode.TextEditor for WinForms from SharpDevelop 3.2
3 |
--------------------------------------------------------------------------------
/Sample.md:
--------------------------------------------------------------------------------
1 | # Title1
2 |
3 | ## Title2
4 |
5 | ### Title3
6 |
7 | #### Title4
8 |
9 | This *is italic*.
10 | This _is italic_.
11 | This **is bold**.
12 | This __is bold__.
13 |
14 | > Blockquote
15 |
16 | Example of `code inlined`.
17 |
18 | ```
19 | some
20 | multiline
21 | code
22 | ```
23 |
24 |
25 | some other code
26 |
27 | Lists:
28 |
29 | 1. of
30 | 2. ordered
31 | 3. items
32 |
33 |
34 | * of
35 | * unordered
36 | * items
37 |
38 | Links:
39 |
40 | [Web](https://github.com/gitextensions/gitextensions)
41 | [relative](README.md)
42 |
43 | Some html:
44 |
45 |
46 |
--------------------------------------------------------------------------------
/Test/HighlightingManagerTests.cs:
--------------------------------------------------------------------------------
1 | using ICSharpCode.TextEditor.Document;
2 | using NUnit.Framework;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Xml.Linq;
6 |
7 | namespace ICSharpCode.TextEditor.Tests
8 | {
9 | [TestFixture]
10 | public class HighlightingManagerTests
11 | {
12 | [TestCase("test.xml", "XML")]
13 | [TestCase("test.vcxproj.filters", "XML")] //Extension with a '.' inside
14 | [TestCase("test.cs", "C#")] //lowercase
15 | [TestCase("test.CS", "C#")] //Upper case
16 | [TestCase("test.htm", "HTML")]
17 | public void FindHighlighterForFile_Should_find_Highlight_strategy(string filename, string expectedStrategy)
18 | {
19 | IHighlightingStrategy highlightingStrategy = HighlightingManager.Manager.FindHighlighterForFile(filename);
20 | Assert.AreEqual(expectedStrategy, highlightingStrategy.Name);
21 | }
22 |
23 | [Test]
24 | public void FindHighlighterForFile_Should_not_find_Highlight_strategy()
25 | {
26 | IHighlightingStrategy highlightingStrategy = HighlightingManager.Manager.FindHighlighterForFile("test.unkown");
27 | Assert.AreEqual("Default", highlightingStrategy.Name);
28 | }
29 |
30 | [Test]
31 | public void ResourceStreamNamesMatchSyntaxNodes()
32 | {
33 | Assembly assembly = typeof(ICSharpCode.TextEditor.Document.ResourceSyntaxModeProvider).Assembly;
34 | var resources = assembly.GetManifestResourceNames();
35 | var syntaxNodesResource = resources.First(r => r.Contains("SyntaxModes"));
36 | var xmlModes = XElement.Load(assembly.GetManifestResourceStream(syntaxNodesResource)).Elements("Mode");
37 | var resourcesToCheck = resources.Where(r => r.EndsWith("xshd"));
38 |
39 | var matched = from xml in xmlModes
40 | join res in resourcesToCheck on xml.Attribute("file").Value equals
41 | res.Replace("ICSharpCode.TextEditor.Resources.", "")
42 | select new { ResourceName = res, XMLModeFile = xml.Attribute("file").Value };
43 |
44 | var missingInXML = resourcesToCheck.Except(matched.Select(m => m.ResourceName));
45 |
46 | var missingInResources = from nd in xmlModes
47 | where !matched.Select(m => m.XMLModeFile).Contains(nd.Attribute("file").Value)
48 | select nd.Attribute("file").Value;
49 |
50 | Assert.That(!missingInXML.Any(), "The SyntaxNodes.xml file is out of sync with the actual resources. Check the following resource names that don't exist in xml file. {0}", string.Join(",", missingInXML));
51 | Assert.That(!missingInResources.Any(), "The SyntaxNodes.xml file is out of sync with the actual resources. Check the following resource names that don't exist in embedded resources. {0}", string.Join(",", missingInResources));
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Test/ICSharpCode.TextEditor.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Library
5 | ..\..\..\..\bin\UnitTests
6 | net9.0-windows
7 | true
8 |
9 |
10 |
11 |
12 | {2d18be89-d210-49eb-a9dd-2246fbb3df6d}
13 | ICSharpCode.TextEditor
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/Test/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: 4.1.0.{build}
2 |
3 | branches:
4 | except:
5 | - /experimental\/*/
6 |
7 | matrix:
8 | fast_finish: true
9 |
10 | # https://www.appveyor.com/docs/build-environment/#build-worker-images
11 | image: Visual Studio 2022
12 |
13 | environment:
14 | # Disable the .NET logo in the console output.
15 | DOTNET_NOLOGO: true
16 | # Disable the .NET first time experience to skip caching NuGet packages and speed up the build.
17 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
18 | # Use latest version of current used .NET version. 6.0 could use the latest of 6.0. See .\Scripts\Update-DotnetVersion.ps1
19 | GE_USE_LATEST_DOTNET: false
20 |
21 | # Build settings, not to be confused with "before_build" and "after_build".
22 | # "project" is relative to the original build directory and not influenced by directory changes in "before_build".
23 | build:
24 | # enable MSBuild parallel builds
25 | parallel: true
26 | # MSBuild verbosity level
27 | verbosity: minimal
28 |
29 | # to run your custom scripts instead of automatic MSBuild
30 | build_script:
31 | - ps: |
32 | # Install the required .NET SDK
33 | Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile "./dotnet-install.ps1"
34 | ./dotnet-install.ps1 -Channel LTS -InstallDir 'C:\Program Files\dotnet'
35 | # Remove the script so it doesn't "pollute" the build
36 | Remove-Item -Path .\dotnet-install.ps1
37 | - ps: |
38 | # build .NET
39 | dotnet build -c Release --verbosity q --nologo /bl:.\build.binlog
40 | if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
41 |
42 | # to run your custom scripts instead of automatic tests
43 | test_script:
44 | - ps: |
45 | dotnet test -c Release --no-restore --nologo --verbosity q --test-adapter-path:. --logger:Appveyor --logger:trx /bl:.\tests.binlog
46 | if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
47 |
48 | # on build failure
49 | on_failure:
50 | - ps: |
51 | Get-ChildItem -recurse *.binlog -ErrorAction SilentlyContinue `
52 | | ForEach-Object {
53 | Push-AppveyorArtifact "$_"
54 | }
55 | - ps: |
56 | Get-ChildItem -recurse Test\TestsResults\*.trx | `
57 | ForEach-Object {
58 | $file = $_.FullName.Replace('[', '``[').Replace(']', '``]')
59 | #Write-Output "Processing $file"
60 |
61 | [xml]$xml = Get-Content -Path $file
62 | $xml.TestRun.Results.UnitTestResult | Where-Object outcome -eq 'Failed' | ForEach-Object {
63 | $errorMessage = "$($_.Output.ErrorInfo.Message)`r`n$($_.Output.ErrorInfo.StackTrace)`r`n"
64 | Write-Host $errorMessage -ForegroundColor Red
65 | }
66 | }
67 |
--------------------------------------------------------------------------------