From c6cbd00ae2b4604adc52ba6661e208a2c81d781d Mon Sep 17 00:00:00 2001 From: SilasD Date: Sat, 29 Nov 2025 11:09:50 -0800 Subject: [PATCH 1/3] combine.lua try harder to find the currently-selected stockpile If a stockpile is not selected, try finding it using these: * If an item is selected, find the stockpile (if any) that it is in. * If a dwarfmode/ViewSheets/ITEM_LIST is active in the UI, find the stockpile (if any) of the tile being viewed. --- changelog.txt | 1 + combine.lua | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/changelog.txt b/changelog.txt index 5268f53622..edb075539c 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 3253d28db3..a20d4fbf3b 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(--[[silent]]true) ~= nil then + item = dfhack.gui.getSelectedItem(--[[silent]]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 From eaa53cf86fda1659902c03276d79d93d0216f971 Mon Sep 17 00:00:00 2001 From: SilasD Date: Sat, 29 Nov 2025 11:19:30 -0800 Subject: [PATCH 2/3] combine.lua update documentation Note: I did not try to rebuild the documentation .txt and .html files. --- docs/combine.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/combine.rst b/docs/combine.rst index 9a0ec5f530..7dea937672 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 ------- From d4712b808d37919cd267b7d9460b8f9b8e877b34 Mon Sep 17 00:00:00 2001 From: SilasD Date: Fri, 5 Dec 2025 07:48:31 -0800 Subject: [PATCH 3/3] remove useless cruft this delta removes two inline comments which uselessly documented a function parameter. minimal testing -- one minute total to test the four ways that stockpiles can be selected. --- combine.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/combine.lua b/combine.lua index a20d4fbf3b..233c1b8649 100644 --- a/combine.lua +++ b/combine.lua @@ -740,8 +740,8 @@ local function get_stockpile_here() -- try finding the stockpile by viewed item or first item in itemlist viewsheet. if building == nil then local item = nil - if dfhack.gui.getSelectedItem(--[[silent]]true) ~= nil then - item = dfhack.gui.getSelectedItem(--[[silent]]true) + 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