CA-338829: Check the clicked item is indeed a ToolstripMenuItem.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2020-05-04 19:14:35 +01:00
parent 1d74094e5a
commit 94eeb1ddf3
4 changed files with 16 additions and 26 deletions

View File

@ -122,7 +122,8 @@ namespace XenAdmin.Controls
private void _contextMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
DefaultItem = e.ClickedItem;
if (e.ClickedItem is ToolStripMenuItem)
DefaultItem = e.ClickedItem;
}
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)

View File

@ -90,16 +90,14 @@ namespace XenAdmin.Controls
return false;
}
public bool FilterIsOn
{
get { return !toolStripMenuItemShowAll.Checked; }
}
public bool FilterIsOn => !toolStripMenuItemShowAll.Checked;
protected override void OnDropDownItemClicked(ToolStripItemClickedEventArgs e)
{
base.OnDropDownItemClicked(e);
var menuItem = (ToolStripMenuItem)e.ClickedItem;
if (!(e.ClickedItem is ToolStripMenuItem menuItem))
return;
//we do not allow unchecking by clicking an already checked item
if (menuItem.Checked)
@ -131,8 +129,7 @@ namespace XenAdmin.Controls
foreach (ToolStripItem t in DropDownItems)
{
var mt = t as ToolStripMenuItem;
if (mt != null)
if (t is ToolStripMenuItem mt)
mt.Checked = false;
}

View File

@ -76,18 +76,15 @@ namespace XenAdmin.Controls.MainWindowControls
protected override void OnDropDownItemClicked(ToolStripItemClickedEventArgs e)
{
var curItem = e.ClickedItem as ToolStripMenuItem;
if (curItem != null && !curItem.Checked)
if (e.ClickedItem is ToolStripMenuItem curItem && !curItem.Checked)
{
foreach (ToolStripMenuItem item in DropDownItems)
foreach (var it in DropDownItems)
{
if (item != null)
if (it is ToolStripMenuItem item)
item.Checked = item == curItem;
}
if (NavigationViewChanged != null)
NavigationViewChanged(curItem.Tag);
NavigationViewChanged?.Invoke(curItem.Tag);
}
base.OnDropDownItemClicked(e);
}

View File

@ -83,24 +83,19 @@ namespace XenAdmin.Controls.MainWindowControls
private void dropDownButton_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
var curItem = e.ClickedItem as ToolStripMenuItem;
if (curItem == null || !curItem.Checked)
if (!(e.ClickedItem is ToolStripMenuItem curItem) || !curItem.Checked)
return;
foreach (var toolStripItem in Items)
{
var buttonItem = toolStripItem as ToolStripButton;
if (buttonItem != null && buttonItem.Checked)
if (toolStripItem is ToolStripButton buttonItem && buttonItem.Checked)
buttonItem.Checked = false;
var dropDownButton = toolStripItem as ToolStripDropDownButton;
if (dropDownButton != null && dropDownButton != curItem.OwnerItem)
if (toolStripItem is ToolStripDropDownButton dropDownButton && dropDownButton != curItem.OwnerItem)
{
foreach (ToolStripMenuItem item in dropDownButton.DropDownItems)
item.Checked = false;
foreach (var it in dropDownButton.DropDownItems)
if (it is ToolStripMenuItem item)
item.Checked = false;
}
}