コード例 #1
0
        public void AddUndo(string name, string objName)
        {
            UndoRedoInfo info = new UndoRedoInfo(GetUndoActionName(name, objName));

            SaveReport(info.Stream);
            FUndo.Insert(0, info);
        }
コード例 #2
0
    public override void JustDoIt(UndoRedoInfo info)
    {
        base.JustDoIt(info);

        switch (operation)
        {
        case OperationType.AddSceneObj:
            for (int i = 0; i < info.parma.Length; i++)
            {
                SceneObjectClass sceneObjectClass = info.parma[i] as SceneObjectClass;
                GameObjectPool.instance.InsertChild(sceneObjectClass.gameObject.name, sceneObjectClass.gameObject);
            }
            break;

        case OperationType.DeleteSceneObj:
            for (int i = 0; i < info.parma.Length; i++)
            {
                SceneObjectClass sceneObjectClass = info.parma[i] as SceneObjectClass;
                GameObjectPool.instance.RemoveTarge(sceneObjectClass.gameObject.name, sceneObjectClass.gameObject);
                sceneObjectClass.gameObject.SetActive(true);
                sceneObjectClass.Refresh(false);
                sceneObjectClass.cell.chunkParent.sceneObjectMgr.AddSceneObject(sceneObjectClass);
            }
            break;
        }
    }
コード例 #3
0
    public override void JustDoIt(UndoRedoInfo info)
    {
        base.JustDoIt(info);

        switch (operation)
        {
        case OperationType.HeightEdit:
            info.hexCell.Elevation = (int)info.parma[0];
            break;

        case OperationType.WaterLevelEdit:
            info.hexCell.WaterLevel = (int)info.parma[0];
            break;

        case OperationType.EdgeEdit:
            for (int i = 0; i < 6; i++)
            {
                info.hexCell.isStepDirection[i] = (bool)info.parma[i];
                if (info.hexCell.GetNeighbor((HexDirection)i) != null)
                {
                    info.hexCell.GetNeighbor((HexDirection)i).isStepDirection[(int)((HexDirection)i).Opposite()] = (bool)info.parma[i];
                }
            }
            break;
        }
    }
コード例 #4
0
        protected override void OnTextChanged(EventArgs e)
        {
            if (parsing)
            {
                return;
            }


            if (!isUndoRedo)
            {
                redoStack.Clear();
                undoStack.Push(lastInfo);
                lastInfo = new UndoRedoInfo(this.Text, this.SelectionStart, GetScrollPos());
            }


            //var temp = this.ZoomFactor;
            if (EnableHighlight)
            {
                Highlight();
            }
            //this.ZoomFactor = 1;
            //this.ZoomFactor = temp;


            if (enableAutoComplete)
            {
                AutoShowListBox();
            }

            //require saving after text changed
            requiresSaving = 1;

            base.OnTextChanged(e);
        }
コード例 #5
0
 protected override void OnTextChanged(EventArgs e)
 {
     if (_highlighting)
     {
         return;
     }
     _highlightTimer.Change(Delay, int.MaxValue);
     HideAutoCompleteForm();
     _visitor.Clear();
     if (!string.IsNullOrEmpty(Text))
     {
         var nodes = _parser.Parse(Text);
         _visitor.Visit(nodes);
     }
     base.OnTextChanged(e);
     if (!_isUndo)
     {
         _redoStack.Clear();
         _undoList.Insert(0, _lastInfo);
         UpdateUndoLimit();
         _lastInfo = UndoRedoInfo.Create(this);
     }
     if (CanAutoComplete(true))
     {
         ShowAutoComplete();
     }
 }
コード例 #6
0
        /// <summary>
        /// The on text changed overrided. Here we parse the text into RTF for the highlighting.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnTextChanged(EventArgs e)
        {
            if (mParsing)
            {
                return;
            }

            if (!mIsUndo)
            {
                mRedoStack.Clear();
                mUndoList.Insert(0, mLastInfo);
                this.LimitUndo();
                mLastInfo = new UndoRedoInfo(Text, GetScrollPos(), SelectionStart);
            }

            if (mEnableHighlihting && Text.Length < maxAutoHighlightTextLength)
            {
                Highlight();
            }

            if (mAutoCompleteShown)
            {
                if (mFilterAutoComplete)
                {
                    SetAutoCompleteItems();
                    SetAutoCompleteSize();
                    SetAutoCompleteLocation(false);
                }
                SetBestSelectedAutoCompleteItem();
            }

            base.OnTextChanged(e);
        }
コード例 #7
0
        protected override void OnTextChanged(EventArgs e)
        {
            // suppress notifications while parsing
            if (!_parsing)
            {
                // save undo info
                if (!_isUndo)
                {
                    _redoStack.Clear();
                    _undoList.Insert(0, _lastUndoInfo);
                    LimitUndo();
                    _lastUndoInfo = new UndoRedoInfo(Text, GetScrollPos(), SelectionStart);
                }

                // update styles
                if (_timer == null)
                {
                    _timer          = new Timer();
                    _timer.Interval = 250;
                    _timer.Enabled  = false;
                    _timer.Tick    += new EventHandler(_timer_Tick);
                }
                _timer.Enabled = false;
                _timer.Enabled = true;

                // fire event
                base.OnTextChanged(e);
            }
        }
コード例 #8
0
        public void InitText(string newContents)
        {
            AppendText(newContents);
            SelectionStart = 0;

            mUndoList.RemoveAt(0);
            mLastInfo = new UndoRedoInfo(Text, GetScrollPos(), SelectionStart);
        }
