123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Runtime.CompilerServices;
- using System.Windows.Forms;
- namespace FastReport.Design.PageDesigners.Code
- {
- internal interface ITextEditor
- {
- string Text { get; set; }
- void Focus();
- void Select(int start, int length);
- }
- public enum SyntaxType
- {
- None,
- Cs,
- Vb,
- Xml
- }
- public abstract class SyntaxEditorBase : Control, ITextEditor
- {
- public abstract string SelectedText { get; set; }
- public abstract bool Modified { get; set; }
- public abstract bool ShowLineNumbers { get; set; }
- public abstract bool EnableVirtualSpace { get; set; }
- public abstract bool ConvertTabsToSpaces { get; set; }
- public abstract int IndentationSize { get; set; }
- public abstract SyntaxType SyntaxType { get; set; }
- public abstract bool AllowCodeCompletion { get; set; }
- public new event EventHandler TextChanged;
- protected void OnTextChanged() => TextChanged?.Invoke(this, EventArgs.Empty);
- public abstract void Cut();
- public abstract void Copy();
- public abstract void Paste();
- public abstract bool CanUndo { get; }
- public abstract void Undo();
- public abstract bool CanRedo { get; }
- public abstract void Redo();
- public abstract void SelectAll();
- public abstract new void Focus();
- public abstract void Locate(int line, int column);
- public abstract void Select(int start, int length);
- public abstract void SetCaretFromMousePosition(System.Drawing.Point pos);
- // for code completion
- public abstract void UpdateInternals(Report report);
- }
- public enum SyntaxEditorKind
- {
- Code,
- Xml
- }
- public static class SyntaxEditorClass
- {
- private static Dictionary<SyntaxEditorKind, Type> syntaxEditorTypes;
- private static Dictionary<SyntaxEditorKind, Type> SyntaxEditorTypes
- {
- get
- {
- if (syntaxEditorTypes == null)
- {
- syntaxEditorTypes = new Dictionary<SyntaxEditorKind, Type>();
- syntaxEditorTypes[SyntaxEditorKind.Code] = typeof(AvalonSyntaxEditor);
- syntaxEditorTypes[SyntaxEditorKind.Xml] = typeof(AvalonSyntaxEditor);
- }
- return syntaxEditorTypes;
- }
- }
- internal static SyntaxEditorBase CreateInstance(SyntaxEditorKind editorKind) => Activator.CreateInstance(SyntaxEditorTypes[editorKind]) as SyntaxEditorBase;
- public static void Register(Type editorType, SyntaxEditorKind editorKind)
- {
- if (!typeof(SyntaxEditorBase).IsAssignableFrom(editorType))
- throw new ArgumentException("editorType must be of SyntaxEditorBase type");
- SyntaxEditorTypes[editorKind] = editorType;
- }
- }
- }
|