diff --git a/tabs/search/filter.lua b/tabs/search/filter.lua index 49df42c..eda9cd5 100644 --- a/tabs/search/filter.lua +++ b/tabs/search/filter.lua @@ -192,7 +192,7 @@ function private.clear_form() UIDropDownMenu_ClearAll(m.subclass_dropdown) UIDropDownMenu_ClearAll(m.slot_dropdown) UIDropDownMenu_ClearAll(m.quality_dropdown) - m.filter_input:ClearFocus() + m.filter_parameter_input:ClearFocus() m.post_filter = {} m.filter_builder_state = {selected=0} m.update_filter_display() @@ -209,7 +209,7 @@ end function private.export_query_string() m.search_box:SetText(m.get_filter_builder_query()) - m.filter_input:ClearFocus() + m.filter_parameter_input:ClearFocus() end function public.formatted_post_filter(components) @@ -223,21 +223,22 @@ function public.formatted_post_filter(components) elseif i > 1 then str = str..'
' for _=1,getn(stack) do - str = str..aux.gui.inline_color.content.backdrop..'----'..FONT_COLOR_CODE_CLOSE + str = str..aux.gui.color.content.backdrop('----') end end no_line_break = component[1] == 'operator' and component[2] == 'not' - local component_text = component[2] + local filter_color = (m.filter_builder_state.selected == i and aux.gui.color.green or aux.gui.color.yellow) + local component_text = filter_color(component[2]) if component[1] == 'operator' and component[2] ~= 'not' then - component_text = component_text..(tonumber(component[3]) or '') + component_text = component_text..filter_color(tonumber(component[3]) or '') tinsert(stack, component[3]) elseif component[1] == 'filter' then - for _, parameter in {component[3]} do + for parameter in aux.util.present(component[3]) do if aux.filter.filters[component[2]].input_type == 'money' then parameter = aux.money.to_string(aux.money.from_string(parameter), nil, true, nil, nil, true) end - component_text = component_text..': '..aux.auction_listing.colors.ORANGE..parameter..FONT_COLOR_CODE_CLOSE or component_text + component_text = component_text..filter_color(': ')..aux.gui.color.orange(parameter) end while getn(stack) > 0 and stack[getn(stack)] do local top = tremove(stack) @@ -247,11 +248,6 @@ function public.formatted_post_filter(components) end end end - if m.filter_builder_state.selected == i then - component_text = aux.auction_listing.colors.GREEN..component_text..FONT_COLOR_CODE_CLOSE - else - component_text = aux.auction_listing.colors.YELLOW..component_text..FONT_COLOR_CODE_CLOSE - end str = str..m.data_link(i, component_text) end @@ -290,31 +286,23 @@ function private.add_component(component) tinsert(m.post_filter, m.filter_builder_state.selected, component) end -function private.add_dropdown_component() - for _, str in {UIDropDownMenu_GetSelectedValue(m.filter_dropdown)} do - if not aux.filter.filters[str] and str == 'and' or str == 'or' then - local arity = m.filter_input:GetText() - arity = tonumber(arity) and aux.util.round(tonumber(arity)) - if arity and arity < 2 then - aux.log('Invalid operator suffix') - return - end - str = str..(arity or '') - end - for _, filter in {aux.filter.filters[str]} do +function private.add_post_filter() + for str in aux.util.present(m.filter_input:GetText()) do + for filter in aux.util.present(aux.filter.filters[str]) do if filter.input_type ~= '' then - str = str..'/'..m.filter_input:GetText() + str = str..'/'..m.filter_parameter_input:GetText() end end local components, error, suggestions = aux.filter.parse_query_string(str) - if components then + if components and getn(components.blizzard) == 0 and getn(components.post) == 1 then m.add_component(components.post[1]) m.update_filter_display() - m.filter_input:SetText('') - m.filter_input:ClearFocus() - else + m.filter_parameter_input:SetText('') + m.filter_input:HighlightText() + m.filter_input:SetFocus() + elseif error then aux.log(error) end end @@ -357,25 +345,18 @@ function private.set_filter_display_offset(x_offset, y_offset) end function private.initialize_filter_dropdown() - local function on_click() - UIDropDownMenu_SetSelectedValue(m.filter_dropdown, this.value) - m.filter_button:SetText(this.value) - if (not aux.filter.filters[this.value] or aux.filter.filters[this.value].input_type == '') and this.value ~= 'and' and this.value ~= 'or' then - m.filter_input:Hide() - else - local _, _, suggestions = aux.filter.parse_query_string(UIDropDownMenu_GetSelectedValue(m.filter_dropdown)..'/') - m.filter_input:SetNumeric(not aux.filter.filters[this.value] or aux.filter.filters[this.value].input_type == 'number') - m.filter_input.complete = aux.completion.complete(function() return suggestions or {} end) - m.filter_input:Show() - m.filter_input:SetFocus() - end - end - - for _, filter in {'and', 'or', 'not', 'min-unit-buy', 'max-unit-bid', 'max-unit-bid', 'max-unit-buy', 'bid-profit', 'buy-profit', 'bid-vend-profit', 'buy-vend-profit', 'bid-dis-profit', 'buy-dis-profit', 'bid-pct', 'buy-pct', 'item', 'tooltip', 'min-lvl', 'max-lvl', 'rarity', 'left', 'utilizable', 'discard'} do + for _, filter in {'and', 'or', 'not', 'min-unit-bid', 'min-unit-buy', 'max-unit-bid', 'max-unit-buy', 'bid-profit', 'buy-profit', 'bid-vend-profit', 'buy-vend-profit', 'bid-dis-profit', 'buy-dis-profit', 'bid-pct', 'buy-pct', 'item', 'tooltip', 'min-lvl', 'max-lvl', 'rarity', 'left', 'utilizable', 'discard'} do UIDropDownMenu_AddButton{ text = filter, value = filter, - func = on_click, + func = function() + m.filter_input:SetText(this.value) + if aux.filter.filters[this.value] and aux.filter.filters[this.value].input_type ~= '' then + m.filter_parameter_input:SetFocus() + else + m.add_post_filter() + end + end, } end end diff --git a/tabs/search/frames.lua b/tabs/search/frames.lua index 0fbf85b..a59e493 100644 --- a/tabs/search/frames.lua +++ b/tabs/search/frames.lua @@ -500,7 +500,6 @@ function private.create_frames() dropdown:SetScript('OnShow', function() UIDropDownMenu_Initialize(this, m.initialize_slot_dropdown) end) - end do local dropdown = aux.gui.dropdown(m.frame.filter) @@ -531,31 +530,49 @@ function private.create_frames() private.filter_dropdown = dropdown end do - local btn = aux.gui.button(m.frame.filter, 16) - btn:SetWidth(150) - btn:SetHeight(25) - btn:SetPoint('CENTER', m.filter_dropdown, 'CENTER', 0, 0) - btn:RegisterForClicks('LeftButtonUp', 'RightButtonUp') - btn:SetScript('OnClick', function() - if arg1 == 'LeftButton' then - m.add_dropdown_component() - elseif arg1 == 'RightButton' then - m.remove_component() - end - end) - private.filter_button = btn + local input = aux.gui.editbox(m.frame.filter) + input:SetPoint('CENTER', m.filter_dropdown, 'CENTER', 0, 0) + input:SetWidth(150) + input:SetScript('OnTabPressed', function() + m.filter_parameter_input:SetFocus() + end) + input.complete = aux.completion.complete(function() return {'and', 'or', 'not', unpack(aux.util.keys(aux.filter.filters))} end) + input:SetScript('OnChar', function() + this:complete() + end) + input:SetScript('OnTextChanged', function() + local filter = this:GetText() + if aux.filter.filters[filter] and aux.filter.filters[filter].input_type ~= '' then + local _, _, suggestions = aux.filter.parse_query_string(filter..'/') + m.filter_parameter_input:SetNumeric(aux.filter.filters[filter].input_type == 'number') + m.filter_parameter_input.complete = aux.completion.complete(function() return suggestions or {} end) + m.filter_parameter_input:Show() + else + m.filter_parameter_input:Hide() + end + end) + input:SetScript('OnEnterPressed', function() + if m.filter_parameter_input:IsVisible() then + m.filter_parameter_input:SetFocus() + else + m.add_post_filter() + end + end) + private.filter_input = input end do local input = aux.gui.editbox(m.frame.filter) input:SetPoint('LEFT', m.filter_dropdown, 'RIGHT', 10, 0) input:SetWidth(150) - input:SetHeight(25) + input:SetScript('OnTabPressed', function() + m.filter_parameter_input:SetFocus() + end) input:SetScript('OnChar', function() this:complete() end) - input:SetScript('OnEnterPressed', m.add_dropdown_component) + input:SetScript('OnEnterPressed', m.add_post_filter) input:Hide() - private.filter_input = input + private.filter_parameter_input = input end do local scroll_frame = CreateFrame('ScrollFrame', nil, m.frame.filter) @@ -672,7 +689,7 @@ function private.create_frames() } private.recent_searches_listing = aux.listing.CreateScrollingTable(m.frame.saved.recent) - m.recent_searches_listing:SetColInfo({{name='Recent Searches', width=1}}) + m.recent_searches_listing:SetColInfo{{name='Recent Searches', width=1}} m.recent_searches_listing:EnableSorting(false) m.recent_searches_listing:DisableSelection(true) m.recent_searches_listing:SetHandler('OnClick', handlers.OnClick) @@ -680,7 +697,7 @@ function private.create_frames() m.recent_searches_listing:SetHandler('OnLeave', handlers.OnLeave) private.favorite_searches_listing = aux.listing.CreateScrollingTable(m.frame.saved.favorite) - m.favorite_searches_listing:SetColInfo({{name='Favorite Searches', width=1}}) + m.favorite_searches_listing:SetColInfo{{name='Favorite Searches', width=1}} m.favorite_searches_listing:EnableSorting(false) m.favorite_searches_listing:DisableSelection(true) m.favorite_searches_listing:SetHandler('OnClick', handlers.OnClick) diff --git a/util/core.lua b/util/core.lua index 5a98c79..463be4e 100644 --- a/util/core.lua +++ b/util/core.lua @@ -1,7 +1,13 @@ local m, public, private = aux.module'util' -function public.present(value) - return value ~= nil and {[value]=true} or {} +function public.present(...) + local called + return function() + if not called then + called = true + return unpack(arg) + end + end end function public.unpack(array, ...)