diff options
| author | ruki <[email protected]> | 2018-02-03 08:36:50 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-02-03 08:36:50 +0800 |
| commit | f2dea7df338f116631fa8d6d567478855684fa07 (patch) | |
| tree | 55a4c5a86a76c6f808269cfddf1060a0430e3bf8 | |
| parent | ba8726073c7d471daad25bb797e1a26e151885d0 (diff) | |
impl search config
| -rw-r--r-- | xmake/core/ui/mconfdialog.lua | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/xmake/core/ui/mconfdialog.lua b/xmake/core/ui/mconfdialog.lua index c2abd3016..92b7a1f59 100644 --- a/xmake/core/ui/mconfdialog.lua +++ b/xmake/core/ui/mconfdialog.lua @@ -96,9 +96,15 @@ end -- load configs function mconfdialog:load(configs) + self._CONFIGS = configs return self:menuconf():load(configs) end +-- get configs +function mconfdialog:configs() + return self._CONFIGS +end + -- get menu config function mconfdialog:menuconf() if not self._MENUCONF then @@ -119,6 +125,16 @@ function mconfdialog:helpdialog() return self._HELPDIALOG end +-- get result dialog +function mconfdialog:resultdialog() + if not self._RESULTDIALOG then + local resultdialog = textdialog:new("mconfdialog.result", self:bounds(), "result") + resultdialog:button_add("exit", "< Exit >", function (v) resultdialog:quit() end) + self._RESULTDIALOG = resultdialog + end + return self._RESULTDIALOG +end + -- get input dialog function mconfdialog:inputdialog() if not self._INPUTDIALOG then @@ -168,7 +184,22 @@ function mconfdialog:searchdialog() dialog_search:textedit():option_set("multiline", false) dialog_search:text():text_set("Enter (sub)string or lua pattern string to search for configuration") dialog_search:button_add("ok", "< Ok >", function (v) - -- TODO + local configs = self:search(self:configs(), dialog_search:textedit():text()) + local results = "Search('" .. dialog_search:textedit():text() .. "') results:" + for _, config in ipairs(configs) do + results = results .. "\n" .. config:prompt() + if config.kind then + results = results .. "\nkind: " .. config.kind + end + if config.default then + results = results .. "\ndefault: " .. config.default + end + if config.path then + results = results .. "\npath: " .. config.path + end + results = results .. "\n" + end + self:show_result(results) dialog_search:quit() end) dialog_search:button_add("cancel", "< Cancel >", function (v) @@ -180,6 +211,21 @@ function mconfdialog:searchdialog() return self._SEARCHDIALOG end +-- search configs via the given text +function mconfdialog:search(configs, text) + local results = {} + for _, config in ipairs(configs) do + local prompt = config:prompt() + if prompt and prompt:find(text) then + table.insert(results, config) + end + if config.kind == "menu" then + table.join2(results, self:search(config.configs, text)) + end + end + return results +end + -- show help dialog function mconfdialog:show_help() if self:parent() then @@ -227,6 +273,13 @@ function mconfdialog:show_search() self:insert(dialog_search, {centerx = true, centery = true}) end +-- show result dialog +function mconfdialog:show_result(text) + local dialog_result = self:resultdialog() + dialog_result:text():text_set(text) + self:insert(dialog_result, {centerx = true, centery = true}) +end + -- on event function mconfdialog:event_on(e) |
