Esempio n. 1
0
        public override void DeleteMultipleItems()
        {
            var  projects    = new Set <SolutionItem> ();
            var  files       = new List <ProjectFile> ();
            bool hasChildren = false;

            foreach (var node in CurrentNodes)
            {
                var pf = (ProjectFile)node.DataItem;
                projects.Add(pf.Project);
                if (pf.HasChildren || FileNestingService.HasChildren(pf))
                {
                    hasChildren = true;
                }
                files.Add(pf);
            }

            string question;
            bool   filesExist = CheckAnyFileExists(files);

            if (hasChildren)
            {
                if (files.Count == 1)
                {
                    question = GettextCatalog.GetString("Are you sure you want to delete the file {0} and " +
                                                        "its code-behind children from project {1}?",
                                                        Path.GetFileName(files[0].Name), files[0].Project.Name);
                }
                else
                {
                    question = GettextCatalog.GetString("Are you sure you want to delete the selected files and " +
                                                        "their code-behind children from the project?");
                }
            }
            else
            {
                if (files.Count == 1)
                {
                    question = GettextCatalog.GetString("Are you sure you want to delete file {0} from project {1}?",
                                                        Path.GetFileName(files[0].Name), files[0].Project.Name);
                }
                else
                {
                    question = GettextCatalog.GetString("Are you sure you want to delete the selected files from the project?");
                }
            }

            var result = MessageService.AskQuestion(question, GetDeleteConfirmationButtons(filesExist));

            if (result != AlertButton.Delete)
            {
                return;
            }

            RemoveFilesFromProject(true, files);
            IdeApp.ProjectOperations.SaveAsync(projects);
        }
Esempio n. 2
0
        public override void DeleteMultipleItems()
        {
            var  projects    = new Set <SolutionItem> ();
            var  files       = new List <ProjectFile> ();
            bool hasChildren = false;

            foreach (var node in CurrentNodes)
            {
                var pf = (ProjectFile)node.DataItem;
                projects.Add(pf.Project);
                if (pf.HasChildren || FileNestingService.HasChildren(pf))
                {
                    hasChildren = true;
                }
                files.Add(pf);
            }

            var    removeFromProject = new AlertButton(GettextCatalog.GetString("_Remove from Project"), Gtk.Stock.Remove);
            string question;
            string secondaryText = null;

            bool filesExist = CheckAnyFileExists(files);

            if (filesExist)
            {
                secondaryText = GettextCatalog.GetString("The Delete option permanently removes the file from your hard disk. " +
                                                         "Click Remove from Project if you only want to remove it from your current solution.");
            }

            if (hasChildren)
            {
                if (files.Count == 1)
                {
                    question = GettextCatalog.GetString("Are you sure you want to remove the file {0} and " +
                                                        "its code-behind children from project {1}?",
                                                        Path.GetFileName(files[0].Name), files[0].Project.Name);
                }
                else
                {
                    question = GettextCatalog.GetString("Are you sure you want to remove the selected files and " +
                                                        "their code-behind children from the project?");
                }
            }
            else
            {
                if (files.Count == 1)
                {
                    question = GettextCatalog.GetString("Are you sure you want to remove file {0} from project {1}?",
                                                        Path.GetFileName(files[0].Name), files[0].Project.Name);
                }
                else
                {
                    question = GettextCatalog.GetString("Are you sure you want to remove the selected files from the project?");
                }
            }

            var result = MessageService.AskQuestion(question, secondaryText, GetDeleteConfirmationButtons(filesExist, removeFromProject));

            if (result != removeFromProject && result != AlertButton.Delete)
            {
                return;
            }

            foreach (var file in files)
            {
                var project  = file.Project;
                var inFolder = project.Files.GetFilesInVirtualPath(file.ProjectVirtualPath.ParentDirectory).ToList();

                if (inFolder.Count == 1 && inFolder [0] == file && project.Files.GetFileWithVirtualPath(file.ProjectVirtualPath.ParentDirectory) == null)
                {
                    // This is the last project file in the folder. Make sure we keep
                    // a reference to the folder, so it is not deleted from the tree.
                    var folderFile = new ProjectFile(project.BaseDirectory.Combine(file.ProjectVirtualPath.ParentDirectory));
                    folderFile.Subtype = Subtype.Directory;
                    project.Files.Add(folderFile);
                }

                var children = FileNestingService.GetDependentOrNestedChildren(file);
                if (children != null)
                {
                    foreach (var child in children.ToArray())
                    {
                        project.Files.Remove(child);
                        if (result == AlertButton.Delete)
                        {
                            FileService.DeleteFile(child.Name);
                        }
                    }
                }

                project.Files.Remove(file);
                if (result == AlertButton.Delete && !file.IsLink)
                {
                    FileService.DeleteFile(file.Name);
                }
            }

            IdeApp.ProjectOperations.SaveAsync(projects);
        }
Esempio n. 3
0
        public override bool HasChildNodes(ITreeBuilder builder, object dataObject)
        {
            ProjectFile file = (ProjectFile)dataObject;

            return(file.HasChildren || FileNestingService.HasChildren(file));
        }