瀏覽代碼

tools: detect file changes

Daniele Bartolini 1 年之前
父節點
當前提交
e39245c4a4
共有 2 個文件被更改,包括 22 次插入15 次删除
  1. 15 15
      tools/level_editor/project.vala
  2. 7 0
      tools/level_editor/project_store.vala

+ 15 - 15
tools/level_editor/project.vala

@@ -71,10 +71,10 @@ public class Project
 	public Hashtable _data_index;
 
 	public signal void file_added(string type, string name, uint64 size, uint64 mtime);
+	public signal void file_changed(string type, string name, uint64 size, uint64 mtime);
 	public signal void file_removed(string type, string name);
 	public signal void tree_added(string name);
 	public signal void tree_removed(string name);
-	public signal void file_changed(string type, string name, uint64 size, uint64 mtime);
 	public signal void project_reset();
 	public signal void project_loaded();
 
@@ -456,6 +456,20 @@ public class Project
 		file_added(type, name, size, mtime);
 	}
 
+	public void change_file(string path, uint64 size, uint64 mtime)
+	{
+		string type = path_extension(path);
+		string name = type == "" ? path : path.substring(0, path.last_index_of("."));
+
+		Guid id = _map[path];
+		_files.set_property_string(id, "size", size.to_string());
+		_files.set_property_string(id, "mtime", mtime.to_string());
+
+		_data_compiled = false;
+
+		file_changed(type, name, size, mtime);
+	}
+
 	public void remove_file(string path)
 	{
 		if (!_map.has_key(path)) {
@@ -482,20 +496,6 @@ public class Project
 		tree_removed(path);
 	}
 
-	public void change_file(string path, uint64 size, uint64 mtime)
-	{
-		string type = path_extension(path);
-		string name = type == "" ? path : path.substring(0, path.last_index_of("."));
-
-		Guid id = _map[path];
-		_files.set_property_string(id, "size", size.to_string());
-		_files.set_property_string(id, "mtime", mtime.to_string());
-
-		_data_compiled = false;
-
-		file_changed(type, name, size, mtime);
-	}
-
 	public string resource_filename(string absolute_path)
 	{
 		string prefix = _source_dir.get_path();

+ 7 - 0
tools/level_editor/project_store.vala

@@ -34,6 +34,7 @@ public class ProjectStore
 		// Data
 		_project = project;
 		_project.file_added.connect(on_project_file_added);
+		_project.file_changed.connect(on_project_file_changed);
 		_project.file_removed.connect(on_project_file_removed);
 		_project.tree_added.connect(on_project_tree_added);
 		_project.tree_removed.connect(on_project_tree_removed);
@@ -295,6 +296,12 @@ public class ProjectStore
 			);
 	}
 
+	private void on_project_file_changed(string type, string name, uint64 size, uint64 mtime)
+	{
+		on_project_file_removed(type, name);
+		on_project_file_added(type, name, size, mtime);
+	}
+
 	private void on_project_file_removed(string type, string name)
 	{
 		string parent_folder = ResourceId.parent_folder(name);