コード例 #9
0
ファイル: MyTextBox.cs プロジェクト: zouchengjun/YDWE
 public void AddToUndoStack(string text)
 {
     this.ClearUndo();                                            // 禁止自身的Undo
     this.redoStack.Clear();                                      // 清空重做
     this.undoStack.Push(lastText);                               // 写入上一次的内容
     this.lastText = new UndoRedoInfo(text, this.SelectionStart); // 保存本次的内容
     undoStackChange(undoStack.Count, EventArgs.Empty);
     redoStackChange(redoStack.Count, EventArgs.Empty);
 }
コード例 #10
0
ファイル: MyTextBox.cs プロジェクト: h82258652/YDWE
 public void AddToUndoStack(string text)
 {
     this.ClearUndo();// 禁止自身的Undo
     this.redoStack.Clear();// 清空重做
     this.undoStack.Push(lastText);// 写入上一次的内容
     this.lastText = new UndoRedoInfo(text, this.SelectionStart);// 保存本次的内容
     undoStackChange(undoStack.Count, EventArgs.Empty);
     redoStackChange(redoStack.Count, EventArgs.Empty);
 }
コード例 #11
0
        private void SuspendPainting()
        {
            if (_paintSuspended)
            {
                return;
            }

            _painSuspendedInfo = UndoRedoInfo.Create(this);
            SendMessage(Handle, WM_SETREDRAW, 0, IntPtr.Zero);
            _eventMask      = SendMessage(Handle, EM_GETEVENTMASK, 0, IntPtr.Zero);
            _paintSuspended = true;
        }
コード例 #12
0
ファイル: TextBoxEx.cs プロジェクト: smithbrow/PL0Compiler
        /// <summary>
        /// The on text changed overrided.
        /// </summary>
        /// <param name="e"> </param>
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);

            if (!mIsUndo)
            {
                mRedoStack.Clear();
                mUndoList.Insert(0, mLastInfo);
                this.LimitUndo();
                mLastInfo = new UndoRedoInfo(Text, SelectionStart);
            }
            //Invalidate();
        }
コード例 #13
0
        public void GetRedo(int actionsCount)
        {
            UndoRedoInfo info = FRedo[actionsCount - 1];

            LoadReport(info.Stream);

            for (int i = 0; i < actionsCount; i++)
            {
                info = FRedo[0];
                FUndo.Insert(0, info);
                FRedo.Remove(info);
            }
        }
コード例 #14
0
        public new void Redo()
        {
            if (!CanRedo)
            {
                return;
            }
            _isUndo = true;
            _undoList.Insert(0, UndoRedoInfo.Create(this));
            UpdateUndoLimit();
            UndoRedoInfo info = _redoStack.Pop();

            info.Restore(this, true);
            _isUndo = false;
        }
コード例 #15
0
 public new void Redo()
 {
     if (CanRedo)
     {
         _isUndo = true;
         _undoList.Insert(0, new UndoRedoInfo(Text, GetScrollPos(), SelectionStart));
         LimitUndo();
         UndoRedoInfo info = (UndoRedoInfo)_redoStack.Pop();
         Text           = info.Text;
         SelectionStart = info.SelectionStart;
         SetScrollPos(info.ScrollPos);
         _isUndo = false;
     }
 }
コード例 #16
0
        public void ClearUndo(string initialText)
        {
            _undoList.Clear();

            if (base.IsHandleCreated) // base.ClearUndo() does nothing unless handle has been created
            {
                base.ClearUndo();
            }
            else
            {
                base.HandleCreated += RegexTextBox_HandleCreated;
            }

            _lastUndoInfo = new UndoRedoInfo(initialText, new POINT(), 0);
        }
コード例 #17
0
ファイル: MyTextBox.cs プロジェクト: zouchengjun/YDWE
 public void Undo(object sender, EventArgs e)
 {
     this.lockTextChange = true;
     if (undoStack.Count > 0)// 可以撤销
     {
         this.redoStack.Push(new UndoRedoInfo(this.Text, this.SelectionStart));
         this.lastText       = undoStack.Peek();
         this.Text           = lastText.Text;
         this.SelectionStart = lastText.CursorLocation;
         this.undoStack.Pop();
         undoStackChange(undoStack.Count, EventArgs.Empty);
         redoStackChange(redoStack.Count, EventArgs.Empty);
     }
     this.lockTextChange = false;
 }
コード例 #18
0
        public new void Undo()
        {
            if (!CanUndo)
            {
                return;
            }
            _isUndo = true;
            _redoStack.Push(UndoRedoInfo.Create(this));
            UndoRedoInfo info = _undoList[0];

            _undoList.RemoveAt(0);
            info.Restore(this, true);
            _lastInfo = info;
            _isUndo   = false;
        }
コード例 #19
0
 public new void Undo()
 {
     if (CanUndo)
     {
         _isUndo = true;
         _redoStack.Push(new UndoRedoInfo(Text, GetScrollPos(), SelectionStart));
         UndoRedoInfo info = (UndoRedoInfo)_undoList[0];
         _undoList.RemoveAt(0);
         Text           = info.Text;
         SelectionStart = info.SelectionStart;
         SetScrollPos(info.ScrollPos);
         _lastUndoInfo = info;
         _isUndo       = false;
     }
 }
コード例 #20
0
ファイル: RTBLinkEnabled.cs プロジェクト: carlhuth/GenXSource
        public new void Redo()
        {
            if (!CanRedo)
            {
                return;
            }
            mIsUndo = true;
            mUndoList.Insert(0, new UndoRedoInfo(Text, GetScrollPos(), SelectionStart));
            LimitUndo();
            UndoRedoInfo info = (UndoRedoInfo)mRedoStack.Pop();

            Text           = info.Text;
            SelectionStart = info.CursorLocation;
            SetScrollPos(info.ScrollPos);
            mIsUndo = false;
        }
コード例 #21
0
        public void GetUndo(int actionsCount)
        {
            if (actionsCount >= FUndo.Count - 1)
            {
                actionsCount = FUndo.Count - 1;
            }
            UndoRedoInfo info = FUndo[actionsCount];

            LoadReport(info.Stream);

            for (int i = 0; i < actionsCount; i++)
            {
                info = FUndo[0];
                FRedo.Insert(0, info);
                FUndo.Remove(info);
            }
        }
コード例 #22
0
ファイル: RTBLinkEnabled.cs プロジェクト: carlhuth/GenXSource
        public new void Undo()
        {
            if (!CanUndo)
            {
                return;
            }
            mIsUndo = true;
            mRedoStack.Push(new UndoRedoInfo(Text, GetScrollPos(), SelectionStart));
            UndoRedoInfo info = (UndoRedoInfo)mUndoList[0];

            mUndoList.RemoveAt(0);
            Text           = info.Text;
            SelectionStart = info.CursorLocation;
            SetScrollPos(info.ScrollPos);
            mLastInfo = info;
            mIsUndo   = false;
        }
コード例 #23
0
    public override void JustDoIt(UndoRedoInfo info)
    {
        base.JustDoIt(info);

        switch (operation)
        {
        case OperationType.WholeCellEdit:
            if (HexMetrics.instance.isEditorTexture)
            {
                info.hexCell.TerrainTypeIndex = (TerrainTypes)info.parma[0];
            }
            else
            {
                info.hexCell.color = (Color)info.parma[0];
            }
            break;
        }
    }
コード例 #24
0
        public new void Redo()
        {
            if (!CanRedo)
            {
                return;
            }

            isUndoRedo = true;
            undoStack.Push(new UndoRedoInfo(Text, SelectionStart, GetScrollPos()));
            UndoRedoInfo info = redoStack.Pop();

            Text           = info.text;
            SelectionStart = info.caretPosition;
            SetScrollPos(info.scrollPosition);
            //In case the first index of this.Text is the character matching auto complete word table
            autoCompleteListBox.Visible = false;

            lastInfo   = info;
            isUndoRedo = false;
        }
コード例 #25
0
        public TypingArea()
        {
            InitializeComponent();

            //Some default setup
            caseSensitive      = true;
            enableHighlight    = true;
            parsing            = false;
            isUndoRedo         = false;
            EnableAutoComplete = true;
            requiresSaving     = 0;
            this.Font          = new Font(FontFamily.GenericMonospace, 12);

            rtfHeader = new StringBuilder();
            undoStack = new Stack <UndoRedoInfo>();
            redoStack = new Stack <UndoRedoInfo>();
            lastInfo  = new UndoRedoInfo("", 0, new Win32.POINT());

            //Add ListBox to this TypingArea
            autoCompleteListBox         = new ListBox();
            autoCompleteListBox.Visible = false;
            autoCompleteListBox.Font    = new Font(FontFamily.GenericMonospace, 14);
            this.Controls.Add(autoCompleteListBox);

            //Inherited properties
            this.AcceptsTab = true;


            //Load separators
            var separators = new List <char>()
            {
                '?', ',', '.', ';', '(', ')', '[', ']', '{', '}', '+', '-',
                '%', '^', '=', '~', '!', '|', ' ', '\r', '\n', '\t'
            };

            AddListOfSeparators(separators);
        }
コード例 #26
0
 protected override void OnTextChanged(EventArgs e)
 {
     if (_highlighting)
         return;
     _highlightTimer.Change(Delay, int.MaxValue);
     HideAutoCompleteForm();
     _visitor.Clear();
     if (!string.IsNullOrEmpty(Text))
     {
         var nodes = _parser.Parse(Text);
         _visitor.Visit(nodes);
     }
     base.OnTextChanged(e);
     if (!_isUndo)
     {
         _redoStack.Clear();
         _undoList.Insert(0, _lastInfo);
         UpdateUndoLimit();
         _lastInfo = UndoRedoInfo.Create(this);
     }
     if (CanAutoComplete(true))
         ShowAutoComplete();
 }
コード例 #27
0
 public new void Undo()
 {
     if (!CanUndo)
         return;
     _isUndo = true;
     _redoStack.Push(UndoRedoInfo.Create(this));
     UndoRedoInfo info = _undoList[0];
     _undoList.RemoveAt(0);
     info.Restore(this, true);
     _lastInfo = info;
     _isUndo = false;
 }
コード例 #28
0
        public void InitText(string newContents)
        {
            AppendText(newContents);
            SelectionStart = 0;

            mUndoList.RemoveAt(0);
            mLastInfo = new UndoRedoInfo(Text, GetScrollPos(), SelectionStart);
        }
