Ejemplo 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)
        {
            var dteSolutionHelper = new DteSolutionHelper();
            var messageBoxHelper  = new MessageBoxHelper(this.ServiceProvider);

            var selectedProject = dteSolutionHelper.GetSelectedProject();

            string newProjectName;
            bool   isOkButtonClicked = TextInputDialog
                                       .Show("Full Rename", "Enter new project name", selectedProject.Name, out newProjectName);

            if (!isOkButtonClicked)
            {
                return;
            }
            if (newProjectName == selectedProject.Name)
            {
                return;
            }

            var projectRenamer = new ProjectRenamer()
            {
                SolutionFullName  = dteSolutionHelper.GetSolutionFullName(),
                ProjectFullName   = selectedProject.FullName,
                ProjectName       = selectedProject.Name,
                ProjectUniqueName = selectedProject.UniqueName,
                ProjectNameNew    = newProjectName,
                SolutionProjects  = dteSolutionHelper.GetSolutionProjects().Select(it => it.FullName)
            };

            if (IsSharedProject(selectedProject))
            {
                projectRenamer = new SharedTypeProjectRenamer
                {
                    SolutionFullName  = projectRenamer.SolutionFullName,
                    ProjectFullName   = selectedProject.FullName,
                    ProjectName       = selectedProject.Name,
                    ProjectUniqueName = Path.ChangeExtension(selectedProject.UniqueName, null),
                    ProjectNameNew    = newProjectName,
                    SolutionProjects  = projectRenamer.SolutionProjects
                };
            }

            try
            {
                projectRenamer.FullRename();
                messageBoxHelper.ShowSuccessMessage();
            }
            catch (IOException ioe)
            {
                messageBoxHelper.ShowErrorMessage(ioe, "Close all folders, text editors related to the project");
            }
            catch (Exception ex)
            {
                messageBoxHelper.ShowErrorMessage(ex);
            }
        }
Ejemplo n.º 2
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)
        {
            var dteSolutionHelper = new DteSolutionHelper();
            var messageBoxHelper  = new MessageBoxHelper(this.ServiceProvider);

            var selectedProject = dteSolutionHelper.GetSelectedProject();

            if (!selectedProject.Saved)
            {
                messageBoxHelper.ShowInfoMessage("Build/rebuild project before renaming");
                return;
            }

            if (!dteSolutionHelper.IsProjectFilesSaved(selectedProject))
            {
                messageBoxHelper.ShowInfoMessage("Some files are not saved. Save them or build/rebuild project");
                return;
            }

            var renameOptions = new RenameOptions
            {
                ProjectName     = selectedProject.Name,
                ProjectFullName = selectedProject.FullName
            };
            var dialog            = new FullRenameDialog(renameOptions);
            var isOkButtonClicked = dialog.ShowModal();

            if (isOkButtonClicked == false)
            {
                return;
            }
            if (renameOptions.ProjectName == selectedProject.Name)
            {
                return;
            }

            try
            {
                var projectRenamer = ProjectRenamerFactory.Create(selectedProject, renameOptions);
                projectRenamer.FullRename();
                messageBoxHelper.ShowSuccessMessage();
            }
            catch (UnauthorizedAccessException uae)
            {
                messageBoxHelper.ShowErrorMessage(uae, "You don't have enough permisssion");
            }
            catch (IOException ioe)
            {
                messageBoxHelper.ShowErrorMessage(ioe, "Close all folders, text editors related to the project");
            }
            catch (Exception ex)
            {
                messageBoxHelper.ShowErrorMessage(ex);
            }
        }