Add sorting to project manager. Fixes #8794.
This commit is contained in:
parent
8ba0d513fa
commit
911cf63eb8
|
@ -866,16 +866,22 @@ struct ProjectItem {
|
||||||
uint64_t last_modified;
|
uint64_t last_modified;
|
||||||
bool favorite;
|
bool favorite;
|
||||||
bool grayed;
|
bool grayed;
|
||||||
|
bool ordered_latest_modification;
|
||||||
ProjectItem() {}
|
ProjectItem() {}
|
||||||
ProjectItem(const String &p_project, const String &p_path, const String &p_conf, uint64_t p_last_modified, bool p_favorite = false, bool p_grayed = false) {
|
ProjectItem(const String &p_project, const String &p_path, const String &p_conf, uint64_t p_last_modified, bool p_favorite = false, bool p_grayed = false, const bool p_ordered_latest_modification = true) {
|
||||||
project = p_project;
|
project = p_project;
|
||||||
path = p_path;
|
path = p_path;
|
||||||
conf = p_conf;
|
conf = p_conf;
|
||||||
last_modified = p_last_modified;
|
last_modified = p_last_modified;
|
||||||
favorite = p_favorite;
|
favorite = p_favorite;
|
||||||
grayed = p_grayed;
|
grayed = p_grayed;
|
||||||
|
ordered_latest_modification = p_ordered_latest_modification;
|
||||||
|
}
|
||||||
|
_FORCE_INLINE_ bool operator<(const ProjectItem &l) const {
|
||||||
|
if (ordered_latest_modification)
|
||||||
|
return last_modified > l.last_modified;
|
||||||
|
return project < l.project;
|
||||||
}
|
}
|
||||||
_FORCE_INLINE_ bool operator<(const ProjectItem &l) const { return last_modified > l.last_modified; }
|
|
||||||
_FORCE_INLINE_ bool operator==(const ProjectItem &l) const { return project == l.project; }
|
_FORCE_INLINE_ bool operator==(const ProjectItem &l) const { return project == l.project; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1156,6 +1162,13 @@ void ProjectManager::_load_recent_projects() {
|
||||||
|
|
||||||
Color font_color = gui_base->get_color("font_color", "Tree");
|
Color font_color = gui_base->get_color("font_color", "Tree");
|
||||||
|
|
||||||
|
bool set_ordered_latest_modification;
|
||||||
|
ProjectListFilter::FilterOption filter_order_option = project_order_filter->get_filter_option();
|
||||||
|
if (filter_order_option == ProjectListFilter::FILTER_NAME)
|
||||||
|
set_ordered_latest_modification = false;
|
||||||
|
else
|
||||||
|
set_ordered_latest_modification = true;
|
||||||
|
|
||||||
List<ProjectItem> projects;
|
List<ProjectItem> projects;
|
||||||
List<ProjectItem> favorite_projects;
|
List<ProjectItem> favorite_projects;
|
||||||
|
|
||||||
|
@ -1188,13 +1201,12 @@ void ProjectManager::_load_recent_projects() {
|
||||||
grayed = true;
|
grayed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectItem item(project, path, conf, last_modified, favorite, grayed);
|
ProjectItem item(project, path, conf, last_modified, favorite, grayed, set_ordered_latest_modification);
|
||||||
if (favorite)
|
if (favorite)
|
||||||
favorite_projects.push_back(item);
|
favorite_projects.push_back(item);
|
||||||
else
|
else
|
||||||
projects.push_back(item);
|
projects.push_back(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
projects.sort();
|
projects.sort();
|
||||||
favorite_projects.sort();
|
favorite_projects.sort();
|
||||||
|
|
||||||
|
@ -1818,16 +1830,41 @@ ProjectManager::ProjectManager() {
|
||||||
tabs->add_child(tree_hb);
|
tabs->add_child(tree_hb);
|
||||||
|
|
||||||
VBoxContainer *search_tree_vb = memnew(VBoxContainer);
|
VBoxContainer *search_tree_vb = memnew(VBoxContainer);
|
||||||
search_tree_vb->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
||||||
tree_hb->add_child(search_tree_vb);
|
tree_hb->add_child(search_tree_vb);
|
||||||
|
search_tree_vb->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||||
|
|
||||||
HBoxContainer *search_box = memnew(HBoxContainer);
|
HBoxContainer *sort_filters = memnew(HBoxContainer);
|
||||||
search_box->add_spacer(true);
|
Label *sort_label = memnew(Label);
|
||||||
|
sort_label->set_text(TTR("Sort:"));
|
||||||
|
sort_filters->add_child(sort_label);
|
||||||
|
Vector<String> vec1;
|
||||||
|
vec1.push_back("Name");
|
||||||
|
vec1.push_back("Last Modified");
|
||||||
|
project_order_filter = memnew(ProjectListFilter);
|
||||||
|
project_order_filter->_setup_filters(vec1);
|
||||||
|
project_order_filter->set_filter_size(150);
|
||||||
|
sort_filters->add_child(project_order_filter);
|
||||||
|
project_order_filter->connect("filter_changed", this, "_load_recent_projects");
|
||||||
|
project_order_filter->set_custom_minimum_size(Size2(180, 10) * EDSCALE);
|
||||||
|
|
||||||
|
sort_filters->add_spacer(true);
|
||||||
|
Label *search_label = memnew(Label);
|
||||||
|
search_label->set_text(TTR(" Search:"));
|
||||||
|
sort_filters->add_child(search_label);
|
||||||
|
|
||||||
|
HBoxContainer *search_filters = memnew(HBoxContainer);
|
||||||
|
Vector<String> vec2;
|
||||||
|
vec2.push_back("Name");
|
||||||
|
vec2.push_back("Path");
|
||||||
project_filter = memnew(ProjectListFilter);
|
project_filter = memnew(ProjectListFilter);
|
||||||
search_box->add_child(project_filter);
|
project_filter->_setup_filters(vec2);
|
||||||
|
project_filter->add_search_box();
|
||||||
|
search_filters->add_child(project_filter);
|
||||||
project_filter->connect("filter_changed", this, "_load_recent_projects");
|
project_filter->connect("filter_changed", this, "_load_recent_projects");
|
||||||
project_filter->set_custom_minimum_size(Size2(280, 10) * EDSCALE);
|
project_filter->set_custom_minimum_size(Size2(280, 10) * EDSCALE);
|
||||||
search_tree_vb->add_child(search_box);
|
sort_filters->add_child(search_filters);
|
||||||
|
|
||||||
|
search_tree_vb->add_child(sort_filters);
|
||||||
|
|
||||||
PanelContainer *pc = memnew(PanelContainer);
|
PanelContainer *pc = memnew(PanelContainer);
|
||||||
pc->add_style_override("panel", gui_base->get_stylebox("bg", "Tree"));
|
pc->add_style_override("panel", gui_base->get_stylebox("bg", "Tree"));
|
||||||
|
@ -2017,11 +2054,11 @@ ProjectManager::~ProjectManager() {
|
||||||
EditorSettings::destroy();
|
EditorSettings::destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectListFilter::_setup_filters() {
|
void ProjectListFilter::_setup_filters(Vector<String> options) {
|
||||||
|
|
||||||
filter_option->clear();
|
filter_option->clear();
|
||||||
filter_option->add_item(TTR("Name"));
|
for (int i = 0; i < options.size(); i++)
|
||||||
filter_option->add_item(TTR("Path"));
|
filter_option->add_item(TTR(options[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectListFilter::_search_text_changed(const String &p_newtext) {
|
void ProjectListFilter::_search_text_changed(const String &p_newtext) {
|
||||||
|
@ -2046,7 +2083,7 @@ void ProjectListFilter::_filter_option_selected(int p_idx) {
|
||||||
|
|
||||||
void ProjectListFilter::_notification(int p_what) {
|
void ProjectListFilter::_notification(int p_what) {
|
||||||
|
|
||||||
if (p_what == NOTIFICATION_ENTER_TREE) {
|
if (p_what == NOTIFICATION_ENTER_TREE && has_search_box) {
|
||||||
search_box->set_right_icon(get_icon("Search", "EditorIcons"));
|
search_box->set_right_icon(get_icon("Search", "EditorIcons"));
|
||||||
search_box->set_clear_button_enabled(true);
|
search_box->set_clear_button_enabled(true);
|
||||||
}
|
}
|
||||||
|
@ -2060,20 +2097,27 @@ void ProjectListFilter::_bind_methods() {
|
||||||
ADD_SIGNAL(MethodInfo("filter_changed"));
|
ADD_SIGNAL(MethodInfo("filter_changed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProjectListFilter::add_search_box() {
|
||||||
|
search_box = memnew(LineEdit);
|
||||||
|
search_box->connect("text_changed", this, "_search_text_changed");
|
||||||
|
search_box->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||||
|
add_child(search_box);
|
||||||
|
has_search_box = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProjectListFilter::set_filter_size(int h_size) {
|
||||||
|
filter_option->set_custom_minimum_size(Size2(h_size * EDSCALE, 10 * EDSCALE));
|
||||||
|
}
|
||||||
|
|
||||||
ProjectListFilter::ProjectListFilter() {
|
ProjectListFilter::ProjectListFilter() {
|
||||||
|
|
||||||
_current_filter = FILTER_NAME;
|
_current_filter = FILTER_NAME;
|
||||||
|
|
||||||
filter_option = memnew(OptionButton);
|
filter_option = memnew(OptionButton);
|
||||||
filter_option->set_custom_minimum_size(Size2(80 * EDSCALE, 10 * EDSCALE));
|
set_filter_size(80);
|
||||||
filter_option->set_clip_text(true);
|
filter_option->set_clip_text(true);
|
||||||
filter_option->connect("item_selected", this, "_filter_option_selected");
|
filter_option->connect("item_selected", this, "_filter_option_selected");
|
||||||
add_child(filter_option);
|
add_child(filter_option);
|
||||||
|
|
||||||
_setup_filters();
|
has_search_box = false;
|
||||||
|
|
||||||
search_box = memnew(LineEdit);
|
|
||||||
search_box->connect("text_changed", this, "_search_text_changed");
|
|
||||||
search_box->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
||||||
add_child(search_box);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ class ProjectManager : public Control {
|
||||||
EditorAssetLibrary *asset_library;
|
EditorAssetLibrary *asset_library;
|
||||||
|
|
||||||
ProjectListFilter *project_filter;
|
ProjectListFilter *project_filter;
|
||||||
|
ProjectListFilter *project_order_filter;
|
||||||
|
|
||||||
ConfirmationDialog *language_restart_ask;
|
ConfirmationDialog *language_restart_ask;
|
||||||
ConfirmationDialog *erase_ask;
|
ConfirmationDialog *erase_ask;
|
||||||
|
@ -130,6 +131,7 @@ private:
|
||||||
|
|
||||||
OptionButton *filter_option;
|
OptionButton *filter_option;
|
||||||
LineEdit *search_box;
|
LineEdit *search_box;
|
||||||
|
bool has_search_box;
|
||||||
|
|
||||||
enum FilterOption {
|
enum FilterOption {
|
||||||
FILTER_NAME,
|
FILTER_NAME,
|
||||||
|
@ -138,7 +140,6 @@ private:
|
||||||
FilterOption _current_filter;
|
FilterOption _current_filter;
|
||||||
|
|
||||||
void _search_text_changed(const String &p_newtext);
|
void _search_text_changed(const String &p_newtext);
|
||||||
void _setup_filters();
|
|
||||||
void _filter_option_selected(int p_idx);
|
void _filter_option_selected(int p_idx);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -146,6 +147,9 @@ protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void _setup_filters(Vector<String> options);
|
||||||
|
void add_search_box();
|
||||||
|
void set_filter_size(int h_size);
|
||||||
String get_search_term();
|
String get_search_term();
|
||||||
FilterOption get_filter_option();
|
FilterOption get_filter_option();
|
||||||
ProjectListFilter();
|
ProjectListFilter();
|
||||||
|
|
Loading…
Reference in a new issue