mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 09:33:46 -07:00
Changes to make the context menu work on multiple items
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1629 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
0398e831db
commit
08d56090c4
7 changed files with 186 additions and 127 deletions
|
@ -116,17 +116,17 @@ namespace Greenshot.Drawing {
|
||||||
graphics.DrawImage(bitmap, Bounds);
|
graphics.DrawImage(bitmap, Bounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void AddContextMenuItems(ContextMenuStrip menu) {
|
public override bool hasDefaultSize {
|
||||||
base.AddContextMenuItems(menu);
|
get {
|
||||||
ToolStripMenuItem resetItem = new ToolStripMenuItem("Reset size");
|
return true;
|
||||||
resetItem.Click += delegate {
|
}
|
||||||
this.Invalidate();
|
}
|
||||||
Width = Bitmap.Width;
|
|
||||||
Height = Bitmap.Height;
|
public override Size DefaultSize {
|
||||||
this.Invalidate();
|
get {
|
||||||
};
|
return bitmap.Size;
|
||||||
menu.Items.Add(resetItem);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,11 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ShowContextMenu(MouseEventArgs e) {
|
public override bool hasContextMenu {
|
||||||
// No context menu for the CropContainer
|
get {
|
||||||
|
// No context menu for the CropContainer
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,17 +101,11 @@ namespace Greenshot.Drawing {
|
||||||
cursor.DrawStretched(graphics, Bounds);
|
cursor.DrawStretched(graphics, Bounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void AddContextMenuItems(ContextMenuStrip menu) {
|
public override Size DefaultSize {
|
||||||
base.AddContextMenuItems(menu);
|
get {
|
||||||
ToolStripMenuItem resetItem = new ToolStripMenuItem("Reset size");
|
return cursor.Size;
|
||||||
resetItem.Click += delegate {
|
}
|
||||||
this.Invalidate();
|
|
||||||
Width = cursor.Size.Width;
|
|
||||||
Height = cursor.Size.Height;
|
|
||||||
this.Invalidate();
|
|
||||||
};
|
|
||||||
menu.Items.Add(resetItem);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ using Greenshot.Plugin;
|
||||||
using GreenshotPlugin.Core;
|
using GreenshotPlugin.Core;
|
||||||
using Greenshot.Plugin.Drawing;
|
using Greenshot.Plugin.Drawing;
|
||||||
using Greenshot.Memento;
|
using Greenshot.Memento;
|
||||||
using IniFile;
|
|
||||||
|
|
||||||
namespace Greenshot.Drawing {
|
namespace Greenshot.Drawing {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -44,8 +43,6 @@ namespace Greenshot.Drawing {
|
||||||
[Serializable()]
|
[Serializable()]
|
||||||
public abstract class DrawableContainer : AbstractFieldHolderWithChildren, INotifyPropertyChanged, IDrawableContainer {
|
public abstract class DrawableContainer : AbstractFieldHolderWithChildren, INotifyPropertyChanged, IDrawableContainer {
|
||||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(DrawableContainer));
|
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<CoreConfiguration>();
|
|
||||||
|
|
||||||
private bool isMadeUndoable = false;
|
private bool isMadeUndoable = false;
|
||||||
|
|
||||||
|
@ -598,95 +595,21 @@ namespace Greenshot.Drawing {
|
||||||
return ScaleHelper.ShapeAngleRoundBehavior.Instance;
|
return ScaleHelper.ShapeAngleRoundBehavior.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public virtual bool hasContextMenu {
|
||||||
/// Add items to a context menu for the selected item
|
get {
|
||||||
/// </summary>
|
return true;
|
||||||
/// <param name="menu"></param>
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
// 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) {
|
public virtual bool hasDefaultSize {
|
||||||
if (conf.isExperimentalFeatureEnabled("Contextmenu")) {
|
get {
|
||||||
ContextMenuStrip menu = new ContextMenuStrip();
|
return false;
|
||||||
AddContextMenuItems(menu);
|
}
|
||||||
if (menu.Items.Count > 0) {
|
}
|
||||||
menu.Show(parent, e.Location);
|
|
||||||
}
|
public virtual Size DefaultSize {
|
||||||
|
get {
|
||||||
|
throw new NotSupportedException("Object doesn't have a default size");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,11 @@ using Greenshot.Drawing.Fields;
|
||||||
using Greenshot.Memento;
|
using Greenshot.Memento;
|
||||||
using Greenshot.Plugin;
|
using Greenshot.Plugin;
|
||||||
using Greenshot.Plugin.Drawing;
|
using Greenshot.Plugin.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using GreenshotPlugin.Core;
|
||||||
|
using IniFile;
|
||||||
|
using Greenshot.Configuration;
|
||||||
|
using Greenshot.Helpers;
|
||||||
|
|
||||||
namespace Greenshot.Drawing {
|
namespace Greenshot.Drawing {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -32,7 +37,9 @@ namespace Greenshot.Drawing {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable()]
|
[Serializable()]
|
||||||
public class DrawableContainerList : List<DrawableContainer> {
|
public class DrawableContainerList : List<DrawableContainer> {
|
||||||
|
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
private static System.ComponentModel.ComponentResourceManager editorFormResources = new System.ComponentModel.ComponentResourceManager(typeof(ImageEditorForm));
|
||||||
|
|
||||||
public DrawableContainerList() {
|
public DrawableContainerList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,5 +360,133 @@ namespace Greenshot.Drawing {
|
||||||
Parent.Modified = true;
|
Parent.Modified = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add items to a context menu for the selected item
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="menu"></param>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,16 +101,16 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void AddContextMenuItems(ContextMenuStrip menu) {
|
public override bool hasDefaultSize {
|
||||||
base.AddContextMenuItems(menu);
|
get {
|
||||||
ToolStripMenuItem resetItem = new ToolStripMenuItem("Reset size");
|
return true;
|
||||||
resetItem.Click += delegate {
|
}
|
||||||
this.Invalidate();
|
}
|
||||||
Width = icon.Size.Width;
|
|
||||||
Height = icon.Size.Height;
|
public override Size DefaultSize {
|
||||||
this.Invalidate();
|
get {
|
||||||
};
|
return icon.Size;
|
||||||
menu.Items.Add(resetItem);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -579,16 +579,20 @@ namespace Greenshot.Drawing {
|
||||||
|
|
||||||
// check contextmenu
|
// check contextmenu
|
||||||
if (e.Button == MouseButtons.Right) {
|
if (e.Button == MouseButtons.Right) {
|
||||||
|
DrawableContainerList selectedList = null;
|
||||||
if (selectedElements != null && selectedElements.Count > 0) {
|
if (selectedElements != null && selectedElements.Count > 0) {
|
||||||
// ContainerList logik hier
|
selectedList = selectedElements;
|
||||||
} else {
|
} else {
|
||||||
// Single element
|
// Single element
|
||||||
DrawableContainer rightClickedContainer = elements.ClickableElementAt(mouseStart.X, mouseStart.Y);
|
DrawableContainer rightClickedContainer = elements.ClickableElementAt(mouseStart.X, mouseStart.Y);
|
||||||
if (rightClickedContainer != null) {
|
if (rightClickedContainer != null) {
|
||||||
SelectElement(rightClickedContainer);
|
selectedList = new DrawableContainerList();
|
||||||
rightClickedContainer.ShowContextMenu(e);
|
selectedList.Add(rightClickedContainer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (selectedList != null && selectedList.Count > 0) {
|
||||||
|
selectedList.ShowContextMenu(e, this);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue