public async void AddExistingFolder () { var project = (Project) CurrentNode.GetParentDataItem (typeof(Project), true); var selectedFolder = ((FilePath) GetFolderPath (CurrentNode.DataItem)).CanonicalPath; var ofdlg = new SelectFolderDialog (GettextCatalog.GetString ("Add Existing Folder")) { CurrentFolder = !PreviousFolderPath.IsNullOrEmpty ? PreviousFolderPath : selectedFolder }; if(!ofdlg.Run ()) return; // We store the parent directory of the folder the user chooses as they will not need to add the same // directory twice. We can save them navigating up one directory by doing it for them PreviousFolderPath = ofdlg.SelectedFile.CanonicalPath; if (!PreviousFolderPath.ParentDirectory.IsNullOrEmpty) PreviousFolderPath = PreviousFolderPath.ParentDirectory; var srcRoot = ofdlg.SelectedFile.CanonicalPath; var targetRoot = selectedFolder.Combine (srcRoot.FileName); bool changedProject = false; if (File.Exists (targetRoot)) { MessageService.ShowWarning (GettextCatalog.GetString ( "There is already a file with the name '{0}' in the target directory", srcRoot.FileName)); return; } var existingPf = project.Files.GetFileWithVirtualPath (targetRoot.ToRelative (project.BaseDirectory)); if (existingPf != null) { if (existingPf.Subtype != Subtype.Directory) { MessageService.ShowWarning (GettextCatalog.GetString ( "There is already a link with the name '{0}' in the target directory", srcRoot.FileName)); return; } } var foundFiles = Directory.GetFiles (srcRoot, "*", SearchOption.AllDirectories); using (var impdlg = new IncludeNewFilesDialog (GettextCatalog.GetString ("Select files to add from {0}", srcRoot.FileName), srcRoot.ParentDirectory)) { impdlg.AddFiles (foundFiles); if (MessageService.ShowCustomDialog (impdlg) == (int)ResponseType.Ok) { var srcFiles = impdlg.SelectedFiles; var targetFiles = srcFiles.Select (f => targetRoot.Combine (f.ToRelative (srcRoot))); if (IdeApp.ProjectOperations.AddFilesToProject (project, srcFiles.ToArray (), targetFiles.ToArray (), null).Any ()) changedProject = true; else if (!srcFiles.Any () && existingPf == null) { // Just add empty folder. project.Files.Add (new ProjectFile (targetRoot) { Subtype = Subtype.Directory }); changedProject = true; } } if (changedProject) await IdeApp.ProjectOperations.SaveAsync (project); } }
public void AddExistingFolder() { var project = (FolderBasedProject)CurrentNode.GetParentDataItem(typeof(FolderBasedProject), true); var selectedFolder = ((FilePath)GetPath(CurrentNode.DataItem)).CanonicalPath; var ofdlg = new SelectFolderDialog(GettextCatalog.GetString("Add Existing Folder")) { CurrentFolder = !PreviousFolderPath.IsNullOrEmpty ? PreviousFolderPath : selectedFolder }; if (!ofdlg.Run()) { return; } // We store the parent directory of the folder the user chooses as they will not need to add the same // directory twice. We can save them navigating up one directory by doing it for them PreviousFolderPath = ofdlg.SelectedFile.CanonicalPath; if (!PreviousFolderPath.ParentDirectory.IsNullOrEmpty) { PreviousFolderPath = PreviousFolderPath.ParentDirectory; } var srcRoot = ofdlg.SelectedFile.CanonicalPath; var targetRoot = selectedFolder.Combine(srcRoot.FileName); if (File.Exists(targetRoot)) { MessageService.ShowWarning(GettextCatalog.GetString( "There is already a file with the name '{0}' in the target directory", srcRoot.FileName)); return; } var foundFiles = Directory.GetFiles(srcRoot, "*", SearchOption.AllDirectories); using (var impdlg = new IncludeNewFilesDialog(GettextCatalog.GetString("Select files to add from {0}", srcRoot.FileName), srcRoot.ParentDirectory)) { impdlg.AddFiles(foundFiles); if (MessageService.ShowCustomDialog(impdlg) == (int)ResponseType.Ok) { var srcFiles = impdlg.SelectedFiles; var targetFiles = srcFiles.Select(f => targetRoot.Combine(f.ToRelative(srcRoot))); foreach (var srcFile in srcFiles) { foreach (var targetFile in targetFiles) { if (srcFile.ToRelative(srcRoot).Equals(targetFile.ToRelative(targetRoot))) { CopyFile(srcFile, targetFile); } } } project.OnFilesAdded(targetFiles.ToList()); } } Tree.BuilderContext.GetTreeBuilder(CurrentNode).UpdateChildren(); }
public void AddFilesFromFolder() { var project = (FolderBasedProject)CurrentNode.GetParentDataItem(typeof(FolderBasedProject), true); var targetRoot = ((FilePath)GetPath(CurrentNode.DataItem)).CanonicalPath; var ofdlg = new SelectFolderDialog(GettextCatalog.GetString("Import From Folder")) { CurrentFolder = !PreviousFolderPath.IsNullOrEmpty ? PreviousFolderPath : targetRoot }; if (!ofdlg.Run()) { return; } PreviousFolderPath = ofdlg.SelectedFile.CanonicalPath; if (!PreviousFolderPath.ParentDirectory.IsNullOrEmpty) { PreviousFolderPath = PreviousFolderPath.ParentDirectory; } var srcRoot = ofdlg.SelectedFile.CanonicalPath; var foundFiles = Directory.GetFiles(srcRoot, "*", SearchOption.AllDirectories); if (foundFiles.Length == 0) { MessageService.GenericAlert(MonoDevelop.Ide.Gui.Stock.Information, GettextCatalog.GetString("Empty directory."), GettextCatalog.GetString("Directory {0} is empty, no files have been added.", srcRoot.FileName), AlertButton.Close); return; } using (var impdlg = new IncludeNewFilesDialog(GettextCatalog.GetString("Select files to add from {0}", srcRoot.FileName), srcRoot)) { impdlg.AddFiles(foundFiles); if (MessageService.ShowCustomDialog(impdlg) != (int)ResponseType.Ok) { return; } var srcFiles = impdlg.SelectedFiles; var targetFiles = srcFiles.Select(f => targetRoot.Combine(f.ToRelative(srcRoot))); foreach (var file in srcFiles.ToArray()) { CopyFile(file, targetRoot); } project.OnFilesAdded(targetFiles.ToList()); } Tree.BuilderContext.GetTreeBuilder(CurrentNode).UpdateChildren(); }
public void AddFilesFromFolder() { var project = (Project)CurrentNode.GetParentDataItem(typeof(Project), true); var targetRoot = ((FilePath)GetFolderPath(CurrentNode.DataItem)).CanonicalPath; var ofdlg = new SelectFolderDialog(GettextCatalog.GetString("Import From Folder")) { CurrentFolder = !PreviousFolderPath.IsNullOrEmpty ? PreviousFolderPath : targetRoot }; if (!ofdlg.Run()) { return; } PreviousFolderPath = ofdlg.SelectedFile.CanonicalPath; if (!PreviousFolderPath.ParentDirectory.IsNullOrEmpty) { PreviousFolderPath = PreviousFolderPath.ParentDirectory; } var srcRoot = ofdlg.SelectedFile.CanonicalPath; var foundFiles = Directory.GetFiles(srcRoot, "*", SearchOption.AllDirectories); if (foundFiles.Length == 0) { MessageService.GenericAlert(Stock.Information, GettextCatalog.GetString("Empty directory."), GettextCatalog.GetString("Directory {0} is empty, no files have been added.", srcRoot.FileName), AlertButton.Close); return; } var impdlg = new IncludeNewFilesDialog(GettextCatalog.GetString("Select files to add from {0}", srcRoot.FileName), srcRoot); impdlg.AddFiles(foundFiles); if (MessageService.ShowCustomDialog(impdlg) != (int)ResponseType.Ok) { return; } var srcFiles = impdlg.SelectedFiles; var targetFiles = srcFiles.Select(f => targetRoot.Combine(f.ToRelative(srcRoot))); var added = IdeApp.ProjectOperations.AddFilesToProject(project, srcFiles.ToArray(), targetFiles.ToArray(), null).Any(); if (added) { IdeApp.ProjectOperations.Save(project); } }
public void AddFilesFromFolder() { var project = (Project)CurrentNode.GetParentDataItem(typeof(Project), true); var targetRoot = ((FilePath)GetFolderPath(CurrentNode.DataItem)).CanonicalPath; var ofdlg = new SelectFolderDialog(GettextCatalog.GetString("Import From Folder")) { CurrentFolder = targetRoot }; if (!ofdlg.Run()) { return; } var srcRoot = ofdlg.SelectedFile.CanonicalPath; var foundFiles = Directory.GetFiles(srcRoot, "*", SearchOption.AllDirectories); var impdlg = new IncludeNewFilesDialog(GettextCatalog.GetString("Select files to add from {0}", srcRoot.FileName), srcRoot); impdlg.AddFiles(foundFiles); if (MessageService.ShowCustomDialog(impdlg) != (int)ResponseType.Ok) { return; } var srcFiles = impdlg.SelectedFiles; var targetFiles = srcFiles.Select(f => targetRoot.Combine(f.ToRelative(srcRoot))); var added = IdeApp.ProjectOperations.AddFilesToProject(project, srcFiles.ToArray(), targetFiles.ToArray(), null).Any(); if (added) { IdeApp.ProjectOperations.Save(project); } }
public void AddExistingFolder() { var project = (Project)CurrentNode.GetParentDataItem(typeof(Project), true); var selectedFolder = ((FilePath)GetFolderPath(CurrentNode.DataItem)).CanonicalPath; var ofdlg = new SelectFolderDialog(GettextCatalog.GetString("Add Existing Folder")) { CurrentFolder = selectedFolder }; if (!ofdlg.Run()) { return; } var srcRoot = ofdlg.SelectedFile.CanonicalPath; var targetRoot = selectedFolder.Combine(srcRoot.FileName); bool changedProject = false; if (File.Exists(targetRoot)) { MessageService.ShowWarning(GettextCatalog.GetString( "There is already a file with the name '{0}' in the target directory", srcRoot.FileName)); return; } var existingPf = project.Files.GetFileWithVirtualPath(targetRoot.ToRelative(project.BaseDirectory)); if (existingPf != null) { if (existingPf.Subtype != Subtype.Directory) { MessageService.ShowWarning(GettextCatalog.GetString( "There is already a link with the name '{0}' in the target directory", srcRoot.FileName)); return; } } else { project.Files.Add(new ProjectFile(targetRoot) { Subtype = Subtype.Directory }); changedProject = true; } var foundFiles = Directory.GetFiles(srcRoot, "*", SearchOption.AllDirectories); var impdlg = new IncludeNewFilesDialog(GettextCatalog.GetString("Select files to add from {0}", srcRoot.FileName), srcRoot.ParentDirectory); impdlg.AddFiles(foundFiles); if (MessageService.ShowCustomDialog(impdlg) == (int)ResponseType.Ok) { var srcFiles = impdlg.SelectedFiles; var targetFiles = srcFiles.Select(f => targetRoot.Combine(f.ToRelative(srcRoot))); if (IdeApp.ProjectOperations.AddFilesToProject(project, srcFiles.ToArray(), targetFiles.ToArray(), null).Any()) { changedProject = true; } } if (changedProject) { IdeApp.ProjectOperations.Save(project); } }