Exemple #1
0
        private bool IsValidInsertionPoint(IHTMLElement e, MarkupPointer p)
        {
            if (InlineEditField.IsEditField(p.CurrentScope))
            {
                return(true);
            }

            IHTMLElement contentEditableParent = null;
            IHTMLElement parent = e;

            while (parent != null)
            {
                if ((parent as IHTMLElement3).isContentEditable)
                {
                    contentEditableParent = parent;
                }
                else if (contentEditableParent != null)
                {
                    break; //we hit the top-most editable parent.
                }
                parent = parent.parentElement;
            }

            if (contentEditableParent != null)
            {
                MarkupRange range = EditorContext.MarkupServices.CreateMarkupRange(contentEditableParent, false);
                return(range.InRange(p));
            }
            else
            {
                return(false);
            }
        }
        private SidebarControl GetSidebarForCurrentSelection(object selection)
        {
            IHtmlEditorSelection htmlSelection = selection as IHtmlEditorSelection;

            if (selection == null || (!htmlSelection.IsValid && !InlineEditField.IsEditField(selection)))
            {
                return(_defaultSidebarControl);
            }

            foreach (SidebarEntry sidebarEntry in _sidebars)
            {
                ISidebar sidebar = sidebarEntry.Sidebar;
                if (sidebar.AppliesToSelection(selection))
                {
                    SidebarControl sidebarControl = sidebarEntry.SidebarControl;
                    if (sidebarControl == null)
                    {
                        // demand-create sidebar
                        sidebarEntry.SidebarControl         = CreateAndInitializeSidebar(sidebar);
                        sidebarEntry.SidebarControl.Visible = sidebarEntry.SidebarControl.Controls.Count > 0;
                    }
                    return(sidebarEntry.SidebarControl);
                }
            }

            // got this far so no active sidebar for current selection
            return(_defaultSidebarControl);
        }
Exemple #3
0
        public static IHTMLElement GetSelectedChildEditField(IHTMLElement parent, MarkupRange selection)
        {
            if (selection == null || !selection.Positioned)
            {
                Trace.Fail("Selection is invalid!");
                return(null);
            }

            IHTMLElement element = selection.ParentElement();

            if (element == null || !HTMLElementHelper.IsChildOrSameElement(parent, element))
            {
                return(null);
            }

            do
            {
                if (InlineEditField.IsEditField(element))
                {
                    return(element);
                }

                element = element.parentElement;
            } while (element != null && element.sourceIndex != parent.sourceIndex);

            return(null);
        }
Exemple #4
0
        protected override bool DoInsertData(DataAction action, MarkupPointer begin, MarkupPointer end)
        {
            // get a reference to the underlying data object
            IDataObject dataObject = DataMeister.IDataObject;

            string dataObjectInstanceId = dataObject.GetData(SmartContentDataObject.INSTANCE_ID_DATAFORMAT) as string;

            if (EditorContext.EditorId.Equals(dataObjectInstanceId))
            {
                // get the internal items out of the data object
                string smartContentElementId = (string)dataObject.GetData(SmartContentDataObject.INTERNAL_SMART_CONTENT_DATAFORMAT);

                IHTMLElement element = (EditorContext.HtmlDocument as IHTMLDocument3).getElementById(smartContentElementId);
                Debug.Assert(element != null, "Invalid smart content item id detected: " + smartContentElementId);
                if (element != null)
                {
                    MarkupRange   elementRange   = EditorContext.MarkupServices.CreateMarkupRange(element, true);
                    MarkupPointer insertionPoint = begin;
                    MarkupPointerMoveHelper.PerformImageBreakout(insertionPoint);

                    insertionPoint.PushCling(false);
                    insertionPoint.PushGravity(_POINTER_GRAVITY.POINTER_GRAVITY_Left);

                    //verify the insertion point is inside of the same content editable parent (bug 290729)
                    if (!IsValidInsertionPoint(element, insertionPoint))
                    {
                        return(false);
                    }

                    try
                    {
                        if (InlineEditField.IsEditField(insertionPoint.CurrentScope))
                        {
                            // If we are in an edit field, since we strip the content wdown to plain text we have to use
                            // InsertHtml.  However, this means we need to move the content via a string.  This sucks because
                            // we break any markup ranges in that area.  This is why ignore once will not work in edit fields.
                            EditorContext.MarkupServices.Remove(begin, end);
                            string html = elementRange.HtmlText;
                            EditorContext.MarkupServices.Remove(elementRange.Start, elementRange.End);
                            EditorContext.InsertHtml(insertionPoint, insertionPoint, html, null);
                        }
                        else
                        {
                            EditorContext.MarkupServices.Remove(begin, end);
                            EditorContext.MarkupServices.Move(elementRange.Start, elementRange.End, insertionPoint);
                        }
                        return(true);
                    }
                    finally
                    {
                        insertionPoint.PopCling();
                        insertionPoint.PopGravity();
                    }
                }
            }
            return(false);
        }
