Ejemplo n.º 1
0
        void HandlePositionChanged(object sender, DocumentLocationEventArgs e)
        {
            int      caretOffset = Editor.Caret.Offset - baseOffset;
            TextLink link        = links.Find(l => !l.PrimaryLink.IsInvalid() && l.PrimaryLink.Offset <= caretOffset && caretOffset <= l.PrimaryLink.EndOffset);

            if (link != null && link.Count > 0 && link.IsEditable)
            {
                if (closedLink == link)
                {
                    return;
                }
                closedLink = null;

                /* Disabled because code completion was enabled in link mode.
                 * if (window == null) {
                 *      window = new ListWindow<string> ();
                 *      window.DoubleClicked += delegate {
                 *              CompleteWindow ();
                 *      };
                 *      window.DataProvider = link;
                 *
                 *      DocumentLocation loc = Editor.Document.OffsetToLocation (BaseOffset + link.PrimaryLink.Offset);
                 *      Editor.ShowListWindow (window, loc);
                 *
                 * } */
            }
            else
            {
                closedLink = null;
            }
        }
Ejemplo n.º 2
0
        void HandlePositionChanged(object sender, DocumentLocationEventArgs e)
        {
            int      caretOffset = Editor.Caret.Offset - baseOffset;
            TextLink link        = links.Find(l => l.PrimaryLink != null && l.PrimaryLink.Offset <= caretOffset && caretOffset <= l.PrimaryLink.EndOffset);

            if (link != null && link.Count > 0 && link.IsEditable)
            {
                if (window != null && window.DataProvider != link)
                {
                    DestroyWindow();
                }
                if (closedLink == link)
                {
                    return;
                }
                closedLink = null;
                if (window == null)
                {
                    window = new ListWindow <string> ();
                    window.DataProvider = link;

                    DocumentLocation loc = Editor.Document.OffsetToLocation(BaseOffset + link.PrimaryLink.Offset);
                    Editor.ShowListWindow(window, loc);
                }
            }
            else
            {
                DestroyWindow();
                closedLink = null;
            }
        }
Ejemplo n.º 3
0
        void GotoPreviousLink(TextLink link)
        {
            int caretOffset = Editor.Caret.Offset - baseOffset;
            var prevLink    = links.FindLast(l => l.IsEditable && l.PrimaryLink.Offset < (link != null ? link.PrimaryLink.Offset : caretOffset));

            if (prevLink == null)
            {
                prevLink = links.FindLast(l => l.IsEditable);
            }
            Setlink(prevLink);
        }
Ejemplo n.º 4
0
        void GotoNextLink(TextLink link)
        {
            int      caretOffset = Editor.Caret.Offset - baseOffset;
            TextLink nextLink    = links.Find(l => l.IsEditable && l.PrimaryLink.Offset > (link != null ? link.PrimaryLink.EndOffset : caretOffset));

            if (nextLink == null)
            {
                nextLink = links.Find(l => l.IsEditable);
            }
            closedLink = null;
            Setlink(nextLink);
        }
Ejemplo n.º 5
0
 void Setlink(TextLink link)
 {
     if (link.PrimaryLink.IsInvalid())
     {
         return;
     }
     Editor.Caret.Offset = baseOffset + link.PrimaryLink.Offset;
     Editor.ScrollToCaret();
     Editor.Caret.Offset  = baseOffset + link.PrimaryLink.EndOffset;
     Editor.MainSelection = new MonoDevelop.Ide.Editor.Selection(Editor.Document.OffsetToLocation(baseOffset + link.PrimaryLink.Offset),
                                                                 Editor.Document.OffsetToLocation(baseOffset + link.PrimaryLink.EndOffset));
     Editor.Document.CommitUpdateAll();
 }
Ejemplo n.º 6
0
 void Setlink(TextLink link)
 {
     if (link.PrimaryLink == null)
     {
         return;
     }
     Editor.Caret.Offset = baseOffset + link.PrimaryLink.Offset;
     Editor.ScrollToCaret();
     Editor.Caret.Offset  = baseOffset + link.PrimaryLink.EndOffset;
     Editor.MainSelection = new Selection(Editor.Document.OffsetToLocation(baseOffset + link.PrimaryLink.Offset),
                                          Editor.Document.OffsetToLocation(baseOffset + link.PrimaryLink.EndOffset));
     Editor.Document.CommitUpdateAll();
 }
Ejemplo n.º 7
0
        void CompleteWindow()
        {
            if (window == null)
            {
                return;
            }
            TextLink lnk = (TextLink)window.DataProvider;

            //int line = Editor.Caret.Line;
            lnk.CurrentText = (string)window.CurrentItem;
            UpdateLinkText(lnk);
            UpdateTextLinks();
            Editor.Document.CommitUpdateAll();
        }
