1
0
mirror of synced 2024-11-12 10:10:53 +01:00

sys: Copy pattern source code from current provider to newly created one

This commit is contained in:
WerWolv 2022-07-31 11:09:20 +02:00
parent 623756c4f4
commit 4d3538781b
3 changed files with 8 additions and 9 deletions

View File

@ -245,9 +245,9 @@ namespace hex {
return;
s_providers.push_back(provider);
setCurrentProvider(s_providers.size() - 1);
EventManager::post<EventProviderCreated>(provider);
setCurrentProvider(s_providers.size() - 1);
}
void remove(prv::Provider *provider) {

View File

@ -307,7 +307,7 @@ namespace hex::plugin::builtin {
ImGui::PushStyleColor(ImGuiCol_TabActive, ImGui::GetColorU32(ImGuiCol_MenuBarBg));
ImGui::PushStyleColor(ImGuiCol_TabUnfocusedActive, ImGui::GetColorU32(ImGuiCol_MenuBarBg));
auto providerSelectorVisible = ImGui::BeginTabBar("provider_switcher", ImGuiTabBarFlags_FittingPolicyScroll | ImGuiTabBarFlags_Reorderable);
auto providerSelectorVisible = ImGui::BeginTabBar("provider_switcher", ImGuiTabBarFlags_FittingPolicyScroll | ImGuiTabBarFlags_Reorderable | ImGuiTabBarFlags_AutoSelectNewTabs);
ImGui::PopStyleColor(2);
if (providerSelectorVisible) {

View File

@ -96,16 +96,15 @@ namespace hex::plugin::builtin {
this->m_textEditor.SetText(code);
});
EventManager::subscribe<EventFileLoaded>(this, [this](const std::fs::path &path) {
hex::unused(path);
EventManager::subscribe<EventProviderCreated>(this, [this](prv::Provider *provider) {
if (!ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.auto_load_patterns", 1))
return;
if (!ImHexApi::Provider::isValid())
return;
// Copy over current pattern source code to the new provider
{
provider->getPatternLanguageSourceCode() = this->m_textEditor.GetText();
}
auto provider = ImHexApi::Provider::get();
auto &runtime = provider->getPatternLanguageRuntime();
auto mimeType = magic::getMIMEType(ImHexApi::Provider::get());