parent
f06fc1fdf4
commit
c029a03bc3
|
@ -32,20 +32,17 @@
|
||||||
|
|
||||||
#include "core/os/keyboard.h"
|
#include "core/os/keyboard.h"
|
||||||
|
|
||||||
void EditorQuickOpen::popup_dialog(const StringName &p_base, bool p_enable_multi, bool p_add_dirs, bool p_dontclear) {
|
void EditorQuickOpen::popup_dialog(const StringName &p_base, bool p_enable_multi, bool p_dontclear) {
|
||||||
|
base_type = p_base;
|
||||||
|
search_options->set_select_mode(p_enable_multi ? Tree::SELECT_MULTI : Tree::SELECT_SINGLE);
|
||||||
|
popup_centered_ratio(0.4);
|
||||||
|
|
||||||
add_directories = p_add_dirs;
|
|
||||||
popup_centered_ratio(0.6);
|
|
||||||
if (p_dontclear)
|
if (p_dontclear)
|
||||||
search_box->select_all();
|
search_box->select_all();
|
||||||
else
|
else
|
||||||
search_box->clear();
|
search_box->clear();
|
||||||
if (p_enable_multi)
|
|
||||||
search_options->set_select_mode(Tree::SELECT_MULTI);
|
|
||||||
else
|
|
||||||
search_options->set_select_mode(Tree::SELECT_SINGLE);
|
|
||||||
search_box->grab_focus();
|
search_box->grab_focus();
|
||||||
base_type = p_base;
|
|
||||||
_update_search();
|
_update_search();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +102,6 @@ void EditorQuickOpen::_sbox_input(const Ref<InputEvent> &p_ie) {
|
||||||
}
|
}
|
||||||
|
|
||||||
current->select(0);
|
current->select(0);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,65 +125,26 @@ float EditorQuickOpen::_path_cmp(String search, String path) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector<Pair<String, Ref<Texture> > > &list) {
|
void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector<Pair<String, Ref<Texture> > > &list) {
|
||||||
|
for (int i = 0; i < efsd->get_subdir_count(); i++) {
|
||||||
if (!add_directories) {
|
_parse_fs(efsd->get_subdir(i), list);
|
||||||
for (int i = 0; i < efsd->get_subdir_count(); i++) {
|
|
||||||
|
|
||||||
_parse_fs(efsd->get_subdir(i), list);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String search_text = search_box->get_text();
|
String search_text = search_box->get_text();
|
||||||
|
|
||||||
if (add_directories) {
|
|
||||||
String path = efsd->get_path();
|
|
||||||
if (!path.ends_with("/"))
|
|
||||||
path += "/";
|
|
||||||
if (path != "res://") {
|
|
||||||
path = path.substr(6, path.length());
|
|
||||||
if (search_text.is_subsequence_ofi(path)) {
|
|
||||||
Pair<String, Ref<Texture> > pair;
|
|
||||||
pair.first = path;
|
|
||||||
pair.second = get_icon("folder", "FileDialog");
|
|
||||||
|
|
||||||
if (search_text != String() && list.size() > 0) {
|
|
||||||
|
|
||||||
float this_sim = _path_cmp(search_text, path);
|
|
||||||
float other_sim = _path_cmp(list[0].first, path);
|
|
||||||
int pos = 1;
|
|
||||||
|
|
||||||
while (pos < list.size() && this_sim <= other_sim) {
|
|
||||||
other_sim = _path_cmp(list[pos++].first, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
pos = this_sim >= other_sim ? pos - 1 : pos;
|
|
||||||
list.insert(pos, pair);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
list.push_back(pair);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = 0; i < efsd->get_file_count(); i++) {
|
for (int i = 0; i < efsd->get_file_count(); i++) {
|
||||||
|
|
||||||
String file = efsd->get_file_path(i);
|
String file = efsd->get_file_path(i);
|
||||||
file = file.substr(6, file.length());
|
file = file.substr(6, file.length());
|
||||||
|
|
||||||
if (ClassDB::is_parent_class(efsd->get_file_type(i), base_type) && (search_text.is_subsequence_ofi(file))) {
|
StringName file_type = efsd->get_file_type(i);
|
||||||
|
if (ClassDB::is_parent_class(file_type, base_type) && search_text.is_subsequence_ofi(file)) {
|
||||||
Pair<String, Ref<Texture> > pair;
|
Pair<String, Ref<Texture> > pair;
|
||||||
pair.first = file;
|
pair.first = file;
|
||||||
pair.second = get_icon((has_icon(efsd->get_file_type(i), ei) ? efsd->get_file_type(i) : ot), ei);
|
StringName icon_name = search_options->has_icon(file_type, ei) ? file_type : ot;
|
||||||
|
pair.second = search_options->get_icon(icon_name, ei);
|
||||||
list.push_back(pair);
|
list.push_back(pair);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add_directories) {
|
|
||||||
for (int i = 0; i < efsd->get_subdir_count(); i++) {
|
|
||||||
|
|
||||||
_parse_fs(efsd->get_subdir(i), list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<Pair<String, Ref<Texture> > > EditorQuickOpen::_sort_fs(Vector<Pair<String, Ref<Texture> > > &list) {
|
Vector<Pair<String, Ref<Texture> > > EditorQuickOpen::_sort_fs(Vector<Pair<String, Ref<Texture> > > &list) {
|
||||||
|
@ -295,21 +252,24 @@ EditorQuickOpen::EditorQuickOpen() {
|
||||||
|
|
||||||
VBoxContainer *vbc = memnew(VBoxContainer);
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
||||||
add_child(vbc);
|
add_child(vbc);
|
||||||
|
|
||||||
search_box = memnew(LineEdit);
|
search_box = memnew(LineEdit);
|
||||||
vbc->add_margin_child(TTR("Search:"), search_box);
|
|
||||||
search_box->connect("text_changed", this, "_text_changed");
|
search_box->connect("text_changed", this, "_text_changed");
|
||||||
search_box->connect("gui_input", this, "_sbox_input");
|
search_box->connect("gui_input", this, "_sbox_input");
|
||||||
|
vbc->add_margin_child(TTR("Search:"), search_box);
|
||||||
|
|
||||||
search_options = memnew(Tree);
|
search_options = memnew(Tree);
|
||||||
vbc->add_margin_child(TTR("Matches:"), search_options, true);
|
|
||||||
get_ok()->set_text(TTR("Open"));
|
|
||||||
get_ok()->set_disabled(true);
|
|
||||||
register_text_enter(search_box);
|
|
||||||
set_hide_on_ok(false);
|
|
||||||
search_options->connect("item_activated", this, "_confirmed");
|
search_options->connect("item_activated", this, "_confirmed");
|
||||||
search_options->set_hide_root(true);
|
search_options->set_hide_root(true);
|
||||||
search_options->set_hide_folding(true);
|
search_options->set_hide_folding(true);
|
||||||
search_options->add_constant_override("draw_guides", 1);
|
search_options->add_constant_override("draw_guides", 1);
|
||||||
|
vbc->add_margin_child(TTR("Matches:"), search_options, true);
|
||||||
|
|
||||||
|
get_ok()->set_text(TTR("Open"));
|
||||||
|
get_ok()->set_disabled(true);
|
||||||
|
register_text_enter(search_box);
|
||||||
|
set_hide_on_ok(false);
|
||||||
|
|
||||||
ei = "EditorIcons";
|
ei = "EditorIcons";
|
||||||
ot = "Object";
|
ot = "Object";
|
||||||
add_directories = false;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "editor_file_system.h"
|
#include "editor_file_system.h"
|
||||||
#include "scene/gui/dialogs.h"
|
#include "scene/gui/dialogs.h"
|
||||||
#include "scene/gui/tree.h"
|
#include "scene/gui/tree.h"
|
||||||
|
|
||||||
class EditorQuickOpen : public ConfirmationDialog {
|
class EditorQuickOpen : public ConfirmationDialog {
|
||||||
|
|
||||||
GDCLASS(EditorQuickOpen, ConfirmationDialog);
|
GDCLASS(EditorQuickOpen, ConfirmationDialog);
|
||||||
|
@ -44,7 +45,6 @@ class EditorQuickOpen : public ConfirmationDialog {
|
||||||
StringName base_type;
|
StringName base_type;
|
||||||
StringName ei;
|
StringName ei;
|
||||||
StringName ot;
|
StringName ot;
|
||||||
bool add_directories;
|
|
||||||
|
|
||||||
void _update_search();
|
void _update_search();
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ public:
|
||||||
String get_selected() const;
|
String get_selected() const;
|
||||||
Vector<String> get_selected_files() const;
|
Vector<String> get_selected_files() const;
|
||||||
|
|
||||||
void popup_dialog(const StringName &p_base, bool p_enable_multi = false, bool p_add_dirs = false, bool p_dontclear = false);
|
void popup_dialog(const StringName &p_base, bool p_enable_multi = false, bool p_dontclear = false);
|
||||||
EditorQuickOpen();
|
EditorQuickOpen();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue