SyntaxEditorBase.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Runtime.CompilerServices;
  5. using System.Windows.Forms;
  6. namespace FastReport.Design.PageDesigners.Code
  7. {
  8. internal interface ITextEditor
  9. {
  10. string Text { get; set; }
  11. void Focus();
  12. void Select(int start, int length);
  13. }
  14. public enum SyntaxType
  15. {
  16. None,
  17. Cs,
  18. Vb,
  19. Xml
  20. }
  21. public abstract class SyntaxEditorBase : Control, ITextEditor
  22. {
  23. public abstract string SelectedText { get; set; }
  24. public abstract bool Modified { get; set; }
  25. public abstract bool ShowLineNumbers { get; set; }
  26. public abstract bool EnableVirtualSpace { get; set; }
  27. public abstract bool ConvertTabsToSpaces { get; set; }
  28. public abstract int IndentationSize { get; set; }
  29. public abstract SyntaxType SyntaxType { get; set; }
  30. public abstract bool AllowCodeCompletion { get; set; }
  31. public new event EventHandler TextChanged;
  32. protected void OnTextChanged() => TextChanged?.Invoke(this, EventArgs.Empty);
  33. public abstract void Cut();
  34. public abstract void Copy();
  35. public abstract void Paste();
  36. public abstract bool CanUndo { get; }
  37. public abstract void Undo();
  38. public abstract bool CanRedo { get; }
  39. public abstract void Redo();
  40. public abstract void SelectAll();
  41. public abstract new void Focus();
  42. public abstract void Locate(int line, int column);
  43. public abstract void Select(int start, int length);
  44. public abstract void SetCaretFromMousePosition(System.Drawing.Point pos);
  45. // for code completion
  46. public abstract void UpdateInternals(Report report);
  47. }
  48. public enum SyntaxEditorKind
  49. {
  50. Code,
  51. Xml
  52. }
  53. public static class SyntaxEditorClass
  54. {
  55. private static Dictionary<SyntaxEditorKind, Type> syntaxEditorTypes;
  56. private static Dictionary<SyntaxEditorKind, Type> SyntaxEditorTypes
  57. {
  58. get
  59. {
  60. if (syntaxEditorTypes == null)
  61. {
  62. syntaxEditorTypes = new Dictionary<SyntaxEditorKind, Type>();
  63. syntaxEditorTypes[SyntaxEditorKind.Code] = typeof(AvalonSyntaxEditor);
  64. syntaxEditorTypes[SyntaxEditorKind.Xml] = typeof(AvalonSyntaxEditor);
  65. }
  66. return syntaxEditorTypes;
  67. }
  68. }
  69. internal static SyntaxEditorBase CreateInstance(SyntaxEditorKind editorKind) => Activator.CreateInstance(SyntaxEditorTypes[editorKind]) as SyntaxEditorBase;
  70. public static void Register(Type editorType, SyntaxEditorKind editorKind)
  71. {
  72. if (!typeof(SyntaxEditorBase).IsAssignableFrom(editorType))
  73. throw new ArgumentException("editorType must be of SyntaxEditorBase type");
  74. SyntaxEditorTypes[editorKind] = editorType;
  75. }
  76. }
  77. }