ExpressionEditorForm.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using System.Reflection;
  6. using FastReport.Utils;
  7. using FastReport.Data;
  8. using FastReport.Controls;
  9. namespace FastReport.Forms
  10. {
  11. internal partial class ExpressionEditorForm : BaseDialogForm
  12. {
  13. private Report report;
  14. private static List<string> expandedNodes;
  15. public string ExpressionText
  16. {
  17. get { return tbText.Text; }
  18. set { tbText.Text = value; }
  19. }
  20. private string GetTextWithBrackets()
  21. {
  22. if (tvData.SelectedItemType == DataTreeSelectedItemType.Function ||
  23. tvData.SelectedItemType == DataTreeSelectedItemType.CustomItem)
  24. return tvData.SelectedItem;
  25. return "[" + tvData.SelectedItem + "]";
  26. }
  27. private void tbText_KeyDown(object sender, KeyEventArgs e)
  28. {
  29. if (e.KeyCode == Keys.Enter && e.Control)
  30. DialogResult = DialogResult.OK;
  31. else if (e.KeyData == (Keys.A | Keys.Control))
  32. tbText.SelectAll();
  33. }
  34. private void tvData_AfterSelect(object sender, TreeViewEventArgs e)
  35. {
  36. bool descrVisible = tvData.SelectedNode != null &&
  37. (tvData.SelectedNode.Tag is MethodInfo || tvData.SelectedNode.Tag is SystemVariable);
  38. expandableSplitter1.Visible = descrVisible;
  39. lblDescription.Visible = descrVisible;
  40. if (descrVisible)
  41. lblDescription.ShowDescription(report, tvData.SelectedNode.Tag);
  42. }
  43. private void tvData_ItemDrag(object sender, ItemDragEventArgs e)
  44. {
  45. tvData.SelectedNode = e.Item as TreeNode;
  46. if (tvData.SelectedItem != "")
  47. tvData.DoDragDrop(e.Item, DragDropEffects.Move);
  48. else
  49. tvData.DoDragDrop(e.Item, DragDropEffects.None);
  50. }
  51. private void tbText_DragOver(object sender, DragEventArgs e)
  52. {
  53. int index = tbText.GetCharIndexFromPosition(tbText.PointToClient(new Point(e.X, e.Y)));
  54. if (index == tbText.Text.Length - 1)
  55. index++;
  56. tbText.Focus();
  57. tbText.Select(index, 0);
  58. e.Effect = e.AllowedEffect;
  59. }
  60. private void tbText_DragDrop(object sender, DragEventArgs e)
  61. {
  62. tbText.SelectedText = GetTextWithBrackets();
  63. tbText.Focus();
  64. }
  65. private void tvData_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
  66. {
  67. if (tvData.SelectedItem != "")
  68. {
  69. tbText.SelectedText = GetTextWithBrackets();
  70. tbText.Focus();
  71. }
  72. }
  73. private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
  74. {
  75. tbText.Focus();
  76. }
  77. private void TextEditorForm_Shown(object sender, EventArgs e)
  78. {
  79. tbText.Focus();
  80. tbText.Select(0, 0);
  81. }
  82. private void Init()
  83. {
  84. tvData.CreateNodes(report.Dictionary);
  85. }
  86. protected override void SaveState()
  87. {
  88. base.SaveState();
  89. Storage.SetDip("Splitter", splitContainer1.SplitterDistance);
  90. Storage.SetDip("DescriptionHeight", lblDescription.Height);
  91. expandedNodes = tvData.ExpandedNodes;
  92. }
  93. protected override void RestoreState()
  94. {
  95. base.RestoreState();
  96. splitContainer1.SplitterDistance = Storage.GetDip("Splitter", 320, 50, Width - 50);
  97. lblDescription.Height = Storage.GetDip("DescriptionHeight", 50, 50, 200);
  98. if (expandedNodes != null)
  99. tvData.ExpandedNodes = expandedNodes;
  100. }
  101. public override void Localize()
  102. {
  103. base.Localize();
  104. Text = Res.Get("Forms,ExpressionEditor");
  105. }
  106. public override void UpdateDpiDependencies()
  107. {
  108. base.UpdateDpiDependencies();
  109. tvData.ImageList = GetImages();
  110. tbText.Font = this.LogicalToDevice(Storage.GetFont("FormulaEditor", DrawUtils.FixedFont), true);
  111. MinimumSize = this.LogicalToDevice(new Size(360, 230));
  112. }
  113. public ExpressionEditorForm(Report report)
  114. {
  115. this.report = report;
  116. CanSaveRestoreState = true;
  117. InitializeComponent();
  118. Localize();
  119. Init();
  120. UIUtils.CheckRTL(this);
  121. UpdateDpiDependencies();
  122. }
  123. }
  124. }