private void RemoveCommandBar(string name, IVsProfferCommands3 profferCommands3)
        {
            // Remove a command bar and contained controls
            DTE2        dte            = GetGlobalService(typeof(DTE)) as DTE2;
            CommandBars commandBars    = (CommandBars)dte.CommandBars;
            Commands    commands       = dte.Commands;
            CommandBar  existingCmdBar = null;

            try
            {
                existingCmdBar = commandBars[name];
            }
            catch (Exception)
            {
            }

            if (existingCmdBar != null)
            {
                // Remove all buttons

                while (existingCmdBar.Controls.Count > 0)
                {
                    foreach (CommandBarControl ctrl in existingCmdBar.Controls)
                    {
                        profferCommands3.RemoveCommandBarControl(ctrl);
                        break;
                    }
                }
            }
            profferCommands3.RemoveCommandBar(existingCmdBar);
        }
        // Remove a command bar and contained controls
        private static void RemoveCommandBar(string name, IVsProfferCommands3 profferCommands3)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var        dte            = GetGlobalService(typeof(DTE)) as DTE2;
            var        commandBars    = (CommandBars)dte.CommandBars;
            CommandBar existingCmdBar = null;

            try
            {
                existingCmdBar = commandBars[name];
            }
            catch (Exception)
            {
            }

            if (existingCmdBar != null)
            {
                // Remove all buttons

                while (existingCmdBar.Controls.Count > 0)
                {
                    foreach (CommandBarControl ctrl in existingCmdBar.Controls)
                    {
                        profferCommands3.RemoveCommandBarControl(ctrl);
                        break;
                    }
                }
            }

            profferCommands3.RemoveCommandBar(existingCmdBar);
        }
        /// <summary>
        ///  Removes all installed commands and controls for testing purposes.
        /// </summary>
        private void Cleanup()
        {
            IVsProfferCommands3 profferCommands3 = base.GetService(typeof(SVsProfferCommands)) as IVsProfferCommands3;

            RemoveCommandBar("NiftyPerforceCmdBar", profferCommands3);
            RemoveCommandBar("NiftyPerforce", profferCommands3);

            RemoveCommand("NiftyConfig", profferCommands3);
            RemoveCommand("NiftyEditModified", profferCommands3);
            RemoveCommand("NiftyEdit", profferCommands3);
            RemoveCommand("NiftyEditItem", profferCommands3);
            RemoveCommand("NiftyEditSolution", profferCommands3);
            RemoveCommand("NiftyDiff", profferCommands3);
            RemoveCommand("NiftyDiffItem", profferCommands3);
            RemoveCommand("NiftyDiffSolution", profferCommands3);
            RemoveCommand("NiftyHistory", profferCommands3);
            RemoveCommand("NiftyHistoryMain", profferCommands3);
            RemoveCommand("NiftyHistoryItem", profferCommands3);
            RemoveCommand("NiftyHistoryItemMain", profferCommands3);
            RemoveCommand("NiftyHistorySolution", profferCommands3);
            RemoveCommand("NiftyTimeLapse", profferCommands3);
            RemoveCommand("NiftyTimeLapseMain", profferCommands3);
            RemoveCommand("NiftyTimeLapseItem", profferCommands3);
            RemoveCommand("NiftyTimeLapseItemMain", profferCommands3);
            RemoveCommand("NiftyRevisionGraph", profferCommands3);
            RemoveCommand("NiftyRevisionGraphMain", profferCommands3);
            RemoveCommand("NiftyRevisionGraphItem", profferCommands3);
            RemoveCommand("NiftyRevisionGraphItemMain", profferCommands3);
            RemoveCommand("NiftyRevert", profferCommands3);
            RemoveCommand("NiftyRevertItem", profferCommands3);
            RemoveCommand("NiftyRevertUnchanged", profferCommands3);
            RemoveCommand("NiftyRevertUnchangedItem", profferCommands3);
            RemoveCommand("NiftyShow", profferCommands3);
            RemoveCommand("NiftyShowItem", profferCommands3);
        }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // Load up the options from file.
            string  optionsFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "NiftySolution.xml");
            Options options         = Options.Load(optionsFileName);

            // Create our main plugin facade.
            DTE2 application = GetGlobalService(typeof(DTE)) as DTE2;
            IVsProfferCommands3   profferCommands3      = base.GetService(typeof(SVsProfferCommands)) as IVsProfferCommands3;
            OleMenuCommandService oleMenuCommandService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            ImageList icons = new ImageList();

            icons.Images.AddStrip(Properties.Resources.Icons);
            m_plugin = new Plugin(application, profferCommands3, icons, oleMenuCommandService, "NiftySolution", "Aurora.NiftySolution.Connect", options);

            // Every plugin needs a command bar.
            CommandBar commandBar = m_plugin.AddCommandBar("NiftySolution", MsoBarPosition.msoBarTop);

            m_commandRegistry = new CommandRegistry(m_plugin, commandBar, new Guid(PackageGuidString), new Guid(PackageGuidGroup));

            // Initialize the logging system.
            if (Log.HandlerCount == 0)
            {
                                #if DEBUG
                Log.AddHandler(new DebugLogHandler());
                                #endif

                Log.AddHandler(new VisualStudioLogHandler(m_plugin));
                Log.Prefix = "NiftySolution";
            }

            // Now we can take care of registering ourselves and all our commands and hooks.
            Log.Debug("Booting up...");
            Log.IncIndent();


            bool doBindings = options.EnableBindings;

            m_commandRegistry.RegisterCommand(doBindings, new QuickOpen(m_plugin, "NiftyOpen"));
            m_commandRegistry.RegisterCommand(doBindings, new ToggleFile(m_plugin, "NiftyToggle"));
            m_commandRegistry.RegisterCommand(doBindings, new CloseToolWindow(m_plugin, "NiftyClose"));
            m_commandRegistry.RegisterCommand(doBindings, new Configure(m_plugin, "NiftyConfigure"));

            if (options.SilentDebuggerExceptions || options.IgnoreDebuggerExceptions)
            {
                m_debuggerEvents = application.Events.DebuggerEvents;
                m_debuggerEvents.OnExceptionNotHandled += new _dispDebuggerEvents_OnExceptionNotHandledEventHandler(OnExceptionNotHandled);
            }

            m_timings = new SolutionBuildTimings(m_plugin);

            Log.DecIndent();
            Log.Debug("Initialized...");
        }
        private void RemoveCommand(string name, IVsProfferCommands3 profferCommands3)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            try
            {
                Command cmd = m_plugin.Commands.Item(name, -1);
                if (cmd != null)
                {
                    profferCommands3.RemoveNamedCommand(name);
                }
            }
            catch (Exception) { }

            string[] bars =
            {
                "Project",
                "Item",
                "Easy MDI Document Window",
                "Cross Project Multi Item",
                "Cross Project Multi Project"
            };

            const string prefix  = "Aurora.NiftyPerforce.Connect";
            string       Absname = prefix + "." + name;

            foreach (string bar in bars)
            {
                CommandBar b = ((CommandBars)m_plugin.App.CommandBars)[bar];
                if (null != b)
                {
                    bool done = false;
                    while (!done)
                    {
                        bool found = false;
                        foreach (CommandBarControl ctrl in b.Controls)
                        {
                            if (ctrl.Caption == name || ctrl.Caption == Absname)
                            {
                                found = true;
                                try
                                {
                                    profferCommands3.RemoveCommandBarControl(ctrl);
                                }
                                catch (Exception)
                                {
                                }

                                break;
                            }
                        }

                        done = !found;
                    }
                }
            }
        }