コード例 #29
0
ファイル: RTBLinkEnabled.cs プロジェクト: carlhuth/GenXSource
        /// <summary>
        /// The on text changed overrided. Here we parse the text into RTF for the highlighting.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnTextChanged(EventArgs e)
        {
            if (mParsing)
            {
                return;
            }

            if (this.HighlightDescriptors.Count == 0)
            {
                base.OnTextChanged(e);
                OnItemTextChanged(new ItemTextChangedEventArgs(this));
                return;
            }

            mParsing = true;
            Win32.SendMessage(Handle, Win32.WM_SETREDRAW, 0, (IntPtr)0);
            base.OnTextChanged(e);

            if (!mIsUndo)
            {
                mRedoStack.Clear();
                mUndoList.Insert(0, mLastInfo);
                this.LimitUndo();
                mLastInfo = new UndoRedoInfo(Text, GetScrollPos(), SelectionStart);
            }

            //Save scroll bar an cursor position, changeing the RTF moves the cursor and scrollbars to top positin
            Win32.POINT scrollPos = GetScrollPos();
            int         cursorLoc = SelectionStart;

            this.Select(0, this.Text.Length);
            this.SelectionFont  = Parent.Font;
            this.SelectionColor = SystemColors.WindowText;

            int    lastPos;
            int    tokenLength;
            string token;

            foreach (HighlightDescriptor hd in this.HighlightDescriptors)
            {
                token       = hd.Token.Replace("\t", " ");
                token       = token.Replace("\v", ".");
                lastPos     = 0;
                tokenLength = token.Length;
                while (true)
                {
                    lastPos = this.Find(token, lastPos, RichTextBoxFinds.WholeWord);
                    if (lastPos == -1 || lastPos >= this.Text.Length)
                    {
                        break;
                    }
                    this.Select(lastPos, tokenLength);
                    this.SelectionColor = hd.Color;
                    this.Select(lastPos + tokenLength, 1);
                    this.SelectionColor = SystemColors.WindowText;
                    lastPos            += 1;
                }
            }

            //Restore cursor and scrollbars location.
            this.SelectionStart  = cursorLoc;
            this.SelectionLength = 0;

            SetScrollPos(scrollPos);
            Win32.SendMessage(Handle, Win32.WM_SETREDRAW, 1, (IntPtr)0);
            Invalidate();

            if (mAutoCompleteShown)
            {
                if (mFilterAutoComplete)
                {
                    SetAutoCompleteItems();
                    SetAutoCompleteSize();
                    SetAutoCompleteLocation(false);
                }
                SetBestSelectedAutoCompleteItem();
            }

            mParsing = false;

            OnItemTextChanged(new ItemTextChangedEventArgs(this));
        }
コード例 #30
0
ファイル: ASSTextBoxRegEx.cs プロジェクト: nuukcillo/PerrySub
        public new void Undo()
        {
            if (!CanUndo) return;
            isUndoRedo = true;

            RedoStack.Push(new UndoRedoInfo(this.Text, GetScrollPos(), this.SelectionStart));
            UndoRedoInfo info = (UndoRedoInfo)UndoStack.Pop();
            this.Text = info.Text;
            this.SelectionStart = info.CursorLocation;
            SetScrollPos(info.ScrollPos);

            LastInfo = info;
            isUndoRedo = false;
        }
コード例 #31
0
 public new void Redo()
 {
     if (!CanRedo)
         return;
     mIsUndo = true;
     mUndoList.Insert(0,new UndoRedoInfo(Text, GetScrollPos(), SelectionStart));
     LimitUndo();
     UndoRedoInfo info = (UndoRedoInfo)mRedoStack.Pop();
     Text = info.Text;
     SelectionStart = info.CursorLocation;
     SetScrollPos(info.ScrollPos);
     mLastInfo = info;
     mIsUndo = false;
 }
