|
|
|
@@ -90,30 +90,44 @@ local _save_state = ya.sync(function(state, bookmarks)
|
|
|
|
|
ps.pub_to(0, "@bookmarks", save_state)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
local _save_last_directory = ya.sync(function(state, persist)
|
|
|
|
|
if persist then
|
|
|
|
|
ps.sub_remote("@bookmarks-lastdir", function(body)
|
|
|
|
|
state.curr_dir = body
|
|
|
|
|
state.curr_dir.on = state.last_directory_key
|
|
|
|
|
local _load_last = ya.sync(function(state)
|
|
|
|
|
ps.sub_remote("@bookmarks-last", function(body)
|
|
|
|
|
state.last_dir = body
|
|
|
|
|
|
|
|
|
|
if state.last_mode ~= "dir" then
|
|
|
|
|
ps.unsub_remote("@bookmarks-last")
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
ps.sub("cd", function()
|
|
|
|
|
local _save_last = ya.sync(function(state, persist, imediate)
|
|
|
|
|
local file = _get_bookmark_file()
|
|
|
|
|
state.last_dir = state.curr_dir
|
|
|
|
|
|
|
|
|
|
if persist and state.last_dir then
|
|
|
|
|
ps.pub_to(0, "@bookmarks-lastdir", state.last_dir)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
state.curr_dir = {
|
|
|
|
|
on = state.last_directory_key,
|
|
|
|
|
local curr = {
|
|
|
|
|
on = "'",
|
|
|
|
|
desc = _generate_description(file),
|
|
|
|
|
path = tostring(file.url),
|
|
|
|
|
is_parent = file.is_parent,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if imediate then
|
|
|
|
|
state.curr_dir = nil
|
|
|
|
|
state.last_dir = curr
|
|
|
|
|
else
|
|
|
|
|
state.last_dir = state.curr_dir
|
|
|
|
|
state.curr_dir = curr
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if persist and state.last_dir then
|
|
|
|
|
ps.pub_to(0, "@bookmarks-last", state.last_dir)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
local get_last_mode = ya.sync(function(state) return state.last_mode end)
|
|
|
|
|
|
|
|
|
|
local save_last_dir = ya.sync(function(state)
|
|
|
|
|
ps.sub("cd", function() _save_last(state.last_persist, false) end)
|
|
|
|
|
|
|
|
|
|
ps.sub("hover", function()
|
|
|
|
|
local file = _get_bookmark_file()
|
|
|
|
|
state.curr_dir.desc = _generate_description(file)
|
|
|
|
@@ -121,11 +135,17 @@ local _save_last_directory = ya.sync(function(state, persist)
|
|
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
local save_last_jump = ya.sync(function(state) _save_last(state.last_persist, true) end)
|
|
|
|
|
|
|
|
|
|
local save_last_mark = ya.sync(function(state) _save_last(state.last_persist, true) end)
|
|
|
|
|
|
|
|
|
|
local _is_custom_desc_input_enabled = ya.sync(function(state) return state.custom_desc_input end)
|
|
|
|
|
|
|
|
|
|
-- ***********************************************
|
|
|
|
|
-- **============= C O M M A N D S =============**
|
|
|
|
|
-- ***********************************************
|
|
|
|
|
|
|
|
|
|
local save_bookmark = ya.sync(function(state, idx)
|
|
|
|
|
local save_bookmark = ya.sync(function(state, idx, custom_desc)
|
|
|
|
|
local file = _get_bookmark_file()
|
|
|
|
|
|
|
|
|
|
state.bookmarks = state.bookmarks or {}
|
|
|
|
@@ -135,9 +155,14 @@ local save_bookmark = ya.sync(function(state, idx)
|
|
|
|
|
_idx = #state.bookmarks + 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local bookmark_desc = tostring(file.url)
|
|
|
|
|
if custom_desc then
|
|
|
|
|
bookmark_desc = tostring(custom_desc)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
state.bookmarks[_idx] = {
|
|
|
|
|
on = SUPPORTED_KEYS[idx].on,
|
|
|
|
|
desc = _generate_description(file),
|
|
|
|
|
desc = bookmark_desc,
|
|
|
|
|
path = tostring(file.url),
|
|
|
|
|
is_parent = file.is_parent,
|
|
|
|
|
}
|
|
|
|
@@ -174,6 +199,10 @@ local save_bookmark = ya.sync(function(state, idx)
|
|
|
|
|
message, _ = message:gsub("<folder>", state.bookmarks[_idx].desc)
|
|
|
|
|
_send_notification(message)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if get_last_mode() == "mark" then
|
|
|
|
|
save_last_mark()
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
local all_bookmarks = ya.sync(function(state, append_last_dir)
|
|
|
|
@@ -219,14 +248,6 @@ local delete_all_bookmarks = ya.sync(function(state)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
local jump_to_last = ya.sync(function(state)
|
|
|
|
|
if state.last_dir.is_parent then
|
|
|
|
|
ya.manager_emit("cd", { state.last_dir.is_parent })
|
|
|
|
|
else
|
|
|
|
|
ya.manager_emit("reveal", { state.last_dir.is_parent })
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
entry = function(_, job)
|
|
|
|
|
local action = job.args[1]
|
|
|
|
@@ -237,13 +258,26 @@ return {
|
|
|
|
|
if action == "save" then
|
|
|
|
|
local key = ya.which { cands = SUPPORTED_KEYS, silent = true }
|
|
|
|
|
if key then
|
|
|
|
|
if _is_custom_desc_input_enabled() then
|
|
|
|
|
local value, event = ya.input {
|
|
|
|
|
title = "Save with custom description:",
|
|
|
|
|
position = { "top-center", y = 3, w = 60 },
|
|
|
|
|
value = tostring(_get_bookmark_file().url),
|
|
|
|
|
}
|
|
|
|
|
if event ~= 1 then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
save_bookmark(key, value)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
save_bookmark(key)
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
elseif action == "delete_all" then
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if action == "delete_all" then
|
|
|
|
|
return delete_all_bookmarks()
|
|
|
|
|
elseif action == "jump_last" then
|
|
|
|
|
return jump_to_last()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local bookmarks = all_bookmarks(action == "jump")
|
|
|
|
@@ -253,6 +287,10 @@ return {
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if action == "jump" then
|
|
|
|
|
if get_last_mode() == "jump" then
|
|
|
|
|
save_last_jump()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if bookmarks[selected].is_parent then
|
|
|
|
|
ya.manager_emit("cd", { bookmarks[selected].path })
|
|
|
|
|
else
|
|
|
|
@@ -269,12 +307,26 @@ return {
|
|
|
|
|
|
|
|
|
|
if type(args.last_directory) == "table" then
|
|
|
|
|
if args.last_directory.enable then
|
|
|
|
|
state.last_directory_key = "'"
|
|
|
|
|
if type(args.last_directory.key) == "string" then
|
|
|
|
|
state.last_directory_key = args.last_directory.key
|
|
|
|
|
if args.last_directory.mode == "mark" then
|
|
|
|
|
state.last_persist = args.last_directory.persist
|
|
|
|
|
state.last_mode = "mark"
|
|
|
|
|
elseif args.last_directory.mode == "jump" then
|
|
|
|
|
state.last_persist = args.last_directory.persist
|
|
|
|
|
state.last_mode = "jump"
|
|
|
|
|
elseif args.last_directory.mode == "dir" then
|
|
|
|
|
state.last_persist = args.last_directory.persist
|
|
|
|
|
state.last_mode = "dir"
|
|
|
|
|
save_last_dir()
|
|
|
|
|
else
|
|
|
|
|
-- default
|
|
|
|
|
state.last_persist = args.last_directory.persist
|
|
|
|
|
state.last_mode = "dir"
|
|
|
|
|
save_last_dir()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
_save_last_directory(args.last_directory.persist)
|
|
|
|
|
if args.last_directory.persist then
|
|
|
|
|
_load_last()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@@ -295,6 +347,10 @@ return {
|
|
|
|
|
state.file_pick_mode = "hover"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if type(args.custom_desc_input) == "boolean" then
|
|
|
|
|
state.custom_desc_input = args.custom_desc_input
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
state.notify = {
|
|
|
|
|
enable = false,
|
|
|
|
|
timeout = 1,
|
|
|
|
|