Merge pull request #37149 from neikeq/issue-12917-3.2
[3.2] Sync csproj when files are changed from the Godot FileSystem dock
This commit is contained in:
commit
eec14d4323
12 changed files with 205 additions and 43 deletions
|
@ -3673,6 +3673,7 @@ void EditorNode::register_editor_types() {
|
|||
ClassDB::register_class<ScriptCreateDialog>();
|
||||
ClassDB::register_class<EditorFeatureProfile>();
|
||||
ClassDB::register_class<EditorSpinSlider>();
|
||||
ClassDB::register_virtual_class<FileSystemDock>();
|
||||
|
||||
// FIXME: Is this stuff obsolete, or should it be ported to new APIs?
|
||||
ClassDB::register_class<EditorScenePostImport>();
|
||||
|
|
|
@ -227,6 +227,10 @@ EditorFileSystem *EditorInterface::get_resource_file_system() {
|
|||
return EditorFileSystem::get_singleton();
|
||||
}
|
||||
|
||||
FileSystemDock *EditorInterface::get_file_system_dock() {
|
||||
return EditorNode::get_singleton()->get_filesystem_dock();
|
||||
}
|
||||
|
||||
EditorSelection *EditorInterface::get_selection() {
|
||||
return EditorNode::get_singleton()->get_editor_selection();
|
||||
}
|
||||
|
@ -296,6 +300,7 @@ void EditorInterface::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("select_file", "file"), &EditorInterface::select_file);
|
||||
ClassDB::bind_method(D_METHOD("get_selected_path"), &EditorInterface::get_selected_path);
|
||||
ClassDB::bind_method(D_METHOD("get_current_path"), &EditorInterface::get_current_path);
|
||||
ClassDB::bind_method(D_METHOD("get_file_system_dock"), &EditorInterface::get_file_system_dock);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_plugin_enabled", "plugin", "enabled"), &EditorInterface::set_plugin_enabled);
|
||||
ClassDB::bind_method(D_METHOD("is_plugin_enabled", "plugin"), &EditorInterface::is_plugin_enabled);
|
||||
|
|
|
@ -53,6 +53,7 @@ class EditorSpatialGizmoPlugin;
|
|||
class EditorResourcePreview;
|
||||
class EditorFileSystem;
|
||||
class EditorToolAddons;
|
||||
class FileSystemDock;
|
||||
class ScriptEditor;
|
||||
|
||||
class EditorInterface : public Node {
|
||||
|
@ -88,6 +89,8 @@ public:
|
|||
EditorResourcePreview *get_resource_previewer();
|
||||
EditorFileSystem *get_resource_file_system();
|
||||
|
||||
FileSystemDock *get_file_system_dock();
|
||||
|
||||
Control *get_base_control();
|
||||
|
||||
void set_plugin_enabled(const String &p_plugin, bool p_enabled);
|
||||
|
|
|
@ -1287,12 +1287,12 @@ void FileSystemDock::_make_scene_confirm() {
|
|||
editor->get_editor_data().set_scene_path(idx, scene_name);
|
||||
}
|
||||
|
||||
void FileSystemDock::_file_deleted(String p_file) {
|
||||
emit_signal("file_deleted", p_file);
|
||||
void FileSystemDock::_file_removed(String p_file) {
|
||||
emit_signal("file_removed", p_file);
|
||||
}
|
||||
|
||||
void FileSystemDock::_folder_deleted(String p_folder) {
|
||||
emit_signal("folder_deleted", p_folder);
|
||||
void FileSystemDock::_folder_removed(String p_folder) {
|
||||
emit_signal("folder_removed", p_folder);
|
||||
}
|
||||
|
||||
void FileSystemDock::_rename_operation_confirm() {
|
||||
|
@ -2470,8 +2470,8 @@ void FileSystemDock::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("_file_list_rmb_pressed"), &FileSystemDock::_file_list_rmb_pressed);
|
||||
ClassDB::bind_method(D_METHOD("_tree_rmb_empty"), &FileSystemDock::_tree_rmb_empty);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_file_deleted"), &FileSystemDock::_file_deleted);
|
||||
ClassDB::bind_method(D_METHOD("_folder_deleted"), &FileSystemDock::_folder_deleted);
|
||||
ClassDB::bind_method(D_METHOD("_file_removed"), &FileSystemDock::_file_removed);
|
||||
ClassDB::bind_method(D_METHOD("_folder_removed"), &FileSystemDock::_folder_removed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_file_list_thumbnail_done"), &FileSystemDock::_file_list_thumbnail_done);
|
||||
ClassDB::bind_method(D_METHOD("_tree_thumbnail_done"), &FileSystemDock::_tree_thumbnail_done);
|
||||
|
@ -2651,8 +2651,8 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
|
|||
add_child(owners_editor);
|
||||
|
||||
remove_dialog = memnew(DependencyRemoveDialog);
|
||||
remove_dialog->connect("file_removed", this, "_file_deleted");
|
||||
remove_dialog->connect("folder_removed", this, "_folder_deleted");
|
||||
remove_dialog->connect("file_removed", this, "_file_removed");
|
||||
remove_dialog->connect("folder_removed", this, "_folder_removed");
|
||||
add_child(remove_dialog);
|
||||
|
||||
move_dialog = memnew(EditorDirDialog);
|
||||
|
|
|
@ -210,8 +210,8 @@ private:
|
|||
void _update_favorites_list_after_move(const Map<String, String> &p_files_renames, const Map<String, String> &p_folders_renames) const;
|
||||
void _update_project_settings_after_move(const Map<String, String> &p_renames) const;
|
||||
|
||||
void _file_deleted(String p_file);
|
||||
void _folder_deleted(String p_folder);
|
||||
void _file_removed(String p_file);
|
||||
void _folder_removed(String p_folder);
|
||||
void _files_moved(String p_old_file, String p_new_file);
|
||||
void _folder_moved(String p_old_folder, String p_new_folder);
|
||||
|
||||
|
|
|
@ -2881,22 +2881,6 @@ void CSharpScript::initialize_for_managed_type(Ref<CSharpScript> p_script, GDMon
|
|||
|
||||
bool CSharpScript::can_instance() const {
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
|
||||
// Hack to lower the risk of attached scripts not being added to the C# project
|
||||
if (!get_path().empty() && get_path().find("::") == -1) { // Ignore if built-in script. Can happen if the file is deleted...
|
||||
if (_create_project_solution_if_needed()) {
|
||||
CSharpProject::add_item(GodotSharpDirs::get_project_csproj_path(),
|
||||
"Compile",
|
||||
ProjectSettings::get_singleton()->globalize_path(get_path()));
|
||||
} else {
|
||||
ERR_PRINTS("C# project could not be created; cannot add file: '" + get_path() + "'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
bool extra_cond = tool || ScriptServer::is_scripting_enabled();
|
||||
#else
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace GodotTools.Core
|
|||
|
||||
path = string.Join(Path.DirectorySeparatorChar.ToString(), parts).Trim();
|
||||
|
||||
return rooted ? Path.DirectorySeparatorChar.ToString() + path : path;
|
||||
return rooted ? Path.DirectorySeparatorChar + path : path;
|
||||
}
|
||||
|
||||
private static readonly string driveRoot = Path.GetPathRoot(Environment.CurrentDirectory);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using GodotTools.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using DotNet.Globbing;
|
||||
using Microsoft.Build.Construction;
|
||||
|
||||
|
@ -7,16 +9,15 @@ namespace GodotTools.ProjectEditor
|
|||
{
|
||||
public static class ProjectExtensions
|
||||
{
|
||||
public static bool HasItem(this ProjectRootElement root, string itemType, string include)
|
||||
public static ProjectItemElement FindItemOrNull(this ProjectRootElement root, string itemType, string include, bool noCondition = false)
|
||||
{
|
||||
GlobOptions globOptions = new GlobOptions();
|
||||
globOptions.Evaluation.CaseInsensitive = false;
|
||||
GlobOptions globOptions = new GlobOptions {Evaluation = {CaseInsensitive = false}};
|
||||
|
||||
string normalizedInclude = include.NormalizePath();
|
||||
|
||||
foreach (var itemGroup in root.ItemGroups)
|
||||
{
|
||||
if (itemGroup.Condition.Length != 0)
|
||||
if (noCondition && itemGroup.Condition.Length != 0)
|
||||
continue;
|
||||
|
||||
foreach (var item in itemGroup.Items)
|
||||
|
@ -27,20 +28,79 @@ namespace GodotTools.ProjectEditor
|
|||
var glob = Glob.Parse(item.Include.NormalizePath(), globOptions);
|
||||
|
||||
if (glob.IsMatch(normalizedInclude))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public static ProjectItemElement FindItemOrNullAbs(this ProjectRootElement root, string itemType, string include, bool noCondition = false)
|
||||
{
|
||||
GlobOptions globOptions = new GlobOptions {Evaluation = {CaseInsensitive = false}};
|
||||
|
||||
string normalizedInclude = Path.GetFullPath(include).NormalizePath();
|
||||
|
||||
foreach (var itemGroup in root.ItemGroups)
|
||||
{
|
||||
if (noCondition && itemGroup.Condition.Length != 0)
|
||||
continue;
|
||||
|
||||
foreach (var item in itemGroup.Items)
|
||||
{
|
||||
if (item.ItemType != itemType)
|
||||
continue;
|
||||
|
||||
var glob = Glob.Parse(Path.GetFullPath(item.Include).NormalizePath(), globOptions);
|
||||
|
||||
if (glob.IsMatch(normalizedInclude))
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IEnumerable<ProjectItemElement> FindAllItemsInFolder(this ProjectRootElement root, string itemType, string folder)
|
||||
{
|
||||
string absFolderNormalizedWithSep = Path.GetFullPath(folder).NormalizePath() + Path.DirectorySeparatorChar;
|
||||
|
||||
foreach (var itemGroup in root.ItemGroups)
|
||||
{
|
||||
foreach (var item in itemGroup.Items)
|
||||
{
|
||||
if (item.ItemType != itemType)
|
||||
continue;
|
||||
|
||||
string absPathNormalized = Path.GetFullPath(item.Include).NormalizePath();
|
||||
|
||||
if (absPathNormalized.StartsWith(absFolderNormalizedWithSep))
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool HasItem(this ProjectRootElement root, string itemType, string include, bool noCondition = false)
|
||||
{
|
||||
return root.FindItemOrNull(itemType, include, noCondition) != null;
|
||||
}
|
||||
|
||||
public static bool AddItemChecked(this ProjectRootElement root, string itemType, string include)
|
||||
{
|
||||
if (!root.HasItem(itemType, include, noCondition: true))
|
||||
{
|
||||
root.AddItem(itemType, include);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool AddItemChecked(this ProjectRootElement root, string itemType, string include)
|
||||
public static bool RemoveItemChecked(this ProjectRootElement root, string itemType, string include)
|
||||
{
|
||||
if (!root.HasItem(itemType, include))
|
||||
var item = root.FindItemOrNullAbs(itemType, include);
|
||||
if (item != null)
|
||||
{
|
||||
root.AddItem(itemType, include);
|
||||
item.Parent.RemoveChild(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,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);
|
||||
|
|
|
@ -96,7 +96,7 @@ namespace GodotTools.Export
|
|||
if (type != Internal.CSharpLanguageType)
|
||||
return;
|
||||
|
||||
if (Path.GetExtension(path) != $".{Internal.CSharpLanguageExtension}")
|
||||
if (Path.GetExtension(path) != Internal.CSharpLanguageExtension)
|
||||
throw new ArgumentException($"Resource of type {Internal.CSharpLanguageType} has an invalid file extension: {path}", nameof(path));
|
||||
|
||||
// TODO What if the source file is not part of the game's C# project
|
||||
|
|
|
@ -13,6 +13,7 @@ using JetBrains.Annotations;
|
|||
using static GodotTools.Internals.Globals;
|
||||
using File = GodotTools.Utils.File;
|
||||
using OS = GodotTools.Utils.OS;
|
||||
using Path = System.IO.Path;
|
||||
|
||||
namespace GodotTools
|
||||
{
|
||||
|
@ -61,7 +62,7 @@ namespace GodotTools
|
|||
{
|
||||
Guid = guid,
|
||||
PathRelativeToSolution = name + ".csproj",
|
||||
Configs = new List<string> { "Debug", "Release", "Tools" }
|
||||
Configs = new List<string> {"Debug", "Release", "Tools"}
|
||||
};
|
||||
|
||||
solution.AddNewProject(name, projectInfo);
|
||||
|
@ -154,6 +155,34 @@ namespace GodotTools
|
|||
Instance.BottomPanel.BuildProjectPressed();
|
||||
}
|
||||
|
||||
private void _FileSystemDockFileMoved(string file, string newFile)
|
||||
{
|
||||
if (Path.GetExtension(file) == Internal.CSharpLanguageExtension)
|
||||
{
|
||||
ProjectUtils.RenameItemInProjectChecked(GodotSharpDirs.ProjectCsProjPath, "Compile",
|
||||
ProjectSettings.GlobalizePath(file), ProjectSettings.GlobalizePath(newFile));
|
||||
}
|
||||
}
|
||||
|
||||
private void _FileSystemDockFileRemoved(string file)
|
||||
{
|
||||
if (Path.GetExtension(file) == Internal.CSharpLanguageExtension)
|
||||
ProjectUtils.RemoveItemFromProjectChecked(GodotSharpDirs.ProjectCsProjPath, "Compile",
|
||||
ProjectSettings.GlobalizePath(file));
|
||||
}
|
||||
|
||||
private void _FileSystemDockFolderMoved(string oldFolder, string newFolder)
|
||||
{
|
||||
ProjectUtils.RenameItemsToNewFolderInProjectChecked(GodotSharpDirs.ProjectCsProjPath, "Compile",
|
||||
ProjectSettings.GlobalizePath(oldFolder), ProjectSettings.GlobalizePath(newFolder));
|
||||
}
|
||||
|
||||
private void _FileSystemDockFolderRemoved(string oldFolder)
|
||||
{
|
||||
ProjectUtils.RemoveItemsInFolderFromProjectChecked(GodotSharpDirs.ProjectCsProjPath, "Compile",
|
||||
ProjectSettings.GlobalizePath(oldFolder));
|
||||
}
|
||||
|
||||
public override void _Notification(int what)
|
||||
{
|
||||
base._Notification(what);
|
||||
|
@ -168,6 +197,13 @@ namespace GodotTools
|
|||
// Once shown a first time, it can be seen again via the Mono menu - it doesn't have to be exclusive from that time on.
|
||||
aboutDialog.PopupExclusive = false;
|
||||
}
|
||||
|
||||
var fileSystemDock = GetEditorInterface().GetFileSystemDock();
|
||||
|
||||
fileSystemDock.Connect("files_moved", this, nameof(_FileSystemDockFileMoved));
|
||||
fileSystemDock.Connect("file_removed", this, nameof(_FileSystemDockFileRemoved));
|
||||
fileSystemDock.Connect("folder_moved", this, nameof(_FileSystemDockFolderMoved));
|
||||
fileSystemDock.Connect("folder_removed", this, nameof(_FileSystemDockFolderRemoved));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,7 +246,7 @@ namespace GodotTools
|
|||
string scriptPath = ProjectSettings.GlobalizePath(script.ResourcePath);
|
||||
RiderPathManager.OpenFile(GodotSharpDirs.ProjectSlnPath, scriptPath, line);
|
||||
return Error.Ok;
|
||||
}
|
||||
}
|
||||
case ExternalEditorId.MonoDevelop:
|
||||
{
|
||||
string scriptPath = ProjectSettings.GlobalizePath(script.ResourcePath);
|
||||
|
@ -346,7 +382,7 @@ namespace GodotTools
|
|||
|
||||
bottomPanelBtn = AddControlToBottomPanel(BottomPanel, "Mono".TTR());
|
||||
|
||||
AddChild(new HotReloadAssemblyWatcher { Name = "HotReloadAssemblyWatcher" });
|
||||
AddChild(new HotReloadAssemblyWatcher {Name = "HotReloadAssemblyWatcher"});
|
||||
|
||||
menuPopup = new PopupMenu();
|
||||
menuPopup.Hide();
|
||||
|
@ -394,7 +430,7 @@ namespace GodotTools
|
|||
EditorDef("mono/editor/show_info_on_start", true);
|
||||
|
||||
// CheckBox in main container
|
||||
aboutDialogCheckBox = new CheckBox { Text = "Show this warning when starting the editor" };
|
||||
aboutDialogCheckBox = new CheckBox {Text = "Show this warning when starting the editor"};
|
||||
aboutDialogCheckBox.Connect("toggled", this, nameof(_ToggleAboutDialogOnStart));
|
||||
aboutVBox.AddChild(aboutDialogCheckBox);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace GodotTools.Internals
|
|||
public static class Internal
|
||||
{
|
||||
public const string CSharpLanguageType = "CSharpScript";
|
||||
public const string CSharpLanguageExtension = "cs";
|
||||
public const string CSharpLanguageExtension = ".cs";
|
||||
|
||||
public static string UpdateApiAssembliesFromPrebuilt(string config) =>
|
||||
internal_UpdateApiAssembliesFromPrebuilt(config);
|
||||
|
|
Loading…
Reference in a new issue