mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
refactor: Make sure unlocalized strings are always actually unlocalized
This commit is contained in:
@@ -15,7 +15,7 @@ namespace hex::plugin::builtin {
|
||||
template<typename T>
|
||||
class PopupNotification : public Popup<T> {
|
||||
public:
|
||||
PopupNotification(std::string unlocalizedName, std::string message, std::function<void()> function)
|
||||
PopupNotification(UnlocalizedString unlocalizedName, std::string message, std::function<void()> function)
|
||||
: hex::Popup<T>(std::move(unlocalizedName), false),
|
||||
m_message(std::move(message)), m_function(std::move(function)) { }
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@ namespace hex::plugin::builtin {
|
||||
|
||||
class PopupTextInput : public Popup<PopupTextInput> {
|
||||
public:
|
||||
PopupTextInput(std::string unlocalizedName, std::string message, std::function<void(std::string)> function)
|
||||
PopupTextInput(UnlocalizedString unlocalizedName, UnlocalizedString message, std::function<void(std::string)> function)
|
||||
: hex::Popup<PopupTextInput>(std::move(unlocalizedName), false),
|
||||
m_message(std::move(message)), m_function(std::move(function)) { }
|
||||
|
||||
void drawContent() override {
|
||||
ImGuiExt::TextFormattedWrapped("{}", this->m_message.c_str());
|
||||
ImGuiExt::TextFormattedWrapped("{}", Lang(this->m_message));
|
||||
ImGui::NewLine();
|
||||
|
||||
ImGui::PushItemWidth(-1);
|
||||
@@ -65,7 +65,7 @@ namespace hex::plugin::builtin {
|
||||
private:
|
||||
std::string m_input;
|
||||
|
||||
std::string m_message;
|
||||
UnlocalizedString m_message;
|
||||
std::function<void(std::string)> m_function;
|
||||
bool m_justOpened = true;
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
private:
|
||||
struct InspectorCacheEntry {
|
||||
std::string unlocalizedName;
|
||||
UnlocalizedString unlocalizedName;
|
||||
ContentRegistry::DataInspector::impl::DisplayFunction displayFunction;
|
||||
std::optional<ContentRegistry::DataInspector::impl::EditingFunction> editingFunction;
|
||||
bool editing;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace hex::plugin::builtin {
|
||||
};
|
||||
|
||||
struct StoreCategory {
|
||||
std::string unlocalizedName;
|
||||
UnlocalizedString unlocalizedName;
|
||||
std::string requestName;
|
||||
fs::ImHexPath path;
|
||||
std::vector<StoreEntry> entries;
|
||||
@@ -76,7 +76,7 @@ namespace hex::plugin::builtin {
|
||||
void refresh();
|
||||
void parseResponse();
|
||||
|
||||
void addCategory(const std::string &unlocalizedName, const std::string &requestName, fs::ImHexPath path, std::function<void()> downloadCallback = []{});
|
||||
void addCategory(const UnlocalizedString &unlocalizedName, const std::string &requestName, fs::ImHexPath path, std::function<void()> downloadCallback = []{});
|
||||
|
||||
bool download(fs::ImHexPath pathType, const std::string &fileName, const std::string &url, bool update);
|
||||
bool remove(fs::ImHexPath pathType, const std::string &fileName);
|
||||
|
||||
@@ -16,32 +16,32 @@ namespace hex::plugin::builtin {
|
||||
|
||||
class AchievementStartingOut : public Achievement {
|
||||
public:
|
||||
explicit AchievementStartingOut(std::string unlocalizedName) : Achievement("hex.builtin.achievement.starting_out", std::move(unlocalizedName)) { }
|
||||
explicit AchievementStartingOut(UnlocalizedString unlocalizedName) : Achievement("hex.builtin.achievement.starting_out", std::move(unlocalizedName)) { }
|
||||
};
|
||||
|
||||
class AchievementHexEditor : public Achievement {
|
||||
public:
|
||||
explicit AchievementHexEditor(std::string unlocalizedName) : Achievement("hex.builtin.achievement.hex_editor", std::move(unlocalizedName)) { }
|
||||
explicit AchievementHexEditor(UnlocalizedString unlocalizedName) : Achievement("hex.builtin.achievement.hex_editor", std::move(unlocalizedName)) { }
|
||||
};
|
||||
|
||||
class AchievementPatterns : public Achievement {
|
||||
public:
|
||||
explicit AchievementPatterns(std::string unlocalizedName) : Achievement("hex.builtin.achievement.patterns", std::move(unlocalizedName)) { }
|
||||
explicit AchievementPatterns(UnlocalizedString unlocalizedName) : Achievement("hex.builtin.achievement.patterns", std::move(unlocalizedName)) { }
|
||||
};
|
||||
|
||||
class AchievementDataProcessor : public Achievement {
|
||||
public:
|
||||
explicit AchievementDataProcessor(std::string unlocalizedName) : Achievement("hex.builtin.achievement.data_processor", std::move(unlocalizedName)) { }
|
||||
explicit AchievementDataProcessor(UnlocalizedString unlocalizedName) : Achievement("hex.builtin.achievement.data_processor", std::move(unlocalizedName)) { }
|
||||
};
|
||||
|
||||
class AchievementFind : public Achievement {
|
||||
public:
|
||||
explicit AchievementFind(std::string unlocalizedName) : Achievement("hex.builtin.achievement.find", std::move(unlocalizedName)) { }
|
||||
explicit AchievementFind(UnlocalizedString unlocalizedName) : Achievement("hex.builtin.achievement.find", std::move(unlocalizedName)) { }
|
||||
};
|
||||
|
||||
class AchievementMisc : public Achievement {
|
||||
public:
|
||||
explicit AchievementMisc(std::string unlocalizedName) : Achievement("hex.builtin.achievement.misc", std::move(unlocalizedName)) { }
|
||||
explicit AchievementMisc(UnlocalizedString unlocalizedName) : Achievement("hex.builtin.achievement.misc", std::move(unlocalizedName)) { }
|
||||
};
|
||||
|
||||
void registerGettingStartedAchievements() {
|
||||
|
||||
@@ -91,8 +91,8 @@ namespace hex::plugin::builtin {
|
||||
autoBackupTime = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.auto_backup_time", 0).get<int>() * 30;
|
||||
});
|
||||
|
||||
ContentRegistry::BackgroundServices::registerService("hex.builtin.background_service.network_interface"_lang, handleNetworkInterfaceService);
|
||||
ContentRegistry::BackgroundServices::registerService("hex.builtin.background_service.auto_backup"_lang, handleAutoBackup);
|
||||
ContentRegistry::BackgroundServices::registerService("hex.builtin.background_service.network_interface", handleNetworkInterfaceService);
|
||||
ContentRegistry::BackgroundServices::registerService("hex.builtin.background_service.auto_backup", handleAutoBackup);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -542,14 +542,14 @@ namespace hex::plugin::builtin {
|
||||
ContentRegistry::Interface::registerMainMenuItem("hex.builtin.menu.workspace", 4000);
|
||||
|
||||
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) {
|
||||
PopupTextInput::open("hex.builtin.popup.save_layout.title", "hex.builtin.popup.save_layout.desc", [](const std::string &name) {
|
||||
LayoutManager::save(name);
|
||||
});
|
||||
}, ImHexApi::Provider::isValid);
|
||||
|
||||
ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.workspace", "hex.builtin.menu.workspace.layout" }, 1150, [] {
|
||||
bool locked = LayoutManager::isLayoutLocked();
|
||||
if (ImGui::MenuItem("hex.builtin.menu.workspace.layout.lock"_lang, nullptr, &locked, ImHexApi::Provider::isValid())) {
|
||||
if (ImGui::MenuItem("hex.builtin.menu.workspace.layout.lock", nullptr, &locked, ImHexApi::Provider::isValid())) {
|
||||
LayoutManager::lockLayout(locked);
|
||||
ContentRegistry::Settings::write("hex.builtin.setting.interface", "hex.builtin.setting.interface.layout_locked", locked);
|
||||
}
|
||||
@@ -584,7 +584,7 @@ namespace hex::plugin::builtin {
|
||||
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) {
|
||||
PopupTextInput::open("hex.builtin.popup.create_workspace.title", "hex.builtin.popup.create_workspace.desc", [](const std::string &name) {
|
||||
WorkspaceManager::createWorkspace(name);
|
||||
});
|
||||
}, ImHexApi::Provider::isValid);
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
void MemoryFileProvider::renameFile() {
|
||||
PopupTextInput::open("hex.builtin.provider.mem_file.rename"_lang, "hex.builtin.provider.mem_file.rename.desc"_lang, [this](const std::string &name) {
|
||||
PopupTextInput::open("hex.builtin.provider.mem_file.rename", "hex.builtin.provider.mem_file.rename.desc", [this](const std::string &name) {
|
||||
this->m_name = name;
|
||||
RequestUpdateWindowTitle::post();
|
||||
});
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace hex::plugin::builtin::recent {
|
||||
std::fs::path path;
|
||||
};
|
||||
public:
|
||||
PopupAutoBackups() : Popup("hex.builtin.welcome.start.recent.auto_backups"_lang, true, true) {
|
||||
PopupAutoBackups() : Popup("hex.builtin.welcome.start.recent.auto_backups", true, true) {
|
||||
for (const auto &backupPath : fs::getDefaultPaths(fs::ImHexPath::Backups)) {
|
||||
for (const auto &entry : std::fs::directory_iterator(backupPath)) {
|
||||
if (entry.is_regular_file() && entry.path().extension() == ".hexproj") {
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace hex::plugin::builtin {
|
||||
})
|
||||
.onAppear([&step] {
|
||||
EventViewOpened::subscribe([&step](View *view){
|
||||
if (view->getUnlocalizedName() == "hex.builtin.view.tutorials.name")
|
||||
if (view->getUnlocalizedName() == UnlocalizedString("hex.builtin.view.tutorials.name"))
|
||||
step.complete();
|
||||
});
|
||||
})
|
||||
|
||||
@@ -579,7 +579,7 @@ namespace hex::plugin::builtin {
|
||||
nlohmann::json nodeJson = nlohmann::json::parse(file.readString());
|
||||
|
||||
// Add the loaded node to the list of custom nodes
|
||||
this->m_customNodes.push_back(CustomNode { Lang(nodeJson.at("name")), nodeJson });
|
||||
this->m_customNodes.push_back(CustomNode { Lang(nodeJson.at("name").get<std::string>()), nodeJson });
|
||||
} catch (nlohmann::json::exception &e) {
|
||||
log::warn("Failed to load custom node '{}': {}", entry.path().string(), e.what());
|
||||
}
|
||||
@@ -1077,7 +1077,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
std::unique_ptr<dp::Node> newNode;
|
||||
for (auto &entry : nodeEntries) {
|
||||
if (data.contains("name") && entry.name == data["type"].get<std::string>())
|
||||
if (data.contains("name") && entry.unlocalizedName == data["type"].get<std::string>())
|
||||
newNode = entry.creatorFunction();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace hex::plugin::builtin {
|
||||
m_hash(hash) { }
|
||||
|
||||
void drawContent() override {
|
||||
ImGuiExt::Header(this->getUnlocalizedName().c_str(), true);
|
||||
ImGuiExt::Header(this->getUnlocalizedName(), true);
|
||||
|
||||
ImGui::PushItemWidth(-1);
|
||||
if (ImGui::InputTextMultiline("##input", this->m_input)) {
|
||||
|
||||
@@ -1044,7 +1044,7 @@ namespace hex::plugin::builtin {
|
||||
ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.file" }, 1300);
|
||||
|
||||
/* Save */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.view.hex_editor.menu.file.save"_lang }, 1350,
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.view.hex_editor.menu.file.save" }, 1350,
|
||||
CTRLCMD + Keys::S,
|
||||
save,
|
||||
[] {
|
||||
@@ -1055,7 +1055,7 @@ namespace hex::plugin::builtin {
|
||||
});
|
||||
|
||||
/* Save As */
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.view.hex_editor.menu.file.save_as"_lang }, 1375,
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.file", "hex.builtin.view.hex_editor.menu.file.save_as" }, 1375,
|
||||
CTRLCMD + SHIFT + Keys::S,
|
||||
saveAs,
|
||||
[] {
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
// Add the settings menu item to the Extras menu
|
||||
ContentRegistry::Interface::addMenuItemSeparator({ "hex.builtin.menu.extras" }, 3000);
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.view.settings.name"_lang }, 4000, Shortcut::None, [&, this] {
|
||||
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.view.settings.name" }, 4000, Shortcut::None, [&, this] {
|
||||
this->getWindowOpenState() = true;
|
||||
});
|
||||
}
|
||||
@@ -80,7 +80,7 @@ namespace hex::plugin::builtin {
|
||||
ContentRegistry::Settings::write(category.unlocalizedName, setting.unlocalizedName, newValue);
|
||||
|
||||
// Print a debug message
|
||||
log::debug("Setting [{} / {}]: Value was changed to {}", category.unlocalizedName, setting.unlocalizedName, nlohmann::to_string(newValue));
|
||||
log::debug("Setting [{} / {}]: Value was changed to {}", category.unlocalizedName.get(), setting.unlocalizedName.get(), nlohmann::to_string(newValue));
|
||||
|
||||
// Signal that the setting was changed
|
||||
EventSettingsChanged::post();
|
||||
|
||||
@@ -37,20 +37,20 @@ namespace hex::plugin::builtin {
|
||||
|
||||
this->m_httpRequest.setTimeout(30'0000);
|
||||
|
||||
addCategory("hex.builtin.view.store.tab.patterns"_lang, "patterns", fs::ImHexPath::Patterns);
|
||||
addCategory("hex.builtin.view.store.tab.includes"_lang, "includes", fs::ImHexPath::PatternsInclude);
|
||||
addCategory("hex.builtin.view.store.tab.magic"_lang, "magic", fs::ImHexPath::Magic, []{
|
||||
addCategory("hex.builtin.view.store.tab.patterns", "patterns", fs::ImHexPath::Patterns);
|
||||
addCategory("hex.builtin.view.store.tab.includes", "includes", fs::ImHexPath::PatternsInclude);
|
||||
addCategory("hex.builtin.view.store.tab.magic", "magic", fs::ImHexPath::Magic, []{
|
||||
magic::compile();
|
||||
});
|
||||
addCategory("hex.builtin.view.store.tab.nodes"_lang, "nodes", fs::ImHexPath::Nodes);
|
||||
addCategory("hex.builtin.view.store.tab.encodings"_lang, "encodings", fs::ImHexPath::Encodings);
|
||||
addCategory("hex.builtin.view.store.tab.constants"_lang, "constants", fs::ImHexPath::Constants);
|
||||
addCategory("hex.builtin.view.store.tab.themes"_lang, "themes", fs::ImHexPath::Themes, [this]{
|
||||
addCategory("hex.builtin.view.store.tab.nodes", "nodes", fs::ImHexPath::Nodes);
|
||||
addCategory("hex.builtin.view.store.tab.encodings", "encodings", fs::ImHexPath::Encodings);
|
||||
addCategory("hex.builtin.view.store.tab.constants", "constants", fs::ImHexPath::Constants);
|
||||
addCategory("hex.builtin.view.store.tab.themes", "themes", fs::ImHexPath::Themes, [this]{
|
||||
auto themeFile = wolv::io::File(this->m_downloadPath, wolv::io::File::Mode::Read);
|
||||
|
||||
ThemeManager::addTheme(themeFile.readString());
|
||||
});
|
||||
addCategory("hex.builtin.view.store.tab.yara"_lang, "yara", fs::ImHexPath::Yara);
|
||||
addCategory("hex.builtin.view.store.tab.yara", "yara", fs::ImHexPath::Yara);
|
||||
}
|
||||
|
||||
|
||||
@@ -333,7 +333,7 @@ namespace hex::plugin::builtin {
|
||||
return removed;
|
||||
}
|
||||
|
||||
void ViewStore::addCategory(const std::string &unlocalizedName, const std::string &requestName, fs::ImHexPath path, std::function<void()> downloadCallback) {
|
||||
void ViewStore::addCategory(const UnlocalizedString &unlocalizedName, const std::string &requestName, fs::ImHexPath path, std::function<void()> downloadCallback) {
|
||||
this->m_categories.push_back({ unlocalizedName, requestName, path, { }, std::move(downloadCallback) });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user