public override bool FindLink(string linkText, HyperlinkForm caller)
 {
     using (SelectPostLinkForm openPostForm = new SelectPostLinkForm())
     {
         if (openPostForm.ShowDialog(Win32WindowImpl.ForegroundWin32Window) == DialogResult.OK)
         {
             if (String.Empty == caller.LinkText.Trim())
                 caller.LinkText = openPostForm.PostTitle;
             caller.Hyperlink = openPostForm.PostLink;
             return true;
         }
     }
     return false;
 }
Exemplo n.º 2
0
        void IHtmlEditorCommandSource.InsertLink()
        {
            // allow for inserting links even when there is no text selection (insert a
            // link w/ the user specified title at the current caret location). Wasn't exactly
            // sure how to do this....

            // show our "insert-link" dialog
            using (new WaitCursor())
            {
                //check out the selection to see if it is appropriate use of insert hyperlink
                bool _isImageOnly = false;
                if ((this as IHtmlEditorComponentContext).Selection.SelectedImage != null)
                {
                    _isImageOnly = true;

                }
                else if (!FullyEditableRegionActive || SelectedMarkupRange.GetElements(ElementFilters.VISIBLE_EMPTY_ELEMENTS, true).Length > 0)
                {
                    DisplayMessage.Show(MessageId.NotLinkable);
                    return;
                }
                else if (ContainsMultipleAnchors()) //contains multiple links
                {
                    DisplayMessage.Show(MessageId.MultipleLinks);
                    return;
                }

                //else is text only

                using (HyperlinkForm hyperlinkForm = new HyperlinkForm(this.CommandManager, ShowAllHyperlinkOptions))
                {

                    LinkInfo info = ((IHtmlEditorCommandSource)this).DiscoverCurrentLink();

                    hyperlinkForm.ContainsImage = _isImageOnly;

                    if (info.AnchorText != null && !_isImageOnly)
                    {
                        hyperlinkForm.LinkText = info.AnchorText;
                    }

                    //if not editing a current link, check glossary for auto-populate info
                    if (info.Url == null && !_isImageOnly)
                    {
                        if (info.AnchorText != null)
                        {
                            GlossaryLinkItem item = GlossaryManager.Instance.FindEntry(info.AnchorText.Trim());
                            if (item != null)
                            {
                                if (item.Url != String.Empty) hyperlinkForm.Hyperlink = item.Url;
                                if (item.Title != String.Empty) hyperlinkForm.LinkTitle = item.Title;
                                hyperlinkForm.IsInGlossary = true;
                            }
                        }
                    }
                    else if (info.Url != null)
                    {
                        // don't set the url if it is pointing to a local "backing file" for
                        // the current image thumbnail
                        if (!UrlIsTemporaryLocalFilePath(info.Url))
                            hyperlinkForm.Hyperlink = info.Url;
                        if (info.LinkTitle != null) hyperlinkForm.LinkTitle = info.LinkTitle;
                        if (info.Rel != null) hyperlinkForm.Rel = info.Rel;
                        hyperlinkForm.NewWindow = info.NewWindow;
                        if (!_isImageOnly)
                        {
                            hyperlinkForm.IsInGlossary =
                                GlossaryManager.Instance.FindExactEntry(hyperlinkForm.LinkText, hyperlinkForm.Hyperlink, hyperlinkForm.LinkTitle);
                        }
                    }

                    //tell whether this is edit style
                    hyperlinkForm.EditStyle = info.Url != null;

                    // show the dialog to edit the link
                    DialogResult linkDialogResult = hyperlinkForm.ShowDialog(EditorControl.FindForm());
                    if (linkDialogResult != DialogResult.Cancel)
                    {
                        IUndoUnit undoUnit = CreateUndoUnit();
                        using (undoUnit)
                        {
                            if (_isImageOnly)
                            {
                                if (linkDialogResult == DialogResult.OK)
                                {
                                    InsertImageLink(hyperlinkForm.Hyperlink, hyperlinkForm.LinkTitle, hyperlinkForm.NewWindow, hyperlinkForm.Rel);
                                }
                                else
                                {
                                    InsertImageLink(String.Empty, String.Empty, false, String.Empty);
                                }
                            }
                            else
                            {

                                ExpandAnchorSelection();
                                MarkupRange mRange = CleanUpRange();

                                //add the link if this is add/edit
                                if (linkDialogResult == DialogResult.OK)
                                {
                                    InsertLink(hyperlinkForm.Hyperlink, hyperlinkForm.LinkText, hyperlinkForm.LinkTitle, hyperlinkForm.Rel, hyperlinkForm.NewWindow, mRange);
                                }

                            }
                            // commit the change
                            undoUnit.Commit();
                        }
                    }
                }
            }
        }
        private DialogResult EditTargetOptions()
        {
            using (LinkToOptionsForm linkOptionsForm = new LinkToOptionsForm())
            {
                if (SelectedLinkTarget == LinkTargetType.IMAGE)
                {
                    using (ImageTargetEditorControl editor = new ImageTargetEditorControl())
                    {
                        editor.LoadImageSize(HtmlImageTargetSettings.ImageSize, EditorContext.SourceImageSize, EditorContext.ImageRotation);
                        editor.LinkOptions = HtmlImageTargetSettings.LinkOptions;
                        editor.EditorOptions = ImageEditingContext.EditorOptions;
                        linkOptionsForm.EditorControl = editor;

                        HtmlImageTargetSettings.DhtmlImageViewer = ImageEditingContext.EditorOptions.DhtmlImageViewer;

                        DialogResult result = linkOptionsForm.ShowDialog(this);
                        if (result == DialogResult.OK)
                        {
                            HtmlImageTargetSettings.ImageSize = editor.ImageSize;
                            HtmlImageTargetSettings.DhtmlImageViewer = ImageEditingContext.EditorOptions.DhtmlImageViewer;
                            HtmlImageTargetSettings.LinkOptions = editor.LinkOptions;
                            HtmlImageTargetSettings.ImageSizeName = editor.ImageBoundsSize;
                        }
                        return result;
                    }
                }
                else if (SelectedLinkTarget == LinkTargetType.URL)
                {
                    using (HyperlinkForm hyperlinkForm = new HyperlinkForm(EditorContext.CommandManager, GlobalEditorOptions.SupportsFeature(ContentEditorFeature.ShowAllLinkOptions)))
                    {
                        hyperlinkForm.ContainsImage = true;
                        hyperlinkForm.EditStyle = HtmlImageTargetSettings.LinkTargetUrl != null && HtmlImageTargetSettings.LinkTargetUrl != String.Empty;
                        hyperlinkForm.NewWindow = HtmlImageTargetSettings.LinkOptions.ShowInNewWindow;
                        if (HtmlImageTargetSettings.LinkTitle != String.Empty)
                            hyperlinkForm.LinkTitle = HtmlImageTargetSettings.LinkTitle;
                        if (HtmlImageTargetSettings.LinkRel != String.Empty)
                            hyperlinkForm.Rel = HtmlImageTargetSettings.LinkRel;
                        if (HtmlImageTargetSettings.LinkTargetUrl != null && HtmlImageTargetSettings.LinkTarget != LinkTargetType.IMAGE)
                        {
                            hyperlinkForm.Hyperlink = HtmlImageTargetSettings.LinkTargetUrl;
                        }

                        DialogResult result = hyperlinkForm.ShowDialog(FindForm());
                        if (result == DialogResult.OK)
                        {
                            HtmlImageTargetSettings.LinkTargetUrl = hyperlinkForm.Hyperlink;
                            HtmlImageTargetSettings.UpdateImageLinkOptions(hyperlinkForm.LinkTitle, hyperlinkForm.Rel, hyperlinkForm.NewWindow);
                            HtmlImageTargetSettings.LinkOptions = new LinkOptions(hyperlinkForm.NewWindow, false, null);
                        }
                        return result;
                    }
                }

                return DialogResult.Abort;
            }
        }
 void IHtmlEditorCommandSource.InsertLink()
 {
     using (new WaitCursor())
     {
         if (!_canInsertHyperlink)
         {
             DisplayMessage.Show(MessageId.TitleNotLinkable);
             return;
         }
         using (HyperlinkForm hyperlinkForm = new HyperlinkForm(CommandManager, ShowAllLinkOptions))
         {
             hyperlinkForm.LinkText = _textBox.SelectedText;
             hyperlinkForm.EditStyle = false;
             if (hyperlinkForm.ShowDialog(Owner) == DialogResult.OK)
             {
                 InsertLink(hyperlinkForm.Hyperlink, hyperlinkForm.LinkText, hyperlinkForm.LinkTitle, hyperlinkForm.Rel, hyperlinkForm.NewWindow);
             }
         }
     }
 }
        private DialogResult EditTargetOptions(LinkTargetType linkTargetType)
        {
            using (LinkToOptionsForm linkOptionsForm = new LinkToOptionsForm())
            {
                if (linkTargetType == LinkTargetType.IMAGE)
                {
                    using (ImageTargetEditorControl editor = new ImageTargetEditorControl())
                    {
                        editor.LoadImageSize(ImagePropertiesInfo.LinkTargetImageSize, ImagePropertiesInfo.ImageSourceSize, ImagePropertiesInfo.ImageRotation);
                        editor.LinkOptions = ImagePropertiesInfo.LinkOptions;
                        editor.EditorOptions = _imageEditingContext.EditorOptions;
                        linkOptionsForm.EditorControl = editor;

                        ImagePropertiesInfo.DhtmlImageViewer = _imageEditingContext.EditorOptions.DhtmlImageViewer;

                        DialogResult result = linkOptionsForm.ShowDialog(_editorContext.MainFrameWindow);
                        if (result == DialogResult.OK)
                        {
                            ImagePropertiesInfo.LinkTargetImageSize = editor.ImageSize;
                            ImagePropertiesInfo.DhtmlImageViewer = _imageEditingContext.EditorOptions.DhtmlImageViewer;
                            ImagePropertiesInfo.LinkOptions = editor.LinkOptions;
                            ImagePropertiesInfo.LinkTargetImageSizeName = editor.ImageBoundsSize;
                        }
                        return result;
                    }
                }
                else if (linkTargetType == LinkTargetType.URL)
                {
                    using (HyperlinkForm hyperlinkForm = new HyperlinkForm(_editorContext.CommandManager, GlobalEditorOptions.SupportsFeature(ContentEditorFeature.ShowAllLinkOptions)))
                    {
                        hyperlinkForm.ContainsImage = true;
                        hyperlinkForm.EditStyle = !String.IsNullOrEmpty(ImagePropertiesInfo.LinkTargetUrl);
                        hyperlinkForm.NewWindow = ImagePropertiesInfo.LinkOptions.ShowInNewWindow;
                        if (ImagePropertiesInfo.LinkTitle != String.Empty)
                            hyperlinkForm.LinkTitle = ImagePropertiesInfo.LinkTitle;
                        if (ImagePropertiesInfo.LinkRel != String.Empty)
                            hyperlinkForm.Rel = ImagePropertiesInfo.LinkRel;
                        if (ImagePropertiesInfo.LinkTargetUrl != null && ImagePropertiesInfo.LinkTarget != LinkTargetType.IMAGE)
                        {
                            hyperlinkForm.Hyperlink = ImagePropertiesInfo.LinkTargetUrl;
                        }

                        DialogResult result = hyperlinkForm.ShowDialog(_editorContext.MainFrameWindow);
                        if (result == DialogResult.OK)
                        {
                            ImagePropertiesInfo.LinkTargetUrl = hyperlinkForm.Hyperlink;
                            ImagePropertiesInfo.UpdateImageLinkOptions(hyperlinkForm.LinkTitle, hyperlinkForm.Rel, hyperlinkForm.NewWindow);
                            ImagePropertiesInfo.LinkOptions = new LinkOptions(hyperlinkForm.NewWindow, false, null);
                        }
                        return result;
                    }
                }

                return DialogResult.Abort;
            }
        }