示例#1
0
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            IVsSolution solution;

            solution = this.GetService(typeof(SVsSolution)) as IVsSolution;

            if (solution != null)
            {
                string solutionDirectory;
                string solutionFileName;
                string solutionOptions;

                solution.GetSolutionInfo(out solutionDirectory, out solutionFileName, out solutionOptions);

                if (!(string.IsNullOrEmpty(solutionDirectory) || string.IsNullOrEmpty(solutionFileName)))
                {
                    using (AddProjectsDialog dialog = new AddProjectsDialog(solution))
                    {
                        dialog.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("This command can only be used with a saved solution.", "Add Projects", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                MessageBox.Show("This command can only be used with an open solution.", "Add Projects", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
    /// <summary>
    /// This function is the callback used to execute a command when the a menu item is clicked.
    /// See the Initialize method to see how the menu item is associated to this function using
    /// the OleMenuCommandService service and the MenuCommand class.
    /// </summary>
    private void MenuItemCallback(object sender, EventArgs e)
    {
      IVsSolution solution;

      solution = this.GetService(typeof(SVsSolution)) as IVsSolution;

      if (solution != null)
      {
        string solutionDirectory;
        string solutionFileName;
        string solutionOptions;

        solution.GetSolutionInfo(out solutionDirectory, out solutionFileName, out solutionOptions);

        if (!(string.IsNullOrEmpty(solutionDirectory) || string.IsNullOrEmpty(solutionFileName)))
        {
          using (AddProjectsDialog dialog = new AddProjectsDialog(solution))
          {
            dialog.ShowDialog();
          }
        }
        else
        {
          MessageBox.Show("This command can only be used with a saved solution.", "Add Projects", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
      }
      else
      {
        MessageBox.Show("This command can only be used with an open solution.", "Add Projects", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
      }
    }