123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Reflection;
- using FastReport.Utils;
- using FastReport.Data;
- using FastReport.Controls;
- namespace FastReport.Forms
- {
- internal partial class ExpressionEditorForm : BaseDialogForm
- {
- private Report report;
- private static List<string> expandedNodes;
- public string ExpressionText
- {
- get { return tbText.Text; }
- set { tbText.Text = value; }
- }
- private string GetTextWithBrackets()
- {
- if (tvData.SelectedItemType == DataTreeSelectedItemType.Function ||
- tvData.SelectedItemType == DataTreeSelectedItemType.CustomItem)
- return tvData.SelectedItem;
- return "[" + tvData.SelectedItem + "]";
- }
- private void tbText_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter && e.Control)
- DialogResult = DialogResult.OK;
- else if (e.KeyData == (Keys.A | Keys.Control))
- tbText.SelectAll();
- }
- private void tvData_AfterSelect(object sender, TreeViewEventArgs e)
- {
- bool descrVisible = tvData.SelectedNode != null &&
- (tvData.SelectedNode.Tag is MethodInfo || tvData.SelectedNode.Tag is SystemVariable);
- expandableSplitter1.Visible = descrVisible;
- lblDescription.Visible = descrVisible;
- if (descrVisible)
- lblDescription.ShowDescription(report, tvData.SelectedNode.Tag);
- }
- private void tvData_ItemDrag(object sender, ItemDragEventArgs e)
- {
- tvData.SelectedNode = e.Item as TreeNode;
- if (tvData.SelectedItem != "")
- tvData.DoDragDrop(e.Item, DragDropEffects.Move);
- else
- tvData.DoDragDrop(e.Item, DragDropEffects.None);
- }
- private void tbText_DragOver(object sender, DragEventArgs e)
- {
- int index = tbText.GetCharIndexFromPosition(tbText.PointToClient(new Point(e.X, e.Y)));
- if (index == tbText.Text.Length - 1)
- index++;
- tbText.Focus();
- tbText.Select(index, 0);
- e.Effect = e.AllowedEffect;
- }
- private void tbText_DragDrop(object sender, DragEventArgs e)
- {
- tbText.SelectedText = GetTextWithBrackets();
- tbText.Focus();
- }
- private void tvData_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
- {
- if (tvData.SelectedItem != "")
- {
- tbText.SelectedText = GetTextWithBrackets();
- tbText.Focus();
- }
- }
- private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
- {
- tbText.Focus();
- }
- private void TextEditorForm_Shown(object sender, EventArgs e)
- {
- tbText.Focus();
- tbText.Select(0, 0);
- }
- private void Init()
- {
- tvData.CreateNodes(report.Dictionary);
- }
- protected override void SaveState()
- {
- base.SaveState();
- Storage.SetDip("Splitter", splitContainer1.SplitterDistance);
- Storage.SetDip("DescriptionHeight", lblDescription.Height);
- expandedNodes = tvData.ExpandedNodes;
- }
- protected override void RestoreState()
- {
- base.RestoreState();
- splitContainer1.SplitterDistance = Storage.GetDip("Splitter", 320, 50, Width - 50);
- lblDescription.Height = Storage.GetDip("DescriptionHeight", 50, 50, 200);
- if (expandedNodes != null)
- tvData.ExpandedNodes = expandedNodes;
- }
- public override void Localize()
- {
- base.Localize();
- Text = Res.Get("Forms,ExpressionEditor");
- }
- public override void UpdateDpiDependencies()
- {
- base.UpdateDpiDependencies();
- tvData.ImageList = GetImages();
- tbText.Font = this.LogicalToDevice(Storage.GetFont("FormulaEditor", DrawUtils.FixedFont), true);
- MinimumSize = this.LogicalToDevice(new Size(360, 230));
- }
- public ExpressionEditorForm(Report report)
- {
- this.report = report;
- CanSaveRestoreState = true;
- InitializeComponent();
- Localize();
- Init();
- UIUtils.CheckRTL(this);
- UpdateDpiDependencies();
- }
- }
- }
|