From a2094f4d1984482ef2a3a1b782de2e6238f59542 Mon Sep 17 00:00:00 2001 From: streetturtle Date: Tue, 11 Aug 2020 21:15:38 -0400 Subject: [PATCH] [todo] allow to move items in the list --- todo-widget/down.png | Bin 0 -> 384 bytes todo-widget/todo.lua | 64 ++++++++++++++++++++++++++++++++++++++++--- todo-widget/up.png | Bin 0 -> 363 bytes 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 todo-widget/down.png create mode 100644 todo-widget/up.png diff --git a/todo-widget/down.png b/todo-widget/down.png new file mode 100644 index 0000000000000000000000000000000000000000..a93d2a7385e51d88043bfc96e44a6c4b7d515c79 GIT binary patch literal 384 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4v zn&8Bxy^;IG-FNeP)dj;ZM(xjav11 zfvGP~21RD)KJ5t6FAkaNx&Aw!|MQwBSH$!MlSC`d{eI7MX(QhqCehSMvkh!!oloEW z_M1ym_j5@dX67|fm!od;t24ADE}!GM>wr+o_d|kvrrase2^2qYO4>5RB#VE3-2~+> zzqH`=bq%f$_#~J@7wFI7ef4$izVDs!>WuS0Z)Z{l>fCYur+db>DC4s)Djr@xV&4{i YeM-E}^BJ)^z<^-zboFyt=akR{03~OZlK=n! literal 0 HcmV?d00001 diff --git a/todo-widget/todo.lua b/todo-widget/todo.lua index befe51e..71484b2 100644 --- a/todo-widget/todo.lua +++ b/todo-widget/todo.lua @@ -183,6 +183,7 @@ local function worker(args) end) end) + local trash_button = wibox.widget { { { image = WIDGET_DIR .. '/window-close-symbolic.svg', @@ -206,11 +207,57 @@ local function worker(args) end) end) + + local move_up = wibox.widget { + image = WIDGET_DIR .. '/up.png', + resize = false, + widget = wibox.widget.imagebox + } + + move_up:connect_signal("button::press", function(c) + local temp = result.todo_items[i] + result.todo_items[i] = result.todo_items[i-1] + result.todo_items[i-1] = temp + spawn.easy_async_with_shell("printf '" .. json.encode(result) .. "' > " .. STORAGE, function () + spawn.easy_async(GET_TODO_ITEMS, function(stdout) update_widget(stdout) end) + end) + end) + + local move_down = wibox.widget { + image = WIDGET_DIR .. '/down.png', + resize = false, + widget = wibox.widget.imagebox + } + + move_down:connect_signal("button::press", function(c) + local temp = result.todo_items[i] + result.todo_items[i] = result.todo_items[i+1] + result.todo_items[i+1] = temp + spawn.easy_async_with_shell("printf '" .. json.encode(result) .. "' > " .. STORAGE, function () + spawn.easy_async(GET_TODO_ITEMS, function(stdout) update_widget(stdout) end) + end) + end) + + + local move_buttons = { + layout = wibox.layout.fixed.vertical + } + + if 1 == #result.todo_items then + -- one item, no need in arrows + elseif i == 1 then + table.insert(move_buttons, move_down) + elseif i == #result.todo_items then + table.insert(move_buttons, move_up) + else + table.insert(move_buttons, move_up) + table.insert(move_buttons, move_down) + end + local row = wibox.widget { { { { - checkbox, valign = 'center', layout = wibox.container.place, @@ -225,9 +272,18 @@ local function worker(args) layout = wibox.container.margin }, { - trash_button, - valign = 'center', - layout = wibox.container.place, + { + move_buttons, + valign = 'center', + layout = wibox.container.place, + }, + { + trash_button, + valign = 'center', + layout = wibox.container.place, + }, + spacing = 8, + layout = wibox.layout.align.horizontal }, spacing = 8, layout = wibox.layout.align.horizontal diff --git a/todo-widget/up.png b/todo-widget/up.png new file mode 100644 index 0000000000000000000000000000000000000000..0579121d6939258a50f75b563c4ae3117b8774af GIT binary patch literal 363 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR40%5D96xjc1ah|#8WTW(h!&Pr@D=%ksaS=V2vb0kB*tdSBhLca;Mfb=~(U0Bc z^YPbfRz~@V&W(vO?z`vTJyN(uIN3Qtw;(X|Mg38^nYzg?tlJ|G0R7D1>FVdQ&MBb@ E00N1T3IG5A literal 0 HcmV?d00001