Esempio n. 1
0
        void IHtmlEditorCommandSource.ApplyAlignment(EditorTextAlignment alignment)
        {
            switch (alignment)
            {
            case EditorTextAlignment.Left:
                ApplyAlignment("left");
                break;

            case EditorTextAlignment.Center:
                ApplyAlignment("center");
                break;

            case EditorTextAlignment.Right:
                ApplyAlignment("right");
                break;

            case EditorTextAlignment.Justify:
                ApplyAlignment("justify");
                break;
            }
        }
 void IHtmlEditorCommandSource.ApplyAlignment(EditorTextAlignment alignment)
 {
     switch (alignment)
     {
         case EditorTextAlignment.Left:
             ExecuteBlockCommand(new CommandExecutor(GetMshtmlCommand(IDM.JUSTIFYLEFT).Execute));
             break;
         case EditorTextAlignment.Center:
             ExecuteBlockCommand(new CommandExecutor(GetMshtmlCommand(IDM.JUSTIFYCENTER).Execute));
             break;
         case EditorTextAlignment.Right:
             ExecuteBlockCommand(new CommandExecutor(GetMshtmlCommand(IDM.JUSTIFYRIGHT).Execute));
             break;
         case EditorTextAlignment.Justify:
             ExecuteBlockCommand(new CommandExecutor(GetMshtmlCommand(IDM.JUSTIFYFULL).Execute));
             break;
         case EditorTextAlignment.None:
             ExecuteBlockCommand(new CommandExecutor(GetMshtmlCommand(IDM.JUSTIFYNONE).Execute));
             break;
     }
 }
        void IHtmlEditorCommandSource.ApplyAlignment(EditorTextAlignment alignment)
        {
            switch (alignment)
            {
                case EditorTextAlignment.Left:
                    ApplyAlignment("left");
                    break;
                case EditorTextAlignment.Center:
                    ApplyAlignment("center");
                    break;
                case EditorTextAlignment.Right:
                    ApplyAlignment("right");
                    break;
                case EditorTextAlignment.Justify:
                    ApplyAlignment("justify");
                    break;

            }

        }
        public void ApplyAlignment(EditorTextAlignment alignment)
        {
            // Check to see if our current editor is one that allows selections
            IHtmlEditorComponentContext editorIHtmlEditorComponentContext = _currentEditor as IHtmlEditorComponentContext;
            if (editorIHtmlEditorComponentContext != null
                && editorIHtmlEditorComponentContext.Selection != null)
            {
                // Check to see if the editor has an image selected
                if (editorIHtmlEditorComponentContext.Selection.SelectedImage != null)
                {
                    ApplyAlignmentToImage(alignment, editorIHtmlEditorComponentContext, (IHTMLElement)editorIHtmlEditorComponentContext.Selection.SelectedImage);
                    return;
                }

                // Check to see what is selectedi smart content
                IHTMLElement[] elements =
                    editorIHtmlEditorComponentContext.Selection.SelectedMarkupRange.GetTopLevelElements(
                        MarkupRange.FilterNone);
                if (elements.Length == 1 && ContentSourceManager.IsSmartContent(elements[0]))
                {
                    ApplyAlignmentToSmartContent(alignment, editorIHtmlEditorComponentContext, elements[0]);
                    return;
                }
            }

            // It wasnt smart content or an image, so continue with the normal way of applying alignment
            _currentEditor.CommandSource.ApplyAlignment(alignment);
        }
        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();
            }
        }
        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();
            }
        }