Ejemplo n.º 8
0
        public Gtk.Window CreateTooltipWindow(TextEditor Editor, int offset, Gdk.ModifierType modifierState, TooltipItem item)
        {
            TextLink link = item.Item as TextLink;

            if (link == null || string.IsNullOrEmpty(link.Tooltip))
            {
                return(null);
            }

            TooltipWindow window = new TooltipWindow();

            window.Markup = link.Tooltip;
            return(window);
        }
        protected override Window CreateTooltipWindow(TextEditor Editor, int offset, ModifierKeys modifierState, TooltipItem item)
        {
            TextLink link = item.Item as TextLink;

            if (link == null || string.IsNullOrEmpty(link.Tooltip))
            {
                return(null);
            }

            TooltipWindow window = new TooltipWindow();

            window.Markup = link.Tooltip;
            return(window);
        }
Ejemplo n.º 10
0
        public override Task <TooltipItem> GetItem(MonoTextEditor Editor, int offset, CancellationToken token = default(CancellationToken))
        {
            int o = offset - mode.BaseOffset;

            for (int i = 0; i < mode.Links.Count; i++)
            {
                TextLink l = mode.Links [i];
                if (!l.PrimaryLink.IsInvalid && l.PrimaryLink.Offset <= o && o <= l.PrimaryLink.EndOffset)
                {
                    return(Task.FromResult(new TooltipItem(l, l.PrimaryLink.Offset, l.PrimaryLink.Length)));
                }
            }
            return(Task.FromResult <TooltipItem> (null));
            //return mode.Links.First (l => l.PrimaryLink != null && l.PrimaryLink.Offset <= o && o <= l.PrimaryLink.EndOffset);
        }
Ejemplo n.º 11
0
        public TooltipItem GetItem(TextEditor Editor, int offset)
        {
            int o = offset - mode.BaseOffset;

            for (int i = 0; i < mode.Links.Count; i++)
            {
                TextLink l = mode.Links[i];
                if (l.PrimaryLink != null && l.PrimaryLink.Offset <= o && o <= l.PrimaryLink.EndOffset)
                {
                    return(new TooltipItem(l, l.PrimaryLink.Offset, l.PrimaryLink.Length));
                }
            }
            return(null);
            //return mode.Links.First (l => l.PrimaryLink != null && l.PrimaryLink.Offset <= o && o <= l.PrimaryLink.EndOffset);
        }
Ejemplo n.º 12
0
        void UpdateLinkText(TextLink link, Microsoft.VisualStudio.Text.ITextEdit edit)
        {
            for (int i = 0; (i < link.Links.Count); ++i)
            {
                var s      = link.Links[i];
                int offset = s.Offset + baseOffset;
                if (offset < 0 || s.Length < 0 || offset + s.Length > Editor.Document.Length)
                {
                    // This should never happen since it implies a corrupted link/bad update following a text change.
                    continue;
                }

                var span = new Microsoft.VisualStudio.Text.Span(offset, s.Length);
                if (edit.Snapshot.GetText(span) != link.CurrentText)
                {
                    edit.Replace(span, link.CurrentText);
                }
            }
        }
Ejemplo n.º 13
0
        public void StartMode()
        {
            foreach (TextLink link in links)
            {
                if (!link.PrimaryLink.IsInvalid)
                {
                    link.CurrentText = Editor.Document.GetTextAt(link.PrimaryLink.Offset + baseOffset, link.PrimaryLink.Length);
                }
                foreach (TextSegment segment in link.Links)
                {
                    Editor.Document.EnsureOffsetIsUnfolded(baseOffset + segment.Offset);
                    DocumentLine line = Editor.Document.GetLineByOffset(baseOffset + segment.Offset);
                    if (line.GetMarker(typeof(TextLinkMarker)) != null)
                    {
                        continue;
                    }
                    TextLinkMarker marker = (TextLinkMarker)line.GetMarker(typeof(TextLinkMarker));
                    if (marker == null)
                    {
                        marker            = new TextLinkMarker(this);
                        marker.BaseOffset = baseOffset;
                        Editor.Document.AddMarker(line, marker);
                        textLinkMarkers.Add(marker);
                    }
                }
            }

            editor.Document.BeforeUndoOperation += HandleEditorDocumentBeginUndo;
            Editor.Document.TextReplaced        += UpdateLinksOnTextReplace;
            this.Editor.Caret.PositionChanged   += HandlePositionChanged;
            this.UpdateTextLinks();
            this.HandlePositionChanged(null, null);
            TextLink firstLink = links.First(l => l.IsEditable);

            if (SelectPrimaryLink)
            {
                Setlink(firstLink);
            }
            Editor.Document.CommitUpdateAll();
            editor.Document.OptimizeTypedUndo();
            this.undoDepth = Editor.Document.GetCurrentUndoDepth();
            ShowHelpWindow();
        }
Ejemplo n.º 14
0
 public void UpdateLinkText(TextLink link)
 {
     Editor.Document.TextReplaced -= UpdateLinksOnTextReplace;
     for (int i = link.Links.Count - 1; i >= 0; i--)
     {
         Segment s      = link.Links[i];
         int     offset = s.Offset + baseOffset;
         if (offset < 0 || s.Length < 0 || offset + s.Length > Editor.Document.Length)
         {
             continue;
         }
         if (Editor.Document.GetTextAt(offset, s.Length) != link.CurrentText)
         {
             Editor.Replace(offset, s.Length, link.CurrentText);
             int delta = link.CurrentText.Length - s.Length;
             AdjustLinkOffsets(s.Offset, delta);
             Editor.Document.CommitLineUpdate(Editor.Document.OffsetToLineNumber(offset));
         }
     }
     Editor.Document.TextReplaced += UpdateLinksOnTextReplace;
 }
Ejemplo n.º 15
0
 void UpdateTextLink(TextLink link, Microsoft.VisualStudio.Text.ITextEdit edit)
 {
     if (link.GetStringFunc != null)
     {
         link.Values = link.GetStringFunc(GetStringCallback);
     }
     if (!link.IsEditable && link.Values != null && link.Values.Count > 0)
     {
         link.CurrentText = (string)link.Values [link.Values.Count - 1];
     }
     else
     {
         if (!link.PrimaryLink.IsInvalid())
         {
             int offset = link.PrimaryLink.Offset + baseOffset;
             if (offset >= 0 && link.PrimaryLink.Length >= 0)
             {
                 link.CurrentText = Editor.Document.GetTextAt(offset, link.PrimaryLink.Length);
             }
         }
     }
     UpdateLinkText(link, edit);
 }
Ejemplo n.º 16
0
 void UpdateTextLink(TextLink link)
 {
     if (link.GetStringFunc != null)
     {
         link.Values = link.GetStringFunc(GetStringCallback);
     }
     if (!link.IsEditable && link.Values.Count > 0)
     {
         link.CurrentText = (string)link.Values[link.Values.Count - 1];
     }
     else
     {
         if (link.PrimaryLink != null)
         {
             int offset = link.PrimaryLink.Offset + baseOffset;
             if (offset >= 0 && link.PrimaryLink.Length >= 0)
             {
                 link.CurrentText = Editor.Document.GetTextAt(offset, link.PrimaryLink.Length);
             }
         }
     }
     UpdateLinkText(link);
 }
Ejemplo n.º 17
0
        protected override void HandleKeypress(Gdk.Key key, uint unicodeKey, Gdk.ModifierType modifier)
        {
            int      caretOffset = Editor.Caret.Offset - baseOffset;
            TextLink link        = links.Find(l => l.Links.Any(s => s.Offset <= caretOffset && caretOffset <= s.EndOffset));

            switch (key)
            {
            case Gdk.Key.BackSpace:
                if (link != null && caretOffset == link.PrimaryLink.Offset && !IsSomethingSelectedInLink(editor, link.PrimaryLink))
                {
                    return;
                }
                goto default;

            case Gdk.Key.space:
                if (link == null || !link.IsIdentifier)
                {
                    goto default;
                }
                return;

            case Gdk.Key.Delete:
                if (link != null && caretOffset == link.PrimaryLink.EndOffset && !IsSomethingSelectedInLink(editor, link.PrimaryLink))
                {
                    return;
                }
                goto default;

            case Gdk.Key.Tab:
                if ((modifier & Gdk.ModifierType.ControlMask) != 0)
                {
                    if (link != null && !link.IsIdentifier)
                    {
                        goto default;
                    }
                }
                if ((modifier & Gdk.ModifierType.ShiftMask) == 0)
                {
                    GotoNextLink(link);
                }
                else
                {
                    GotoPreviousLink(link);
                }
                return;

            case Gdk.Key.Escape:
            case Gdk.Key.Return:
            case Gdk.Key.KP_Enter:
                if ((modifier & Gdk.ModifierType.ControlMask) != 0)
                {
                    if (link != null && !link.IsIdentifier)
                    {
                        goto default;
                    }
                }
                ExitTextLinkMode();
                if (key == Gdk.Key.Escape)
                {
                    OnCancel(EventArgs.Empty);
                }
                return;

            default:
                wasReplaced = false;
                base.HandleKeypress(key, unicodeKey, modifier);
                if (wasReplaced && link == null)
                {
                    resetCaret = false;
                    ExitTextLinkMode();
                }
                break;
            }
        }
