123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- using System;
- using System.Windows.Forms;
- using System.Drawing;
- using System.ComponentModel;
- using FastReport.Editor;
- using FastReport.Editor.Common;
- using FastReport.Editor.Syntax;
- using FastReport.Utils;
- using FastReport.Forms;
- namespace FastReport.Design.PageDesigners.Code
- {
- internal class FRXPageDesigner : PageDesignerBase
- {
- #region Fields
- private SyntaxEdit edit;
- private TextSource source;
- private bool editInitialized;
- private Point positionInText;
- private bool canModify;
- Font defaultFont;
- #endregion
- #region Properties
- public SyntaxEdit Edit
- {
- get
- {
- if (!editInitialized)
- CreateEdit();
- return edit;
- }
- }
- public TextSource Source
- {
- get
- {
- if (!editInitialized)
- CreateEdit();
- return source;
- }
- }
- #endregion
- #region Private Methods
- private void CreateEdit()
- {
- editInitialized = true;
- source = new TextSource();
- edit = new SyntaxEdit();
- defaultFont = edit.Font;
- edit.Dock = DockStyle.Fill;
- edit.BorderStyle = EditBorderStyle.None;
- edit.Source = source;
- edit.AllowDrop = true;
- edit.TextChanged += Edit_TextChanged;
- Controls.Add(edit);
- // do this after controls.add!
- edit.IndentOptions = IndentOptions.AutoIndent | IndentOptions.SmartIndent;
- edit.NavigateOptions = NavigateOptions.BeyondEol;
- edit.Braces.BracesOptions = BracesOptions.Highlight | BracesOptions.HighlightBounds;
- edit.Braces.BackColor = Color.LightGray;
- edit.Braces.Style = FontStyle.Regular;
- edit.Scroll.ScrollBars = RichTextBoxScrollBars.Both;
- edit.Scroll.Options = ScrollingOptions.AllowSplitHorz | ScrollingOptions.AllowSplitVert | ScrollingOptions.SmoothScroll;
- edit.Outlining.AllowOutlining = true;
- edit.DisplayLines.UseSpaces = true;
- edit.SplitHorz += new EventHandler(Edit_SplitHorz);
- edit.SplitVert += new EventHandler(Edit_SplitVert);
- edit.ImeMode = ImeMode.On;
- UpdateOptions();
- UpdateEditColors();
- UpdateFont();
- LocalizeEditMenu();
- }
- private void Edit_TextChanged(object sender, EventArgs e)
- {
- if (canModify)
- Designer.SetModified(this, "no-undo");
- }
- private void UpdateEditColors()
- {
- edit.Gutter.BrushColor = UIStyleUtils.GetControlColor(Designer.UIStyle);
- edit.Gutter.PenColor = edit.Gutter.BrushColor;
- }
- private void Edit_SplitHorz(object sender, EventArgs e)
- {
- Edit.HorzSplitEdit.BorderStyle = Edit.BorderStyle;
- }
- private void Edit_SplitVert(object sender, EventArgs e)
- {
- Edit.VertSplitEdit.BorderStyle = Edit.BorderStyle;
- }
- private void LocalizeEditMenu()
- {
- MyRes res = new MyRes("Designer,Menu,Edit");
- StringConsts.MenuUndoCaption = res.Get("Undo");
- StringConsts.MenuRedoCaption = res.Get("Redo");
- StringConsts.MenuCutCaption = res.Get("Cut");
- StringConsts.MenuCopyCaption = res.Get("Copy");
- StringConsts.MenuPasteCaption = res.Get("Paste");
- StringConsts.MenuDeleteCaption = res.Get("Delete");
- StringConsts.MenuSelectAllCaption = res.Get("SelectAll");
- }
- private void SetScriptText()
- {
- canModify = false;
- Edit.Source.Text = Designer.Report.SaveToString();
- Edit.Modified = false;
- canModify = true;
- }
- #endregion
- #region Public Methods
- public void UpdateOptions()
- {
- Edit.DisplayLines.UseSpaces = FRXPageSettings.UseSpaces;
- Edit.DisplayLines.TabStops = new int[] { FRXPageSettings.TabSize };
- }
- public void UpdateFont()
- {
- Edit.Font = this.LogicalToDevice(Storage.GetFont("CodePageDesigner,CodePage", defaultFont));
- }
- public override bool CanCopy() => true;
- public override void Copy()
- {
- Edit.Selection.Copy();
- }
- public override void Cut()
- {
- Edit.Selection.Cut();
- }
- public override bool CanPaste() => true;
- public override void Paste()
- {
- Edit.Selection.Paste();
- }
- public override bool CanUndo()
- {
- return Source.CanUndo();
- }
- public override void Undo()
- {
- Source.Undo();
- }
- public override bool CanRedo()
- {
- return Source.CanRedo();
- }
- public override void Redo()
- {
- Source.Redo();
- }
- public override void SelectAll()
- {
- Edit.Selection.SelectAll();
- }
- public override void ResetModified()
- {
- if (editInitialized)
- Edit.Modified = false;
- }
- public override void FillObjects(bool resetSelection)
- {
- // do nothing
- }
- public override void PageActivated()
- {
- base.PageActivated();
- SetScriptText();
- UpdateOptions();
- UpdateLanguage();
- Edit.Position = new Point(0, 0);
- Edit.Position = positionInText;
- }
- public override void PageDeactivated()
- {
- base.PageDeactivated();
- if (editInitialized)
- {
- CommitChanges();
- positionInText = Edit.Position;
- }
- }
- public override void SaveState()
- {
- FRXPageSettings.SaveState();
- }
- public override void RestoreState()
- {
- }
- public override DesignerOptionsPage GetOptionsPage()
- {
- return new FRXPageOptions(this);
- }
- #endregion
- #region IDesignerPlugin
- public override void UpdateUIStyle()
- {
- base.UpdateUIStyle();
- if (editInitialized)
- UpdateEditColors();
- }
- public override void Localize()
- {
- base.Localize();
- if (editInitialized)
- LocalizeEditMenu();
- }
- public override void UpdateDpiDependencies()
- {
- base.UpdateDpiDependencies();
- if (editInitialized)
- UpdateFont();
- }
- public void UpdateLanguage()
- {
- SyntaxParser parser = new XmlParser();
- parser.Options |= SyntaxOptions.SyntaxErrors;
- Edit.Lexer = parser;
- Source.Lexer = parser;
- Source.FormatText();
- Edit.Refresh();
- }
- public void CommitChanges()
- {
- if (Edit.Modified)
- {
- Edit.Modified = false;
- Designer.ActiveReportTab.UpdateFromFRX(Edit.Source.Text);
- }
- }
- #endregion
- public FRXPageDesigner(Designer designer) : base(designer)
- {
- Name = "FRXPage";
- RightToLeft = Config.RightToLeft ? RightToLeft.Yes : RightToLeft.No;
- }
- }
- }
|