DirectoryNode CreateNewDirectory(DirectoryNode upper, string directoryName) { upper.ExpandSubtree(); Directory.CreateDirectory(directoryName); FileService.FireFileCreated(directoryName, true); DirectoryNode directoryNode = new DirectoryNode(directoryName, FileNodeStatus.InProject); directoryNode.InsertSorted(upper); IncludeFileInProject.IncludeDirectoryNode(directoryNode, false); return(directoryNode); }
public override void Run() { ProjectBrowserPad.Instance.BringToFront(); DirectoryNode node = ProjectBrowserPad.Instance.ProjectBrowserControl.SelectedDirectoryNode; if (node == null) { return; } node.ExpandSubtree(); string newDirectoryName = GenerateValidDirectoryName(node.Directory); DirectoryNode newDirectoryNode = CreateNewDirectory(node, newDirectoryName); //ProjectBrowserPad.Instance.StartLabelEdit(newDirectoryNode); }
protected IEnumerable <FileProjectItem> AddNewItems() { DirectoryNode node = ProjectBrowserPad.Instance.ProjectBrowserControl.SelectedDirectoryNode; if (node == null) { return(null); } node.ExpandSubtree(); //node.Expanding(); FileTemplateResult result = SD.UIService.ShowNewFileDialog(node.Project, node.Directory); if (result != null) { node.RecreateSubNodes(); ProjectBrowserPad.Instance.ProjectBrowserControl.SelectFile(result.Options.FileName); return(result.NewFiles.Select(node.Project.FindFile).Where(f => f != null).ToArray()); } else { return(null); } }
public static void CopyDirectory(string directoryName, DirectoryNode node, bool includeInProject) { directoryName = FileUtility.NormalizePath(directoryName); string copiedFileName = Path.Combine(node.Directory, Path.GetFileName(directoryName)); LoggingService.Debug("Copy " + directoryName + " to " + copiedFileName); if (!FileUtility.IsEqualFileName(directoryName, copiedFileName)) { if (includeInProject && ProjectService.OpenSolution != null) { // get ProjectItems in source directory foreach (IProject project in ProjectService.OpenSolution.Projects) { if (!FileUtility.IsBaseDirectory(project.Directory, directoryName)) { continue; } LoggingService.Debug("Searching for child items in " + project.Name); foreach (ProjectItem item in project.Items) { FileProjectItem fileItem = item as FileProjectItem; if (fileItem == null) { continue; } string virtualFullName = Path.Combine(project.Directory, fileItem.VirtualName); if (FileUtility.IsBaseDirectory(directoryName, virtualFullName)) { if (item.ItemType == ItemType.Folder && FileUtility.IsEqualFileName(directoryName, virtualFullName)) { continue; } LoggingService.Debug("Found file " + virtualFullName); FileProjectItem newItem = new FileProjectItem(node.Project, fileItem.ItemType); if (FileUtility.IsBaseDirectory(directoryName, fileItem.FileName)) { newItem.FileName = FileName.Create(FileUtility.RenameBaseDirectory(fileItem.FileName, directoryName, copiedFileName)); } else { newItem.FileName = fileItem.FileName; } fileItem.CopyMetadataTo(newItem); if (fileItem.IsLink) { string newVirtualFullName = FileUtility.RenameBaseDirectory(virtualFullName, directoryName, copiedFileName); fileItem.SetEvaluatedMetadata("Link", FileUtility.GetRelativePath(node.Project.Directory, newVirtualFullName)); } ProjectService.AddProjectItem(node.Project, newItem); } } } } FileService.CopyFile(directoryName, copiedFileName, true, false); DirectoryNode newNode = new DirectoryNode(copiedFileName); newNode.InsertSorted(node); if (includeInProject) { IncludeFileInProject.IncludeDirectoryNode(newNode, false); } newNode.ExpandSubtree(); } else if (includeInProject) { foreach (TreeNode childNode in node.Items) { if (childNode is DirectoryNode) { DirectoryNode directoryNode = (DirectoryNode)childNode; if (FileUtility.IsEqualFileName(directoryNode.Directory, copiedFileName)) { IncludeFileInProject.IncludeDirectoryNode(directoryNode, true); } } } } }
public override void Run() { ProjectBrowserPad.Instance.BringToFront(); DirectoryNode node = ProjectBrowserPad.Instance.ProjectBrowserControl.SelectedDirectoryNode; if (node == null) { return; } //node.Expanding(); node.ExpandSubtree(); //using (FolderBrowserDialog dlg = new FolderBrowserDialog()) { //dlg.SelectedPath = node.Directory; //dlg.ShowNewFolderButton = false; //if (dlg.ShowDialog(SD.WinForms.MainWin32Window) == DialogResult.OK) string selectedPath = null; { Caliburn.Micro.Execute.OnUIThread(delegate { System.Windows.Forms.FolderBrowserDialog fldrDialog = new System.Windows.Forms.FolderBrowserDialog { SelectedPath = node.Directory, ShowNewFolderButton = false }; selectedPath = ((fldrDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) ? fldrDialog.SelectedPath : null); }); string folderName = selectedPath; //dlg.SelectedPath; string copiedFolderName = Path.Combine(node.Directory, Path.GetFileName(folderName)); if (!FileUtility.IsEqualFileName(folderName, copiedFolderName)) { if (FileUtility.IsBaseDirectory(folderName, node.Directory)) { MessageService.ShowError("Cannot copy " + folderName + " to " + copiedFolderName); return; } if (Directory.Exists(copiedFolderName)) { MessageService.ShowError("Cannot copy " + folderName + " to " + copiedFolderName + ": target already exists."); return; } int res = MessageService.ShowCustomDialog( "${res:ProjectComponent.ContextMenu.ExistingFolder}", "${res:ProjectComponent.ContextMenu.ExistingFolder.CopyQuestion}", 0, 1, "${res:ProjectComponent.ContextMenu.AddExistingFiles.Copy}", "${res:Global.CancelButtonText}"); if (res != 0) { return; } if (!FileService.CopyFile(folderName, copiedFolderName, true, false)) { return; } } // ugly HACK to get IncludeDirectoryNode to work properly AbstractProjectBrowserTreeNode.ShowAll = true; try { node.RecreateSubNodes(); DirectoryNode newNode = node.AllNodes.OfType <DirectoryNode>() .FirstOrDefault(dir => FileUtility.IsEqualFileName(copiedFolderName, dir.Directory)); if (newNode != null) { newNode.ExpandSubtree(); IncludeFileInProject.IncludeDirectoryNode(newNode, true); } } finally { AbstractProjectBrowserTreeNode.ShowAll = false; } node.RecreateSubNodes(); } } }
protected IEnumerable <FileProjectItem> AddExistingItems() { DirectoryNode node = ProjectBrowserPad.Instance.ProjectBrowserControl.SelectedDirectoryNode; if (node == null) { return(null); } //node.Expanding(); node.ExpandSubtree(); List <FileProjectItem> addedItems = new List <FileProjectItem>(); //using (OpenFileDialog fdiag = new OpenFileDialog()) { string[] files = null; Caliburn.Micro.Execute.OnUIThread(delegate { Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog { Title = StringParser.Parse("${res:ProjectComponent.ContextMenu.AddExistingFiles}"), CheckFileExists = true, RestoreDirectory = true, InitialDirectory = node.Directory, AddExtension = true, FilterIndex = GetFileFilterIndex(node.Project, ProjectService.GetFileFilters()), Filter = String.Join("|", ProjectService.GetFileFilters()), Multiselect = true }; if (fileDialog.ShowDialog() == true) { files = fileDialog.FileNames; } }); //if (fdiag.ShowDialog(SD.WinForms.MainWin32Window) == DialogResult.OK) { List <KeyValuePair <string, string> > fileNames = new List <KeyValuePair <string, string> >(files.Length); foreach (string fileName in files) { fileNames.Add(new KeyValuePair <string, string>(fileName, "")); } bool addedDependentFiles = false; foreach (string fileName in files) { foreach (string additionalFile in FindAdditionalFiles(fileName)) { if (!fileNames.Exists(delegate(KeyValuePair <string, string> pair) { return(FileUtility.IsEqualFileName(pair.Key, additionalFile)); })) { addedDependentFiles = true; fileNames.Add(new KeyValuePair <string, string>(additionalFile, Path.GetFileName(fileName))); } } } string copiedFileName = Path.Combine(node.Directory, Path.GetFileName(fileNames[0].Key)); if (!FileUtility.IsEqualFileName(fileNames[0].Key, copiedFileName)) { int res = MessageService.ShowCustomDialog( StringParser.Parse("${res:ProjectComponent.ContextMenu.AddExistingFiles}"), "${res:ProjectComponent.ContextMenu.AddExistingFiles.Question}", 0, 2, "${res:ProjectComponent.ContextMenu.AddExistingFiles.Copy}", "${res:ProjectComponent.ContextMenu.AddExistingFiles.Link}", "${res:Global.CancelButtonText}"); if (res == 1) { // Link foreach (KeyValuePair <string, string> pair in fileNames) { string fileName = pair.Key; string relFileName = FileUtility.GetRelativePath(node.Project.Directory, fileName); FileNode fileNode = new FileNode(fileName, FileNodeStatus.InProject); FileProjectItem fileProjectItem = new FileProjectItem(node.Project, node.Project.GetDefaultItemType(fileName), relFileName); fileProjectItem.SetEvaluatedMetadata("Link", Path.Combine(node.RelativePath, Path.GetFileName(fileName))); fileProjectItem.DependentUpon = pair.Value; addedItems.Add(fileProjectItem); fileNode.ProjectItem = fileProjectItem; fileNode.InsertSorted(node); ProjectService.AddProjectItem(node.Project, fileProjectItem); } node.Project.Save(); if (addedDependentFiles) { node.RecreateSubNodes(); } return(addedItems.AsReadOnly()); } if (res == 2) { // Cancel return(addedItems.AsReadOnly()); } // only continue for res==0 (Copy) } bool replaceAll = false; foreach (KeyValuePair <string, string> pair in fileNames) { copiedFileName = Path.Combine(node.Directory, Path.GetFileName(pair.Key)); if (!replaceAll && File.Exists(copiedFileName) && !FileUtility.IsEqualFileName(pair.Key, copiedFileName)) { ReplaceExistingFile res = ShowReplaceExistingFileDialog( StringParser.Parse("${res:ProjectComponent.ContextMenu.AddExistingFiles}"), Path.GetFileName(pair.Key), true); if (res == ReplaceExistingFile.YesToAll) { replaceAll = true; } else if (res == ReplaceExistingFile.No) { continue; } else if (res == ReplaceExistingFile.Cancel) { break; } } FileProjectItem item = CopyFile(pair.Key, node, true); if (item != null) { addedItems.Add(item); item.DependentUpon = pair.Value; } } node.Project.Save(); if (addedDependentFiles) { node.RecreateSubNodes(); } } //} return(addedItems.AsReadOnly()); }