sys: Added setting to synchronize pattern source code between providers
This commit is contained in:
parent
df94370598
commit
763f15fa36
@ -24,6 +24,40 @@ namespace hex::plugin::builtin {
|
||||
void drawAlwaysVisible() override;
|
||||
void drawContent() override;
|
||||
|
||||
private:
|
||||
struct PatternVariable {
|
||||
bool inVariable;
|
||||
bool outVariable;
|
||||
|
||||
pl::Token::ValueType type;
|
||||
pl::Token::Literal value;
|
||||
};
|
||||
|
||||
enum class EnvVarType
|
||||
{
|
||||
Integer,
|
||||
Float,
|
||||
String,
|
||||
Bool
|
||||
};
|
||||
|
||||
struct EnvVar {
|
||||
u64 id;
|
||||
std::string name;
|
||||
pl::Token::Literal value;
|
||||
EnvVarType type;
|
||||
|
||||
bool operator==(const EnvVar &other) const {
|
||||
return this->id == other.id;
|
||||
}
|
||||
};
|
||||
|
||||
enum class DangerousFunctionPerms : u8 {
|
||||
Ask,
|
||||
Allow,
|
||||
Deny
|
||||
};
|
||||
|
||||
private:
|
||||
std::unique_ptr<pl::PatternLanguage> m_parserRuntime;
|
||||
|
||||
@ -47,47 +81,18 @@ namespace hex::plugin::builtin {
|
||||
TextEditor m_textEditor;
|
||||
std::vector<std::pair<pl::LogConsole::Level, std::string>> m_console;
|
||||
|
||||
struct PatternVariable {
|
||||
bool inVariable;
|
||||
bool outVariable;
|
||||
|
||||
pl::Token::ValueType type;
|
||||
pl::Token::Literal value;
|
||||
};
|
||||
|
||||
std::map<std::string, PatternVariable> m_patternVariables;
|
||||
|
||||
enum class EnvVarType
|
||||
{
|
||||
Integer,
|
||||
Float,
|
||||
String,
|
||||
Bool
|
||||
};
|
||||
|
||||
struct EnvVar {
|
||||
u64 id;
|
||||
std::string name;
|
||||
pl::Token::Literal value;
|
||||
EnvVarType type;
|
||||
|
||||
bool operator==(const EnvVar &other) const {
|
||||
return this->id == other.id;
|
||||
}
|
||||
};
|
||||
|
||||
u64 m_envVarIdCounter;
|
||||
std::list<EnvVar> m_envVarEntries;
|
||||
|
||||
enum class DangerousFunctionPerms : u8 {
|
||||
Ask,
|
||||
Allow,
|
||||
Deny
|
||||
};
|
||||
|
||||
std::atomic<bool> m_dangerousFunctionCalled = false;
|
||||
std::atomic<DangerousFunctionPerms> m_dangerousFunctionsAllowed = DangerousFunctionPerms::Ask;
|
||||
|
||||
bool m_syncPatternSourceCode = false;
|
||||
bool m_autoLoadPatterns = true;
|
||||
|
||||
private:
|
||||
void drawConsole(ImVec2 size);
|
||||
void drawEnvVars(ImVec2 size);
|
||||
void drawVariableSettings(ImVec2 size);
|
||||
|
@ -54,6 +54,17 @@ namespace hex::plugin::builtin {
|
||||
return false;
|
||||
});
|
||||
|
||||
ContentRegistry::Settings::add("hex.builtin.setting.general", "hex.builtin.setting.general.sync_pattern_source", 0, [](auto name, nlohmann::json &setting) {
|
||||
static bool enabled = static_cast<int>(setting);
|
||||
|
||||
if (ImGui::Checkbox(name.data(), &enabled)) {
|
||||
setting = static_cast<int>(enabled);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/* Interface */
|
||||
|
||||
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", 0, [](auto name, nlohmann::json &setting) {
|
||||
|
@ -1,18 +1,21 @@
|
||||
#include "content/views/view_pattern_editor.hpp"
|
||||
|
||||
#include <hex/api/content_registry.hpp>
|
||||
|
||||
#include <pl/preprocessor.hpp>
|
||||
#include <pl/patterns/pattern.hpp>
|
||||
#include <pl/ast/ast_node_variable_decl.hpp>
|
||||
#include <pl/ast/ast_node_type_decl.hpp>
|
||||
#include <pl/ast/ast_node_builtin_type.hpp>
|
||||
|
||||
#include <hex/api/content_registry.hpp>
|
||||
#include <hex/helpers/fs.hpp>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/project_file_handler.hpp>
|
||||
#include <hex/helpers/magic.hpp>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
using namespace hex::literals;
|
||||
@ -96,12 +99,28 @@ namespace hex::plugin::builtin {
|
||||
this->m_textEditor.SetText(code);
|
||||
});
|
||||
|
||||
EventManager::subscribe<EventSettingsChanged>(this, [this] {
|
||||
{
|
||||
auto syncPatternSource = ContentRegistry::Settings::getSetting("hex.builtin.setting.general", "hex.builtin.setting.general.sync_pattern_source");
|
||||
|
||||
if (syncPatternSource.is_number())
|
||||
this->m_syncPatternSourceCode = static_cast<int>(syncPatternSource);
|
||||
}
|
||||
|
||||
{
|
||||
auto autoLoadPatterns = ContentRegistry::Settings::getSetting("hex.builtin.setting.general", "hex.builtin.setting.general.auto_load_patterns");
|
||||
|
||||
if (autoLoadPatterns.is_number())
|
||||
this->m_autoLoadPatterns = static_cast<int>(autoLoadPatterns);
|
||||
}
|
||||
});
|
||||
|
||||
EventManager::subscribe<EventProviderCreated>(this, [this](prv::Provider *provider) {
|
||||
if (!ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.auto_load_patterns", 1))
|
||||
if (!this->m_autoLoadPatterns)
|
||||
return;
|
||||
|
||||
// Copy over current pattern source code to the new provider
|
||||
{
|
||||
if (!this->m_syncPatternSourceCode) {
|
||||
provider->getPatternLanguageSourceCode() = this->m_textEditor.GetText();
|
||||
}
|
||||
|
||||
@ -154,12 +173,14 @@ namespace hex::plugin::builtin {
|
||||
});
|
||||
|
||||
EventManager::subscribe<EventProviderChanged>(this, [this](prv::Provider *oldProvider, prv::Provider *newProvider) {
|
||||
if (oldProvider != nullptr) oldProvider->getPatternLanguageSourceCode() = this->m_textEditor.GetText();
|
||||
if (newProvider != nullptr) this->m_textEditor.SetText(newProvider->getPatternLanguageSourceCode());
|
||||
if (!this->m_syncPatternSourceCode) {
|
||||
if (oldProvider != nullptr) oldProvider->getPatternLanguageSourceCode() = this->m_textEditor.GetText();
|
||||
if (newProvider != nullptr) this->m_textEditor.SetText(newProvider->getPatternLanguageSourceCode());
|
||||
|
||||
auto lines = this->m_textEditor.GetTextLines();
|
||||
lines.pop_back();
|
||||
this->m_textEditor.SetTextLines(lines);
|
||||
auto lines = this->m_textEditor.GetTextLines();
|
||||
lines.pop_back();
|
||||
this->m_textEditor.SetTextLines(lines);
|
||||
}
|
||||
});
|
||||
|
||||
/* Settings */
|
||||
|
@ -56,8 +56,16 @@ namespace hex::plugin::builtin {
|
||||
ImGui::Separator();
|
||||
|
||||
for (auto &[name, requiresRestart, callback] : settings) {
|
||||
if (callback(LangEntry(name), ContentRegistry::Settings::getSettingsData()[category.name][name])) {
|
||||
log::debug("Setting [{}]: {} was changed", category.name, name);
|
||||
auto &setting = ContentRegistry::Settings::getSettingsData()[category.name][name];
|
||||
if (callback(LangEntry(name), setting)) {
|
||||
log::debug("Setting [{}]: {} was changed to {}", category.name, name, [&] -> std::string{
|
||||
if (setting.is_number())
|
||||
return std::to_string(setting.get<int>());
|
||||
else if (setting.is_string())
|
||||
return setting.get<std::string>();
|
||||
else
|
||||
return "";
|
||||
}());
|
||||
EventManager::post<EventSettingsChanged>();
|
||||
|
||||
if (requiresRestart)
|
||||
|
@ -682,7 +682,8 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.imhex.recent_files", "Kürzlich geöffnete Dateien" },
|
||||
{ "hex.builtin.setting.general", "Allgemein" },
|
||||
{ "hex.builtin.setting.general.show_tips", "Tipps beim start anzeigen" },
|
||||
{ "hex.builtin.setting.general.auto_load_patterns", "Unterstützte Pattern automatisch laden" },
|
||||
{ "hex.builtin.setting.general.auto_load_patterns", "Automatisches Pattern laden" },
|
||||
{ "hex.builtin.setting.general.sync_pattern_source", "Pattern Source Code zwischen Providern synchronisieren" },
|
||||
{ "hex.builtin.setting.interface", "Aussehen" },
|
||||
{ "hex.builtin.setting.interface.color", "Farbthema" },
|
||||
{ "hex.builtin.setting.interface.color.system", "System" },
|
||||
|
@ -687,6 +687,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.general", "General" },
|
||||
{ "hex.builtin.setting.general.show_tips", "Show tips on startup" },
|
||||
{ "hex.builtin.setting.general.auto_load_patterns", "Auto-load supported pattern" },
|
||||
{ "hex.builtin.setting.general.sync_pattern_source", "Sync pattern source code between providers" },
|
||||
{ "hex.builtin.setting.interface", "Interface" },
|
||||
{ "hex.builtin.setting.interface.color", "Color theme" },
|
||||
{ "hex.builtin.setting.interface.color.system", "System" },
|
||||
|
@ -691,6 +691,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.general", "Generali" },
|
||||
{ "hex.builtin.setting.general.show_tips", "Mostra consigli all'avvio" },
|
||||
{ "hex.builtin.setting.general.auto_load_patterns", "Auto-caricamento del pattern supportato" },
|
||||
// { "hex.builtin.setting.general.sync_pattern_source", "Sync pattern source code between providers" },
|
||||
{ "hex.builtin.setting.interface", "Interfaccia" },
|
||||
{ "hex.builtin.setting.interface.color", "Colore del Tema" },
|
||||
{ "hex.builtin.setting.interface.color.system", "Sistema" },
|
||||
|
@ -685,6 +685,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.general", "一般" },
|
||||
{ "hex.builtin.setting.general.show_tips", "起動時に豆知識を表示" },
|
||||
{ "hex.builtin.setting.general.auto_load_patterns", "対応するパターンを自動で読み込む" },
|
||||
// { "hex.builtin.setting.general.sync_pattern_source", "Sync pattern source code between providers" },
|
||||
{ "hex.builtin.setting.interface", "インタフェース" },
|
||||
{ "hex.builtin.setting.interface.color", "カラーテーマ" },
|
||||
{ "hex.builtin.setting.interface.color.system", "システム設定に従う" },
|
||||
|
@ -683,6 +683,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.general", "General" },
|
||||
{ "hex.builtin.setting.general.show_tips", "Mostrar dicas na inicialização" },
|
||||
{ "hex.builtin.setting.general.auto_load_patterns", "Padrão compatível com carregamento automático" },
|
||||
// { "hex.builtin.setting.general.sync_pattern_source", "Sync pattern source code between providers" },
|
||||
{ "hex.builtin.setting.interface", "Interface" },
|
||||
{ "hex.builtin.setting.interface.color", "Color theme" },
|
||||
{ "hex.builtin.setting.interface.color.system", "Sistema" },
|
||||
|
@ -688,6 +688,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.general", "通用" },
|
||||
{ "hex.builtin.setting.general.show_tips", "在启动时显示每日提示" },
|
||||
{ "hex.builtin.setting.general.auto_load_patterns", "自动加载支持的模式" },
|
||||
// { "hex.builtin.setting.general.sync_pattern_source", "Sync pattern source code between providers" },
|
||||
{ "hex.builtin.setting.interface", "界面" },
|
||||
{ "hex.builtin.setting.interface.color", "颜色主题" },
|
||||
{ "hex.builtin.setting.interface.color.system", "跟随系统" },
|
||||
|
@ -684,6 +684,7 @@ namespace hex::plugin::builtin {
|
||||
{ "hex.builtin.setting.general", "一般" },
|
||||
{ "hex.builtin.setting.general.show_tips", "啟動時顯示提示" },
|
||||
{ "hex.builtin.setting.general.auto_load_patterns", "自動載入支援的模式" },
|
||||
// { "hex.builtin.setting.general.sync_pattern_source", "Sync pattern source code between providers" },
|
||||
{ "hex.builtin.setting.interface", "介面" },
|
||||
{ "hex.builtin.setting.interface.color", "顏色主題" },
|
||||
{ "hex.builtin.setting.interface.color.system", "系統" },
|
||||
|
Loading…
Reference in New Issue
Block a user