public bool JumpToLine()
        {
            IEditableTextBuffer ipos = (IEditableTextBuffer)newContent.GetContent(typeof(IEditableTextBuffer));

            ipos.SetCaretTo(Math.Max(1, fileInfo.Line), Math.Max(1, fileInfo.Column), fileInfo.HighlightCaretLine);
            return(false);
        }
Beispiel #2
0
        private void InsertEntry(Document document)
        {
            IEditableTextBuffer textBuffer = document.GetContent <IEditableTextBuffer>();

            if (textBuffer == null)
            {
                return;
            }

            string changeLogFileName          = document.FileName;
            string changeLogFileNameDirectory = Path.GetDirectoryName(changeLogFileName);
            string selectedFileName           = GetSelectedFile();
            string selectedFileNameDirectory  = Path.GetDirectoryName(selectedFileName);
            string eol = document.Editor != null ? document.Editor.EolMarker : Environment.NewLine;

            int pos = GetHeaderEndPosition(document);

            if (pos > 0 && selectedFileNameDirectory.StartsWith(changeLogFileNameDirectory))
            {
                string text = "\t* "
                              + selectedFileName.Substring(changeLogFileNameDirectory.Length + 1) + ": "
                              + eol + eol;
                int insertPos = Math.Min(pos + 2, textBuffer.Length);
                textBuffer.InsertText(insertPos, text);

                insertPos += text.Length;
                textBuffer.Select(insertPos, insertPos);
                textBuffer.CursorPosition = insertPos;

                document.Select();
            }
        }
Beispiel #3
0
        public bool JumpToLine()
        {
            IEditableTextBuffer ipos = newContent.GetContent <IEditableTextBuffer> ();

            ipos.SetCaretTo(Math.Max(1, fileInfo.Line), Math.Max(1, fileInfo.Column), fileInfo.Options.HasFlag(OpenDocumentOptions.HighlightCaretLine));
            return(false);
        }
        static NavigationPoint GetNavPointForDoc(Document doc)
        {
            if (doc == null)
            {
                return(null);
            }

            NavigationPoint point = null;

            INavigable navigable = doc.GetContent <INavigable> ();

            if (navigable != null)
            {
                point = navigable.BuildNavigationPoint();
                if (point != null)
                {
                    return(point);
                }
            }

            IEditableTextBuffer editBuf = doc.GetContent <IEditableTextBuffer> ();

            if (editBuf != null)
            {
                point = new TextFileNavigationPoint(doc, editBuf);
                if (point != null)
                {
                    return(point);
                }
            }

            return(new DocumentNavigationPoint(doc));
        }
Beispiel #5
0
        private bool InsertHeader(Document document)
        {
            IEditableTextBuffer textBuffer = document.GetContent <IEditableTextBuffer>();

            if (textBuffer == null)
            {
                return(false);
            }

            AuthorInformation userInfo = document.Project != null ? document.Project.AuthorInformation : AuthorInformation.Default;

            if (!userInfo.IsValid)
            {
                string title  = GettextCatalog.GetString("ChangeLog entries can't be generated");
                string detail = GettextCatalog.GetString("The name or e-mail of the user has not been configured.");
                MessageService.ShowError(title, detail);
                return(false);
            }
            string eol  = document.Editor != null ? document.Editor.EolMarker : Environment.NewLine;
            string date = DateTime.Now.ToString("yyyy-MM-dd");
            string text = date + "  " + userInfo.Name + "  <" + userInfo.Email + ">"
                          + eol + eol;

            // Read the first line and compare it with the header: if they are
            // the same don't insert a new header.
            int pos = GetHeaderEndPosition(document);

            if (pos < 0 || (pos + 2 > textBuffer.Length) || textBuffer.GetText(0, pos + 2) != text)
            {
                textBuffer.InsertText(0, text);
            }
            return(true);
        }
        protected virtual ICompletionDataList ClosingTagCompletion(IEditableTextBuffer buf, TextLocation currentLocation)
        {
            //get name of current node in document that's being ended
            XElement el = tracker.Engine.Nodes.Peek() as XElement;

            if (el != null && el.Region.End >= currentLocation && !el.IsClosed && el.IsNamed)
            {
                string tag = String.Concat("</", el.Name.FullName, ">");
                if (XmlEditorOptions.AutoCompleteElements)
                {
                    //						//make sure we have a clean atomic undo so the user can undo the tag insertion
                    //						//independently of the >
                    //						bool wasInAtomicUndo = this.Editor.Document.IsInAtomicUndo;
                    //						if (wasInAtomicUndo)
                    //							this.Editor.Document.EndAtomicUndo ();

                    using (var undo = buf.OpenUndoGroup()) {
                        buf.InsertText(buf.CursorPosition, tag);
                        buf.CursorPosition -= tag.Length;
                    }

                    //						if (wasInAtomicUndo)
                    //							this.Editor.Document.BeginAtomicUndo ();

                    return(null);
                }
                else
                {
                    CompletionDataList cp = new CompletionDataList();
                    cp.Add(new XmlTagCompletionData(tag, 0, true));
                    return(cp);
                }
            }
            return(null);
        }
Beispiel #7
0
        public TextFileNavigationPoint(Document doc, IEditableTextBuffer buffer)
            : base(doc)
        {
            int col;

            buffer.GetLineColumnFromPosition(buffer.CursorPosition, out line, out col);
        }
Beispiel #8
0
        /// <summary>
        /// Returns  the currently selected text within the current IDE content window.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/>
        /// </returns>
        public static string SelectedText()
        {
            // Get active documents text buffer
            IEditableTextBuffer editor = IdeApp.Workbench.ActiveDocument.GetContent <IEditableTextBuffer>();

            // Return trimmed selection
            return(editor.SelectedText.Trim());
        }
		public override bool ExtendsEditor (Document doc, IEditableTextBuffer editor)
		{
			return (Path.GetExtension (doc.Title).ToUpper () == ".C"   ||
			        Path.GetExtension (doc.Title).ToUpper () == ".CPP" ||
			        Path.GetExtension (doc.Title).ToUpper () == ".CXX" ||
			        Path.GetExtension (doc.Title).ToUpper () == ".H"   ||
			        Path.GetExtension (doc.Title).ToUpper () == ".HPP");
		}
 public override bool ExtendsEditor(Document doc, IEditableTextBuffer editor)
 {
     return(Path.GetExtension(doc.Title).ToUpper() == ".C" ||
            Path.GetExtension(doc.Title).ToUpper() == ".CPP" ||
            Path.GetExtension(doc.Title).ToUpper() == ".CXX" ||
            Path.GetExtension(doc.Title).ToUpper() == ".H" ||
            Path.GetExtension(doc.Title).ToUpper() == ".HPP");
 }
 public override bool ExtendsEditor(MonoDevelop.Ide.Gui.Document doc, IEditableTextBuffer editor)
 {
     if (doc == null)
     {
         return(false);
     }
     return(IsFileNameHandled(doc.Name));
 }
Beispiel #12
0
        ///////////////////////////////////////////////////////////////////////

        #region Protected Helper Methods (Update)
        protected virtual void UpdateText(
            CommandInfo info
            )
        {
            IEditableTextBuffer buffer = GetEditableTextBuffer();

            info.Enabled = (buffer != null) &&
                           !String.IsNullOrEmpty(buffer.SelectedText);
        }
Beispiel #13
0
        public void JumpTo(int line, int column)
        {
            IEditableTextBuffer ip = (IEditableTextBuffer)content.GetContent(typeof(IEditableTextBuffer));

            if (ip != null)
            {
                ShowPage(0);
                ip.SetCaretTo(line, column);
            }
        }
Beispiel #14
0
        protected override Document DoShow()
        {
            Document doc = base.DoShow();

            if (doc != null)
            {
                IEditableTextBuffer buf = doc.GetContent <IEditableTextBuffer> ();
                if (buf != null)
                {
                    buf.SetCaretTo(Math.Max(line, 1), Math.Max(column, 1));
                }
            }
            return(doc);
        }
Beispiel #15
0
            protected override MonoDevelop.Ide.Gui.Document DoShow()
            {
                var doc = base.DoShow();

                if (doc != null)
                {
                    IEditableTextBuffer buf = doc.GetContent <IEditableTextBuffer> ();
                    if (buf != null)
                    {
                        buf.SetCaretTo(Math.Max(Line, 1), Math.Max(Column, 1));
                    }
                }
                return(doc);
            }
 protected void on_btn_go_to_line_clicked(object sender, EventArgs e)
 {
     try {
         IEditableTextBuffer view = IdeApp.Workbench.ActiveDocument.GetContent <IEditableTextBuffer> ();
         if (view != null)
         {
             int l = Math.Max(1, Int32.Parse(line_number_entry.Text));
             view.SetCaretTo(l, 1);
         }
     } catch (Exception) {
     } finally {
         GotoLineDialog.Hide();
     }
 }
        private int GetHeaderEndPosition(Document document)
        {
            IEditableTextBuffer textBuffer = document.GetContent <IEditableTextBuffer>();

            if (textBuffer == null)
            {
                return(0);
            }

            // This is less than optimal, we simply read 1024 chars hoping to
            // find a newline there: if we don't find it we just return 0.
            string text = textBuffer.GetText(0, Math.Min(textBuffer.Length, 1023));

            return(text.IndexOf(Environment.NewLine + Environment.NewLine));
        }
        public override void InsertCompletionText(CompletionListWindow window, ref KeyActions ka, Gdk.Key closeChar, char keyChar, Gdk.ModifierType modifier)
        {
            IEditableTextBuffer buf = window.CompletionWidget as IEditableTextBuffer;

            if (buf != null)
            {
                using (var undo = buf.OpenUndoGroup()) {
                    buf.InsertText(buf.CursorPosition, element);

                    // Move caret into the middle of the tags
                    buf.CursorPosition = window.CodeCompletionContext.TriggerOffset + cursorOffset;
                    buf.Select(buf.CursorPosition, buf.CursorPosition);
                }
            }
        }
        public override void InsertCompletionText(CompletionListWindow window)
        {
            IEditableTextBuffer buf = window.CompletionWidget as IEditableTextBuffer;

            if (buf != null)
            {
                buf.BeginAtomicUndo();
                buf.InsertText(buf.CursorPosition, element);

                // Move caret into the middle of the tags
                buf.CursorPosition = window.CodeCompletionContext.TriggerOffset + cursorOffset;
                buf.Select(buf.CursorPosition, buf.CursorPosition);
                buf.EndAtomicUndo();
            }
        }
Beispiel #20
0
        static int GetHeaderEndPosition(Document document)
        {
            IEditableTextBuffer textBuffer = document.GetContent <IEditableTextBuffer>();

            if (textBuffer == null)
            {
                return(0);
            }

            // This is less than optimal, we simply read 1024 chars hoping to
            // find a newline there: if we don't find it we just return 0.
            string text = textBuffer.GetText(0, Math.Min(textBuffer.Length, 1023));
            string eol  = document.Editor != null ? document.Editor.EolMarker : Environment.NewLine;

            return(text.IndexOf(eol + eol, StringComparison.Ordinal));
        }
Beispiel #21
0
        protected override Document DoShow()
        {
            Document doc = base.DoShow();

            if (doc != null)
            {
                IEditableTextBuffer buf = doc.GetContent <IEditableTextBuffer> ();
                if (buf != null)
                {
                    doc.DisableAutoScroll();
                    buf.RunWhenLoaded(() => {
                        buf.SetCaretTo(Math.Max(line, 1), Math.Max(column, 1));
                    });
                }
            }
            return(doc);
        }
Beispiel #22
0
        public void OnLowercaseSelection()
        {
            IEditableTextBuffer buffer = GetContent <IEditableTextBuffer> ();

            if (buffer == null)
            {
                return;
            }

            string selectedText = buffer.SelectedText;

            if (string.IsNullOrEmpty(selectedText))
            {
                int    pos   = buffer.CursorPosition;
                string ch    = buffer.GetText(pos, pos + 1);
                string lower = ch.ToLower();
                if (lower == ch)
                {
                    buffer.CursorPosition = pos + 1;
                    return;
                }
                ;
                using (var undo = buffer.OpenUndoGroup())
                {
                    buffer.DeleteText(pos, 1);
                    buffer.InsertText(pos, lower);
                    buffer.CursorPosition = pos + 1;
                }
            }
            else
            {
                string newText = selectedText.ToLower();
                if (newText == selectedText)
                {
                    return;
                }
                int startPos = buffer.SelectionStartPosition;
                using (var undo = buffer.OpenUndoGroup())
                {
                    buffer.DeleteText(startPos, selectedText.Length);
                    buffer.InsertText(startPos, newText);
                    buffer.Select(startPos, startPos + newText.Length);
                }
            }
        }
Beispiel #23
0
        // All line and column numbers are 1-based

        public static TextEditor GetTextEditor(IBaseViewContent content)
        {
            IEditableTextBuffer tb = (IEditableTextBuffer)content.GetContent(typeof(IEditableTextBuffer));

            if (tb == null)
            {
                return(null);
            }

            TextEditor ed = new TextEditor();

            ed.textBuffer         = tb;
            ed.bookmarkBuffer     = (IBookmarkBuffer)content.GetContent(typeof(IBookmarkBuffer));
            ed.encodedTextContent = (IEncodedTextContent)content.GetContent(typeof(IEncodedTextContent));
            ed.completionWidget   = (ICompletionWidget)content.GetContent(typeof(ICompletionWidget));
            ed.clipboardHandler   = (IClipboardHandler)content.GetContent(typeof(IClipboardHandler));
            return(ed);
        }
        public void OnJoinWithNextLine()
        {
            IEditableTextBuffer buffer = GetContent <IEditableTextBuffer> ();

            if (buffer != null)
            {
                int cursor_pos = buffer.CursorPosition;
                int line, column;
                buffer.GetLineColumnFromPosition(buffer.CursorPosition, out line, out column);
                if (line >= doc.TextEditor.LineCount)
                {
                    return;
                }
                int start_pos = buffer.GetPositionFromLineColumn(line, 0) + 1;

                int line_len      = doc.TextEditor.GetLineLength(line);
                int next_line_len = doc.TextEditor.GetLineLength(line + 1);

                if (next_line_len < 0)
                {
                    return;
                }

                int end_pos = start_pos + line_len + next_line_len + 1;

                string curr_line = doc.TextEditor.GetLineText(line);
                string next_line = doc.TextEditor.GetLineText(line + 1);

                string new_text          = curr_line;
                string next_line_trimmed = next_line.TrimStart('\n', '\r', '\t', ' ');
                if (!string.IsNullOrEmpty(next_line_trimmed))
                {
                    new_text += " " + next_line_trimmed;
                }

                buffer.BeginAtomicUndo();
                buffer.DeleteText(start_pos, end_pos - start_pos);
                buffer.InsertText(start_pos, new_text);
                buffer.EndAtomicUndo();

                buffer.CursorPosition = cursor_pos;
            }
        }
Beispiel #25
0
        void saveDocumentToTextView()
        {
            if (editorProcess != null && !editorProcess.ExceptionOccurred)
            {
                IEditableTextBuffer textBuf = (IEditableTextBuffer)viewContent.GetContent(typeof(IEditableTextBuffer));

                string doc = null;
                try {
                    doc = editorProcess.Editor.GetDocument();
                } catch (Exception e) {
                    MonoDevelop.Ide.MessageService.ShowException(e,
                                                                 AddinManager.CurrentLocalizer.GetString(
                                                                     "The document could not be retrieved from the designer"));
                }

                if (doc != null)
                {
                    textBuf.Text = doc;
                }
            }
        }
Beispiel #26
0
        ///////////////////////////////////////////////////////////////////////

        protected virtual void HandleBufferResult(
            IEditableTextBuffer buffer,
            Result result
            )
        {
            if (buffer == null)
            {
                return;
            }

            buffer.BeginAtomicUndo();

            try
            {
                buffer.SelectedText = result;
            }
            finally
            {
                buffer.EndAtomicUndo();
            }
        }
Beispiel #27
0
        ///////////////////////////////////////////////////////////////////////

        protected virtual void HandleResult(
            Type type,
            IEditableTextBuffer buffer,
            ReturnCode code,
            Result result
            )
        {
            if (buffer == null)
            {
                return;
            }

            if (replace)
            {
                HandleBufferResult(buffer, result);
            }
            else
            {
                HandleDocumentResult(type, code, result);
            }
        }
        public void OnLowercaseSelection()
        {
            IEditableTextBuffer buffer = GetContent <IEditableTextBuffer> ();

            if (buffer != null)
            {
                if (buffer.SelectedText == String.Empty)
                {
                    int    pos = buffer.CursorPosition;
                    string ch  = buffer.GetText(pos, pos + 1);
                    buffer.DeleteText(pos, 1);
                    buffer.InsertText(pos, ch.ToLower());
                    buffer.CursorPosition = pos + 1;
                }
                else
                {
                    string newText  = buffer.SelectedText.ToLower();
                    int    startPos = buffer.SelectionStartPosition;
                    buffer.DeleteText(startPos, buffer.SelectedText.Length);
                    buffer.InsertText(startPos, newText);
                }
            }
        }
Beispiel #29
0
        ///////////////////////////////////////////////////////////////////////

        #region MonoDevelop.Components.Commands.CommandHandler Overrides
        protected override void Run()
        {
            IEditableTextBuffer buffer = GetEditableTextBuffer();

            if (buffer == null)
            {
                return;
            }

            string text = buffer.SelectedText;

            if (String.IsNullOrEmpty(text))
            {
                return;
            }

            ReturnCode code;
            Result     result = null;

            code   = EvaluateExpression(text, ref result);
            result = Utility.FormatResult(code, result);

            HandleResult(GetType(), buffer, code, result);
        }
 public override bool ExtendsEditor(MonoDevelop.Ide.Gui.Document doc, IEditableTextBuffer editor)
 {
     return(doc.IsFile && DLanguageBinding.IsDFile(doc.FileName));
 }
 public override bool ExtendsEditor(Document doc, IEditableTextBuffer editor)
 {
     return (Path.GetExtension (doc.FileName).Equals (RubyLanguageBinding.RubyExtension, StringComparison.OrdinalIgnoreCase));
 }
		public override bool ExtendsEditor (Document doc, IEditableTextBuffer editor)
		{
			var binding = LanguageBindingService.GetBindingPerFileName (doc.Name);
			return binding != null && binding is IDotNetLanguageBinding;
		}
		public override bool ExtendsEditor (MonoDevelop.Ide.Gui.Document doc, IEditableTextBuffer editor)
		{
			return System.IO.Path.GetExtension (doc.Name) == ".cs";
		}
		protected virtual ICompletionDataList ClosingTagCompletion (IEditableTextBuffer buf, TextLocation currentLocation)
		{
			//get name of current node in document that's being ended
			XElement el = tracker.Engine.Nodes.Peek () as XElement;
			if (el != null && el.Region.End >= currentLocation && !el.IsClosed && el.IsNamed) {
				string tag = String.Concat ("</", el.Name.FullName, ">");
				if (XmlEditorOptions.AutoCompleteElements) {

					//						//make sure we have a clean atomic undo so the user can undo the tag insertion
					//						//independently of the >
					//						bool wasInAtomicUndo = this.Editor.Document.IsInAtomicUndo;
					//						if (wasInAtomicUndo)
					//							this.Editor.Document.EndAtomicUndo ();

					using (var undo = buf.OpenUndoGroup ()) {
						buf.InsertText (buf.CursorPosition, tag);
						buf.CursorPosition -= tag.Length;
					}

					//						if (wasInAtomicUndo)
					//							this.Editor.Document.BeginAtomicUndo ();

					return null;
				} else {
					CompletionDataList cp = new CompletionDataList ();
					cp.Add (new XmlTagCompletionData (tag, 0, true));
					return cp;
				}
			}
			return null;
		}
		public override bool ExtendsEditor (MonoDevelop.Ide.Gui.Document doc, IEditableTextBuffer editor)
		{
			return StringComparer.OrdinalIgnoreCase.Equals (System.IO.Path.GetExtension (doc.Name), ".cs");
		}
		public override bool ExtendsEditor (Document doc, IEditableTextBuffer editor)
		{
			MonoDevelop.Projects.IDotNetLanguageBinding binding = MonoDevelop.Projects.LanguageBindingService.GetBindingPerFileName (doc.Name) as MonoDevelop.Projects.IDotNetLanguageBinding;
			return binding != null;
		}
