mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-01 21:17:44 -05:00
Make File Dialogs less hacky
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
#include <hex/views/view.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <ImGuiFileBrowser.h>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace hex { class SharedData; }
|
||||
@@ -59,6 +61,12 @@ namespace hex {
|
||||
static std::string errorPopupMessage;
|
||||
static std::list<ImHexApi::Bookmarks::Entry> bookmarkEntries;
|
||||
|
||||
static imgui_addons::ImGuiFileBrowser fileBrowser;
|
||||
static imgui_addons::ImGuiFileBrowser::DialogMode fileBrowserDialogMode;
|
||||
static std::string fileBrowserTitle;
|
||||
static std::string fileBrowserValidExtensions;
|
||||
static std::function<void(std::string)> fileBrowserCallback;
|
||||
|
||||
static int mainArgc;
|
||||
static char **mainArgv;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <hex.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <ImGuiFileBrowser.h>
|
||||
|
||||
#include <hex/api/event.hpp>
|
||||
|
||||
@@ -22,6 +23,7 @@ namespace hex {
|
||||
virtual void drawMenu();
|
||||
virtual bool handleShortcut(int key, int mods);
|
||||
|
||||
static void openFileBrowser(std::string title, imgui_addons::ImGuiFileBrowser::DialogMode mode, std::string validExtensions, const std::function<void(std::string)> &callback);
|
||||
static void doLater(std::function<void()> &&function);
|
||||
static std::vector<std::function<void()>>& getDeferedCalls();
|
||||
|
||||
|
||||
@@ -18,6 +18,12 @@ namespace hex {
|
||||
std::string SharedData::errorPopupMessage;
|
||||
std::list<ImHexApi::Bookmarks::Entry> SharedData::bookmarkEntries;
|
||||
|
||||
imgui_addons::ImGuiFileBrowser SharedData::fileBrowser;
|
||||
imgui_addons::ImGuiFileBrowser::DialogMode SharedData::fileBrowserDialogMode;
|
||||
std::string SharedData::fileBrowserTitle;
|
||||
std::string SharedData::fileBrowserValidExtensions;
|
||||
std::function<void(std::string)> SharedData::fileBrowserCallback;
|
||||
|
||||
int SharedData::mainArgc;
|
||||
char **SharedData::mainArgv;
|
||||
|
||||
|
||||
@@ -24,6 +24,17 @@ 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;
|
||||
|
||||
View::doLater([title]{
|
||||
ImGui::OpenPopup(title.c_str());
|
||||
});
|
||||
}
|
||||
|
||||
void View::drawCommonInterfaces() {
|
||||
if (ImGui::BeginPopupModal("Error", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||
ImGui::NewLine();
|
||||
@@ -38,6 +49,11 @@ namespace hex {
|
||||
ImGui::CloseCurrentPopup();
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user