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()
else
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:Show()
m.filter_input:SetFocus()
@@ -757,7 +758,7 @@ function private.get_form()
query_string = query_string == '' and part or query_string..'/'..part
end
add('"'..m.name_input:GetText()..'"')
add(Aux.filter.quote(m.name_input:GetText()))
if m.exact_checkbox:GetChecked() then
add('exact')
@@ -811,7 +812,7 @@ function private.set_form(components)
if name and strsub(name, 1, 1) == '"' and strsub(name, -1, -1) == '"' then
name = strsub(name, 2, -2)
end
m.name_input:SetText(name)
m.name_input:SetText(Aux.filter.unquote(filter[2]))
elseif filter[1] == 'exact' then
m.exact_checkbox:SetChecked(true)
elseif filter[1] == 'min_level' then
@@ -863,16 +864,18 @@ end
private.post_components = {}
function private.add_post_filter()
function private.add_post_component()
local name = UIDropDownMenu_GetSelectedValue(m.filter_dropdown)
if name then
local filter = name
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')
return
end
filter = filter..m.filter_input:GetText()
filter = filter..Aux.filter.operator_suffix(arity)
end
if Aux.filter.filters[name] and Aux.filter.filters[name].input_type ~= '' then
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()
end
end)
editbox:SetScript('OnEnterPressed', function()
this:ClearFocus()
m.execute()
end)
editbox:SetScript('OnEnterPressed', Aux.f(editbox.ClearFocus, editbox))
local label = Aux.gui.label(editbox, 13)
label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1)
label:SetText('Name')
@@ -418,10 +415,7 @@ Aux.search_tab.FRAMES(function(m, public, private)
m.max_level_input:SetFocus()
end
end)
editbox:SetScript('OnEnterPressed', function()
this:ClearFocus()
m.execute()
end)
editbox:SetScript('OnEnterPressed', Aux.f(editbox.ClearFocus, editbox))
local label = Aux.gui.label(editbox, 13)
label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1)
label:SetText('Level Range')
@@ -440,10 +434,7 @@ Aux.search_tab.FRAMES(function(m, public, private)
m.name_input:SetFocus()
end
end)
editbox:SetScript('OnEnterPressed', function()
this:ClearFocus()
m.execute()
end)
editbox:SetScript('OnEnterPressed', Aux.f(editbox.ClearFocus, editbox))
local label = Aux.gui.label(editbox, 13)
label:SetPoint('RIGHT', editbox, 'LEFT', -3.5, 0)
label:SetText('-')
@@ -539,7 +530,7 @@ Aux.search_tab.FRAMES(function(m, public, private)
btn:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
btn:SetScript('OnClick', function()
if arg1 == 'LeftButton' then
m.add_post_filter()
m.add_post_component()
elseif arg1 == 'RightButton' then
m.remove_post_filter()
end
@@ -551,12 +542,10 @@ Aux.search_tab.FRAMES(function(m, public, private)
input:SetPoint('LEFT', m.filter_dropdown, 'RIGHT', 10, 0)
input:SetWidth(150)
input:SetHeight(25)
-- editbox:SetNumeric(true)
-- editbox:SetMaxLetters(2)
input:SetScript('OnChar', function()
this:complete()
end)
input:SetScript('OnEnterPressed', m.add_post_filter)
input:SetScript('OnEnterPressed', m.add_post_component)
input:Hide()
private.filter_input = input
end
+29 -24
View File
@@ -518,13 +518,7 @@ function public.query_string(components)
for _, component in components.post do
if component[1] == 'operator' then
local suffix = ''
if not component[3] then
suffix = '*'
elseif component[3] > 2 then
suffix = component[3]
end
prettified.append(component[2]..suffix)
prettified.append(component[2]..m.operator_suffix(component[3]))
elseif component[1] == 'filter' then
prettified.append(component[2])
if component[3] then
@@ -553,13 +547,7 @@ function public.indented_post_query_string(components)
if component[1] == 'operator' and component[2] then
no_line_break = component[2] == 'not'
local suffix = ''
if not component[3] then
suffix = '*'
elseif component[3] > 2 then
suffix = component[3]
end
str = str..'|cffffff00'..component[2]..suffix..'|r'
str = str..'|cffffff00'..component[2]..m.operator_suffix(component[3])..'|r'
tinsert(stack, component[3] or '*')
elseif component[1] == 'filter' then
str = str..'|cffffff00'..component[2]..'|r'
@@ -586,17 +574,17 @@ function private.prettified_query_string(components)
for _, filter in components.blizzard do
blizzard_filters[filter[1]] = filter[2] or true
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
prettified.append(Aux.gui.inline_color({216, 225, 211, 1})..(filter[2] or filter[1])..'|r')
end
end
if not blizzard_filters.exact then
if blizzard_filters.name == '' then
if blizzard_filters.name and not blizzard_filters.exact then
if m.unquote(blizzard_filters.name) == '' then
prettified.prepend('|cffff0000'..'No Filter'..'|r')
elseif blizzard_filters.name then
prettified.prepend(Aux.gui.inline_color({216, 225, 211, 1})..blizzard_filters.name..'|r')
else
prettified.prepend(Aux.gui.inline_color({216, 225, 211, 1})..m.unquote(blizzard_filters.name)..'|r')
end
end
@@ -622,17 +610,34 @@ function private.prettified_query_string(components)
return prettified.get()
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)
local filters = {}
for _, filter in components.blizzard do
filters[filter[1]] = filter[2] or true
end
local name = 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 query = { name = filters.name and m.unquote(filters.name) }
local item_info, class_index, subclass_index, slot_index
if filters.exact then