Allow to insert ints and other simple types. Also allow inserting of same base type as the container.

Also simplify it a bit.
develop
Warmist 2016-04-30 22:10:01 +03:00
parent 208eb6f452
commit 3ee829f05b
1 changed files with 15 additions and 11 deletions

@ -212,21 +212,25 @@ end
function GmEditorUi:insertNew(typename) function GmEditorUi:insertNew(typename)
local tp=typename local tp=typename
if typename == nil then if typename == nil then
dialog.showInputPrompt("Class type","Input class type:",COLOR_WHITE,"",self:callback("insertNew")) dialog.showInputPrompt("Class type","Input class type or leave empty for auto and '*' for new ptr type auto:",COLOR_WHITE,"",self:callback("insertNew"))
return return
end end
local trg=self:currentTarget()
if trg.target and trg.target._kind and trg.target._kind=="container" then
if tp == "" then
trg.target:resize(#trg.target+1)
elseif tp== "*" then
trg.target:insert("#",{new=true})
else
local ntype=df[tp] local ntype=df[tp]
if ntype== nil then if ntype== nil then
dialog.showMessage("Error!","Type '"..tp.." not found",COLOR_LIGHTRED) dialog.showMessage("Error!","Type '"..tp.." not found",COLOR_RED)
return return
end end
trg.target:insert("#",{new=ntype})
local trg=self:currentTarget() end
if trg.target and trg.target._kind and trg.target._kind=="container" then self:updateTarget(true,true)
local thing=ntype:new()
dfhack.call_with_finalizer(1,false,df.delete,thing,function (tscreen,target,to_insert)
target:insert("#",to_insert); tscreen:updateTarget(true,true);end,self,trg.target,thing)
end end
end end
function GmEditorUi:deleteSelected(key) function GmEditorUi:deleteSelected(key)