internal void RefreshMdiItems ()
{
if (this.mdi_window_list_item == null)
return;
Form parent_form = this.FindForm ();
if (parent_form == null || parent_form.MainMenuStrip != this)
return;
MdiClient mdi = parent_form.MdiContainer;
// If there isn't a MdiContainer, we don't need to worry about MdiItems :)
if (mdi == null)
return;
// Make a copy so we can delete from the real one
ToolStripItem[] loopitems = new ToolStripItem[this.mdi_window_list_item.DropDownItems.Count];
this.mdi_window_list_item.DropDownItems.CopyTo (loopitems, 0);
// If the mdi child has been removed, remove our menu item
foreach (ToolStripItem tsi in loopitems)
if (tsi is ToolStripMenuItem && (tsi as ToolStripMenuItem).IsMdiWindowListEntry)
if (!mdi.mdi_child_list.Contains ((tsi as ToolStripMenuItem).MdiClientForm) || !(tsi as ToolStripMenuItem).MdiClientForm.Visible)
this.mdi_window_list_item.DropDownItems.Remove (tsi);
// Add the new forms and update state
for (int i = 0; i < mdi.mdi_child_list.Count; i++) {
Form mdichild = (Form)mdi.mdi_child_list[i];
ToolStripMenuItem tsi;
if (!mdichild.Visible)
continue;
if ((tsi = FindMdiMenuItemOfForm (mdichild)) == null) {
if (CountMdiMenuItems () == 0 && this.mdi_window_list_item.DropDownItems.Count > 0 && !(this.mdi_window_list_item.DropDownItems[this.mdi_window_list_item.DropDownItems.Count - 1] is ToolStripSeparator))
this.mdi_window_list_item.DropDownItems.Add (new ToolStripSeparator ());
tsi = new ToolStripMenuItem ();
tsi.MdiClientForm = mdichild;
this.mdi_window_list_item.DropDownItems.Add (tsi);
}
tsi.Text = string.Format ("&{0} {1}", i + 1, mdichild.Text);
tsi.Checked = parent_form.ActiveMdiChild == mdichild;
}
// Check that everything is in the correct order
if (NeedToReorderMdi ())
ReorderMdiMenu ();
}