[todo] allow to move items in the list

This commit is contained in:
streetturtle 2020-08-11 21:15:38 -04:00
parent bf6c45fb3a
commit a2094f4d19
3 changed files with 60 additions and 4 deletions

BIN
todo-widget/down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

View File

@ -183,6 +183,7 @@ local function worker(args)
end) end)
end) end)
local trash_button = wibox.widget { local trash_button = wibox.widget {
{ {
{ image = WIDGET_DIR .. '/window-close-symbolic.svg', { image = WIDGET_DIR .. '/window-close-symbolic.svg',
@ -206,11 +207,57 @@ local function worker(args)
end) end)
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 { local row = wibox.widget {
{ {
{ {
{ {
checkbox, checkbox,
valign = 'center', valign = 'center',
layout = wibox.container.place, layout = wibox.container.place,
@ -224,6 +271,12 @@ local function worker(args)
left = 10, left = 10,
layout = wibox.container.margin layout = wibox.container.margin
}, },
{
{
move_buttons,
valign = 'center',
layout = wibox.container.place,
},
{ {
trash_button, trash_button,
valign = 'center', valign = 'center',
@ -232,6 +285,9 @@ local function worker(args)
spacing = 8, spacing = 8,
layout = wibox.layout.align.horizontal layout = wibox.layout.align.horizontal
}, },
spacing = 8,
layout = wibox.layout.align.horizontal
},
margins = 8, margins = 8,
layout = wibox.container.margin layout = wibox.container.margin
}, },

BIN
todo-widget/up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B