summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorgroud <gilles.roudiere@gmail.com>2018-09-18 14:02:59 +0200
committergroud <gilles.roudiere@gmail.com>2018-09-18 14:02:59 +0200
commit76b2ae8dc684d86904a28eb6568f68b88a8d59be (patch)
treefd5951c443ca54f4d5bd5374d7025f54f3eb4104 /editor
parent59536b98b91751c524ad3560275ca8d5e4b9ac2a (diff)
Fixes favorites not updating and rename favorite_dirs to favorites
Diffstat (limited to 'editor')
-rw-r--r--editor/dependency_editor.cpp28
-rw-r--r--editor/editor_file_dialog.cpp16
-rw-r--r--editor/editor_settings.cpp22
-rw-r--r--editor/editor_settings.h6
-rw-r--r--editor/filesystem_dock.cpp46
-rw-r--r--editor/filesystem_dock.h4
6 files changed, 63 insertions, 59 deletions
diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp
index 9f04d40763..02971f4467 100644
--- a/editor/dependency_editor.cpp
+++ b/editor/dependency_editor.cpp
@@ -515,7 +515,7 @@ void DependencyRemoveDialog::ok_pressed() {
}
if (dirs_to_delete.size() == 0) {
- //If we only deleted files we should only need to tell the file system about the files we touched.
+ // If we only deleted files we should only need to tell the file system about the files we touched.
for (int i = 0; i < files_to_delete.size(); ++i)
EditorFileSystem::get_singleton()->update_file(files_to_delete[i]);
} else {
@@ -529,21 +529,25 @@ void DependencyRemoveDialog::ok_pressed() {
}
}
- // if some dirs would be deleted, favorite dirs need to be updated
- Vector<String> previous_favorite_dirs = EditorSettings::get_singleton()->get_favorite_dirs();
- Vector<String> new_favorite_dirs;
+ EditorFileSystem::get_singleton()->scan_changes();
+ }
- for (int i = 0; i < previous_favorite_dirs.size(); ++i) {
- if (dirs_to_delete.find(previous_favorite_dirs[i] + "/") < 0) {
- new_favorite_dirs.push_back(previous_favorite_dirs[i]);
- }
- }
+ // If some files/dirs would be deleted, favorite dirs need to be updated
+ Vector<String> previous_favorites = EditorSettings::get_singleton()->get_favorites();
+ Vector<String> new_favorites;
- if (new_favorite_dirs.size() < previous_favorite_dirs.size()) {
- EditorSettings::get_singleton()->set_favorite_dirs(new_favorite_dirs);
+ for (int i = 0; i < previous_favorites.size(); ++i) {
+ if (previous_favorites[i].ends_with("/")) {
+ if (dirs_to_delete.find(previous_favorites[i]) < 0)
+ new_favorites.push_back(previous_favorites[i]);
+ } else {
+ if (files_to_delete.find(previous_favorites[i]) < 0)
+ new_favorites.push_back(previous_favorites[i]);
}
+ }
- EditorFileSystem::get_singleton()->scan_changes();
+ if (new_favorites.size() < previous_favorites.size()) {
+ EditorSettings::get_singleton()->set_favorites(new_favorites);
}
}
diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp
index d0007bd5d1..f11a30bb86 100644
--- a/editor/editor_file_dialog.cpp
+++ b/editor/editor_file_dialog.cpp
@@ -1115,7 +1115,7 @@ void EditorFileDialog::_update_drives() {
void EditorFileDialog::_favorite_selected(int p_idx) {
- Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();
+ Vector<String> favorited = EditorSettings::get_singleton()->get_favorites();
ERR_FAIL_INDEX(p_idx, favorited.size());
dir_access->change_dir(favorited[p_idx]);
@@ -1130,7 +1130,7 @@ void EditorFileDialog::_favorite_move_up() {
int current = favorites->get_current();
if (current > 0 && current < favorites->get_item_count()) {
- Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();
+ Vector<String> favorited = EditorSettings::get_singleton()->get_favorites();
int a_idx = favorited.find(String(favorites->get_item_metadata(current - 1)));
int b_idx = favorited.find(String(favorites->get_item_metadata(current)));
@@ -1139,7 +1139,7 @@ void EditorFileDialog::_favorite_move_up() {
return;
SWAP(favorited.write[a_idx], favorited.write[b_idx]);
- EditorSettings::get_singleton()->set_favorite_dirs(favorited);
+ EditorSettings::get_singleton()->set_favorites(favorited);
_update_favorites();
update_file_list();
@@ -1150,7 +1150,7 @@ void EditorFileDialog::_favorite_move_down() {
int current = favorites->get_current();
if (current >= 0 && current < favorites->get_item_count() - 1) {
- Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();
+ Vector<String> favorited = EditorSettings::get_singleton()->get_favorites();
int a_idx = favorited.find(String(favorites->get_item_metadata(current + 1)));
int b_idx = favorited.find(String(favorites->get_item_metadata(current)));
@@ -1159,7 +1159,7 @@ void EditorFileDialog::_favorite_move_down() {
return;
SWAP(favorited.write[a_idx], favorited.write[b_idx]);
- EditorSettings::get_singleton()->set_favorite_dirs(favorited);
+ EditorSettings::get_singleton()->set_favorites(favorited);
_update_favorites();
update_file_list();
@@ -1176,7 +1176,7 @@ void EditorFileDialog::_update_favorites() {
favorite->set_pressed(false);
- Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();
+ Vector<String> favorited = EditorSettings::get_singleton()->get_favorites();
for (int i = 0; i < favorited.size(); i++) {
bool cres = favorited[i].begins_with("res://");
if (cres != res)
@@ -1206,7 +1206,7 @@ void EditorFileDialog::_favorite_toggled(bool p_toggle) {
String cd = get_current_dir();
- Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();
+ Vector<String> favorited = EditorSettings::get_singleton()->get_favorites();
bool found = false;
for (int i = 0; i < favorited.size(); i++) {
@@ -1228,7 +1228,7 @@ void EditorFileDialog::_favorite_toggled(bool p_toggle) {
favorite->set_pressed(true);
}
- EditorSettings::get_singleton()->set_favorite_dirs(favorited);
+ EditorSettings::get_singleton()->set_favorites(favorited);
_update_favorites();
}
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 33fac52782..7ea2f17e30 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -1147,20 +1147,20 @@ Variant EditorSettings::get_project_metadata(const String &p_section, const Stri
return cf->get_value(p_section, p_key, p_default);
}
-void EditorSettings::set_favorite_dirs(const Vector<String> &p_favorites_dirs) {
+void EditorSettings::set_favorites(const Vector<String> &p_favorites) {
- favorite_dirs = p_favorites_dirs;
- FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("favorite_dirs"), FileAccess::WRITE);
+ favorites = p_favorites;
+ FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("favorites"), FileAccess::WRITE);
if (f) {
- for (int i = 0; i < favorite_dirs.size(); i++)
- f->store_line(favorite_dirs[i]);
+ for (int i = 0; i < favorites.size(); i++)
+ f->store_line(favorites[i]);
memdelete(f);
}
}
-Vector<String> EditorSettings::get_favorite_dirs() const {
+Vector<String> EditorSettings::get_favorites() const {
- return favorite_dirs;
+ return favorites;
}
void EditorSettings::set_recent_dirs(const Vector<String> &p_recent_dirs) {
@@ -1181,11 +1181,11 @@ Vector<String> EditorSettings::get_recent_dirs() const {
void EditorSettings::load_favorites() {
- FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("favorite_dirs"), FileAccess::READ);
+ FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("favorites"), FileAccess::READ);
if (f) {
String line = f->get_line().strip_edges();
while (line != "") {
- favorite_dirs.push_back(line);
+ favorites.push_back(line);
line = f->get_line().strip_edges();
}
memdelete(f);
@@ -1466,8 +1466,8 @@ void EditorSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_project_metadata", "section", "key", "data"), &EditorSettings::set_project_metadata);
ClassDB::bind_method(D_METHOD("get_project_metadata", "section", "key", "default"), &EditorSettings::get_project_metadata, DEFVAL(Variant()));
- ClassDB::bind_method(D_METHOD("set_favorite_dirs", "dirs"), &EditorSettings::set_favorite_dirs);
- ClassDB::bind_method(D_METHOD("get_favorite_dirs"), &EditorSettings::get_favorite_dirs);
+ ClassDB::bind_method(D_METHOD("set_favorites", "dirs"), &EditorSettings::set_favorites);
+ ClassDB::bind_method(D_METHOD("get_favorites"), &EditorSettings::get_favorites);
ClassDB::bind_method(D_METHOD("set_recent_dirs", "dirs"), &EditorSettings::set_recent_dirs);
ClassDB::bind_method(D_METHOD("get_recent_dirs"), &EditorSettings::get_recent_dirs);
diff --git a/editor/editor_settings.h b/editor/editor_settings.h
index 8165c36e67..7b0de9617c 100644
--- a/editor/editor_settings.h
+++ b/editor/editor_settings.h
@@ -107,7 +107,7 @@ private:
String config_file_path;
String project_config_dir;
- Vector<String> favorite_dirs;
+ Vector<String> favorites;
Vector<String> recent_dirs;
bool save_changed_setting;
@@ -173,8 +173,8 @@ public:
void set_project_metadata(const String &p_section, const String &p_key, Variant p_data);
Variant get_project_metadata(const String &p_section, const String &p_key, Variant p_default) const;
- void set_favorite_dirs(const Vector<String> &p_favorites_dirs);
- Vector<String> get_favorite_dirs() const;
+ void set_favorites(const Vector<String> &p_favorites);
+ Vector<String> get_favorites() const;
void set_recent_dirs(const Vector<String> &p_recent_dirs);
Vector<String> get_recent_dirs() const;
void load_favorites();
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index 7889bff93d..bd1d355fb3 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -172,7 +172,7 @@ void FileSystemDock::_update_tree(const Vector<String> p_uncollapsed_paths, bool
favorites->set_text(0, TTR("Favorites:"));
favorites->set_selectable(0, false);
- Vector<String> favorite_paths = EditorSettings::get_singleton()->get_favorite_dirs();
+ Vector<String> favorite_paths = EditorSettings::get_singleton()->get_favorites();
for (int i = 0; i < favorite_paths.size(); i++) {
String fave = favorite_paths[i];
if (!fave.begins_with("res://"))
@@ -1091,23 +1091,23 @@ void FileSystemDock::_update_project_settings_after_move(const Map<String, Strin
ProjectSettings::get_singleton()->save();
}
-void FileSystemDock::_update_favorite_dirs_list_after_move(const Map<String, String> &p_renames) const {
+void FileSystemDock::_update_favorites_list_after_move(const Map<String, String> &p_files_renames, const Map<String, String> &p_folders_renames) const {
- Vector<String> favorite_dirs = EditorSettings::get_singleton()->get_favorite_dirs();
- Vector<String> new_favorite_dirs;
+ Vector<String> favorites = EditorSettings::get_singleton()->get_favorites();
+ Vector<String> new_favorites;
- for (int i = 0; i < favorite_dirs.size(); i++) {
- String old_path = favorite_dirs[i] + "/";
-
- if (p_renames.has(old_path)) {
- String new_path = p_renames[old_path];
- new_favorite_dirs.push_back(new_path.substr(0, new_path.length() - 1));
+ for (int i = 0; i < favorites.size(); i++) {
+ String old_path = favorites[i];
+ if (p_folders_renames.has(old_path)) {
+ new_favorites.push_back(p_folders_renames[old_path]);
+ } else if (p_files_renames.has(old_path)) {
+ new_favorites.push_back(p_files_renames[old_path]);
} else {
- new_favorite_dirs.push_back(favorite_dirs[i]);
+ new_favorites.push_back(old_path);
}
}
- EditorSettings::get_singleton()->set_favorite_dirs(new_favorite_dirs);
+ EditorSettings::get_singleton()->set_favorites(new_favorites);
}
void FileSystemDock::_make_dir_confirm() {
@@ -1178,7 +1178,7 @@ void FileSystemDock::_rename_operation_confirm() {
_update_dependencies_after_move(file_renames);
_update_resource_paths_after_move(file_renames);
_update_project_settings_after_move(file_renames);
- _update_favorite_dirs_list_after_move(folder_renames);
+ _update_favorites_list_after_move(file_renames, folder_renames);
//Rescan everything
print_verbose("FileSystem: calling rescan.");
@@ -1271,7 +1271,7 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool overw
_update_dependencies_after_move(file_renames);
_update_resource_paths_after_move(file_renames);
_update_project_settings_after_move(file_renames);
- _update_favorite_dirs_list_after_move(folder_renames);
+ _update_favorites_list_after_move(file_renames, folder_renames);
print_verbose("FileSystem: calling rescan.");
_rescan();
@@ -1393,23 +1393,23 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> p_selected)
case FILE_ADD_FAVORITE: {
// Add the files from favorites
- Vector<String> favorites = EditorSettings::get_singleton()->get_favorite_dirs();
+ Vector<String> favorites = EditorSettings::get_singleton()->get_favorites();
for (int i = 0; i < p_selected.size(); i++) {
if (favorites.find(p_selected[i]) == -1) {
favorites.push_back(p_selected[i]);
}
}
- EditorSettings::get_singleton()->set_favorite_dirs(favorites);
+ EditorSettings::get_singleton()->set_favorites(favorites);
_update_tree(_compute_uncollapsed_paths());
} break;
case FILE_REMOVE_FAVORITE: {
// Remove the files from favorites
- Vector<String> favorites = EditorSettings::get_singleton()->get_favorite_dirs();
+ Vector<String> favorites = EditorSettings::get_singleton()->get_favorites();
for (int i = 0; i < p_selected.size(); i++) {
favorites.erase(p_selected[i]);
}
- EditorSettings::get_singleton()->set_favorite_dirs(favorites);
+ EditorSettings::get_singleton()->set_favorites(favorites);
_update_tree(_compute_uncollapsed_paths());
} break;
@@ -1751,7 +1751,7 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
return;
Dictionary drag_data = p_data;
- Vector<String> dirs = EditorSettings::get_singleton()->get_favorite_dirs();
+ Vector<String> dirs = EditorSettings::get_singleton()->get_favorites();
if (drag_data.has("type") && String(drag_data["type"]) == "favorite") {
// Moving favorite around
@@ -1801,7 +1801,7 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
drop_position++;
}
- EditorSettings::get_singleton()->set_favorite_dirs(dirs);
+ EditorSettings::get_singleton()->set_favorites(dirs);
_update_tree(_compute_uncollapsed_paths());
return;
}
@@ -1833,13 +1833,13 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
} else if (favorite) {
// Add the files from favorites
Vector<String> fnames = drag_data["files"];
- Vector<String> favorites = EditorSettings::get_singleton()->get_favorite_dirs();
+ Vector<String> favorites = EditorSettings::get_singleton()->get_favorites();
for (int i = 0; i < fnames.size(); i++) {
if (favorites.find(fnames[i]) == -1) {
favorites.push_back(fnames[i]);
}
}
- EditorSettings::get_singleton()->set_favorite_dirs(favorites);
+ EditorSettings::get_singleton()->set_favorites(favorites);
_update_tree(_compute_uncollapsed_paths());
}
}
@@ -1908,7 +1908,7 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str
Vector<String> filenames;
Vector<String> foldernames;
- Vector<String> favorites = EditorSettings::get_singleton()->get_favorite_dirs();
+ Vector<String> favorites = EditorSettings::get_singleton()->get_favorites();
bool all_files = true;
bool all_files_scenes = true;
diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h
index 72baa88a06..51c8791b25 100644
--- a/editor/filesystem_dock.h
+++ b/editor/filesystem_dock.h
@@ -210,8 +210,8 @@ private:
void _try_duplicate_item(const FileOrFolder &p_item, const String &p_new_path) const;
void _update_dependencies_after_move(const Map<String, String> &p_renames) const;
void _update_resource_paths_after_move(const Map<String, String> &p_renames) const;
- void _update_favorite_dirs_list_after_move(const Map<String, String> &p_renames) const;
- void _update_project_settings_after_move(const Map<String, String> &p_renames) const;
+ 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_folders_renames) const;
void _resource_created() const;
void _make_dir_confirm();