From c084c9bb5d76630c5a3c8b0b62485b384d9884f6 Mon Sep 17 00:00:00 2001 From: Ksaper Date: Mon, 27 Feb 2023 11:15:31 +0200 Subject: [PATCH] Add a method to get the current page + pass the current page in the page signals --- widget/app_launcher/init.lua | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/widget/app_launcher/init.lua b/widget/app_launcher/init.lua index 6a79551..01d812d 100644 --- a/widget/app_launcher/init.lua +++ b/widget/app_launcher/init.lua @@ -461,7 +461,7 @@ function app_launcher:set_favorites(favorites) end function app_launcher:refresh() - local max_app_index_to_include = self._private.apps_per_page * self._private.current_page + local max_app_index_to_include = self._private.apps_per_page * self:get_current_page() local min_app_index_to_include = max_app_index_to_include - self._private.apps_per_page self:get_grid():reset() @@ -555,10 +555,10 @@ function app_launcher:page_forward(dir) local min_app_index_to_include = 0 local max_app_index_to_include = self._private.apps_per_page - if self._private.current_page < self._private.pages_count then - min_app_index_to_include = self._private.apps_per_page * self._private.current_page - self._private.current_page = self._private.current_page + 1 - max_app_index_to_include = self._private.apps_per_page * self._private.current_page + if self:get_current_page() < self._private.pages_count then + min_app_index_to_include = self._private.apps_per_page * self:get_current_page() + self._private.current_page = self:get_current_page() + 1 + max_app_index_to_include = self._private.apps_per_page * self:get_current_page() elseif self.wrap_page_scrolling and #self._private.matched_apps >= self._private.max_apps_per_page then self._private.current_page = 1 min_app_index_to_include = 0 @@ -583,7 +583,7 @@ function app_launcher:page_forward(dir) end end - if self._private.current_page > 1 or self.wrap_page_scrolling then + if self:get_current_page() > 1 or self.wrap_page_scrolling then local app = nil if dir == "down" then app = self:get_grid():get_widgets_at(1, 1)[1] @@ -599,12 +599,12 @@ function app_launcher:page_forward(dir) app:select() end - self:emit_signal("page::forward", dir) + self:emit_signal("page::forward", dir, self:get_current_page()) end function app_launcher:page_backward(dir) - if self._private.current_page > 1 then - self._private.current_page = self._private.current_page - 1 + if self:get_current_page() > 1 then + self._private.current_page = self:get_current_page() - 1 elseif self.wrap_page_scrolling and #self._private.matched_apps >= self._private.max_apps_per_page then self._private.current_page = self._private.pages_count elseif self.wrap_app_scrolling then @@ -620,7 +620,7 @@ function app_launcher:page_backward(dir) -- Remove the current page apps from the grid self:get_grid():reset() - local max_app_index_to_include = self._private.apps_per_page * self._private.current_page + local max_app_index_to_include = self._private.apps_per_page * self:get_current_page() local min_app_index_to_include = max_app_index_to_include - self._private.apps_per_page for index, app in ipairs(self._private.matched_apps) do @@ -631,7 +631,7 @@ function app_launcher:page_backward(dir) end local app = nil - if self._private.current_page < self._private.pages_count then + if self:get_current_page() < self._private.pages_count then if dir == "up" then app = self:get_grid().children[#self:get_grid().children] else @@ -644,7 +644,7 @@ function app_launcher:page_backward(dir) end app:select() - self:emit_signal("page::backward", dir) + self:emit_signal("page::backward", dir, self:get_current_page()) end function app_launcher:show() @@ -713,6 +713,10 @@ function app_launcher:get_grid() return self._private.grid end +function app_launcher:get_current_page() + return self._private.current_page +end + local function new(args) args = args or {}