| 1 | /**************************************************************************/ |
| 2 | /* editor_autoload_settings.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #ifndef EDITOR_AUTOLOAD_SETTINGS_H |
| 32 | #define EDITOR_AUTOLOAD_SETTINGS_H |
| 33 | |
| 34 | #include "scene/gui/box_container.h" |
| 35 | #include "scene/gui/button.h" |
| 36 | #include "scene/gui/tree.h" |
| 37 | |
| 38 | class EditorFileDialog; |
| 39 | |
| 40 | class EditorAutoloadSettings : public VBoxContainer { |
| 41 | GDCLASS(EditorAutoloadSettings, VBoxContainer); |
| 42 | |
| 43 | enum { |
| 44 | BUTTON_OPEN, |
| 45 | BUTTON_MOVE_UP, |
| 46 | BUTTON_MOVE_DOWN, |
| 47 | BUTTON_DELETE |
| 48 | }; |
| 49 | |
| 50 | String path = "res://" ; |
| 51 | String autoload_changed = "autoload_changed" ; |
| 52 | |
| 53 | struct AutoloadInfo { |
| 54 | String name; |
| 55 | String path; |
| 56 | bool is_singleton = false; |
| 57 | bool in_editor = false; |
| 58 | int order = 0; |
| 59 | Node *node = nullptr; |
| 60 | |
| 61 | bool operator==(const AutoloadInfo &p_info) const { |
| 62 | return order == p_info.order; |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | List<AutoloadInfo> autoload_cache; |
| 67 | |
| 68 | bool updating_autoload = false; |
| 69 | String selected_autoload; |
| 70 | |
| 71 | Tree *tree = nullptr; |
| 72 | LineEdit *autoload_add_name = nullptr; |
| 73 | Button *add_autoload = nullptr; |
| 74 | LineEdit *autoload_add_path = nullptr; |
| 75 | Label *error_message = nullptr; |
| 76 | Button *browse_button = nullptr; |
| 77 | EditorFileDialog *file_dialog = nullptr; |
| 78 | |
| 79 | bool _autoload_name_is_valid(const String &p_name, String *r_error = nullptr); |
| 80 | |
| 81 | void _autoload_add(); |
| 82 | void _autoload_selected(); |
| 83 | void _autoload_edited(); |
| 84 | void _autoload_button_pressed(Object *p_item, int p_column, int p_button, MouseButton p_mouse_button); |
| 85 | void _autoload_activated(); |
| 86 | void _autoload_path_text_changed(const String p_path); |
| 87 | void _autoload_text_submitted(const String p_name); |
| 88 | void _autoload_text_changed(const String p_name); |
| 89 | void _autoload_open(const String &fpath); |
| 90 | void _autoload_file_callback(const String &p_path); |
| 91 | Node *_create_autoload(const String &p_path); |
| 92 | |
| 93 | void _script_created(Ref<Script> p_script); |
| 94 | |
| 95 | Variant get_drag_data_fw(const Point2 &p_point, Control *p_control); |
| 96 | bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_control) const; |
| 97 | void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_control); |
| 98 | |
| 99 | void _set_autoload_add_path(const String &p_text); |
| 100 | void _browse_autoload_add_path(); |
| 101 | |
| 102 | protected: |
| 103 | void _notification(int p_what); |
| 104 | static void _bind_methods(); |
| 105 | |
| 106 | public: |
| 107 | void update_autoload(); |
| 108 | bool autoload_add(const String &p_name, const String &p_path); |
| 109 | void autoload_remove(const String &p_name); |
| 110 | |
| 111 | EditorAutoloadSettings(); |
| 112 | ~EditorAutoloadSettings(); |
| 113 | }; |
| 114 | |
| 115 | #endif // EDITOR_AUTOLOAD_SETTINGS_H |
| 116 | |