private bool InsertSmartContentFromLiveClipboard(ContentSourceInfo contentSource, XmlDocument lcDocument) { SmartContentSource smartSource = contentSource.Instance as SmartContentSource; if (smartSource == null) { Trace.Fail("Unexpected failure to get live clipboard content-source!"); return(false); } // create the smart content IExtensionData extensionData = _contentSourceSite.CreateExtensionData(Guid.NewGuid().ToString()); ISmartContent smartContent = new SmartContent(extensionData); if (smartSource.CreateContentFromLiveClipboard(EditorContext.FrameWindow, lcDocument, smartContent) == DialogResult.OK) { // generate html and insert it string content = smartSource.GenerateEditorHtml(smartContent, _contentSourceSite); if (content != null) { _contentSourceSite.InsertContent(contentSource.Id, content, extensionData); return(true); } else { return(false); } } else { return(false); } }
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); }
private bool InsertSmartContentFromEmbed(string embed) { ContentSourceInfo contentSource = ContentSourceManager.FindContentSource(typeof(VideoContentSource)); if (contentSource != null) { SmartContentSource smartSource = contentSource.Instance as SmartContentSource; VideoContentSource videoSource = smartSource as VideoContentSource; IExtensionData extensionData = _contentSourceSite.CreateExtensionData(Guid.NewGuid().ToString()); ISmartContent smartContent = new SmartContent(extensionData); videoSource.CreateContentFromEmbed(embed, smartContent); // generate html and insert it string content = videoSource.GenerateEditorHtml(smartContent, _contentSourceSite); if (content != null) { _contentSourceSite.InsertContent(VideoContentSource.ID, content, extensionData); return(true); } else { Trace.Fail("Video Source content generated from embed tag was empty"); return(false); } } Trace.Fail("Cannot find the video plugin"); return(false); }
internal static void PlainTextTransform(IPublishingContext site, SmartContentSource source, ISmartContent sContent, ref string content) { if (source is IInternalSmartContentSource) { try { content = ((IInternalSmartContentSource)source).GeneratePlainTextHtml(sContent, site); } catch (Exception ex) { Trace.WriteLine("Content Source failed to generate plain text html: " + ex); Trace.Flush(); throw; } } }
protected override void OnElementAttached() { SmartContent content = SmartContent; if (content == null) { return; } ContentSourceInfo contentSourceInfo = _contentSourceContext.FindContentSource(ContentSourceId); _contentSource = contentSourceInfo.Instance as SmartContentSource; if (_contentSource != null && _contentSource.ResizeCapabilities != ResizeCapabilities.None) { Resizable = true; PreserveAspectRatio = ResizeCapabilities.PreserveAspectRatio == (_contentSource.ResizeCapabilities & ResizeCapabilities.PreserveAspectRatio); _realtimeResizing = ResizeCapabilities.LiveResize == (_contentSource.ResizeCapabilities & ResizeCapabilities.LiveResize); } else { Resizable = false; } EditorContext.CommandKey += new KeyEventHandler(EditorContext_CommandKey); EditorContext.DocumentEvents.DoubleClick += new HtmlEventHandler(EditorContext_DoubleClick); EditorContext.SelectionChanged += new EventHandler(EditorContext_SelectionChanged); EditorContext.PostEventNotify += new MshtmlEditor.EditDesignerEventHandler(EditorContext_PostEventNotify); EditorContext.CommandManager.BeforeExecute += new CommandManagerExecuteEventHandler(CommandManager_BeforeExecute); EditorContext.CommandManager.AfterExecute += new CommandManagerExecuteEventHandler(CommandManager_AfterExecute); EditorContext.HtmlInserted += new EventHandler(EditorContext_HtmlInserted); base.OnElementAttached(); foreach (IHTMLElement el in EditFields) { InlineEditField field = new InlineEditField(el, content, EditorContext, HTMLElement, this); if (!field.ContentEditable && EditorContext.EditMode) { field.ContentEditable = true; } field.SetDefaultText(); } }
public EditableSmartContent(IContentSourceSidebarContext context, SmartContentSource contentSource, IHTMLElement smartContentElement) { GC.SuppressFinalize(this); _contentSourceContext = context; _contentSource = contentSource; _smartContentElement = smartContentElement; ContentSourceManager.ParseContainingElementId(_smartContentElement.id, out _contentSourceId, out _smartContentId); _smartContent = _contentSourceContext.FindSmartContent(_smartContentId); _extensionData = _contentSourceContext.FindExtentsionData(_smartContentId); _properties = new EditableRootProperties(); _layout = new EditableLayoutStyle(); _supportingFiles = new EditableSupportingFiles(); MakeSmartContentEditable(); }
private bool InsertSmartContentFromUrl(ContentSourceInfo contentSource, string url) { SmartContentSource smartSource = contentSource.Instance as SmartContentSource; string title = String.Empty; IExtensionData extensionData = _contentSourceSite.CreateExtensionData(Guid.NewGuid().ToString()); ISmartContent smartContent = new SmartContent(extensionData); if (UrlContentRetreivalWithProgress.ExecuteSmartContentRetreival( EditorContext.FrameWindow, contentSource, url, ref title, smartContent)) { string content = smartSource.GenerateEditorHtml(smartContent, _contentSourceSite); if (content != null) { _contentSourceSite.InsertContent(contentSource.Id, content, extensionData); } return(true); } else { return(false); } }
public static void InsertEditorHtmlIntoElement(IContentSourceSidebarContext contentSourceContext, SmartContentSource source, ISmartContent sContent, IHTMLElement element) { string content = source.GenerateEditorHtml(sContent, contentSourceContext); // If the plugin returned null has the HTML it would like to insert, remove the element from the editor if (content == null) { HTMLElementHelper.RemoveElement(element); } else { InsertContentIntoElement(content, sContent, contentSourceContext, element); } }
public SmartUrlContentRetreivalAsyncOperation( ISynchronizeInvoke invokeTarget, SmartContentSource contentSource, string url, string title, ISmartContent newContent) : base(invokeTarget, contentSource, url, title) { _newContent = newContent; }
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; } }
/// <summary> /// Walks the current contents to find smart content areas. When one is found, it calls the operation on the smart content. The operation has a chance /// to return new content. If the content is non-null it will replace the current content. /// </summary> /// <param name="contents">the raw HTML string whose structured blocks will be replaced.</param> /// <param name="operation">Delegate for generating replacement content.</param> /// <param name="editMode">If true, then the element's stylename will be activated for editing</param> /// <param name="continueOnError"> /// true - if the plugin throws an exception, it keeps crawling the DOM /// false - if a plugin throws an exception, it stops processing the DOM and return empty string /// null - if a plugin throws an exception, this function will rethrow it /// </param /// <returns>the contents with structured blocks replaced.</returns> internal static string PerformOperation(string contents, SmartContentOperation operation, bool editMode, IContentSourceSidebarContext sourceContext, bool?continueOnError) { //replace all structured content blocks with their editor HTML //string html = PostBodyPreprocessor.Preprocess(contents); StringBuilder sb = new StringBuilder(); SimpleHtmlParser parser = new SimpleHtmlParser(contents); for (Element e = parser.Next(); e != null; e = parser.Next()) { if (e is BeginTag) { BeginTag beginTag = (BeginTag)e; string elementClassName = beginTag.GetAttributeValue("class"); if (ContentSourceManager.IsSmartContentClass(elementClassName)) { ISmartContent sContent = null; try { string contentSourceId, contentItemId; string blockId = beginTag.GetAttributeValue("id"); if (blockId != null) { ContentSourceManager.ParseContainingElementId(blockId, out contentSourceId, out contentItemId); ContentSourceInfo contentSource = sourceContext.FindContentSource(contentSourceId); if (contentSource != null && contentSource.Instance is SmartContentSource) { SmartContentSource sSource = (SmartContentSource)contentSource.Instance; sContent = sourceContext.FindSmartContent(contentItemId); if (sContent != null) { //write the div with the appropriate className string newClassName = editMode ? ContentSourceManager.EDITABLE_SMART_CONTENT : ContentSourceManager.SMART_CONTENT; beginTag.GetAttribute("class").Value = newClassName; //replace the inner HTML of the div with the source's editor HTML string content = parser.CollectHtmlUntil("div"); sb.Append(e.ToString()); operation(sourceContext, sSource, sContent, ref content); sb.Append(content); sb.Append("</div>"); continue; } } } } catch (Exception ex) { Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, "Error loading smart content item\r\n{0}", ex)); sContent = null; if (continueOnError == null) { throw; } if (!continueOnError.Value) { return(String.Empty); } } if (sContent == null) { //this element references an unknown smart content, so it should not be editable Attr classAttr = beginTag.GetAttribute("class"); classAttr.Value = ContentSourceManager.SMART_CONTENT; } } } sb.Append(e.ToString()); } return(sb.ToString()); }