diff --git a/changelog.txt b/changelog.txt index d84f46e54..74d7a8b98 100644 --- a/changelog.txt +++ b/changelog.txt @@ -33,6 +33,7 @@ Template for new versions: ## Fixes ## Misc Improvements +- `combine`: try harder to find the currently-selected stockpile ## Removed diff --git a/combine.lua b/combine.lua index 3253d28db..233c1b864 100644 --- a/combine.lua +++ b/combine.lua @@ -736,6 +736,26 @@ local function get_stockpile_here() -- return the stockpile as a table local stockpiles = {} local building = dfhack.gui.getSelectedStockpile(true) + + -- try finding the stockpile by viewed item or first item in itemlist viewsheet. + if building == nil then + local item = nil + if dfhack.gui.getSelectedItem(true) ~= nil then + item = dfhack.gui.getSelectedItem(true) + elseif tonumber(dfhack.DF_VERSION:match("^0*%.*(%d+%.%d+)")) >= 50.07 -- matchFocusString() in Commit a770a4c + and dfhack.gui.matchFocusString("dwarfmode/ViewSheets/ITEM_LIST", dfhack.gui.getDFViewscreen()) + and df.global.game.main_interface.view_sheets.open == true + and df.global.game.main_interface.view_sheets.active_sheet == df.view_sheet_type.ITEM_LIST + and #df.global.game.main_interface.view_sheets.viewing_itid > 0 + then + local itemid = df.global.game.main_interface.view_sheets.viewing_itid[0] + item = df.item.find(itemid) + end + local pos = (item) and xyz2pos(dfhack.items.getPosition(item)) or nil + building = (pos) and dfhack.buildings.findAtTile(pos) or nil + building = (df.building_stockpilest:is_instance(building)) and building or nil + end + if not building then qerror('Please select a stockpile.') end table.insert(stockpiles, building) if opts.verbose > 0 then diff --git a/docs/combine.rst b/docs/combine.rst index 9a0ec5f53..7dea93767 100644 --- a/docs/combine.rst +++ b/docs/combine.rst @@ -38,7 +38,9 @@ Commands ``all`` Search all stockpiles. ``here`` - Search the currently selected stockpile. + Search the currently selected stockpile, or the stockpile that the + currently-seelected item is in, or the stockpile that the currently- + displayed item-list is in. Options -------