コード例 #32
0
        /// <summary>
        /// The on text changed overrided. Here we parse the text into RTF for the highlighting.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnTextChanged(EventArgs e)
        {
            if (mParsing)
            {
                return;
            }
            mParsing = true;
            Win32.LockWindowUpdate(Handle);
            base.OnTextChanged(e);

            if (!mIsUndo)
            {
                mRedoStack.Clear();
                mUndoList.Insert(0, mLastInfo);
                this.LimitUndo();
                mLastInfo = new UndoRedoInfo(Text, GetScrollPos(), SelectionStart);
            }

            //Save scroll bar an cursor position, changeing the RTF moves the cursor and scrollbars to top positin
            Win32.POINT scrollPos = GetScrollPos();
            int         cursorLoc = SelectionStart;

            //Created with an estimate of how big the stringbuilder has to be...
            StringBuilder sb = new
                               StringBuilder((int)(Text.Length * 1.5 + 150));

            //Adding RTF header
            sb.Append(@"{\rtf1\fbidis\ansi\ansicpg1255\deff0\deflang1037{\fonttbl{");

            //Font table creation
            int       fontCounter = 0;
            Hashtable fonts       = new Hashtable();

            AddFontToTable(sb, Font, ref fontCounter, fonts);
            foreach (HighlightDescriptor hd in mHighlightDescriptors)
            {
                if ((hd.Font != null) && !fonts.ContainsKey(hd.Font.Name))
                {
                    AddFontToTable(sb, hd.Font, ref fontCounter, fonts);
                }
            }
            sb.Append("}\n");

            //ColorTable

            sb.Append(@"{\colortbl ;");
            Hashtable colors       = new Hashtable();
            int       colorCounter = 1;

            AddColorToTable(sb, ForeColor, ref colorCounter, colors);
            AddColorToTable(sb, BackColor, ref colorCounter, colors);

            foreach (HighlightDescriptor hd in mHighlightDescriptors)
            {
                if (!colors.ContainsKey(hd.Color))
                {
                    AddColorToTable(sb, hd.Color, ref colorCounter, colors);
                }
            }

            //Parsing text

            sb.Append("}\n").Append(@"\viewkind4\uc1\pard\ltrpar");
            SetDefaultSettings(sb, colors, fonts);

            char[] sperators = mSeperators.GetAsCharArray();

            //Replacing "\" to "\\" for RTF...
            string[] lines = Text.Replace("\\", "\\\\").Replace("{", "\\{").Replace("}", "\\}").Split('\n');
            for (int lineCounter = 0; lineCounter < lines.Length; lineCounter++)
            {
                if (lineCounter != 0)
                {
                    AddNewLine(sb);
                }
                string   line   = lines[lineCounter];
                string[] tokens = mCaseSesitive ? line.Split(sperators) : line.ToUpper().Split(sperators);
                if (tokens.Length == 0)
                {
                    sb.Append(line);
                    AddNewLine(sb);
                    continue;
                }

                int tokenCounter = 0;
                for (int i = 0; i < line.Length;)
                {
                    char curChar = line[i];
                    if (mSeperators.Contains(curChar))
                    {
                        sb.Append(curChar);
                        i++;
                    }
                    else
                    {
                        string curToken  = tokens[tokenCounter++];
                        bool   bAddToken = true;
                        foreach (HighlightDescriptor hd in mHighlightDescriptors)
                        {
                            string compareStr = mCaseSesitive ? hd.Token : hd.Token.ToUpper();
                            bool   match      = false;

                            //Check if the highlight descriptor matches the current toker according to the DescriptoRecognision property.
                            switch (hd.DescriptorRecognition)
                            {
                            case DescriptorRecognition.WholeWord:
                                if (curToken == compareStr)
                                {
                                    match = true;
                                }
                                break;

                            case DescriptorRecognition.StartsWith:
                                if (curToken.StartsWith(compareStr))
                                {
                                    match = true;
                                }
                                break;

                            case DescriptorRecognition.Contains:
                                if (curToken.IndexOf(compareStr) != -1)
                                {
                                    match = true;
                                }
                                break;
                            }
                            if (!match)
                            {
                                //If this token doesn't match chech the next one.
                                continue;
                            }

                            //printing this token will be handled by the inner code, don't apply default settings...
                            bAddToken = false;

                            //Set colors to current descriptor settings.
                            SetDescriptorSettings(sb, hd, colors, fonts);

                            //Print text affected by this descriptor.
                            switch (hd.DescriptorType)
                            {
                            case DescriptorType.Word:
                                sb.Append(line.Substring(i, curToken.Length));
                                SetDefaultSettings(sb, colors, fonts);
                                i += curToken.Length;
                                break;

                            case DescriptorType.ToEOL:
                                sb.Append(line.Remove(0, i));
                                i = line.Length;
                                SetDefaultSettings(sb, colors, fonts);
                                break;

                            case DescriptorType.ToCloseToken:
                                while ((line.IndexOf(hd.CloseToken, i) == -1) && (lineCounter < lines.Length))
                                {
                                    sb.Append(line.Remove(0, i));
                                    lineCounter++;
                                    if (lineCounter < lines.Length)
                                    {
                                        AddNewLine(sb);
                                        line = lines[lineCounter];
                                        i    = 0;
                                    }
                                    else
                                    {
                                        i = line.Length;
                                    }
                                }
                                if (line.IndexOf(hd.CloseToken, i) != -1)
                                {
                                    sb.Append(line.Substring(i, line.IndexOf(hd.CloseToken, i) + hd.CloseToken.Length - i));
                                    line         = line.Remove(0, line.IndexOf(hd.CloseToken, i) + hd.CloseToken.Length);
                                    tokenCounter = 0;
                                    tokens       = mCaseSesitive ? line.Split(sperators) : line.ToUpper().Split(sperators);
                                    SetDefaultSettings(sb, colors, fonts);
                                    i = 0;
                                }
                                break;
                            }
                            break;
                        }
                        if (bAddToken)
                        {
                            //Print text with default settings...
                            sb.Append(line.Substring(i, curToken.Length));
                            i += curToken.Length;
                        }
                    }
                }
            }

//			System.Diagnostics.Debug.WriteLine(sb.ToString());
            Rtf = sb.ToString();

            //Restore cursor and scrollbars location.
            SelectionStart = cursorLoc;

            mParsing = false;

            SetScrollPos(scrollPos);
            Win32.LockWindowUpdate((IntPtr)0);
            Invalidate();

            if (mAutoCompleteShown)
            {
                if (mFilterAutoComplete)
                {
                    SetAutoCompleteItems();
                    SetAutoCompleteSize();
                    SetAutoCompleteLocation(false);
                }
                SetBestSelectedAutoCompleteItem();
            }
        }
コード例 #33
0
ファイル: MyTextBox.cs プロジェクト: h82258652/YDWE
 public void Undo(object sender, EventArgs e)
 {
     this.lockTextChange = true;
     if (undoStack.Count > 0)// 可以撤销
     {
         this.redoStack.Push(new UndoRedoInfo(this.Text, this.SelectionStart));
         this.lastText = undoStack.Peek();
         this.Text = lastText.Text;
         this.SelectionStart = lastText.CursorLocation;
         this.undoStack.Pop();
         undoStackChange(undoStack.Count, EventArgs.Empty);
         redoStackChange(redoStack.Count, EventArgs.Empty);
     }
     this.lockTextChange = false;
 }
