From 8436988ae71d08b87b45e3b67c70e3573459b70a Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Sun, 1 May 2016 18:34:20 +0200 Subject: [PATCH] editbox refactoring --- gui.lua | 17 +++++++++++++++++ post_frame.lua | 24 ------------------------ search_frame.lua | 44 -------------------------------------------- 3 files changed, 17 insertions(+), 68 deletions(-) diff --git a/gui.lua b/gui.lua index 4c22d5c..f88cf3c 100644 --- a/gui.lua +++ b/gui.lua @@ -284,6 +284,23 @@ function m.editbox(parent, name) editbox:SetBackdropColor(unpack(m.config.content_color)) editbox:SetBackdropBorderColor(unpack(m.config.content_border_color)) + editbox:SetScript('OnEscapePressed', function() + this:HighlightText(0, 0) + this:ClearFocus() + end) + + local last_time, last_x, last_y + editbox:SetScript('OnMouseUp', function() + local x, y = GetCursorPosition() + if last_time and last_time > GetTime() - .5 and abs(x - last_x) < 10 and abs(y - last_y) < 10 then + this:HighlightText() + last_time = nil + else + last_time = GetTime() + last_x, last_y = GetCursorPosition() + end + end) + -- local label = frame:CreateFontString(nil, 'OVERLAY') -- label:SetPoint('TOPLEFT', 0, -2) -- label:SetPoint('TOPRIGHT', 0, -2) diff --git a/post_frame.lua b/post_frame.lua index 91df65e..4369c54 100644 --- a/post_frame.lua +++ b/post_frame.lua @@ -272,12 +272,6 @@ function public.on_load() private.write_settings(settings) end end) - slider.editbox:SetScript('OnEscapePressed', function() - this:ClearFocus() - end) - slider.editbox:SetScript('OnEditFocusGained', function() - this:HighlightText() - end) slider.editbox:SetScript('OnEditFocusLost', function() this:HighlightText(0, 0) end) @@ -309,12 +303,6 @@ function public.on_load() slider:SetValue(this:GetNumber()) private.quantity_update() end) - slider.editbox:SetScript('OnEscapePressed', function() - this:ClearFocus() - end) - slider.editbox:SetScript('OnEditFocusGained', function() - this:HighlightText() - end) slider.editbox:SetScript('OnEditFocusLost', function() this:HighlightText(0, 0) end) @@ -384,12 +372,6 @@ function public.on_load() editbox:SetScript('OnEnterPressed', function() this:ClearFocus() end) - editbox:SetScript('OnEscapePressed', function() - this:ClearFocus() - end) - editbox:SetScript('OnEditFocusGained', function() - this:HighlightText() - end) editbox:SetScript('OnEditFocusLost', function() this:SetText(Aux.money.to_string(private.get_unit_start_price(), true, nil, 3)) end) @@ -425,12 +407,6 @@ function public.on_load() editbox:SetScript('OnEnterPressed', function() this:ClearFocus() end) - editbox:SetScript('OnEscapePressed', function() - this:ClearFocus() - end) - editbox:SetScript('OnEditFocusGained', function() - this:HighlightText() - end) editbox:SetScript('OnEditFocusLost', function() this:SetText(Aux.money.to_string(private.get_unit_buyout_price(), true, nil, 3)) end) diff --git a/search_frame.lua b/search_frame.lua index 61f7122..7ab389a 100644 --- a/search_frame.lua +++ b/search_frame.lua @@ -257,26 +257,6 @@ function public.on_load() this:ClearFocus() public.start_search() end) - editbox:SetScript('OnEscapePressed', function() - this:HighlightText(0, 0) - this:ClearFocus() - end) - editbox:SetScript('OnEditFocusGained', function() - this:HighlightText() - end) - do - local last_time, last_x, last_y - editbox:SetScript('OnMouseUp', function() - local x, y = GetCursorPosition() - if last_time and last_time > GetTime() - .5 and abs(x - last_x) < 10 and abs(y - last_y) < 10 then - this:HighlightText() - last_time = nil - else - last_time = GetTime() - last_x, last_y = GetCursorPosition() - end - end) - end editbox:SetScript('OnReceiveDrag', function() local item_info = Aux.cursor_item() and Aux.info.item(Aux.cursor_item().item_id) if item_info then @@ -425,12 +405,6 @@ function public.on_load() this:ClearFocus() public.start_search() end) - editbox:SetScript('OnEscapePressed', function() - this:ClearFocus() - end) - editbox:SetScript('OnEditFocusGained', function() - this:HighlightText() - end) local label = Aux.gui.label(editbox, 13) label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1) label:SetText('Name') @@ -462,12 +436,6 @@ function public.on_load() this:ClearFocus() public.start_search() end) - editbox:SetScript('OnEscapePressed', function() - this:ClearFocus() - end) - editbox:SetScript('OnEditFocusGained', function() - this:HighlightText() - end) local label = Aux.gui.label(editbox, 13) label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1) label:SetText('Level Range') @@ -489,12 +457,6 @@ function public.on_load() this:ClearFocus() public.start_search() end) - editbox:SetScript('OnEscapePressed', function() - this:ClearFocus() - end) - editbox:SetScript('OnEditFocusGained', function() - this:HighlightText() - end) local label = Aux.gui.label(editbox, 13) label:SetPoint('RIGHT', editbox, 'LEFT', -3, 0) label:SetText('-') @@ -729,12 +691,6 @@ function public.on_load() editbox:SetScript('OnEnterPressed', function() on_click() end) - editbox:SetScript('OnEscapePressed', function() - this:ClearFocus() - end) - editbox:SetScript('OnEditFocusGained', function() - this:HighlightText() - end) tinsert(btn.inputs, editbox) end end