CodePageDesigner.Mono.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. using FastReport.Code;
  2. using FastReport.Data;
  3. using FastReport.Design.ToolWindows;
  4. using FastReport.Forms;
  5. using FastReport.Utils;
  6. using System;
  7. using System.Drawing;
  8. using System.Reflection;
  9. using System.Windows.Forms;
  10. namespace FastReport.Design.PageDesigners.Code
  11. {
  12. internal interface ITextEditor
  13. {
  14. string Text { get; set; }
  15. bool Focus();
  16. void Select(int start, int length);
  17. }
  18. internal class SyntaxEditorBase : TextBox, ITextEditor
  19. {
  20. public void Locate(int line, int column)
  21. {
  22. // nope...
  23. }
  24. }
  25. internal class TextEditor : SyntaxEditorBase
  26. {
  27. }
  28. internal class CodePageDesigner : PageDesignerBase
  29. {
  30. #region Fields
  31. private bool canModify;
  32. #endregion
  33. #region Properties
  34. public TextEditor Edit { get; private set; }
  35. public string Script
  36. {
  37. get => Edit.Text;
  38. set => SetText(value);
  39. }
  40. #endregion
  41. #region Private Methods
  42. private void CreateEdit()
  43. {
  44. Edit = new TextEditor();
  45. Edit.Multiline = true;
  46. Edit.AcceptsReturn = true;
  47. Edit.AcceptsTab = true;
  48. Edit.Font = DrawUtils.FixedFont;
  49. Edit.Dock = DockStyle.Fill;
  50. Edit.BorderStyle = BorderStyle.None;
  51. Edit.MaxLength = int.MaxValue;
  52. Edit.AllowDrop = true;
  53. Edit.DragOver += new DragEventHandler(Edit_DragOver);
  54. Edit.DragDrop += new DragEventHandler(Edit_DragDrop);
  55. Controls.Add(Edit);
  56. Edit.ScrollBars = ScrollBars.Both;
  57. Edit.TextChanged += new EventHandler(Edit_TextChanged);
  58. Edit.ImeMode = ImeMode.On;
  59. }
  60. private void SetText(string value)
  61. {
  62. canModify = false;
  63. Edit.Text = value;
  64. Edit.Modified = false;
  65. canModify = true;
  66. }
  67. private void Edit_DragOver(object sender, DragEventArgs e)
  68. {
  69. int index = Edit.GetCharIndexFromPosition(Edit.PointToClient(new Point(e.X, e.Y)));
  70. Edit.Select(index, 0);
  71. e.Effect = e.AllowedEffect;
  72. }
  73. private void Edit_DragDrop(object sender, DragEventArgs e)
  74. {
  75. DictionaryWindow.DraggedItem item = DictionaryWindow.DragUtils.GetOne(e);
  76. if (item == null)
  77. return;
  78. CodeHelperBase codeHelper = Designer.ActiveReport.Report.CodeHelper;
  79. string text = "";
  80. if (item.obj is Column)
  81. text = codeHelper.ReplaceColumnName(item.text, (item.obj as Column).DataType);
  82. else if (item.obj is SystemVariable)
  83. text = codeHelper.ReplaceVariableName(item.obj as Parameter);
  84. else if (item.obj is Parameter)
  85. text = codeHelper.ReplaceParameterName(item.obj as Parameter);
  86. else if (item.obj is Total)
  87. text = codeHelper.ReplaceTotalName(item.text);
  88. else if (item.obj is MethodInfo)
  89. text = item.text;
  90. else
  91. text = "Report.Calc(\"" + item.text + "\")";
  92. Edit.SelectedText = text;
  93. Edit.Focus();
  94. }
  95. private void Edit_TextChanged(object sender, EventArgs e)
  96. {
  97. if (canModify)
  98. Designer.SetModified(null, "no-undo");
  99. }
  100. public void CommitChanges()
  101. {
  102. if (Edit.Modified)
  103. {
  104. Edit.Modified = false;
  105. Designer.SetModified(this, "Script");
  106. }
  107. }
  108. #endregion
  109. #region Public Methods
  110. public void UpdateFont()
  111. {
  112. }
  113. public void UpdateLanguage()
  114. {
  115. // do nothing
  116. }
  117. public override bool CanCopy() => true;
  118. public override void Copy()
  119. {
  120. Edit.Copy();
  121. }
  122. public override void Cut()
  123. {
  124. Edit.Cut();
  125. }
  126. public override bool CanPaste() => true;
  127. public override void Paste()
  128. {
  129. Edit.Paste();
  130. }
  131. public override bool CanUndo()
  132. {
  133. return Edit.CanUndo;
  134. }
  135. public override void Undo()
  136. {
  137. Edit.Undo();
  138. }
  139. public override void SelectAll()
  140. {
  141. Edit.SelectAll();
  142. }
  143. public override void ResetModified()
  144. {
  145. Edit.Modified = false;
  146. }
  147. public override void FillObjects(bool resetSelection)
  148. {
  149. // do nothing
  150. }
  151. public override void PageDeactivated()
  152. {
  153. base.PageDeactivated();
  154. CommitChanges();
  155. }
  156. #endregion
  157. #region IDesignerPlugin
  158. public override void SaveState()
  159. {
  160. CodePageSettings.SaveState();
  161. }
  162. public override void RestoreState()
  163. {
  164. }
  165. public override DesignerOptionsPage GetOptionsPage()
  166. {
  167. return new CodePageOptions(this);
  168. }
  169. #endregion
  170. public CodePageDesigner(Designer designer) : base(designer)
  171. {
  172. Name = "Code";
  173. CreateEdit();
  174. }
  175. }
  176. }