コード例 #34
0
        /// <summary>
        /// The on text changed overrided. Here we parse the text into RTF for the highlighting.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnTextChanged(EventArgs e)
        {
            if (mParsing) return;
            mParsing = true;
            Win32.LockWindowUpdate(Handle);
            base.OnTextChanged(e);

            if (!mIsUndo)
            {
                mRedoStack.Clear();
                mUndoList.Insert(0,mLastInfo);
                this.LimitUndo();
                mLastInfo = new UndoRedoInfo(Text, GetScrollPos(), SelectionStart);
            }

            //Save scroll bar an cursor position, changeing the RTF moves the cursor and scrollbars to top positin
            Win32.POINT scrollPos = GetScrollPos();
            int cursorLoc = SelectionStart;

            //Created with an estimate of how big the stringbuilder has to be...
            StringBuilder sb = new
                StringBuilder((int)(Text.Length * 1.5 + 150));

            //Adding RTF header
            sb.Append(@"{\rtf1\fbidis\ansi\ansicpg1255\deff0\deflang1037{\fonttbl{");

            //Font table creation
            int fontCounter = 0;
            Hashtable fonts = new Hashtable();
            AddFontToTable(sb, Font, ref fontCounter, fonts);
            foreach (HighlightDescriptor hd in mHighlightDescriptors)
            {
                if ((hd.Font !=  null) && !fonts.ContainsKey(hd.Font.Name))
                {
                    AddFontToTable(sb, hd.Font,ref fontCounter, fonts);
                }
            }
            sb.Append("}\n");

            //ColorTable

            sb.Append(@"{\colortbl ;");
            Hashtable colors = new Hashtable();
            int colorCounter = 1;
            AddColorToTable(sb, ForeColor, ref colorCounter, colors);
            AddColorToTable(sb, BackColor, ref colorCounter, colors);

            foreach (HighlightDescriptor hd in mHighlightDescriptors)
            {
                if (!colors.ContainsKey(hd.Color))
                {
                    AddColorToTable(sb, hd.Color, ref colorCounter, colors);
                }
            }

            //Parsing text

            sb.Append("}\n").Append(@"\viewkind4\uc1\pard\ltrpar");
            SetDefaultSettings(sb, colors, fonts);

            char[] sperators = mSeperators.GetAsCharArray();

            //Replacing "\" to "\\" for RTF...
            string[] lines = Text.Replace("\\","\\\\").Replace("{", "\\{").Replace("}", "\\}").Split('\n');
            for (int lineCounter = 0 ; lineCounter < lines.Length; lineCounter++)
            {
                if (lineCounter != 0)
                {
                    AddNewLine(sb);
                }
                string line = lines[lineCounter];
                string[] tokens = mCaseSesitive ? line.Split(sperators) : line.ToUpper().Split(sperators);
                if (tokens.Length == 0)
                {
                    sb.Append(line);
                    AddNewLine(sb);
                    continue;
                }

                int tokenCounter = 0;
                for (int i = 0; i < line.Length ;)
                {
                    char curChar = line[i];
                    if (mSeperators.Contains(curChar))
                    {
                        sb.Append(curChar);
                        i++;
                    }
                    else
                    {
                        string curToken = tokens[tokenCounter++];
                        bool bAddToken = true;
                        foreach	(HighlightDescriptor hd in mHighlightDescriptors)
                        {
                            string	compareStr = mCaseSesitive ? hd.Token : hd.Token.ToUpper();
                            bool match = false;

                            //Check if the highlight descriptor matches the current toker according to the DescriptoRecognision property.
                            switch	(hd.DescriptorRecognition)
                            {
                                case DescriptorRecognition.WholeWord:
                                    if (curToken == compareStr)
                                    {
                                            match = true;
                                    }
                                    break;
                                case DescriptorRecognition.StartsWith:
                                    if (curToken.StartsWith(compareStr))
                                    {
                                        match = true;
                                    }
                                    break;
                                case DescriptorRecognition.Contains:
                                    if (curToken.IndexOf(compareStr) != -1)
                                    {
                                        match = true;
                                    }
                                    break;
                            }
                            if (!match)
                            {
                                //If this token doesn't match chech the next one.
                                continue;
                            }

                            //printing this token will be handled by the inner code, don't apply default settings...
                            bAddToken = false;

                            //Set colors to current descriptor settings.
                            SetDescriptorSettings(sb, hd, colors, fonts);

                            //Print text affected by this descriptor.
                            switch (hd.DescriptorType)
                            {
                                case DescriptorType.Word:
                                    sb.Append(line.Substring(i, curToken.Length));
                                    SetDefaultSettings(sb, colors, fonts);
                                    i += curToken.Length;
                                    break;
                                case DescriptorType.ToEOL:
                                    sb.Append(line.Remove(0, i));
                                    i = line.Length;
                                    SetDefaultSettings(sb, colors, fonts);
                                    break;
                                case DescriptorType.ToCloseToken:
                                    while((line.IndexOf(hd.CloseToken, i) == -1) && (lineCounter < lines.Length))
                                    {
                                        sb.Append(line.Remove(0, i));
                                        lineCounter++;
                                        if (lineCounter < lines.Length)
                                        {
                                            AddNewLine(sb);
                                            line = lines[lineCounter];
                                            i = 0;
                                        }
                                        else
                                        {
                                            i = line.Length;
                                        }
                                    }
                                    if (line.IndexOf(hd.CloseToken, i) != -1)
                                    {
                                        sb.Append(line.Substring(i, line.IndexOf(hd.CloseToken, i) + hd.CloseToken.Length - i) );
                                        line = line.Remove(0, line.IndexOf(hd.CloseToken, i) + hd.CloseToken.Length);
                                        tokenCounter = 0;
                                        tokens = mCaseSesitive ? line.Split(sperators) : line.ToUpper().Split(sperators);
                                        SetDefaultSettings(sb, colors, fonts);
                                        i = 0;
                                    }
                                    break;
                            }
                            break;
                        }
                        if (bAddToken)
                        {
                            //Print text with default settings...
                            sb.Append(line.Substring(i, curToken.Length));
                            i+=	curToken.Length;
                        }
                    }
                }
            }

            //			System.Diagnostics.Debug.WriteLine(sb.ToString());
            Rtf = sb.ToString();

            //Restore cursor and scrollbars location.
            SelectionStart = cursorLoc;

            mParsing = false;

            SetScrollPos(scrollPos);
            Win32.LockWindowUpdate((IntPtr)0);
            Invalidate();

            if (mAutoCompleteShown)
            {
                if (mFilterAutoComplete)
                {
                    SetAutoCompleteItems();
                    SetAutoCompleteSize();
                    SetAutoCompleteLocation(false);
                }
                SetBestSelectedAutoCompleteItem();
            }
        }
