From f44117271998ff453ee7ce6023233d5f35bf11c2 Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Mon, 10 Jun 2024 11:30:30 -0400 Subject: [PATCH] Customize the file manager for each platform --- core/os/os.h | 16 ++++++++++++++++ drivers/apple_embedded/os_apple_embedded.h | 11 +++++++++++ editor/debugger/script_editor_debugger.cpp | 2 +- editor/docks/filesystem_dock.cpp | 2 +- editor/editor_node.cpp | 2 +- editor/gui/editor_quick_open_dialog.cpp | 2 +- editor/project_manager/project_list.cpp | 14 +++++++------- .../editor/objectdb_profiler_panel.cpp | 2 +- platform/macos/os_macos.h | 11 +++++++++++ platform/windows/os_windows.h | 11 +++++++++++ scene/gui/file_dialog.cpp | 2 +- 11 files changed, 62 insertions(+), 13 deletions(-) diff --git a/core/os/os.h b/core/os/os.h index c8efac5a03..c3efa22776 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -68,6 +68,11 @@ public: RENDERING_SOURCE_FALLBACK }; + enum PlatformString { + PLATFORM_STRING_FILE_MANAGER_OPEN, + PLATFORM_STRING_FILE_MANAGER_SHOW, + }; + private: static OS *singleton; static uint64_t target_ticks; @@ -392,6 +397,17 @@ public: // This is invoked by the GDExtensionManager after loading GDExtensions specified by the project. virtual void load_platform_gdextensions() const {} + virtual String get_platform_string(PlatformString p_platform_string) const { + switch (p_platform_string) { + case PlatformString::PLATFORM_STRING_FILE_MANAGER_OPEN: + return ETR("Open in File Manager"); + case PlatformString::PLATFORM_STRING_FILE_MANAGER_SHOW: + return ETR("Show in File Manager"); + default: + ERR_FAIL_V_MSG("", vformat("Couldn't find a string for platform string: %d.", p_platform_string)); + } + } + #ifdef TOOLS_ENABLED // Tests OpenGL context and Rendering Device simultaneous creation. This function is expected to crash on some NVIDIA drivers. virtual bool _test_create_rendering_device_and_gl(const String &p_display_driver) const { return true; } diff --git a/drivers/apple_embedded/os_apple_embedded.h b/drivers/apple_embedded/os_apple_embedded.h index 7dc1509409..1bab2bbda8 100644 --- a/drivers/apple_embedded/os_apple_embedded.h +++ b/drivers/apple_embedded/os_apple_embedded.h @@ -144,6 +144,17 @@ public: virtual bool request_permission(const String &p_name) override; virtual Vector get_granted_permissions() const override; + + virtual String get_platform_string(PlatformString p_platform_string) const override { + switch (p_platform_string) { + case OS::PlatformString::PLATFORM_STRING_FILE_MANAGER_OPEN: + return ETR("Open in Files"); + case OS::PlatformString::PLATFORM_STRING_FILE_MANAGER_SHOW: + return ETR("Show in Files"); + default: + return OS::get_platform_string(p_platform_string); + } + } }; #endif // APPLE_EMBEDDED_ENABLED diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index 448d828ea5..3b7276dc12 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -2438,7 +2438,7 @@ Instead, use the monitors tab to obtain more precise VRAM usage. vmem_item_menu = memnew(PopupMenu); vmem_item_menu->connect(SceneStringName(id_pressed), callable_mp(this, &ScriptEditorDebugger::_vmem_item_menu_id_pressed)); vmem_item_menu->add_item(TTRC("Show in FileSystem"), VMEM_MENU_SHOW_IN_FILESYSTEM); - vmem_item_menu->add_item(TTRC("Show in File Manager"), VMEM_MENU_SHOW_IN_EXPLORER); + vmem_item_menu->add_item(OS::get_singleton()->get_platform_string(OS::PLATFORM_STRING_FILE_MANAGER_SHOW), VMEM_MENU_SHOW_IN_EXPLORER); vmem_item_menu->add_item(TTRC("View Owners..."), VMEM_MENU_OWNERS); add_child(vmem_item_menu); } diff --git a/editor/docks/filesystem_dock.cpp b/editor/docks/filesystem_dock.cpp index 537947f454..3b3073b6b9 100644 --- a/editor/docks/filesystem_dock.cpp +++ b/editor/docks/filesystem_dock.cpp @@ -3651,7 +3651,7 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, const Vect } p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("Filesystem")), ED_GET_SHORTCUT("filesystem_dock/show_in_explorer"), FILE_MENU_SHOW_IN_EXPLORER); - p_popup->set_item_text(p_popup->get_item_index(FILE_MENU_SHOW_IN_EXPLORER), is_directory ? TTRC("Open in File Manager") : TTRC("Show in File Manager")); + p_popup->set_item_text(p_popup->get_item_index(FILE_MENU_SHOW_IN_EXPLORER), is_directory ? OS::get_singleton()->get_platform_string(OS::PLATFORM_STRING_FILE_MANAGER_OPEN) : OS::get_singleton()->get_platform_string(OS::PLATFORM_STRING_FILE_MANAGER_SHOW)); #endif current_path = fpath; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 346335a6dc..db78ab609a 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -9191,7 +9191,7 @@ EditorNode::EditorNode() { } remove_android_build_template = memnew(ConfirmationDialog); - remove_android_build_template->set_ok_button_text(TTR("Show in File Manager")); + remove_android_build_template->set_ok_button_text(OS::get_singleton()->get_platform_string(OS::PLATFORM_STRING_FILE_MANAGER_OPEN)); remove_android_build_template->connect(SceneStringName(confirmed), callable_mp(this, &EditorNode::_android_explore_build_templates)); gui_base->add_child(remove_android_build_template); diff --git a/editor/gui/editor_quick_open_dialog.cpp b/editor/gui/editor_quick_open_dialog.cpp index 287dd3b2ae..2d34b14f56 100644 --- a/editor/gui/editor_quick_open_dialog.cpp +++ b/editor/gui/editor_quick_open_dialog.cpp @@ -361,7 +361,7 @@ QuickOpenResultContainer::QuickOpenResultContainer() { file_context_menu = memnew(PopupMenu); file_context_menu->add_item(TTR("Show in FileSystem"), FILE_SHOW_IN_FILESYSTEM); - file_context_menu->add_item(TTR("Show in File Manager"), FILE_SHOW_IN_FILE_MANAGER); + file_context_menu->add_item(OS::get_singleton()->get_platform_string(OS::PLATFORM_STRING_FILE_MANAGER_SHOW), FILE_SHOW_IN_FILE_MANAGER); file_context_menu->connect(SceneStringName(id_pressed), callable_mp(this, &QuickOpenResultContainer::_menu_option)); file_context_menu->hide(); scroll_container->add_child(file_context_menu); diff --git a/editor/project_manager/project_list.cpp b/editor/project_manager/project_list.cpp index c6f00329f3..ea75ebd439 100644 --- a/editor/project_manager/project_list.cpp +++ b/editor/project_manager/project_list.cpp @@ -328,13 +328,13 @@ void ProjectListItemControl::set_is_missing(bool p_missing) { explore_button->set_button_icon(get_editor_theme_icon(SNAME("FileBroken"))); explore_button->set_tooltip_text(TTRC("Error: Project is missing on the filesystem.")); } else { -#if !defined(ANDROID_ENABLED) && !defined(WEB_ENABLED) - explore_button->set_button_icon(get_editor_theme_icon(SNAME("Load"))); - explore_button->set_tooltip_text(TTRC("Show in File Manager")); -#else +#if defined(ANDROID_ENABLED) || defined(WEB_ENABLED) // Opening the system file manager is not supported on the Android and web editors. explore_button->hide(); -#endif +#else // !defined(ANDROID_ENABLED) && !defined(WEB_ENABLED) + explore_button->set_button_icon(get_editor_theme_icon(SNAME("Load"))); + explore_button->set_tooltip_text(OS::get_singleton()->get_platform_string(OS::PLATFORM_STRING_FILE_MANAGER_OPEN)); +#endif // defined(ANDROID_ENABLED) || defined(WEB_ENABLED) } } @@ -1199,8 +1199,8 @@ void ProjectList::_open_menu(const Vector2 &p_at, Control *p_hb) { project_context_menu->add_item(TTRC("Run Project"), MENU_RUN); project_context_menu->add_separator(); #if !defined(ANDROID_ENABLED) && !defined(WEB_ENABLED) - project_context_menu->add_item(TTRC("Show in File Manager"), MENU_SHOW_IN_FILE_MANAGER); -#endif + project_context_menu->add_item(OS::get_singleton()->get_platform_string(OS::PLATFORM_STRING_FILE_MANAGER_OPEN), MENU_SHOW_IN_FILE_MANAGER); +#endif // !defined(ANDROID_ENABLED) && !defined(WEB_ENABLED) project_context_menu->add_item(TTRC("Copy Path"), MENU_COPY_PATH); project_context_menu->add_separator(); project_context_menu->add_item(TTRC("Rename"), MENU_RENAME); diff --git a/modules/objectdb_profiler/editor/objectdb_profiler_panel.cpp b/modules/objectdb_profiler/editor/objectdb_profiler_panel.cpp index 32526c7ebd..2a85b1d03f 100644 --- a/modules/objectdb_profiler/editor/objectdb_profiler_panel.cpp +++ b/modules/objectdb_profiler/editor/objectdb_profiler_panel.cpp @@ -270,7 +270,7 @@ void ObjectDBProfilerPanel::_snapshot_rmb(const Vector2 &p_pos, MouseButton p_bu rmb_menu->clear(false); rmb_menu->add_icon_item(get_editor_theme_icon(SNAME("Rename")), TTRC("Rename"), OdbProfilerMenuOptions::ODB_MENU_RENAME); - rmb_menu->add_icon_item(get_editor_theme_icon(SNAME("Folder")), TTRC("Show in File Manager"), OdbProfilerMenuOptions::ODB_MENU_SHOW_IN_FOLDER); + rmb_menu->add_icon_item(get_editor_theme_icon(SNAME("Folder")), OS::get_singleton()->get_platform_string(OS::PLATFORM_STRING_FILE_MANAGER_OPEN), OdbProfilerMenuOptions::ODB_MENU_SHOW_IN_FOLDER); rmb_menu->add_icon_item(get_editor_theme_icon(SNAME("Remove")), TTRC("Delete"), OdbProfilerMenuOptions::ODB_MENU_DELETE); rmb_menu->set_position(snapshot_list->get_screen_position() + p_pos); diff --git a/platform/macos/os_macos.h b/platform/macos/os_macos.h index b171d88a7e..5c311d1f34 100644 --- a/platform/macos/os_macos.h +++ b/platform/macos/os_macos.h @@ -167,6 +167,17 @@ public: virtual void run() = 0; + virtual String get_platform_string(PlatformString p_platform_string) const override { + switch (p_platform_string) { + case OS::PlatformString::PLATFORM_STRING_FILE_MANAGER_OPEN: + return ETR("Open in Finder"); + case OS::PlatformString::PLATFORM_STRING_FILE_MANAGER_SHOW: + return ETR("Show in Finder"); + default: + return OS::get_platform_string(p_platform_string); + } + } + OS_MacOS(const char *p_execpath, int p_argc, char **p_argv); }; diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 453f333449..ea1896318f 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -264,6 +264,17 @@ public: void set_main_window(HWND p_main_window) { main_window = p_main_window; } + virtual String get_platform_string(PlatformString p_platform_string) const override { + switch (p_platform_string) { + case OS::PlatformString::PLATFORM_STRING_FILE_MANAGER_OPEN: + return ETR("Open in File Explorer"); + case OS::PlatformString::PLATFORM_STRING_FILE_MANAGER_SHOW: + return ETR("Show in File Explorer"); + default: + return OS::get_platform_string(p_platform_string); + } + } + #ifdef TOOLS_ENABLED virtual bool _test_create_rendering_device_and_gl(const String &p_display_driver) const override; virtual bool _test_create_rendering_device(const String &p_display_driver) const override; diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index c15181b096..ecf75a8a28 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -800,7 +800,7 @@ void FileDialog::_popup_menu(const Vector2 &p_pos, int p_for_item) { meta = file_list->get_item_metadata(p_for_item); } - 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); + item_menu->add_item((p_for_item == -1 || meta["dir"]) ? OS::get_singleton()->get_platform_string(OS::PLATFORM_STRING_FILE_MANAGER_OPEN) : OS::get_singleton()->get_platform_string(OS::PLATFORM_STRING_FILE_MANAGER_SHOW), ITEM_MENU_SHOW_IN_EXPLORER); item_menu->set_item_icon(-1, theme_cache.menu_show_in_file_manager); if (meta["bundle"]) { item_menu->add_item(ETR("Show Package Contents"), ITEM_MENU_SHOW_BUNDLE_CONTENT);