diff --git a/Greenshot/Drawing/BitmapContainer.cs b/Greenshot/Drawing/BitmapContainer.cs index e1192f940..d94b8e6e2 100644 --- a/Greenshot/Drawing/BitmapContainer.cs +++ b/Greenshot/Drawing/BitmapContainer.cs @@ -116,17 +116,17 @@ namespace Greenshot.Drawing { graphics.DrawImage(bitmap, Bounds); } } - - public override void AddContextMenuItems(ContextMenuStrip menu) { - base.AddContextMenuItems(menu); - ToolStripMenuItem resetItem = new ToolStripMenuItem("Reset size"); - resetItem.Click += delegate { - this.Invalidate(); - Width = Bitmap.Width; - Height = Bitmap.Height; - this.Invalidate(); - }; - menu.Items.Add(resetItem); + + public override bool hasDefaultSize { + get { + return true; + } + } + + public override Size DefaultSize { + get { + return bitmap.Size; + } } } } diff --git a/Greenshot/Drawing/CropContainer.cs b/Greenshot/Drawing/CropContainer.cs index 1a6c39d0a..a4724df3d 100644 --- a/Greenshot/Drawing/CropContainer.cs +++ b/Greenshot/Drawing/CropContainer.cs @@ -57,8 +57,11 @@ namespace Greenshot.Drawing { } } - public override void ShowContextMenu(MouseEventArgs e) { - // No context menu for the CropContainer + public override bool hasContextMenu { + get { + // No context menu for the CropContainer + return false; + } } } } diff --git a/Greenshot/Drawing/CursorContainer.cs b/Greenshot/Drawing/CursorContainer.cs index 0b6d8dde3..b03888555 100644 --- a/Greenshot/Drawing/CursorContainer.cs +++ b/Greenshot/Drawing/CursorContainer.cs @@ -101,17 +101,11 @@ namespace Greenshot.Drawing { cursor.DrawStretched(graphics, Bounds); } } - - public override void AddContextMenuItems(ContextMenuStrip menu) { - base.AddContextMenuItems(menu); - ToolStripMenuItem resetItem = new ToolStripMenuItem("Reset size"); - resetItem.Click += delegate { - this.Invalidate(); - Width = cursor.Size.Width; - Height = cursor.Size.Height; - this.Invalidate(); - }; - menu.Items.Add(resetItem); + + public override Size DefaultSize { + get { + return cursor.Size; + } } } } diff --git a/Greenshot/Drawing/DrawableContainer.cs b/Greenshot/Drawing/DrawableContainer.cs index 8bb41cce8..abcbdd30f 100644 --- a/Greenshot/Drawing/DrawableContainer.cs +++ b/Greenshot/Drawing/DrawableContainer.cs @@ -32,7 +32,6 @@ using Greenshot.Plugin; using GreenshotPlugin.Core; using Greenshot.Plugin.Drawing; using Greenshot.Memento; -using IniFile; namespace Greenshot.Drawing { /// @@ -44,8 +43,6 @@ namespace Greenshot.Drawing { [Serializable()] public abstract class DrawableContainer : AbstractFieldHolderWithChildren, INotifyPropertyChanged, IDrawableContainer { private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(DrawableContainer)); - private static System.ComponentModel.ComponentResourceManager editorFormResources = new System.ComponentModel.ComponentResourceManager(typeof(ImageEditorForm)); - private static CoreConfiguration conf = IniConfig.GetIniSection(); private bool isMadeUndoable = false; @@ -598,95 +595,21 @@ namespace Greenshot.Drawing { return ScaleHelper.ShapeAngleRoundBehavior.Instance; } - /// - /// Add items to a context menu for the selected item - /// - /// - public virtual void AddContextMenuItems(ContextMenuStrip menu) { - DrawableContainerList myselfAsList = new DrawableContainerList(); - myselfAsList.Add(this); - ILanguage lang = Language.GetInstance(); - bool push = parent.Elements.CanPushDown(myselfAsList); - bool pull = parent.Elements.CanPullUp(myselfAsList); - - ToolStripMenuItem item; - - // Pull "up" - if (pull) { - item = new ToolStripMenuItem(lang.GetString(LangKey.editor_uptotop)); - item.Click += delegate { - parent.Elements.PullElementsToTop(myselfAsList); - parent.Elements.Invalidate(); - }; - menu.Items.Add(item); - item = new ToolStripMenuItem(lang.GetString(LangKey.editor_uponelevel)); - item.Click += delegate { - parent.Elements.PullElementsUp(myselfAsList); - parent.Elements.Invalidate(); - }; - menu.Items.Add(item); + public virtual bool hasContextMenu { + get { + return true; } - // Push "down" - if (push) { - item = new ToolStripMenuItem(lang.GetString(LangKey.editor_downtobottom)); - item.Click += delegate { - parent.Elements.PushElementsToBottom(myselfAsList); - parent.Elements.Invalidate(); - }; - menu.Items.Add(item); - item = new ToolStripMenuItem(lang.GetString(LangKey.editor_downonelevel)); - item.Click += delegate { - parent.Elements.PushElementsDown(myselfAsList); - parent.Elements.Invalidate(); - }; - menu.Items.Add(item); - } - - // Duplicate - item = new ToolStripMenuItem(lang.GetString(LangKey.editor_duplicate)); - item.Click += delegate { - DrawableContainerList dcs = myselfAsList.Clone(); - dcs.Parent = parent; - dcs.MoveBy(10,10); - parent.AddElements(dcs); - parent.DeselectAllElements(); - parent.SelectElements(dcs); - }; - menu.Items.Add(item); - - // Copy - item = new ToolStripMenuItem(lang.GetString(LangKey.editor_copytoclipboard)); - item.Image = ((System.Drawing.Image)(editorFormResources.GetObject("copyToolStripMenuItem.Image"))); - item.Click += delegate { - ClipboardHelper.SetClipboardData(typeof(DrawableContainerList), myselfAsList); - }; - menu.Items.Add(item); - - // Cut - item = new ToolStripMenuItem(lang.GetString(LangKey.editor_cuttoclipboard)); - item.Image = ((System.Drawing.Image)(editorFormResources.GetObject("editor_cuttoclipboard.Image"))); - item.Click += delegate { - ClipboardHelper.SetClipboardData(typeof(DrawableContainerList), myselfAsList); - parent.RemoveElement(this, true); - }; - menu.Items.Add(item); - - // Delete - item = new ToolStripMenuItem(lang.GetString(LangKey.editor_deleteelement)); - item.Image = ((System.Drawing.Image)(editorFormResources.GetObject("removeObjectToolStripMenuItem.Image"))); - item.Click += delegate { - parent.RemoveElement(this, true); - }; - menu.Items.Add(item); } - public virtual void ShowContextMenu(MouseEventArgs e) { - if (conf.isExperimentalFeatureEnabled("Contextmenu")) { - ContextMenuStrip menu = new ContextMenuStrip(); - AddContextMenuItems(menu); - if (menu.Items.Count > 0) { - menu.Show(parent, e.Location); - } + public virtual bool hasDefaultSize { + get { + return false; + } + } + + public virtual Size DefaultSize { + get { + throw new NotSupportedException("Object doesn't have a default size"); } } } diff --git a/Greenshot/Drawing/DrawableContainerList.cs b/Greenshot/Drawing/DrawableContainerList.cs index c4c933c3b..3ddb09acf 100644 --- a/Greenshot/Drawing/DrawableContainerList.cs +++ b/Greenshot/Drawing/DrawableContainerList.cs @@ -25,6 +25,11 @@ using Greenshot.Drawing.Fields; using Greenshot.Memento; using Greenshot.Plugin; using Greenshot.Plugin.Drawing; +using System.Windows.Forms; +using GreenshotPlugin.Core; +using IniFile; +using Greenshot.Configuration; +using Greenshot.Helpers; namespace Greenshot.Drawing { /// @@ -32,7 +37,9 @@ namespace Greenshot.Drawing { /// [Serializable()] public class DrawableContainerList : List { - + private static CoreConfiguration conf = IniConfig.GetIniSection(); + private static System.ComponentModel.ComponentResourceManager editorFormResources = new System.ComponentModel.ComponentResourceManager(typeof(ImageEditorForm)); + public DrawableContainerList() { } @@ -353,5 +360,133 @@ namespace Greenshot.Drawing { Parent.Modified = true; } } + + /// + /// Add items to a context menu for the selected item + /// + /// + public virtual void AddContextMenuItems(ContextMenuStrip menu, Surface surface) { + ILanguage lang = Language.GetInstance(); + bool push = surface.Elements.CanPushDown(this); + bool pull = surface.Elements.CanPullUp(this); + + ToolStripMenuItem item; + + // Pull "up" + if (pull) { + item = new ToolStripMenuItem(lang.GetString(LangKey.editor_uptotop)); + item.Click += delegate { + surface.Elements.PullElementsToTop(this); + surface.Elements.Invalidate(); + }; + menu.Items.Add(item); + item = new ToolStripMenuItem(lang.GetString(LangKey.editor_uponelevel)); + item.Click += delegate { + surface.Elements.PullElementsUp(this); + surface.Elements.Invalidate(); + }; + menu.Items.Add(item); + } + // Push "down" + if (push) { + item = new ToolStripMenuItem(lang.GetString(LangKey.editor_downtobottom)); + item.Click += delegate { + surface.Elements.PushElementsToBottom(this); + surface.Elements.Invalidate(); + }; + menu.Items.Add(item); + item = new ToolStripMenuItem(lang.GetString(LangKey.editor_downonelevel)); + item.Click += delegate { + surface.Elements.PushElementsDown(this); + surface.Elements.Invalidate(); + }; + menu.Items.Add(item); + } + + // Duplicate + item = new ToolStripMenuItem(lang.GetString(LangKey.editor_duplicate)); + item.Click += delegate { + DrawableContainerList dcs = this.Clone(); + dcs.Parent = surface; + dcs.MoveBy(10, 10); + surface.AddElements(dcs); + surface.DeselectAllElements(); + surface.SelectElements(dcs); + }; + menu.Items.Add(item); + + // Copy + item = new ToolStripMenuItem(lang.GetString(LangKey.editor_copytoclipboard)); + item.Image = ((System.Drawing.Image)(editorFormResources.GetObject("copyToolStripMenuItem.Image"))); + item.Click += delegate { + ClipboardHelper.SetClipboardData(typeof(DrawableContainerList), this); + }; + menu.Items.Add(item); + + // Cut + item = new ToolStripMenuItem(lang.GetString(LangKey.editor_cuttoclipboard)); + item.Image = ((System.Drawing.Image)(editorFormResources.GetObject("btnCut.Image"))); + item.Click += delegate { + ClipboardHelper.SetClipboardData(typeof(DrawableContainerList), this); + foreach (DrawableContainer container in this) { + surface.RemoveElement(container, true); + } + }; + menu.Items.Add(item); + + // Delete + item = new ToolStripMenuItem(lang.GetString(LangKey.editor_deleteelement)); + item.Image = ((System.Drawing.Image)(editorFormResources.GetObject("removeObjectToolStripMenuItem.Image"))); + item.Click += delegate { + foreach(DrawableContainer container in this) { + surface.RemoveElement(container, true); + } + }; + menu.Items.Add(item); + + // Reset + bool canReset = false; + foreach (DrawableContainer container in this) { + if (container.hasDefaultSize) { + canReset = true; + } + } + if (canReset) { + item = new ToolStripMenuItem("Reset size"); + //item.Image = ((System.Drawing.Image)(editorFormResources.GetObject("removeObjectToolStripMenuItem.Image"))); + item.Click += delegate { + foreach (DrawableContainer container in this) { + if (container.hasDefaultSize) { + Size defaultSize = container.DefaultSize; + container.Invalidate(); + container.MakeBoundsChangeUndoable(false); + container.Width = defaultSize.Width; + container.Height = defaultSize.Height; + container.Invalidate(); + } + } + }; + menu.Items.Add(item); + } + } + + public virtual void ShowContextMenu(MouseEventArgs e, Surface surface) { + if (conf.isExperimentalFeatureEnabled("Contextmenu")) { + bool hasMenu = false; + foreach (DrawableContainer container in this) { + if (container.hasContextMenu) { + hasMenu = true; + break; + } + } + if (hasMenu) { + ContextMenuStrip menu = new ContextMenuStrip(); + AddContextMenuItems(menu, surface); + if (menu.Items.Count > 0) { + menu.Show(surface, e.Location); + } + } + } + } } } diff --git a/Greenshot/Drawing/IconContainer.cs b/Greenshot/Drawing/IconContainer.cs index 7542a9d52..b58f1163f 100644 --- a/Greenshot/Drawing/IconContainer.cs +++ b/Greenshot/Drawing/IconContainer.cs @@ -101,16 +101,16 @@ namespace Greenshot.Drawing { } } - public override void AddContextMenuItems(ContextMenuStrip menu) { - base.AddContextMenuItems(menu); - ToolStripMenuItem resetItem = new ToolStripMenuItem("Reset size"); - resetItem.Click += delegate { - this.Invalidate(); - Width = icon.Size.Width; - Height = icon.Size.Height; - this.Invalidate(); - }; - menu.Items.Add(resetItem); + public override bool hasDefaultSize { + get { + return true; + } + } + + public override Size DefaultSize { + get { + return icon.Size; + } } } } diff --git a/Greenshot/Drawing/Surface.cs b/Greenshot/Drawing/Surface.cs index 86271c251..3709aadd8 100644 --- a/Greenshot/Drawing/Surface.cs +++ b/Greenshot/Drawing/Surface.cs @@ -579,16 +579,20 @@ namespace Greenshot.Drawing { // check contextmenu if (e.Button == MouseButtons.Right) { + DrawableContainerList selectedList = null; if (selectedElements != null && selectedElements.Count > 0) { - // ContainerList logik hier + selectedList = selectedElements; } else { // Single element DrawableContainer rightClickedContainer = elements.ClickableElementAt(mouseStart.X, mouseStart.Y); if (rightClickedContainer != null) { - SelectElement(rightClickedContainer); - rightClickedContainer.ShowContextMenu(e); + selectedList = new DrawableContainerList(); + selectedList.Add(rightClickedContainer); } } + if (selectedList != null && selectedList.Count > 0) { + selectedList.ShowContextMenu(e, this); + } return; }