1
0
mirror of synced 2024-11-28 01:20:51 +01:00

impr: Clean up some more clang-tidy issues

This commit is contained in:
WerWolv 2023-04-16 22:12:35 +02:00
parent 1690cd2740
commit c32515bc44
3 changed files with 21 additions and 25 deletions

View File

@ -27,7 +27,6 @@ cppcoreguidelines-pro-type-member-init,
cppcoreguidelines-slicing,
cppcoreguidelines-interfaces-global-init,
cppcoreguidelines-pro-type-static-cast-downcast,
cppcoreguidelines-avoid-capture-default-when-capturing-this,
cppcoreguidelines-narrowing-conversions,
google-default-arguments,
google-runtime-operator,
@ -65,4 +64,5 @@ readability-*,
-readability-else-after-return,
-readability-redundant-access-specifiers,
-readability-function-cognitive-complexity,
-readability-identifier-naming'
-readability-identifier-naming,
-readability-qualified-auto'

View File

@ -44,10 +44,10 @@ namespace hex::plugin::builtin {
class PopupAcceptPattern : public Popup<PopupAcceptPattern> {
public:
PopupAcceptPattern(ViewPatternEditor *view) : Popup("hex.builtin.view.pattern_editor.accept_pattern"), m_view(view) {}
explicit PopupAcceptPattern(ViewPatternEditor *view) : Popup("hex.builtin.view.pattern_editor.accept_pattern"), m_view(view) {}
void drawContent() override {
auto provider = ImHexApi::Provider::get();
auto* provider = ImHexApi::Provider::get();
ImGui::TextFormattedWrapped("{}", static_cast<const char *>("hex.builtin.view.pattern_editor.accept_pattern.desc"_lang));
@ -61,11 +61,11 @@ namespace hex::plugin::builtin {
if (ImGui::BeginListBox("##patterns_accept", ImVec2(-FLT_MIN, 0))) {
u32 index = 0;
for (auto &path : this->m_view->m_possiblePatternFiles) {
if (ImGui::Selectable(wolv::util::toUTF8String(path.filename()).c_str(), index == this->m_view->m_selectedPatternFile, ImGuiSelectableFlags_DontClosePopups))
this->m_view->m_selectedPatternFile = index;
if (ImGui::Selectable(wolv::util::toUTF8String(path.filename()).c_str(), index == this->m_selectedPatternFile, ImGuiSelectableFlags_DontClosePopups))
this->m_selectedPatternFile = index;
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0))
this->m_view->loadPatternFile(this->m_view->m_possiblePatternFiles[this->m_view->m_selectedPatternFile], provider);
this->m_view->loadPatternFile(this->m_view->m_possiblePatternFiles[this->m_selectedPatternFile], provider);
ImGui::InfoTooltip(wolv::util::toUTF8String(path).c_str());
@ -80,7 +80,7 @@ namespace hex::plugin::builtin {
confirmButtons("hex.builtin.common.yes"_lang, "hex.builtin.common.no"_lang,
[this, provider] {
this->m_view->loadPatternFile(this->m_view->m_possiblePatternFiles[this->m_view->m_selectedPatternFile], provider);
this->m_view->loadPatternFile(this->m_view->m_possiblePatternFiles[this->m_selectedPatternFile], provider);
this->close();
},
[this] {
@ -98,6 +98,7 @@ namespace hex::plugin::builtin {
private:
ViewPatternEditor *m_view;
u32 m_selectedPatternFile = 0;
};
private:
@ -106,7 +107,6 @@ namespace hex::plugin::builtin {
std::unique_ptr<pl::PatternLanguage> m_parserRuntime;
std::vector<std::fs::path> m_possiblePatternFiles;
u32 m_selectedPatternFile = 0;
bool m_runAutomatically = false;
bool m_triggerEvaluation = false;
@ -118,8 +118,6 @@ namespace hex::plugin::builtin {
bool m_hasUnevaluatedChanges = false;
bool m_acceptPatternWindowOpen = false;
TextEditor m_textEditor;
std::atomic<bool> m_dangerousFunctionCalled = false;

View File

@ -51,7 +51,7 @@ namespace hex::plugin::builtin {
langDef.mTokenize = [](const char *inBegin, const char *inEnd, const char *&outBegin, const char *&outEnd, TextEditor::PaletteIndex &paletteIndex) -> bool {
paletteIndex = TextEditor::PaletteIndex::Max;
while (inBegin < inEnd && isascii(*inBegin) && isblank(*inBegin))
while (inBegin < inEnd && isascii(*inBegin) && std::isblank(*inBegin))
inBegin++;
if (inBegin == inEnd) {
@ -279,9 +279,9 @@ namespace hex::plugin::builtin {
ON_SCOPE_EXIT { ImGui::PopID(); };
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
constexpr static const char *Types[] = { "I", "F", "S", "B" };
constexpr static std::array Types = { "I", "F", "S", "B" };
if (ImGui::BeginCombo("", Types[static_cast<int>(type)])) {
for (auto i = 0; i < IM_ARRAYSIZE(Types); i++) {
for (size_t i = 0; i < Types.size(); i++) {
if (ImGui::Selectable(Types[i]))
type = static_cast<PlData::EnvVarType>(i);
}
@ -398,8 +398,8 @@ namespace hex::plugin::builtin {
ImGui::Checkbox(label.c_str(), &value);
variable.value = value;
} else if (variable.type == pl::core::Token::ValueType::Character) {
char buffer[2];
ImGui::InputText(label.c_str(), buffer, 2);
std::array<char, 2> buffer;
ImGui::InputText(label.c_str(), buffer.data(), buffer.size());
variable.value = buffer[0];
}
}
@ -462,7 +462,7 @@ namespace hex::plugin::builtin {
auto patternProvider = ImHexApi::Provider::get();
this->m_sectionWindowDrawer[patternProvider] = [id, patternProvider, dataProvider = std::move(dataProvider), hexEditor = std::move(hexEditor), patternDrawer = ui::PatternDrawer()] mutable {
this->m_sectionWindowDrawer[patternProvider] = [id, patternProvider, dataProvider = std::move(dataProvider), hexEditor, patternDrawer = ui::PatternDrawer()] mutable {
hexEditor.setProvider(dataProvider.get());
hexEditor.draw(480_scaled);
patternDrawer.setSelectionCallback([&](const auto &region) {
@ -724,8 +724,8 @@ namespace hex::plugin::builtin {
});
EventManager::subscribe<EventSettingsChanged>(this, [this] {
this->m_syncPatternSourceCode = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.sync_pattern_source", 0);
this->m_autoLoadPatterns = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.auto_load_patterns", 1);
this->m_syncPatternSourceCode = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.sync_pattern_source", 0) == 1;
this->m_autoLoadPatterns = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.auto_load_patterns", 1) == 1;
});
EventManager::subscribe<EventProviderOpened>(this, [this](prv::Provider *provider) {
@ -785,9 +785,7 @@ namespace hex::plugin::builtin {
}
if (!this->m_possiblePatternFiles.empty()) {
this->m_selectedPatternFile = 0;
PopupAcceptPattern::open(this);
this->m_acceptPatternWindowOpen = true;
}
});
@ -883,7 +881,7 @@ namespace hex::plugin::builtin {
/* Place pattern... */
ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.edit", "hex.builtin.view.pattern_editor.menu.edit.place_pattern", "hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin" }, 3000,
[&]{
[&, this] {
if (ImGui::BeginMenu("hex.builtin.view.pattern_editor.menu.edit.place_pattern.builtin.single"_lang)) {
for (const auto &[type, size] : Types)
if (ImGui::MenuItem(type))
@ -902,7 +900,7 @@ namespace hex::plugin::builtin {
});
ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.edit", "hex.builtin.view.pattern_editor.menu.edit.place_pattern", "hex.builtin.view.pattern_editor.menu.edit.place_pattern.custom" }, 3050,
[&]{
[&, this] {
const auto &types = this->m_parserRuntime->getInternals().parser->getTypes();
auto selection = ImHexApi::HexEditor::getSelection();
@ -910,7 +908,7 @@ namespace hex::plugin::builtin {
if (type->isTemplateType())
continue;
createNestedMenu(hex::splitString(typeName, "::"), [&] {
createNestedMenu(hex::splitString(typeName, "::"), [&, this] {
std::string variableName;
for (char &c : hex::replaceStrings(typeName, "::", "_"))
variableName += static_cast<char>(std::tolower(c));
@ -1020,4 +1018,4 @@ namespace hex::plugin::builtin {
});
}
}
}