feat: Added workspaces

This commit is contained in:
WerWolv
2023-12-11 15:54:22 +01:00
parent cc4d61f8f5
commit 91230ba438
30 changed files with 273 additions and 67 deletions

View File

@@ -8,7 +8,7 @@ namespace hex::plugin::builtin {
void extractBundledFiles() {
for (const auto &romfsPath : romfs::list("auto_extract")) {
for (const auto &imhexPath : fs::getDataPaths()) {
wolv::io::File file(imhexPath, wolv::io::File::Mode::Create);
wolv::io::File file(imhexPath / std::fs::relative(romfsPath, "auto_extract"), wolv::io::File::Mode::Create);
if (!file.isValid())
continue;

View File

@@ -16,6 +16,7 @@
#include <content/global_actions.hpp>
#include <content/popups/popup_notification.hpp>
#include <content/popups/popup_text_input.hpp>
#include <hex/api/workspace_manager.hpp>
#include <wolv/io/file.hpp>
@@ -540,28 +541,28 @@ namespace hex::plugin::builtin {
static void createLayoutMenu() {
LayoutManager::reload();
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.layout", 4000);
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.workspace", 4000);
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.layout", "hex.builtin.menu.layout.save" }, 1100, Shortcut::None, [] {
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.workspace", "hex.builtin.menu.workspace.layout", "hex.builtin.menu.workspace.layout.save" }, 1100, Shortcut::None, [] {
PopupTextInput::open("hex.builtin.popup.save_layout.title"_lang, "hex.builtin.popup.save_layout.desc"_lang, [](const std::string &name) {
LayoutManager::save(name);
});
}, ImHexApi::Provider::isValid);
ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.layout" }, 1150, [] {
ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.workspace", "hex.builtin.menu.workspace.layout" }, 1150, [] {
bool locked = LayoutManager::isLayoutLocked();
if (ImGui::MenuItem("hex.builtin.menu.layout.lock"_lang, nullptr, &locked, ImHexApi::Provider::isValid())) {
if (ImGui::MenuItem("hex.builtin.menu.workspace.layout.lock"_lang, nullptr, &locked, ImHexApi::Provider::isValid())) {
LayoutManager::lockLayout(locked);
ContentRegistry::Settings::write("hex.builtin.setting.interface", "hex.builtin.setting.interface.layout_locked", locked);
}
});
ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.layout" }, 1200);
ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.workspace", "hex.builtin.menu.workspace.layout" }, 1200);
ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.layout" }, 2000, [] {
ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.workspace", "hex.builtin.menu.workspace.layout" }, 2000, [] {
for (const auto &path : romfs::list("layouts")) {
if (ImGui::MenuItem(wolv::util::capitalizeString(path.stem().string()).c_str(), "", false, ImHexApi::Provider::isValid())) {
LayoutManager::loadString(std::string(romfs::get(path).string()));
LayoutManager::loadFromString(std::string(romfs::get(path).string()));
}
}
@@ -579,6 +580,29 @@ namespace hex::plugin::builtin {
});
}
static void createWorkspaceMenu() {
createLayoutMenu();
ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.workspace" }, 3000);
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.workspace", "hex.builtin.menu.workspace.create" }, 3100, Shortcut::None, [] {
PopupTextInput::open("hex.builtin.popup.create_workspace.title"_lang, "hex.builtin.popup.create_workspace.desc"_lang, [](const std::string &name) {
WorkspaceManager::createWorkspace(name);
});
}, ImHexApi::Provider::isValid);
ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.workspace" }, 3200, [] {
const auto &workspaces = WorkspaceManager::getWorkspaces();
for (auto it = workspaces.begin(); it != workspaces.end(); ++it) {
const auto &[name, workspace] = *it;
if (ImGui::MenuItem(name.c_str(), "", it == WorkspaceManager::getCurrentWorkspace(), ImHexApi::Provider::isValid())) {
WorkspaceManager::switchWorkspace(name);
}
}
});
}
static void createExtrasMenu() {
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.extras", 5000);
}
@@ -592,7 +616,7 @@ namespace hex::plugin::builtin {
createFileMenu();
createEditMenu();
createViewMenu();
createLayoutMenu();
createWorkspaceMenu();
createExtrasMenu();
createHelpMenu();

View File

@@ -30,6 +30,7 @@
#include <string>
#include <random>
#include <hex/api/workspace_manager.hpp>
namespace hex::plugin::builtin {
@@ -136,7 +137,7 @@ namespace hex::plugin::builtin {
};
void loadDefaultLayout() {
LayoutManager::loadString(std::string(romfs::get("layouts/default.hexlyt").string()));
LayoutManager::loadFromString(std::string(romfs::get("layouts/default.hexlyt").string()));
}
bool isAnyViewOpen() {
@@ -402,8 +403,10 @@ namespace hex::plugin::builtin {
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg));
ImGuiExt::BeginSubWindow("hex.builtin.welcome.header.quick_settings"_lang, windowSize);
{
if (ImGuiExt::ToggleSwitch("hex.builtin.welcome.quick_settings.simplified"_lang, &s_simplifiedWelcomeScreen))
if (ImGuiExt::ToggleSwitch("hex.builtin.welcome.quick_settings.simplified"_lang, &s_simplifiedWelcomeScreen)) {
ContentRegistry::Settings::write("hex.builtin.setting.interface", "hex.builtin.setting.interface.simplified_welcome_screen", s_simplifiedWelcomeScreen);
WorkspaceManager::switchWorkspace(s_simplifiedWelcomeScreen ? "Minimal" : "Default");
}
}
ImGuiExt::EndSubWindow();
ImGui::PopStyleColor();

View File

@@ -0,0 +1,27 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/workspace_manager.hpp>
#include <hex/helpers/fs.hpp>
#include <wolv/utils/guards.hpp>
namespace hex::plugin::builtin {
void loadWorkspaces() {
for (const auto &defaultPath : fs::getDefaultPaths(fs::ImHexPath::Workspaces)) {
for (const auto &entry : std::fs::directory_iterator(defaultPath)) {
if (!entry.is_regular_file())
continue;
const auto &path = entry.path();
if (path.extension() != ".hexws")
continue;
WorkspaceManager::importFromFile(path);
}
}
std::string currentWorkspace = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.curr_workspace", "Default");
WorkspaceManager::switchWorkspace(currentWorkspace);
}
}