Merge pull request #527 from warmist/gm-editor

Add search bar to gui/gm-editor
develop
Lethosor 2015-02-03 12:29:01 -05:00
commit 7aa82fdbdb
1 changed files with 40 additions and 3 deletions

@ -12,6 +12,7 @@ local keybindings={
insert={key="CUSTOM_ALT_I",desc="Insert a new value to the vector"}, insert={key="CUSTOM_ALT_I",desc="Insert a new value to the vector"},
delete={key="CUSTOM_ALT_D",desc="Delete selected entry"}, delete={key="CUSTOM_ALT_D",desc="Delete selected entry"},
reinterpret={key="CUSTOM_ALT_R",desc="Open selected entry as something else"}, reinterpret={key="CUSTOM_ALT_R",desc="Open selected entry as something else"},
start_filter={key="CUSTOM_S",desc="Start typing filter, Enter to finish"},
help={key="HELP",desc="Show this help"}, help={key="HELP",desc="Show this help"},
NOT_USED={key="SEC_SELECT",desc="Choose an enum value from a list"}, --not a binding... NOT_USED={key="SEC_SELECT",desc="Choose an enum value from a list"}, --not a binding...
} }
@ -63,6 +64,7 @@ function Disclaimer(tlb)
end end
return dsc return dsc
end end
function GmEditorUi:init(args) function GmEditorUi:init(args)
self.stack={} self.stack={}
self.item_count=0 self.item_count=0
@ -84,6 +86,7 @@ function GmEditorUi:init(args)
subviews={ subviews={
mainList, mainList,
widgets.Label{text={{text="<no item>",id="name"},{gap=1,text="Help",key="HELP",key_sep = '()'}}, view_id = 'lbl_current_item',frame = {l=1,t=1,yalign=0}}, widgets.Label{text={{text="<no item>",id="name"},{gap=1,text="Help",key="HELP",key_sep = '()'}}, view_id = 'lbl_current_item',frame = {l=1,t=1,yalign=0}},
widgets.EditField{frame={l=1,t=2},active=false,on_change=self:callback('text_input'),on_submit=self:callback("enable_input",false),view_id="filter_input"},
--widgets.Label{text="BLAH2"} --widgets.Label{text="BLAH2"}
} }
,view_id='page_main'} ,view_id='page_main'}
@ -94,6 +97,12 @@ function GmEditorUi:init(args)
} }
self:pushTarget(args.target) self:pushTarget(args.target)
end end
function GmEditorUi:text_input(new_text)
self:updateTarget(true,true)
end
function GmEditorUi:enable_input(enable)
self.subviews.filter_input.active=enable
end
function GmEditorUi:find(test) function GmEditorUi:find(test)
local trg=self:currentTarget() local trg=self:currentTarget()
@ -242,12 +251,23 @@ function GmEditorUi:set(key,input)
end end
function GmEditorUi:onInput(keys) function GmEditorUi:onInput(keys)
if keys.LEAVESCREEN then if keys.LEAVESCREEN then
if self.subviews.filter_input.active then
self:enable_input(false)
return
end
if self.subviews.pages:getSelected()==2 then if self.subviews.pages:getSelected()==2 then
self.subviews.pages:setSelected(1) self.subviews.pages:setSelected(1)
else else
self:popTarget() self:popTarget()
end end
elseif keys[keybindings.offset.key] then end
if self.subviews.filter_input.active then
self.super.onInput(self,keys)
return
end
if keys[keybindings.offset.key] then
local trg=self:currentTarget() local trg=self:currentTarget()
local _,stoff=df.sizeof(trg.target) local _,stoff=df.sizeof(trg.target)
local size,off=df.sizeof(trg.target:_field(self:getSelectedKey())) local size,off=df.sizeof(trg.target:_field(self:getSelectedKey()))
@ -263,6 +283,9 @@ function GmEditorUi:onInput(keys)
self:deleteSelected(self:getSelectedKey()) self:deleteSelected(self:getSelectedKey())
elseif keys[keybindings.reinterpret.key] then elseif keys[keybindings.reinterpret.key] then
self:openReinterpret(self:getSelectedKey()) self:openReinterpret(self:getSelectedKey())
elseif keys[keybindings.start_filter.key] then
self:enable_input(true)
return
end end
self.super.onInput(self,keys) self.super.onInput(self,keys)
@ -283,10 +306,21 @@ function getStringValue(trg,field)
end end
function GmEditorUi:updateTarget(preserve_pos,reindex) function GmEditorUi:updateTarget(preserve_pos,reindex)
local trg=self:currentTarget() local trg=self:currentTarget()
local filter=self.subviews.filter_input.text
if reindex then if reindex then
trg.keys={} trg.keys={}
for k,v in pairs(trg.target) do for k,v in pairs(trg.target) do
table.insert(trg.keys,k) if filter~= "" then
local ok,ret=dfhack.pcall(string.match,tostring(k),filter)
if not ok then
table.insert(trg.keys,k)
elseif ret then
table.insert(trg.keys,k)
end
else
table.insert(trg.keys,k)
end
end end
end end
self.subviews.lbl_current_item:itemById('name').text=tostring(trg.target) self.subviews.lbl_current_item:itemById('name').text=tostring(trg.target)
@ -310,15 +344,17 @@ function GmEditorUi:pushTarget(target_to_push)
new_tbl.target=target_to_push new_tbl.target=target_to_push
new_tbl.keys={} new_tbl.keys={}
new_tbl.selected=1 new_tbl.selected=1
new_tbl.filter=""
if self:currentTarget()~=nil then if self:currentTarget()~=nil then
self:currentTarget().selected=self.subviews.list_main:getSelected() self:currentTarget().selected=self.subviews.list_main:getSelected()
self.stack[#self.stack].filter=self.subviews.filter_input.text
end end
for k,v in pairs(target_to_push) do for k,v in pairs(target_to_push) do
table.insert(new_tbl.keys,k) table.insert(new_tbl.keys,k)
end end
new_tbl.item_count=#new_tbl.keys new_tbl.item_count=#new_tbl.keys
table.insert(self.stack,new_tbl) table.insert(self.stack,new_tbl)
self.subviews.filter_input.text=""
self:updateTarget() self:updateTarget()
end end
function GmEditorUi:popTarget() function GmEditorUi:popTarget()
@ -327,6 +363,7 @@ function GmEditorUi:popTarget()
self:dismiss() self:dismiss()
return return
end end
self.subviews.filter_input.text=self.stack[#self.stack].filter --restore filter
self:updateTarget() self:updateTarget()
end end
function show_editor(trg) function show_editor(trg)