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 SmartContentEditor GetSmartContentEditor(string contentSourceId) { SmartContentEditor smartContentEditor = _contentSourceControls[contentSourceId] as SmartContentEditor; if (smartContentEditor == null) { smartContentEditor = CreateSmartContentEditor(contentSourceId); } return(smartContentEditor); }
/// <summary> /// This writes into the currentEditor's SelectedContent properties. /// Be sure that only the edit field associated with the *selected* content gets persisted there. /// </summary> public void PersistFieldValueToContent(bool persistToEditorContent) { SmartContentEditor currentEditor = ((IBlogPostHtmlEditor)_editorContext).CurrentEditor; if (currentEditor == null || currentEditor.SelectedContent == null || IsDefaultText) { return; } string propertyPath = PropertyPath; IProperties sidebarProperties = currentEditor.SelectedContent.Properties; IProperties smartContentProperties = _smartContent.Properties; string[] pathElements = (PropertyPath ?? "").Split('\\'); for (int i = 0; i < pathElements.Length; i++) { if (string.IsNullOrEmpty(pathElements[i])) { Trace.Fail("Failed to sync to malformed property path " + propertyPath); return; } if (i == pathElements.Length - 1) { if (persistToEditorContent) { // Save to smart content in sidebar contextual editor sidebarProperties[pathElements[i]] = TextValue; sidebarProperties.SetString("wlPropertyPath", pathElements[i]); } // Save to smart content in canvas smartContentProperties[pathElements[i]] = TextValue; smartContentProperties.SetString("wlPropertyPath", pathElements[i]); return; } else { sidebarProperties = sidebarProperties.GetSubProperties(pathElements[i]); smartContentProperties = smartContentProperties.GetSubProperties(pathElements[i]); } } }
/// <summary> /// Unloads the current editor. /// </summary> private void UnloadCurrentEditor() { if (_currentEditor != null) { //unload the current editor. _currentEditor.ContentEdited -= new EventHandler(_editor_ContentEdited); EnableableSmartContentEditor contentContext = _currentEditor as EnableableSmartContentEditor; if (contentContext != null) { contentContext.UnloadEditor(); } _currentEditor = null; //TODO: does this clear cause the current editor to be disposed? We don't want it to be. Controls.Clear(); _sidebarContext.UpdateStatusBar(String.Empty); } }
public InternalSmartContentContext(IInternalSmartContentContextSource contextSource, string contentSourceId) { _contextSource = contextSource; _smartContentEditor = contextSource.GetSmartContentEditor(contentSourceId); }
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; } }