internal void SetHyperlink()
        {
            var textArea = Editor.TextArea;
            if (textArea.Selection.IsEmpty)
                return;

            var selectedText = textArea.Selection.GetText(textArea.Document);

            //  Check if the selected text already is a link...
            string text = selectedText, url = string.Empty;
            var match = Regex.Match(selectedText, @"\[(?<text>(?:[^\\]|\\.)+)\]\((?<url>[^)]+)\)");
            if (match.Success)
            {
                text = match.Groups["text"].Value;
                url = match.Groups["url"].Value;
            }
            var hyperlink = new MarkPadHyperlink(text, url);

            (DataContext as DocumentViewModel)
                .ExecuteSafely(vm =>
                                   {
                                       hyperlink = vm.GetHyperlink(hyperlink);
                                       textArea.Selection.ReplaceSelectionWithText(textArea,
                                           string.Format("[{0}]({1})", hyperlink.Text, hyperlink.Url));
                                   });
        }
        internal void SetHyperlink()
        {
            var textArea = Editor.TextArea;

            if (textArea.Selection.IsEmpty)
            {
                return;
            }

            var selectedText = textArea.Selection.GetText();

            //  Check if the selected text already is a link...
            string text = selectedText, url = string.Empty;
            var    match = Regex.Match(selectedText, @"\[(?<text>(?:[^\\]|\\.)+)\]\((?<url>[^)]+)\)");

            if (match.Success)
            {
                text = match.Groups["text"].Value;
                url  = match.Groups["url"].Value;
            }
            var hyperlink = new MarkPadHyperlink(text, url);

            (DataContext as DocumentViewModel)
            .ExecuteSafely(vm =>
            {
                hyperlink = vm.GetHyperlink(hyperlink);
                if (hyperlink != null)
                {
                    textArea.Selection.ReplaceSelectionWithText(string.Format("[{0}]({1})", hyperlink.Text, hyperlink.Url));
                }
            });
        }
Exemple #3
0
        public MarkPadHyperlink GetHyperlink(MarkPadHyperlink hyperlink)
        {
            var viewModel = new HyperlinkEditorViewModel(hyperlink.Text, hyperlink.Url);

            this.windowManager.ShowDialog(viewModel);
            if (!viewModel.WasCancelled)
            {
                hyperlink.Set(viewModel.Text, viewModel.Url);
            }
            return(hyperlink);
        }
        public MarkPadHyperlink GetHyperlink(MarkPadHyperlink hyperlink)
        {
            var viewModel = new HyperlinkEditorViewModel(hyperlink.Text, hyperlink.Url)
            {
                IsUrlFocussed = !String.IsNullOrWhiteSpace(hyperlink.Text)
            };

            windowManager.ShowDialog(viewModel);
            if (!viewModel.WasCancelled)
            {
                hyperlink.Set(viewModel.Text, viewModel.Url);
                return(hyperlink);
            }
            return(null);
        }
 public MarkPadHyperlink GetHyperlink(MarkPadHyperlink hyperlink)
 {
     var viewModel = new HyperlinkEditorViewModel(hyperlink.Text, hyperlink.Url)
                         {
                             IsUrlFocussed = !String.IsNullOrWhiteSpace(hyperlink.Text)
                         };
     windowManager.ShowDialog(viewModel);
     if (!viewModel.WasCancelled)
     {
         hyperlink.Set(viewModel.Text, viewModel.Url);
         return hyperlink;
     }
     return null;
 }
 public MarkPadHyperlink GetHyperlink(MarkPadHyperlink hyperlink)
 {
     var viewModel = new HyperlinkEditorViewModel(hyperlink.Text, hyperlink.Url);
     windowManager.ShowDialog(viewModel);
     if (!viewModel.WasCancelled)
     {
         hyperlink.Set(viewModel.Text, viewModel.Url);
         return hyperlink;
     }
     return null;
 }