IndexOf() public method

public IndexOf ( ToolStripItem value ) : int
value ToolStripItem
return int
示例#1
0
        public void RecordHistory(IDataObject dataObject)
        {
            TSMenuItem item;

            if (unused.Count > 0)
            {
                item = unused.First();
                unused.Remove(item);
            }
            else
            {
                item = new TSMenuItem();
                item.DropDownItems.AddRange(new TSItem[] {
                    new TSMenuItem(Language.RestoreHistory, null, HandleUseClick)
                    {
                        Tag = item
                    },
                    new TSMenuItem(Language.ForgetHistory, null, HandleRemoveClick)
                    {
                        Tag = item
                    },
                    new TSSeparator(),
                });
            }
            ClipboardApplication.UpdateDisplay(dataObject, item);
            item.Tag     = CloneDataObject(dataObject);
            item.Enabled = true;
            root.Insert(root.IndexOf(index) + 1, item);
            list.Add(item);
            UpdateClearEnabled();
        }
        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);
            }
        }
示例#3
0
        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();
        }
示例#4
0
        // Maintains separators between different command groups
        private void MaintainSeparateGroups(ToolStripItemCollection commands, ToolStripItem item, object groupTag)
        {
            int index = commands.IndexOf(item);
            if (index > 0) // look for previous item
            {
                ToolStripItem prevItem = commands[index - 1];
                object prevTag = prevItem.Tag;
                while (prevTag == null)
                {
                    ToolStripMenuItem prevMenuItem = prevItem as ToolStripMenuItem;
                    if (prevMenuItem == null)
                        break;
                    ToolStripItemCollection prevItems = prevMenuItem.DropDownItems;
                    prevItem = prevItems[prevItems.Count - 1];
                    prevTag = prevItem.Tag;
                }

                // add a separator if the new command is from a different group
                CommandInfo prevInfo = GetCommandInfo(prevTag);
                if (prevInfo != null &&
                    !TagsEqual(groupTag, prevInfo.GroupTag))
                {
                    commands.Insert(index, new ToolStripSeparator());
                }
            }
        }
示例#5
0
 private void SetPreviewControlItems(ToolStripItemCollection dropdown, ToolStripItem tss, string prefix, IEnumerable<ToolStripItem> items)
 {
     int i = dropdown.Count - 1;
     int j = dropdown.Count - dropdown.IndexOf(tss);
     foreach (var item in items)
     {
         item.Name = prefix + (++j);
         dropdown.Insert(++i, item);
     }
 }
示例#6
0
        private void SetHelpers(ToolStripItemCollection dropdown, ToolStripItem tss, string prefix, IEnumerable<s3pi.Helpers.HelperManager.Helper> helpers)
        {
            if (helpers.Count() == 0) return;

            int i = dropdown.IndexOf(tss);
            int j = 0;

            dropdown.Insert(++i, new ToolStripSeparator() { Name = prefix + j, });

            foreach (var helper in helpers)
            {
                ToolStripMenuItem tsiHelper = new ToolStripMenuItem(helper.label, null, tsHelper_Click) { Name = prefix + j, Tag = j++, };
                dropdown.Insert(++i, tsiHelper);
            }
        }
示例#7
0
 private void AddHelper(ToolStripItemCollection dropdown, ToolStripItem tss, string prefix, int helper, string value)
 {
     ToolStripMenuItem tsiHelper = new ToolStripMenuItem(value, null, tsHelper_Click) { Name = prefix + helper, Tag = helper, };
     int i = dropdown.IndexOf(tss);
     while (true)
     {
         i++;
         if (i >= dropdown.Count) break;
         if (!dropdown[i].Name.StartsWith(prefix)) break;
     }
     dropdown.Insert(i, tsiHelper);
 }
示例#8
0
 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);
     }
 }
示例#9
0
        private ToolStripItem newLoadingListToolStripItem(long listId, String index)
        {
            ToolStripMenuItem item = new ToolStripMenuItem(LL_DeserializeName(index), WarehouseApp.Properties.Resources.table, null, "l" + listId);
            item.Tag = listId;
            item.Click += new System.EventHandler(LoadingList_MoveToSelected_Click);
            Events_LoadingListButton(item);

            if (cmsLoadingLists.Tag != null)
            {
                ToolStripItemCollection col2 = new ToolStripItemCollection(cmsLoadingLists, ((ToolStripItem[])cmsLoadingLists.Tag));
                if (col2.IndexOfKey(item.Name) == -1)
                {
                    col2.Insert(col2.IndexOf(tsmiNewLL), item);
                    cmsLoadingLists.Tag = new ToolStripItem[col2.Count];
                    col2.CopyTo((ToolStripItem[])cmsLoadingLists.Tag, 0);
                }
            }

            return item;
        }