ux: Added interface to choose encoding files more easily

This commit is contained in:
WerWolv
2022-01-23 21:52:43 +01:00
parent 9cf7fc4a2e
commit 49610f59ea
10 changed files with 73 additions and 38 deletions

View File

@@ -71,6 +71,11 @@ namespace hex {
static std::list<ImHexApi::Bookmarks::Entry> bookmarkEntries;
static std::vector<pl::PatternData*> patternData;
static u32 selectableFileIndex;
static std::vector<fs::path> selectableFiles;
static std::function<void(fs::path)> selectableFileOpenCallback;
static std::vector<nfdfilteritem_t> selectableFilesValidExtensions;
static std::map<std::string, std::string> languageNames;
static std::map<std::string, std::vector<LanguageDefinition>> languageDefinitions;
static std::map<std::string, std::string> loadedLanguageStrings;

View File

@@ -44,6 +44,8 @@ namespace hex {
static void showErrorPopup(const std::string &errorMessage);
static void showFatalPopup(const std::string &errorMessage);
static void showFileChooserPopup(const std::vector<fs::path> &paths, const std::vector<nfdfilteritem_t> &validExtensions, const std::function<void(fs::path)> &callback);
virtual bool hasViewMenuItemEntry() const;
virtual ImVec2 getMinSize() const;
virtual ImVec2 getMaxSize() const;

View File

@@ -21,6 +21,11 @@ namespace hex {
std::list<ImHexApi::Bookmarks::Entry> SharedData::bookmarkEntries;
std::vector<pl::PatternData*> SharedData::patternData;
u32 SharedData::selectableFileIndex;
std::vector<fs::path> SharedData::selectableFiles;
std::function<void(fs::path)> SharedData::selectableFileOpenCallback;
std::vector<nfdfilteritem_t> SharedData::selectableFilesValidExtensions;
std::map<std::string, std::string> SharedData::languageNames;
std::map<std::string, std::vector<LanguageDefinition>> SharedData::languageDefinitions;
std::map<std::string, std::string> SharedData::loadedLanguageStrings;

View File

@@ -58,6 +58,39 @@ namespace hex {
ImGui::SetWindowPos((SharedData::windowSize - ImGui::GetWindowSize()) / 2, ImGuiCond_Appearing);
ImGui::EndPopup();
}
bool opened = true;
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5F, 0.5F));
if (ImGui::BeginPopupModal("hex.common.choose_file"_lang, &opened, ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::BeginListBox("##files", ImVec2(300_scaled, 0))) {
u32 index = 0;
for (auto &path : SharedData::selectableFiles) {
if (ImGui::Selectable(path.filename().string().c_str(), index == SharedData::selectableFileIndex))
SharedData::selectableFileIndex = index;
index++;
}
ImGui::EndListBox();
}
if (ImGui::Button("hex.common.open"_lang)) {
SharedData::selectableFileOpenCallback(SharedData::selectableFiles[SharedData::selectableFileIndex]);
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button("hex.common.browse"_lang)) {
hex::openFileBrowser("hex.common.open"_lang, DialogMode::Open, SharedData::selectableFilesValidExtensions, [](const auto &path) {
SharedData::selectableFileOpenCallback(path);
ImGui::CloseCurrentPopup();
});
}
ImGui::EndPopup();
}
}
void View::showMessagePopup(const std::string &message) {
@@ -78,6 +111,15 @@ namespace hex {
View::doLater([] { ImGui::OpenPopup("hex.common.fatal"_lang); });
}
void View::showFileChooserPopup(const std::vector<fs::path> &paths, const std::vector<nfdfilteritem_t> &validExtensions, const std::function<void(fs::path)> &callback) {
SharedData::selectableFileIndex = 0;
SharedData::selectableFiles = paths;
SharedData::selectableFilesValidExtensions = validExtensions;
SharedData::selectableFileOpenCallback = callback;
View::doLater([] { ImGui::OpenPopup("hex.common.choose_file"_lang); });
}
bool View::hasViewMenuItemEntry() const {
return true;
}