ui/ux: Give up on custom ImGui file browsers and just use the system one

This commit is contained in:
WerWolv
2021-02-22 23:36:13 +01:00
parent 7f97416e6e
commit 0af8b8155f
15 changed files with 53 additions and 2545 deletions

View File

@@ -28,15 +28,30 @@ namespace hex {
return EventManager::post(eventType, userData);
}
void View::openFileBrowser(std::string title, imgui_addons::ImGuiFileBrowser::DialogMode mode, std::string validExtensions, const std::function<void(std::string)> &callback) {
SharedData::fileBrowserTitle = title;
SharedData::fileBrowserDialogMode = mode;
SharedData::fileBrowserValidExtensions = std::move(validExtensions);
SharedData::fileBrowserCallback = callback;
void View::openFileBrowser(std::string_view title, DialogMode mode, const std::vector<nfdfilteritem_t> &validExtensions, const std::function<void(std::string)> &callback) {
NFD::Init();
View::doLater([title]{
ImGui::OpenPopup(title.c_str());
});
nfdchar_t *outPath;
nfdresult_t result;
switch (mode) {
case DialogMode::Open:
result = NFD::OpenDialog(outPath, validExtensions.data(), validExtensions.size(), nullptr);
break;
case DialogMode::Save:
result = NFD::SaveDialog(outPath, validExtensions.data(), validExtensions.size(), nullptr);
break;
case DialogMode::Folder:
result = NFD::PickFolder(outPath, nullptr);
break;
default: __builtin_unreachable();
}
if (result == NFD_OKAY) {
callback(outPath);
NFD::FreePath(outPath);
}
NFD::Quit();
}
void View::drawCommonInterfaces() {
@@ -49,11 +64,6 @@ namespace hex {
ImGui::EndPopup();
}
if (SharedData::fileBrowser.showFileDialog(SharedData::fileBrowserTitle, SharedData::fileBrowserDialogMode, ImVec2(0, 0), SharedData::fileBrowserValidExtensions)) {
SharedData::fileBrowserCallback(SharedData::fileBrowser.selected_path);
SharedData::fileBrowserTitle = "";
}
}
void View::showErrorPopup(std::string_view errorMessage) {