filter arity input inprovement

This commit is contained in:
Manuel Simon Hirsig
2016-08-02 08:41:58 +02:00
parent 7b3aedd206
commit c1e79c63d8
3 changed files with 42 additions and 45 deletions
+8 -5
View File
@@ -735,6 +735,7 @@ function private.initialize_filter_dropdown()
m.filter_input:Hide() m.filter_input:Hide()
else else
local _, _, suggestions = Aux.filter.parse_query_string(UIDropDownMenu_GetSelectedValue(m.filter_dropdown)..'/') local _, _, suggestions = Aux.filter.parse_query_string(UIDropDownMenu_GetSelectedValue(m.filter_dropdown)..'/')
m.filter_input:SetNumeric(Aux.safe(Aux.filter.filters[this.value]).input_type/'number' == 'number')
m.filter_input.complete = Aux.completion.complete(function() return suggestions or {} end) m.filter_input.complete = Aux.completion.complete(function() return suggestions or {} end)
m.filter_input:Show() m.filter_input:Show()
m.filter_input:SetFocus() m.filter_input:SetFocus()
@@ -757,7 +758,7 @@ function private.get_form()
query_string = query_string == '' and part or query_string..'/'..part query_string = query_string == '' and part or query_string..'/'..part
end end
add('"'..m.name_input:GetText()..'"') add(Aux.filter.quote(m.name_input:GetText()))
if m.exact_checkbox:GetChecked() then if m.exact_checkbox:GetChecked() then
add('exact') add('exact')
@@ -811,7 +812,7 @@ function private.set_form(components)
if name and strsub(name, 1, 1) == '"' and strsub(name, -1, -1) == '"' then if name and strsub(name, 1, 1) == '"' and strsub(name, -1, -1) == '"' then
name = strsub(name, 2, -2) name = strsub(name, 2, -2)
end end
m.name_input:SetText(name) m.name_input:SetText(Aux.filter.unquote(filter[2]))
elseif filter[1] == 'exact' then elseif filter[1] == 'exact' then
m.exact_checkbox:SetChecked(true) m.exact_checkbox:SetChecked(true)
elseif filter[1] == 'min_level' then elseif filter[1] == 'min_level' then
@@ -863,16 +864,18 @@ end
private.post_components = {} private.post_components = {}
function private.add_post_filter() function private.add_post_component()
local name = UIDropDownMenu_GetSelectedValue(m.filter_dropdown) local name = UIDropDownMenu_GetSelectedValue(m.filter_dropdown)
if name then if name then
local filter = name local filter = name
if not Aux.filter.filters[name] and filter == 'and' or filter == 'or' then if not Aux.filter.filters[name] and filter == 'and' or filter == 'or' then
if m.filter_input:GetText() ~= '' and m.filter_input:GetText() ~= '*' and (tonumber(m.filter_input:GetText() or 3 <= 2)) then local arity = m.filter_input:GetText()
arity = tonumber(arity) and Aux.round(tonumber(arity))
if arity and arity < 2 then
Aux.log('Invalid operator suffix') Aux.log('Invalid operator suffix')
return return
end end
filter = filter..m.filter_input:GetText() filter = filter..Aux.filter.operator_suffix(arity)
end end
if Aux.filter.filters[name] and Aux.filter.filters[name].input_type ~= '' then if Aux.filter.filters[name] and Aux.filter.filters[name].input_type ~= '' then
filter = filter..'/'..m.filter_input:GetText() filter = filter..'/'..m.filter_input:GetText()
+5 -16
View File
@@ -386,10 +386,7 @@ Aux.search_tab.FRAMES(function(m, public, private)
m.min_level_input:SetFocus() m.min_level_input:SetFocus()
end end
end) end)
editbox:SetScript('OnEnterPressed', function() editbox:SetScript('OnEnterPressed', Aux.f(editbox.ClearFocus, editbox))
this:ClearFocus()
m.execute()
end)
local label = Aux.gui.label(editbox, 13) local label = Aux.gui.label(editbox, 13)
label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1) label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1)
label:SetText('Name') label:SetText('Name')
@@ -418,10 +415,7 @@ Aux.search_tab.FRAMES(function(m, public, private)
m.max_level_input:SetFocus() m.max_level_input:SetFocus()
end end
end) end)
editbox:SetScript('OnEnterPressed', function() editbox:SetScript('OnEnterPressed', Aux.f(editbox.ClearFocus, editbox))
this:ClearFocus()
m.execute()
end)
local label = Aux.gui.label(editbox, 13) local label = Aux.gui.label(editbox, 13)
label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1) label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1)
label:SetText('Level Range') label:SetText('Level Range')
@@ -440,10 +434,7 @@ Aux.search_tab.FRAMES(function(m, public, private)
m.name_input:SetFocus() m.name_input:SetFocus()
end end
end) end)
editbox:SetScript('OnEnterPressed', function() editbox:SetScript('OnEnterPressed', Aux.f(editbox.ClearFocus, editbox))
this:ClearFocus()
m.execute()
end)
local label = Aux.gui.label(editbox, 13) local label = Aux.gui.label(editbox, 13)
label:SetPoint('RIGHT', editbox, 'LEFT', -3.5, 0) label:SetPoint('RIGHT', editbox, 'LEFT', -3.5, 0)
label:SetText('-') label:SetText('-')
@@ -539,7 +530,7 @@ Aux.search_tab.FRAMES(function(m, public, private)
btn:RegisterForClicks('LeftButtonUp', 'RightButtonUp') btn:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
btn:SetScript('OnClick', function() btn:SetScript('OnClick', function()
if arg1 == 'LeftButton' then if arg1 == 'LeftButton' then
m.add_post_filter() m.add_post_component()
elseif arg1 == 'RightButton' then elseif arg1 == 'RightButton' then
m.remove_post_filter() m.remove_post_filter()
end end
@@ -551,12 +542,10 @@ Aux.search_tab.FRAMES(function(m, public, private)
input:SetPoint('LEFT', m.filter_dropdown, 'RIGHT', 10, 0) input:SetPoint('LEFT', m.filter_dropdown, 'RIGHT', 10, 0)
input:SetWidth(150) input:SetWidth(150)
input:SetHeight(25) input:SetHeight(25)
-- editbox:SetNumeric(true)
-- editbox:SetMaxLetters(2)
input:SetScript('OnChar', function() input:SetScript('OnChar', function()
this:complete() this:complete()
end) end)
input:SetScript('OnEnterPressed', m.add_post_filter) input:SetScript('OnEnterPressed', m.add_post_component)
input:Hide() input:Hide()
private.filter_input = input private.filter_input = input
end end
+29 -24
View File
@@ -518,13 +518,7 @@ function public.query_string(components)
for _, component in components.post do for _, component in components.post do
if component[1] == 'operator' then if component[1] == 'operator' then
local suffix = '' prettified.append(component[2]..m.operator_suffix(component[3]))
if not component[3] then
suffix = '*'
elseif component[3] > 2 then
suffix = component[3]
end
prettified.append(component[2]..suffix)
elseif component[1] == 'filter' then elseif component[1] == 'filter' then
prettified.append(component[2]) prettified.append(component[2])
if component[3] then if component[3] then
@@ -553,13 +547,7 @@ function public.indented_post_query_string(components)
if component[1] == 'operator' and component[2] then if component[1] == 'operator' and component[2] then
no_line_break = component[2] == 'not' no_line_break = component[2] == 'not'
local suffix = '' str = str..'|cffffff00'..component[2]..m.operator_suffix(component[3])..'|r'
if not component[3] then
suffix = '*'
elseif component[3] > 2 then
suffix = component[3]
end
str = str..'|cffffff00'..component[2]..suffix..'|r'
tinsert(stack, component[3] or '*') tinsert(stack, component[3] or '*')
elseif component[1] == 'filter' then elseif component[1] == 'filter' then
str = str..'|cffffff00'..component[2]..'|r' str = str..'|cffffff00'..component[2]..'|r'
@@ -586,17 +574,17 @@ function private.prettified_query_string(components)
for _, filter in components.blizzard do for _, filter in components.blizzard do
blizzard_filters[filter[1]] = filter[2] or true blizzard_filters[filter[1]] = filter[2] or true
if filter[1] == 'exact' then if filter[1] == 'exact' then
prettified.prepend(Aux.info.display_name(Aux.cache.item_id(blizzard_filters.name)) or Aux.gui.inline_color({216, 225, 211, 1})..'['..blizzard_filters.name..']|r') prettified.prepend(Aux.info.display_name(Aux.cache.item_id(m.unquote(blizzard_filters.name))) or Aux.gui.inline_color({216, 225, 211, 1})..'['..m.unquote(blizzard_filters.name)..']|r')
elseif filter[1] ~= 'name' then elseif filter[1] ~= 'name' then
prettified.append(Aux.gui.inline_color({216, 225, 211, 1})..(filter[2] or filter[1])..'|r') prettified.append(Aux.gui.inline_color({216, 225, 211, 1})..(filter[2] or filter[1])..'|r')
end end
end end
if not blizzard_filters.exact then if blizzard_filters.name and not blizzard_filters.exact then
if blizzard_filters.name == '' then if m.unquote(blizzard_filters.name) == '' then
prettified.prepend('|cffff0000'..'No Filter'..'|r') prettified.prepend('|cffff0000'..'No Filter'..'|r')
elseif blizzard_filters.name then else
prettified.prepend(Aux.gui.inline_color({216, 225, 211, 1})..blizzard_filters.name..'|r') prettified.prepend(Aux.gui.inline_color({216, 225, 211, 1})..m.unquote(blizzard_filters.name)..'|r')
end end
end end
@@ -622,17 +610,34 @@ function private.prettified_query_string(components)
return prettified.get() return prettified.get()
end end
function public.quote(name)
return '<'..name..'>'
end
function public.unquote(name)
if name and strsub(name, 1, 1) == '<' and strsub(name, -1, -1) == '>' then
name = strsub(name, 2, -2)
end
return name
end
function public.operator_suffix(arity)
if not arity then
return '*'
elseif arity == 2 then
return ''
else
return arity
end
end
function private.blizzard_query(components) function private.blizzard_query(components)
local filters = {} local filters = {}
for _, filter in components.blizzard do for _, filter in components.blizzard do
filters[filter[1]] = filter[2] or true filters[filter[1]] = filter[2] or true
end end
local name = filters.name local query = { name = filters.name and m.unquote(filters.name) }
if name and strsub(name, 1, 1) == '"' and strsub(name, -1, -1) == '"' then
name = strsub(name, 2, -2)
end
local query = { name=name }
local item_info, class_index, subclass_index, slot_index local item_info, class_index, subclass_index, slot_index
if filters.exact then if filters.exact then