Ejemplo n.º 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)
        {
            try
            {
                // Get current active project object.
                var proj = this.GetActiveProject();

                if (proj != null)
                {
                    // Get the project information.
                    var vsProj = new Files.VSProject(proj);

                    // Get the files included in the project.
                    var includedFiles = vsProj.GetIncludedFiles();

                    // Get the files under the project folder.
                    var projfolderFiles =
                        Files.ProjectFolder.GetFilesInProjectFolder(proj.FullName);

                    // Add the other files such as documents under the project folder, so
                    // the user can choose them.
                    var totalItems = new List <Files.ProjectFileItem>(includedFiles);
                    foreach (Files.ProjectFileItem fileItem in projfolderFiles)
                    {
                        if (includedFiles.Count(f => f.FullName.Equals(fileItem.FullName,
                                                                       StringComparison.OrdinalIgnoreCase)) == 0)
                        {
                            totalItems.Add(fileItem);
                        }
                    }

                    // Display the user interface.
                    using (SaveProjectDialog dialog = new SaveProjectDialog())
                    {
                        // Display the all the files.
                        dialog.FilesItems         = totalItems;
                        dialog.OriginalFolderPath = vsProj.ProjectFolder.FullName;

                        var result = dialog.ShowDialog();

                        // Open the new project.
                        if (result == DialogResult.OK && dialog.OpenNewProject)
                        {
                            string newProjectPath = string.Format("{0}\\{1}",
                                                                  dialog.NewFolderPath,
                                                                  proj.FullName.Substring(vsProj.ProjectFolder.FullName.Length));

                            string cmd = string.Format("File.OpenProject \"{0}\"", newProjectPath);

                            this.DTEObject.ExecuteCommand(cmd);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 此功能是用于执行命令菜单项被点击时的回调。请参阅Initialize方法,
        /// 看到菜单项是如何关联到OleMenuCommandService服务和MenuCommand类使用该功能。
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                // 获取当前活动项目的对象。
                var proj = this.GetActiveProject();

                if (proj != null)
                {
                    // 获取项目的信息
                    var vsProj = new Files.VSProject(proj);

                    // 获取在项目中包含的文件
                    var includedFiles = vsProj.GetIncludedFiles();

                    // 获取在项目文件夹下面的文件
                    var projfolderFiles =
                        Files.ProjectFolder.GetFilesInProjectFolder(proj.FullName);

                    // 新增的其他文件,如项目文件夹下的文件,使用户可以选择他们。
                    var totalItems = new List <Files.ProjectFileItem>(includedFiles);
                    foreach (Files.ProjectFileItem fileItem in projfolderFiles)
                    {
                        if (includedFiles.Count(f => f.FullName.Equals(fileItem.FullName,
                                                                       StringComparison.OrdinalIgnoreCase)) == 0)
                        {
                            totalItems.Add(fileItem);
                        }
                    }

                    // 显示用户接口
                    using (SaveProjectDialog dialog = new SaveProjectDialog())
                    {
                        // 显示所有文件
                        dialog.FilesItems         = totalItems;
                        dialog.OriginalFolderPath = vsProj.ProjectFolder.FullName;

                        var result = dialog.ShowDialog();

                        // 打开新的项目
                        if (result == DialogResult.OK && dialog.OpenNewProject)
                        {
                            string newProjectPath = string.Format("{0}\\{1}",
                                                                  dialog.NewFolderPath,
                                                                  proj.FullName.Substring(vsProj.ProjectFolder.FullName.Length));

                            string cmd = string.Format("File.OpenProject \"{0}\"", newProjectPath);

                            this.DTEObject.ExecuteCommand(cmd);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 此功能是用于执行命令菜单项被点击时的回调。请参阅Initialize方法,
        /// 看到菜单项是如何关联到OleMenuCommandService服务和MenuCommand类使用该功能。
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                // 获取当前活动项目的对象。
                var proj = this.GetActiveProject();

                if (proj != null)
                {
                    // 获取项目的信息
                    var vsProj = new Files.VSProject(proj);

                    // 获取在项目中包含的文件
                    var includedFiles = vsProj.GetIncludedFiles();

                    // 获取在项目文件夹下面的文件
                    var projfolderFiles =
                        Files.ProjectFolder.GetFilesInProjectFolder(proj.FullName);

                    // 新增的其他文件,如项目文件夹下的文件,使用户可以选择他们。
                    var totalItems = new List<Files.ProjectFileItem>(includedFiles);
                    foreach (Files.ProjectFileItem fileItem in projfolderFiles)
                    {
                        if (includedFiles.Count(f => f.FullName.Equals(fileItem.FullName,
                            StringComparison.OrdinalIgnoreCase)) == 0)
                        {
                            totalItems.Add(fileItem);
                        }
                    }

                    // 显示用户接口
                    using (SaveProjectDialog dialog = new SaveProjectDialog())
                    {
                        // 显示所有文件
                        dialog.FilesItems = totalItems;
                        dialog.OriginalFolderPath = vsProj.ProjectFolder.FullName;

                        var result = dialog.ShowDialog();

                        // 打开新的项目
                        if (result == DialogResult.OK && dialog.OpenNewProject)
                        {
                            string newProjectPath = string.Format("{0}\\{1}",
                                dialog.NewFolderPath,
                                proj.FullName.Substring(vsProj.ProjectFolder.FullName.Length));

                            string cmd = string.Format("File.OpenProject \"{0}\"", newProjectPath);

                            this.DTEObject.ExecuteCommand(cmd);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }