diff --git a/lib/libimhex/include/hex/helpers/fs.hpp b/lib/libimhex/include/hex/helpers/fs.hpp index 807c48aa7..e61c7e918 100644 --- a/lib/libimhex/include/hex/helpers/fs.hpp +++ b/lib/libimhex/include/hex/helpers/fs.hpp @@ -75,17 +75,16 @@ namespace hex::fs { std::fs::path toShortPath(const std::fs::path &path); - enum class DialogMode - { + enum class DialogMode { Open, Save, Folder }; + void setFileBrowserErrorCallback(const std::function &callback); bool openFileBrowser(DialogMode mode, const std::vector &validExtensions, const std::function &callback, const std::string &defaultPath = {}); - enum class ImHexPath - { + enum class ImHexPath { Patterns, PatternsInclude, Magic, diff --git a/lib/libimhex/source/helpers/fs.cpp b/lib/libimhex/source/helpers/fs.cpp index dc58ced3e..3fcd4e02b 100644 --- a/lib/libimhex/source/helpers/fs.cpp +++ b/lib/libimhex/source/helpers/fs.cpp @@ -75,6 +75,11 @@ namespace hex::fs { return result; } + static std::function s_fileBrowserErrorCallback; + void setFileBrowserErrorCallback(const std::function &callback) { + s_fileBrowserErrorCallback = callback; + } + bool openFileBrowser(DialogMode mode, const std::vector &validExtensions, const std::function &callback, const std::string &defaultPath) { NFD::Init(); @@ -94,9 +99,14 @@ namespace hex::fs { hex::unreachable(); } - if (result == NFD_OKAY && outPath != nullptr) { - callback(reinterpret_cast(outPath)); - NFD::FreePath(outPath); + if (result == NFD_OKAY){ + if(outPath != nullptr) { + callback(reinterpret_cast(outPath)); + NFD::FreePath(outPath); + } + } else if (result==NFD_ERROR) { + if (s_fileBrowserErrorCallback != nullptr) + s_fileBrowserErrorCallback(); } NFD::Quit(); diff --git a/plugins/builtin/source/content/events.cpp b/plugins/builtin/source/content/events.cpp index d5086b140..b91ceae77 100644 --- a/plugins/builtin/source/content/events.cpp +++ b/plugins/builtin/source/content/events.cpp @@ -123,6 +123,14 @@ namespace hex::plugin::builtin { ProviderExtraData::erase(provider); }); + fs::setFileBrowserErrorCallback([]{ + #if defined(NFD_PORTAL) + View::showErrorPopup("hex.builtin.popup.error.file_dialog.portal"_lang); + #else + View::showErrorPopup("hex.builtin.popup.error.file_dialog.common"_lang); + #endif + }); + } } \ No newline at end of file diff --git a/plugins/builtin/source/lang/de_DE.cpp b/plugins/builtin/source/lang/de_DE.cpp index d9a78f93f..44f98532f 100644 --- a/plugins/builtin/source/lang/de_DE.cpp +++ b/plugins/builtin/source/lang/de_DE.cpp @@ -119,6 +119,21 @@ namespace hex::plugin::builtin { { "hex.builtin.popup.error.project.save", "Speichern des Projektes fehlgeschlagen!!" }, { "hex.builtin.popup.error.create", "Erstellen der neuen Datei fehlgeschlagen!" }, { "hex.builtin.popup.error.task_exception", "Fehler in Task '{}':\n\n{}" }, + { "hex.builtin.popup.error.file_dialog.portal", + "Ein Fehler trat beim öffnen des Dateibrowser auf! Der Grund dafür kann sein, dass dein System kein xdg-desktop-portal Backend korrekt installiert hat.\n" + "\n" + "Auf KDE wird xdg-desktop-portal-kde benötigt.\n" + "Auf Gnome wird xdg-desktop-portal-gnome benötigt.\n" + "Auf wlroots wird xdg-desktop-portal-wlr benötigt.\n" + "Andernfalls kann xdg-desktop-portal-gtk.\n" + "\n" + "Starte dein System neu nach der Installation.\n" + "\n" + "Falls der Dateibrowser immer noch nicht funktionieren sollte, erstelle ein Issue auf https://github.com/WerWolv/ImHex/issues\n" + "\n" + "In der Zwischenzeit können Dateien immer noch geöffnet werden, in dem sie auf das ImHex Fenster gezogen werden." + }, + { "hex.builtin.popup.error.file_dialog.common", "Ein Fehler trat beim öffnen des Dateibrowser auf!" }, { "hex.builtin.menu.file", "Datei" }, { "hex.builtin.file.open_file", "Datei öffnen..." }, diff --git a/plugins/builtin/source/lang/en_US.cpp b/plugins/builtin/source/lang/en_US.cpp index c8807f9e6..d5017611e 100644 --- a/plugins/builtin/source/lang/en_US.cpp +++ b/plugins/builtin/source/lang/en_US.cpp @@ -120,6 +120,21 @@ namespace hex::plugin::builtin { { "hex.builtin.popup.error.project.load", "Failed to load project!" }, { "hex.builtin.popup.error.project.save", "Failed to save project!" }, { "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" }, + { "hex.builtin.popup.error.file_dialog.portal", + "There was an error while opening the file browser. This might be caused by your system not having a xdg-desktop-portal backend installed correctly.\n" + "\n" + "On KDE, it's xdg-desktop-portal-kde.\n" + "On Gnome it's xdg-desktop-portal-gnome.\n" + "On wlroots it's xdg-desktop-portal-wlr.\n" + "Otherwise, you can try to use xdg-desktop-portal-gtk.\n" + "\n" + "Reboot your system after installing it.\n" + "\n" + "If the file browser still doesn't work after this, submit an issue at https://github.com/WerWolv/ImHex/issues\n" + "\n" + "In the meantime files can still be opened by dragging them onto the ImHex window!" + }, + { "hex.builtin.popup.error.file_dialog.common", "An error occurred while opening the file browser!" }, { "hex.builtin.menu.file", "File" }, { "hex.builtin.menu.file.create_file", "New File..." }, diff --git a/plugins/builtin/source/lang/it_IT.cpp b/plugins/builtin/source/lang/it_IT.cpp index cc0d3a0f9..9aef6f5e4 100644 --- a/plugins/builtin/source/lang/it_IT.cpp +++ b/plugins/builtin/source/lang/it_IT.cpp @@ -119,6 +119,21 @@ namespace hex::plugin::builtin { //{ "hex.builtin.popup.error.project.load", "Failed to load project!" }, //{ "hex.builtin.popup.error.project.save", "Failed to save project!" }, //{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" }, + //{ "hex.builtin.popup.error.file_dialog.portal", + // "There was an error while opening the file browser. This might be caused by your system not having a xdg-desktop-portal backend installed correctly.\n" + // "\n" + // "On KDE, it's xdg-desktop-portal-kde.\n" + // "On Gnome it's xdg-desktop-portal-gnome.\n" + // "On wlroots it's xdg-desktop-portal-wlr.\n" + // "Otherwise, you can try to use xdg-desktop-portal-gtk.\n" + // "\n" + // "Reboot your system after installing it.\n" + // "\n" + // "If the file browser still doesn't work after this, submit an issue at https://github.com/WerWolv/ImHex/issues\n" + // "\n" + // "In the meantime files can still be opened by dragging them onto the ImHex window!" + //}, + //{ "hex.builtin.popup.error.file_dialog.common", "An error occurred while opening the file browser!" }, { "hex.builtin.menu.file", "File" }, //{ "hex.builtin.menu.file.create_file", "New File..." }, diff --git a/plugins/builtin/source/lang/ja_JP.cpp b/plugins/builtin/source/lang/ja_JP.cpp index 0b0f7ec8c..f15fda981 100644 --- a/plugins/builtin/source/lang/ja_JP.cpp +++ b/plugins/builtin/source/lang/ja_JP.cpp @@ -119,6 +119,21 @@ namespace hex::plugin::builtin { //{ "hex.builtin.popup.error.project.load", "Failed to load project!" }, //{ "hex.builtin.popup.error.project.save", "Failed to save project!" }, //{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" }, + //{ "hex.builtin.popup.error.file_dialog.portal", + // "There was an error while opening the file browser. This might be caused by your system not having a xdg-desktop-portal backend installed correctly.\n" + // "\n" + // "On KDE, it's xdg-desktop-portal-kde.\n" + // "On Gnome it's xdg-desktop-portal-gnome.\n" + // "On wlroots it's xdg-desktop-portal-wlr.\n" + // "Otherwise, you can try to use xdg-desktop-portal-gtk.\n" + // "\n" + // "Reboot your system after installing it.\n" + // "\n" + // "If the file browser still doesn't work after this, submit an issue at https://github.com/WerWolv/ImHex/issues\n" + // "\n" + // "In the meantime files can still be opened by dragging them onto the ImHex window!" + //}, + //{ "hex.builtin.popup.error.file_dialog.common", "An error occurred while opening the file browser!" }, { "hex.builtin.menu.file", "ファイル" }, //{ "hex.builtin.menu.file.create_file", "New File..." }, diff --git a/plugins/builtin/source/lang/ko_KR.cpp b/plugins/builtin/source/lang/ko_KR.cpp index 6872fda47..fe3ada7ec 100644 --- a/plugins/builtin/source/lang/ko_KR.cpp +++ b/plugins/builtin/source/lang/ko_KR.cpp @@ -119,6 +119,21 @@ namespace hex::plugin::builtin { //{ "hex.builtin.popup.error.project.load", "Failed to load project!" }, //{ "hex.builtin.popup.error.project.save", "Failed to save project!" }, //{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" }, + //{ "hex.builtin.popup.error.file_dialog.portal", + // "There was an error while opening the file browser. This might be caused by your system not having a xdg-desktop-portal backend installed correctly.\n" + // "\n" + // "On KDE, it's xdg-desktop-portal-kde.\n" + // "On Gnome it's xdg-desktop-portal-gnome.\n" + // "On wlroots it's xdg-desktop-portal-wlr.\n" + // "Otherwise, you can try to use xdg-desktop-portal-gtk.\n" + // "\n" + // "Reboot your system after installing it.\n" + // "\n" + // "If the file browser still doesn't work after this, submit an issue at https://github.com/WerWolv/ImHex/issues\n" + // "\n" + // "In the meantime files can still be opened by dragging them onto the ImHex window!" + //}, + //{ "hex.builtin.popup.error.file_dialog.common", "An error occurred while opening the file browser!" }, { "hex.builtin.menu.file", "파일" }, { "hex.builtin.menu.file.create_file", "새 파일..." }, diff --git a/plugins/builtin/source/lang/pt_BR.cpp b/plugins/builtin/source/lang/pt_BR.cpp index f8d579dee..045867581 100644 --- a/plugins/builtin/source/lang/pt_BR.cpp +++ b/plugins/builtin/source/lang/pt_BR.cpp @@ -119,6 +119,21 @@ namespace hex::plugin::builtin { //{ "hex.builtin.popup.error.project.load", "Failed to load project!" }, //{ "hex.builtin.popup.error.project.save", "Failed to save project!" }, //{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" }, + //{ "hex.builtin.popup.error.file_dialog.portal", + // "There was an error while opening the file browser. This might be caused by your system not having a xdg-desktop-portal backend installed correctly.\n" + // "\n" + // "On KDE, it's xdg-desktop-portal-kde.\n" + // "On Gnome it's xdg-desktop-portal-gnome.\n" + // "On wlroots it's xdg-desktop-portal-wlr.\n" + // "Otherwise, you can try to use xdg-desktop-portal-gtk.\n" + // "\n" + // "Reboot your system after installing it.\n" + // "\n" + // "If the file browser still doesn't work after this, submit an issue at https://github.com/WerWolv/ImHex/issues\n" + // "\n" + // "In the meantime files can still be opened by dragging them onto the ImHex window!" + //}, + //{ "hex.builtin.popup.error.file_dialog.common", "An error occurred while opening the file browser!" }, { "hex.builtin.menu.file", "File" }, //{ "hex.builtin.menu.file.create_file", "New File..." }, diff --git a/plugins/builtin/source/lang/zh_CN.cpp b/plugins/builtin/source/lang/zh_CN.cpp index d7274f042..db3d52f02 100644 --- a/plugins/builtin/source/lang/zh_CN.cpp +++ b/plugins/builtin/source/lang/zh_CN.cpp @@ -119,6 +119,21 @@ namespace hex::plugin::builtin { //{ "hex.builtin.popup.error.project.load", "Failed to load project!" }, //{ "hex.builtin.popup.error.project.save", "Failed to save project!" }, { "hex.builtin.popup.error.task_exception", "任务 '{}' 异常:\n\n{}" }, + //{ "hex.builtin.popup.error.file_dialog.portal", + // "There was an error while opening the file browser. This might be caused by your system not having a xdg-desktop-portal backend installed correctly.\n" + // "\n" + // "On KDE, it's xdg-desktop-portal-kde.\n" + // "On Gnome it's xdg-desktop-portal-gnome.\n" + // "On wlroots it's xdg-desktop-portal-wlr.\n" + // "Otherwise, you can try to use xdg-desktop-portal-gtk.\n" + // "\n" + // "Reboot your system after installing it.\n" + // "\n" + // "If the file browser still doesn't work after this, submit an issue at https://github.com/WerWolv/ImHex/issues\n" + // "\n" + // "In the meantime files can still be opened by dragging them onto the ImHex window!" + //}, + //{ "hex.builtin.popup.error.file_dialog.common", "An error occurred while opening the file browser!" }, { "hex.builtin.menu.file", "文件" }, { "hex.builtin.menu.file.create_file", "新建文件..." }, diff --git a/plugins/builtin/source/lang/zh_TW.cpp b/plugins/builtin/source/lang/zh_TW.cpp index ceda82022..ad40fe0ca 100644 --- a/plugins/builtin/source/lang/zh_TW.cpp +++ b/plugins/builtin/source/lang/zh_TW.cpp @@ -119,6 +119,21 @@ namespace hex::plugin::builtin { //{ "hex.builtin.popup.error.project.load", "Failed to load project!" }, //{ "hex.builtin.popup.error.project.save", "Failed to save project!" }, //{ "hex.builtin.popup.error.task_exception", "Exception thrown in Task '{}':\n\n{}" }, + //{ "hex.builtin.popup.error.file_dialog.portal", + // "There was an error while opening the file browser. This might be caused by your system not having a xdg-desktop-portal backend installed correctly.\n" + // "\n" + // "On KDE, it's xdg-desktop-portal-kde.\n" + // "On Gnome it's xdg-desktop-portal-gnome.\n" + // "On wlroots it's xdg-desktop-portal-wlr.\n" + // "Otherwise, you can try to use xdg-desktop-portal-gtk.\n" + // "\n" + // "Reboot your system after installing it.\n" + // "\n" + // "If the file browser still doesn't work after this, submit an issue at https://github.com/WerWolv/ImHex/issues\n" + // "\n" + // "In the meantime files can still be opened by dragging them onto the ImHex window!" + //}, + //{ "hex.builtin.popup.error.file_dialog.common", "An error occurred while opening the file browser!" }, { "hex.builtin.menu.file", "檔案" }, //{ "hex.builtin.menu.file.create_file", "New File..." },