summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@gmail.com>2020-08-11 21:15:38 -0400
committerstreetturtle <streetturtle@gmail.com>2020-08-11 21:15:38 -0400
commita2094f4d1984482ef2a3a1b782de2e6238f59542 (patch)
treef2946a73e8b598ef08427ea46133314ec8457968
parentbf6c45fb3a96baf8a39cabdf460f200b82a9de89 (diff)
[todo] allow to move items in the list
-rw-r--r--todo-widget/down.pngbin0 -> 384 bytes
-rw-r--r--todo-widget/todo.lua64
-rw-r--r--todo-widget/up.pngbin0 -> 363 bytes
3 files changed, 60 insertions, 4 deletions
diff --git a/todo-widget/down.png b/todo-widget/down.png
new file mode 100644
index 0000000..a93d2a7
--- /dev/null
+++ b/todo-widget/down.png
Binary files differ
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 0000000..0579121
--- /dev/null
+++ b/todo-widget/up.png
Binary files differ