Beispiel #37
0
 public override bool ExtendsEditor(MonoDevelop.Ide.Gui.Document doc, IEditableTextBuffer editor)
 {
     return doc.FileName.Extension == ".boo";
 }
Beispiel #38
0
 public override bool ExtendsEditor(Document doc, IEditableTextBuffer editor)
 {
     MonoDevelop.Projects.IDotNetLanguageBinding binding = MonoDevelop.Projects.LanguageBindingService.GetBindingPerFileName(doc.Name) as MonoDevelop.Projects.IDotNetLanguageBinding;
     return(binding != null);
 }
		public override bool ExtendsEditor (MonoDevelop.Ide.Gui.Document doc, IEditableTextBuffer editor)
		{
			return IsFileNameHandled (doc.Name) && base.ExtendsEditor (doc, editor);
		}
 public override bool ExtendsEditor(MonoDevelop.Ide.Gui.Document doc, IEditableTextBuffer editor)
 {
     return doc.IsFile && DLanguageBinding.IsDFile(doc.FileName);
 }
 public override bool ExtendsEditor(MonoDevelop.Ide.Gui.Document doc, IEditableTextBuffer editor)
 {
     return doc.FileName.FileName.EndsWith (".ts");
 }
 public override bool ExtendsEditor(Document doc, IEditableTextBuffer editor)
 {
     return doc.IsFile && Path.GetExtension(doc.FileName).ToLower() == ".rst";
 }
		public override bool ExtendsEditor (MonoDevelop.Ide.Gui.Document doc, IEditableTextBuffer editor)
		{
			//can only attach if there is not already an attached BaseXmlEditorExtension
			return doc.GetContent<BaseXmlEditorExtension> () == null;
		}
		public override bool ExtendsEditor(Document doc, IEditableTextBuffer editor)
		{
			return (doc.Project is DotNetProject) && (editor.Name.ToString ().EndsWith (".addin") || editor.Name.ToString ().EndsWith (".addin.xml"));
		}
		public TextFileNavigationPoint (Document doc, IEditableTextBuffer buffer)
			: base (doc)
		{
			int col;
			buffer.GetLineColumnFromPosition (buffer.CursorPosition, out line, out col);
		}
 public virtual bool ExtendsEditor(Document doc, IEditableTextBuffer editor)
 {
     return true;
 }
		public override bool ExtendsEditor (MonoDevelop.Ide.Gui.Document doc, IEditableTextBuffer editor)
		{
			if (doc == null)
				return false;
			return IsFileNameHandled (doc.Name);
		}
 public override bool ExtendsEditor(Document doc, IEditableTextBuffer editor)
 {
     return false;
 }