@@ -653,6 +653,11 @@ int FileDialog::_get_selected_file_idx() {
653653 return selected.is_empty () ? -1 : selected[0 ];
654654}
655655
656+ String FileDialog::_get_item_path (int p_idx) const {
657+ const Dictionary meta = file_list->get_item_metadata (p_idx);
658+ return ProjectSettings::get_singleton ()->globalize_path (dir_access->get_current_dir ().path_join (meta[" name" ]));
659+ }
660+
656661void FileDialog::_file_list_multi_selected (int p_item, bool p_selected) {
657662 if (p_selected) {
658663 _file_list_selected (p_item);
@@ -715,13 +720,32 @@ void FileDialog::update_file_name() {
715720}
716721
717722void FileDialog::_item_menu_id_pressed (int p_option) {
723+ int selected = _get_selected_file_idx ();
718724 switch (p_option) {
725+ case ITEM_MENU_COPY_PATH: {
726+ if (selected > -1 ) {
727+ DisplayServer::get_singleton ()->clipboard_set (_get_item_path (selected));
728+ }
729+ } break ;
730+
731+ case ITEM_MENU_DELETE: {
732+ if (selected > -1 ) {
733+ delete_dialog->popup_centered (Size2 (250 , 80 ));
734+ }
735+ } break ;
736+
737+ case ITEM_MENU_REFRESH: {
738+ invalidate ();
739+ } break ;
740+
741+ case ITEM_MENU_NEW_FOLDER: {
742+ _make_dir ();
743+ } break ;
744+
719745 case ITEM_MENU_SHOW_IN_EXPLORER: {
720746 String path;
721- int selected = _get_selected_file_idx ();
722747 if (selected > -1 ) {
723- Dictionary d = file_list->get_item_metadata (selected);
724- path = ProjectSettings::get_singleton ()->globalize_path (dir_access->get_current_dir ().path_join (d[" name" ]));
748+ path = _get_item_path (selected);
725749 } else {
726750 path = ProjectSettings::get_singleton ()->globalize_path (dir_access->get_current_dir ());
727751 }
@@ -730,12 +754,11 @@ void FileDialog::_item_menu_id_pressed(int p_option) {
730754 } break ;
731755
732756 case ITEM_MENU_SHOW_BUNDLE_CONTENT: {
733- int selected = _get_selected_file_idx ();
734757 if (selected == -1 ) {
735758 return ;
736759 }
737- Dictionary d = file_list->get_item_metadata (selected);
738- _change_dir (d [" name" ]);
760+ Dictionary meta = file_list->get_item_metadata (selected);
761+ _change_dir (meta [" name" ]);
739762 if (mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES || mode == FILE_MODE_OPEN_DIR || mode == FILE_MODE_OPEN_ANY) {
740763 filename_edit->set_text (" " );
741764 }
@@ -746,36 +769,55 @@ void FileDialog::_item_menu_id_pressed(int p_option) {
746769
747770void FileDialog::_empty_clicked (const Vector2 &p_pos, MouseButton p_button) {
748771 if (p_button == MouseButton::RIGHT) {
749- item_menu->clear ();
750- #if !defined(ANDROID_ENABLED) && !defined(WEB_ENABLED)
751- // Opening the system file manager is not supported on the Android and web editors.
752- item_menu->add_item (ETR (" Open in File Manager" ), ITEM_MENU_SHOW_IN_EXPLORER);
753-
754- item_menu->set_position (file_list->get_screen_position () + p_pos);
755- item_menu->reset_size ();
756- item_menu->popup ();
757- #endif
772+ _popup_menu (p_pos, -1 );
758773 } else if (p_button == MouseButton::LEFT) {
759774 deselect_all ();
760775 }
761776}
762777
763778void FileDialog::_item_clicked (int p_item, const Vector2 &p_pos, MouseButton p_button) {
764779 if (p_button == MouseButton::RIGHT) {
765- item_menu->clear ();
766- #if !defined(ANDROID_ENABLED) && !defined(WEB_ENABLED)
767- // Opening the system file manager is not supported on the Android and web editors.
768- Dictionary d = file_list->get_item_metadata (p_item);
769- if (d[" bundle" ]) {
770- item_menu->add_item (ETR (" Show Package Contents" ), ITEM_MENU_SHOW_BUNDLE_CONTENT);
780+ _popup_menu (p_pos, p_item);
781+ }
782+ }
783+
784+ void FileDialog::_popup_menu (const Vector2 &p_pos, int p_for_item) {
785+ item_menu->clear ();
786+
787+ if (p_for_item > -1 ) {
788+ item_menu->add_item (ETR (" Copy Path" ), ITEM_MENU_COPY_PATH);
789+ if (customization_flags[CUSTOMIZATION_DELETE]) {
790+ item_menu->add_item (ETR (" Delete" ), ITEM_MENU_DELETE);
771791 }
772- item_menu->add_item (ETR (" Open in File Manager" ), ITEM_MENU_SHOW_IN_EXPLORER);
792+ } else {
793+ if (can_create_folders) {
794+ item_menu->add_item (ETR (" New Folder..." ), ITEM_MENU_NEW_FOLDER);
795+ }
796+ item_menu->add_item (ETR (" Refresh" ), ITEM_MENU_REFRESH);
797+ }
798+
799+ #if !defined(ANDROID_ENABLED) && !defined(WEB_ENABLED)
800+ // Opening the system file manager is not supported on the Android and web editors.
801+ item_menu->add_separator ();
773802
774- item_menu->set_position (file_list->get_screen_position () + p_pos);
775- item_menu->reset_size ();
776- item_menu->popup ();
803+ Dictionary meta;
804+ if (p_for_item > -1 ) {
805+ meta = file_list->get_item_metadata (p_for_item);
806+ }
807+
808+ item_menu->add_item ((p_for_item == -1 || meta[" dir" ]) ? ETR (" Open in File Manager" ) : ETR (" Show in File Manager" ), ITEM_MENU_SHOW_IN_EXPLORER);
809+ if (meta[" bundle" ]) {
810+ item_menu->add_item (ETR (" Show Package Contents" ), ITEM_MENU_SHOW_BUNDLE_CONTENT);
811+ }
777812#endif
813+
814+ if (item_menu->get_item_count () == 0 ) {
815+ return ;
778816 }
817+
818+ item_menu->set_position (file_list->get_screen_position () + p_pos);
819+ item_menu->reset_size ();
820+ item_menu->popup ();
779821}
780822
781823void FileDialog::update_file_list () {
@@ -1063,6 +1105,11 @@ void FileDialog::_file_list_select_first() {
10631105 }
10641106}
10651107
1108+ void FileDialog::_delete_confirm () {
1109+ OS::get_singleton ()->move_to_trash (_get_item_path (_get_selected_file_idx ()));
1110+ invalidate ();
1111+ }
1112+
10661113void FileDialog::_filename_filter_selected () {
10671114 int selected = _get_selected_file_idx ();
10681115 if (selected > -1 ) {
@@ -1518,7 +1565,8 @@ void FileDialog::_setup_button(Button *p_button, const Ref<Texture2D> &p_icon) {
15181565}
15191566
15201567void FileDialog::_update_make_dir_visible () {
1521- make_dir_container->set_visible (customization_flags[CUSTOMIZATION_CREATE_FOLDER] && mode != FILE_MODE_OPEN_FILE && mode != FILE_MODE_OPEN_FILES);
1568+ can_create_folders = customization_flags[CUSTOMIZATION_CREATE_FOLDER] && mode != FILE_MODE_OPEN_FILE && mode != FILE_MODE_OPEN_FILES;
1569+ make_dir_container->set_visible (can_create_folders);
15221570}
15231571
15241572FileDialog::Access FileDialog::get_access () const {
@@ -2058,6 +2106,7 @@ void FileDialog::_bind_methods() {
20582106 ADD_PROPERTYI (PropertyInfo (Variant::BOOL, " recent_list_enabled" ), " set_customization_flag_enabled" , " is_customization_flag_enabled" , CUSTOMIZATION_RECENT);
20592107 ADD_PROPERTYI (PropertyInfo (Variant::BOOL, " layout_toggle_enabled" ), " set_customization_flag_enabled" , " is_customization_flag_enabled" , CUSTOMIZATION_LAYOUT);
20602108 ADD_PROPERTYI (PropertyInfo (Variant::BOOL, " overwrite_warning_enabled" ), " set_customization_flag_enabled" , " is_customization_flag_enabled" , CUSTOMIZATION_OVERWRITE_WARNING);
2109+ ADD_PROPERTYI (PropertyInfo (Variant::BOOL, " deleting_enabled" ), " set_customization_flag_enabled" , " is_customization_flag_enabled" , CUSTOMIZATION_DELETE);
20612110
20622111 ADD_PROPERTY (PropertyInfo (Variant::STRING, " current_dir" , PROPERTY_HINT_DIR, " " , PROPERTY_USAGE_NONE), " set_current_dir" , " get_current_dir" );
20632112 ADD_PROPERTY (PropertyInfo (Variant::STRING, " current_file" , PROPERTY_HINT_FILE_PATH, " *" , PROPERTY_USAGE_NONE), " set_current_file" , " get_current_file" );
@@ -2089,6 +2138,7 @@ void FileDialog::_bind_methods() {
20892138 BIND_ENUM_CONSTANT (CUSTOMIZATION_RECENT);
20902139 BIND_ENUM_CONSTANT (CUSTOMIZATION_LAYOUT);
20912140 BIND_ENUM_CONSTANT (CUSTOMIZATION_OVERWRITE_WARNING);
2141+ BIND_ENUM_CONSTANT (CUSTOMIZATION_DELETE);
20922142
20932143 BIND_THEME_ITEM (Theme::DATA_TYPE_CONSTANT, FileDialog, thumbnail_size);
20942144 BIND_THEME_ITEM (Theme::DATA_TYPE_ICON, FileDialog, parent_folder);
@@ -2495,6 +2545,11 @@ FileDialog::FileDialog() {
24952545 add_child (confirm_save, false , INTERNAL_MODE_FRONT);
24962546 confirm_save->connect (SceneStringName (confirmed), callable_mp (this , &FileDialog::_save_confirm_pressed));
24972547
2548+ delete_dialog = memnew (ConfirmationDialog);
2549+ delete_dialog->set_text (ETR (" Delete the selected file?\n Depending on your filesystem configuration, the files will either be moved to the system trash or deleted permanently." ));
2550+ add_child (delete_dialog, false , INTERNAL_MODE_FRONT);
2551+ delete_dialog->connect (SceneStringName (confirmed), callable_mp (this , &FileDialog::_delete_confirm));
2552+
24982553 make_dir_dialog = memnew (ConfirmationDialog);
24992554 make_dir_dialog->set_title (ETR (" Create Folder" ));
25002555 add_child (make_dir_dialog, false , INTERNAL_MODE_FRONT);
0 commit comments