public AutoReplaceAction(BlogPostHtmlEditorControl editor, char key, string replacement, MarkupRange range) { this.editor = editor; this.key = key; this.replacement = replacement; this.range = range; }
public void Dispose() { if (_blogPostHtmlEditorControl != null) { _blogPostHtmlEditorControl.PostEditorEvent -= _blogPostHtmlEditorControl_PostEditorEvent; _blogPostHtmlEditorControl.KeyPress -= _blogPostHtmlEditorControl_KeyPress; _blogPostHtmlEditorControl.KeyDown -= _blogPostHtmlEditorControl_KeyDown; _blogPostHtmlEditorControl.SelectionChanged -= _blogPostHtmlEditorControl_SelectionChanged; _blogPostHtmlEditorControl = null; } LastChanceKeyboardHook.BeforeKeyHandled -= _keyHandled; AutoreplaceSettings.SettingsChanged -= AutoreplaceSettings_SettingsChanged; }
public PostEditorKeyboardHandler(BlogPostHtmlEditorControl blogPostHtmlEditorControl, IBlogPostImageEditingContext imageEditingContext, IEditingMode editingModeContext) { _blogPostHtmlEditorControl = blogPostHtmlEditorControl; _blogPostHtmlEditorControl.PostEditorEvent += _blogPostHtmlEditorControl_PostEditorEvent; _blogPostHtmlEditorControl.KeyPress += _blogPostHtmlEditorControl_KeyPress; _blogPostHtmlEditorControl.KeyDown += _blogPostHtmlEditorControl_KeyDown; _blogPostHtmlEditorControl.SelectionChanged += _blogPostHtmlEditorControl_SelectionChanged; _imageEditingContext = imageEditingContext; _editingModeContext = editingModeContext; _autoreplaceManager = new AutoreplaceManager(); AutoreplaceSettings.SettingsChanged += AutoreplaceSettings_SettingsChanged; LastChanceKeyboardHook.BeforeKeyHandled += _keyHandled; }
private static void HandleNewImage(BlogPostHtmlEditorControl currentEditor, Control owner, IHTMLElement imageElement, bool select) { // If the selection has changed since we first inserted the img tag, don't force a new selection. currentEditor.SelectionChanged -= blogPostEditor_SelectionChanged; if (selectionChanged || !select) { return; } try { currentEditor.EmptySelection(); // programmatically select the image currentEditor.SelectImage(imageElement); currentEditor.Focus(); } catch (Exception ex) { Trace.Fail("Unexpected error while attempting to select newly inserted image: " + ex.ToString()); } }
/// <summary> /// Inserts a set of images into the current editor, optionally assigning each image an id. /// </summary> /// <param name="imagePaths">paths of the images to insert</param> internal static void InsertImagesCore(IBlogPostHtmlEditor currentEditor, ISupportingFileService fileService, IEditorAccount editorAccount, OpenLiveWriter.PostEditor.ContentEditor editor, string[] imagePaths) { using (OpenLiveWriter.PostEditor.ContentEditor.EditorUndoUnit undo = new OpenLiveWriter.PostEditor.ContentEditor.EditorUndoUnit(currentEditor)) { StringBuilder htmlBuilder = new StringBuilder(); //calculate the size for inserted images (based on the user's saved default for this blog) DefaultImageSettings defaultImageSettings = new DefaultImageSettings(editorAccount.Id, editor.DecoratorsManager); Size defaultImageSize = defaultImageSettings.GetDefaultInlineImageSize(); //Generate the default img HTML for the image paths. Initially, the images are linked to the source image //path so that the DOM version of the HTML can be loaded. Once the images are loaded into the DOM, we can apply //the image decorators to generate scaled images, borders, etc. ImagePropertiesInfo[] imageInfos = new ImagePropertiesInfo[imagePaths.Length]; // don't insert into the title currentEditor.FocusBody(); for (int i = 0; i < imageInfos.Length; i++) { string imagePath = imagePaths[i]; Uri imgUri; if (UrlHelper.IsUrl(imagePath)) { imgUri = new Uri(imagePath); } else { imgUri = new Uri(UrlHelper.CreateUrlFromPath(imagePath)); } Size imageSize = new Size(1, 1); if (imgUri.IsFile && File.Exists(imagePath)) { if (!File.Exists(imgUri.LocalPath)) { Trace.Fail("Error inserting image - the image URL was corrupted: " + imagePath); } else { try { //check the validity of the image file imageSize = ImageUtils.GetImageSize(imagePath); } catch (Exception) { Trace.WriteLine("There is a problem with the image file: " + imagePath); // Insert anyway, MSHTML will show a red X in place of the image. htmlBuilder.AppendFormat(CultureInfo.InvariantCulture, "<img src=\"{0}\" />", HtmlUtils.EscapeEntities(UrlHelper.SafeToAbsoluteUri(imgUri))); continue; } } } // If the image has an embedded thumbnail, we'll use it as a place holder for the <img src="..."> // until we generate an inline image and apply decorators. Stream embeddedThumbnailStream = ImageHelper2.GetEmbeddedThumbnailStream(imagePath); if (embeddedThumbnailStream != null) { // Save thumbnail to disk. ISupportingFile imageFileEmbeddedThumbnail = fileService.CreateSupportingFile(Path.GetFileName(imagePath), Guid.NewGuid().ToString(), embeddedThumbnailStream); imageSize = ImageUtils.GetScaledImageSize(defaultImageSize.Width, defaultImageSize.Height, imageSize); //insert the default image html String imageElementAttrs = String.Format(CultureInfo.InvariantCulture, " width=\"{0}\" height=\"{1}\"", imageSize.Width, imageSize.Height); htmlBuilder.AppendFormat(CultureInfo.InvariantCulture, "<img src=\"{0}\" srcDelay=\"{1}\" {2} />", HtmlUtils.EscapeEntities(UrlHelper.SafeToAbsoluteUri(imageFileEmbeddedThumbnail.FileUri)), HtmlUtils.EscapeEntities(imgUri.ToString()), imageElementAttrs); } else if (currentEditor is BlogPostHtmlEditorControl && (imagePaths.Length > DELAYED_IMAGE_THRESHOLD || imageSize.Width * imageSize.Height > 16777216 /*4096 X 4096*/)) { // If we are using a delayed loading tactic then we insert using the srcdelay htmlBuilder.Append(MakeHtmlForImageSourceDelay(imgUri.ToString())); } else { imageSize = ImageUtils.GetScaledImageSize(defaultImageSize.Width, defaultImageSize.Height, imageSize); //insert the default image html String imageElementAttrs = imgUri.IsFile ? String.Format(CultureInfo.InvariantCulture, " width=\"{0}\" height=\"{1}\"", imageSize.Width, imageSize.Height) : String.Empty; htmlBuilder.AppendFormat(CultureInfo.InvariantCulture, "<img src=\"{0}\" {1} />", HtmlUtils.EscapeEntities(UrlHelper.SafeToAbsoluteUri(imgUri)), imageElementAttrs); } } //insert the HTML into the editor currentEditor.InsertHtml(htmlBuilder.ToString(), false); selectionChanged = false; BlogPostHtmlEditorControl blogPostEditor = currentEditor as BlogPostHtmlEditorControl; if (blogPostEditor != null) { blogPostEditor.SelectionChanged += blogPostEditor_SelectionChanged; } //now that the image HTML is inserted into the editor, apply the default settings to the new images. undo.Commit(); } }
public PostBodyEditingElementBehavior(BlogPostHtmlEditorControl editor, IHtmlEditorComponentContext editorContext, IHTMLElement prevEditableRegion, IHTMLElement nextEditableRegion) : base(editorContext, prevEditableRegion, nextEditableRegion) { _editor = editor; }