mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-06 05:05:42 +13:00
Add context menu to surface container, update menu items on current shape style changed event so it can be updated when menu is already open
This commit is contained in:
parent
5718122407
commit
6b9d0bf379
2 changed files with 35 additions and 27 deletions
|
@ -94,6 +94,8 @@ public SurfaceForm()
|
||||||
|
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
|
components = new Container();
|
||||||
|
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
AutoScaleDimensions = new SizeF(6F, 13F);
|
AutoScaleDimensions = new SizeF(6F, 13F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
@ -413,7 +415,7 @@ protected void HideNodes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IContainer components = null;
|
public IContainer components = null;
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,7 +51,7 @@ private set
|
||||||
currentShapeType = value;
|
currentShapeType = value;
|
||||||
config.CurrentShapeType = CurrentShapeType;
|
config.CurrentShapeType = CurrentShapeType;
|
||||||
DeselectArea();
|
DeselectArea();
|
||||||
UpdateMenuShapeType();
|
OnCurrentShapeTypeChanged(CurrentShapeType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,6 +141,8 @@ public bool IsResizing
|
||||||
public bool IncludeControls { get; set; }
|
public bool IncludeControls { get; set; }
|
||||||
public int MinimumSize { get; set; } = 3;
|
public int MinimumSize { get; set; } = 3;
|
||||||
|
|
||||||
|
public event Action<ShapeType> CurrentShapeTypeChanged;
|
||||||
|
|
||||||
private RectangleRegionForm surface;
|
private RectangleRegionForm surface;
|
||||||
private SurfaceOptions config;
|
private SurfaceOptions config;
|
||||||
private ContextMenuStrip cmsContextMenu;
|
private ContextMenuStrip cmsContextMenu;
|
||||||
|
@ -150,8 +152,6 @@ public AreaManager(RectangleRegionForm surface)
|
||||||
this.surface = surface;
|
this.surface = surface;
|
||||||
config = surface.Config;
|
config = surface.Config;
|
||||||
|
|
||||||
//CurrentShapeType = config.CurrentShapeType;
|
|
||||||
|
|
||||||
ResizeManager = new ResizeManager(surface, this);
|
ResizeManager = new ResizeManager(surface, this);
|
||||||
|
|
||||||
surface.MouseDown += surface_MouseDown;
|
surface.MouseDown += surface_MouseDown;
|
||||||
|
@ -161,6 +161,9 @@ public AreaManager(RectangleRegionForm surface)
|
||||||
surface.MouseWheel += surface_MouseWheel;
|
surface.MouseWheel += surface_MouseWheel;
|
||||||
|
|
||||||
CreateContextMenu();
|
CreateContextMenu();
|
||||||
|
|
||||||
|
//CurrentShapeType = config.CurrentShapeType;
|
||||||
|
CurrentShapeType = ShapeType.RegionRectangle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void surface_MouseWheel(object sender, MouseEventArgs e)
|
private void surface_MouseWheel(object sender, MouseEventArgs e)
|
||||||
|
@ -177,7 +180,7 @@ private void surface_MouseWheel(object sender, MouseEventArgs e)
|
||||||
|
|
||||||
private void CreateContextMenu()
|
private void CreateContextMenu()
|
||||||
{
|
{
|
||||||
cmsContextMenu = new ContextMenuStrip();
|
cmsContextMenu = new ContextMenuStrip(surface.components);
|
||||||
|
|
||||||
ToolStripMenuItem tsmiCancelCapture = new ToolStripMenuItem("Cancel capture");
|
ToolStripMenuItem tsmiCancelCapture = new ToolStripMenuItem("Cancel capture");
|
||||||
tsmiCancelCapture.Click += (sender, e) => surface.Close(SurfaceResult.Close);
|
tsmiCancelCapture.Click += (sender, e) => surface.Close(SurfaceResult.Close);
|
||||||
|
@ -393,9 +396,18 @@ private void CreateContextMenu()
|
||||||
tsmiShowCrosshair.Click += (sender, e) => config.ShowCrosshair = tsmiShowCrosshair.Checked;
|
tsmiShowCrosshair.Click += (sender, e) => config.ShowCrosshair = tsmiShowCrosshair.Checked;
|
||||||
tsmiOptions.DropDownItems.Add(tsmiShowCrosshair);
|
tsmiOptions.DropDownItems.Add(tsmiShowCrosshair);
|
||||||
|
|
||||||
cmsContextMenu.Opening += (sender, e) =>
|
CurrentShapeTypeChanged += shapeType =>
|
||||||
{
|
{
|
||||||
switch (CurrentShapeType)
|
foreach (ToolStripMenuItem tsmi in cmsContextMenu.Items.OfType<ToolStripMenuItem>().Where(x => x.Tag is ShapeType))
|
||||||
|
{
|
||||||
|
if ((ShapeType)tsmi.Tag == shapeType)
|
||||||
|
{
|
||||||
|
tsmi.RadioCheck();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (shapeType)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
tssShapeOptions.Visible = false;
|
tssShapeOptions.Visible = false;
|
||||||
|
@ -413,7 +425,7 @@ private void CreateContextMenu()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (CurrentShapeType)
|
switch (shapeType)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
tsmiBorderColor.Visible = false;
|
tsmiBorderColor.Visible = false;
|
||||||
|
@ -429,7 +441,7 @@ private void CreateContextMenu()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (CurrentShapeType)
|
switch (shapeType)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
tsmiFillColor.Visible = false;
|
tsmiFillColor.Visible = false;
|
||||||
|
@ -441,10 +453,10 @@ private void CreateContextMenu()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
tslnudRoundedRectangleRadius.Visible = CurrentShapeType == ShapeType.RegionRoundedRectangle || CurrentShapeType == ShapeType.DrawingRoundedRectangle;
|
tslnudRoundedRectangleRadius.Visible = shapeType == ShapeType.RegionRoundedRectangle || shapeType == ShapeType.DrawingRoundedRectangle;
|
||||||
tslnudBlurRadius.Visible = CurrentShapeType == ShapeType.DrawingBlur;
|
tslnudBlurRadius.Visible = shapeType == ShapeType.DrawingBlur;
|
||||||
tslnudPixelateSize.Visible = CurrentShapeType == ShapeType.DrawingPixelate;
|
tslnudPixelateSize.Visible = shapeType == ShapeType.DrawingPixelate;
|
||||||
tsmiHighlightColor.Visible = CurrentShapeType == ShapeType.DrawingHighlight;
|
tsmiHighlightColor.Visible = shapeType == ShapeType.DrawingHighlight;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -848,20 +860,6 @@ private void UpdateShape(BaseShape shape)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateMenuShapeType()
|
|
||||||
{
|
|
||||||
foreach (ToolStripMenuItem tsmi in cmsContextMenu.Items.OfType<ToolStripMenuItem>().Where(x => x.Tag is ShapeType))
|
|
||||||
{
|
|
||||||
ShapeType shapeType = (ShapeType)tsmi.Tag;
|
|
||||||
|
|
||||||
if (shapeType == CurrentShapeType)
|
|
||||||
{
|
|
||||||
tsmi.RadioCheck();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SelectArea()
|
private void SelectArea()
|
||||||
{
|
{
|
||||||
if (!CurrentRectangle.IsEmpty && !config.IsFixedSize)
|
if (!CurrentRectangle.IsEmpty && !config.IsFixedSize)
|
||||||
|
@ -958,5 +956,13 @@ public Rectangle CombineAreas()
|
||||||
|
|
||||||
return Rectangle.Empty;
|
return Rectangle.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnCurrentShapeTypeChanged(ShapeType shapeType)
|
||||||
|
{
|
||||||
|
if (CurrentShapeTypeChanged != null)
|
||||||
|
{
|
||||||
|
CurrentShapeTypeChanged(shapeType);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue