public void StartTextLinkMode(TextLinkModeOptions textLinkModeOptions)
 {
     if (textLinkModeOptions == null)
     {
         throw new ArgumentNullException(nameof(textLinkModeOptions));
     }
     textEditorImpl.StartTextLinkMode(textLinkModeOptions);
 }
Exemplo n.º 2
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;
			}
		}