2021-08-29 14:18:45 +02:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2021-06-07 18:13:54 +02:00
|
|
|
|
2022-05-27 20:42:07 +02:00
|
|
|
#include <hex/ui/view.hpp>
|
2021-08-29 22:15:18 +02:00
|
|
|
#include <hex/helpers/utils.hpp>
|
|
|
|
#include <hex/helpers/fmt.hpp>
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <hex/api/localization.hpp>
|
|
|
|
|
|
|
|
#include <hex/providers/provider.hpp>
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-08-21 00:52:11 +02:00
|
|
|
#include <codicons_font.h>
|
|
|
|
#include <imgui.h>
|
|
|
|
#include <imgui_internal.h>
|
2021-12-31 01:10:06 +01:00
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
2021-08-21 00:52:11 +02:00
|
|
|
|
2021-12-16 23:48:52 +01:00
|
|
|
#include <atomic>
|
|
|
|
|
2021-06-07 18:13:54 +02:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
2022-05-27 20:42:07 +02:00
|
|
|
static void drawGlobalPopups() {
|
|
|
|
|
|
|
|
// "Are you sure you want to exit?" Popup
|
|
|
|
if (ImGui::BeginPopupModal("hex.builtin.popup.exit_application.title"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
|
|
|
ImGui::NewLine();
|
|
|
|
ImGui::TextUnformatted("hex.builtin.popup.exit_application.desc"_lang);
|
|
|
|
ImGui::NewLine();
|
|
|
|
|
|
|
|
View::confirmButtons(
|
|
|
|
"hex.builtin.common.yes"_lang, "hex.builtin.common.no"_lang, [] { ImHexApi::Common::closeImHex(true); }, [] { ImGui::CloseCurrentPopup(); });
|
|
|
|
|
|
|
|
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
|
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void addGlobalUIItems() {
|
|
|
|
EventManager::subscribe<EventFrameEnd>(drawGlobalPopups);
|
|
|
|
}
|
|
|
|
|
2021-06-07 18:13:54 +02:00
|
|
|
void addFooterItems() {
|
|
|
|
|
2021-12-13 22:58:23 +01:00
|
|
|
if (hex::isProcessElevated()) {
|
|
|
|
ContentRegistry::Interface::addFooterItem([] {
|
|
|
|
ImGui::TextUnformatted(ICON_VS_SHIELD);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-07 18:13:54 +02:00
|
|
|
ContentRegistry::Interface::addFooterItem([] {
|
|
|
|
static float framerate = 0;
|
|
|
|
if (ImGui::HasSecondPassed()) {
|
2021-07-27 21:50:49 +02:00
|
|
|
framerate = 1.0F / ImGui::GetIO().DeltaTime;
|
2021-06-07 18:13:54 +02:00
|
|
|
}
|
|
|
|
|
2021-12-31 01:10:06 +01:00
|
|
|
ImGui::TextFormatted("FPS {0:2}.{1:02}", u32(framerate), u32(framerate * 100) % 100);
|
2021-12-16 23:48:52 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
ContentRegistry::Interface::addFooterItem([] {
|
2022-02-01 22:09:44 +01:00
|
|
|
size_t taskCount = 0;
|
2021-12-16 23:48:52 +01:00
|
|
|
double taskProgress = 0.0;
|
|
|
|
std::string taskName;
|
|
|
|
|
|
|
|
{
|
2022-02-01 18:09:40 +01:00
|
|
|
std::scoped_lock lock(Task::getTaskMutex());
|
2021-12-16 23:48:52 +01:00
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
taskCount = Task::getRunningTasks().size();
|
2021-12-16 23:48:52 +01:00
|
|
|
if (taskCount > 0) {
|
2022-02-01 18:09:40 +01:00
|
|
|
auto frontTask = Task::getRunningTasks().front();
|
2022-02-01 22:09:44 +01:00
|
|
|
taskProgress = frontTask->getProgress();
|
|
|
|
taskName = frontTask->getName();
|
2021-12-16 23:48:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (taskCount > 0) {
|
|
|
|
if (taskCount > 0)
|
|
|
|
ImGui::TextSpinner(hex::format("({})", taskCount).c_str());
|
|
|
|
else
|
|
|
|
ImGui::TextSpinner("");
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
2022-01-11 23:48:18 +01:00
|
|
|
ImGui::SmallProgressBar(taskProgress, (ImGui::GetCurrentWindow()->MenuBarHeight() - 10_scaled) / 2.0);
|
2021-12-16 23:48:52 +01:00
|
|
|
ImGui::InfoTooltip(taskName.c_str());
|
|
|
|
}
|
2021-06-07 18:13:54 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-21 00:52:11 +02:00
|
|
|
void addToolbarItems() {
|
|
|
|
ContentRegistry::Interface::addToolbarItem([] {
|
2022-03-13 17:46:59 +01:00
|
|
|
auto provider = ImHexApi::Provider::get();
|
|
|
|
bool providerValid = provider != nullptr;
|
2021-08-21 13:53:50 +02:00
|
|
|
|
|
|
|
// Undo
|
2022-05-27 20:42:07 +02:00
|
|
|
ImGui::BeginDisabled(!providerValid || !provider->canUndo());
|
|
|
|
{
|
2021-10-07 11:34:46 +02:00
|
|
|
if (ImGui::ToolBarButton(ICON_VS_DISCARD, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarBlue)))
|
2021-08-21 13:53:50 +02:00
|
|
|
provider->undo();
|
2022-05-27 20:42:07 +02:00
|
|
|
}
|
|
|
|
ImGui::EndDisabled();
|
2021-08-21 13:53:50 +02:00
|
|
|
|
|
|
|
// Redo
|
2022-05-27 20:42:07 +02:00
|
|
|
ImGui::BeginDisabled(!providerValid || !provider->canRedo());
|
|
|
|
{
|
2021-10-07 11:34:46 +02:00
|
|
|
if (ImGui::ToolBarButton(ICON_VS_REDO, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarBlue)))
|
2021-08-21 13:53:50 +02:00
|
|
|
provider->redo();
|
2022-05-27 20:42:07 +02:00
|
|
|
}
|
|
|
|
ImGui::EndDisabled();
|
2021-08-21 00:52:11 +02:00
|
|
|
|
|
|
|
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
|
|
|
|
2021-08-21 13:53:50 +02:00
|
|
|
// Create new file
|
2021-10-07 11:34:46 +02:00
|
|
|
if (ImGui::ToolBarButton(ICON_VS_FILE, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarGray)))
|
2021-08-21 13:53:50 +02:00
|
|
|
EventManager::post<RequestOpenWindow>("Create File");
|
|
|
|
|
|
|
|
// Open file
|
2021-10-07 11:34:46 +02:00
|
|
|
if (ImGui::ToolBarButton(ICON_VS_FOLDER_OPENED, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarBrown)))
|
2021-08-21 13:53:50 +02:00
|
|
|
EventManager::post<RequestOpenWindow>("Open File");
|
|
|
|
|
2021-08-21 00:52:11 +02:00
|
|
|
|
|
|
|
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
|
|
|
|
2021-08-21 13:53:50 +02:00
|
|
|
// Save file
|
2022-05-27 20:42:07 +02:00
|
|
|
ImGui::BeginDisabled(!providerValid || !provider->isWritable() || !provider->isSavable());
|
|
|
|
{
|
2021-10-07 11:34:46 +02:00
|
|
|
if (ImGui::ToolBarButton(ICON_VS_SAVE, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarBlue)))
|
2021-08-21 13:53:50 +02:00
|
|
|
provider->save();
|
2022-05-27 20:42:07 +02:00
|
|
|
}
|
|
|
|
ImGui::EndDisabled();
|
2021-08-21 13:53:50 +02:00
|
|
|
|
|
|
|
// Save file as
|
2022-05-27 20:42:07 +02:00
|
|
|
ImGui::BeginDisabled(!providerValid || !provider->isSavable());
|
|
|
|
{
|
2021-10-07 11:34:46 +02:00
|
|
|
if (ImGui::ToolBarButton(ICON_VS_SAVE_AS, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarBlue)))
|
2022-03-27 00:01:28 +01:00
|
|
|
fs::openFileBrowser(fs::DialogMode::Save, {}, [&provider](auto path) {
|
2021-08-21 13:53:50 +02:00
|
|
|
provider->saveAs(path);
|
|
|
|
});
|
2022-05-27 20:42:07 +02:00
|
|
|
}
|
|
|
|
ImGui::EndDisabled();
|
2021-08-21 13:53:50 +02:00
|
|
|
|
2021-08-21 00:52:11 +02:00
|
|
|
|
|
|
|
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
|
|
|
|
2021-08-21 13:53:50 +02:00
|
|
|
|
|
|
|
// Create bookmark
|
2022-05-27 20:42:07 +02:00
|
|
|
ImGui::BeginDisabled(!providerValid || !provider->isReadable() || !ImHexApi::HexEditor::isSelectionValid());
|
|
|
|
{
|
2021-10-07 11:34:46 +02:00
|
|
|
if (ImGui::ToolBarButton(ICON_VS_BOOKMARK, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarGreen))) {
|
2022-05-27 20:42:07 +02:00
|
|
|
auto region = ImHexApi::HexEditor::getSelection();
|
2021-08-21 13:53:50 +02:00
|
|
|
|
2022-05-27 20:42:07 +02:00
|
|
|
if (region.has_value())
|
|
|
|
ImHexApi::Bookmarks::add(region->address, region->size, {}, {});
|
2021-08-21 13:53:50 +02:00
|
|
|
}
|
2022-05-27 20:42:07 +02:00
|
|
|
}
|
|
|
|
ImGui::EndDisabled();
|
2021-09-21 02:29:54 +02:00
|
|
|
|
|
|
|
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
|
|
|
ImGui::Spacing();
|
|
|
|
|
|
|
|
// Provider switcher
|
2022-05-27 20:42:07 +02:00
|
|
|
ImGui::BeginDisabled(!providerValid);
|
|
|
|
{
|
2021-09-21 02:29:54 +02:00
|
|
|
auto &providers = ImHexApi::Provider::getProviders();
|
|
|
|
|
|
|
|
std::string preview;
|
|
|
|
if (ImHexApi::Provider::isValid())
|
2022-02-01 18:09:40 +01:00
|
|
|
preview = ImHexApi::Provider::get()->getName();
|
2021-09-21 02:29:54 +02:00
|
|
|
|
2022-01-11 23:48:18 +01:00
|
|
|
ImGui::SetNextItemWidth(200_scaled);
|
2021-09-21 02:29:54 +02:00
|
|
|
if (ImGui::BeginCombo("", preview.c_str())) {
|
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
for (size_t i = 0; i < providers.size(); i++) {
|
2021-09-21 02:29:54 +02:00
|
|
|
if (ImGui::Selectable(providers[i]->getName().c_str())) {
|
2022-02-01 18:09:40 +01:00
|
|
|
ImHexApi::Provider::setCurrentProvider(i);
|
2021-09-21 02:29:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndCombo();
|
|
|
|
}
|
2022-05-27 20:42:07 +02:00
|
|
|
}
|
|
|
|
ImGui::EndDisabled();
|
2021-08-21 00:52:11 +02:00
|
|
|
});
|
2022-05-27 20:42:07 +02:00
|
|
|
|
2021-08-21 00:52:11 +02:00
|
|
|
}
|
|
|
|
|
2021-06-07 18:13:54 +02:00
|
|
|
}
|