예제 #1
0
 /// <summary>
 /// Load the default image decorators for the current image context.
 /// </summary>
 /// <returns></returns>
 public ImageDecoratorsList LoadDefaultImageDecoratorsList()
 {
     using (SettingsPersisterHelper contextImageSettings = GetImageSettingsPersister(_contextId, false))
     {
         ImageDecoratorsList decoratorsList;
         if (contextImageSettings == null)
         {
             decoratorsList = GetInitialLocalImageDecoratorsList();
         }
         else
         {
             decoratorsList = new ImageDecoratorsList(_decoratorsManager, new BlogPostSettingsBag(), false);
             string[] decoratorIds = contextImageSettings.GetString(ImageDecoratorsListKey, "").Split(',');
             foreach (string decoratorId in decoratorIds)
             {
                 ImageDecorator imageDecorator = _decoratorsManager.GetImageDecorator(decoratorId);
                 if (imageDecorator != null) //can be null if the decorator is no longer valid
                 {
                     decoratorsList.AddDecorator(imageDecorator);
                     using (SettingsPersisterHelper decoratorDefaultSettings = contextImageSettings.GetSubSettings(decoratorId))
                     {
                         PluginSettingsAdaptor settings = new PluginSettingsAdaptor(decoratorDefaultSettings);
                         CopySettings(settings, decoratorsList.GetImageDecoratorSettings(decoratorId));
                     }
                 }
             }
         }
         //now add the implicit decorators IFF they aren't already in the list
         decoratorsList.MergeDecorators(GetImplicitLocalImageDecorators());
         return(decoratorsList);
     }
 }
예제 #2
0
        private void ApplyImageDecorator(ImageDecorator decorator, Bitmap bitmap, ref bool borderNeedsReset)
        {
            if (_embedType != ImageEmbedType.Embedded &&
                (decorator.IsBorderDecorator || decorator.Id == TiltDecorator.Id))
            {
                return;
            }

            if (borderNeedsReset &&
                _embedType == ImageEmbedType.Embedded &&
                (decorator.IsBorderDecorator || decorator.Id == TiltDecorator.Id))
            {
                borderNeedsReset = false;
                //BorderMargin = ImageBorderMargin.Empty;
            }

            try
            {
                using (ApplicationPerformance.LogEvent("ApplyDecorator: " + decorator.DecoratorName))
                    using (new WaitCursor())
                    {
                        _currImage    = bitmap;
                        _currSettings = _decoratorsList.GetImageDecoratorSettings(decorator);
                        decorator.Decorate(this);
                    }
            }
            catch (Exception e)
            {
                Trace.Fail(String.Format(CultureInfo.InvariantCulture, "Failed to apply image decorator [{0}]: {1}", decorator.DecoratorName, e.ToString()));
            }
        }
        private void ApplyImageDecorator(ImageDecorator decorator, Bitmap bitmap, ref bool borderNeedsReset)
        {
            if (_embedType != ImageEmbedType.Embedded
                && (decorator.IsBorderDecorator || decorator.Id == TiltDecorator.Id))
            {
                return;
            }

            if (borderNeedsReset
                && _embedType == ImageEmbedType.Embedded
                && (decorator.IsBorderDecorator || decorator.Id == TiltDecorator.Id))
            {
                borderNeedsReset = false;
                //BorderMargin = ImageBorderMargin.Empty;
            }

            try
            {
                using (ApplicationPerformance.LogEvent("ApplyDecorator: " + decorator.DecoratorName))
                using (new WaitCursor())
                {
                    _currImage = bitmap;
                    _currSettings = _decoratorsList.GetImageDecoratorSettings(decorator);
                    decorator.Decorate(this);
                }
            }
            catch (Exception e)
            {
                Trace.Fail(String.Format(CultureInfo.InvariantCulture, "Failed to apply image decorator [{0}]: {1}", decorator.DecoratorName, e.ToString()));
            }
        }
        internal ImageDecoratorsList(ImageDecoratorsManager decoratorsManager, BlogPostSettingsBag settingsBag, bool addDefaultBorderDecorator)
        {
            _decoratorsManager     = decoratorsManager;
            _decoratorsSettingsBag = settingsBag;
            List <ImageDecorator> decorators = new List <ImageDecorator>();

            string appliedDecorators = settingsBag.GetString(APPLIED_DECORATORS, "");

            //Add all of the defined decorators from the settings bag to the decoratorslist.
            //Bug fix note: collect decorators into an arraylist to avoid enumeration modified exception
            //from _decoratorsSettingsBag.SubsettingNames when calling AddDecorator(decorator);
            foreach (string decoratorId in appliedDecorators.Split(','))
            {
                ImageDecorator decorator = decoratorsManager.GetImageDecorator(decoratorId);
                if (decorator != null)
                {
                    decorators.Add(decorator);
                }
            }

            AddDecorator(decorators.ToArray());

            if (addDefaultBorderDecorator && (BorderImageDecorator == null))
            {
                AddDecorator(HtmlBorderDecorator.Id);
            }
        }
예제 #5
0
        public void SaveAsDefault(ImagePropertiesInfo imageInfo)
        {
            ImageDecoratorsList decorators = imageInfo.ImageDecorators;

            //delete the existing image settings
            DeleteImageSettings(_contextId);

            using (SettingsPersisterHelper contextImageSettings = GetImageSettingsPersister(_contextId, true))
            {
                //loop over the image decorators and save the settings of any decorators that are defaultable.
                StringBuilder sb = new StringBuilder();
                foreach (string decoratorId in decorators.GetImageDecoratorIds())
                {
                    ImageDecorator decorator = decorators.GetImageDecorator(decoratorId);
                    if (decorator.IsDefaultable)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append(",");
                        }
                        sb.Append(decorator.Id);
                        using (SettingsPersisterHelper decoratorDefaultSettings = contextImageSettings.GetSubSettings(decoratorId))
                        {
                            PluginSettingsAdaptor settings = new PluginSettingsAdaptor(decoratorDefaultSettings);
                            IProperties           decoratorCurrentSettings = decorators.GetImageDecoratorSettings(decoratorId);
                            CopySettings(decoratorCurrentSettings, settings);
                            ImageDecoratorEditorContext editorContext =
                                new ImageDecoratorEditorContextImpl(decoratorCurrentSettings, null, imageInfo, new NoOpUndoUnitFactory(), _decoratorsManager.CommandManager);
                            decorator.ApplyCustomizeDefaultSettingsHook(editorContext, settings);
                        }
                    }
                }
                contextImageSettings.SetString(ImageDecoratorsListKey, sb.ToString());
            }
        }
        private void ReloadImageDecorators()
        {
            ListView.SelectedIndexCollection selectedIndices = listViewDecoratorsTable.SelectedIndices;
            int selectedIndex = selectedIndices.Count > 0 ? selectedIndices[0] : 0;

            using (new UpdateListViewEntries(listViewDecoratorsTable, new EventHandler(listViewDecoratorsTable_SelectedIndexChanged)))
            {
                listViewDecoratorsTable.Items.Clear();
                if (ImageDecoratorsList != null)
                {
                    foreach (string decoratorId in ImageDecoratorsList.GetImageDecoratorIds())
                    {
                        ImageDecorator decorator = _decoratorsManager.GetImageDecorator(decoratorId);
                        if (!decorator.IsHidden)
                        {
                            ListViewItem listItem = new ListViewItem(decorator.DecoratorName);
                            listItem.Tag = decorator;
                            listViewDecoratorsTable.Items.Add(listItem);
                        }
                    }
                }

                if (listViewDecoratorsTable.Items.Count > 0)
                {
                    //reselect the last selected index
                    selectedIndex = Math.Min(listViewDecoratorsTable.Items.Count - 1, selectedIndex);
                    listViewDecoratorsTable.Items[selectedIndex].Selected = true;
                }
            }
        }