コード例 #35
0
ファイル: ASSTextBoxRegEx.cs プロジェクト: nuukcillo/PerrySub
        protected override void OnTextChanged(EventArgs e)
        {
            if (!_Paint) return;
            _Paint = false;
            LockWindowUpdate(Handle);
            base.OnTextChanged(e);

            if (!isUndoRedo)
            {
                RedoStack.Clear();
                UndoStack.Push(LastInfo);
                LastInfo = new UndoRedoInfo(this.Text, GetScrollPos(), this.SelectionStart);
            }

            ActualizarTextBox();

            LockWindowUpdate((IntPtr)0);
            this.Invalidate();
            _Paint = true;
        }
コード例 #36
0
 public new void Undo()
 {
     if (!CanUndo)
         return;
     mIsUndo = true;
     mRedoStack.Push(new UndoRedoInfo(Text, GetScrollPos(), SelectionStart));
     UndoRedoInfo info = (UndoRedoInfo)mUndoList[0];
     mUndoList.RemoveAt(0);
     Text = info.Text;
     SelectionStart = info.CursorLocation;
     SetScrollPos(info.ScrollPos);
     mLastInfo = info;
     mIsUndo = false;
 }
コード例 #37
0
        private void SuspendPainting()
        {
            if (_paintSuspended)
                return;

            _painSuspendedInfo = UndoRedoInfo.Create(this);
            SendMessage(Handle, WM_SETREDRAW, 0, IntPtr.Zero);
            _eventMask = SendMessage(Handle, EM_GETEVENTMASK, 0, IntPtr.Zero);
            _paintSuspended = true;
        }
コード例 #38
0
 public virtual void JustDoIt(UndoRedoInfo info)
 {
 }
コード例 #39
0
		/// <summary>
		/// The on text changed overrided. Here we parse the text into RTF for the highlighting.
		/// </summary>
		/// <param name="e"></param>
		protected override void OnTextChanged(EventArgs e)
		{
			if(mParsing) return;

			if(this.HighlightDescriptors.Count == 0)
			{
				base.OnTextChanged(e);
				OnItemTextChanged(new ItemTextChangedEventArgs(this));
				return;
			}

			mParsing = true;
			Win32.SendMessage(Handle,Win32.WM_SETREDRAW,0,(IntPtr)0);
			base.OnTextChanged(e);

			if (!mIsUndo)
			{
				mRedoStack.Clear();
				mUndoList.Insert(0,mLastInfo);
				this.LimitUndo();
				mLastInfo = new UndoRedoInfo(Text, GetScrollPos(), SelectionStart);
			}
			
			//Save scroll bar an cursor position, changeing the RTF moves the cursor and scrollbars to top positin
			Win32.POINT scrollPos = GetScrollPos();
			int cursorLoc = SelectionStart;

			this.Select(0,this.Text.Length);
			this.SelectionFont = Parent.Font;
			this.SelectionColor = SystemColors.WindowText;

			int lastPos;
			int tokenLength;
			string token;
			foreach(HighlightDescriptor hd in this.HighlightDescriptors)
			{
				token = hd.Token.Replace("\t"," ");
				token = token.Replace("\v",".");
				lastPos = 0;
				tokenLength = token.Length;
				while(true)
				{
					lastPos = this.Find(token,lastPos,RichTextBoxFinds.WholeWord);
					if(lastPos == -1 || lastPos >= this.Text.Length)
					{
						break;
					}
					this.Select(lastPos,tokenLength);
					this.SelectionColor = hd.Color;
					this.Select(lastPos+tokenLength,1);
					this.SelectionColor = SystemColors.WindowText;
					lastPos += 1;
				}
			}

			//Restore cursor and scrollbars location.
			this.SelectionStart = cursorLoc;
			this.SelectionLength = 0;

			SetScrollPos(scrollPos);
			Win32.SendMessage(Handle,Win32.WM_SETREDRAW,1,(IntPtr)0);
			Invalidate();
			
			if (mAutoCompleteShown)
			{
				if (mFilterAutoComplete)
				{
					SetAutoCompleteItems();
					SetAutoCompleteSize();
					SetAutoCompleteLocation(false);
				}
				SetBestSelectedAutoCompleteItem();
			}

			mParsing = false;

			OnItemTextChanged(new ItemTextChangedEventArgs(this));
		}
