コード例 #1
0
 private void UpdateActiveSidebarControl()
 {
     if (GlobalEditorOptions.SupportsFeature(ContentEditorFeature.EnableSidebar))
     {
         ActiveSidebarControl = GetSidebarForCurrentSelection(_editorContext.Selection);
     }
 }
コード例 #2
0
        /// <summary>
        /// Saves the emoticon image to disk and returns the path. Should only be called if the emoticon image has not been saved previously for this blog post.
        /// </summary>
        private Uri CreateInlineImage(Emoticon emoticon)
        {
            Debug.Assert(_imageEditingContext.ImageList != null && _imageEditingContext.SupportingFileService != null, "ImageEditingContext not initalized yet.");

            Stream          emoticonStream = StreamHelper.AsStream(ImageHelper.GetBitmapBytes(emoticon.Bitmap, ImageFormat.Png));
            ISupportingFile sourceFile     = _imageEditingContext.SupportingFileService.CreateSupportingFile(emoticon.Id + emoticon.FileExtension, emoticonStream);
            ImageFileData   sourceFileData = new ImageFileData(sourceFile, emoticon.Bitmap.Width, emoticon.Bitmap.Height, ImageFileRelationship.Source);

            BlogPostImageData imageData = new BlogPostImageData(sourceFileData);

            if (GlobalEditorOptions.SupportsFeature(ContentEditorFeature.ShadowImageForDrafts))
            {
                imageData.InitShadowFile(_imageEditingContext.SupportingFileService);
            }

            emoticonStream.Seek(0, SeekOrigin.Begin);
            ISupportingFile inlineFile = _imageEditingContext.SupportingFileService.CreateSupportingFile(emoticon.Id + emoticon.FileExtension, emoticonStream);

            imageData.InlineImageFile = new ImageFileData(inlineFile, emoticon.Bitmap.Width, emoticon.Bitmap.Height, ImageFileRelationship.Inline);

            _imageEditingContext.ImageList.AddImage(imageData);

            SetInlineImageUri(emoticon, imageData.InlineImageFile.Uri);

            return(imageData.InlineImageFile.Uri);
        }
コード例 #3
0
        public static bool CanCreateFrom(DataObjectMeister data)
        {
            if (!GlobalEditorOptions.SupportsFeature(ContentEditorFeature.UrlContentSourcePaste))
            {
                return(false);
            }

            return(TextDataContainsEmbed(data));
        }
コード例 #4
0
        public TableEditingManager(IHtmlEditorComponentContext editorContext)
        {
            _editorContext = editorContext;

            if (!GlobalEditorOptions.SupportsFeature(ContentEditorFeature.Table))
            {
                _editorContext.SelectionChanged += new EventHandler(_editorContext_SelectionChanged);
                _selectionChangedHooked          = true;
            }

            InitializeCommands();
        }
コード例 #5
0
        protected override void LoadEditor()
        {
            base.LoadEditor();
            HtmlImageTargetSettings = new HtmlImageTargetDecoratorSettings(EditorContext.Settings, EditorContext.ImgElement);
            LoadLinkTargetsCombo();

            string imgUrl = (string)EditorContext.ImgElement.getAttribute("src", 2);

            LinkToSourceImageEnabled = UrlHelper.IsFileUrl(imgUrl) && GlobalEditorOptions.SupportsFeature(ContentEditorFeature.SupportsImageClickThroughs);

            if (ImageEditingContext.EditorOptions.DhtmlImageViewer != null)
            {
                imageViewer = DhtmlImageViewers.GetImageViewer(ImageEditingContext.EditorOptions.DhtmlImageViewer);
            }
        }
コード例 #6
0
        public static new bool CanCreateFrom(DataObjectMeister data)
        {
            if (!GlobalEditorOptions.SupportsFeature(ContentEditorFeature.UrlContentSourcePaste))
            {
                return(false);
            }

            if (HasUrl(data))
            {
                return(ContentSourceManager.FindContentSourceForUrl(ExtractUrl(data)) != null);
            }
            else
            {
                return(false);
            }
        }
コード例 #7
0
        public override void OnEditorAccountChanged(IEditorAccount newEditorAccount)
        {
            Command cmd = CommandManager.Get(CommandId.IgnoreOnce);

            if (cmd != null)
            {
                cmd.On = GlobalEditorOptions.SupportsFeature(ContentEditorFeature.SpellCheckIgnoreOnce);
            }
            base.OnEditorAccountChanged(newEditorAccount);

            // If any of these are null(or more likely all of them all null) then the editor has not been
            // fully loaded.  This will get called 1 time before the editor is fully loaded, this is
            // why SetAccountId is called at the end of Initialize()
            if (commandSemanticHtml != null && _currentEditor != null)
            {
                commandSemanticHtml.SetAccountId(_currentBlog.Id, IsRTLTemplate, false);
            }
        }
コード例 #8
0
        /// <summary>
        /// Launches a window as part of the starting of a process.
        /// </summary>
        private static void LaunchFirstInstance(IDisposable splashScreen, string[] args)
        {
            try
            {
                PostEditorFile.Initialize();

                MaybeMigrateSettings();

                // Make sure editor options are available before we launch the first instance.
                GlobalEditorOptions.Init(new OpenLiveWriterContentTarget(), new OpenLiveWriterSettingsProvider());

                // register file associations
                // Removing this call, as it causes exceptions in Vista
                // RegisterFileAssociations() ;
                Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, "Starting {0} {1}", ApplicationEnvironment.ProductNameQualified, ApplicationEnvironment.ProductVersion));
                Trace.WriteLine(String.Format(CultureInfo.InvariantCulture, ".NET version: {0}", Environment.Version));
                // force initialization which may fail with error dialogs
                // and/or cause the whole application to not load
                if (PostEditorLifetimeManager.Initialize())
                {
                    initComplete = true;

                    // launch blogging form
                    ApplicationLauncher.LaunchBloggingForm(args, splashScreen, true);
                }

                ManualKeepalive.Wait(true);
            }
            catch (DirectoryException ex)
            {
                if (ex.MessageId != null)
                {
                    DisplayMessage.Show(ex.MessageId.Value);
                }
                else if (ex.Path != null)
                {
                    DisplayMessage.Show(MessageId.DirectoryFail, ex.Path);
                }
                else
                {
                    UnexpectedErrorMessage.Show(ex);
                }
            }
            catch (Exception ex)
            {
                UnexpectedErrorMessage.Show(ex);
            }
            finally
            {
                try
                {
                    // shut down
                    PostEditorLifetimeManager.Uninitialize();
                    TempFileManager.Instance.Dispose();

                    // Delete legacy post supporting files that might have
                    // been orphaned by a previous version of Writer. We
                    // now keep these in the temp directory like everything
                    // else
                    string legacyPostSupportingFiles = Path.Combine(ApplicationEnvironment.ApplicationDataDirectory, "PostSupportingFiles");
                    if (Directory.Exists(legacyPostSupportingFiles))
                    {
                        Directory.Delete(legacyPostSupportingFiles, true);
                    }
                }
                catch (Exception ex2)
                {
                    Trace.Fail(ex2.ToString());
                }
            }
        }
コード例 #9
0
        private DialogResult EditTargetOptions(LinkTargetType linkTargetType)
        {
            using (LinkToOptionsForm linkOptionsForm = new LinkToOptionsForm())
            {
                if (linkTargetType == LinkTargetType.IMAGE)
                {
                    using (ImageTargetEditorControl editor = new ImageTargetEditorControl())
                    {
                        editor.LoadImageSize(ImagePropertiesInfo.LinkTargetImageSize, ImagePropertiesInfo.ImageSourceSize, ImagePropertiesInfo.ImageRotation);
                        editor.LinkOptions            = ImagePropertiesInfo.LinkOptions;
                        editor.EditorOptions          = _imageEditingContext.EditorOptions;
                        linkOptionsForm.EditorControl = editor;

                        ImagePropertiesInfo.DhtmlImageViewer = _imageEditingContext.EditorOptions.DhtmlImageViewer;

                        DialogResult result = linkOptionsForm.ShowDialog(_editorContext.MainFrameWindow);
                        if (result == DialogResult.OK)
                        {
                            ImagePropertiesInfo.LinkTargetImageSize     = editor.ImageSize;
                            ImagePropertiesInfo.DhtmlImageViewer        = _imageEditingContext.EditorOptions.DhtmlImageViewer;
                            ImagePropertiesInfo.LinkOptions             = editor.LinkOptions;
                            ImagePropertiesInfo.LinkTargetImageSizeName = editor.ImageBoundsSize;
                        }
                        return(result);
                    }
                }
                else if (linkTargetType == LinkTargetType.URL)
                {
                    using (HyperlinkForm hyperlinkForm = new HyperlinkForm(_editorContext.CommandManager, GlobalEditorOptions.SupportsFeature(ContentEditorFeature.ShowAllLinkOptions)))
                    {
                        hyperlinkForm.ContainsImage = true;
                        hyperlinkForm.EditStyle     = !String.IsNullOrEmpty(ImagePropertiesInfo.LinkTargetUrl);
                        hyperlinkForm.NewWindow     = ImagePropertiesInfo.LinkOptions.ShowInNewWindow;
                        if (ImagePropertiesInfo.LinkTitle != String.Empty)
                        {
                            hyperlinkForm.LinkTitle = ImagePropertiesInfo.LinkTitle;
                        }
                        if (ImagePropertiesInfo.LinkRel != String.Empty)
                        {
                            hyperlinkForm.Rel = ImagePropertiesInfo.LinkRel;
                        }
                        if (ImagePropertiesInfo.LinkTargetUrl != null && ImagePropertiesInfo.LinkTarget != LinkTargetType.IMAGE)
                        {
                            hyperlinkForm.Hyperlink = ImagePropertiesInfo.LinkTargetUrl;
                        }

                        DialogResult result = hyperlinkForm.ShowDialog(_editorContext.MainFrameWindow);
                        if (result == DialogResult.OK)
                        {
                            ImagePropertiesInfo.LinkTargetUrl = hyperlinkForm.Hyperlink;
                            ImagePropertiesInfo.UpdateImageLinkOptions(hyperlinkForm.LinkTitle, hyperlinkForm.Rel, hyperlinkForm.NewWindow);
                            ImagePropertiesInfo.LinkOptions = new LinkOptions(hyperlinkForm.NewWindow, false, null);
                        }
                        return(result);
                    }
                }

                return(DialogResult.Abort);
            }
        }
コード例 #10
0
        /// <summary>
        /// Initializes ribbon commands when a new image is loaded.
        /// </summary>
        private void ResetPropertiesChunkCommands(bool isImageSelected, bool isEditableEmbeddedImage)
        {
            // Set enabled state.
            _imageLinkTargetDropdown.Enabled  = isImageSelected;
            _imageLinkToSourceCommand.Enabled = isImageSelected && UrlHelper.IsFileUrl(ImagePropertiesInfo.ImageSourceUri.ToString()) && GlobalEditorOptions.SupportsFeature(ContentEditorFeature.SupportsImageClickThroughs);
            _imageLinkOptionsCommand.Enabled  = isImageSelected;
            _imageAltTextCommand.Enabled      = isImageSelected;

            // Set any defaults.
            _imageLinkTargetDropdown.SelectTag(LinkTargetType.NONE);
        }
コード例 #11
0
        private static List <NewImageInfo> ScanImages(IBlogPostHtmlEditor currentEditor, IEditorAccount editorAccount, ContentEditor editor, bool useDefaultTargetSettings)
        {
            List <NewImageInfo> newImages = new List <NewImageInfo>();

            ApplicationPerformance.ClearEvent("InsertImage");
            ApplicationPerformance.StartEvent("InsertImage");

            using (new WaitCursor())
            {
                IHTMLElement2 postBodyElement = (IHTMLElement2)((BlogPostHtmlEditorControl)currentEditor).PostBodyElement;
                if (postBodyElement != null)
                {
                    foreach (IHTMLElement imgElement in postBodyElement.getElementsByTagName("img"))
                    {
                        string imageSrc = imgElement.getAttribute("srcDelay", 2) as string;

                        if (string.IsNullOrEmpty(imageSrc))
                        {
                            imageSrc = imgElement.getAttribute("src", 2) as string;
                        }

                        // WinLive 96840 - Copying and pasting images within shared canvas should persist source
                        // decorator settings. "wlCopySrcUrl" is inserted while copy/pasting within canvas.
                        bool   copyDecoratorSettings = false;
                        string attributeCopySrcUrl   = imgElement.getAttribute("wlCopySrcUrl", 2) as string;
                        if (!string.IsNullOrEmpty(attributeCopySrcUrl))
                        {
                            copyDecoratorSettings = true;
                            imgElement.removeAttribute("wlCopySrcUrl", 0);
                        }

                        // Check if we need to apply default values for image decorators
                        bool   applyDefaultDecorator       = true;
                        string attributeNoDefaultDecorator = imgElement.getAttribute("wlNoDefaultDecorator", 2) as string;
                        if (!string.IsNullOrEmpty(attributeNoDefaultDecorator) && string.Compare(attributeNoDefaultDecorator, "TRUE", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            applyDefaultDecorator = false;
                            imgElement.removeAttribute("wlNoDefaultDecorator", 0);
                        }

                        string applyDefaultMargins = imgElement.getAttribute("wlApplyDefaultMargins", 2) as string;
                        if (!String.IsNullOrEmpty(applyDefaultMargins))
                        {
                            DefaultImageSettings defaultImageSettings = new DefaultImageSettings(editorAccount.Id, editor.DecoratorsManager);
                            MarginStyle          defaultMargin        = defaultImageSettings.GetDefaultImageMargin();
                            // Now apply it to the image
                            imgElement.style.marginTop    = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Top);
                            imgElement.style.marginLeft   = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Left);
                            imgElement.style.marginBottom = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Bottom);
                            imgElement.style.marginRight  = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Right);
                            imgElement.removeAttribute("wlApplyDefaultMargins", 0);
                        }

                        if ((UrlHelper.IsFileUrl(imageSrc) || IsFullPath(imageSrc)) && !ContentSourceManager.IsSmartContent(imgElement))
                        {
                            Uri imageSrcUri = new Uri(imageSrc);
                            try
                            {
                                BlogPostImageData imageData = BlogPostImageDataList.LookupImageDataByInlineUri(editor.ImageList, imageSrcUri);
                                Emoticon          emoticon  = EmoticonsManager.GetEmoticon(imgElement);
                                if (imageData == null && emoticon != null)
                                {
                                    // This is usually an emoticon copy/paste and needs to be cleaned up.
                                    Uri inlineImageUri = editor.EmoticonsManager.GetInlineImageUri(emoticon);
                                    imgElement.setAttribute("src", UrlHelper.SafeToAbsoluteUri(inlineImageUri), 0);
                                }
                                else if (imageData == null)
                                {
                                    if (!File.Exists(imageSrcUri.LocalPath))
                                    {
                                        throw new FileNotFoundException(imageSrcUri.LocalPath);
                                    }

                                    // WinLive 188841: Manually attach the behavior so that the image cannot be selected or resized while its loading.
                                    DisabledImageElementBehavior disabledImageBehavior = new DisabledImageElementBehavior(editor.IHtmlEditorComponentContext);
                                    disabledImageBehavior.AttachToElement(imgElement);

                                    Size sourceImageSize                      = ImageUtils.GetImageSize(imageSrcUri.LocalPath);
                                    ImagePropertiesInfo  imageInfo            = new ImagePropertiesInfo(imageSrcUri, sourceImageSize, new ImageDecoratorsList(editor.DecoratorsManager, new BlogPostSettingsBag()));
                                    DefaultImageSettings defaultImageSettings = new DefaultImageSettings(editorAccount.Id, editor.DecoratorsManager);

                                    // Make sure this is set because some imageInfo properties depend on it.
                                    imageInfo.ImgElement = imgElement;

                                    bool isMetafile = ImageHelper2.IsMetafile(imageSrcUri.LocalPath);
                                    ImageClassification imgClass = ImageHelper2.Classify(imageSrcUri.LocalPath);
                                    if (!isMetafile && ((imgClass & ImageClassification.AnimatedGif) != ImageClassification.AnimatedGif))
                                    {
                                        // WinLive 96840 - Copying and pasting images within shared canvas should persist source
                                        // decorator settings.
                                        if (copyDecoratorSettings)
                                        {
                                            // Try to look up the original copied source image.
                                            BlogPostImageData imageDataOriginal = BlogPostImageDataList.LookupImageDataByInlineUri(editor.ImageList, new Uri(attributeCopySrcUrl));
                                            if (imageDataOriginal != null && imageDataOriginal.GetImageSourceFile() != null)
                                            {
                                                // We have the original image reference, so lets make a clone of it.
                                                BlogPostSettingsBag originalBag            = (BlogPostSettingsBag)imageDataOriginal.ImageDecoratorSettings.Clone();
                                                ImageDecoratorsList originalDecoratorsList = new ImageDecoratorsList(editor.DecoratorsManager, originalBag);

                                                ImageFileData originalImageFileData = imageDataOriginal.GetImageSourceFile();
                                                Size          originalImageSize     = new Size(originalImageFileData.Width, originalImageFileData.Height);
                                                imageInfo = new ImagePropertiesInfo(originalImageFileData.Uri, originalImageSize, originalDecoratorsList);
                                            }
                                            else
                                            {
                                                // There are probably decorators applied to the image, but in a different editor so we can't access them.
                                                // We probably don't want to apply any decorators to this image, so apply blank decorators and load the
                                                // image as full size so it looks like it did before.
                                                imageInfo.ImageDecorators     = defaultImageSettings.LoadBlankLocalImageDecoratorsList();
                                                imageInfo.InlineImageSizeName = ImageSizeName.Full;
                                            }
                                        }
                                        else if (applyDefaultDecorator)
                                        {
                                            imageInfo.ImageDecorators = defaultImageSettings.LoadDefaultImageDecoratorsList();

                                            if ((imgClass & ImageClassification.TransparentGif) == ImageClassification.TransparentGif)
                                            {
                                                imageInfo.ImageDecorators.AddDecorator(NoBorderDecorator.Id);
                                            }
                                        }
                                        else
                                        {
                                            // Don't use default values for decorators
                                            imageInfo.ImageDecorators     = defaultImageSettings.LoadBlankLocalImageDecoratorsList();
                                            imageInfo.InlineImageSizeName = ImageSizeName.Full;
                                        }
                                    }
                                    else
                                    {
                                        ImageDecoratorsList decorators = new ImageDecoratorsList(editor.DecoratorsManager, new BlogPostSettingsBag());
                                        decorators.AddDecorator(editor.DecoratorsManager.GetDefaultRemoteImageDecorators());
                                        imageInfo.ImageDecorators = decorators;
                                    }

                                    imageInfo.ImgElement       = imgElement;
                                    imageInfo.DhtmlImageViewer = editorAccount.EditorOptions.DhtmlImageViewer;

                                    //discover the "natural" target settings from the DOM
                                    string linkTargetUrl = imageInfo.LinkTargetUrl;
                                    if (linkTargetUrl == imageSrc)
                                    {
                                        imageInfo.LinkTarget = LinkTargetType.IMAGE;
                                    }
                                    else if (!String.IsNullOrEmpty(linkTargetUrl) && !UrlHelper.IsFileUrl(linkTargetUrl))
                                    {
                                        imageInfo.LinkTarget = LinkTargetType.URL;
                                    }
                                    else
                                    {
                                        imageInfo.LinkTarget = LinkTargetType.NONE;
                                    }

                                    if (useDefaultTargetSettings)
                                    {
                                        if (!GlobalEditorOptions.SupportsFeature(ContentEditorFeature.SupportsImageClickThroughs) && imageInfo.DefaultLinkTarget == LinkTargetType.IMAGE)
                                        {
                                            imageInfo.DefaultLinkTarget = LinkTargetType.NONE;
                                        }

                                        if (imageInfo.LinkTarget == LinkTargetType.NONE)
                                        {
                                            imageInfo.LinkTarget = imageInfo.DefaultLinkTarget;
                                        }
                                        if (imageInfo.DefaultLinkOptions.ShowInNewWindow)
                                        {
                                            imageInfo.LinkOptions.ShowInNewWindow = true;
                                        }
                                        imageInfo.LinkOptions.UseImageViewer       = imageInfo.DefaultLinkOptions.UseImageViewer;
                                        imageInfo.LinkOptions.ImageViewerGroupName = imageInfo.DefaultLinkOptions.ImageViewerGroupName;
                                    }

                                    Size defaultImageSize = defaultImageSettings.GetDefaultInlineImageSize();
                                    Size initialSize      = ImageUtils.GetScaledImageSize(defaultImageSize.Width, defaultImageSize.Height, sourceImageSize);

                                    // add to list of new images
                                    newImages.Add(new NewImageInfo(imageInfo, imgElement, initialSize, disabledImageBehavior));
                                }
                                else
                                {
                                    // When switching blogs, try to adapt image viewer settings according to the blog settings.

                                    ImagePropertiesInfo imageInfo = new ImagePropertiesInfo(imageSrcUri, ImageUtils.GetImageSize(imageSrcUri.LocalPath), new ImageDecoratorsList(editor.DecoratorsManager, imageData.ImageDecoratorSettings));
                                    imageInfo.ImgElement = imgElement;
                                    // Make sure the new crop and tilt decorators get loaded
                                    imageInfo.ImageDecorators.MergeDecorators(DefaultImageSettings.GetImplicitLocalImageDecorators());
                                    string viewer = imageInfo.DhtmlImageViewer;
                                    if (viewer != editorAccount.EditorOptions.DhtmlImageViewer)
                                    {
                                        imageInfo.DhtmlImageViewer = editorAccount.EditorOptions.DhtmlImageViewer;
                                        imageInfo.LinkOptions      = imageInfo.DefaultLinkOptions;
                                    }

                                    // If the image is an emoticon, update the EmoticonsManager with the image's uri so that duplicate emoticons can point to the same file.
                                    if (emoticon != null)
                                    {
                                        editor.EmoticonsManager.SetInlineImageUri(emoticon, imageData.InlineImageFile.Uri);
                                    }
                                }
                            }
                            catch (ArgumentException e)
                            {
                                Trace.WriteLine("Could not initialize image: " + imageSrc);
                                Trace.WriteLine(e.ToString());
                            }
                            catch (DirectoryNotFoundException)
                            {
                                Debug.WriteLine("Image file does not exist: " + imageSrc);
                            }
                            catch (FileNotFoundException)
                            {
                                Debug.WriteLine("Image file does not exist: " + imageSrc);
                            }
                            catch (IOException e)
                            {
                                Debug.WriteLine("Image file cannot be read: " + imageSrc + " " + e);
                                DisplayMessage.Show(MessageId.FileInUse, imageSrc);
                            }
                        }
                    }
                }
            }

            return(newImages);
        }
