private static void MergeRecursive(ToolStripItem source, ToolStripItemCollection destinationItems, Stack<MergeHistoryItem> history) { Debug.Indent(); MergeHistoryItem maction; switch (source.MergeAction) { case MergeAction.MatchOnly: case MergeAction.Replace: case MergeAction.Remove: ToolStripItem item = FindMatch(source, destinationItems); if (item != null) { switch (source.MergeAction) { case MergeAction.MatchOnly: //Debug.WriteLine("matchonly"); ToolStripDropDownItem tsddownDest = item as ToolStripDropDownItem; ToolStripDropDownItem tsddownSrc = source as ToolStripDropDownItem; if (tsddownDest != null && tsddownSrc != null && tsddownSrc.DropDownItems.Count != 0) { int originalCount = tsddownSrc.DropDownItems.Count; if (originalCount > 0) { int lastCount = originalCount; tsddownSrc.DropDown.SuspendLayout(); try { // the act of walking through this collection removes items from // the dropdown. for (int i = 0, itemToLookAt = 0; i < originalCount; i++) { MergeRecursive(tsddownSrc.DropDownItems[itemToLookAt], tsddownDest.DropDownItems, history); int numberOfItemsMerged = lastCount - tsddownSrc.DropDownItems.Count; itemToLookAt = (numberOfItemsMerged > 0) ? itemToLookAt : itemToLookAt + 1; lastCount = tsddownSrc.DropDownItems.Count; } } finally { tsddownSrc.DropDown.ResumeLayout(); } } } break; case MergeAction.Replace: case MergeAction.Remove: //Debug.WriteLine("remove"); maction = new MergeHistoryItem(MergeAction.Insert); maction.TargetItem = item; int indexOfDestinationItem = destinationItems.IndexOf(item); destinationItems.RemoveAt(indexOfDestinationItem); maction.Index = indexOfDestinationItem; maction.IndexCollection = destinationItems; maction.TargetItem = item; history.Push(maction); //Debug.WriteLine(maction.ToString()); if (source.MergeAction == MergeAction.Replace) { //Debug.WriteLine("replace"); //ToolStripItem clonedItem = source.Clone(); maction = new MergeHistoryItem(MergeAction.Remove); maction.PreviousIndexCollection = source.Owner.Items; maction.PreviousIndex = maction.PreviousIndexCollection.IndexOf(source); maction.TargetItem = source; destinationItems.Insert(indexOfDestinationItem, source); maction.Index = indexOfDestinationItem; maction.IndexCollection = destinationItems; history.Push(maction); //Debug.WriteLine(maction.ToString()); } break; } } break; case MergeAction.Insert: if (source.MergeIndex > -1) { maction = new MergeHistoryItem(MergeAction.Remove); maction.PreviousIndexCollection = source.Owner.Items; maction.PreviousIndex = maction.PreviousIndexCollection.IndexOf(source); maction.TargetItem = source; int insertIndex = Math.Min(destinationItems.Count, source.MergeIndex); destinationItems.Insert(insertIndex, source); maction.IndexCollection = destinationItems; maction.Index = insertIndex; history.Push(maction); //Debug.WriteLine(maction.ToString()); } break; case MergeAction.Append: maction = new MergeHistoryItem(MergeAction.Remove); maction.PreviousIndexCollection = source.Owner.Items; maction.PreviousIndex = maction.PreviousIndexCollection.IndexOf(source); maction.TargetItem = source; int index = destinationItems.Add(source); maction.Index = index; maction.IndexCollection = destinationItems; history.Push(maction); //Debug.WriteLine(maction.ToString()); break; } Debug.Unindent(); }
private static void MergeRecursive(ToolStripItem source, ToolStripItemCollection destinationItems, Stack<MergeHistoryItem> history) { MergeHistoryItem item; ToolStripItem item2; switch (source.MergeAction) { case MergeAction.Append: { item = new MergeHistoryItem(MergeAction.Remove) { PreviousIndexCollection = source.Owner.Items, PreviousIndex = item.PreviousIndexCollection.IndexOf(source), TargetItem = source }; int num8 = destinationItems.Add(source); item.Index = num8; item.IndexCollection = destinationItems; history.Push(item); return; } case MergeAction.Insert: if (source.MergeIndex > -1) { item = new MergeHistoryItem(MergeAction.Remove) { PreviousIndexCollection = source.Owner.Items, PreviousIndex = item.PreviousIndexCollection.IndexOf(source), TargetItem = source }; int num7 = Math.Min(destinationItems.Count, source.MergeIndex); destinationItems.Insert(num7, source); item.IndexCollection = destinationItems; item.Index = num7; history.Push(item); } return; case MergeAction.Replace: case MergeAction.Remove: case MergeAction.MatchOnly: item2 = FindMatch(source, destinationItems); if (item2 != null) { switch (source.MergeAction) { case MergeAction.MatchOnly: { ToolStripDropDownItem item3 = item2 as ToolStripDropDownItem; ToolStripDropDownItem item4 = source as ToolStripDropDownItem; if (((item3 == null) || (item4 == null)) || (item4.DropDownItems.Count == 0)) { return; } int count = item4.DropDownItems.Count; if (count <= 0) { return; } int num2 = count; item4.DropDown.SuspendLayout(); try { int num3 = 0; int num4 = 0; while (num3 < count) { MergeRecursive(item4.DropDownItems[num4], item3.DropDownItems, history); int num5 = num2 - item4.DropDownItems.Count; num4 = (num5 > 0) ? num4 : (num4 + 1); num2 = item4.DropDownItems.Count; num3++; } return; } finally { item4.DropDown.ResumeLayout(); } goto Label_0108; } } } return; default: return; } Label_0108: item = new MergeHistoryItem(MergeAction.Insert); item.TargetItem = item2; int index = destinationItems.IndexOf(item2); destinationItems.RemoveAt(index); item.Index = index; item.IndexCollection = destinationItems; item.TargetItem = item2; history.Push(item); if (source.MergeAction == MergeAction.Replace) { item = new MergeHistoryItem(MergeAction.Remove) { PreviousIndexCollection = source.Owner.Items, PreviousIndex = item.PreviousIndexCollection.IndexOf(source), TargetItem = source }; destinationItems.Insert(index, source); item.Index = index; item.IndexCollection = destinationItems; history.Push(item); } }
private void ClearHelpers(ToolStripItemCollection dropdown, ToolStripItem tss, string prefix) { int i = dropdown.IndexOf(tss) + 1; while (true) { if (i >= dropdown.Count) break; if (!dropdown[i].Name.StartsWith(prefix)) break; dropdown.RemoveAt(i); } }
private static void Clear(ToolStripItemCollection items) { while (items.Count > 2) items.RemoveAt(items.Count - 1); }
/// <summary> /// Immerge l'itemReport dans la collection cible source /// </summary> /// <param name="target">collection cible de l'immersion</param> /// <param name="sourceItem">élément à immerger dans la collection cible</param> /// <param name="kept">true si l'élément à immerger a été retenu</param> private static void DoMergeItem( ToolStripItemCollection target, ToolStripItem sourceItem, out bool kept ) { int targetMatch; // -1 ou index de l'itemReport cible mis en correspondance avec l'itemReport source int targetAnchor; // -1 ou index d'insertion éventuel dans la collection cible // recherche d'un match kept = false; targetMatch = IndexOfMatch( target, sourceItem ); switch (sourceItem.MergeAction) { // adjonction en fin de collection case MergeAction.Append: target.Add( sourceItem ); break; // insertion case MergeAction.Insert: targetAnchor = IndexOfAnchor( target, targetMatch, sourceItem.MergeIndex ); target.Insert( targetAnchor, sourceItem ); break; // fusion case MergeAction.MatchOnly: if (targetMatch != -1 && target[ targetMatch ] is ToolStripMenuItem && sourceItem is ToolStripMenuItem) { kept = true; DoMergeItems( (target[ targetMatch ] as ToolStripMenuItem).DropDownItems, (sourceItem as ToolStripMenuItem).DropDownItems ); } else { targetAnchor = IndexOfAnchor( target, targetMatch, sourceItem.MergeIndex ); target.Insert( targetAnchor, sourceItem ); } break; // suppression case MergeAction.Remove: kept = true; if (targetMatch == -1) break; target.RemoveAt( targetMatch ); break; // remplacement case MergeAction.Replace: if (targetMatch == -1) target.Add( sourceItem ); else { target.RemoveAt( targetMatch ); target.Insert( targetMatch, sourceItem ); } break; } }
////////////////////////////////////////////////////////////////////////// private void WeedSeparators(ToolStripItemCollection Items, bool RemoveSeparators) { bool PrevSeparator = true; for (int i = 0; i < Items.Count; i++) { if (!Items[i].Available) continue; if (Items[i] is ToolStripSeparator) { if (PrevSeparator) { if (RemoveSeparators) { Items.RemoveAt(i); i--; } else Items[i].Available = false; } PrevSeparator = true; } else PrevSeparator = false; } PrevSeparator = true; for (int i = Items.Count - 1; i >= 0; i--) { if (!Items[i].Available) continue; if (Items[i] is ToolStripSeparator && PrevSeparator) { if (RemoveSeparators) { Items.RemoveAt(i); } else Items[i].Available = false; } else break; } }
private int DBSelect_LoadingLists_Reset() { DataTable openedLists = new DataTable(); using (OleDbDataAdapter adapter = new OleDbDataAdapter("Select * from LoadingListOpened_View", conn)) { adapter.SelectCommand.Parameters.Add("@stock_id", OleDbType.Integer).Value = getStockId(); adapter.Fill(openedLists); } openedLists.PrimaryKey = new DataColumn[] { openedLists.Columns[openedLists.Columns.IndexOf("id")] }; //checking for contained buttons, remove not existing in db KryptonCheckButton[] buttons = new KryptonCheckButton[openedLists.Rows.Count]; ToolStripMenuItem[] items = new ToolStripMenuItem[openedLists.Rows.Count]; foreach (DataRow row in openedLists.Rows) { long listId = long.Parse(row.ItemArray[openedLists.Columns.IndexOf("id")].ToString()); string index = (string)row.ItemArray[openedLists.Columns.IndexOf("index")]; KryptonCheckButton button = CreateLoadingListButton(listId, index); if (!flpControls.Controls.ContainsKey(button.Name)) { //buttons[openedLists.Rows.IndexOf(row)] = button; flpControls.Controls.Add(button); tsmiLL.DropDownItems.Insert(tsmiLL.DropDownItems.IndexOf(tsmiHistorySeparator), newLoadingListMenuItem(listId, index)); newLoadingListToolStripItem(listId, index); } } ToolStripItemCollection col2 = new ToolStripItemCollection(cmsLoadingLists, ((ToolStripItem[])cmsLoadingLists.Tag)); foreach (Control control in flpControls.Controls) { if (!openedLists.Rows.Contains(control.Tag)) { flpControls.Controls.RemoveAt(flpControls.Controls.IndexOfKey(control.Name)); col2.RemoveAt(col2.IndexOfKey(csLoadingList.CheckedButton.Name)); col2.CopyTo((ToolStripItem[])cmsLoadingLists.Tag, 0); tsmiLL.DropDownItems.RemoveAt(tsmiLL.DropDownItems.IndexOfKey(control.Name)); } } //flpControls.Controls.AddRange(buttons); return openedLists.Rows.Count; }