예제 #7
0
        private void imageDecoratorCommand_Execute(object sender, EventArgs e)
        {
            using (IUndoUnit undo = _editorContext.CreateUndoUnit())
            {
                ImageDecorator imageDecorator = ((ImageDecorator)((Command)sender).Tag);

                //perform the execution so that the decorator is added to the list of active decorators
                imageDecorator.Command.PerformExecute();

                //since this command was invoked explicitly via a command button, display the editor dialog.
                object state = null;
                if (imageDecorator.Id == CropDecorator.Id)
                {
                    state = ImagePropertiesInfo.Image;
                }

                using (state as IDisposable)
                {
                    DialogResult result = ImageDecoratorHelper.ShowImageDecoratorEditorDialog(imageDecorator,
                                                                                              ImagePropertiesInfo, new ApplyDecoratorCallback(ApplyImageDecorations),
                                                                                              _editorContext, state, _imageEditingContext, _imageEditingContext.DecoratorsManager.CommandManager);

                    if (result == DialogResult.OK)
                    {
                        undo.Commit();
                    }
                }
            }
        }
        public void RemoveDecorator(ImageDecorator decorator)
        {
            _RemoveDecorator(decorator);

            EnforceInvariants();

            SaveDecoratorList();
        }
        private void commandImageDecorator_Execute(object sender, EventArgs e)
        {
            ImageDecorator imageDecorator = ((ImageDecorator)((Command)sender).Tag);

            //perform the execution so that the decorator is added to the list of active decorators
            imageDecorator.Command.PerformExecute();

            //since this command was invoked explicitly via a command button, display the editor dialog.
            ImageDecoratorHelper.ShowImageDecoratorEditorDialog(FindForm(), imageDecorator, ImageInfo, new ApplyDecoratorCallback(ApplyImageDecorations));
        }
        /// <summary>
        /// Removes an decorator without saving the decorators list.
        /// </summary>
        public void _RemoveDecorator(ImageDecorator decorator)
        {
            _decoratorsList.Remove(decorator);
            _decoratorsTable.Remove(decorator.Id);

            //if this was the last decorator assigned to the settings namespace, blow the namespace way
            if (!IsSettingsNamespaceInUse(decorator.SettingsNamespace))
            {
                _decoratorsSettingsBag.RemoveSubSettings(decorator.SettingsNamespace);
            }
        }
        public void AddDecorator(string decoratorId)
        {
            ImageDecorator decorator = _decoratorsManager.GetImageDecorator(decoratorId);

            if (decorator == null)
            {
                Trace.Fail("Attempted to add unregistered decorator " + decoratorId);
                return;
            }
            AddDecorator(decorator);
        }
        private void OnDeleteCommand()
        {
            ImageDecorator decorator = SelectedImageDecorator;

            if (decorator != null)
            {
                ImageDecoratorsList.RemoveDecorator(decorator);
                ReloadImageDecorators();
                OnImageDecoratorsChanged(EventArgs.Empty);
                //this is needed to clear/change the visible editor. switching editors is disabled in the RefreshImageDecorators() call
                OnSelectedImageDecoratorChanged(EventArgs.Empty);
            }
        }
예제 #13
0
        public ImageDecorator[] GetDefaultRemoteImageDecorators()
        {
            ImageDecorator imageResizeDecorator = this.GetImageDecorator(HtmlImageResizeDecorator.Id);
            ImageDecorator imageTargetDecorator = this.GetImageDecorator(HtmlImageTargetDecorator.Id);
            ImageDecorator htmlMarginDecorator  = this.GetImageDecorator(HtmlMarginDecorator.Id);
            ImageDecorator htmlAlignDecorator   = this.GetImageDecorator(HtmlAlignDecorator.Id);
            ImageDecorator htmlAltTextDecorator = this.GetImageDecorator(HtmlAltTextDecorator.Id);
            ImageDecorator recolorDecorator     = this.GetImageDecorator(NoRecolorDecorator.Id);
            ImageDecorator sharpenDecorator     = this.GetImageDecorator(NoSharpenDecorator.Id);
            ImageDecorator blurDecorator        = this.GetImageDecorator(NoBlurDecorator.Id);
            ImageDecorator embossDecorator      = this.GetImageDecorator(NoEmbossDecorator.Id);

            return(new ImageDecorator[] { imageResizeDecorator, imageTargetDecorator, htmlMarginDecorator, htmlAlignDecorator, htmlAltTextDecorator, recolorDecorator, sharpenDecorator, blurDecorator, embossDecorator });
        }
