From 9f3e9d16872de4e6ed8444624ba8ae791fd65f85 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Sun, 30 Apr 2023 23:48:23 +0200 Subject: [PATCH 1/2] Add support for search input to Configuration tab Signed-off-by: Tomas Slusny --- src/Classes/ConfigTab.lua | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Classes/ConfigTab.lua b/src/Classes/ConfigTab.lua index 5992fa3b9a..f910241fd3 100644 --- a/src/Classes/ConfigTab.lua +++ b/src/Classes/ConfigTab.lua @@ -29,6 +29,23 @@ local ConfigTabClass = newClass("ConfigTab", "UndoHandler", "ControlHost", "Cont self:BuildModList() + self.controls.search = new("EditControl", { "TOPLEFT", self, "TOPLEFT" }, 8, 5, 360, 20, "", "Search", "%c", 100, function() + self:UpdateControls() + end) + self.controls.sectionAnchor = new("LabelControl", { "TOPLEFT", self.controls.search, "TOPLEFT" }, -10, 15, 0, 0, "") + + local function searchMatch(varData) + local searchStr = self.controls.search.buf:lower():gsub("[%-%.%+%[%]%$%^%%%?%*]", "%%%0") + if searchStr and searchStr:match("%S") then + local err, match = PCall(string.matchOrPattern, (varData.label or ""):lower(), searchStr) + if not err and match then + return true + end + return false + end + return true + end + local function implyCond(varData) local mainEnv = self.build.calcsTab.mainEnv if self.input[varData.var] then @@ -81,7 +98,7 @@ local ConfigTabClass = newClass("ConfigTab", "UndoHandler", "ControlHost", "Cont local lastSection for _, varData in ipairs(varList) do if varData.section then - lastSection = new("SectionControl", {"TOPLEFT",self,"TOPLEFT"}, 0, 0, 360, 0, varData.section) + lastSection = new("SectionControl", {"TOPLEFT",self.controls.sectionAnchor,"TOPLEFT"}, 0, 0, 360, 0, varData.section) lastSection.varControlList = { } lastSection.col = varData.col lastSection.height = function(self) @@ -143,6 +160,10 @@ local ConfigTabClass = newClass("ConfigTab", "UndoHandler", "ControlHost", "Cont local shownFuncs = {} control.shown = function() + if not searchMatch(varData) then + return false + end + for _, shownFunc in ipairs(shownFuncs) do if not shownFunc() then return false @@ -471,6 +492,9 @@ local ConfigTabClass = newClass("ConfigTab", "UndoHandler", "ControlHost", "Cont if not varData.hideIfInvalid then control.shown = function() + if not searchMatch(varData) then + return false + end local shown = type(innerShown) == "boolean" and innerShown or innerShown() local cur = self.input[varData.var] local def = self:GetDefaultState(varData.var, type(cur)) From d664e77244e0f954b91f4c4f878208335b7f905e Mon Sep 17 00:00:00 2001 From: LocalIdentity Date: Fri, 8 Dec 2023 15:19:08 +1100 Subject: [PATCH 2/2] Add search hotkey + clear button --- src/Classes/ConfigTab.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Classes/ConfigTab.lua b/src/Classes/ConfigTab.lua index f910241fd3..748a72d48b 100644 --- a/src/Classes/ConfigTab.lua +++ b/src/Classes/ConfigTab.lua @@ -31,7 +31,7 @@ local ConfigTabClass = newClass("ConfigTab", "UndoHandler", "ControlHost", "Cont self.controls.search = new("EditControl", { "TOPLEFT", self, "TOPLEFT" }, 8, 5, 360, 20, "", "Search", "%c", 100, function() self:UpdateControls() - end) + end, nil, nil, true) self.controls.sectionAnchor = new("LabelControl", { "TOPLEFT", self.controls.search, "TOPLEFT" }, -10, 15, 0, 0, "") local function searchMatch(varData) @@ -655,6 +655,8 @@ function ConfigTabClass:Draw(viewPort, inputEvents) elseif event.key == "y" and IsKeyDown("CTRL") then self:Redo() self.build.buildFlag = true + elseif event.key == "f" and IsKeyDown("CTRL") then + self:SelectControl(self.controls.search) end end end