private static void ClearItems(ContextMenuStrip menu, IVCMenuItems menuItems)
 {
     RemoveItem(menuItems.Add);
     RemoveItem(menuItems.Commit);
     RemoveItem(menuItems.Diff);
     RemoveItem(menuItems.DiffChange);
     RemoveItem(menuItems.EditConflict);
     RemoveItem(menuItems.MidSeparator);
     RemoveItem(menuItems.Revert);
     RemoveItem(menuItems.UndoAdd);
     RemoveItem(menuItems.Update);
     RemoveItem(menuItems.Ignore);
 }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TfsManager"/> class.
        /// </summary>
        /// <param name="pluginMain">The plugin main.</param>
        /// <remarks>Documented by CFI, 2011-01-05</remarks>
        public TfsManager(PluginMain pluginMain)
        {
            this.pluginMain = pluginMain;

            pluginUI                 = new PluginUI(this);
            pluginUI.Text            = "Pending Changes";
            pluginPanel              = PluginBase.MainForm.CreateDockablePanel(pluginUI, pluginMain.Guid, Resources.icon, DockState.DockBottomAutoHide);
            pluginPanel.FormClosing += new FormClosingEventHandler(pluginPanel_FormClosing);

            ToolStripMenuItem viewMenu = (ToolStripMenuItem)PluginBase.MainForm.FindMenuItem("ViewMenu");

            viewMenu.DropDownItems.Add(new ToolStripMenuItem("Pending Changes", Resources.icon, new EventHandler(this.OpenPanel)));

            menuItems   = new MenuItems();
            fileActions = new FileActions(this);
        }
        static internal void SetMenu(ProjectTreeView tree, ProjectSelectionState state)
        {
            if (tree == null || state.Manager == null)
            {
                return;
            }

            IVCMenuItems menuItems = state.Manager.MenuItems;

            menuItems.CurrentNodes   = (TreeNode[])tree.SelectedNodes.ToArray(typeof(TreeNode));
            menuItems.CurrentManager = state.Manager;

            AddSCMainItem(tree);
            scItem.DropDownItems.Clear();

            // let a VC provide a completely custom items list
            foreach (KeyValuePair <ToolStripItem, VCMenuItemProperties> item in menuItems.Items)
            {
                if (item.Value.Show.Invoke(state))
                {
                    scItem.DropDownItems.Add(item.Key);
                    if (item.Value.Enable != null)
                    {
                        item.Key.Enabled = item.Value.Enable.Invoke(state);
                    }
                }
            }

            // classical VC menu items
            if (menuItems != null)
            {
                List <ToolStripItem> items = new List <ToolStripItem>();

                // generic
                items.Add(menuItems.Update);
                items.Add(menuItems.Commit);
                items.Add(menuItems.Push);
                items.Add(menuItems.ShowLog);
                int minLen = items.Count;

                // specific
                if (state.Files == 1 && state.Total == 1)
                {
                    items.Add(menuItems.Annotate);
                }

                if (state.Files == 2 && state.Total == 2)
                {
                    items.Add(menuItems.Diff);
                }
                if (state.Conflict == 1 && state.Total == 1)
                {
                    items.Add(menuItems.EditConflict);
                }

                if (state.Unknown + state.Ignored > 0 || state.Dirs > 0)
                {
                    items.Add(menuItems.Add);
                }
                if (state.Unknown + state.Ignored == state.Total)
                {
                    items.Add(menuItems.Ignore);
                }

                if (state.Unknown + state.Ignored < state.Total)
                {
                    if (state.Added > 0)
                    {
                        items.Add(menuItems.UndoAdd);
                    }
                    else if (state.Revert > 0)
                    {
                        if (state.Diff > 0)
                        {
                            items.Add(menuItems.DiffChange);
                        }
                        items.Add(menuItems.Revert);
                    }
                    else if (state.Total == 1)
                    {
                        items.Add(menuItems.DiffChange);
                    }
                }
                if (items.Count > minLen)
                {
                    items.Insert(minLen, menuItems.MidSeparator);
                }
                items.RemoveAll(item => item == null);
                scItem.DropDownItems.AddRange(items.ToArray());
            }
        }
        static internal void SetMenu(ProjectTreeView tree, ProjectSelectionState state)
        {
            if (tree == null || state.Manager == null)
            {
                return;
            }

            ContextMenuStrip menu = tree.ContextMenuStrip;

            IVCMenuItems menuItems = state.Manager.MenuItems;

            if (menuItems == null)
            {
                return;
            }

            ClearItems(menu, menuItems);

            menuItems.CurrentNodes   = (TreeNode[])tree.SelectedNodes.ToArray(typeof(TreeNode));
            menuItems.CurrentManager = state.Manager;

            List <ToolStripItem> items = new List <ToolStripItem>();

            // generic
            items.Add(menuItems.Update);
            items.Add(menuItems.Commit);
            items.Add(menuItems.Push);
            items.Add(menuItems.ShowLog);
            int minLen = items.Count;

            // specific
            if (state.Files == 2 && state.Total == 2)
            {
                items.Add(menuItems.Diff);
            }
            if (state.Conflict == 1 && state.Total == 1)
            {
                items.Add(menuItems.EditConflict);
            }

            if (state.Unknown + state.Ignored > 0 || state.Dirs > 0)
            {
                items.Add(menuItems.Add);
            }
            if (state.Unknown + state.Ignored == state.Total)
            {
                items.Add(menuItems.Ignore);
            }

            if (state.Unknown + state.Ignored < state.Total)
            {
                if (state.Added > 0)
                {
                    items.Add(menuItems.UndoAdd);
                }
                else if (state.Revert > 0)
                {
                    if (state.Diff > 0)
                    {
                        items.Add(menuItems.DiffChange);
                    }
                    items.Add(menuItems.Revert);
                }
                else if (state.Total == 1)
                {
                    items.Add(menuItems.DiffChange);
                }
            }
            if (items.Count > minLen)
            {
                items.Insert(minLen, menuItems.MidSeparator);
            }
            items.RemoveAll(item => item == null);
            if (scItem.Owner == null)
            {
                AddSCMainItem(menu);
            }
            scItem.DropDownItems.AddRange(items.ToArray());
        }