explorer: intuitive search. Search strings are handeled/stored per per node
This commit is contained in:
parent
e99fbc135c
commit
4eac99cf92
@ -84,9 +84,11 @@ local function get_explorer_obj(state)
|
|||||||
selected = selected,
|
selected = selected,
|
||||||
}
|
}
|
||||||
for _, stacknode in ipairs(self.stack) do
|
for _, stacknode in ipairs(self.stack) do
|
||||||
|
local saveentry = { search = stacknode.search }
|
||||||
if stacknode.parent then
|
if stacknode.parent then
|
||||||
table.insert(savedata.stack, stacknode.label)
|
saveentry.label = stacknode.label
|
||||||
end
|
end
|
||||||
|
table.insert(savedata.stack, saveentry)
|
||||||
end
|
end
|
||||||
state.param.persist.data.qa_explorer = savedata
|
state.param.persist.data.qa_explorer = savedata
|
||||||
state.param.persist:save()
|
state.param.persist:save()
|
||||||
@ -97,15 +99,18 @@ local function get_explorer_obj(state)
|
|||||||
local savedata = state.param.persist.data.qa_explorer
|
local savedata = state.param.persist.data.qa_explorer
|
||||||
if savedata.stack then
|
if savedata.stack then
|
||||||
local cursor = _G
|
local cursor = _G
|
||||||
for _, label in ipairs(savedata.stack) do
|
for _, saveentry in ipairs(savedata.stack) do
|
||||||
if cursor[label] then
|
if not saveentry.label then -- root node
|
||||||
|
self.stack[1].search = saveentry.search
|
||||||
|
elseif cursor[saveentry.label] then
|
||||||
table.insert(self.stack, {
|
table.insert(self.stack, {
|
||||||
label = label,
|
label = saveentry.label,
|
||||||
ref = cursor[label],
|
search = saveentry.search,
|
||||||
|
ref = cursor[saveentry.label],
|
||||||
parent = cursor,
|
parent = cursor,
|
||||||
--text =
|
--text =
|
||||||
})
|
})
|
||||||
cursor = cursor[label]
|
cursor = cursor[saveentry.label]
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -135,8 +140,8 @@ local function _explore_dialog(state)
|
|||||||
local fld_search = state:field(8, 7.32, 2, 0.5, "search")
|
local fld_search = state:field(8, 7.32, 2, 0.5, "search")
|
||||||
local btn_search = state:button(9.7,7,1,0.5,"search_btn", "Search")
|
local btn_search = state:button(9.7,7,1,0.5,"search_btn", "Search")
|
||||||
local ck_funchide = state:checkbox(11, 6.75, "funchide", "Hide functions")
|
local ck_funchide = state:checkbox(11, 6.75, "funchide", "Hide functions")
|
||||||
if state.param.persist.data.explorer_funchide then
|
if state.param.persist.data.explore_funchide then
|
||||||
ck_funchide:setValue(state.param.persist.data.explorer_funchide)
|
ck_funchide:setValue(state.param.persist.data.explore_funchide)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update_current(state, index)
|
local function update_current(state, index)
|
||||||
@ -144,12 +149,11 @@ local function _explore_dialog(state)
|
|||||||
local explorer = get_explorer_obj(state)
|
local explorer = get_explorer_obj(state)
|
||||||
local ck_funchide = state:get("funchide")
|
local ck_funchide = state:get("funchide")
|
||||||
local stackentry = explorer.stack[index]
|
local stackentry = explorer.stack[index]
|
||||||
local search = state:get("search"):getText()
|
|
||||||
state.param.explore_search = search
|
|
||||||
explorer.list = {}
|
explorer.list = {}
|
||||||
if stackentry then
|
if stackentry then
|
||||||
|
state:get("search"):setText(stackentry.search or "")
|
||||||
for name, val in pairs(stackentry.ref) do
|
for name, val in pairs(stackentry.ref) do
|
||||||
if string.match(name, search) then
|
if string.match(name, stackentry.search or "") then
|
||||||
local entry
|
local entry
|
||||||
local sval
|
local sval
|
||||||
local t = type(val)
|
local t = type(val)
|
||||||
@ -183,7 +187,7 @@ local function _explore_dialog(state)
|
|||||||
lb_current:addItem(stackentry.text)
|
lb_current:addItem(stackentry.text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
state.param.persist.data.explorer_funchide = ck_funchide:getValue()
|
state.param.persist.data.explore_funchide = ck_funchide:getValue()
|
||||||
explorer:save_path(index)
|
explorer:save_path(index)
|
||||||
state.param.persist:save()
|
state.param.persist:save()
|
||||||
end
|
end
|
||||||
@ -212,6 +216,7 @@ local function _explore_dialog(state)
|
|||||||
if not explorer.list[index] then
|
if not explorer.list[index] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(explorer.list[index].ref) == "table" then
|
if type(explorer.list[index].ref) == "table" then
|
||||||
local nav_to = explorer.list[index]
|
local nav_to = explorer.list[index]
|
||||||
-- cleanup stack before add the item
|
-- cleanup stack before add the item
|
||||||
@ -247,8 +252,11 @@ local function _explore_dialog(state)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
state:onInput(function(state, fields, player)
|
state:onInput(function(state, fields, player)
|
||||||
if state.param.explore_search ~= state:get("search"):getText() then
|
local selected = state:get("stack"):getSelected()
|
||||||
update_current(state, state:get("stack"):getSelected())
|
local stackentry = explorer.stack[selected]
|
||||||
|
if stackentry and stackentry.search ~= state:get("search"):getText() then
|
||||||
|
stackentry.search = state:get("search"):getText()
|
||||||
|
update_current(state, selected)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -18,12 +18,6 @@ function storage.new(location)
|
|||||||
local serialized_data = meta:get_string("qa_block_data")
|
local serialized_data = meta:get_string("qa_block_data")
|
||||||
if serialized_data then
|
if serialized_data then
|
||||||
self.data = minetest.deserialize(serialized_data) or {}
|
self.data = minetest.deserialize(serialized_data) or {}
|
||||||
else
|
|
||||||
-- compatibility to first version till 20.03.2017
|
|
||||||
serialized_data = meta:get_string("qa_explorer")
|
|
||||||
if serialized_data then
|
|
||||||
self.data.qa_explorer = minetest.deserialize(serialized_data) or {}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user