예제 #14
0
        public int CompareTo(object obj)
        {
            if (obj is ImageDecorator)
            {
                ImageDecorator otherImageDecorator = (ImageDecorator)obj;
                return(Id.CompareTo(otherImageDecorator.Id));
            }
            else if (obj == null)
            {
                // By definition, any object compares greater than a null reference.
                return(1);
            }

            throw new ArgumentException("object is not an ImageDecorator");
        }
        /// <summary>
        /// Specifies the order in which decorators need to appear.
        /// </summary>
        private static int Classify(ImageDecorator x)
        {
            if (x.Id == CropDecorator.Id)
            {
                return(-1);
            }
            if (x.IsBorderDecorator)
            {
                return(1);
            }
            if (x.Id == TiltDecorator.Id)
            {
                return(2);
            }

            return(0);
        }
        /// <summary>
        /// Displays the editor (if one exists) for an image decorator in a dialog.
        /// </summary>
        /// <param name="imageDecorator"></param>
        /// <param name="ImageInfo"></param>
        /// <param name="applyCallback"></param>
        /// <param name="owner"></param>
        internal static DialogResult ShowImageDecoratorEditorDialog(ImageDecorator imageDecorator, ImagePropertiesInfo ImageInfo, ApplyDecoratorCallback applyCallback, IUndoUnitFactory undoUnitFactory, object state, IImageTargetEditor targetEditor, CommandManager commandManager)
        {
            ImageDecoratorEditor editor = imageDecorator.CreateEditor(commandManager);
            if (editor != null)
            {
                IProperties settings = ImageInfo.ImageDecorators.GetImageDecoratorSettings(imageDecorator);
                editor.LoadEditor(new ImageDecoratorEditorContextImpl(settings, new ApplyDecoratorCallback(applyCallback), ImageInfo, undoUnitFactory, commandManager), state, targetEditor);
                using (ImageDecoratorEditorForm editorForm = new ImageDecoratorEditorForm())
                {
                    editorForm.ImageDecoratorEditor = editor;

                    // for automation
                    editorForm.Name = imageDecorator.Id + "EditorForm";
                    return editorForm.ShowDialog();
                }
            }
            return DialogResult.Abort;
        }
예제 #17
0
        /// <summary>
        /// Displays the editor (if one exists) for an image decorator in a dialog.
        /// </summary>
        /// <param name="imageDecorator"></param>
        /// <param name="ImageInfo"></param>
        /// <param name="applyCallback"></param>
        /// <param name="owner"></param>
        internal static DialogResult ShowImageDecoratorEditorDialog(ImageDecorator imageDecorator, ImagePropertiesInfo ImageInfo, ApplyDecoratorCallback applyCallback, IUndoUnitFactory undoUnitFactory, object state, IImageTargetEditor targetEditor, CommandManager commandManager)
        {
            ImageDecoratorEditor editor = imageDecorator.CreateEditor(commandManager);

            if (editor != null)
            {
                IProperties settings = ImageInfo.ImageDecorators.GetImageDecoratorSettings(imageDecorator);
                editor.LoadEditor(new ImageDecoratorEditorContextImpl(settings, new ApplyDecoratorCallback(applyCallback), ImageInfo, undoUnitFactory, commandManager), state, targetEditor);
                using (ImageDecoratorEditorForm editorForm = new ImageDecoratorEditorForm())
                {
                    editorForm.ImageDecoratorEditor = editor;

                    // for automation
                    editorForm.Name = imageDecorator.Id + "EditorForm";
                    return(editorForm.ShowDialog());
                }
            }
            return(DialogResult.Abort);
        }
        public void MergeDecorators(params string[] decoratorIds)
        {
            List <ImageDecorator> decorators = new List <ImageDecorator>(decoratorIds.Length);

            foreach (string decoratorId in decoratorIds)
            {
                ImageDecorator decorator = _decoratorsManager.GetImageDecorator(decoratorId);

                ImageDecoratorGroup group = _decoratorsManager.GetImageDecoratorsGroup(decorator.GroupName);
                if (group.MutuallyExclusive && _decoratorsList.Exists(d => d.GroupName == decorator.GroupName))
                {
                    continue;
                }

                if (!_decoratorsList.Contains(decorator))
                {
                    decorators.Add(decorator);
                }
            }
            AddDecorator(decorators.ToArray());
        }
예제 #19
0
        void imageEffectsGalleryCommand_ExecuteWithArgs(object sender, ExecuteEventHandlerArgs args)
        {
            ImageEffectsGalleryCommand galleryCommand = (ImageEffectsGalleryCommand)sender;
            int            newSelectedIndex           = args.GetInt(galleryCommand.CommandId.ToString());
            string         newDecoratorId             = galleryCommand.Items[newSelectedIndex].Cookie;
            ImageDecorator newDecorator = _imageEditingContext.DecoratorsManager.GetImageDecorator(newDecoratorId);

            Debug.Assert(newDecorator != null);

            if (galleryCommand.SelectedItem != newDecorator.Id)
            {
                ImagePropertiesInfo.ImageDecorators.AddDecorator(newDecorator);

                if (!ImagePropertiesInfo.IsEditableEmbeddedImage())
                {
                    // If this is a web image, calling ApplyImageDecorations will keep properties up to date but won't
                    // actually do any decorating, so do it manually. Only borders should be manually decorated.
                    SimpleImageDecoratorContext context = new SimpleImageDecoratorContext(ImagePropertiesInfo);
                    newDecorator.Decorate(context);
                }

                ApplyImageDecorations();
            }
        }
        internal void SynchronizeImageDecorators()
        {
            ArrayList decoratorsList = new ArrayList();

            foreach (string decoratorId in ImageDecoratorsList.GetImageDecoratorIds())
            {
                ImageDecorator decorator = _decoratorsManager.GetImageDecorator(decoratorId);
                if (!decorator.IsHidden)
                {
                    decoratorsList.Add(decorator);
                }
            }

            bool needsReload = false;

            if (decoratorsList.Count != listViewDecoratorsTable.Items.Count)
            {
                needsReload = true;
            }
            else
            {
                for (int i = 0; i < decoratorsList.Count && !needsReload; i++)
                {
                    ImageDecorator decorator = (ImageDecorator)decoratorsList[i];
                    if (listViewDecoratorsTable.Items[i].Tag != decorator)
                    {
                        needsReload = true;
                    }
                }
            }

            if (needsReload)
            {
                ReloadImageDecorators();
            }
        }
예제 #21
0
        public override bool Equals(object obj)
        {
            ImageDecorator decorator = obj as ImageDecorator;

            return(decorator != null && decorator.Id == this.Id);
        }
        /// <summary>
        /// Specifies the order in which decorators need to appear.
        /// </summary>
        private static int Classify(ImageDecorator x)
        {
            if (x.Id == CropDecorator.Id)
                return -1;
            if (x.IsBorderDecorator)
                return 1;
            if (x.Id == TiltDecorator.Id)
                return 2;

            return 0;
        }
        public IProperties GetImageDecoratorSettings(string decoratorId)
        {
            ImageDecorator decorator = _decoratorsManager.GetImageDecorator(decoratorId);

            return(new ImageDecoratorSettingsBagAdapter(_decoratorsSettingsBag.CreateSubSettings(decorator.SettingsNamespace)));
        }
 public IProperties GetImageDecoratorSettings(ImageDecorator decorator)
 {
     return(new ImageDecoratorSettingsBagAdapter(_decoratorsSettingsBag.CreateSubSettings(decorator.SettingsNamespace)));
 }
        public void RemoveDecorator(ImageDecorator decorator)
        {
            _RemoveDecorator(decorator);

            EnforceInvariants();

            SaveDecoratorList();
        }
        public bool IsDecoratorEditable(string decoratorId)
        {
            ImageDecorator decorator = _decoratorsManager.GetImageDecorator(decoratorId);

            return(decorator != null && decorator.IsEditable);
        }
        /// <summary>
        /// Removes an decorator without saving the decorators list.
        /// </summary>
        public void _RemoveDecorator(ImageDecorator decorator)
        {
            _decoratorsList.Remove(decorator);
            _decoratorsTable.Remove(decorator.Id);

            //if this was the last decorator assigned to the settings namespace, blow the namespace way
            if (!IsSettingsNamespaceInUse(decorator.SettingsNamespace))
            {
                _decoratorsSettingsBag.RemoveSubSettings(decorator.SettingsNamespace);
            }
        }
 public IProperties GetImageDecoratorSettings(ImageDecorator decorator)
 {
     return new ImageDecoratorSettingsBagAdapter(_decoratorsSettingsBag.CreateSubSettings(decorator.SettingsNamespace));
 }
 public ImageDecoratorGroup(string groupName, bool mutuallyExclusive, ImageDecorator[] ImageDecorators)
 {
     _groupName = groupName;
     _mutuallyExclusive = mutuallyExclusive;
     _decorators = new List<ImageDecorator>(ImageDecorators);
 }