Exemple #6
0
        public Plugin(DTE2 application, IVsProfferCommands3 profferCommands, ImageList icons, OleMenuCommandService oleMenuCommandService, string panelName, string connectPath, object options)
        {
            // TODO: This can be figured out from traversing the assembly and locating the Connect class...
            m_connectPath = connectPath;

            m_application = application;
            m_panelName = panelName;
            m_profferCommands = profferCommands;
            m_oleMenuCommandService = oleMenuCommandService;
            mOptions = options;
            m_icons = icons;
        }
Exemple #7
0
        public Plugin(DTE2 application, IVsProfferCommands3 profferCommands, ImageList icons, OleMenuCommandService oleMenuCommandService, string panelName, string connectPath, object options)
        {
            // TODO: This can be figured out from traversing the assembly and locating the Connect class...
            m_connectPath = connectPath;

            m_application           = application;
            m_panelName             = panelName;
            m_profferCommands       = profferCommands;
            m_oleMenuCommandService = oleMenuCommandService;
            mOptions = options;
            m_icons  = icons;
        }
        private int AddCommand(IVsProfferCommands3 profferCommands3, OleMenuCommandService oleMenuCommandService, string commandName, string commandCaption, string commandTooltip)
        {
            const uint   CMD_FLAGS = 0;
            const string SATELLITE_DLL = "";
            const uint   BITMAP_RESOURCE_ID = 0;
            const uint   BITMAP_IMAGE_INDEX = 0;
            const int    UI_CONTEXTS = 0;
            const        Guid[] GUID_UI_CONTEXTS = null;

            Guid           packageGuid  = new Guid(PackageGuidString);
            Guid           cmdGroupGuid = new Guid(PackageGuidGroup);
            int            result;
            CommandID      commandID;
            OleMenuCommand oleMenuCommand;
            uint           cmdId = 0;

            result = profferCommands3.AddNamedCommand(ref packageGuid, ref cmdGroupGuid, commandName, out cmdId, commandName, commandCaption, commandTooltip,
                                                      SATELLITE_DLL, BITMAP_RESOURCE_ID, BITMAP_IMAGE_INDEX, CMD_FLAGS, UI_CONTEXTS, GUID_UI_CONTEXTS);

            // Note: the result can be:
            // 1) Microsoft.VisualStudio.VSConstants.S_OK. This should be the case of the first creation, when the command didn't exist previously
            // 2) Microsoft.VisualStudio.VSConstants.S_FALSE. This can be because:
            //   2.1) The command with that name already exists. In this case the returned cmdId is valid.
            //   2.2) There is some error. In this case the returned cmdId remains with value 0.

            if (cmdId != 0)
            {
                if (oleMenuCommandService != null)
                {
                    commandID = new CommandID(cmdGroupGuid, (int)cmdId);

                    oleMenuCommand = new OleMenuCommand(OleMenuCommandCallback, commandID);
                    oleMenuCommand.BeforeQueryStatus += this.OleMenuCommandBeforeQueryStatus;
                    oleMenuCommandService.AddCommand(oleMenuCommand);
                }
            }
            else
            {
                throw new ApplicationException("Failed to add command");
            }
            return((int)cmdId);
        }
        private int AddCommand(IVsProfferCommands3 profferCommands3, OleMenuCommandService oleMenuCommandService, string commandName, string commandCaption, string commandTooltip)
        {
            const uint CMD_FLAGS = 0;
             const string SATELLITE_DLL = "";
             const uint BITMAP_RESOURCE_ID = 0;
             const uint BITMAP_IMAGE_INDEX = 0;
             const int UI_CONTEXTS = 0;
             const Guid[] GUID_UI_CONTEXTS = null;

             Guid packageGuid = new Guid(PackageGuidString);
             Guid cmdGroupGuid = new Guid(PackageGuidGroup);
             int result;
             CommandID commandID;
             OleMenuCommand oleMenuCommand;
             uint cmdId = 0;

             result = profferCommands3.AddNamedCommand(ref packageGuid, ref cmdGroupGuid, commandName, out cmdId, commandName, commandCaption, commandTooltip,
            SATELLITE_DLL, BITMAP_RESOURCE_ID, BITMAP_IMAGE_INDEX, CMD_FLAGS, UI_CONTEXTS, GUID_UI_CONTEXTS);

             // Note: the result can be:
             // 1) Microsoft.VisualStudio.VSConstants.S_OK. This should be the case of the first creation, when the command didn't exist previously
             // 2) Microsoft.VisualStudio.VSConstants.S_FALSE. This can be because:
             //   2.1) The command with that name already exists. In this case the returned cmdId is valid.
             //   2.2) There is some error. In this case the returned cmdId remains with value 0.

             if (cmdId != 0)
             {
            if (oleMenuCommandService != null)
            {
               commandID = new CommandID(cmdGroupGuid, (int)cmdId);

               oleMenuCommand = new OleMenuCommand(OleMenuCommandCallback, commandID);
               oleMenuCommand.BeforeQueryStatus += this.OleMenuCommandBeforeQueryStatus;
               oleMenuCommandService.AddCommand(oleMenuCommand);
            }
             }
             else
             {
            throw new ApplicationException("Failed to add command");
             }
             return (int)cmdId;
        }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // Load up the options from file.
            string optionsFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "NiftyPerforce.xml");
            Config options         = Config.Load(optionsFileName);

            // Every plugin needs a command bar.
            DTE2 application = GetGlobalService(typeof(DTE)) as DTE2;
            IVsProfferCommands3   profferCommands3      = base.GetService(typeof(SVsProfferCommands)) as IVsProfferCommands3;
            OleMenuCommandService oleMenuCommandService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            ImageList icons = new ImageList();

            icons.Images.AddStrip(Properties.Resources.Icons);
            m_plugin = new Plugin(application, profferCommands3, icons, oleMenuCommandService, "NiftyPerforce", "Aurora.NiftyPerforce.Connect", options);

            Cleanup();

            CommandBar commandBar = m_plugin.AddCommandBar("NiftyPerforce", MsoBarPosition.msoBarTop);

            m_commandRegistry = new CommandRegistry(m_plugin, commandBar, new Guid(PackageGuidString), new Guid(PackageGuidGroup));

            // Initialize the logging system.
            if (Log.HandlerCount == 0)
            {
#if DEBUG
                Log.AddHandler(new DebugLogHandler());
#endif
                Log.AddHandler(new VisualStudioLogHandler(m_plugin));
                Log.Prefix = "NiftyPerforce";
            }

            // Now we can take care of registering ourselves and all our commands and hooks.
            Log.Debug("Booting up...");
            Log.IncIndent();

            bool doContextCommands  = options.EnableContextMenus;
            bool doBindings         = options.EnableBindings;
            bool doAdvancedCommands = options.EnableAdvancedCommands;

            m_commandRegistry.RegisterCommand(doBindings, new NiftyConfigure(m_plugin, "NiftyConfig"), true);

            if (doAdvancedCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4EditModified(m_plugin, "NiftyEditModified"), true);
            }

            m_commandRegistry.RegisterCommand(doBindings, new P4EditItem(m_plugin, "NiftyEdit"), true);
            if (doContextCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4EditItem(m_plugin, "NiftyEditItem"), false);
            }
            if (doContextCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4EditSolution(m_plugin, "NiftyEditSolution"), false);
            }

            m_commandRegistry.RegisterCommand(doBindings, new P4DiffItem(m_plugin, "NiftyDiff"));
            if (doContextCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4DiffItem(m_plugin, "NiftyDiffItem"), false);
            }
            if (doContextCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4DiffSolution(m_plugin, "NiftyDiffSolution"), false);
            }

            m_commandRegistry.RegisterCommand(doBindings, new P4RevisionHistoryItem(m_plugin, "NiftyHistory", false), true);
            if (doAdvancedCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4RevisionHistoryItem(m_plugin, "NiftyHistoryMain", true), true);
            }
            if (doContextCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4RevisionHistoryItem(m_plugin, "NiftyHistoryItem", false), false);
            }
            if (doContextCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4RevisionHistoryItem(m_plugin, "NiftyHistoryItemMain", true), false);
            }
            if (doContextCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4RevisionHistorySolution(m_plugin, "NiftyHistorySolution"), false);
            }

            m_commandRegistry.RegisterCommand(doBindings, new P4TimeLapseItem(m_plugin, "NiftyTimeLapse", false), true);
            if (doAdvancedCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4TimeLapseItem(m_plugin, "NiftyTimeLapseMain", true), true);
            }
            if (doContextCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4TimeLapseItem(m_plugin, "NiftyTimeLapseItem", false), false);
            }
            if (doContextCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4TimeLapseItem(m_plugin, "NiftyTimeLapseItemMain", true), false);
            }

            m_commandRegistry.RegisterCommand(doBindings, new P4RevisionGraphItem(m_plugin, "NiftyRevisionGraph", false), true);
            if (doAdvancedCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4RevisionGraphItem(m_plugin, "NiftyRevisionGraphMain", true), true);
            }
            if (doContextCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4RevisionGraphItem(m_plugin, "NiftyRevisionGraphItem", false), false);
            }
            if (doContextCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4RevisionGraphItem(m_plugin, "NiftyRevisionGraphItemMain", true), false);
            }

            m_commandRegistry.RegisterCommand(doBindings, new P4RevertItem(m_plugin, "NiftyRevert", false), true);
            m_commandRegistry.RegisterCommand(doBindings, new P4RevertItem(m_plugin, "NiftyRevertUnchanged", true), true);
            if (doContextCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4RevertItem(m_plugin, "NiftyRevertItem", false), false);
            }
            if (doContextCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4RevertItem(m_plugin, "NiftyRevertUnchangedItem", true), false);
            }

            m_commandRegistry.RegisterCommand(doBindings, new P4ShowItem(m_plugin, "NiftyShow"), true);
            if (doContextCommands)
            {
                m_commandRegistry.RegisterCommand(doBindings, new P4ShowItem(m_plugin, "NiftyShowItem"), false);
            }

            m_plugin.AddFeature(new AutoAddDelete(m_plugin));
            m_plugin.AddFeature(new AutoCheckoutProject(m_plugin));
            m_plugin.AddFeature(new AutoCheckoutOnBuild(m_plugin));
            m_plugin.AddFeature(new AutoCheckoutTextEdit(m_plugin));
            m_plugin.AddFeature(new AutoCheckoutOnSave(m_plugin));

