예제 #1
0
        private void commandInsertEmoticon_Execute(object sender, ExecuteEventHandlerArgs args)
        {
            EmoticonsGalleryCommand galleryCommand = (EmoticonsGalleryCommand)sender;
            int newSelectedIndex = args.GetInt(galleryCommand.CommandId.ToString());
            Emoticon emoticon = galleryCommand.Items[newSelectedIndex].Cookie;

            EmoticonsManager.AddToRecent(emoticon);
            using (EditorUndoUnit undo = new EditorUndoUnit(_currentEditor))
            {
                FocusBody();
                InsertHtml(EmoticonsManager.GetHtml(emoticon), HtmlInsertionOptions.MoveCursorAfter);
                undo.Commit();
            }
        }
예제 #2
0
        private void ApplyAlignmentToSmartContent(EditorTextAlignment alignment, IHtmlEditorComponentContext editor, IHTMLElement element)
        {
            using (EditorUndoUnit undo = new EditorUndoUnit(_currentEditor))
            {
                // It was smart content but know we need a reference to it as ISmartContent
                string contentId = element.id;
                string sourceId = "";
                string blockId = "";
                ContentSourceManager.ParseContainingElementId(contentId, out sourceId, out blockId);
                ISmartContent content = (this as IContentSourceSidebarContext).FindSmartContent(blockId);

                if (content != null)
                {
                    // Set the alignment on the smart content
                    switch (alignment)
                    {

                        case EditorTextAlignment.Center:
                            content.Layout.Alignment = Alignment.Center;
                            break;
                        case EditorTextAlignment.Right:
                            content.Layout.Alignment = Alignment.Right;
                            break;
                        case EditorTextAlignment.Left:
                            content.Layout.Alignment = Alignment.Left;
                            break;
                        case EditorTextAlignment.None:
                        case EditorTextAlignment.Justify:
                            content.Layout.Alignment = Alignment.None;
                            break;
                    }

                    // Ask its command source for some new html now that we have set its alignment property
                    string newHtml =
                        SmartContentInsertionHelper.GenerateContentBlock(sourceId, blockId,
                                                                         element.innerHTML, content,
                                                                         element);

                    InsertHtml(newHtml, false);

                    string elementId = ContentSourceManager.MakeContainingElementId(sourceId, blockId);
                    element = (_normalHtmlContentEditor.GetHtmlDocument() as IHTMLDocument3).getElementById(elementId);

                    _normalHtmlContentEditor.EmptySelection();
                    _normalHtmlContentEditor.FocusBody();

                    // We need to do this in the future because at this point, the behavior might not be attached yet
                    // and if it isnt, the content will be selected but it wont show the dashes lines around the smart content
                    TimerHelper.CallbackOnDelay(
                        delegate () { SmartContentSelection.SelectIfSmartContentElement(editor, element); }, 25);
                }
                undo.Commit();
            }
        }
예제 #3
0
        private void ApplyAlignmentToImage(EditorTextAlignment alignment, IHtmlEditorComponentContext editor, IHTMLElement element)
        {
            using (EditorUndoUnit undo = new EditorUndoUnit(_currentEditor))
            {
                // Make an alignment helper to help us change the alignment of the image
                HtmlAlignDecoratorSettings alignmentManager = new HtmlAlignDecoratorSettings(element);

                switch (alignment)
                {
                    case EditorTextAlignment.Center:
                        alignmentManager.SetImageHtmlFromAlignment(ImgAlignment.CENTER);
                        break;
                    case EditorTextAlignment.Right:
                        alignmentManager.SetImageHtmlFromAlignment(ImgAlignment.RIGHT);
                        break;
                    case EditorTextAlignment.Left:
                        alignmentManager.SetImageHtmlFromAlignment(ImgAlignment.LEFT);
                        break;
                    case EditorTextAlignment.None:
                        alignmentManager.SetImageHtmlFromAlignment(ImgAlignment.NONE);
                        break;
                    default:
                        break;
                }

                // Tell the side bar to update its settings to refect the new alignment
                PictureEditingManager.UpdateView(editor.Selection.SelectedImage);
                undo.Commit();
            }
        }
예제 #4
0
        IExtensionData[] IContentSourceSite.UpdateContent(IExtensionData[] extensionDataListOrginal)
        {
            IExtensionData[] extensionDataList = (IExtensionData[])extensionDataListOrginal.Clone();
            // Find all the smart content in the list, and tell them to update.
            IHTMLElement2 postBodyElement = (IHTMLElement2)_normalHtmlContentEditor.PostBodyElement;
            if (postBodyElement != null)
            {
                foreach (IHTMLElement divElement in postBodyElement.getElementsByTagName("div"))
                {
                    // Make sure that the div we have is a smart content, and that it isn't just a div that is part of smart content.
                    if (divElement.className == null || divElement.id == null || divElement.className == ContentSourceManager.SMART_CONTENT || !ContentSourceManager.IsSmartContent(divElement))
                        continue;

                    string contentSourceId = "";
                    string contentId = "";

                    // Get the contentid of the div smart content we have
                    ContentSourceManager.ParseContainingElementId(divElement.id, out contentSourceId, out contentId);

                    // Check to see if this smart content is one we want to update
                    int index = ArrayHelper.SearchForIndexOf<string, IExtensionData>(extensionDataList,
                                                             contentId,
                                                             delegate (string a, IExtensionData b) { return b != null && a == b.Id; });

                    if (index == -1)
                        continue;

                    // The smart content we found in the DOM is also one we
                    // want to update, so save a reference to it from the data list
                    IExtensionData extensionData = extensionDataList[index];

                    // We remove it from the list, which at the end of the function will only
                    // leave the IExtensionData that were not found in the editor.
                    extensionDataList[index] = null;

                    // Make a SmartContent for the element we are about to update,
                    // this will allow the content source to  get at the properties bag
                    // for the smart content so it knows how to update the content
                    SmartContent smartContent = new SmartContent(extensionData);

                    IContentSourceSidebarContext sourceContext = this;

                    // Find the content source that we will use to update the smart content
                    ContentSourceInfo contentSourceInfo = sourceContext.FindContentSource(contentSourceId);

                    // Make sure that we found one, and that is it indeed SmartContentSource
                    if (contentSourceInfo != null && contentSourceInfo.Instance is SmartContentSource)
                    {
                        // Get the html that the content source wants to update the element with
                        string newHtml = ((SmartContentSource)contentSourceInfo.Instance).GenerateEditorHtml(smartContent, this);

                        // If the source for this smart content wants to filter some updates
                        // give it a chance to right now.
                        if (contentSourceInfo.Instance is IContentUpdateFilter)
                        {
                            if (!((IContentUpdateFilter)contentSourceInfo.Instance).ShouldUpdateContent(divElement.innerHTML, newHtml))
                                continue;
                        }

                        // If we are actually sure we want to update the element then we insert it
                        // and wrap it in an invisible undo unit so it will undo the last change the user
                        // made if they ctrl+z
                        using (EditorUndoUnit undo = new EditorUndoUnit(_currentEditor, true))
                        {
                            SmartContentInsertionHelper.InsertContentIntoElement(newHtml, smartContent, sourceContext, divElement);
                            _htmlEditorSidebarHost.ForceUpdateSidebarState();
                            undo.Commit();
                        }

                    }
                }
            }

            return (IExtensionData[])ArrayHelper.Compact(extensionDataList);
        }
예제 #5
0
        public void InsertSmartContentFromTabbedDialog(string contentSourceID, int selectedTab)
        {
            // Get a reference to the video plugin
            ITabbedInsertDialogContentSource contentSource =
                (ITabbedInsertDialogContentSource)ContentSourceManager.GetContentSourceInfoById(contentSourceID).Instance;

            if (contentSource == null)
                return;

            IExtensionData extensionData = (this as IContentSourceSite).CreateExtensionData(Guid.NewGuid().ToString());
            ISmartContent sContent = new InternalSmartContent(extensionData, this, contentSourceID);
            using (EditorUndoUnit undo = new EditorUndoUnit(_currentEditor))
            {
                if (contentSource.CreateContentFromTabbedDialog(_mainFrameWindow, sContent, selectedTab) == DialogResult.OK)
                {
                    string content = ((SmartContentSource)contentSource).GenerateEditorHtml(sContent, this);
                    if (content != null)
                    {
                        ((IContentSourceSite)this).InsertContent(contentSourceID, content, extensionData);
                        undo.Commit();
                    }
                    Focus();

                }

            }
        }
예제 #6
0
        public void InsertSmartContentFromFile(string[] files, string contentSourceID, HtmlInsertionOptions insertionOptions, object context)
        {
            files = RemoveInvalidImages(files);

            if (files == null || files.Length == 0)
                return;

            // Get a reference to the video plugin
            ISupportsDragDropFile contentSource =
                (ISupportsDragDropFile)ContentSourceManager.GetContentSourceInfoById(contentSourceID).Instance;

            if (contentSource == null)
                return;

            IExtensionData extensionData = (this as IContentSourceSite).CreateExtensionData(Guid.NewGuid().ToString());
            ISmartContent sContent = new SmartContent(extensionData);

            if (context == null)
                context = new InternalSmartContentContext(this, contentSourceID);

            using (EditorUndoUnit undo = new EditorUndoUnit(_currentEditor))
            {
                // Have the plugin try to make some new content from the path that we just got through the drag and drop
                if (contentSource.CreateContentFromFile(_mainFrameWindow, sContent, files, context) == DialogResult.OK)
                {
                    string content = ((SmartContentSource)contentSource).GenerateEditorHtml(sContent, this);
                    if (content != null)
                    {
                        ((IContentSourceSite)this).InsertContent(contentSourceID, content, extensionData, insertionOptions);
                        undo.Commit();
                    }
                    Focus();

                }

            }
        }