public void ToggleDocumentClass(Project project, string[] paths) { foreach (string path in paths) { bool isMain = project.IsDocumentClass(path); project.SetDocumentClass(path, !isMain); } project.Save(); OnProjectModified(null); }
private void MoveRefactoredFiles() { MessageBar.Locked = true; AssociatedDocumentHelper.CloseTemporarilyOpenedDocuments(); foreach (var target in targets) { File.Delete(target.OldFilePath); if (target.OwnerPath == null) { OldPathToNewPath.Remove(target.OldFilePath); } // Casing changes, we cannot move directly here, there may be conflicts, better leave it to the next step if (target.TmpFilePath != null) { RefactoringHelper.Move(target.TmpFilePath, target.NewFilePath); } } // Move non-source files and whole folders foreach (KeyValuePair <string, string> item in OldPathToNewPath) { string oldPath = item.Key; string newPath = item.Value; if (File.Exists(oldPath)) { newPath = Path.Combine(newPath, Path.GetFileName(oldPath)); if (!Path.IsPathRooted(newPath)) { newPath = Path.Combine(Path.GetDirectoryName(oldPath), newPath); } RefactoringHelper.Move(oldPath, newPath, true); } else if (Directory.Exists(oldPath)) { newPath = renaming ? Path.Combine(Path.GetDirectoryName(oldPath), newPath) : Path.Combine(newPath, Path.GetFileName(oldPath)); // Look for document class changes // Do not use RefactoringHelper to avoid possible dialogs that we don't want ProjectManager.Projects.Project project = (ProjectManager.Projects.Project)PluginBase.CurrentProject; string newDocumentClass = null; string searchPattern = project.DefaultSearchFilter; foreach (string pattern in searchPattern.Split(';')) { foreach (string file in Directory.GetFiles(oldPath, pattern, SearchOption.AllDirectories)) { if (project.IsDocumentClass(file)) { newDocumentClass = file.Replace(oldPath, newPath); break; } } if (newDocumentClass != null) { break; } } // Check if this is a name casing change if (oldPath.Equals(newPath, StringComparison.OrdinalIgnoreCase)) { string tmpPath = oldPath + "$renaming$"; FileHelper.ForceMoveDirectory(oldPath, tmpPath); PluginCore.Managers.DocumentManager.MoveDocuments(oldPath, tmpPath); oldPath = tmpPath; } // Move directory contents to final location FileHelper.ForceMoveDirectory(oldPath, newPath); PluginCore.Managers.DocumentManager.MoveDocuments(oldPath, newPath); if (!string.IsNullOrEmpty(newDocumentClass)) { project.SetDocumentClass(newDocumentClass, true); project.Save(); } } } MessageBar.Locked = false; }