From 0fb920834cb2f4c3338553746e55cf954481e739 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Fri, 30 Sep 2016 22:01:39 +0200 Subject: [PATCH] refactoring --- tabs/search/core.lua | 2 +- tabs/search/filter.lua | 36 +++++++++++++++---------------- tabs/search/frame.lua | 48 +++++++++++++++++++++--------------------- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/tabs/search/core.lua b/tabs/search/core.lua index 1ca0f6b..d88753b 100644 --- a/tabs/search/core.lua +++ b/tabs/search/core.lua @@ -60,7 +60,7 @@ function public.execute(resume, real_time) aux_search_tab_results.execute(resume, real_time) end -function private.subtab.set(tab) +function public.subtab.set(tab) search_results_button:UnlockHighlight() saved_searches_button:UnlockHighlight() new_filter_button:UnlockHighlight() diff --git a/tabs/search/filter.lua b/tabs/search/filter.lua index 9855418..4e37872 100644 --- a/tabs/search/filter.lua +++ b/tabs/search/filter.lua @@ -12,12 +12,12 @@ end local filter_util = aux_filter_util -function private.valid_level(str) +function public.valid_level(str) local level = tonumber(str) return level and bounded(1, 60, level) end -private.blizzard_query = setmetatable(t, { +public.blizzard_query = setmetatable(t, { __index = function(_, key) if key == 'name' then return name_input:GetText() @@ -30,16 +30,16 @@ private.blizzard_query = setmetatable(t, { elseif key == 'usable' then return usable_checkbox:GetChecked() elseif key == 'class' then - local class_index = UIDropDownMenu_GetSelectedValue(class_dropdown) + local class_index = UIDropDownMenu_GetSelectedValue(aux_search_tab.class_dropdown) return (class_index or 0) > 0 and class_index or nil elseif key == 'subclass' then - local subclass_index = UIDropDownMenu_GetSelectedValue(subclass_dropdown) + local subclass_index = UIDropDownMenu_GetSelectedValue(aux_search_tab.subclass_dropdown) return (subclass_index or 0) > 0 and subclass_index or nil elseif key == 'slot' then - local slot_index = UIDropDownMenu_GetSelectedValue(slot_dropdown) + local slot_index = UIDropDownMenu_GetSelectedValue(aux_search_tab.slot_dropdown) return (slot_index or 0) > 0 and slot_index or nil elseif key == 'quality' then - local quality_code = UIDropDownMenu_GetSelectedValue(quality_dropdown) + local quality_code = UIDropDownMenu_GetSelectedValue(aux_search_tab.quality_dropdown) return (quality_code or -1) >= 0 and quality_code or nil end end, @@ -70,7 +70,7 @@ private.blizzard_query = setmetatable(t, { end, }) -function private.update_form() +function public.update_form() if blizzard_query.class and GetAuctionItemSubClasses(blizzard_query.class) then subclass_dropdown.button:Enable() else @@ -186,14 +186,14 @@ function private.clear_form() update_filter_display() end -function private.import_filter_string() +function public.import_filter_string() local filter, error = filter_util.parse_filter_string(select(3, strfind(search_box:GetText(), '^([^;]*)'))) if filter or print(error) then set_form(filter) end end -function private.export_filter_string() +function public.export_filter_string() search_box:SetText(get_filter_builder_query()) filter_parameter_input:ClearFocus() end @@ -296,7 +296,7 @@ end do local text = '' - function private.update_filter_display() + function public.update_filter_display() text = formatted_post_filter(post_filter) filter_display:SetWidth(filter_display_size()) set_filter_display_offset() @@ -328,7 +328,7 @@ function private.set_filter_display_offset(x_offset, y_offset) scroll_frame:SetVerticalScroll(bounded(y_lower_bound, y_upper_bound, y_offset)) end -function private.initialize_filter_dropdown() +function public.initialize_filter_dropdown() for filter in temp-S('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(T( 'text', filter, @@ -348,7 +348,7 @@ function private.initialize_filter_dropdown() end end -function private.initialize_class_dropdown() +function public.initialize_class_dropdown() local function on_click() if this.value ~= blizzard_query.class then UIDropDownMenu_SetSelectedValue(class_dropdown, this.value) @@ -365,7 +365,7 @@ function private.initialize_class_dropdown() end end -function private.initialize_subclass_dropdown() +function public.initialize_subclass_dropdown() local function on_click() if this.value ~= blizzard_query.subclass then UIDropDownMenu_SetSelectedValue(subclass_dropdown, this.value) @@ -374,7 +374,7 @@ function private.initialize_subclass_dropdown() update_form() end end - local class_index = UIDropDownMenu_GetSelectedValue(class_dropdown) + local class_index = UIDropDownMenu_GetSelectedValue(aux_search_tab.class_dropdown) if class_index and GetAuctionItemSubClasses(class_index) then UIDropDownMenu_AddButton(T('text', ALL, 'value', 0, 'func', on_click)) for i, subclass in temp-A(GetAuctionItemSubClasses(class_index)) do @@ -383,13 +383,13 @@ function private.initialize_subclass_dropdown() end end -function private.initialize_slot_dropdown() +function public.initialize_slot_dropdown() local function on_click() UIDropDownMenu_SetSelectedValue(slot_dropdown, this.value) update_form() end - local class_index = UIDropDownMenu_GetSelectedValue(class_dropdown) - local subclass_index = UIDropDownMenu_GetSelectedValue(subclass_dropdown) + local class_index = UIDropDownMenu_GetSelectedValue(aux_search_tab.class_dropdown) + local subclass_index = UIDropDownMenu_GetSelectedValue(aux_search_tab.subclass_dropdown) if subclass_index and GetAuctionInvTypes(class_index, subclass_index) then UIDropDownMenu_AddButton(T('text', ALL, 'value', '', 'func', on_click)) for i, slot in temp-A(GetAuctionInvTypes(class_index, subclass_index)) do @@ -398,7 +398,7 @@ function private.initialize_slot_dropdown() end end -function private.initialize_quality_dropdown() +function public.initialize_quality_dropdown() local function on_click() UIDropDownMenu_SetSelectedValue(quality_dropdown, this.value) update_form() diff --git a/tabs/search/frame.lua b/tabs/search/frame.lua index c35ee7d..b112803 100644 --- a/tabs/search/frame.lua +++ b/tabs/search/frame.lua @@ -6,7 +6,7 @@ local FILTER_SPACING = 28.5 function public.create() setfenv(1, getfenv(2)) - private.frame = CreateFrame('Frame', nil, AuxFrame) + public.frame = CreateFrame('Frame', nil, AuxFrame) frame:SetAllPoints() frame:SetScript('OnUpdate', on_update) frame:Hide() @@ -327,19 +327,19 @@ function public.create() btn1:SetPoint('TOPLEFT', status_bar_frame, 'TOPRIGHT', 5, 0) btn1:SetText('Search') btn1:SetScript('OnClick', function() - export_filter_string() + aux_search_tab_filter.export_filter_string() execute() end) local btn2 = gui.button(frame.filter) btn2:SetPoint('LEFT', btn1, 'RIGHT', 5, 0) btn2:SetText('Export') - btn2:SetScript('OnClick', export_filter_string) + btn2:SetScript('OnClick', aux_search_tab_filter.export_filter_string) local btn3 = gui.button(frame.filter) btn3:SetPoint('LEFT', btn2, 'RIGHT', 5, 0) btn3:SetText('Import') - btn3:SetScript('OnClick', import_filter_string) + btn3:SetScript('OnClick', aux_search_tab_filter.import_filter_string) end do local editbox = gui.editbox(frame.filter) @@ -347,12 +347,12 @@ function public.create() editbox:SetPoint('TOPLEFT', 14, -FILTER_SPACING) editbox:SetWidth(260) editbox.char = function() - if blizzard_query.exact then + if aux_search_tab_filter.blizzard_query.exact then this:complete_item() end end editbox:SetScript('OnTabPressed', function() - if blizzard_query.exact then + if aux_search_tab_filter.blizzard_query.exact then return end if IsShiftKeyDown() then @@ -361,7 +361,7 @@ function public.create() min_level_input:SetFocus() end end) - editbox.change = update_form + editbox.change = aux_search_tab_filter.update_form editbox.enter = papply(editbox.ClearFocus, editbox) local label = gui.label(editbox, gui.font_size.small) label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1) @@ -371,7 +371,7 @@ function public.create() do local checkbox = gui.checkbox(frame.filter) checkbox:SetPoint('TOPLEFT', name_input, 'TOPRIGHT', 16, 0) - checkbox:SetScript('OnClick', update_form) + checkbox:SetScript('OnClick', aux_search_tab_filter.update_form) local label = gui.label(checkbox, gui.font_size.small) label:SetPoint('BOTTOMLEFT', checkbox, 'TOPLEFT', -2, 1) label:SetText('Exact') @@ -391,11 +391,11 @@ function public.create() end) editbox.enter = papply(editbox.ClearFocus, editbox) editbox.change = function() - local valid_level = valid_level(this:GetText()) + local valid_level = aux_search_tab_filter.valid_level(this:GetText()) if tostring(valid_level) ~= this:GetText() then this:SetText(valid_level or '') end - update_form() + aux_search_tab_filter.update_form() end local label = gui.label(editbox, gui.font_size.small) label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1) @@ -416,11 +416,11 @@ function public.create() end) editbox.enter = papply(editbox.ClearFocus, editbox) editbox.change = function() - local valid_level = valid_level(this:GetText()) + local valid_level = aux_search_tab_filter.valid_level(this:GetText()) if tostring(valid_level) ~= this:GetText() then this:SetText(valid_level or '') end - update_form() + aux_search_tab_filter.update_form() end local label = gui.label(editbox, gui.font_size.medium) label:SetPoint('RIGHT', editbox, 'LEFT', -3, 0) @@ -430,7 +430,7 @@ function public.create() do local checkbox = gui.checkbox(frame.filter) checkbox:SetPoint('TOPLEFT', max_level_input, 'TOPRIGHT', 16, 0) - checkbox:SetScript('OnClick', update_form) + checkbox:SetScript('OnClick', aux_search_tab_filter.update_form) local label = gui.label(checkbox, gui.font_size.small) label:SetPoint('BOTTOMLEFT', checkbox, 'TOPLEFT', -2, 1) label:SetText('Usable') @@ -444,9 +444,9 @@ function public.create() local label = gui.label(dropdown, gui.font_size.small) label:SetPoint('BOTTOMLEFT', dropdown, 'TOPLEFT', -2, -3) label:SetText('Item Class') - UIDropDownMenu_Initialize(dropdown, initialize_class_dropdown) + UIDropDownMenu_Initialize(dropdown, aux_search_tab_filter.initialize_class_dropdown) dropdown:SetScript('OnShow', function() - UIDropDownMenu_Initialize(this, initialize_class_dropdown) + UIDropDownMenu_Initialize(this, aux_search_tab_filter.initialize_class_dropdown) end) end do @@ -457,9 +457,9 @@ function public.create() local label = gui.label(dropdown, gui.font_size.small) label:SetPoint('BOTTOMLEFT', dropdown, 'TOPLEFT', -2, -3) label:SetText('Item Subclass') - UIDropDownMenu_Initialize(dropdown, initialize_subclass_dropdown) + UIDropDownMenu_Initialize(dropdown, aux_search_tab_filter.initialize_subclass_dropdown) dropdown:SetScript('OnShow', function() - UIDropDownMenu_Initialize(this, initialize_subclass_dropdown) + UIDropDownMenu_Initialize(this, aux_search_tab_filter.initialize_subclass_dropdown) end) end do @@ -470,9 +470,9 @@ function public.create() local label = gui.label(dropdown, gui.font_size.small) label:SetPoint('BOTTOMLEFT', dropdown, 'TOPLEFT', -2, -3) label:SetText('Item Slot') - UIDropDownMenu_Initialize(dropdown, initialize_slot_dropdown) + UIDropDownMenu_Initialize(dropdown, aux_search_tab_filter.initialize_slot_dropdown) dropdown:SetScript('OnShow', function() - UIDropDownMenu_Initialize(this, initialize_slot_dropdown) + UIDropDownMenu_Initialize(this, aux_search_tab_filter.initialize_slot_dropdown) end) end do @@ -483,9 +483,9 @@ function public.create() local label = gui.label(dropdown, gui.font_size.small) label:SetPoint('BOTTOMLEFT', dropdown, 'TOPLEFT', -2, -3) label:SetText('Min Quality') - UIDropDownMenu_Initialize(dropdown, initialize_quality_dropdown) + UIDropDownMenu_Initialize(dropdown, aux_search_tab_filter.initialize_quality_dropdown) dropdown:SetScript('OnShow', function() - UIDropDownMenu_Initialize(this, initialize_quality_dropdown) + UIDropDownMenu_Initialize(this, aux_search_tab_filter.initialize_quality_dropdown) end) end gui.vertical_line(frame.filter, 332) @@ -493,9 +493,9 @@ function public.create() local dropdown = gui.dropdown(frame.filter) dropdown:SetPoint('TOPRIGHT', -174.5, -10) dropdown:SetWidth(150) - UIDropDownMenu_Initialize(dropdown, initialize_filter_dropdown) + UIDropDownMenu_Initialize(dropdown, aux_search_tab_filter.initialize_filter_dropdown) dropdown:SetScript('OnShow', function() - UIDropDownMenu_Initialize(this, initialize_filter_dropdown) + UIDropDownMenu_Initialize(this, aux_search_tab_filter.initialize_filter_dropdown) end) _G[dropdown:GetName() .. 'Text']:Hide() local label = gui.label(dropdown, gui.font_size.medium) @@ -552,7 +552,7 @@ function public.create() scroll_frame:SetScript('OnMouseWheel', function() local child = this:GetScrollChild() child:SetFont('p', [[Fonts\ARIALN.TTF]], bounded(11, 23, select(2, child:GetFont()) + arg1*2)) - update_filter_display() + aux_search_tab_filter.update_filter_display() end) scroll_frame:RegisterForDrag('LeftButton') scroll_frame:SetScript('OnDragStart', function()