private SmartContentEditor CreateSmartContentEditor(string contentSourceId) { Debug.Assert(!_contentSourceControls.Contains(contentSourceId)); SmartContentEditor smartContentEditor = null; ContentSourceInfo contentSource = _contentSourceContext.FindContentSource(contentSourceId); if (contentSource != null && contentSource.Instance is SmartContentSource) { _contentSource = (SmartContentSource)contentSource.Instance; smartContentEditor = _contentSource.CreateEditor(this); _contentSourceControls[contentSourceId] = smartContentEditor; if (smartContentEditor is IActiveSmartContentEditor) { ((IActiveSmartContentEditor)smartContentEditor).ForceContentEdited += new EventHandler(ContentSourceSidebarControl_ForceContentEdited); } //apply the current scale the new control if (smartContentEditor != null) { smartContentEditor.Scale(new SizeF(scale.Width, scale.Height)); } } else { Trace.Fail("Incorrectly calling GetSmartContentEditor for a source that is not a SmartContentSource."); } return(smartContentEditor); }
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; } }