diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2020-03-18 15:05:50 +0100 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2020-03-18 15:06:41 +0100 |
commit | 40f8de4c1e8d61bc2d90c6fef740ee91b5851906 (patch) | |
tree | 7b6b0b6b01dcf3824fe35c946bd4178193cbb7f8 /modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs | |
parent | fe0b783e707198fbe64abda795ad234999f87834 (diff) |
Sync csproj when files are changed from the Godot FileSystem dock
Diffstat (limited to 'modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs')
-rw-r--r-- | modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs index af36f125f5..1776b46e6a 100644 --- a/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs +++ b/modules/mono/editor/GodotTools/GodotTools.ProjectEditor/ProjectUtils.cs @@ -23,6 +23,79 @@ namespace GodotTools.ProjectEditor root.Save(); } + public static void RenameItemInProjectChecked(string projectPath, string itemType, string oldInclude, string newInclude) + { + var dir = Directory.GetParent(projectPath).FullName; + var root = ProjectRootElement.Open(projectPath); + Debug.Assert(root != null); + + var normalizedOldInclude = oldInclude.NormalizePath(); + var normalizedNewInclude = newInclude.NormalizePath(); + + var item = root.FindItemOrNullAbs(itemType, normalizedOldInclude); + + if (item == null) + return; + + item.Include = normalizedNewInclude.RelativeToPath(dir).Replace("/", "\\"); + root.Save(); + } + + public static void RemoveItemFromProjectChecked(string projectPath, string itemType, string include) + { + var dir = Directory.GetParent(projectPath).FullName; + var root = ProjectRootElement.Open(projectPath); + Debug.Assert(root != null); + + var normalizedInclude = include.NormalizePath(); + + if (root.RemoveItemChecked(itemType, normalizedInclude)) + root.Save(); + } + + public static void RenameItemsToNewFolderInProjectChecked(string projectPath, string itemType, string oldFolder, string newFolder) + { + var dir = Directory.GetParent(projectPath).FullName; + var root = ProjectRootElement.Open(projectPath); + Debug.Assert(root != null); + + bool dirty = false; + + var oldFolderNormalized = oldFolder.NormalizePath(); + var newFolderNormalized = newFolder.NormalizePath(); + string absOldFolderNormalized = Path.GetFullPath(oldFolderNormalized).NormalizePath(); + string absNewFolderNormalized = Path.GetFullPath(newFolderNormalized).NormalizePath(); + + foreach (var item in root.FindAllItemsInFolder(itemType, oldFolderNormalized)) + { + string absPathNormalized = Path.GetFullPath(item.Include).NormalizePath(); + string absNewIncludeNormalized = absNewFolderNormalized + absPathNormalized.Substring(absOldFolderNormalized.Length); + item.Include = absNewIncludeNormalized.RelativeToPath(dir).Replace("/", "\\"); + dirty = true; + } + + if (dirty) + root.Save(); + } + + public static void RemoveItemsInFolderFromProjectChecked(string projectPath, string itemType, string folder) + { + var root = ProjectRootElement.Open(projectPath); + Debug.Assert(root != null); + + var folderNormalized = folder.NormalizePath(); + + var itemsToRemove = root.FindAllItemsInFolder(itemType, folderNormalized).ToList(); + + if (itemsToRemove.Count > 0) + { + foreach (var item in itemsToRemove) + item.Parent.RemoveChild(item); + + root.Save(); + } + } + private static string[] GetAllFilesRecursive(string rootDirectory, string mask) { string[] files = Directory.GetFiles(rootDirectory, mask, SearchOption.AllDirectories); |