From a2094f4d1984482ef2a3a1b782de2e6238f59542 Mon Sep 17 00:00:00 2001 From: streetturtle Date: Tue, 11 Aug 2020 21:15:38 -0400 Subject: [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 (limited to 'todo-widget') diff --git a/todo-widget/down.png b/todo-widget/down.png new file mode 100644 index 0000000..a93d2a7 Binary files /dev/null and b/todo-widget/down.png 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 Binary files /dev/null and b/todo-widget/up.png differ -- cgit v1.2.3