added notification for delete and delete_all

This commit is contained in:
Diogo Duarte
2024-03-12 14:49:57 +00:00
parent e1ca89ed7f
commit 5a908d31d5

View File

@@ -25,12 +25,12 @@ local save_bookmark = ya.sync(function(state, idx)
}
if state.notify.enable then
local description = state.notify.format
description, _ = description:gsub("<key>", SUPPORTED_KEYS[idx].on)
description, _ = description:gsub("<folder>", tostring(folder.cwd))
local message = state.notify.message.new
message, _ = message:gsub("<key>", SUPPORTED_KEYS[idx].on)
message, _ = message:gsub("<folder>", tostring(folder.cwd))
ya.notify {
title = "Bookmarks",
content = description,
content = message,
timeout = state.notify.timeout,
}
end
@@ -38,9 +38,32 @@ end)
local all_bookmarks = ya.sync(function(state) return state.bookmarks or {} end)
local delete_bookmark = ya.sync(function(state, idx) table.remove(state.bookmarks, idx) end)
local delete_bookmark = ya.sync(function(state, idx)
if state.notify.enable then
local message = state.notify.message.delete
message, _ = message:gsub("<key>", state.bookmarks[idx].on)
message, _ = message:gsub("<folder>", state.bookmarks[idx].desc)
ya.notify {
title = "Bookmarks",
content = message,
timeout = state.notify.timeout,
}
end
local delete_all_bookmarks = ya.sync(function(state) state.bookmarks = nil end)
table.remove(state.bookmarks, idx)
end)
local delete_all_bookmarks = ya.sync(function(state)
state.bookmarks = nil
if state.notify.enable then
ya.notify {
title = "Bookmarks",
content = state.notify.message.delete_all,
timeout = state.notify.timeout,
}
end
end)
return {
entry = function(_, args)
@@ -80,16 +103,32 @@ return {
return
end
state.notify = { enable = false, timeout = 2, format = "New bookmark in '<key>' -> '<folder>'" }
if args.notify ~= nil then
state.notify = {
enable = false,
timeout = 1,
message = {
new = "New bookmark '<key>' -> '<folder>'",
delete = "Deleted bookmark in '<key>'",
delete_all = "Deleted all bookmarks",
},
}
if type(args.notify) == "table" then
if type(args.notify.enable) == "boolean" then
state.notify.enable = args.notify.enable
end
if type(args.notify.timeout) == "number" then
state.notify.timeout = args.notify.timeout
end
if type(args.notify.format) == "string" then
state.notify.format = args.notify.format
if type(args.notify.message) == "table" then
if type(args.notify.message.new) == "string" then
state.notify.message.new = args.notify.message.new
end
if type(args.notify.message.delete) == "string" then
state.notify.message.delete = args.notify.message.delete
end
if type(args.notify.message.delete_all) == "string" then
state.notify.message.delete_all = args.notify.message.delete_all
end
end
end
end,