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 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); }
private void buttonOptions_Click(object sender, System.EventArgs e) { ContentSourceInfo selectedContentSource = GetSelectedPlugin(); if (selectedContentSource != null) { if (selectedContentSource.WriterPluginHasEditableOptions) { try { selectedContentSource.Instance.EditOptions(FindForm()); } catch (NotImplementedException ex) { ContentSourceManager.DisplayContentRetreivalError(FindForm(), ex, selectedContentSource); } catch (Exception exception) { Trace.Fail(exception.ToString()); DisplayableException dex = new DisplayableException( Res.Get(StringId.UnexpectedErrorPluginTitle), string.Format(CultureInfo.CurrentCulture, Res.Get(StringId.UnexpectedErrorPluginDescription), selectedContentSource.Name, exception.Message)); DisplayableExceptionDisplayForm.Show(FindForm(), dex); } } } }
public static ContentSourceInfo FindContentSourceForLiveClipboardFormat(LiveClipboardFormat format) { // see if the preferred content source is noted in the registry string contentSourceId = GetContentSourceIdForFormat(format); if (contentSourceId != null) { // if the content-source is still installed and active then return it ContentSourceInfo contentSourceInfo = ContentSourceManager.FindContentSource(contentSourceId); if (contentSourceInfo != null) { return(contentSourceInfo); } } // didn't find a valid preconfigured entry, scan all sources to see if we've got one foreach (ContentSourceInfo contentSourceInfo in ContentSourceManager.ActiveContentSources) { foreach (LiveClipboardFormatHandler csFormatHandler in contentSourceInfo.LiveClipboardFormatHandlers) { if (csFormatHandler.Format.Equals(format)) { // note that this is now our default SetContentSourceForFormat(format, contentSourceInfo.Id); // return the source return(contentSourceInfo); } } } // no match found return(null); }
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 void RefreshListViewItem(ListViewItem listViewItem) { ContentSourceInfo itemContentSource = listViewItem.Tag as ContentSourceInfo; listViewItem.SubItems.Clear(); listViewItem.Text = " " + itemContentSource.Name; listViewItem.SubItems.Add(new ListViewItem.ListViewSubItem(listViewItem, _pluginsPreferences.GetPluginEnabledState(itemContentSource) ? Res.Get(StringId.Enabled) : Res.Get(StringId.Disabled))); }
protected override void SavePreferences() { foreach (DictionaryEntry entry in _enabledStateChanges) { ContentSourceInfo contentSourceInfo = entry.Key as ContentSourceInfo; contentSourceInfo.Enabled = (bool)entry.Value; } _enabledStateChanges.Clear(); }
public bool GetPluginEnabledState(ContentSourceInfo contentSourceInfo) { if (_enabledStateChanges.Contains(contentSourceInfo)) { return((bool)_enabledStateChanges[contentSourceInfo]); } else { return(contentSourceInfo.Enabled); } }
public LiveClipboardFormatHandler(LiveClipboardContentSourceAttribute lcAttribute, ContentSourceInfo contentSource) { ResourceManager resMan = new ResourceManager(contentSource.GetType()); string resourceNamePrefix = "LiveClipboardContentSource." + lcAttribute.Name + "."; _format = new LiveClipboardFormat(lcAttribute.ContentType, lcAttribute.Type); _formatName = LoadResourcedString(resMan, resourceNamePrefix + "Name", lcAttribute.Name); _formatDescription = LoadResourcedString(resMan, resourceNamePrefix + "Description", lcAttribute.Description); _formatImagePath = lcAttribute.ImagePath; _contentSource = contentSource; }
protected override bool DoInsertData(DataAction action, MarkupPointer begin, MarkupPointer end) { // get the live clipboard data LiveClipboardData lcData = DataMeister.LiveClipboardData; if (lcData == null) { Trace.Fail("Unexpected failure to get LC data!"); return(false); } // lookup the content-source ContentSourceInfo contentSource = LiveClipboardManager.FindContentSourceForLiveClipboard(lcData.Formats); if (contentSource == null) { Trace.Fail("Unexpected failure to find content soure!"); return(false); } using (new WaitCursor()) { try { // HACK: drive the selection textRange to the caret so we can call generic // content-source routines that work off the current selection // Note that we do the same thing below for Images so we can use the common // InsertImages method -- we may want to bake this into core marshalling // or add MarkupRange parameters to the image and content-source routines EditorContext.MarkupServices.CreateMarkupRange(begin, end).ToTextRange().select(); if (contentSource.Instance is SmartContentSource) { return(InsertSmartContentFromLiveClipboard(contentSource, lcData.Document)); } else if (contentSource.Instance is ContentSource) { return(InsertSimpleContentFromLiveClipboard(contentSource, lcData.Document)); } else { Debug.Fail("Unexpected content source type: " + contentSource.GetType()); return(false); } } catch (Exception ex) { ContentSourceManager.DisplayContentRetreivalError(EditorContext.FrameWindow, ex, contentSource); return(false); } } }
private void linkLabelPluginName_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { ContentSourceInfo selectedContentSource = GetSelectedPlugin(); if (selectedContentSource != null) { if (selectedContentSource.WriterPluginPublisherUrl != String.Empty) { ShellHelper.LaunchUrl(selectedContentSource.WriterPluginPublisherUrl); } } }
private void radioButtonEnablePlugin_CheckedChanged(object sender, EventArgs e) { ContentSourceInfo selectedContentSource = GetSelectedPlugin(); if (selectedContentSource != null) { // if our underlying state has changed then update underlying prefs if (_pluginsPreferences.GetPluginEnabledState(selectedContentSource) != radioButtonEnablePlugin.Checked) { _pluginsPreferences.SetPluginEnabledState(selectedContentSource, radioButtonEnablePlugin.Checked); RefreshSelectedListViewItem(); } } }
public override void Save() { BlogPublishingPluginSettings settings = TemporaryBlogSettings.PublishingPluginSettings; settings.ClearOrder(); int i = 0; foreach (ListViewItem lvi in listViewPlugins.Items) { ContentSourceInfo csi = (ContentSourceInfo)lvi.Tag; settings.Set(csi.Id, lvi.Checked, i++); } base.Save(); }
public LiveClipboardComponentDisplay(ContentSourceInfo contentSource) { // if this format handler is "built-in" then override the content-source to // list it as "windows-live writer" if (ContentSourceManager.ContentSourceIsPlugin(contentSource.Id)) { _icon = contentSource.Image; _name = contentSource.Name; } else { _icon = _writerLogoBitmap; _name = ApplicationEnvironment.ProductName; } }
private bool InsertSimpleContentFromUrl(ContentSourceInfo contentSource, string url) { string title = String.Empty; string content = String.Empty; if (UrlContentRetreivalWithProgress.ExecuteSimpleContentRetreival( EditorContext.FrameWindow, contentSource, url, ref title, ref content)) { _contentSourceSite.InsertContent(content, false); return(true); } else { return(false); } }
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 static ContentSourceInfo FindContentSourceForLiveClipboard(LiveClipboardFormat[] formats) { // formats are supposed to be arranged in order of richness/desirability, // iterate through the formats in this order searching for a content-source // that can handle them foreach (LiveClipboardFormat format in formats) { ContentSourceInfo contentSource = FindContentSourceForLiveClipboardFormat(format); if (contentSource != null) { return(contentSource); } } // didn't find a match return(null); }
public static bool ExecuteSimpleContentRetreival( IWin32Window dialogOwner, ContentSourceInfo contentSourceInfo, string url, ref string title, ref string newContent) { try { // if there is progress requested then just do it on the main UI thread if (contentSourceInfo.UrlContentSourceRequiresProgress) { // create the progress dialog and the async operation UrlContentRetreivalWithProgressDialog progressDialog = new UrlContentRetreivalWithProgressDialog(contentSourceInfo); progressDialog.CreateControl(); SimpleUrlContentRetreivalAsyncOperation asyncOperation = new SimpleUrlContentRetreivalAsyncOperation(progressDialog, contentSourceInfo.Instance as ContentSource, url, title); // execute and retrieve results if (ExecuteWithProgress(dialogOwner, progressDialog, asyncOperation, contentSourceInfo)) { title = asyncOperation.Title; newContent = asyncOperation.NewContent; return(true); } else { return(false); } } else { try { (contentSourceInfo.Instance as ContentSource).CreateContentFromUrl(url, ref title, ref newContent); return(true); } catch (Exception ex) { ContentSourceManager.DisplayContentRetreivalError(dialogOwner, ex, contentSourceInfo); return(false); } } } catch (Exception ex) { Trace.Fail("Unexpected exception executing network operation for content source: " + ex.ToString()); return(false); } }
protected override bool DoInsertData(DataAction action, MarkupPointer begin, MarkupPointer end) { // lookup the content-source ContentSourceInfo contentSource = ContentSourceManager.FindContentSourceForUrl(Url); if (contentSource != null) { // HACK: drive the selection textRange to the caret so we can call generic // content-source routines that work off the current selection // Note that we do the same thing below for Images so we can use the common // InsertImages method -- we may want to bake this into core marshalling // or add MarkupRange parameters to the image and content-source routines EditorContext.MarkupServices.CreateMarkupRange(begin, end).ToTextRange().select(); try { if (contentSource.Instance is SmartContentSource) { return(InsertSmartContentFromUrl(contentSource, Url)); } else if (contentSource.Instance is ContentSource) { return(InsertSimpleContentFromUrl(contentSource, Url)); } else { Debug.Fail("Unexpected content source type: " + contentSource.GetType()); return(false); } } catch (Exception ex) { Trace.Fail("Unexpected exception inserting content: " + ex.ToString()); return(false); } } else { Debug.Fail("No content source found during marshalling!"); return(false); } }
public UrlContentRetreivalWithProgressDialog(ContentSourceInfo contentSourceInfo) { // // Required for Windows Form Designer support // InitializeComponent(); this.buttonCancel.Text = Res.Get(StringId.CancelButton); this.labelCaption.Font = Res.GetFont(FontSize.Normal, FontStyle.Bold); // initialize text Text = contentSourceInfo.Name; labelCaption.Text = contentSourceInfo.UrlContentSourceProgressCaption != String.Empty ? contentSourceInfo.UrlContentSourceProgressCaption : Res.Get(StringId.UrlRetrieveProgressCaption); labelDetails.Text = contentSourceInfo.UrlContentSourceProgressMessage != String.Empty ? contentSourceInfo.UrlContentSourceProgressMessage : Res.Get(StringId.UrlRetrieveProgressMessage); // initialize animated bitmap _animatedBitmapControl.Bitmaps = AnimationBitmaps; _animatedBitmapControl.Interval = 75; Icon = ApplicationEnvironment.ProductIcon; }
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); } }
private void UpdateDetailsPane() { ContentSourceInfo selectedContentSource = GetSelectedPlugin(); if (selectedContentSource != null) { panelPluginDetails.Visible = true; labelNoPluginSelected.Visible = false; pictureBoxPluginImage.Image = selectedContentSource.Image; linkLabelPluginName.Text = selectedContentSource.Name; labelPluginDescription.Text = selectedContentSource.WriterPluginDescription; radioButtonEnablePlugin.Checked = selectedContentSource.Enabled; radioButtonDisablePlugin.Checked = !selectedContentSource.Enabled; buttonOptions.Visible = selectedContentSource.WriterPluginHasEditableOptions; } else { labelNoPluginSelected.Visible = true; panelPluginDetails.Visible = false; } }
private bool InsertSimpleContentFromLiveClipboard(ContentSourceInfo contentSource, XmlDocument lcDocument) { ContentSource lcContentSource = contentSource.Instance as ContentSource; if (lcContentSource == null) { Trace.Fail("Unexpected failure to get live clipboard content-source!"); return(false); } // create the content string content = String.Empty; if (lcContentSource.CreateContentFromLiveClipboard(EditorContext.FrameWindow, lcDocument, ref content) == DialogResult.OK) { _contentSourceSite.InsertContent(content, false); return(true); } else { return(false); } }
private static bool ExecuteWithProgress( IWin32Window dialogOwner, UrlContentRetreivalWithProgressDialog progressDialog, UrlContentRetreivalAsyncOperation asyncOperation, ContentSourceInfo contentSourceInfo) { try { // show the progress dialog using (progressDialog) { asyncOperation.Start(); progressDialog.ShowProgress(dialogOwner, asyncOperation); } // handle the result if (asyncOperation.Error != null) { ContentSourceManager.DisplayContentRetreivalError(dialogOwner, asyncOperation.Error, contentSourceInfo); return(false); } else if (asyncOperation.WasCancelled) { return(false); } else { return(true); } } catch (Exception ex) { Trace.Fail("Unexpected exception executing network operation for content source: " + ex.ToString()); return(false); } }
/// <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()); }
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; } }
public void SetPluginEnabledState(ContentSourceInfo contentSourceInfo, bool enabled) { _enabledStateChanges[contentSourceInfo] = enabled; Modified(); }