Rename active_widget for selected_app_widget and a public method to retrive it's value

This commit is contained in:
Ksaper 2023-03-02 03:31:09 +02:00
parent c6581734d8
commit 468e4d9119
1 changed files with 19 additions and 15 deletions

View File

@ -85,7 +85,7 @@ end
local function scroll(self, dir) local function scroll(self, dir)
if #self:get_grid().children < 1 then if #self:get_grid().children < 1 then
self._private.active_widget = nil self._private.selected_app_widget = nil
return return
end end
@ -93,16 +93,16 @@ local function scroll(self, dir)
local if_cant_scroll_func = nil local if_cant_scroll_func = nil
if dir == "up" then if dir == "up" then
next_app_index = self:get_grid():index(self._private.active_widget) - 1 next_app_index = self:get_grid():index(self:get_selected_app_widget()) - 1
if_cant_scroll_func = function() self:page_backward("up") end if_cant_scroll_func = function() self:page_backward("up") end
elseif dir == "down" then elseif dir == "down" then
next_app_index = self:get_grid():index(self._private.active_widget) + 1 next_app_index = self:get_grid():index(self:get_selected_app_widget()) + 1
if_cant_scroll_func = function() self:page_forward("down") end if_cant_scroll_func = function() self:page_forward("down") end
elseif dir == "left" then elseif dir == "left" then
next_app_index = self:get_grid():index(self._private.active_widget) - self:get_grid().forced_num_rows next_app_index = self:get_grid():index(self:get_selected_app_widget()) - self:get_grid().forced_num_rows
if_cant_scroll_func = function() self:page_backward("left") end if_cant_scroll_func = function() self:page_backward("left") end
elseif dir == "right" then elseif dir == "right" then
next_app_index = self:get_grid():index(self._private.active_widget) + self:get_grid().forced_num_rows next_app_index = self:get_grid():index(self:get_selected_app_widget()) + self:get_grid().forced_num_rows
if_cant_scroll_func = function() self:page_forward("right") end if_cant_scroll_func = function() self:page_forward("right") end
end end
@ -236,10 +236,10 @@ local function app_widget(self, app)
end end
function widget:select() function widget:select()
if app_launcher._private.active_widget then if app_launcher:get_selected_app_widget() then
app_launcher._private.active_widget:unselect() app_launcher:get_selected_app_widget():unselect()
end end
app_launcher._private.active_widget = self app_launcher._private.selected_app_widget = self
self:emit_signal("select") self:emit_signal("select")
self.selected = true self.selected = true
@ -253,7 +253,7 @@ local function app_widget(self, app)
function widget:unselect() function widget:unselect()
self:emit_signal("unselect") self:emit_signal("unselect")
self.selected = false self.selected = false
app_launcher._private.active_widget = nil app_launcher._private.selected_app_widget = nil
if app_launcher.app_template == nil then if app_launcher.app_template == nil then
widget.bg = app_launcher.app_normal_color widget.bg = app_launcher.app_normal_color
@ -263,7 +263,7 @@ local function app_widget(self, app)
end end
function widget:is_selected() function widget:is_selected()
return app_launcher._private.active_widget == self return app_launcher._private.selected_app_widget == self
end end
function app:run() widget:run() end function app:run() widget:run() end
@ -424,8 +424,8 @@ local function build_widget(self)
self:hide() self:hide()
end end
if key == "Return" then if key == "Return" then
if self._private.active_widget ~= nil then if self:get_selected_app_widget() ~= nil then
self._private.active_widget:run() self:get_selected_app_widget():run()
end end
end end
if key == "Up" then if key == "Up" then
@ -492,7 +492,7 @@ end
function app_launcher:search() function app_launcher:search()
local text = self:get_text() local text = self:get_text()
local old_pos = self:get_grid():get_widget_position(self._private.active_widget) local old_pos = self:get_grid():get_widget_position(self:get_selected_app_widget())
-- Reset all the matched apps -- Reset all the matched apps
self._private.matched_apps = {} self._private.matched_apps = {}
@ -594,7 +594,7 @@ function app_launcher:page_forward(dir)
return return
end end
local pos = self:get_grid():get_widget_position(self._private.active_widget) local pos = self:get_grid():get_widget_position(self:get_selected_app_widget())
-- Remove the current page apps from the grid -- Remove the current page apps from the grid
self:get_grid():reset() self:get_grid():reset()
@ -639,7 +639,7 @@ function app_launcher:page_backward(dir)
return return
end end
local pos = self:get_grid():get_widget_position(self._private.active_widget) local pos = self:get_grid():get_widget_position(self:get_selected_app_widget())
-- Remove the current page apps from the grid -- Remove the current page apps from the grid
self:get_grid():reset() self:get_grid():reset()
@ -750,6 +750,10 @@ function app_launcher:get_text()
return self._private.text return self._private.text
end end
function app_launcher:get_selected_app_widget()
return self._private.selected_app_widget
end
local function new(args) local function new(args)
args = args or {} args = args or {}