コード例 #12
0
        /// <summary>
        /// Initializes and registers images with the editor.
        /// </summary>
        protected override void DoWork()
        {
            foreach (NewImageInfo newImage in this.newImages)
            {
                // Before starting on the next image, make sure we weren't cancelled.
                if (CancelRequested)
                {
                    AcknowledgeCancel();
                    return;
                }

                try
                {
                    // Register the image file as a BlogPostImageData so that the editor can manage the supporting files
                    ISupportingFile sourceFile = this.fileService.AddLinkedSupportingFileReference(newImage.ImageInfo.ImageSourceUri);
                    newImage.ImageData = new BlogPostImageData(new ImageFileData(sourceFile, newImage.ImageInfo.ImageSourceSize.Width, newImage.ImageInfo.ImageSourceSize.Height, ImageFileRelationship.Source));

                    // Create the shadow file if necessary.
                    if (GlobalEditorOptions.SupportsFeature(ContentEditorFeature.ShadowImageForDrafts))
                    {
                        newImage.ImageData.InitShadowFile(this.fileService);
                    }

                    // Create the initial inline image.
                    Stream inlineImageStream = new MemoryStream();
                    using (Bitmap sourceBitmap = new Bitmap(newImage.ImageInfo.ImageSourceUri.LocalPath))
                    {
                        string      extension;
                        ImageFormat imageFormat;
                        ImageHelper2.GetImageFormat(newImage.ImageInfo.ImageSourceUri.LocalPath, out extension, out imageFormat);

                        using (Bitmap resizedBitmap = ImageHelper2.CreateResizedBitmap(sourceBitmap, newImage.InitialSize.Width, newImage.InitialSize.Height, imageFormat))
                        {
                            // Resizing the bitmap is a time-consuming operation, so its possible we were cancelled during it.
                            if (CancelRequested)
                            {
                                AcknowledgeCancel();
                                return;
                            }

                            ImageHelper2.SaveImage(resizedBitmap, imageFormat, inlineImageStream);
                        }

                        inlineImageStream.Seek(0, SeekOrigin.Begin);
                    }

                    // Saving the bitmap is a time-consuming operation, so its possible we were cancelled during it.
                    if (CancelRequested)
                    {
                        AcknowledgeCancel();
                        return;
                    }

                    // Link up the initial inline image.
                    ISupportingFile imageFilePlaceholderHolder = this.fileService.CreateSupportingFile(Path.GetFileName(newImage.ImageInfo.ImageSourceUri.LocalPath), Guid.NewGuid().ToString(), inlineImageStream);
                    newImage.ImageData.InlineImageFile = new ImageFileData(imageFilePlaceholderHolder, newImage.InitialSize.Width, newImage.InitialSize.Height, ImageFileRelationship.Inline);
                }
                catch (Exception e)
                {
                    // Something failed for this image, flag this for removal
                    Debug.WriteLine("Image file could not be initialized: " + newImage.ImageInfo.ImageSourceUri.LocalPath + " " + e);
                    Trace.WriteLine("Could not initialize image: " + newImage.ImageInfo.ImageSourceUri.LocalPath);
                    Trace.WriteLine(e.ToString());
                    newImage.Remove = true;
                }
            }

            // We've successfully intialized all the images, but make sure we weren't cancelled at the last second.
            if (CancelRequested)
            {
                AcknowledgeCancel();
                return;
            }
        }
コード例 #13
0
        private DialogResult EditTargetOptions()
        {
            using (LinkToOptionsForm linkOptionsForm = new LinkToOptionsForm())
            {
                if (SelectedLinkTarget == LinkTargetType.IMAGE)
                {
                    using (ImageTargetEditorControl editor = new ImageTargetEditorControl())
                    {
                        editor.LoadImageSize(HtmlImageTargetSettings.ImageSize, EditorContext.SourceImageSize, EditorContext.ImageRotation);
                        editor.LinkOptions            = HtmlImageTargetSettings.LinkOptions;
                        editor.EditorOptions          = ImageEditingContext.EditorOptions;
                        linkOptionsForm.EditorControl = editor;

                        HtmlImageTargetSettings.DhtmlImageViewer = ImageEditingContext.EditorOptions.DhtmlImageViewer;

                        DialogResult result = linkOptionsForm.ShowDialog(this);
                        if (result == DialogResult.OK)
                        {
                            HtmlImageTargetSettings.ImageSize        = editor.ImageSize;
                            HtmlImageTargetSettings.DhtmlImageViewer = ImageEditingContext.EditorOptions.DhtmlImageViewer;
                            HtmlImageTargetSettings.LinkOptions      = editor.LinkOptions;
                            HtmlImageTargetSettings.ImageSizeName    = editor.ImageBoundsSize;
                        }
                        return(result);
                    }
                }
                else if (SelectedLinkTarget == LinkTargetType.URL)
                {
                    using (HyperlinkForm hyperlinkForm = new HyperlinkForm(EditorContext.CommandManager, GlobalEditorOptions.SupportsFeature(ContentEditorFeature.ShowAllLinkOptions)))
                    {
                        hyperlinkForm.ContainsImage = true;
                        hyperlinkForm.EditStyle     = HtmlImageTargetSettings.LinkTargetUrl != null && HtmlImageTargetSettings.LinkTargetUrl != String.Empty;
                        hyperlinkForm.NewWindow     = HtmlImageTargetSettings.LinkOptions.ShowInNewWindow;
                        if (HtmlImageTargetSettings.LinkTitle != String.Empty)
                        {
                            hyperlinkForm.LinkTitle = HtmlImageTargetSettings.LinkTitle;
                        }
                        if (HtmlImageTargetSettings.LinkRel != String.Empty)
                        {
                            hyperlinkForm.Rel = HtmlImageTargetSettings.LinkRel;
                        }
                        if (HtmlImageTargetSettings.LinkTargetUrl != null && HtmlImageTargetSettings.LinkTarget != LinkTargetType.IMAGE)
                        {
                            hyperlinkForm.Hyperlink = HtmlImageTargetSettings.LinkTargetUrl;
                        }

                        DialogResult result = hyperlinkForm.ShowDialog(FindForm());
                        if (result == DialogResult.OK)
                        {
                            HtmlImageTargetSettings.LinkTargetUrl = hyperlinkForm.Hyperlink;
                            HtmlImageTargetSettings.UpdateImageLinkOptions(hyperlinkForm.LinkTitle, hyperlinkForm.Rel, hyperlinkForm.NewWindow);
                            HtmlImageTargetSettings.LinkOptions = new LinkOptions(hyperlinkForm.NewWindow, false, null);
                        }
                        return(result);
                    }
                }

                return(DialogResult.Abort);
            }
        }