Reorganize project manager code
- Extract individual components to their own files. - Improve order of declarations and definitions within those files. - ProjectDialog is only extracted as there are upcoming PRs touching on it.
This commit is contained in:
@@ -113,6 +113,7 @@ if env.editor_build:
|
||||
SConscript("icons/SCsub")
|
||||
SConscript("import/SCsub")
|
||||
SConscript("plugins/SCsub")
|
||||
SConscript("project_manager/SCsub")
|
||||
SConscript("themes/SCsub")
|
||||
|
||||
lib = env.add_library("editor", env.editor_sources)
|
||||
|
||||
+515
-2477
File diff suppressed because it is too large
Load Diff
+81
-353
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
Import("env")
|
||||
|
||||
env.add_source_files(env.editor_sources, "*.cpp")
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,136 @@
|
||||
/**************************************************************************/
|
||||
/* project_dialog.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PROJECT_DIALOG_H
|
||||
#define PROJECT_DIALOG_H
|
||||
|
||||
#include "scene/gui/dialogs.h"
|
||||
|
||||
class Button;
|
||||
class EditorFileDialog;
|
||||
class LineEdit;
|
||||
class OptionButton;
|
||||
class TextureRect;
|
||||
|
||||
class ProjectDialog : public ConfirmationDialog {
|
||||
GDCLASS(ProjectDialog, ConfirmationDialog);
|
||||
|
||||
public:
|
||||
enum Mode {
|
||||
MODE_NEW,
|
||||
MODE_IMPORT,
|
||||
MODE_INSTALL,
|
||||
MODE_RENAME,
|
||||
};
|
||||
|
||||
private:
|
||||
enum MessageType {
|
||||
MESSAGE_ERROR,
|
||||
MESSAGE_WARNING,
|
||||
MESSAGE_SUCCESS,
|
||||
};
|
||||
|
||||
enum InputType {
|
||||
PROJECT_PATH,
|
||||
INSTALL_PATH,
|
||||
};
|
||||
|
||||
Mode mode = MODE_NEW;
|
||||
bool is_folder_empty = true;
|
||||
|
||||
Button *browse = nullptr;
|
||||
Button *install_browse = nullptr;
|
||||
Button *create_dir = nullptr;
|
||||
VBoxContainer *name_container = nullptr;
|
||||
VBoxContainer *path_container = nullptr;
|
||||
VBoxContainer *install_path_container = nullptr;
|
||||
|
||||
VBoxContainer *renderer_container = nullptr;
|
||||
Label *renderer_info = nullptr;
|
||||
HBoxContainer *default_files_container = nullptr;
|
||||
Ref<ButtonGroup> renderer_button_group;
|
||||
|
||||
Label *msg = nullptr;
|
||||
LineEdit *project_path = nullptr;
|
||||
LineEdit *project_name = nullptr;
|
||||
LineEdit *install_path = nullptr;
|
||||
TextureRect *status_rect = nullptr;
|
||||
TextureRect *install_status_rect = nullptr;
|
||||
|
||||
OptionButton *vcs_metadata_selection = nullptr;
|
||||
|
||||
EditorFileDialog *fdialog = nullptr;
|
||||
EditorFileDialog *fdialog_install = nullptr;
|
||||
AcceptDialog *dialog_error = nullptr;
|
||||
|
||||
String zip_path;
|
||||
String zip_title;
|
||||
String fav_dir;
|
||||
|
||||
String created_folder_path;
|
||||
|
||||
void _set_message(const String &p_msg, MessageType p_type = MESSAGE_SUCCESS, InputType input_type = PROJECT_PATH);
|
||||
|
||||
String _test_path();
|
||||
void _update_path(const String &p_path);
|
||||
void _path_text_changed(const String &p_path);
|
||||
void _path_selected(const String &p_path);
|
||||
void _file_selected(const String &p_path);
|
||||
void _install_path_selected(const String &p_path);
|
||||
|
||||
void _browse_path();
|
||||
void _browse_install_path();
|
||||
void _create_folder();
|
||||
|
||||
void _text_changed(const String &p_text);
|
||||
void _nonempty_confirmation_ok_pressed();
|
||||
void _renderer_selected();
|
||||
void _remove_created_folder();
|
||||
|
||||
void ok_pressed() override;
|
||||
void cancel_pressed() override;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_zip_path(const String &p_path);
|
||||
void set_zip_title(const String &p_title);
|
||||
void set_mode(Mode p_mode);
|
||||
void set_project_path(const String &p_path);
|
||||
|
||||
void ask_for_path_and_show();
|
||||
void show_dialog();
|
||||
|
||||
ProjectDialog();
|
||||
};
|
||||
|
||||
#endif // PROJECT_DIALOG_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,264 @@
|
||||
/**************************************************************************/
|
||||
/* project_list.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PROJECT_LIST_H
|
||||
#define PROJECT_LIST_H
|
||||
|
||||
#include "core/io/config_file.h"
|
||||
#include "scene/gui/box_container.h"
|
||||
#include "scene/gui/scroll_container.h"
|
||||
|
||||
class Button;
|
||||
class Label;
|
||||
class ProjectList;
|
||||
class TextureButton;
|
||||
class TextureRect;
|
||||
|
||||
class ProjectListItemControl : public HBoxContainer {
|
||||
GDCLASS(ProjectListItemControl, HBoxContainer)
|
||||
|
||||
VBoxContainer *main_vbox = nullptr;
|
||||
TextureButton *favorite_button = nullptr;
|
||||
Button *explore_button = nullptr;
|
||||
|
||||
TextureRect *project_icon = nullptr;
|
||||
Label *project_title = nullptr;
|
||||
Label *project_path = nullptr;
|
||||
TextureRect *project_unsupported_features = nullptr;
|
||||
HBoxContainer *tag_container = nullptr;
|
||||
|
||||
bool project_is_missing = false;
|
||||
bool icon_needs_reload = true;
|
||||
bool is_selected = false;
|
||||
bool is_hovering = false;
|
||||
|
||||
void _favorite_button_pressed();
|
||||
void _explore_button_pressed();
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void set_project_title(const String &p_title);
|
||||
void set_project_path(const String &p_path);
|
||||
void set_tags(const PackedStringArray &p_tags, ProjectList *p_parent_list);
|
||||
void set_project_icon(const Ref<Texture2D> &p_icon);
|
||||
void set_unsupported_features(PackedStringArray p_features);
|
||||
|
||||
bool should_load_project_icon() const;
|
||||
void set_selected(bool p_selected);
|
||||
|
||||
void set_is_favorite(bool p_favorite);
|
||||
void set_is_missing(bool p_missing);
|
||||
void set_is_grayed(bool p_grayed);
|
||||
|
||||
ProjectListItemControl();
|
||||
};
|
||||
|
||||
class ProjectList : public ScrollContainer {
|
||||
GDCLASS(ProjectList, ScrollContainer)
|
||||
|
||||
friend class ProjectManager;
|
||||
|
||||
public:
|
||||
enum FilterOption {
|
||||
EDIT_DATE,
|
||||
NAME,
|
||||
PATH,
|
||||
TAGS,
|
||||
};
|
||||
|
||||
// Can often be passed by copy.
|
||||
struct Item {
|
||||
String project_name;
|
||||
String description;
|
||||
PackedStringArray tags;
|
||||
String tag_sort_string;
|
||||
String path;
|
||||
String icon;
|
||||
String main_scene;
|
||||
PackedStringArray unsupported_features;
|
||||
uint64_t last_edited = 0;
|
||||
bool favorite = false;
|
||||
bool grayed = false;
|
||||
bool missing = false;
|
||||
int version = 0;
|
||||
|
||||
ProjectListItemControl *control = nullptr;
|
||||
|
||||
Item() {}
|
||||
|
||||
Item(const String &p_name,
|
||||
const String &p_description,
|
||||
const PackedStringArray &p_tags,
|
||||
const String &p_path,
|
||||
const String &p_icon,
|
||||
const String &p_main_scene,
|
||||
const PackedStringArray &p_unsupported_features,
|
||||
uint64_t p_last_edited,
|
||||
bool p_favorite,
|
||||
bool p_grayed,
|
||||
bool p_missing,
|
||||
int p_version) {
|
||||
project_name = p_name;
|
||||
description = p_description;
|
||||
tags = p_tags;
|
||||
path = p_path;
|
||||
icon = p_icon;
|
||||
main_scene = p_main_scene;
|
||||
unsupported_features = p_unsupported_features;
|
||||
last_edited = p_last_edited;
|
||||
favorite = p_favorite;
|
||||
grayed = p_grayed;
|
||||
missing = p_missing;
|
||||
version = p_version;
|
||||
|
||||
control = nullptr;
|
||||
|
||||
PackedStringArray sorted_tags = tags;
|
||||
sorted_tags.sort();
|
||||
tag_sort_string = String().join(sorted_tags);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool operator==(const Item &l) const {
|
||||
return path == l.path;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
String _config_path;
|
||||
ConfigFile _config;
|
||||
|
||||
Vector<Item> _projects;
|
||||
|
||||
int _icon_load_index = 0;
|
||||
bool project_opening_initiated = false;
|
||||
|
||||
String _search_term;
|
||||
FilterOption _order_option = FilterOption::EDIT_DATE;
|
||||
HashSet<String> _selected_project_paths;
|
||||
String _last_clicked; // Project key
|
||||
|
||||
VBoxContainer *project_list_vbox = nullptr;
|
||||
|
||||
// Initialization & loading.
|
||||
|
||||
void _migrate_config();
|
||||
|
||||
static Item load_project_data(const String &p_property_key, bool p_favorite);
|
||||
void _update_icons_async();
|
||||
void _load_project_icon(int p_index);
|
||||
|
||||
// Project list updates.
|
||||
|
||||
void _scan_folder_recursive(const String &p_path, List<String> *r_projects);
|
||||
|
||||
// Project list items.
|
||||
|
||||
void _create_project_item_control(int p_index);
|
||||
void _toggle_project(int p_index);
|
||||
void _remove_project(int p_index, bool p_update_settings);
|
||||
|
||||
void _list_item_input(const Ref<InputEvent> &p_ev, Node *p_hb);
|
||||
void _on_favorite_pressed(Node *p_hb);
|
||||
void _on_explore_pressed(const String &p_path);
|
||||
|
||||
// Project list selection.
|
||||
|
||||
void _clear_project_selection();
|
||||
void _select_project_nocheck(int p_index);
|
||||
void _deselect_project_nocheck(int p_index);
|
||||
void _select_project_range(int p_begin, int p_end);
|
||||
|
||||
// Global menu integration.
|
||||
|
||||
void _global_menu_new_window(const Variant &p_tag);
|
||||
void _global_menu_open_project(const Variant &p_tag);
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
static const char *SIGNAL_LIST_CHANGED;
|
||||
static const char *SIGNAL_SELECTION_CHANGED;
|
||||
static const char *SIGNAL_PROJECT_ASK_OPEN;
|
||||
|
||||
static bool project_feature_looks_like_version(const String &p_feature);
|
||||
|
||||
// Initialization & loading.
|
||||
|
||||
void save_config();
|
||||
|
||||
// Project list updates.
|
||||
|
||||
void update_project_list();
|
||||
void sort_projects();
|
||||
int get_project_count() const;
|
||||
|
||||
void find_projects(const String &p_path);
|
||||
void find_projects_multiple(const PackedStringArray &p_paths);
|
||||
|
||||
// Project list items.
|
||||
|
||||
void add_project(const String &dir_path, bool favorite);
|
||||
void set_project_version(const String &p_project_path, int version);
|
||||
int refresh_project(const String &dir_path);
|
||||
void ensure_project_visible(int p_index);
|
||||
|
||||
// Project list selection.
|
||||
|
||||
void select_project(int p_index);
|
||||
void select_first_visible_project();
|
||||
Vector<Item> get_selected_projects() const;
|
||||
const HashSet<String> &get_selected_project_keys() const;
|
||||
int get_single_selected_index() const;
|
||||
void erase_selected_projects(bool p_delete_project_contents);
|
||||
|
||||
// Missing projects.
|
||||
|
||||
bool is_any_project_missing() const;
|
||||
void erase_missing_projects();
|
||||
|
||||
// Project list sorting and filtering.
|
||||
|
||||
void set_search_term(String p_search_term);
|
||||
void add_search_tag(const String &p_tag);
|
||||
void set_order_option(int p_option);
|
||||
|
||||
// Global menu integration.
|
||||
|
||||
void update_dock_menu();
|
||||
|
||||
ProjectList();
|
||||
};
|
||||
|
||||
#endif // PROJECT_LIST_H
|
||||
@@ -0,0 +1,74 @@
|
||||
/**************************************************************************/
|
||||
/* project_tag.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "project_tag.h"
|
||||
|
||||
#include "editor/themes/editor_scale.h"
|
||||
#include "scene/gui/button.h"
|
||||
#include "scene/gui/color_rect.h"
|
||||
|
||||
void ProjectTag::_notification(int p_what) {
|
||||
if (display_close && p_what == NOTIFICATION_THEME_CHANGED) {
|
||||
button->set_icon(get_theme_icon(SNAME("close"), SNAME("TabBar")));
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectTag::connect_button_to(const Callable &p_callable) {
|
||||
button->connect(SNAME("pressed"), p_callable, CONNECT_DEFERRED);
|
||||
}
|
||||
|
||||
const String ProjectTag::get_tag() const {
|
||||
return tag_string;
|
||||
}
|
||||
|
||||
ProjectTag::ProjectTag(const String &p_text, bool p_display_close) {
|
||||
add_theme_constant_override(SNAME("separation"), 0);
|
||||
set_v_size_flags(SIZE_SHRINK_CENTER);
|
||||
tag_string = p_text;
|
||||
display_close = p_display_close;
|
||||
|
||||
Color tag_color = Color(1, 0, 0);
|
||||
tag_color.set_ok_hsl_s(0.8);
|
||||
tag_color.set_ok_hsl_h(float(p_text.hash() * 10001 % UINT32_MAX) / float(UINT32_MAX));
|
||||
set_self_modulate(tag_color);
|
||||
|
||||
ColorRect *cr = memnew(ColorRect);
|
||||
add_child(cr);
|
||||
cr->set_custom_minimum_size(Vector2(4, 0) * EDSCALE);
|
||||
cr->set_color(tag_color);
|
||||
|
||||
button = memnew(Button);
|
||||
add_child(button);
|
||||
button->set_auto_translate(false);
|
||||
button->set_text(p_text.capitalize());
|
||||
button->set_focus_mode(FOCUS_NONE);
|
||||
button->set_icon_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
|
||||
button->set_theme_type_variation(SNAME("ProjectTag"));
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/**************************************************************************/
|
||||
/* project_tag.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PROJECT_TAG_H
|
||||
#define PROJECT_TAG_H
|
||||
|
||||
#include "scene/gui/box_container.h"
|
||||
|
||||
class Button;
|
||||
|
||||
class ProjectTag : public HBoxContainer {
|
||||
GDCLASS(ProjectTag, HBoxContainer);
|
||||
|
||||
String tag_string;
|
||||
bool display_close = false;
|
||||
|
||||
Button *button = nullptr;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
public:
|
||||
void connect_button_to(const Callable &p_callable);
|
||||
const String get_tag() const;
|
||||
|
||||
ProjectTag(const String &p_text, bool p_display_close = false);
|
||||
};
|
||||
|
||||
#endif // PROJECT_TAG_H
|
||||
Reference in New Issue
Block a user