@@ -2666,6 +2666,8 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
26662666int FileSystemDock::_get_menu_option_from_key (const Ref<InputEventKey> &p_key) {
26672667 if (ED_IS_SHORTCUT (" filesystem_dock/duplicate" , p_key)) {
26682668 return FILE_MENU_DUPLICATE;
2669+ } else if (ED_IS_SHORTCUT (" filesystem_dock/toggle_plugin" , p_key)) {
2670+ return FILE_MENU_TOGGLE_PLUGIN;
26692671 } else if (ED_IS_SHORTCUT (" filesystem_dock/copy_path" , p_key)) {
26702672 return FILE_MENU_COPY_PATH;
26712673 } else if (ED_IS_SHORTCUT (" filesystem_dock/copy_absolute_path" , p_key)) {
@@ -2700,6 +2702,13 @@ int FileSystemDock::_get_menu_option_from_key(const Ref<InputEventKey> &p_key) {
27002702 return -1 ;
27012703}
27022704
2705+ void FileSystemDock::_addon_option_toggled (int p_option_id, PopupMenu *p_popup) {
2706+ String plugin_name = selected_addons[p_option_id];
2707+ bool toggle = !EditorNode::get_singleton ()->is_addon_plugin_enabled (plugin_name);
2708+ p_popup->set_item_checked (p_option_id, toggle);
2709+ EditorNode::get_singleton ()->set_addon_plugin_enabled (plugin_name, toggle);
2710+ }
2711+
27032712void FileSystemDock::_resource_created () {
27042713 String fpath = current_path;
27052714 if (!fpath.ends_with (" /" )) {
@@ -3274,6 +3283,8 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, const Vect
32743283
32753284 Vector<String> favorites_list = EditorSettings::get_singleton ()->get_favorites ();
32763285
3286+ HashMap<String, String> addons;
3287+
32773288 bool all_files = true ;
32783289 bool all_files_scenes = true ;
32793290 bool all_folders = true ;
@@ -3291,6 +3302,38 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, const Vect
32913302 all_files_scenes &= (EditorFileSystem::get_singleton ()->get_file_type (fpath) == " PackedScene" );
32923303 }
32933304
3305+ // Check if it's an addon.
3306+ selected_addons.clear ();
3307+ const String addons_path = " res://addons/" ;
3308+ if (fpath.begins_with (addons_path)) {
3309+ if (fpath.length () == addons_path.length ()) {
3310+ for (const String &folder : DirAccess::get_directories_at (addons_path)) {
3311+ String full_folder_path = addons_path + folder + " /plugin.cfg" ;
3312+ bool is_plugin = FileAccess::exists (full_folder_path);
3313+ if (is_plugin) {
3314+ ConfigFile plugin_cfg;
3315+ Error err = plugin_cfg.load (full_folder_path);
3316+ ERR_FAIL_COND_MSG (err != OK, vformat (" Could not load plugin config file: %s" , full_folder_path));
3317+ String plugin_name = plugin_cfg.get_value (" plugin" , " name" , folder);
3318+ addons[folder] = plugin_name;
3319+ }
3320+ }
3321+ } else {
3322+ String folder = fpath.get_slicec (' /' , 3 );
3323+ if (!addons.has (folder)) {
3324+ String full_folder_path = addons_path + folder + " /plugin.cfg" ;
3325+ bool is_plugin = FileAccess::exists (full_folder_path);
3326+ if (is_plugin) {
3327+ ConfigFile plugin_cfg;
3328+ Error err = plugin_cfg.load (full_folder_path);
3329+ ERR_FAIL_COND_MSG (err != OK, vformat (" Could not load plugin config file: %s" , full_folder_path));
3330+ String plugin_name = plugin_cfg.get_value (" plugin" , " name" , folder);
3331+ addons[folder] = plugin_name;
3332+ }
3333+ }
3334+ }
3335+ }
3336+
32943337 // Check if in favorites.
32953338 bool found = false ;
32963339 for (int j = 0 ; j < favorites_list.size (); j++) {
@@ -3399,6 +3442,25 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, const Vect
33993442 }
34003443 }
34013444
3445+ // Add the addon options. Only show if at least one addon is selected.
3446+ if (addons.size () > 0 ) {
3447+ PopupMenu *addons_menu = memnew (PopupMenu);
3448+ addons_menu->set_hide_on_checkable_item_selection (false );
3449+ addons_menu->connect (SceneStringName (id_pressed), callable_mp (this , &FileSystemDock::_addon_option_toggled).bind (addons_menu));
3450+ p_popup->add_submenu_node_item (TTRC (" Plugins..." ), addons_menu);
3451+ p_popup->set_item_icon (-1 , get_editor_theme_icon (SNAME (" PluginScript" )));
3452+ int option_id = 0 ;
3453+ for (const KeyValue<String, String> &E : addons) {
3454+ String folder_name = E.key ;
3455+ String plugin_name = E.value ;
3456+ bool is_enabled = EditorNode::get_singleton ()->is_addon_plugin_enabled (folder_name);
3457+ addons_menu->add_check_item (plugin_name, option_id);
3458+ addons_menu->set_item_checked (-1 , is_enabled);
3459+ option_id++;
3460+ selected_addons.push_back (folder_name);
3461+ }
3462+ }
3463+
34023464 // Add the options that are only available when a single item is selected.
34033465 if (p_paths.size () == 1 ) {
34043466 p_popup->add_icon_shortcut (get_editor_theme_icon (SNAME (" ActionCopy" )), ED_GET_SHORTCUT (" filesystem_dock/copy_path" ), FILE_MENU_COPY_PATH);
@@ -4194,6 +4256,7 @@ FileSystemDock::FileSystemDock() {
41944256 ProjectSettings::get_singleton ()->add_hidden_prefix (" file_customization/" );
41954257
41964258 // `KeyModifierMask::CMD_OR_CTRL | Key::C` conflicts with other editor shortcuts.
4259+ ED_SHORTCUT (" filesystem_dock/toggle_plugin" , TTRC (" Toggle Plugin" ), Key::NONE);
41974260 ED_SHORTCUT (" filesystem_dock/copy_path" , TTRC (" Copy Path" ), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::C);
41984261 ED_SHORTCUT (" filesystem_dock/copy_absolute_path" , TTRC (" Copy Absolute Path" ), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::ALT | Key::C);
41994262 ED_SHORTCUT (" filesystem_dock/copy_uid" , TTRC (" Copy UID" ), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::ALT | KeyModifierMask::SHIFT | Key::C);
0 commit comments