#if DEBUG
            // Use this to track down event GUIDs.
            //m_plugin.AddFeature(new FindEvents(m_plugin));
#endif

            P4Operations.CheckInstalledFiles();

            AsyncProcess.Init();

            Log.DecIndent();
            Log.Debug("Initialized...");

#if DEBUG
            Log.Info("NiftyPerforce (Debug)");
#else
            //Log.Info("NiftyPerforce (Release)");
#endif
            // Show where we are and when we were compiled...
            Log.Info("I'm running {0} compiled on {1}", Assembly.GetExecutingAssembly().Location, System.IO.File.GetLastWriteTime(Assembly.GetExecutingAssembly().Location));
        }
        private void RemoveCommandBar(string name, IVsProfferCommands3 profferCommands3)
        {
            // Remove a command bar and contained controls
            DTE2 dte = GetGlobalService(typeof(DTE)) as DTE2;
            CommandBars commandBars = (CommandBars)dte.CommandBars;
            Commands commands = dte.Commands;
            CommandBar existingCmdBar = null;

            try
            {
                existingCmdBar = commandBars[name];
            }
            catch (Exception)
            {
            }

            if (existingCmdBar != null)
            {
                // Remove all buttons

                while (existingCmdBar.Controls.Count > 0)
                {
                    foreach (CommandBarControl ctrl in existingCmdBar.Controls)
                    {
                        profferCommands3.RemoveCommandBarControl(ctrl);
                        break;
                    }
                }
            }
            profferCommands3.RemoveCommandBar(existingCmdBar);
        }
        private void RemoveCommand(string name, IVsProfferCommands3 profferCommands3)
        {
            try
            {
                Command cmd = m_plugin.Commands.Item(name, -1);
                if (cmd != null)
                {
                    profferCommands3.RemoveNamedCommand(name);
                }
            } catch (Exception) {
            }

            string[] bars = {
                "Project",
                "Item",
                "Easy MDI Document Window",
                "Cross Project Multi Item",
                "Cross Project Multi Project"
                };

            string Absname = m_plugin.Prefix + "." + name;

            foreach (string bar in bars)
            {
                CommandBar b = ((CommandBars)m_plugin.App.CommandBars)[bar];
                if (null != b)
                {
                    bool done = false;
                    while (!done)
                    {
                        bool found = false;
                        foreach (CommandBarControl ctrl in b.Controls)
                        {
                            if (ctrl.Caption == name || ctrl.Caption == Absname)
                            {
                                found = true;
                                try
                                {
                                    profferCommands3.RemoveCommandBarControl(ctrl);
                                }
                                catch (Exception)
                                {
                                }
                                break;
                            }
                        }
                        done = !found;
                    }
                }
            }
        }