Exemplo n.º 1
0
        /// <summary>
        /// Called when the ImagePropertiesInfo object has changed in order to sync the commands and decorators with
        /// the currently selected image.
        /// </summary>
        private void ManageCommands()
        {
            using (IUndoUnit undo = _editorContext.CreateInvisibleUndoUnit())
            {
                if (_imageEditingContext != null)
                {
                    for (int i = 0; i < _imageEditingContext.DecoratorsManager.ImageDecoratorGroups.Length; i++)
                    {
                        ImageDecoratorGroup imageDecoratorGroup = _imageEditingContext.DecoratorsManager.ImageDecoratorGroups[i];
                        foreach (ImageDecorator imageDecorator in imageDecoratorGroup.ImageDecorators)
                        {
                            if (_imagePropertiesInfo == null || _imagePropertiesInfo.IsEditableEmbeddedImage() || imageDecorator.IsWebImageSupported)
                            {
                                imageDecorator.Command.Enabled = true;
                            }
                            else
                            {
                                imageDecorator.Command.Enabled = false;
                            }
                        }
                    }

                    ResetCommands();

                    if (ImagePropertiesInfo != null)
                    {
                        RefreshCommands();
                    }
                }
                undo.Commit();
            }
        }
Exemplo n.º 2
0
        public ImageDecorator[] GetImageDecoratorsFromGroup(string groupName)
        {
            ImageDecoratorGroup group = GetImageDecoratorsGroup(groupName);

            if (group == null)
            {
                return(new ImageDecorator[0]);
            }
            else
            {
                return(group.ImageDecorators);
            }
        }
        private void InitializeCommands()
        {
            commandContextManager = new CommandContextManager(_decoratorsManager.CommandManager);
            commandContextManager.BeginUpdate();

            commandAddMenu = new Command(CommandId.AddDecorator);
            _decoratorsManager.CommandManager.Add(commandAddMenu);
            addCommandContextMenuDefinition = new CommandContextMenuDefinition(components);
            if (_decoratorsManager != null)
            {
                for (int i = 0; i < _decoratorsManager.ImageDecoratorGroups.Length; i++)
                {
                    ImageDecoratorGroup imageDecoratorGroup = _decoratorsManager.ImageDecoratorGroups[i];

                    foreach (ImageDecorator imageDecorator in imageDecoratorGroup.ImageDecorators)
                    {
                        if (!imageDecorator.IsHidden) //don't show hidden decorators in the command list
                        {
                            Command ImageDecoratorApplyCommand = imageDecorator.Command;
                            MenuDefinitionEntryCommand imageDecoratorMenuEntry = new MenuDefinitionEntryCommand(components);
                            imageDecoratorMenuEntry.CommandIdentifier = ImageDecoratorApplyCommand.Identifier;
                            addCommandContextMenuDefinition.Entries.Add(imageDecoratorMenuEntry);

                            ImageDecoratorApplyCommand.Execute += new EventHandler(imageDecoratorApplyCommand_Execute);
                            ImageDecoratorApplyCommand.Tag      = imageDecorator.Id;
                        }
                    }
                }
            }

            commandImageRemove          = new Command(CommandId.RemoveDecorator);
            commandImageRemove.Execute += new EventHandler(commandRemoveMenu_Execute);
            commandContextManager.AddCommand(commandImageRemove, CommandContext.Normal);

            _decoratorsManager.CommandManager.SuppressEvents = true;
            try
            {
                commandContextManager.EndUpdate();
            }
            finally
            {
                _decoratorsManager.CommandManager.SuppressEvents = true;
            }
        }
        protected ImageDecorator EnforceOneDecoratorForGroup(ImageDecoratorGroup group)
        {
            List <ImageDecorator> groupDecorators  = new List <ImageDecorator>(group.ImageDecorators);
            List <ImageDecorator> activeDecorators = _decoratorsList.FindAll(d => groupDecorators.Contains(d));

            for (int i = 0; i < activeDecorators.Count - 1; i++)
            {
                _RemoveDecorator(activeDecorators[i]);
            }

            if (activeDecorators.Count == 0)
            {
                return(null);
            }
            else
            {
                return(activeDecorators[activeDecorators.Count - 1]);
            }
        }
 /// <summary>
 /// Manages the commands associated with image editing.
 /// </summary>
 private void ManageCommands()
 {
     if (_imageDataContext != null)
     {
         for (int i = 0; i < _imageDataContext.DecoratorsManager.ImageDecoratorGroups.Length; i++)
         {
             ImageDecoratorGroup imageDecoratorGroup = _imageDataContext.DecoratorsManager.ImageDecoratorGroups[i];
             foreach (ImageDecorator imageDecorator in imageDecoratorGroup.ImageDecorators)
             {
                 if (_imageInfo == null || _imageInfo.ImageSourceUri.IsFile || imageDecorator.IsWebImageSupported)
                 {
                     imageDecorator.Command.Enabled = true;
                 }
                 else
                 {
                     imageDecorator.Command.Enabled = false;
                 }
             }
         }
     }
 }
        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());
        }
