Exemplo n.º 1
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            Workspace currentWorkspace = VsHelper.Current.GetCurrentWorkspace();

            foreach (EnvDTE.Project proj in VsHelper.GetSelectedItemsOfType <EnvDTE.Project>())
            {
                if (ConfigProcessing.IsGenEnabledForProject(proj))
                {
                    IScriptGenEngineProvider <Workspace> provider = Imports.ScriptGenAssemblyCache.GetForProj(proj).EngineProvider;
                    IScriptGenEngine        engine = provider.GetEngine(currentWorkspace, proj.FullName);
                    IScriptGenerationResult result = engine.GenerateScripts();
                    // Show a message box to prove we were here
                    if (!result.Sucess)
                    {
                        VsShellUtilities.ShowMessageBox(
                            this.ServiceProvider,
                            result.ErrorMessage,
                            "Script Generation Failed",
                            OLEMSGICON.OLEMSGICON_CRITICAL,
                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    }
                }
            }
        }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            var question = MessageBox.Show("Selecting this command will install a NuGet package that will enable this project for script generation. " +
                                           "\r\rDo you want to continue?", "Install NuGet Package?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (question == DialogResult.No)
            {
                return;
            }

            foreach (Project proj in VsHelper.GetSelectedItemsOfType <Project>())
            {
                if (!VsHelper.IsSolutionItemsFolder(proj) && !VsHelper.IsPackageInstalled(proj))
                {
                    try
                    {
                        IComponentModel     componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
                        IVsPackageInstaller installer      = componentModel.GetService <IVsPackageInstaller>();
                        installer.InstallPackage(null, proj, TypeRightPackage.NugetID, (string)null, false);
                    }
                    catch (Exception exception)
                    {
                        // Show a message box to prove we were here
                        VsShellUtilities.ShowMessageBox(
                            this.ServiceProvider,
                            "There was an error installing the package: \n\n" + exception.Message,
                            "Could not install package",
                            OLEMSGICON.OLEMSGICON_CRITICAL,
                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// This function is the callback used to execute the command when the menu item is clicked.
 /// See the constructor to see how the menu item is associated with this function using
 /// OleMenuCommandService service and MenuCommand class.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event args.</param>
 private void MenuItemCallback(object sender, EventArgs e)
 {
     foreach (Project proj in VsHelper.GetSelectedItemsOfType <Project>())
     {
         if (!VsHelper.IsSolutionItemsFolder(proj) &&
             !ConfigProcessing.ConfigExistsForProject(proj))
         {
             ConfigProcessing.CreateForProject(proj);
         }
     }
 }
        private ProjectItem GetSelectedItem()
        {
            var selItems = VsHelper.GetSelectedItemsOfType <ProjectItem>().ToList();

            if (selItems.Count != 1)
            {
                return(null);
            }

            return(selItems.First());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Determines whether this command is visible
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_BeforeQueryStatus(object sender, EventArgs e)
        {
            OleMenuCommand button = (OleMenuCommand)sender;

            button.Enabled = false;

            foreach (EnvDTE.Project proj in VsHelper.GetSelectedItemsOfType <EnvDTE.Project>())
            {
                if (!VsHelper.IsSolutionItemsFolder(proj) &&
                    VsHelper.IsPackageInstalled(proj) &&
                    ConfigProcessing.IsGenEnabledForProject(proj))
                {
                    button.Enabled = true;
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Before query for Adding a config file to the solution
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_BeforeQueryStatus(object sender, EventArgs e)
        {
            OleMenuCommand button  = (OleMenuCommand)sender;
            bool           hasProj = VsHelper.GetSelectedItemsOfType <Project>().Any();   // Check if the solution is selectd

            button.Visible = false;
            button.Enabled = false;

            foreach (Project proj in VsHelper.GetSelectedItemsOfType <Project>())
            {
                button.Visible = true;                  // At least one project is selected...
                if (!ConfigProcessing.IsGenEnabledForProject(proj) && VsHelper.IsPackageInstalled(proj))
                {
                    button.Enabled = true;
                }
            }
        }
        /// <summary>
        /// Determines whether this command is visible
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_BeforeQueryStatus(object sender, EventArgs e)
        {
            OleMenuCommand button = (OleMenuCommand)sender;

            button.Enabled = false;

            if (!VsHelper.GetSelectedItemsOfType <Project>().Any())
            {
                return;
            }

            foreach (Project proj in VsHelper.GetSelectedItemsOfType <Project>())
            {
                if (!VsHelper.IsSolutionItemsFolder(proj) && !VsHelper.IsPackageInstalled(proj))
                {
                    button.Enabled = true;
                }
            }
        }