This class handles the auto and smart indenting in the textbuffer while you type.
Inheritance: IFormattingStrategy
        //public event EventHandler<DocumentEventArgs> DocumentEventHandler;

        //public event EventHandler<LineLengthChangeEventArgs> LineLengthChanged
        //{
        //    add { LineManager.LineLengthChanged += value; }
        //    remove { LineManager.LineLengthChanged -= value; }
        //}

        //public event EventHandler<LineCountChangeEventArgs> LineCountChanged
        //{
        //    add { LineManager.LineCountChanged += value; }
        //    remove { LineManager.LineCountChanged -= value; }
        //}

        //public event EventHandler<LineEventArgs> LineDeleted
        //{
        //    add { LineManager.LineDeleted += value; }
        //    remove { LineManager.LineDeleted -= value; }
        //}
        #endregion

        #region Lifecycle
        public Document()
        {
            TextBuffer         = new TextBuffer();
            FormattingStrategy = new DefaultFormattingStrategy();
            LineManager        = new LineManager(this, null);
            FoldingManager     = new FoldingManager(this, LineManager);
            MarkerStrategy     = new MarkerStrategy(this);
            BookmarkManager    = new BookmarkManager(this, LineManager);
        }
        protected virtual int AutoIndentLine(TextArea textArea, int lineNumber)
        {
            string str = (lineNumber != 0 ? this.GetIndentation(textArea, lineNumber - 1) : "");

            if (str.Length > 0)
            {
                string      str1        = string.Concat(str, TextUtilities.GetLineAsString(textArea.Document, lineNumber).Trim());
                LineSegment lineSegment = textArea.Document.GetLineSegment(lineNumber);
                DefaultFormattingStrategy.SmartReplaceLine(textArea.Document, lineSegment, str1);
            }
            return(str.Length);
        }
Esempio n. 3
0
 private void InitializeComponent()
 {
     this.components = new System.ComponentModel.Container();
     System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AIScriptEditor));
     //ICSharpCode.TextEditor.Document.DefaultDocument defaultDocument1 = new ICSharpCode.TextEditor.Document.DefaultDocument();
     ICSharpCode.TextEditor.Document.DefaultFormattingStrategy defaultFormattingStrategy1 = new ICSharpCode.TextEditor.Document.DefaultFormattingStrategy();
     ICSharpCode.TextEditor.Document.DefaultHighlightingStrategy defaultHighlightingStrategy1 = new ICSharpCode.TextEditor.Document.DefaultHighlightingStrategy();
     ICSharpCode.TextEditor.Document.GapTextBufferStrategy gapTextBufferStrategy1 = new ICSharpCode.TextEditor.Document.GapTextBufferStrategy();
     ICSharpCode.TextEditor.Document.DefaultTextEditorProperties defaultTextEditorProperties1 = new ICSharpCode.TextEditor.Document.DefaultTextEditorProperties();
     this.editorContext = new System.Windows.Forms.ContextMenu();
     this.mnuCollapseAll = new System.Windows.Forms.MenuItem();
     this.mnuExpandAll = new System.Windows.Forms.MenuItem();
     this.menuItem1 = new System.Windows.Forms.MenuItem();
     this.mnuScriptHelp = new System.Windows.Forms.MenuItem();
     this.openFile = new System.Windows.Forms.OpenFileDialog();
     this.saveFile = new System.Windows.Forms.SaveFileDialog();
     this.pnlActionsNodes = new System.Windows.Forms.Panel();
     this.pnlNodes = new System.Windows.Forms.Panel();
     this.dgNodes = new System.Windows.Forms.DataGrid();
     this.spltActions = new System.Windows.Forms.Splitter();
     this.dgActions = new System.Windows.Forms.DataGrid();
     this.spltActionsNodes = new System.Windows.Forms.Splitter();
     this.imgToolbar = new System.Windows.Forms.ImageList(this.components);
     this.pnlEditor = new System.Windows.Forms.Panel();
     this.pnlScriptEditor = new System.Windows.Forms.Panel();
     this.pnlPadding = new System.Windows.Forms.Panel();
     this.scriptEditor = new ICSharpCode.TextEditor.TextEditorControl();
     this.tbEditor = new System.Windows.Forms.ToolBar();
     this.tbOpen = new System.Windows.Forms.ToolBarButton();
     this.tbNew = new System.Windows.Forms.ToolBarButton();
     this.tbSave = new System.Windows.Forms.ToolBarButton();
     this.tbSaveSplitSep = new System.Windows.Forms.ToolBarButton();
     this.tbScriptHelp = new System.Windows.Forms.ToolBarButton();
     this.tbSplit = new System.Windows.Forms.ToolBarButton();
     this.tbValidateExpandSep = new System.Windows.Forms.ToolBarButton();
     this.tbExpand = new System.Windows.Forms.ToolBarButton();
     this.spltDetails = new System.Windows.Forms.Splitter();
     this.pnlOutput = new System.Windows.Forms.Panel();
     this.lstOutput = new System.Windows.Forms.ListView();
     this.chLine = new System.Windows.Forms.ColumnHeader();
     this.chMessage = new System.Windows.Forms.ColumnHeader();
     this.imgCompletion = new System.Windows.Forms.ImageList(this.components);
     this.tbValidate = new System.Windows.Forms.ToolBarButton();
     this.pnlActionsNodes.SuspendLayout();
     this.pnlNodes.SuspendLayout();
     ((System.ComponentModel.ISupportInitialize)(this.dgNodes)).BeginInit();
     ((System.ComponentModel.ISupportInitialize)(this.dgActions)).BeginInit();
     this.pnlEditor.SuspendLayout();
     this.pnlScriptEditor.SuspendLayout();
     this.pnlPadding.SuspendLayout();
     this.pnlOutput.SuspendLayout();
     this.SuspendLayout();
     //
     // editorContext
     //
     this.editorContext.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
     this.mnuCollapseAll,
     this.mnuExpandAll,
     this.menuItem1,
     this.mnuScriptHelp});
     //
     // mnuCollapseAll
     //
     this.mnuCollapseAll.Index = 0;
     this.mnuCollapseAll.Text = "Collapse All";
     this.mnuCollapseAll.Click += new System.EventHandler(this.mnuCollapseAll_Click);
     //
     // mnuExpandAll
     //
     this.mnuExpandAll.Index = 1;
     this.mnuExpandAll.Text = "Expand All";
     this.mnuExpandAll.Click += new System.EventHandler(this.mnuExpandAll_Click);
     //
     // menuItem1
     //
     this.menuItem1.Index = 2;
     this.menuItem1.Text = "-";
     //
     // mnuScriptHelp
     //
     this.mnuScriptHelp.Index = 3;
     this.mnuScriptHelp.Text = "Script Help";
     this.mnuScriptHelp.Click += new System.EventHandler(this.mnuScriptHelp_Click);
     //
     // pnlActionsNodes
     //
     this.pnlActionsNodes.Controls.Add(this.pnlNodes);
     this.pnlActionsNodes.Controls.Add(this.spltActions);
     this.pnlActionsNodes.Controls.Add(this.dgActions);
     this.pnlActionsNodes.Dock = System.Windows.Forms.DockStyle.Left;
     this.pnlActionsNodes.Location = new System.Drawing.Point(0, 0);
     this.pnlActionsNodes.Name = "pnlActionsNodes";
     this.pnlActionsNodes.Size = new System.Drawing.Size(336, 552);
     this.pnlActionsNodes.TabIndex = 0;
     //
     // pnlNodes
     //
     this.pnlNodes.Controls.Add(this.dgNodes);
     this.pnlNodes.Dock = System.Windows.Forms.DockStyle.Fill;
     this.pnlNodes.Location = new System.Drawing.Point(0, 252);
     this.pnlNodes.Name = "pnlNodes";
     this.pnlNodes.Padding = new System.Windows.Forms.Padding(0, 2, 0, 0);
     this.pnlNodes.Size = new System.Drawing.Size(336, 300);
     this.pnlNodes.TabIndex = 2;
     //
     // dgNodes
     //
     this.dgNodes.BorderStyle = System.Windows.Forms.BorderStyle.None;
     this.dgNodes.CaptionBackColor = System.Drawing.Color.Beige;
     this.dgNodes.CaptionForeColor = System.Drawing.Color.Black;
     this.dgNodes.CaptionText = "Nodes";
     this.dgNodes.DataMember = "";
     this.dgNodes.Dock = System.Windows.Forms.DockStyle.Fill;
     this.dgNodes.HeaderBackColor = System.Drawing.Color.Beige;
     this.dgNodes.HeaderForeColor = System.Drawing.SystemColors.ControlText;
     this.dgNodes.Location = new System.Drawing.Point(0, 2);
     this.dgNodes.Name = "dgNodes";
     this.dgNodes.ReadOnly = true;
     this.dgNodes.Size = new System.Drawing.Size(336, 298);
     this.dgNodes.TabIndex = 0;
     this.dgNodes.TabStop = false;
     //
     // spltActions
     //
     this.spltActions.BackColor = System.Drawing.Color.Beige;
     this.spltActions.Dock = System.Windows.Forms.DockStyle.Top;
     this.spltActions.Location = new System.Drawing.Point(0, 248);
     this.spltActions.Name = "spltActions";
     this.spltActions.Size = new System.Drawing.Size(336, 4);
     this.spltActions.TabIndex = 1;
     this.spltActions.TabStop = false;
     //
     // dgActions
     //
     this.dgActions.BorderStyle = System.Windows.Forms.BorderStyle.None;
     this.dgActions.CaptionBackColor = System.Drawing.Color.Beige;
     this.dgActions.CaptionForeColor = System.Drawing.Color.Black;
     this.dgActions.CaptionText = "Actions";
     this.dgActions.DataMember = "";
     this.dgActions.Dock = System.Windows.Forms.DockStyle.Top;
     this.dgActions.HeaderBackColor = System.Drawing.Color.Beige;
     this.dgActions.HeaderForeColor = System.Drawing.SystemColors.ControlText;
     this.dgActions.Location = new System.Drawing.Point(0, 0);
     this.dgActions.Name = "dgActions";
     this.dgActions.ReadOnly = true;
     this.dgActions.Size = new System.Drawing.Size(336, 248);
     this.dgActions.TabIndex = 0;
     this.dgActions.TabStop = false;
     //
     // spltActionsNodes
     //
     this.spltActionsNodes.BackColor = System.Drawing.Color.Beige;
     this.spltActionsNodes.Location = new System.Drawing.Point(336, 0);
     this.spltActionsNodes.Name = "spltActionsNodes";
     this.spltActionsNodes.Size = new System.Drawing.Size(4, 552);
     this.spltActionsNodes.TabIndex = 1;
     this.spltActionsNodes.TabStop = false;
     //
     // imgToolbar
     //
     this.imgToolbar.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgToolbar.ImageStream")));
     this.imgToolbar.TransparentColor = System.Drawing.Color.Transparent;
     this.imgToolbar.Images.SetKeyName(0, "");
     this.imgToolbar.Images.SetKeyName(1, "");
     this.imgToolbar.Images.SetKeyName(2, "");
     this.imgToolbar.Images.SetKeyName(3, "");
     this.imgToolbar.Images.SetKeyName(4, "");
     this.imgToolbar.Images.SetKeyName(5, "");
     this.imgToolbar.Images.SetKeyName(6, "");
     this.imgToolbar.Images.SetKeyName(7, "");
     this.imgToolbar.Images.SetKeyName(8, "");
     this.imgToolbar.Images.SetKeyName(9, "");
     this.imgToolbar.Images.SetKeyName(10, "");
     this.imgToolbar.Images.SetKeyName(11, "");
     //
     // pnlEditor
     //
     this.pnlEditor.Controls.Add(this.pnlScriptEditor);
     this.pnlEditor.Controls.Add(this.spltDetails);
     this.pnlEditor.Controls.Add(this.pnlOutput);
     this.pnlEditor.Dock = System.Windows.Forms.DockStyle.Fill;
     this.pnlEditor.Location = new System.Drawing.Point(340, 0);
     this.pnlEditor.Name = "pnlEditor";
     this.pnlEditor.Padding = new System.Windows.Forms.Padding(0, 4, 0, 0);
     this.pnlEditor.Size = new System.Drawing.Size(412, 552);
     this.pnlEditor.TabIndex = 5;
     //
     // pnlScriptEditor
     //
     this.pnlScriptEditor.Controls.Add(this.pnlPadding);
     this.pnlScriptEditor.Controls.Add(this.tbEditor);
     this.pnlScriptEditor.Dock = System.Windows.Forms.DockStyle.Fill;
     this.pnlScriptEditor.Location = new System.Drawing.Point(0, 4);
     this.pnlScriptEditor.Name = "pnlScriptEditor";
     this.pnlScriptEditor.Padding = new System.Windows.Forms.Padding(3);
     this.pnlScriptEditor.Size = new System.Drawing.Size(412, 444);
     this.pnlScriptEditor.TabIndex = 7;
     //
     // pnlPadding
     //
     this.pnlPadding.Controls.Add(this.scriptEditor);
     this.pnlPadding.Dock = System.Windows.Forms.DockStyle.Fill;
     this.pnlPadding.Location = new System.Drawing.Point(3, 43);
     this.pnlPadding.Name = "pnlPadding";
     this.pnlPadding.Padding = new System.Windows.Forms.Padding(2);
     this.pnlPadding.Size = new System.Drawing.Size(406, 398);
     this.pnlPadding.TabIndex = 6;
     //
     // scriptEditor
     //
     this.scriptEditor.AllowDrop = true;
     this.scriptEditor.BackColor = System.Drawing.Color.Beige;
     this.scriptEditor.ContextMenu = this.editorContext;
     this.scriptEditor.Dock = System.Windows.Forms.DockStyle.Fill;
     //defaultDocument1.FormattingStrategy = defaultFormattingStrategy1;
     defaultHighlightingStrategy1.Extensions = new string[0];
     //defaultDocument1.HighlightingStrategy = defaultHighlightingStrategy1;
     //defaultDocument1.ReadOnly = false;
     //defaultDocument1.TextBufferStrategy = gapTextBufferStrategy1;
     //defaultDocument1.TextContent = "";
     defaultTextEditorProperties1.AllowCaretBeyondEOL = false;
     defaultTextEditorProperties1.AutoInsertCurlyBracket = true;
     defaultTextEditorProperties1.BracketMatchingStyle = ICSharpCode.TextEditor.Document.BracketMatchingStyle.After;
     defaultTextEditorProperties1.ConvertTabsToSpaces = false;
     defaultTextEditorProperties1.CreateBackupCopy = false;
     defaultTextEditorProperties1.DocumentSelectionMode = ICSharpCode.TextEditor.Document.DocumentSelectionMode.Normal;
     defaultTextEditorProperties1.EnableFolding = true;
     defaultTextEditorProperties1.Encoding = ((System.Text.Encoding)(resources.GetObject("defaultTextEditorProperties1.Encoding")));
     defaultTextEditorProperties1.Font = new System.Drawing.Font("Courier New", 10F);
     defaultTextEditorProperties1.HideMouseCursor = false;
     defaultTextEditorProperties1.IndentStyle = ICSharpCode.TextEditor.Document.IndentStyle.Smart;
     defaultTextEditorProperties1.IsIconBarVisible = false;
     defaultTextEditorProperties1.LineTerminator = "\r\n";
     defaultTextEditorProperties1.LineViewerStyle = ICSharpCode.TextEditor.Document.LineViewerStyle.None;
     defaultTextEditorProperties1.MouseWheelScrollDown = true;
     defaultTextEditorProperties1.MouseWheelTextZoom = true;
     defaultTextEditorProperties1.ShowEOLMarker = true;
     defaultTextEditorProperties1.ShowHorizontalRuler = false;
     defaultTextEditorProperties1.ShowInvalidLines = true;
     defaultTextEditorProperties1.ShowLineNumbers = true;
     defaultTextEditorProperties1.ShowMatchingBracket = true;
     defaultTextEditorProperties1.ShowSpaces = true;
     defaultTextEditorProperties1.ShowTabs = true;
     defaultTextEditorProperties1.ShowVerticalRuler = true;
     defaultTextEditorProperties1.TabIndent = 4;
     defaultTextEditorProperties1.UseAntiAliasedFont = false;
     defaultTextEditorProperties1.UseCustomLine = false;
     defaultTextEditorProperties1.VerticalRulerRow = 80;
     //defaultDocument1.TextEditorProperties = defaultTextEditorProperties1;
     //this.scriptEditor.Document = defaultDocument1;
     this.scriptEditor.Encoding = ((System.Text.Encoding)(resources.GetObject("scriptEditor.Encoding")));
     this.scriptEditor.IsIconBarVisible = false;
     this.scriptEditor.Location = new System.Drawing.Point(2, 2);
     this.scriptEditor.Name = "scriptEditor";
     this.scriptEditor.ShowEOLMarkers = true;
     this.scriptEditor.ShowSpaces = true;
     this.scriptEditor.ShowTabs = true;
     this.scriptEditor.ShowVRuler = true;
     this.scriptEditor.Size = new System.Drawing.Size(402, 394);
     this.scriptEditor.TabIndex = 2;
     this.scriptEditor.TextEditorProperties = defaultTextEditorProperties1;
     //
     // tbEditor
     //
     this.tbEditor.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
     this.tbEditor.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
     this.tbOpen,
     this.tbNew,
     this.tbSave,
     this.tbSaveSplitSep,
     this.tbScriptHelp,
     this.tbSplit,
     this.tbValidateExpandSep,
     this.tbExpand,
     this.tbValidate});
     this.tbEditor.Divider = false;
     this.tbEditor.DropDownArrows = true;
     this.tbEditor.ImageList = this.imgToolbar;
     this.tbEditor.Location = new System.Drawing.Point(3, 3);
     this.tbEditor.Name = "tbEditor";
     this.tbEditor.ShowToolTips = true;
     this.tbEditor.Size = new System.Drawing.Size(406, 40);
     this.tbEditor.TabIndex = 5;
     //
     // tbOpen
     //
     this.tbOpen.ImageIndex = 0;
     this.tbOpen.Name = "tbOpen";
     this.tbOpen.Text = "Open";
     this.tbOpen.ToolTipText = "Open File";
     //
     // tbNew
     //
     this.tbNew.ImageIndex = 3;
     this.tbNew.Name = "tbNew";
     this.tbNew.Text = "New";
     this.tbNew.ToolTipText = "New Script";
     //
     // tbSave
     //
     this.tbSave.ImageIndex = 1;
     this.tbSave.Name = "tbSave";
     this.tbSave.Text = "Save";
     this.tbSave.ToolTipText = "Save File";
     //
     // tbSaveSplitSep
     //
     this.tbSaveSplitSep.Name = "tbSaveSplitSep";
     this.tbSaveSplitSep.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
     //
     // tbScriptHelp
     //
     this.tbScriptHelp.ImageIndex = 11;
     this.tbScriptHelp.Name = "tbScriptHelp";
     this.tbScriptHelp.Text = "Help";
     this.tbScriptHelp.ToolTipText = "Script Help";
     //
     // tbSplit
     //
     this.tbSplit.ImageIndex = 2;
     this.tbSplit.Name = "tbSplit";
     this.tbSplit.Text = "Split";
     this.tbSplit.ToolTipText = "Split View";
     //
     // tbValidateExpandSep
     //
     this.tbValidateExpandSep.Name = "tbValidateExpandSep";
     this.tbValidateExpandSep.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
     //
     // tbExpand
     //
     this.tbExpand.ImageIndex = 10;
     this.tbExpand.Name = "tbExpand";
     this.tbExpand.Text = "Collapse";
     this.tbExpand.ToolTipText = "Expand / Collapse";
     //
     // spltDetails
     //
     this.spltDetails.BackColor = System.Drawing.Color.Beige;
     this.spltDetails.Dock = System.Windows.Forms.DockStyle.Bottom;
     this.spltDetails.Location = new System.Drawing.Point(0, 448);
     this.spltDetails.Name = "spltDetails";
     this.spltDetails.Size = new System.Drawing.Size(412, 4);
     this.spltDetails.TabIndex = 6;
     this.spltDetails.TabStop = false;
     //
     // pnlOutput
     //
     this.pnlOutput.Controls.Add(this.lstOutput);
     this.pnlOutput.Dock = System.Windows.Forms.DockStyle.Bottom;
     this.pnlOutput.Location = new System.Drawing.Point(0, 452);
     this.pnlOutput.Name = "pnlOutput";
     this.pnlOutput.Size = new System.Drawing.Size(412, 100);
     this.pnlOutput.TabIndex = 5;
     //
     // lstOutput
     //
     this.lstOutput.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
     this.chLine,
     this.chMessage});
     this.lstOutput.Dock = System.Windows.Forms.DockStyle.Fill;
     this.lstOutput.GridLines = true;
     this.lstOutput.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
     this.lstOutput.Location = new System.Drawing.Point(0, 0);
     this.lstOutput.Name = "lstOutput";
     this.lstOutput.Size = new System.Drawing.Size(412, 100);
     this.lstOutput.TabIndex = 0;
     this.lstOutput.TabStop = false;
     this.lstOutput.UseCompatibleStateImageBehavior = false;
     this.lstOutput.View = System.Windows.Forms.View.Details;
     //
     // chLine
     //
     this.chLine.Text = "Line";
     //
     // chMessage
     //
     this.chMessage.Text = "Message";
     this.chMessage.Width = 400;
     //
     // imgCompletion
     //
     this.imgCompletion.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgCompletion.ImageStream")));
     this.imgCompletion.TransparentColor = System.Drawing.Color.Transparent;
     this.imgCompletion.Images.SetKeyName(0, "");
     //
     // tbValidate
     //
     this.tbValidate.ImageIndex = 4;
     this.tbValidate.Name = "tbValidate";
     this.tbValidate.Text = "Validate";
     this.tbValidate.ToolTipText = "Validate Script";
     //
     // AIScriptEditor
     //
     this.Controls.Add(this.pnlEditor);
     this.Controls.Add(this.spltActionsNodes);
     this.Controls.Add(this.pnlActionsNodes);
     this.Name = "AIScriptEditor";
     this.Size = new System.Drawing.Size(752, 552);
     this.pnlActionsNodes.ResumeLayout(false);
     this.pnlNodes.ResumeLayout(false);
     ((System.ComponentModel.ISupportInitialize)(this.dgNodes)).EndInit();
     ((System.ComponentModel.ISupportInitialize)(this.dgActions)).EndInit();
     this.pnlEditor.ResumeLayout(false);
     this.pnlScriptEditor.ResumeLayout(false);
     this.pnlScriptEditor.PerformLayout();
     this.pnlPadding.ResumeLayout(false);
     this.pnlOutput.ResumeLayout(false);
     this.ResumeLayout(false);
 }