public SmartContentElementBehavior(IHtmlEditorComponentContext editorContext, IBlogPostSidebarContext sidebarContext, IContentSourceSidebarContext contentSourceContext, SmartContentResizedListener resizedListener) : base(editorContext) { _editorContext = editorContext; _sidebarContext = sidebarContext; _contentSourceContext = contentSourceContext; _resizedListener = resizedListener; }
public DisabledSmartContentElementBehavior(IHtmlEditorComponentContext editorContext, IContentSourceSidebarContext contentSourceContext) : base(editorContext) { _focusControl = new FocusControl(this); _focusControl.Visible = false; _contentSourceContext = contentSourceContext; Controls.Add(_focusControl); _dragDropController = new SmartContentDragAndDropSource(editorContext); }
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 ContentSourceSidebarControl(ISidebarContext sidebarContext, IContentSourceSidebarContext sourceContext) { /// /// Required for Windows.Forms Class Composition Designer support /// InitializeComponent(); _contentSourceControls = new Hashtable(); _sidebarContext = sidebarContext; _contentSourceContext = sourceContext; _contentSourceContext.ContentResized += new ContentResizedEventHandler(_contentSourceContext_ContentResized); }
/// <summary> /// Clones active smart content contained in the provided HTML, and disables unknown smart content. /// </summary> public static string PrepareSmartContentHtmlForEditorInsertion(string html, IContentSourceSidebarContext sourceContext) { StringBuilder output = new StringBuilder(); ContentSourceManager.SmartContentPredicate predicate = new ContentSourceManager.SmartContentPredicate(); SimpleHtmlParser p = new SimpleHtmlParser(html); for (Element el; null != (el = p.Next());) { if (predicate.IsMatch(el)) { BeginTag bt = el as BeginTag; Attr idAttr = bt.GetAttribute("id"); String contentSourceId, contentItemId; ContentSourceManager.ParseContainingElementId(idAttr.Value, out contentSourceId, out contentItemId); ISmartContent smartContent = sourceContext.FindSmartContent(contentItemId); if (smartContent != null) { String newId = Guid.NewGuid().ToString(); sourceContext.CloneSmartContent(contentItemId, newId); if (RefreshableContentManager.ContentSourcesWithRefreshableContent.Contains(contentSourceId)) { IExtensionData extensionData = sourceContext.FindExtentsionData(newId); Debug.Assert(extensionData != null); // Since we just made a new id for the smart content just about to be inserted // we want to give it a chance to get a callback because its callback might have happened while // it was on the clipboard(in the event of cut). This means the refreshable content manager doesnt know // to watch out for this smart content on paste, it only knows to look out for who created it. Thus // we just force the callback, and if it didnt need it, nothing will happen. if (extensionData.RefreshCallBack == null) { extensionData.RefreshCallBack = DateTime.UtcNow; } } idAttr.Value = ContentSourceManager.MakeContainingElementId(contentSourceId, newId); } else { ContentSourceManager.RemoveSmartContentAttributes(bt); } } output.Append(el.ToString()); } return(output.ToString()); }
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); } }
/// <summary> /// Clones active smart content contained in the provided HTML, and disables unknown smart content. /// </summary> public static string PrepareSmartContentHtmlForEditorInsertion(string html, IContentSourceSidebarContext sourceContext) { StringBuilder output = new StringBuilder(); ContentSourceManager.SmartContentPredicate predicate = new ContentSourceManager.SmartContentPredicate(); SimpleHtmlParser p = new SimpleHtmlParser(html); for (Element el; null != (el = p.Next());) { if (predicate.IsMatch(el)) { BeginTag bt = el as BeginTag; Attr idAttr = bt.GetAttribute("id"); String contentSourceId, contentItemId; ContentSourceManager.ParseContainingElementId(idAttr.Value, out contentSourceId, out contentItemId); ISmartContent smartContent = sourceContext.FindSmartContent(contentItemId); if (smartContent != null) { String newId = Guid.NewGuid().ToString(); sourceContext.CloneSmartContent(contentItemId, newId); if (RefreshableContentManager.ContentSourcesWithRefreshableContent.Contains(contentSourceId)) { IExtensionData extensionData = sourceContext.FindExtentsionData(newId); Debug.Assert(extensionData != null); // Since we just made a new id for the smart content just about to be inserted // we want to give it a chance to get a callback because its callback might have happened while // it was on the clipboard(in the event of cut). This means the refreshable content manager doesnt know // to watch out for this smart content on paste, it only knows to look out for who created it. Thus // we just force the callback, and if it didnt need it, nothing will happen. if (extensionData.RefreshCallBack == null) { extensionData.RefreshCallBack = DateTime.UtcNow; } } idAttr.Value = ContentSourceManager.MakeContainingElementId(contentSourceId, newId); } else { ContentSourceManager.RemoveSmartContentAttributes(bt); } } output.Append(el.ToString()); } return output.ToString(); }
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(); }
//ToDo: OLW Spell Checker //public BlogPostHtmlEditorControl(IMainFrameWindow mainFrameWindow, IStatusBar statusBar, MshtmlOptions options, IBlogPostImageEditingContext imageEditingContext, IBlogPostSidebarContext sidebarContext, IContentSourceSidebarContext sourceContext, SmartContentResizedListener resizedListener, IBlogPostSpellCheckingContext spellingContext, IImageReferenceFixer referenceFixer, IInternetSecurityManager internetSecurityManager, CommandManager commandManager, TemplateStrategy strategy, IEditingMode editingModeContext) : base(mainFrameWindow, statusBar, options, internetSecurityManager, commandManager) public BlogPostHtmlEditorControl(IMainFrameWindow mainFrameWindow, IStatusBar statusBar, MshtmlOptions options, IBlogPostImageEditingContext imageEditingContext, IBlogPostSidebarContext sidebarContext, IContentSourceSidebarContext sourceContext, SmartContentResizedListener resizedListener, IImageReferenceFixer referenceFixer, IInternetSecurityManager internetSecurityManager, CommandManager commandManager, TemplateStrategy strategy, IEditingMode editingModeContext) : base(mainFrameWindow, statusBar, options, internetSecurityManager, commandManager) { _strategy = strategy; _imageEditingContext = imageEditingContext; _sidebarContext = sidebarContext; _sourceContext = sourceContext; _resizedListener = resizedListener; //ToDo: OLW Spell Checker //_spellingContext = spellingContext; //_spellingManager = new SpellingManager(CommandManager); _keyBoardHandler = new PostEditorKeyboardHandler(this, imageEditingContext, editingModeContext); _referenceFixer = referenceFixer; InitializeTableEditingManager(); InitializeElementBehaviors(); SelectionChanged += BlogPostHtmlEditorControl_SelectionChanged; KeyPress += new HtmlEventHandler(BlogPostHtmlEditorControl_KeyPress); }
internal BrokenContentSourceSidebar(IContentSourceSidebarContext context) { _context = context; }
/// <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(); }
internal DisabledContentSourceSidebar(IContentSourceSidebarContext context) { _context = context; }
public HtmlDocument2Wrapper(IHTMLDocument2 doc2, IContentSourceSidebarContext contentSourceSidebarContext) { _innerDoc2 = doc2; _contentSourceSidebarContext = contentSourceSidebarContext; }
public static void InsertContentIntoElement(string content, ISmartContent sContent, IContentSourceSidebarContext contentSourceContext, IHTMLElement element) { MshtmlMarkupServices MarkupServices = new MshtmlMarkupServices((IMarkupServicesRaw)element.document); //Note: undo/redo disabled for smart content since undo causes the HTML to get out of sync //with the inserter's settings state, so undo changes will be blown away the next time the //the inserter's HTML is regenerated. Also note that making this insertion without wrapping it //in an undo clears the undo/redo stack, which is what we want for beta. //string undoId = Guid.NewGuid().ToString(); MarkupRange htmlRange = MarkupServices.CreateMarkupRange(element, false); htmlRange.Start.PushCling(true); htmlRange.End.PushCling(true); MarkupServices.Remove(htmlRange.Start, htmlRange.End); htmlRange.Start.PopCling(); htmlRange.End.PopCling(); element.style.padding = ToPaddingString(sContent.Layout); if (sContent.Layout.Alignment == Alignment.None || sContent.Layout.Alignment == Alignment.Right || sContent.Layout.Alignment == Alignment.Left) { element.style.display = "inline"; element.style.marginLeft = "0px"; element.style.marginRight = "0px"; element.style.styleFloat = sContent.Layout.Alignment.ToString().ToLower(CultureInfo.InvariantCulture); } else if (sContent.Layout.Alignment == Alignment.Center) { element.style.styleFloat = Alignment.None.ToString().ToLower(CultureInfo.InvariantCulture); element.style.display = "block"; element.style.marginLeft = "auto"; element.style.marginRight = "auto"; } // Clear out any width on the overall smart content block, if the element is centered, we will add the width back in later // after we calcuate it from the childern, the current width value is stale. element.style.width = ""; //Note: we use MarkupServices to insert the content so that IE doesn't try to fix up URLs. //Element.insertAdjacentHTML() is a no-no because it rewrites relaive URLs to include //the fullpath from the local filesytem. //MarkupServices.ParseString() doesn't attempt to fix up URLs, so its safe to use. //We will now stage the new content into a MarkupContainer, and then move it into //the working document. MarkupPointer sc1 = MarkupServices.CreateMarkupPointer(); MarkupPointer sc2 = MarkupServices.CreateMarkupPointer(); //Create a temporary document from the html and set the start/end pointers to the //start and end of the document. MarkupServices.ParseString(content, sc1, sc2); IHTMLDocument2 doc = sc1.GetDocument(); MarkupRange stagingRange = MarkupServices.CreateMarkupRange(sc1, sc2); stagingRange.MoveToElement(doc.body, false); //IE7 hack: fixes bug 305512. Note that this will destroy the inner content of the element, //so make sure it is called before the refreshed content is inserted. BeforeInsertInvalidateHackForIE7(element); //move the content from the staging area into the actual insertion point. MarkupServices.Move(stagingRange.Start, stagingRange.End, htmlRange.End); if (sContent.Layout.Alignment == Alignment.Center) { MarkupContext mc = htmlRange.End.Right(false); MarkupRange range = MarkupServices.CreateMarkupRange(mc.Element, false); IHTMLElement[] childern = range.GetTopLevelElements(MarkupRange.FilterNone); int maxWidth = 0; foreach (IHTMLElement child in childern) maxWidth = Math.Max(maxWidth, child.offsetWidth); if (maxWidth != 0) mc.Element.style.width = maxWidth; } // Let the context provider know the smart content was edited. string contentSourceId, contentId; ContentSourceManager.ParseContainingElementId(element.id, out contentSourceId, out contentId); contentSourceContext.OnSmartContentEdited(contentId); }
public static void InsertContentIntoElement(string content, ISmartContent sContent, IContentSourceSidebarContext contentSourceContext, IHTMLElement element) { MshtmlMarkupServices MarkupServices = new MshtmlMarkupServices((IMarkupServicesRaw)element.document); //Note: undo/redo disabled for smart content since undo causes the HTML to get out of sync //with the inserter's settings state, so undo changes will be blown away the next time the //the inserter's HTML is regenerated. Also note that making this insertion without wrapping it //in an undo clears the undo/redo stack, which is what we want for beta. //string undoId = Guid.NewGuid().ToString(); MarkupRange htmlRange = MarkupServices.CreateMarkupRange(element, false); htmlRange.Start.PushCling(true); htmlRange.End.PushCling(true); MarkupServices.Remove(htmlRange.Start, htmlRange.End); htmlRange.Start.PopCling(); htmlRange.End.PopCling(); element.style.padding = ToPaddingString(sContent.Layout); if (sContent.Layout.Alignment == Alignment.None || sContent.Layout.Alignment == Alignment.Right || sContent.Layout.Alignment == Alignment.Left) { element.style.display = "inline"; element.style.marginLeft = "0px"; element.style.marginRight = "0px"; element.style.styleFloat = sContent.Layout.Alignment.ToString().ToLower(CultureInfo.InvariantCulture); } else if (sContent.Layout.Alignment == Alignment.Center) { element.style.styleFloat = Alignment.None.ToString().ToLower(CultureInfo.InvariantCulture); element.style.display = "block"; element.style.marginLeft = "auto"; element.style.marginRight = "auto"; } // Clear out any width on the overall smart content block, if the element is centered, we will add the width back in later // after we calcuate it from the childern, the current width value is stale. element.style.width = ""; //Note: we use MarkupServices to insert the content so that IE doesn't try to fix up URLs. //Element.insertAdjacentHTML() is a no-no because it rewrites relaive URLs to include //the fullpath from the local filesytem. //MarkupServices.ParseString() doesn't attempt to fix up URLs, so its safe to use. //We will now stage the new content into a MarkupContainer, and then move it into //the working document. MarkupPointer sc1 = MarkupServices.CreateMarkupPointer(); MarkupPointer sc2 = MarkupServices.CreateMarkupPointer(); //Create a temporary document from the html and set the start/end pointers to the //start and end of the document. MarkupServices.ParseString(content, sc1, sc2); IHTMLDocument2 doc = sc1.GetDocument(); MarkupRange stagingRange = MarkupServices.CreateMarkupRange(sc1, sc2); stagingRange.MoveToElement(doc.body, false); //IE7 hack: fixes bug 305512. Note that this will destroy the inner content of the element, //so make sure it is called before the refreshed content is inserted. BeforeInsertInvalidateHackForIE7(element); //move the content from the staging area into the actual insertion point. MarkupServices.Move(stagingRange.Start, stagingRange.End, htmlRange.End); if (sContent.Layout.Alignment == Alignment.Center) { MarkupContext mc = htmlRange.End.Right(false); MarkupRange range = MarkupServices.CreateMarkupRange(mc.Element, false); IHTMLElement[] childern = range.GetTopLevelElements(MarkupRange.FilterNone); int maxWidth = 0; foreach (IHTMLElement child in childern) { maxWidth = Math.Max(maxWidth, child.offsetWidth); } if (maxWidth != 0) { mc.Element.style.width = maxWidth; } } // Let the context provider know the smart content was edited. string contentSourceId, contentId; ContentSourceManager.ParseContainingElementId(element.id, out contentSourceId, out contentId); contentSourceContext.OnSmartContentEdited(contentId); }
/// <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()); }