From cdd5d33e898ff8d7b18ddc359f48ef7f61c78ee0 Mon Sep 17 00:00:00 2001 From: qux-bbb <1147635419@qq.com> Date: Tue, 7 Mar 2023 23:05:03 +0800 Subject: [PATCH] feat: Make CTRL + N automatically create a memory provider (#966) "CTRL + N" can open a mem_file directly. --- plugins/builtin/source/content/events.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/plugins/builtin/source/content/events.cpp b/plugins/builtin/source/content/events.cpp index 6e6fe4c2d..85a989027 100644 --- a/plugins/builtin/source/content/events.cpp +++ b/plugins/builtin/source/content/events.cpp @@ -65,18 +65,11 @@ namespace hex::plugin::builtin { EventManager::subscribe([](const std::string &name) { if (name == "Create File") { - fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) { - fs::File file(path, fs::File::Mode::Create); - - if (!file.isValid()) { - View::showErrorPopup("hex.builtin.popup.error.create"_lang); - return; - } - - file.setSize(1); - - EventManager::post(path); - }); + auto newProvider = hex::ImHexApi::Provider::createProvider("hex.builtin.provider.mem_file", true); + if (newProvider != nullptr && !newProvider->open()) + hex::ImHexApi::Provider::remove(newProvider); + else + EventManager::post(newProvider); } else if (name == "Open File") { ImHexApi::Provider::createProvider("hex.builtin.provider.file"); } else if (name == "Open Project") { @@ -141,4 +134,4 @@ namespace hex::plugin::builtin { } -} \ No newline at end of file +}