Exemple #5
0
        public override void UpdateView(object htmlSelection, bool force)
        {
            if (htmlSelection == null) //true when the a non-smartcontent element is selected
            {
                //reset the selected smart content (fixes bug 492456)
                _selectedElement        = null;
                _selectedSmartContentId = null;
                UnloadCurrentEditor();
                return;
            }

            Debug.Assert(htmlSelection is SmartContentSelection || (htmlSelection is IHtmlEditorSelection && InlineEditField.IsEditField(htmlSelection)));


            IHTMLElement          selectedElement       = null;
            SmartContentSelection smartContentSelection = htmlSelection as SmartContentSelection;

            if (smartContentSelection != null && smartContentSelection.ContentState == SmartContentState.Enabled)
            {
                selectedElement = smartContentSelection.HTMLElement;
            }
            else if (htmlSelection is IHtmlEditorSelection)
            {
                selectedElement = ContentSourceManager.GetContainingSmartContent(
                    ((IHtmlEditorSelection)(htmlSelection)).SelectedMarkupRange.ParentElement());
            }


            _currentSelection = htmlSelection;
            if (selectedElement != null)
            {
                //if the selected element id is still the same, then the sidebar is currently
                //in synch with the smart content.
                //Note: the element id will change each time an edit is made to the smart content
                if (!force && _selectedElement != null && _selectedSmartContentId != null && selectedElement.id == _selectedSmartContentId)
                {
                    return;
                }
                else
                {
                    _selectedElement        = selectedElement;
                    _selectedSmartContentId = selectedElement.id;

                    if (_currentEditor != null)
                    {
                        UnloadCurrentEditor();
                    }
                }

                ContentSourceManager.ParseContainingElementId(_selectedElement.id, out _contentSourceId, out _contentItemId);

                SmartContentEditor editor        = (SmartContentEditor)_contentSourceControls[_contentSourceId];
                ContentSourceInfo  contentSource = _contentSourceContext.FindContentSource(_contentSourceId);
                if (contentSource != null && contentSource.Instance is SmartContentSource)
                {
                    _contentSource = (SmartContentSource)contentSource.Instance;

                    if (_editableSmartContent != null)
                    {
                        _editableSmartContent.Dispose();
                    }
                    _editableSmartContent = new EditableSmartContent(_contentSourceContext, _contentSource, _selectedElement);

                    if (editor == null)
                    {
                        editor = _contentSource.CreateEditor(this);

                        if (editor is IActiveSmartContentEditor)
                        {
                            ((IActiveSmartContentEditor)editor).ForceContentEdited += new EventHandler(ContentSourceSidebarControl_ForceContentEdited);
                        }

                        //apply the current scale the new control
                        if (editor != null)
                        {
                            editor.Scale(new SizeF(scale.Width, scale.Height));
                        }
                        _contentSourceControls[_contentSourceId] = editor;
                    }

                    if (editor != null)
                    {
                        editor.ContentEdited  += new EventHandler(_editor_ContentEdited);
                        editor.SelectedContent = _editableSmartContent;

                        EnableableSmartContentEditor enableableSmartContentEditor = editor as EnableableSmartContentEditor;
                        if (enableableSmartContentEditor != null)
                        {
                            enableableSmartContentEditor.ContentEnabled = true;
                        }

                        if (editor != _currentEditor)
                        {
                            if (enableableSmartContentEditor != null)
                            {
                                Controls.Clear();
                            }
                            else
                            {
                                //load the new editor
                                editor.Dock  = DockStyle.Fill;
                                editor.Width = Width - DockPadding.Left - DockPadding.Right;
                                this.Controls.Add(editor);
                            }

                            // set the title caption
                            // Text = String.Format( CultureInfo.CurrentCulture, Res.Get(StringId.PluginSidebarTitle), contentSource.InsertableContentSourceSidebarText ) ;
                        }
                    }
                }
                _currentEditor = editor;
            }
            else
            {
                _currentEditor = null;
            }
        }
Exemple #6
0
 public bool AppliesToSelection(object selection)
 {
     if (selection is SmartContentSelection || (selection is IHtmlEditorSelection && InlineEditField.IsEditField(selection)))
     {
         SmartContentSelection smartContentSelection = selection as SmartContentSelection;
         if (smartContentSelection != null && smartContentSelection.ContentState == SmartContentState.Preserve)
         {
             return(false);
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }