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:
Jaex 2016-05-07 23:31:43 +03:00
parent 5718122407
commit 6b9d0bf379
2 changed files with 35 additions and 27 deletions

View file

@ -94,6 +94,8 @@ public SurfaceForm()
private void InitializeComponent()
{
components = new Container();
SuspendLayout();
AutoScaleDimensions = new SizeF(6F, 13F);
AutoScaleMode = AutoScaleMode.Font;
@ -413,7 +415,7 @@ protected void HideNodes()
}
}
private IContainer components = null;
public IContainer components = null;
protected override void Dispose(bool disposing)
{

View file

@ -51,7 +51,7 @@ private set
currentShapeType = value;
config.CurrentShapeType = CurrentShapeType;
DeselectArea();
UpdateMenuShapeType();
OnCurrentShapeTypeChanged(CurrentShapeType);
}
}
@ -141,6 +141,8 @@ public bool IsResizing
public bool IncludeControls { get; set; }
public int MinimumSize { get; set; } = 3;
public event Action<ShapeType> CurrentShapeTypeChanged;
private RectangleRegionForm surface;
private SurfaceOptions config;
private ContextMenuStrip cmsContextMenu;
@ -150,8 +152,6 @@ public AreaManager(RectangleRegionForm surface)
this.surface = surface;
config = surface.Config;
//CurrentShapeType = config.CurrentShapeType;
ResizeManager = new ResizeManager(surface, this);
surface.MouseDown += surface_MouseDown;
@ -161,6 +161,9 @@ public AreaManager(RectangleRegionForm surface)
surface.MouseWheel += surface_MouseWheel;
CreateContextMenu();
//CurrentShapeType = config.CurrentShapeType;
CurrentShapeType = ShapeType.RegionRectangle;
}
private void surface_MouseWheel(object sender, MouseEventArgs e)
@ -177,7 +180,7 @@ private void surface_MouseWheel(object sender, MouseEventArgs e)
private void CreateContextMenu()
{
cmsContextMenu = new ContextMenuStrip();
cmsContextMenu = new ContextMenuStrip(surface.components);
ToolStripMenuItem tsmiCancelCapture = new ToolStripMenuItem("Cancel capture");
tsmiCancelCapture.Click += (sender, e) => surface.Close(SurfaceResult.Close);
@ -393,9 +396,18 @@ private void CreateContextMenu()
tsmiShowCrosshair.Click += (sender, e) => config.ShowCrosshair = tsmiShowCrosshair.Checked;
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:
tssShapeOptions.Visible = false;
@ -413,7 +425,7 @@ private void CreateContextMenu()
break;
}
switch (CurrentShapeType)
switch (shapeType)
{
default:
tsmiBorderColor.Visible = false;
@ -429,7 +441,7 @@ private void CreateContextMenu()
break;
}
switch (CurrentShapeType)
switch (shapeType)
{
default:
tsmiFillColor.Visible = false;
@ -441,10 +453,10 @@ private void CreateContextMenu()
break;
}
tslnudRoundedRectangleRadius.Visible = CurrentShapeType == ShapeType.RegionRoundedRectangle || CurrentShapeType == ShapeType.DrawingRoundedRectangle;
tslnudBlurRadius.Visible = CurrentShapeType == ShapeType.DrawingBlur;
tslnudPixelateSize.Visible = CurrentShapeType == ShapeType.DrawingPixelate;
tsmiHighlightColor.Visible = CurrentShapeType == ShapeType.DrawingHighlight;
tslnudRoundedRectangleRadius.Visible = shapeType == ShapeType.RegionRoundedRectangle || shapeType == ShapeType.DrawingRoundedRectangle;
tslnudBlurRadius.Visible = shapeType == ShapeType.DrawingBlur;
tslnudPixelateSize.Visible = shapeType == ShapeType.DrawingPixelate;
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()
{
if (!CurrentRectangle.IsEmpty && !config.IsFixedSize)
@ -958,5 +956,13 @@ public Rectangle CombineAreas()
return Rectangle.Empty;
}
private void OnCurrentShapeTypeChanged(ShapeType shapeType)
{
if (CurrentShapeTypeChanged != null)
{
CurrentShapeTypeChanged(shapeType);
}
}
}
}