Пример #1
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();
            }
        }
Пример #2
0
        public EditorTextAlignment GetSelectionAlignment()
        {
            IHTMLElement element = null;

            try
            {
                IHtmlEditorComponentContext editorIHtmlEditorComponentContext = _currentEditor as IHtmlEditorComponentContext;
                if (editorIHtmlEditorComponentContext != null && editorIHtmlEditorComponentContext.Selection != null)
                {
                    // Check and see if this an image
                    if (editorIHtmlEditorComponentContext.Selection.SelectedImage != null)
                    {
                        element = editorIHtmlEditorComponentContext.Selection.SelectedImage as IHTMLElement;
                    }

                    // Check if it is smart content
                    if (editorIHtmlEditorComponentContext.Selection is SmartContentSelection)
                    {
                        IHTMLElement[] elements =
                            editorIHtmlEditorComponentContext.Selection.SelectedMarkupRange.GetTopLevelElements(
                                ContentSourceManager.IsSmartContentContainer);
                        if (elements.Length > 0)
                        {
                            element = elements[0];
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Failed to detect alignment: " + ex);
                element = null;
            }

            // If we found an image or smart content, try to get the alignment off of it
            if (element != null)
            {
                HtmlAlignDecoratorSettings img = new HtmlAlignDecoratorSettings(element);
                switch (img.GetAlignmentFromHtml())
                {
                    case ImgAlignment.LEFT:
                        return EditorTextAlignment.Left;
                    case ImgAlignment.RIGHT:
                        return EditorTextAlignment.Right;
                    case ImgAlignment.CENTER:
                        return EditorTextAlignment.Center;
                }
                return EditorTextAlignment.None;
            }

            return _currentEditor != null ? _currentEditor.CommandSource.GetSelectionAlignment() : EditorTextAlignment.None;
        }