From da3707e4c53331e1618a911a88a65ff467ef8594 Mon Sep 17 00:00:00 2001 From: Alexander Yakushev Date: Thu, 4 Nov 2010 18:47:48 +0200 Subject: Reworked current playlist Now it displays at maximum 15 tracks before and 15 tracks after the current track. --- awesompd.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/awesompd.lua b/awesompd.lua index 7d49bc0..ac864a9 100644 --- a/awesompd.lua +++ b/awesompd.lua @@ -293,12 +293,15 @@ function awesompd:get_list_menu() if self.recreate_list then local new_menu = {} if self.list_array then - for i = 1, table.getn(self.list_array) do - new_menu[i] = { awesompd.protect_string(self.list_array[i]), - self:command_play_specific(i), - self.current_number == i and - (self.status == "Playing" and self.ICONS.PLAY or self.ICONS.PAUSE) - or nil} + local total_count = table.getn(self.list_array) + local start_num = (self.current_number - 15 > 0) and self.current_number - 15 or 1 + local end_num = (self.current_number + 15 < total_count ) and self.current_number + 15 or total_count + for i = start_num, end_num do + table.insert(new_menu, { awesompd.protect_string(self.list_array[i]), + self:command_play_specific(i), + self.current_number == i and + (self.status == "Playing" and self.ICONS.PLAY or self.ICONS.PAUSE) + or nil} ) end end self.recreate_list = false @@ -306,7 +309,7 @@ function awesompd:get_list_menu() end return self.list_menu end - + -- Returns the playlists menu. Menu consists of all files in the playlist folder. function awesompd:get_playlists_menu() if self.recreate_playlists then -- cgit v1.2.3