Skip to content

Commit

Permalink
show tagged tools as autocomplete options when a tag is typed
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Sep 10, 2023
1 parent 2b81eab commit ea4e560
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Template for new versions:
## Misc Improvements
- `autofish`: changed ``--raw`` argument format to allow explicit setting to on or off
- `caravan`: move goods to depot screen can now see/search/trade items inside of barrels and pots
- `gui/launcher`: show tagged tools in the autocomplete list when a tag name is typed

## Removed

Expand Down
20 changes: 13 additions & 7 deletions gui/launcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ function HelpPanel:add_output(output)
if text_len > SCROLLBACK_CHARS then
text = text:sub(-SCROLLBACK_CHARS)
local text_diff = text_len - #text
HelpPanel_update_label(label, label.text_to_wrap:sub(text_len - #text))
HelpPanel_update_label(label, label.text_to_wrap:sub(text_diff))
text_height = label:getTextHeight()
label:scroll('end')
line_num = label.start_line_num
Expand Down Expand Up @@ -699,30 +699,36 @@ local function add_top_related_entries(entries, entry, n)
end

function LauncherUI:update_autocomplete(firstword)
local includes = {{str=firstword, types='command'}}
local excludes
if helpdb.is_tag(firstword) then
table.insert(includes, {tag=firstword, types='command'})
end
if not dev_mode then
excludes = {tag={'dev', 'unavailable'}}
if dfhack.getHideArmokTools() then
if dfhack.getHideArmokTools() and firstword ~= 'armok' then
table.insert(excludes.tag, 'armok')
end
end
local entries = helpdb.search_entries({str=firstword, types='command'}, excludes)
local entries = helpdb.search_entries(includes, excludes)
-- if firstword is in the list, extract it so we can add it to the top later
-- even if it's not in the list, add it back anyway if it's a valid db entry
-- (e.g. if it's a dev script that we masked out) to show that it's a valid
-- command
local found = extract_entry(entries,firstword) or helpdb.is_entry(firstword)
local found = extract_entry(entries, firstword) or helpdb.is_entry(firstword)
sort_by_freq(entries)
if found then
if helpdb.is_tag(firstword) then
self.subviews.autocomplete_label:setText("Tagged tools")
elseif found then
table.insert(entries, 1, firstword)
self.subviews.autocomplete_label:setText("Similar scripts")
self.subviews.autocomplete_label:setText("Similar tools")
add_top_related_entries(entries, firstword, 20)
else
self.subviews.autocomplete_label:setText("Suggestions")
end

if #firstword == 0 then
self.subviews.autocomplete_label:setText("All scripts")
self.subviews.autocomplete_label:setText("All tools")
end

self.subviews.autocomplete:set_options(entries, found)
Expand Down

0 comments on commit ea4e560

Please sign in to comment.