Exemple #1
0
        /// <summary>
        /// Deletes backspace.
        /// </summary>
        /// <param name="sourceEditor">Source editor</param>
        /// <param name="length">Length</param>
        public static void BackspaceDelete(IOTASourceEditor sourceEditor, int length)
        {
            if (sourceEditor != null)
            {
                if (sourceEditor.EditViewCount > 0)
                {
                    IOTAEditView _EditView = sourceEditor.GetEditView(0);

                    IOTAEditPosition _EditPos = _EditView.Position;
                    _EditPos.BackspaceDelete(length);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets char after cursor.
        /// </summary>
        /// <param name="sourceEditor">Source editor</param>
        /// <returns>Char.MinValue if wrong.</returns>
        public static char GetCharAfterCursor(IOTASourceEditor sourceEditor)
        {

            LoggingService.EnterMethod();
            char result = char.MinValue;

            if (sourceEditor != null)
            {
                if (sourceEditor.EditViewCount > 0)
                {
                    IOTAEditView _EditView = sourceEditor.GetEditView(0);

                    IOTAEditPosition _EditPos = _EditView.Position;
                    //_EditPos.Save();

                    //					bool canMove = _EditPos.MoveRelative(0, -1);
                    //					if (canMove) // no content
                    //					{
                    result = _EditPos.Character;
                    LoggingService.Info("get char result is " + result.ToString());
                    //} else {
                    //	LoggingService.Warn("cannot move, may it is the beginning of a line");
                    //}
                    //_EditPos.Restore();
                }
                else
                {
                    LoggingService.Warn("no view");
                }
            }
            else
            {
                LoggingService.Warn("null editor");
            }
            LoggingService.LeaveMethod();

            return result;
        }
Exemple #3
0
        //		/// <summary>
        //		/// Gets word before cursor.
        //		/// </summary>
        //		/// <param name="sourceEditor">Source editor</param>
        //		/// <remarks>
        //		/// <para>Special chars ahead are ignored. </para>
        //		/// <para>If space is before cursor return String.Empty.</para>
        //		///  <para>If there are some chars after cursor return String.Empty.</para>
        //		/// </remarks>
        //		/// <returns>String.Empty if wrong.</returns>
        //		[]
        //		public static string GetWordBeforeCursor2(IOTASourceEditor sourceEditor) {
        //			string result = String.Empty;
        //			if (sourceEditor != null) {
        //				if (sourceEditor.EditViewCount > 0) {
        //					IOTAEditView _EditView = sourceEditor.GetEditView(0);
        //
        //					IOTAEditPosition _EditPos = _EditView.Position;
        //					if (Char.IsWhiteSpace(_EditPos.Character)) {
        //						int _ActualColumn = _EditPos.Column;
        //						int _ActualRow = _EditPos.Row;
        //
        //						int _WordLength = 0;
        //
        //						bool canMove = _EditPos.MoveRelative(0, -1);
        //						if (canMove) // no content
        //						{
        //							while (canMove && _EditView.Position.IsWordCharacter) {
        //								_WordLength++;
        //								canMove = _EditPos.MoveRelative(0, -1);
        //							}
        //							result = _EditView.Position.Read(_WordLength + 1).Trim();
        //							_EditView.Position.Move(_ActualRow, _ActualColumn);
        //						} else {
        //							LoggingService.Warn("no content");
        //						}
        //					} else {
        //						LoggingService.Warn("some char on the right");
        //					}
        //				} else {
        //					LoggingService.Warn("no view");
        //				}
        //			} else {
        //				LoggingService.Warn("null editor");
        //			}
        //			return result;
        //		}

        #endregion

        #region CSBuilder Goodies extensions
        /// <summary>
        /// Gets word before cursor.
        /// </summary>
        /// <param name="sourceEditor">Source editor</param>
        /// <remarks>Special chars are included.</remarks>
        /// <returns>String.Empty if wrong.</returns>
        public static string GetWordBeforeCursor(IOTASourceEditor sourceEditor)
        {
            LoggingService.EnterMethod();
            if (sourceEditor != null)
            {
                if (sourceEditor.EditViewCount > 0)
                {
                    IOTAEditView _EditView = sourceEditor.GetEditView(0);

                    IOTAEditPosition _EditPos = _EditView.Position;
                    _EditPos.Save();
                    string _TheWord = String.Empty;
                    int _WordLength = 0;

                    if (!_EditPos.MoveRelative(0, -1)) // no content
                    {
                        _EditPos.Restore();
                        LoggingService.LeaveMethod();
                        return String.Empty;
                    }
                    while (_EditView.Position.IsWhitespace)
                    {
                        if (!_EditPos.MoveRelative(0, -1))
                        {
                            _EditPos.Restore();
                            LoggingService.LeaveMethod();
                            return String.Empty;
                        }
                    } // slip all whitespaces
                    while (_EditPos.IsWordCharacter || _EditPos.IsSpecialCharacter)
                    {
                        _WordLength++;
                        if (!_EditPos.MoveRelative(0, -1))
                        {
                            break;
                        }
                    }
                    _TheWord = _EditPos.Read(_WordLength + 1).Trim();
                    _EditPos.Restore();
                    LoggingService.Info(_TheWord);
                    LoggingService.LeaveMethod();
                    return _TheWord;
                }
            }
            LoggingService.LeaveMethod();
            return String.Empty;
        }
Exemple #4
0
 /// <summary>
 /// Gets a line string of a certain line number.
 /// </summary>
 /// <param name="sourceEditor">Source editor</param>
 /// <param name="number">Line number</param>
 /// <returns>null if wrong.</returns>
 public static string GetLineOf(IOTASourceEditor sourceEditor, int number)
 {
     if (sourceEditor == null || number < 0 || number >= sourceEditor.LinesInBuffer)
     {
         return null;
     }
     IOTAEditView view = sourceEditor.GetEditView(0);
     if (view == null)
     {
         return null;
     }
     IOTAEditPosition pos = view.Buffer.EditPosition;
     pos.Save();
     pos.GotoLine(number);
     pos.MoveEOL();
     int lastCol = pos.Column;
     pos.MoveBOL();
     int firstCol = pos.Column;
     string result = pos.Read(lastCol - firstCol + 1);
     pos.Restore();
     return result.Split(new char[] { '\r', '\n' })[0];
 }
Exemple #5
0
        /// <summary>
        /// Selects text from position to position.
        /// </summary>
        /// <param name="sourceEditor">Source</param>
        /// <param name="startPos">Start position</param>
        /// <param name="endPos">End position</param>
        public static void SelectTextFromPosToPos(IOTASourceEditor sourceEditor, OTAEditPos startPos, OTAEditPos endPos)
        {
            if (sourceEditor != null)
            {
                if (sourceEditor.EditViewCount > 0)
                {
                    IOTAEditView _EditView = sourceEditor.GetEditView(0);

                    _EditView.CursorPos = startPos;

                    _EditView.Block.BeginBlock();
                    _EditView.Block.Style = OTABlockType.btNonInclusive;

                    _EditView.CursorPos = endPos;
                    _EditView.MoveViewToCursor();
                    _EditView.Block.EndBlock();
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Selects line.
        /// </summary>
        /// <param name="sourceEditor">Source editor</param>
        public static void SelectLine(IOTASourceEditor sourceEditor)
        {
            if (sourceEditor != null)
            {
                if (sourceEditor.EditViewCount > 0)
                {
                    IOTAEditView _EditView = sourceEditor.GetEditView(0);

                    OTAEditPos _EditPos = new OTAEditPos();

                    _EditPos.Line = _EditView.Position.Row;
                    _EditPos.Col = 1;
                    _EditView.CursorPos = _EditPos;
                    _EditView.Block.BeginBlock();
                    _EditView.Block.Style = OTABlockType.btNonInclusive;

                    if (_EditView.Position.MoveEOL())
                    {
                        _EditView.MoveViewToCursor();
                    }

                    _EditView.Block.EndBlock();
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Gets current edit position.
        /// </summary>
        /// <param name="sourceEditor">Source editor</param>
        /// <returns>new object if wrong.</returns>
        public static OTAEditPos GetCurrentEditPos(IOTASourceEditor sourceEditor)
        {
            if (sourceEditor != null)
            {
                if (sourceEditor.EditViewCount > 0)
                {
                    IOTAEditView _EditView = sourceEditor.GetEditView(0);

                    return _EditView.CursorPos;
                }
            }

            return new OTAEditPos();
        }
Exemple #8
0
 /// <summary>
 /// Gets edit view.
 /// </summary>
 /// <param name="sourceEditor">Source editor</param>
 /// <returns></returns>
 public static IOTAEditView GetEditView(IOTASourceEditor sourceEditor)
 {
     if (sourceEditor != null && sourceEditor.EditViewCount > 0)
     {
         return sourceEditor.GetEditView(0);
     }
     else
     {
         return null;
     }
 }