ux: Display an error message if file picker can't be opened (#748)
* add error message for the file picker * set a different message for Windows/MacOS * fix typos * Moved file dialog error handling to a callback function Co-authored-by: Nik <werwolv98@gmail.com>
This commit is contained in:
parent
9656b40d53
commit
3a94be9abb
@ -75,17 +75,16 @@ namespace hex::fs {
|
|||||||
|
|
||||||
std::fs::path toShortPath(const std::fs::path &path);
|
std::fs::path toShortPath(const std::fs::path &path);
|
||||||
|
|
||||||
enum class DialogMode
|
enum class DialogMode {
|
||||||
{
|
|
||||||
Open,
|
Open,
|
||||||
Save,
|
Save,
|
||||||
Folder
|
Folder
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void setFileBrowserErrorCallback(const std::function<void()> &callback);
|
||||||
bool openFileBrowser(DialogMode mode, const std::vector<nfdfilteritem_t> &validExtensions, const std::function<void(std::fs::path)> &callback, const std::string &defaultPath = {});
|
bool openFileBrowser(DialogMode mode, const std::vector<nfdfilteritem_t> &validExtensions, const std::function<void(std::fs::path)> &callback, const std::string &defaultPath = {});
|
||||||
|
|
||||||
enum class ImHexPath
|
enum class ImHexPath {
|
||||||
{
|
|
||||||
Patterns,
|
Patterns,
|
||||||
PatternsInclude,
|
PatternsInclude,
|
||||||
Magic,
|
Magic,
|
||||||
|
@ -75,6 +75,11 @@ namespace hex::fs {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::function<void()> s_fileBrowserErrorCallback;
|
||||||
|
void setFileBrowserErrorCallback(const std::function<void()> &callback) {
|
||||||
|
s_fileBrowserErrorCallback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
bool openFileBrowser(DialogMode mode, const std::vector<nfdfilteritem_t> &validExtensions, const std::function<void(std::fs::path)> &callback, const std::string &defaultPath) {
|
bool openFileBrowser(DialogMode mode, const std::vector<nfdfilteritem_t> &validExtensions, const std::function<void(std::fs::path)> &callback, const std::string &defaultPath) {
|
||||||
NFD::Init();
|
NFD::Init();
|
||||||
|
|
||||||
@ -94,10 +99,15 @@ namespace hex::fs {
|
|||||||
hex::unreachable();
|
hex::unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == NFD_OKAY && outPath != nullptr) {
|
if (result == NFD_OKAY){
|
||||||
|
if(outPath != nullptr) {
|
||||||
callback(reinterpret_cast<char8_t*>(outPath));
|
callback(reinterpret_cast<char8_t*>(outPath));
|
||||||
NFD::FreePath(outPath);
|
NFD::FreePath(outPath);
|
||||||
}
|
}
|
||||||
|
} else if (result==NFD_ERROR) {
|
||||||
|
if (s_fileBrowserErrorCallback != nullptr)
|
||||||
|
s_fileBrowserErrorCallback();
|
||||||
|
}
|
||||||
|
|
||||||
NFD::Quit();
|
NFD::Quit();
|
||||||
|
|
||||||
|
@ -123,6 +123,14 @@ namespace hex::plugin::builtin {
|
|||||||
ProviderExtraData::erase(provider);
|
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
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -119,6 +119,21 @@ namespace hex::plugin::builtin {
|
|||||||
{ "hex.builtin.popup.error.project.save", "Speichern des Projektes fehlgeschlagen!!" },
|
{ "hex.builtin.popup.error.project.save", "Speichern des Projektes fehlgeschlagen!!" },
|
||||||
{ "hex.builtin.popup.error.create", "Erstellen der neuen Datei 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.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.menu.file", "Datei" },
|
||||||
{ "hex.builtin.file.open_file", "Datei öffnen..." },
|
{ "hex.builtin.file.open_file", "Datei öffnen..." },
|
||||||
|
@ -120,6 +120,21 @@ namespace hex::plugin::builtin {
|
|||||||
{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
||||||
{ "hex.builtin.popup.error.project.save", "Failed to save 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.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", "File" },
|
||||||
{ "hex.builtin.menu.file.create_file", "New File..." },
|
{ "hex.builtin.menu.file.create_file", "New File..." },
|
||||||
|
@ -119,6 +119,21 @@ namespace hex::plugin::builtin {
|
|||||||
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
||||||
//{ "hex.builtin.popup.error.project.save", "Failed to save 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.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", "File" },
|
||||||
//{ "hex.builtin.menu.file.create_file", "New File..." },
|
//{ "hex.builtin.menu.file.create_file", "New File..." },
|
||||||
|
@ -119,6 +119,21 @@ namespace hex::plugin::builtin {
|
|||||||
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
||||||
//{ "hex.builtin.popup.error.project.save", "Failed to save 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.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", "ファイル" },
|
||||||
//{ "hex.builtin.menu.file.create_file", "New File..." },
|
//{ "hex.builtin.menu.file.create_file", "New File..." },
|
||||||
|
@ -119,6 +119,21 @@ namespace hex::plugin::builtin {
|
|||||||
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
||||||
//{ "hex.builtin.popup.error.project.save", "Failed to save 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.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", "파일" },
|
||||||
{ "hex.builtin.menu.file.create_file", "새 파일..." },
|
{ "hex.builtin.menu.file.create_file", "새 파일..." },
|
||||||
|
@ -119,6 +119,21 @@ namespace hex::plugin::builtin {
|
|||||||
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
||||||
//{ "hex.builtin.popup.error.project.save", "Failed to save 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.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", "File" },
|
||||||
//{ "hex.builtin.menu.file.create_file", "New File..." },
|
//{ "hex.builtin.menu.file.create_file", "New File..." },
|
||||||
|
@ -119,6 +119,21 @@ namespace hex::plugin::builtin {
|
|||||||
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
||||||
//{ "hex.builtin.popup.error.project.save", "Failed to save project!" },
|
//{ "hex.builtin.popup.error.project.save", "Failed to save project!" },
|
||||||
{ "hex.builtin.popup.error.task_exception", "任务 '{}' 异常:\n\n{}" },
|
{ "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", "文件" },
|
||||||
{ "hex.builtin.menu.file.create_file", "新建文件..." },
|
{ "hex.builtin.menu.file.create_file", "新建文件..." },
|
||||||
|
@ -119,6 +119,21 @@ namespace hex::plugin::builtin {
|
|||||||
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
//{ "hex.builtin.popup.error.project.load", "Failed to load project!" },
|
||||||
//{ "hex.builtin.popup.error.project.save", "Failed to save 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.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", "檔案" },
|
||||||
//{ "hex.builtin.menu.file.create_file", "New File..." },
|
//{ "hex.builtin.menu.file.create_file", "New File..." },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user