Ejemplo n.º 18
0
        protected override void HandleKeypress(Gdk.Key key, uint unicodeKey, Gdk.ModifierType modifier)
        {
            if (window != null)
            {
                ListWindowKeyAction action = window.ProcessKey(key, modifier);
                if ((action & ListWindowKeyAction.Complete) == ListWindowKeyAction.Complete)
                {
                    CompleteWindow();
                }
                if ((action & ListWindowKeyAction.CloseWindow) == ListWindowKeyAction.CloseWindow)
                {
                    closedLink = (TextLink)window.DataProvider;
                    DestroyWindow();
                }
                if ((action & ListWindowKeyAction.Complete) == ListWindowKeyAction.Complete)
                {
                    GotoNextLink(closedLink);
                }

                if ((action & ListWindowKeyAction.Ignore) == ListWindowKeyAction.Ignore)
                {
                    return;
                }
            }
            int      caretOffset = Editor.Caret.Offset - baseOffset;
            TextLink link        = links.Find(l => l.Links.Any(s => s.Offset <= caretOffset && caretOffset <= s.EndOffset));

            switch (key)
            {
            case Gdk.Key.BackSpace:
                if (link != null && caretOffset == link.PrimaryLink.Offset)
                {
                    return;
                }
                goto default;

            case Gdk.Key.space:
                if (link == null || !link.IsIdentifier)
                {
                    goto default;
                }
                return;

            case Gdk.Key.Delete:
                if (link != null && caretOffset == link.PrimaryLink.EndOffset)
                {
                    return;
                }
                goto default;

            case Gdk.Key.Tab:
                if ((modifier & Gdk.ModifierType.ControlMask) != 0)
                {
                    if (link != null && !link.IsIdentifier)
                    {
                        goto default;
                    }
                }
                if ((modifier & Gdk.ModifierType.ShiftMask) == 0)
                {
                    GotoNextLink(link);
                }
                else
                {
                    GotoPreviousLink(link);
                }
                return;

            case Gdk.Key.Escape:
            case Gdk.Key.Return:
                if ((modifier & Gdk.ModifierType.ControlMask) != 0)
                {
                    if (link != null && !link.IsIdentifier)
                    {
                        goto default;
                    }
                }
                if (window != null)
                {
                    CompleteWindow();
                }
                else
                {
                    ExitTextLinkMode();
                }
                if (key == Gdk.Key.Escape)
                {
                    OnCancel(EventArgs.Empty);
                }
                return;

            default:
                wasReplaced = false;
                base.HandleKeypress(key, unicodeKey, modifier);
                if (wasReplaced && link == null)
                {
                    resetCaret = false;
                    ExitTextLinkMode();
                }
                break;
            }

/*			if (link != null)
 *                              UpdateTextLink (link);
 *                      UpdateTextLinks ();
 *                      Editor.Document.CommitUpdateAll ();*/
        }
Ejemplo n.º 19
0
		void ITextEditorImpl.StartTextLinkMode (TextLinkModeOptions textLinkModeOptions)
		{
			var convertedLinks = new List<Mono.TextEditor.TextLink> ();
			foreach (var link in textLinkModeOptions.Links) {
				var convertedLink = new Mono.TextEditor.TextLink (link.Name);
				convertedLink.IsEditable = link.IsEditable;
				convertedLink.IsIdentifier = link.IsIdentifier;
				var func = link.GetStringFunc;
				if (func != null) {
					convertedLink.GetStringFunc = delegate(Func<string, string> arg) {
						return new ListDataProviderWrapper (func (arg));
					};
				}
				foreach (var segment in link.Links) {
					convertedLink.AddLink (new Mono.TextEditor.TextSegment (segment.Offset, segment.Length)); 
				}
				convertedLinks.Add (convertedLink); 
			}

			var tle = new TextLinkEditMode (TextEditor, 0, convertedLinks);
			tle.SetCaretPosition = false;
			if (tle.ShouldStartTextLinkMode) {
				tle.OldMode = TextEditor.CurrentMode;
				if (textLinkModeOptions.ModeExitedAction != null) {
					tle.Cancel += (sender, e) => textLinkModeOptions.ModeExitedAction (new TextLinkModeEventArgs (false));
					tle.Exited += (sender, e) => {
						for (int i = 0; i < convertedLinks.Count; i++) {
							textLinkModeOptions.Links[i].CurrentText = convertedLinks[i].CurrentText;
						}
						textLinkModeOptions.ModeExitedAction (new TextLinkModeEventArgs (true));
						
					};
				}
				var undoOperation = TextEditor.OpenUndoGroup ();
				tle.Exited += (object sender, EventArgs e) => undoOperation.Dispose ();
				tle.StartMode ();
				TextEditor.CurrentMode = tle;
			}
		}