1
0
mirror of synced 2024-12-01 02:37:18 +01:00

Allow most modal popups to be closed with escape

This commit is contained in:
WerWolv 2021-01-14 17:01:44 +01:00
parent 441f4a9fc7
commit 740619529c
6 changed files with 44 additions and 17 deletions

View File

@ -25,7 +25,7 @@ namespace hex {
}
void View::drawCommonInterfaces() {
if (ImGui::BeginPopupModal("Error", nullptr, ImGuiWindowFlags_NoResize)) {
if (ImGui::BeginPopupModal("Error", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::NewLine();
if (ImGui::BeginChild("##scrolling", ImVec2(300, 100))) {
ImGui::SetCursorPosX((300 - ImGui::CalcTextSize(SharedData::errorPopupMessage.c_str(), nullptr, false).x) / 2.0F);
@ -34,7 +34,7 @@ namespace hex {
}
ImGui::NewLine();
ImGui::SetCursorPosX(75);
if (ImGui::Button("Okay", ImVec2(150, 20)))
if (ImGui::Button("Okay", ImVec2(150, 20)) || ImGui::IsKeyDown(ImGuiKey_Escape))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}

View File

@ -10,13 +10,15 @@ namespace hex {
ViewBookmarks::ViewBookmarks(std::list<Bookmark> &bookmarks) : View("Bookmarks"), m_bookmarks(bookmarks) {
View::subscribeEvent(Events::AddBookmark, [this](const void *userData) {
Bookmark bookmark = *reinterpret_cast<const Bookmark*>(userData);
bookmark.name.resize(64);
bookmark.comment.resize(0xF'FFFF);
if (bookmark.name.empty()) {
bookmark.name.resize(64);
std::memset(bookmark.name.data(), 0x00, 64);
std::strcpy(bookmark.name.data(), hex::format("Bookmark [0x%lX - 0x%lX]",
bookmark.region.address,
bookmark.region.address + bookmark.region.size - 1).c_str());
}
if (bookmark.comment.empty())
std::memset(bookmark.comment.data(), 0x00, 0xF'FFFF);

View File

@ -14,7 +14,7 @@ namespace hex {
ContentRegistry::CommandPaletteCommands::add(
ContentRegistry::CommandPaletteCommands::Type::SymbolCommand,
"#", "Calculator",
[](std::string input) {
[](auto input) {
MathEvaluator evaluator;
evaluator.registerStandardVariables();
evaluator.registerStandardFunctions();
@ -31,6 +31,18 @@ namespace hex {
return hex::format("#%s = ???", input.data());
});
ContentRegistry::CommandPaletteCommands::add(
ContentRegistry::CommandPaletteCommands::Type::KeywordCommand,
"/bm", "Create Bookmark",
[](auto input) {
Bookmark bookmark;
bookmark.name.resize(64);
std::strncpy(bookmark.name.data(), input.c_str(), bookmark.name.size());
View::postEvent(Events::AddBookmark, &bookmark);
return "";
});
this->m_lastResults = this->getCommandResults("");
}

View File

@ -56,6 +56,10 @@ namespace hex {
ImGui::BulletText("FreeType");
ImGui::PopStyleColor();
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
}

View File

@ -192,6 +192,10 @@ namespace hex {
ImGui::NewLine();
confirmButtons("Yes", "No", [] { std::exit(0); }, [] { ImGui::CloseCurrentPopup(); });
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
@ -210,6 +214,8 @@ namespace hex {
if (ImGui::Button("File"))
ImGui::OpenPopup("Loader Script: Open File");
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
ImGui::CloseCurrentPopup();
if (this->m_fileBrowser.showFileDialog("Loader Script: Open Script", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2(0, 0), ".py")) {
this->m_loaderScriptScriptPath = this->m_fileBrowser.selected_path;
@ -243,13 +249,15 @@ namespace hex {
ImGui::InputText("Address", this->m_baseAddressBuffer, 16, ImGuiInputTextFlags_CharsHexadecimal);
ImGui::NewLine();
if (ImGui::Button("Set")) {
confirmButtons("Set", "Cancel",
[this, &provider]{
provider->setBaseAddress(strtoull(this->m_baseAddressBuffer, nullptr, 16));
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
}, []{
ImGui::CloseCurrentPopup();
});
if (ImGui::Button("Cancel"))
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();

View File

@ -279,14 +279,15 @@ namespace hex {
ImGui::Text("Do you want to load it?");
ImGui::NewLine();
if (ImGui::Button("Yes", ImVec2(40, 20))) {
confirmButtons("Yes", "No", [this]{
this->loadPatternFile(this->m_possiblePatternFile.string());
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button("No", ImVec2(40, 20))) {
}, []{
ImGui::CloseCurrentPopup();
});
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}