From ef88779f0a43839efaa71c821b21105c80c2b693 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Fri, 16 Oct 2015 22:07:02 +0200 Subject: [PATCH] some autocomplete improvements --- buy.lua | 2 +- buy.xml | 8 +++----- completion.lua | 26 ++++++++++++++------------ scan.lua | 4 ++-- sell.lua | 2 +- util.lua | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/buy.lua b/buy.lua index 7b27e5e..1fcd411 100644 --- a/buy.lua +++ b/buy.lua @@ -79,7 +79,7 @@ function Aux.buy.SearchButton_onclick() current_page = page end, on_start_page = function(page, total_pages) - set_message('Scanning auctions: page ' .. page + 1 .. (total_pages and ' out of ' .. total_pages or '') .. ' ...') + set_message('Scanning auctions: page ' .. page + 1 .. (total_pages > 0 and ' out of ' .. total_pages or '') .. ' ...') end, on_read_auction = function(i) local auction_item = Aux.info.auction_item(i) diff --git a/buy.xml b/buy.xml index 98c3e1c..c85b5b8 100644 --- a/buy.xml +++ b/buy.xml @@ -91,9 +91,9 @@ - + this.completor = Aux.completion.completor(this) - + this.completor.suggest() @@ -105,9 +105,7 @@ end - if this.completor.open() then - this.completor.close() - end + this.completor.close() this:ClearFocus() Aux.buy.SearchButton_onclick() diff --git a/completion.lua b/completion.lua index 223cc99..c9424dd 100644 --- a/completion.lua +++ b/completion.lua @@ -104,21 +104,21 @@ function Aux.completion.completor(edit_box) end end - function self:close() + function self.close() CloseDropDownMenus(1) end - function self:set_quietly(text) + function self.set_quietly(text) quietly_set_text = text edit_box:SetText(text) end - function self:completed() - return index ~= 0 + function self.open() + local _, owner = DropDownList1:GetPoint() + return DropDownList1:IsVisible() and owner == edit_box end - function self:suggest() - + function self.suggest() local new_input = edit_box:GetText() if new_input == quietly_set_text then quietly_set_text = nil @@ -140,26 +140,28 @@ function Aux.completion.completor(edit_box) update_dropdown() end - function self:next() + function self.next() + update_dropdown() if getn(suggestions) > 0 then index = index > 0 and math.mod(index + 1, getn(suggestions) + 1) or 1 - self:update_highlighting() + update_highlighting() if index == 0 then - self:set_quietly(input) + self.set_quietly(input) else - self:set_quietly(suggestions[index]) + self.set_quietly(suggestions[index]) end end end function self.previous() + update_dropdown() if getn(suggestions) > 0 then index = index > 0 and index - 1 or getn(suggestions) update_highlighting() if index == 0 then - self:set_quietly(input) + self.set_quietly(input) else - self:set_quietly(suggestions[index]) + self.set_quietly(suggestions[index]) end end end diff --git a/scan.lua b/scan.lua index 7f09dc4..3bb7c5b 100644 --- a/scan.lua +++ b/scan.lua @@ -12,7 +12,7 @@ end)() local state, abort, new_job -local scan, scan_auctions, scan_auctions_helper, submit_query, wait_for_callback, wait_for_results, abort +local scan, scan_auctions, scan_auctions_helper, submit_query, wait_for_callback, wait_for_results, wait_for_complete_results, abort function Aux.scan.start(job) Aux.control.on_next_update(function() @@ -125,7 +125,7 @@ end function submit_query(k) if state.page then - wait_for_callback(state.job.on_start_page, {state.page, state.total_pages}, function() + wait_for_callback(state.job.on_start_page, {state.page, state.total_pages or 0}, function() controller().wait(CanSendAuctionQuery, function() if state.job.on_submit_query then state.job.on_submit_query() diff --git a/sell.lua b/sell.lua index 699df3a..1eaf515 100644 --- a/sell.lua +++ b/sell.lua @@ -342,7 +342,7 @@ function refresh_entries() }, page = 0, on_start_page = function(page, total_pages) - set_message('Scanning auctions: page ' .. page + 1 .. (total_pages and ' out of ' .. total_pages or '') .. ' ...') + set_message('Scanning auctions: page ' .. page + 1 .. (total_pages > 0 and ' out of ' .. total_pages or '') .. ' ...') end, on_read_auction = function(i) local auction_item = Aux.info.auction_item(i) diff --git a/util.lua b/util.lua index 3c152d5..ab29bde 100644 --- a/util.lua +++ b/util.lua @@ -240,7 +240,7 @@ function Aux.util.group_by(tables, keys) local groups = {} Aux.util.map(tables, function(table) for _, group in ipairs(groups) do - if Aux.util.all(keys, function(key) table[key] == group[1][key] end) then + if Aux.util.all(keys, function(key) return table[key] == group[1][key] end) then tinsert(group, table) return end