MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / update_plugins

Method update_plugins

editor/plugins/editor_plugin_settings.cpp:78–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78void EditorPluginSettings::update_plugins() {
79 plugin_list->clear();
80 updating = true;
81 TreeItem *root = plugin_list->create_item();
82
83 Vector<String> plugins = _get_plugins("res://addons");
84 plugins.sort();
85
86 for (int i = 0; i < plugins.size(); i++) {
87 Ref<ConfigFile> cfg;
88 cfg.instantiate();
89 const String &path = plugins[i];
90
91 Error err = cfg->load(path);
92
93 if (err != OK) {
94 WARN_PRINT("Can't load plugin config at: " + path);
95 } else {
96 Vector<String> missing_keys;
97 for (const String required_key : { "name", "author", "version", "description", "script" }) {
98 if (!cfg->has_section_key("plugin", required_key)) {
99 missing_keys.append("\"plugin/" + required_key + "\"");
100 }
101 }
102
103 if (!missing_keys.is_empty()) {
104 WARN_PRINT(vformat("Plugin config at \"%s\" is missing the following keys: %s", path, String(",").join(missing_keys)));
105 } else {
106 String name = cfg->get_value("plugin", "name");
107 String author = cfg->get_value("plugin", "author");
108 String version = cfg->get_value("plugin", "version");
109 String description = cfg->get_value("plugin", "description");
110 String scr = cfg->get_value("plugin", "script");
111
112 bool is_enabled = EditorNode::get_singleton()->is_addon_plugin_enabled(path);
113 Color disabled_color = get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor));
114
115 const PackedInt32Array boundaries = TS->string_get_word_breaks(description, "", 80);
116 String wrapped_description;
117
118 for (int j = 0; j < boundaries.size(); j += 2) {
119 const int start = boundaries[j];
120 const int end = boundaries[j + 1];
121 wrapped_description += "\n" + description.substr(start, end - start + 1).rstrip("\n");
122 }
123
124 TreeItem *item = plugin_list->create_item(root);
125 item->set_text(COLUMN_NAME, name);
126 if (!is_enabled) {
127 item->set_custom_color(COLUMN_NAME, disabled_color);
128 }
129 item->set_tooltip_text(COLUMN_NAME, vformat(TTR("Name: %s\nPath: %s\nMain Script: %s\n\n%s"), name, path, scr, wrapped_description));
130 item->set_metadata(COLUMN_NAME, path);
131 item->set_text(COLUMN_VERSION, version);
132 item->set_custom_font(COLUMN_VERSION, get_theme_font("source", EditorStringName(EditorFonts)));
133 item->set_metadata(COLUMN_VERSION, scr);
134 item->set_text(COLUMN_AUTHOR, author);
135 item->set_metadata(COLUMN_AUTHOR, description);

Callers 2

_on_plugin_readyMethod · 0.45
_on_confirmedMethod · 0.45

Calls 15

vformatFunction · 0.85
TTRFunction · 0.85
has_section_keyMethod · 0.80
joinMethod · 0.80
rstripMethod · 0.80
substrMethod · 0.80
set_custom_colorMethod · 0.80
set_metadataMethod · 0.80
set_custom_fontMethod · 0.80
set_cell_modeMethod · 0.80

Tested by

no test coverage detected