Exemplo n.º 7
0
        private void InitializeCommands()
        {
            commandContextManager = new CommandContextManager(CommandManager);
            commandContextManager.BeginUpdate();

            for (int i = 0; i < ImageDecoratorGroups.Length; i++)
            {
                ImageDecoratorGroup imageDecoratorGroup = ImageDecoratorGroups[i];
                foreach (ImageDecorator imageDecorator in imageDecoratorGroup.ImageDecorators)
                {
                    Command ImageDecoratorApplyCommand = new Command(CommandId.ImageDecoratorApply);
                    ImageDecoratorApplyCommand.Identifier += imageDecorator.Id;
                    ImageDecoratorApplyCommand.Text        = imageDecorator.DecoratorName;
                    ImageDecoratorApplyCommand.MenuText    = imageDecorator.DecoratorName;
                    imageDecorator.SetCommand(ImageDecoratorApplyCommand);
                    commandContextManager.AddCommand(ImageDecoratorApplyCommand, CommandContext.Normal);

                    ImageDecoratorApplyCommand.Execute += new EventHandler(imageDecoratorCommand_Execute);
                    ImageDecoratorApplyCommand.Tag      = imageDecorator.Id;
                }
            }

            commandContextManager.EndUpdate();
        }
Exemplo n.º 8
0
        public ImageDecoratorsManager(IContainer components, CommandManager commandManager, bool includeInheritBorder)
        {
            this.components = components;
            CommandManager  = commandManager;
            //load the default image decorators
            ImageDecoratorGroup basic = new ImageDecoratorGroup(BASIC_GROUP, false,
                                                                new ImageDecorator[] {
                new ImageDecorator(CropDecorator.Id, "Crop", typeof(CropDecorator), BASIC_GROUP, true, true, false, false)
            });
            ImageDecoratorGroup borders = new ImageDecoratorGroup(BORDER_GROUP, true,
                                                                  new ImageDecorator[] {
                new ImageDecorator(HtmlBorderDecorator.Id, Res.Get(StringId.DecoratorInheritBorder), typeof(HtmlBorderDecorator), BORDER_GROUP, true, false, true, true),
                new ImageDecorator(NoBorderDecorator.Id, Res.Get(StringId.DecoratorNoBorder), typeof(NoBorderDecorator), BORDER_GROUP, true, false, true, true),
                new ImageDecorator(DropShadowBorderDecorator.Id, Res.Get(StringId.DecoratorDropShadow), typeof(DropShadowBorderDecorator), BORDER_GROUP, true, false, true, false),
                new ImageDecorator(PolaroidBorderDecorator.Id, Res.Get(StringId.DecoratorInstantPhoto), typeof(PolaroidBorderDecorator), BORDER_GROUP, true, false, true, false),
                new ImageDecorator(PhotoBorderDecorator.Id, Res.Get(StringId.DecoratorPhotopaper), typeof(PhotoBorderDecorator), BORDER_GROUP, true, false, true, false),
                new ImageDecorator(ReflectionBorderDecorator.Id, Res.Get(StringId.DecoratorReflection), typeof(ReflectionBorderDecorator), BORDER_GROUP, true, false, true, false),
                new ImageDecorator(RoundedCornersBorderDecorator.Id, Res.Get(StringId.DecoratorRoundedCorners), typeof(RoundedCornersBorderDecorator), BORDER_GROUP, true, false, true, false),
                //new ImageDecorator(SoftShadowBorderDecorator.Id, "Soft Shadow", typeof(SoftShadowBorderDecorator), true, false, true, false),
                new ImageDecorator(ThinSolidBorderDecorator.Id, Res.Get(StringId.DecoratorSolid1px), typeof(ThinSolidBorderDecorator), BORDER_GROUP, true, false, true, false),
                new ImageDecorator(ThickSolidBorderDecorator.Id, Res.Get(StringId.DecoratorSolid3px), typeof(ThickSolidBorderDecorator), BORDER_GROUP, true, false, true, false),
            });
            ImageDecoratorGroup colors = new ImageDecoratorGroup(ADJUST_COLOR_GROUP, false,
                                                                 new ImageDecorator[] {
                new ImageDecorator(BrightnessDecorator.Id, "Brightness/Contrast", typeof(BrightnessDecorator), ADJUST_COLOR_GROUP, true, true, false, false),
                new ImageDecorator(TiltDecorator.Id, "Tilt", typeof(TiltDecorator), ADJUST_COLOR_GROUP, true, true, false, false),
                new ImageDecorator(WatermarkDecorator.Id, "Watermark", typeof(WatermarkDecorator), ADJUST_COLOR_GROUP, true, true, true, false)
            });
            ImageDecoratorGroup html = new ImageDecoratorGroup(HTML_GROUP, false,
                                                               new ImageDecorator[] {
                new ImageDecorator(HtmlMarginDecorator.Id, "Margin", typeof(HtmlMarginDecorator), HTML_GROUP, true, true, true, true),
                new ImageDecorator(HtmlAlignDecorator.Id, "Text Wrapping", typeof(HtmlAlignDecorator), HTML_GROUP, true, true, true, true),
                new ImageDecorator(HtmlAltTextDecorator.Id, "Alt Text", typeof(HtmlAltTextDecorator), HTML_GROUP, true, true, false, true),
                new ImageDecorator(HtmlImageResizeDecorator.Id, "Embedded Size", typeof(HtmlImageResizeDecorator), HTML_GROUP, true, true, true, true),
                new ImageDecorator(HtmlImageTargetDecorator.Id, "Image Target", typeof(HtmlImageTargetDecorator), HTML_GROUP, true, true, true, true),
            });


            ImageDecoratorGroup recolor = new ImageDecoratorGroup(RECOLOR_GROUP, true,
                                                                  new ImageDecorator[] {
                new ImageDecorator(NoRecolorDecorator.Id, Res.Get(StringId.DecoratorNoRecolorLabel), typeof(NoRecolorDecorator), RECOLOR_GROUP, false, true, false, false),
                new ImageDecorator(BlackandWhiteDecorator.Id, Res.Get(StringId.DecoratorBWLabel), typeof(BlackandWhiteDecorator), RECOLOR_GROUP, false, true, false, false),
                new ImageDecorator(SepiaToneDecorator.Id, Res.Get(StringId.DecoratorSepiaLabel), typeof(SepiaToneDecorator), RECOLOR_GROUP, false, true, false, false),
                new ImageDecorator(SaturationDecorator.Id, Res.Get(StringId.DecoratorSaturationLabel), typeof(SaturationDecorator), RECOLOR_GROUP, false, true, false, false),
                new ImageDecorator(CoolestDecorator.Id, Res.Get(StringId.DecoratorCoolestTemperatureLabel), typeof(CoolestDecorator), RECOLOR_GROUP, false, true, false, false),
                new ImageDecorator(CoolDecorator.Id, Res.Get(StringId.DecoratorCoolTemperatureLabel), typeof(CoolDecorator), RECOLOR_GROUP, false, true, false, false),
                new ImageDecorator(WarmDecorator.Id, Res.Get(StringId.DecoratorWarmTemperatureLabel), typeof(WarmDecorator), RECOLOR_GROUP, false, true, false, false),
                new ImageDecorator(WarmestDecorator.Id, Res.Get(StringId.DecoratorWarmestTemperatureLabel), typeof(WarmestDecorator), RECOLOR_GROUP, false, true, false, false)
            });

            ImageDecoratorGroup sharpen = new ImageDecoratorGroup(SHARPEN_GROUP, true,
                                                                  new ImageDecorator[] {
                new ImageDecorator(NoSharpenDecorator.Id, Res.Get(StringId.DecoratorNoSharpenLabel), typeof(NoSharpenDecorator), SHARPEN_GROUP, false, true, false, false),
                new ImageDecorator(SharpenDecorator.Id, Res.Get(StringId.DecoratorSharpenLabel), typeof(SharpenDecorator), SHARPEN_GROUP, false, true, false, false)
            });

            ImageDecoratorGroup blur = new ImageDecoratorGroup(BLUR_GROUP, true,
                                                               new ImageDecorator[] {
                new ImageDecorator(NoBlurDecorator.Id, Res.Get(StringId.DecoratorNoBlurLabel), typeof(NoBlurDecorator), BLUR_GROUP, false, true, false, false),
                new ImageDecorator(BlurDecorator.Id, Res.Get(StringId.DecoratorGaussianBlurLabel), typeof(BlurDecorator), BLUR_GROUP, false, true, false, false)
            });

            ImageDecoratorGroup emboss = new ImageDecoratorGroup(EMBOSS_GROUP, true,
                                                                 new ImageDecorator[] {
                new ImageDecorator(NoEmbossDecorator.Id, Res.Get(StringId.DecoratorNoEmbossLabel), typeof(NoEmbossDecorator), EMBOSS_GROUP, false, true, false, false),
                new ImageDecorator(EmbossDecorator.Id, Res.Get(StringId.DecoratorEmbossLabel), typeof(EmbossDecorator), EMBOSS_GROUP, false, true, false, false)
            });

            ImageDecoratorGroup[] groups = new ImageDecoratorGroup[] { basic, colors, html, borders, recolor, sharpen, blur, emboss };
            foreach (ImageDecoratorGroup group in groups)
            {
                _imageDecoratorGroups[group.GroupName] = group;
                foreach (ImageDecorator decorator in group.ImageDecorators)
                {
                    _decorators[decorator.Id] = decorator;
                }
            }

            _groups = groups;

            //load the custom image decorator plugins
            RegisterImageDecoratorPlugins();

            //load the image decorator commands
            InitializeCommands();

            if (!includeInheritBorder)
            {
                borders.ImageDecorators[0].Command.On = false;
            }
        }
        protected ImageDecorator EnforceOneDecoratorForGroup(ImageDecoratorGroup group)
        {
            List<ImageDecorator> groupDecorators = new List<ImageDecorator>(group.ImageDecorators);
            List<ImageDecorator> activeDecorators = _decoratorsList.FindAll(d => groupDecorators.Contains(d));
            for (int i = 0; i < activeDecorators.Count - 1; i++)
                _RemoveDecorator(activeDecorators[i]);

            if (activeDecorators.Count == 0)
                return null;
            else
                return activeDecorators[activeDecorators.Count - 1];
        }
        public ImageDecoratorsManager(IContainer components, CommandManager commandManager, bool includeInheritBorder)
        {
            this.components = components;
            CommandManager = commandManager;
            //load the default image decorators
            ImageDecoratorGroup basic = new ImageDecoratorGroup(BASIC_GROUP, false,
                new ImageDecorator[] {
                                         new ImageDecorator(CropDecorator.Id, "Crop", typeof(CropDecorator), BASIC_GROUP, true, true, false, false)
                                     });
            ImageDecoratorGroup borders = new ImageDecoratorGroup(BORDER_GROUP, true,
                new ImageDecorator[] {
                                         new ImageDecorator(HtmlBorderDecorator.Id, Res.Get(StringId.DecoratorInheritBorder), typeof(HtmlBorderDecorator), BORDER_GROUP, true, false, true, true),
                                         new ImageDecorator(NoBorderDecorator.Id, Res.Get(StringId.DecoratorNoBorder), typeof(NoBorderDecorator), BORDER_GROUP, true, false, true, true),
                                         new ImageDecorator(DropShadowBorderDecorator.Id, Res.Get(StringId.DecoratorDropShadow), typeof(DropShadowBorderDecorator), BORDER_GROUP, true, false, true, false),
                                         new ImageDecorator(PolaroidBorderDecorator.Id, Res.Get(StringId.DecoratorInstantPhoto), typeof(PolaroidBorderDecorator), BORDER_GROUP, true, false, true, false),
                                         new ImageDecorator(PhotoBorderDecorator.Id, Res.Get(StringId.DecoratorPhotopaper), typeof(PhotoBorderDecorator), BORDER_GROUP, true, false, true, false),
                                         new ImageDecorator(ReflectionBorderDecorator.Id, Res.Get(StringId.DecoratorReflection), typeof(ReflectionBorderDecorator), BORDER_GROUP, true, false, true, false),
                                         new ImageDecorator(RoundedCornersBorderDecorator.Id, Res.Get(StringId.DecoratorRoundedCorners), typeof(RoundedCornersBorderDecorator), BORDER_GROUP, true, false, true, false),
                                         //new ImageDecorator(SoftShadowBorderDecorator.Id, "Soft Shadow", typeof(SoftShadowBorderDecorator), true, false, true, false),
                                         new ImageDecorator(ThinSolidBorderDecorator.Id, Res.Get(StringId.DecoratorSolid1px), typeof(ThinSolidBorderDecorator), BORDER_GROUP, true, false, true, false),
                                         new ImageDecorator(ThickSolidBorderDecorator.Id, Res.Get(StringId.DecoratorSolid3px), typeof(ThickSolidBorderDecorator), BORDER_GROUP, true, false, true, false),
            });
            ImageDecoratorGroup colors = new ImageDecoratorGroup(ADJUST_COLOR_GROUP, false,
                new ImageDecorator[] {
                                         new ImageDecorator(BrightnessDecorator.Id, "Brightness/Contrast", typeof(BrightnessDecorator), ADJUST_COLOR_GROUP, true, true, false, false),
                                         new ImageDecorator(TiltDecorator.Id, "Tilt", typeof(TiltDecorator), ADJUST_COLOR_GROUP, true, true, false, false),
                                         new ImageDecorator(WatermarkDecorator.Id, "Watermark", typeof(WatermarkDecorator), ADJUST_COLOR_GROUP, true, true, true, false)
                                     });
            ImageDecoratorGroup html = new ImageDecoratorGroup(HTML_GROUP, false,
                new ImageDecorator[] {
                                         new ImageDecorator(HtmlMarginDecorator.Id, "Margin", typeof(HtmlMarginDecorator), HTML_GROUP, true, true, true, true),
                                         new ImageDecorator(HtmlAlignDecorator.Id, "Text Wrapping", typeof(HtmlAlignDecorator), HTML_GROUP, true, true, true, true),
                                         new ImageDecorator(HtmlAltTextDecorator.Id, "Alt Text", typeof(HtmlAltTextDecorator), HTML_GROUP, true, true, false, true),
                                         new ImageDecorator(HtmlImageResizeDecorator.Id, "Embedded Size", typeof(HtmlImageResizeDecorator), HTML_GROUP, true, true, true, true),
                                         new ImageDecorator(HtmlImageTargetDecorator.Id, "Image Target", typeof(HtmlImageTargetDecorator), HTML_GROUP, true, true, true, true),
            });

            ImageDecoratorGroup recolor = new ImageDecoratorGroup(RECOLOR_GROUP, true,
                new ImageDecorator[] {
                                        new ImageDecorator(NoRecolorDecorator.Id, Res.Get(StringId.DecoratorNoRecolorLabel), typeof(NoRecolorDecorator), RECOLOR_GROUP, false, true, false, false),
                                        new ImageDecorator(BlackandWhiteDecorator.Id, Res.Get(StringId.DecoratorBWLabel), typeof(BlackandWhiteDecorator), RECOLOR_GROUP, false, true, false, false),
                                        new ImageDecorator(SepiaToneDecorator.Id, Res.Get(StringId.DecoratorSepiaLabel), typeof(SepiaToneDecorator), RECOLOR_GROUP, false, true, false, false),
                                        new ImageDecorator(SaturationDecorator.Id, Res.Get(StringId.DecoratorSaturationLabel), typeof(SaturationDecorator), RECOLOR_GROUP, false, true, false, false),
                                        new ImageDecorator(CoolestDecorator.Id, Res.Get(StringId.DecoratorCoolestTemperatureLabel), typeof(CoolestDecorator), RECOLOR_GROUP, false, true, false, false),
                                        new ImageDecorator(CoolDecorator.Id, Res.Get(StringId.DecoratorCoolTemperatureLabel), typeof(CoolDecorator), RECOLOR_GROUP, false, true, false, false),
                                        new ImageDecorator(WarmDecorator.Id, Res.Get(StringId.DecoratorWarmTemperatureLabel), typeof(WarmDecorator), RECOLOR_GROUP, false, true, false, false),
                                        new ImageDecorator(WarmestDecorator.Id, Res.Get(StringId.DecoratorWarmestTemperatureLabel), typeof(WarmestDecorator), RECOLOR_GROUP, false, true, false, false)
                                     });

            ImageDecoratorGroup sharpen = new ImageDecoratorGroup(SHARPEN_GROUP, true,
                new ImageDecorator[] {
                                        new ImageDecorator(NoSharpenDecorator.Id, Res.Get(StringId.DecoratorNoSharpenLabel), typeof(NoSharpenDecorator), SHARPEN_GROUP, false, true, false, false),
                                        new ImageDecorator(SharpenDecorator.Id, Res.Get(StringId.DecoratorSharpenLabel), typeof(SharpenDecorator), SHARPEN_GROUP, false, true, false, false)
                                     });

            ImageDecoratorGroup blur = new ImageDecoratorGroup(BLUR_GROUP, true,
                new ImageDecorator[] {
                                        new ImageDecorator(NoBlurDecorator.Id, Res.Get(StringId.DecoratorNoBlurLabel), typeof(NoBlurDecorator), BLUR_GROUP, false, true, false, false),
                                        new ImageDecorator(BlurDecorator.Id, Res.Get(StringId.DecoratorGaussianBlurLabel), typeof(BlurDecorator), BLUR_GROUP, false, true, false, false)
                                     });

            ImageDecoratorGroup emboss = new ImageDecoratorGroup(EMBOSS_GROUP, true,
                new ImageDecorator[] {
                                        new ImageDecorator(NoEmbossDecorator.Id, Res.Get(StringId.DecoratorNoEmbossLabel), typeof(NoEmbossDecorator), EMBOSS_GROUP, false, true, false, false),
                                        new ImageDecorator(EmbossDecorator.Id, Res.Get(StringId.DecoratorEmbossLabel), typeof(EmbossDecorator), EMBOSS_GROUP, false, true, false, false)
                                     });

            ImageDecoratorGroup[] groups = new ImageDecoratorGroup[] { basic, colors, html, borders, recolor, sharpen, blur, emboss };
            foreach (ImageDecoratorGroup group in groups)
            {
                _imageDecoratorGroups[group.GroupName] = group;
                foreach (ImageDecorator decorator in group.ImageDecorators)
                {
                    _decorators[decorator.Id] = decorator;
                }
            }

            _groups = groups;

            //load the custom image decorator plugins
            RegisterImageDecoratorPlugins();

            //load the image decorator commands
            InitializeCommands();

            if (!includeInheritBorder)
                borders.ImageDecorators[0].Command.On = false;
        }