コード例 #40
0
        /// <summary>
        /// The on text changed overrided. Here we parse the text into RTF for the highlighting.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnTextChanged(EventArgs e)
        {
            if (mParsing) return;
            mParsing = true;
            Win32.LockWindowUpdate(Handle);
            base.OnTextChanged(e);

            try
            {
                if (!mIsUndo)
                {
                    mRedoStack.Clear();
                    mUndoList.Insert(0, mLastInfo);
                    this.LimitUndo();
                    mLastInfo = new UndoRedoInfo(Text, GetScrollPos(), SelectionStart);
                }

                //Save scroll bar an cursor position, changeing the RTF moves the cursor and scrollbars to top positin
                Win32.POINT scrollPos = GetScrollPos();
                int cursorLoc = SelectionStart;

                //Created with an estimate of how big the stringbuilder has to be...
                StringBuilder sb = new StringBuilder((int)(Text.Length * 1.5 + 150));

                //Adding RTF header
                sb.Append(@"{\rtf1\fbidis\ansi\ansicpg1255\deff0\deflang1037{\fonttbl{");

                //Font table creation
                int fontCounter = 0;
                Hashtable fonts = new Hashtable();
                AddFontToTable(sb, Font, ref fontCounter, fonts);
                foreach (HighlightDescriptor hd in mHighlightDescriptors)
                {
                    if ((hd.Font != null) && !fonts.ContainsKey(hd.Font.Name))
                    {
                        AddFontToTable(sb, hd.Font, ref fontCounter, fonts);
                    }
                }
                sb.Append("}\n");

                //ColorTable

                sb.Append(@"{\colortbl ;");
                Hashtable colors = new Hashtable();
                int colorCounter = 1;
                AddColorToTable(sb, ForeColor, ref colorCounter, colors);
                AddColorToTable(sb, BackColor, ref colorCounter, colors);

                foreach (HighlightDescriptor hd in mHighlightDescriptors)
                {
                    if (!colors.ContainsKey(hd.Color))
                    {
                        AddColorToTable(sb, hd.Color, ref colorCounter, colors);
                    }
                }

                //Parsing text

                sb.Append("}\n").Append(@"\viewkind4\uc1\pard\ltrpar");
                SetDefaultSettings(sb, colors, fonts);

                char[] sperators = mSeperators.GetAsCharArray();

                //Replacing "\" to "\\" for RTF...
                //string[] lines = Text.Replace("\\", "\\\\").Replace("{", "\\{").Replace("}", "\\}").Split('\n');

                int firstCharIndexFromLine = this.GetFirstCharIndexOfCurrentLine();
                //int lastCharindexFromLine = this.Rtf.IndexOf('\n', firstCharIndexFromLine);

                //lastCharindexFromLine = lastCharindexFromLine != -1 ? lastCharindexFromLine : this.Rtf.Length;

                    //string line = this.Rtf.Substring(firstCharIndexFromLine, lastCharindexFromLine != -1 ? lastCharindexFromLine - firstCharIndexFromLine : this.Rtf.Length - firstCharIndexFromLine);
                    //Log.Write(line, this, "OnTextChanged - Line", Log.LogType.DEBUG);

                int lineNumber = this.GetLineFromCharIndex(this.GetFirstCharIndexOfCurrentLine());

                string line = this.Text.Length != 0 ? this.Lines[lineNumber] : "";

                // Select line in control
                this.SelectionStart = firstCharIndexFromLine;
                this.SelectionLength = line.Length; // lastCharindexFromLine - firstCharIndexFromLine;

                line = line.Replace("\\", "\\\\").Replace("{", "\\{").Replace("}", "\\}");                //Log.Write(firstCharIndexFromLine + ", " + lastCharindexFromLine, this, "OnTextChanged - IndexOf", Log.LogType.DEBUG);

                string[] tokens = mCaseSesitive ? line.Split(sperators) : line.ToUpper().Split(sperators);
                if (tokens.Length == 0)
                {
                    sb.Append(line);
                    AddNewLine(sb);
                    //continue;
                }

                //Log.Write(line, this, "OntextChange", Log.LogType.DEBUG);

                int tokenCounter = 0;
                for (int i = 0; i < line.Length; )
                {
                    char curChar = line[i];
                    if (mSeperators.Contains(curChar))
                    {
                        sb.Append(curChar);
                        i++;
                    }
                    else
                    {
                        string curToken = tokens[tokenCounter++];
                        //curToken = curToken.Replace("\\}", "}").Replace("\\{", "{");
                        if (descriptorProccessMode == DescriptorProccessModes.ProccessBySeperarators)
                        {
                            ///Log.Write("Ulazim u obradu...DescriptorRecognitionJob");
                            //DescriptorRecognitionJob(sb, fonts, colors, sperators, lines, ref lineCounter, ref line, ref tokens, ref tokenCounter, ref i, curToken, bAddToken);
                            ProccessFormatOnAllLines();
                        }
                        else if (descriptorProccessMode == DescriptorProccessModes.ProcsessLineForDescriptor)
                        {
                            ///Log.Write("Ulazim u obradu...DescriptorRecognitionJob2");
                            line = DescriptorRecognitionJob2(fonts, colors, line);
                            i = line.Length;
                        }
                    }
                }

                    ///Log.Write(string.Concat(this.Rtf.Substring(0, firstCharIndexFromLine), line, this.Rtf.Substring(lastCharindexFromLine)), this, "OnTextChanged", Log.LogType.DEBUG);
                    //Rtf = string.Concat(this.Rtf.Substring(0, firstCharIndexFromLine), line, this.Rtf.Substring(lastCharindexFromLine));

                // Replace edited line with new

                //Log.Write(sb.ToString(), this, "OnTextChanged - sb", Log.LogType.DEBUG);
                //Log.Write(this.Rtf, this, "OnTextChanged - rtf", Log.LogType.DEBUG);
                this.SelectedRtf = string.Concat(sb.ToString(), line,"}");

                //Restore cursor and scrollbars location.
                SelectionStart = cursorLoc;

                mParsing = false;

                SetScrollPos(scrollPos);
            }
            catch (Exception ex)
            {
                Log.Write(ex, this, "OntextChange", Log.LogType.ERROR);
            }

            Win32.LockWindowUpdate((IntPtr)0);
            Invalidate();
        }