Exemple #1
0
        /// <summary>
        /// Create a new Command Bar and remove the existing Command Bar with the same name.
        /// </summary>
        /// <param name="applicationObject">The host application.</param>
        /// <param name="szName">The name of the new command bar.</param>
        /// <returns>The created CommandaBar object.</returns>
        public static CommandBar AddCommandBar(DTE2 applicationObject, String szName)
        {
            Commands   commands = applicationObject.Commands;
            CommandBar cmdBar   = null;

            try
            {
                CommandBars oldCmdBars = (CommandBars)applicationObject.CommandBars;
                CommandBar  oldCmdBar  = oldCmdBars[szName];
                commands.RemoveCommandBar(oldCmdBar);
            }
            catch (ArgumentException)
            {
                // Thrown if command doesn't already exist.
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message, "ChirpyPopupAddIn.AddCommandBar");
            }     // try

            try
            {
                cmdBar = (CommandBar)commands.AddCommandBar(szName, vsCommandBarType.vsCommandBarTypeToolbar, null, 0);
            }
            catch (ArgumentException)
            {
                // Thrown if command doesn't already exist.
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message, "ChirpyPopupAddIn.AddCommandBar");
            } // try
            return(cmdBar);
        }     // AddCommandBar
Exemple #2
0
        /// <summary>
        ///      Implements the OnConnection method of the IDTExtensibility2 interface.
        ///      Receives notification that the Add-in is being loaded.
        /// </summary>
        /// <param term='application'>
        ///      Root object of the host application.
        /// </param>
        /// <param term='connectMode'>
        ///      Describes how the Add-in is being loaded.
        /// </param>
        /// <param term='addInInst'>
        ///      Object representing this Add-in.
        /// </param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
        {
            Mfconsulting.Vsprj2make.RegistryHelper regHlpr = new RegistryHelper();
            string [] monoVersions = null;

            try
            {
                monoVersions = regHlpr.GetMonoVersions();
            }
            catch (Exception exc)
            {
                // Mono may not be installed
                MessageBox.Show(exc.Message, "Prj2make Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;                 // Pull the cord and discontinue loading the add-in
            }

            applicationObject = (_DTE)application;
            addInInstance     = (AddIn)addInInst;
            int selectedIndexForComboBox = 1;

            EnvDTE.Events events       = applicationObject.Events;
            OutputWindow  outputWindow = (OutputWindow)applicationObject.Windows.Item(Constants.vsWindowKindOutput).Object;

            outputWindowPane = outputWindow.OutputWindowPanes.Add("Prj2Make Messages");

            object []    contextGUIDS = new object[] { };
            Commands     commands     = applicationObject.Commands;
            _CommandBars commandBars  = applicationObject.CommandBars;
            CommandBar   cmdBarMonoBarra;

            CommandBar      commandBar = (CommandBar)commandBars["Tools"];
            CommandBarPopup popMenu;                    // Prj2Make popupmenu
            CommandBarPopup popMenu2;                   // Explorer Current Project

            // Creates a more legible representation of the
            // command bar control collection contained in
            // the Tools command bar
            CommandBarControls commandBarControls;

            commandBarControls = commandBar.Controls;

            // Create Makefile
            Command command1 = null;
            // Generate MonoDevelop files
            Command command2 = null;
            // Import MonoDevelop Solutions
            Command command3 = null;
            // Run on Mono
            Command command5 = null;
            // vsprj2make Options
            Command command6 = null;
            // Generate a distribution unit
            Command command7 = null;
            // Explore current solution
            Command command8 = null;
            // Explore current Project
            Command command9 = null;


            // ------------- Add Pop-up menu ----------------
            popMenu2 = (CommandBarPopup)commandBarControls.Add(
                MsoControlType.msoControlPopup,
                System.Reflection.Missing.Value, // Object ID
                System.Reflection.Missing.Value, // Object parameters
                1,                               // Object before
                true);

            popMenu2.Caption = "&Windows Explore";

            // ------------- Add Pop-up menu ----------------
            popMenu = (CommandBarPopup)commandBarControls.Add(
                MsoControlType.msoControlPopup,
                System.Reflection.Missing.Value, // Object ID
                System.Reflection.Missing.Value, // Object parameters
                1,                               // Object before
                true);

            popMenu.Caption = "Prj&2Make";

            // Add the create makefile command -- command1
            command1 = CreateNamedCommand(
                addInInstance,
                commands,
                "CreateMake",
                "Create &Makefile",
                "Generate Makefile",
                ref contextGUIDS
                );

            if (command1 == null)
            {
                command1 = GetExistingNamedCommand(commands, "vsprj2make.Connect.CreateMake");
            }

            try
            {
                command1.AddControl(popMenu.CommandBar, 1);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Add the generate a dist unit command -- command7
            command7 = CreateNamedCommand(
                addInInstance,
                commands,
                "GenDistUnit",
                "Generate Distribution &Unit",
                "Generates a distribution unit (zip file)",
                ref contextGUIDS
                );

            if (command7 == null)
            {
                command7 = GetExistingNamedCommand(commands, "vsprj2make.Connect.GenDistUnit");
            }

            try
            {
                command7.AddControl(popMenu.CommandBar, 2);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Add the GenMDFiles command -- command2
            command2 = CreateNamedCommand(
                addInInstance,
                commands,
                "GenMDFiles",
                "Create Mono&Develop Solution",
                "Generate MonoDevelop Solution",
                ref contextGUIDS
                );

            if (command2 == null)
            {
                command2 = GetExistingNamedCommand(commands, "vsprj2make.Connect.GenMDFiles");
            }

            try
            {
                command2.AddControl(popMenu.CommandBar, 3);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Add the PrjxToCsproj command -- command3
            command3 = CreateNamedCommand(
                addInInstance,
                commands,
                "PrjxToCsproj",
                "&Import MonoDevelop Solution...",
                "Imports a MonoDevelop Solution",
                ref contextGUIDS
                );

            if (command3 == null)
            {
                command3 = GetExistingNamedCommand(commands, "vsprj2make.Connect.PrjxToCsproj");
            }

            try
            {
                command3.AddControl(popMenu.CommandBar, 4);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Add the Ron on Mono command -- command5
            command5 = CreateNamedCommand(
                addInInstance,
                commands,
                "RunOnMono",
                "&Run on Mono",
                "Run solution on mono",
                ref contextGUIDS
                );

            if (command5 == null)
            {
                command5 = GetExistingNamedCommand(commands, "vsprj2make.Connect.RunOnMono");
            }

            try
            {
                command5.AddControl(popMenu.CommandBar, 5);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Add the Options command -- command6
            command6 = CreateNamedCommand(
                addInInstance,
                commands,
                "Options",
                "&Options...",
                "Options for prj2make Add-in",
                ref contextGUIDS
                );

            if (command6 == null)
            {
                command6 = GetExistingNamedCommand(commands, "vsprj2make.Connect.Options");
            }

            try
            {
                command6.AddControl(popMenu.CommandBar, 6);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Add the ExploreCurrSln command -- command8
            command8 = CreateNamedCommand(
                addInInstance,
                commands,
                "ExploreCurrSln",
                "Current &Solution",
                "Explore the current solution",
                ref contextGUIDS
                );

            if (command8 == null)
            {
                command8 = GetExistingNamedCommand(commands, "vsprj2make.Connect.ExploreCurrSln");
            }

            try
            {
                command8.AddControl(popMenu2.CommandBar, 1);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Add the ExploreCurrDoc command -- command9
            command9 = CreateNamedCommand(
                addInInstance,
                commands,
                "ExploreCurrDoc",
                "Current &Document",
                "Explore the current Document",
                ref contextGUIDS
                );

            if (command9 == null)
            {
                command9 = GetExistingNamedCommand(commands, "vsprj2make.Connect.ExploreCurrDoc");
            }

            try
            {
                command9.AddControl(popMenu2.CommandBar, 2);
            }
            catch (System.Exception exc)
            {
                Trace.WriteLine(String.Format("Error during OnConnect of Add-in:\n {0}", exc.Message));
            }

            // Mono Toolbar
            CommandBar cmdBarBuild = (CommandBar)commandBars["Build"];

            try
            {
                cmdBarMonoBarra = (CommandBar)commandBars["MonoBarra"];
            }
            catch (Exception)
            {
                commands.AddCommandBar("MonoBarra",
                                       vsCommandBarType.vsCommandBarTypeToolbar,
                                       cmdBarBuild,
                                       1
                                       );

                cmdBarMonoBarra         = (CommandBar)commandBars["MonoBarra"];
                cmdBarMonoBarra.Visible = true;
            }

            if (testInMonoCommandBarButton == null)
            {
                // Create the Ron on Mono Button
                testInMonoCommandBarButton = (CommandBarButton)cmdBarMonoBarra.Controls.Add(
                    Microsoft.Office.Core.MsoControlType.msoControlButton,
                    System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value,
                    1,
                    false
                    );

                testInMonoCommandBarButton.Caption         = "Run on &Mono";
                testInMonoCommandBarButton.DescriptionText = "Run solution with the mono runtime";
                testInMonoCommandBarButton.TooltipText     = "Run on mono";
                testInMonoCommandBarButton.ShortcutText    = "Run on &Mono";
                testInMonoCommandBarButton.Style           = MsoButtonStyle.msoButtonCaption;
                testInMonoCommandBarButton.Click          += new _CommandBarButtonEvents_ClickEventHandler(testInMonoCommandBarButton_Click);
            }

            if (versionComboBox == null)
            {
                // Create the combobox
                versionComboBox = (CommandBarComboBox)cmdBarMonoBarra.Controls.Add(
                    Microsoft.Office.Core.MsoControlType.msoControlDropdown,
                    System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value,
                    2,
                    false
                    );

                for (int i = 0; i < monoVersions.Length; i++)
                {
                    versionComboBox.AddItem(monoVersions[i], i + 1);
                    if (monoVersions[i].CompareTo(regHlpr.GetDefaultClr()) == 0)
                    {
                        selectedIndexForComboBox = i + 1;
                    }
                }

                versionComboBox.Change += new _CommandBarComboBoxEvents_ChangeEventHandler(versionComboBox_Change);

                // Select the active index based on
                // the current mono version
                versionComboBox.ListIndex = selectedIndexForComboBox;
            }
        }