Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Changelog
DFHack future
=============

Lua
---
- `gui/gm-editor` it's now possible to insert default types to containers. For primitive types leave the type entry empty, for references use ``*``.

DFHack 0.42.06-r1
=================

Expand Down
26 changes: 15 additions & 11 deletions scripts/gui/gm-editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,26 @@ function GmEditorUi:find_id()
end
function GmEditorUi:insertNew(typename)
local tp=typename
if typename== nil then
dialog.showInputPrompt("Class type","Input class type:",COLOR_WHITE,"",self:callback("insertNew"))
return
end
local ntype=df[tp]
if ntype== nil then
dialog.showMessage("Error!","Type '"..tp.." not found",COLOR_LIGHTRED)
if typename == nil then
dialog.showInputPrompt("Class type","You can:\n * Enter type name (without 'df.')\n * Leave empty for default type and 'nil' value\n * Enter '*' for default type and 'new' constructed pointer value",COLOR_WHITE,"",self:callback("insertNew"))
return
end

local trg=self:currentTarget()
if trg.target and trg.target._kind and trg.target._kind=="container" then
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)

if tp == "" then
trg.target:resize(#trg.target+1)
elseif tp== "*" then
trg.target:insert("#",{new=true})
else
local ntype=df[tp]
if ntype== nil then
dialog.showMessage("Error!","Type '"..tp.." not found",COLOR_RED)
return
end
trg.target:insert("#",{new=ntype})
end
self:updateTarget(true,true)
end
end
function GmEditorUi:deleteSelected(key)
Expand Down