Use new `CommandView:enter` options table
This commit is contained in:
parent
e4a806a9d0
commit
11e27c6fda
|
@ -48,36 +48,42 @@ command.add(nil, {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:reload-module"] = function()
|
["core:reload-module"] = function()
|
||||||
core.command_view:enter("Reload Module", function(text, item)
|
core.command_view:enter("Reload Module", {
|
||||||
local text = item and item.text or text
|
submit = function(text, item)
|
||||||
core.reload_module(text)
|
local text = item and item.text or text
|
||||||
core.log("Reloaded module %q", text)
|
core.reload_module(text)
|
||||||
end, function(text)
|
core.log("Reloaded module %q", text)
|
||||||
local items = {}
|
end,
|
||||||
for name in pairs(package.loaded) do
|
suggest = function(text)
|
||||||
table.insert(items, name)
|
local items = {}
|
||||||
|
for name in pairs(package.loaded) do
|
||||||
|
table.insert(items, name)
|
||||||
|
end
|
||||||
|
return common.fuzzy_match(items, text)
|
||||||
end
|
end
|
||||||
return common.fuzzy_match(items, text)
|
})
|
||||||
end)
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:find-command"] = function()
|
["core:find-command"] = function()
|
||||||
local commands = command.get_all_valid()
|
local commands = command.get_all_valid()
|
||||||
core.command_view:enter("Do Command", function(text, item)
|
core.command_view:enter("Do Command", {
|
||||||
if item then
|
submit = function(text, item)
|
||||||
command.perform(item.command)
|
if item then
|
||||||
|
command.perform(item.command)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
suggest = function(text)
|
||||||
|
local res = common.fuzzy_match(commands, text)
|
||||||
|
for i, name in ipairs(res) do
|
||||||
|
res[i] = {
|
||||||
|
text = command.prettify_name(name),
|
||||||
|
info = keymap.get_binding(name),
|
||||||
|
command = name,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return res
|
||||||
end
|
end
|
||||||
end, function(text)
|
})
|
||||||
local res = common.fuzzy_match(commands, text)
|
|
||||||
for i, name in ipairs(res) do
|
|
||||||
res[i] = {
|
|
||||||
text = command.prettify_name(name),
|
|
||||||
info = keymap.get_binding(name),
|
|
||||||
command = name,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
return res
|
|
||||||
end)
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:find-file"] = function()
|
["core:find-file"] = function()
|
||||||
|
@ -91,12 +97,15 @@ command.add(nil, {
|
||||||
table.insert(files, common.home_encode(path .. item.filename))
|
table.insert(files, common.home_encode(path .. item.filename))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
core.command_view:enter("Open File From Project", function(text, item)
|
core.command_view:enter("Open File From Project", {
|
||||||
text = item and item.text or text
|
submit = function(text, item)
|
||||||
core.root_view:open_doc(core.open_doc(common.home_expand(text)))
|
text = item and item.text or text
|
||||||
end, function(text)
|
core.root_view:open_doc(core.open_doc(common.home_expand(text)))
|
||||||
return common.fuzzy_match_with_recents(files, core.visited_files, text)
|
end,
|
||||||
end)
|
suggest = function(text)
|
||||||
|
return common.fuzzy_match_with_recents(files, core.visited_files, text)
|
||||||
|
end
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:new-doc"] = function()
|
["core:new-doc"] = function()
|
||||||
|
@ -104,12 +113,11 @@ command.add(nil, {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:new-named-doc"] = function()
|
["core:new-named-doc"] = function()
|
||||||
core.command_view:enter(
|
core.command_view:enter("File name", {
|
||||||
"File name",
|
submit = function(text)
|
||||||
function(text)
|
|
||||||
core.root_view:open_doc(core.open_doc(text))
|
core.root_view:open_doc(core.open_doc(text))
|
||||||
end
|
end
|
||||||
)
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:open-file"] = function()
|
["core:open-file"] = function()
|
||||||
|
@ -122,30 +130,34 @@ command.add(nil, {
|
||||||
core.command_view:set_text(text)
|
core.command_view:set_text(text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
core.command_view:enter("Open File", function(text)
|
core.command_view:enter("Open File", {
|
||||||
local filename = system.absolute_path(common.home_expand(text))
|
submit = function(text)
|
||||||
core.root_view:open_doc(core.open_doc(filename))
|
local filename = system.absolute_path(common.home_expand(text))
|
||||||
end, function (text)
|
core.root_view:open_doc(core.open_doc(filename))
|
||||||
return common.home_encode_list(common.path_suggest(common.home_expand(text)))
|
end,
|
||||||
end, nil, function(text)
|
suggest = function (text)
|
||||||
local filename = common.home_expand(text)
|
return common.home_encode_list(common.path_suggest(common.home_expand(text)))
|
||||||
local path_stat, err = system.get_file_info(filename)
|
end,
|
||||||
if err then
|
validate = function(text)
|
||||||
if err:find("No such file", 1, true) then
|
local filename = common.home_expand(text)
|
||||||
-- check if the containing directory exists
|
local path_stat, err = system.get_file_info(filename)
|
||||||
local dirname = common.dirname(filename)
|
if err then
|
||||||
local dir_stat = dirname and system.get_file_info(dirname)
|
if err:find("No such file", 1, true) then
|
||||||
if not dirname or (dir_stat and dir_stat.type == 'dir') then
|
-- check if the containing directory exists
|
||||||
|
local dirname = common.dirname(filename)
|
||||||
|
local dir_stat = dirname and system.get_file_info(dirname)
|
||||||
|
if not dirname or (dir_stat and dir_stat.type == 'dir') then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
core.error("Cannot open file %s: %s", text, err)
|
||||||
|
elseif path_stat.type == 'dir' then
|
||||||
|
core.error("Cannot open %s, is a folder", text)
|
||||||
|
else
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
core.error("Cannot open file %s: %s", text, err)
|
})
|
||||||
elseif path_stat.type == 'dir' then
|
|
||||||
core.error("Cannot open %s, is a folder", text)
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end, true)
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:open-log"] = function()
|
["core:open-log"] = function()
|
||||||
|
@ -173,18 +185,21 @@ command.add(nil, {
|
||||||
if dirname then
|
if dirname then
|
||||||
core.command_view:set_text(common.home_encode(dirname) .. PATHSEP)
|
core.command_view:set_text(common.home_encode(dirname) .. PATHSEP)
|
||||||
end
|
end
|
||||||
core.command_view:enter("Change Project Folder", function(text)
|
core.command_view:enter("Change Project Folder", {
|
||||||
local path = common.home_expand(text)
|
submit = function(text)
|
||||||
local abs_path = check_directory_path(path)
|
local path = common.home_expand(text)
|
||||||
if not abs_path then
|
local abs_path = check_directory_path(path)
|
||||||
core.error("Cannot open directory %q", path)
|
if not abs_path then
|
||||||
return
|
core.error("Cannot open directory %q", path)
|
||||||
end
|
return
|
||||||
if abs_path == core.project_dir then return end
|
end
|
||||||
core.confirm_close_docs(core.docs, function(dirpath)
|
if abs_path == core.project_dir then return end
|
||||||
core.open_folder_project(dirpath)
|
core.confirm_close_docs(core.docs, function(dirpath)
|
||||||
end, abs_path)
|
core.open_folder_project(dirpath)
|
||||||
end, suggest_directory)
|
end, abs_path)
|
||||||
|
end,
|
||||||
|
suggest = suggest_directory
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:open-project-folder"] = function()
|
["core:open-project-folder"] = function()
|
||||||
|
@ -192,34 +207,40 @@ command.add(nil, {
|
||||||
if dirname then
|
if dirname then
|
||||||
core.command_view:set_text(common.home_encode(dirname) .. PATHSEP)
|
core.command_view:set_text(common.home_encode(dirname) .. PATHSEP)
|
||||||
end
|
end
|
||||||
core.command_view:enter("Open Project", function(text)
|
core.command_view:enter("Open Project", {
|
||||||
local path = common.home_expand(text)
|
submit = function(text)
|
||||||
local abs_path = check_directory_path(path)
|
local path = common.home_expand(text)
|
||||||
if not abs_path then
|
local abs_path = check_directory_path(path)
|
||||||
core.error("Cannot open directory %q", path)
|
if not abs_path then
|
||||||
return
|
core.error("Cannot open directory %q", path)
|
||||||
end
|
return
|
||||||
if abs_path == core.project_dir then
|
end
|
||||||
core.error("Directory %q is currently opened", abs_path)
|
if abs_path == core.project_dir then
|
||||||
return
|
core.error("Directory %q is currently opened", abs_path)
|
||||||
end
|
return
|
||||||
system.exec(string.format("%q %q", EXEFILE, abs_path))
|
end
|
||||||
end, suggest_directory)
|
system.exec(string.format("%q %q", EXEFILE, abs_path))
|
||||||
|
end,
|
||||||
|
suggest = suggest_directory
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:add-directory"] = function()
|
["core:add-directory"] = function()
|
||||||
core.command_view:enter("Add Directory", function(text)
|
core.command_view:enter("Add Directory", {
|
||||||
text = common.home_expand(text)
|
submit = function(text)
|
||||||
local path_stat, err = system.get_file_info(text)
|
text = common.home_expand(text)
|
||||||
if not path_stat then
|
local path_stat, err = system.get_file_info(text)
|
||||||
core.error("cannot open %q: %s", text, err)
|
if not path_stat then
|
||||||
return
|
core.error("cannot open %q: %s", text, err)
|
||||||
elseif path_stat.type ~= 'dir' then
|
return
|
||||||
core.error("%q is not a directory", text)
|
elseif path_stat.type ~= 'dir' then
|
||||||
return
|
core.error("%q is not a directory", text)
|
||||||
end
|
return
|
||||||
core.add_project_directory(system.absolute_path(text))
|
end
|
||||||
end, suggest_directory)
|
core.add_project_directory(system.absolute_path(text))
|
||||||
|
end,
|
||||||
|
suggest = suggest_directory
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:remove-directory"] = function()
|
["core:remove-directory"] = function()
|
||||||
|
@ -228,14 +249,17 @@ command.add(nil, {
|
||||||
for i = n, 2, -1 do
|
for i = n, 2, -1 do
|
||||||
dir_list[n - i + 1] = core.project_directories[i].name
|
dir_list[n - i + 1] = core.project_directories[i].name
|
||||||
end
|
end
|
||||||
core.command_view:enter("Remove Directory", function(text, item)
|
core.command_view:enter("Remove Directory", {
|
||||||
text = common.home_expand(item and item.text or text)
|
submit = function(text, item)
|
||||||
if not core.remove_project_directory(text) then
|
text = common.home_expand(item and item.text or text)
|
||||||
core.error("No directory %q to be removed", text)
|
if not core.remove_project_directory(text) then
|
||||||
|
core.error("No directory %q to be removed", text)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
suggest = function(text)
|
||||||
|
text = common.home_expand(text)
|
||||||
|
return common.home_encode_list(common.dir_list_suggest(text, dir_list))
|
||||||
end
|
end
|
||||||
end, function(text)
|
})
|
||||||
text = common.home_expand(text)
|
|
||||||
return common.home_encode_list(common.dir_list_suggest(text, dir_list))
|
|
||||||
end)
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
@ -423,21 +423,23 @@ local commands = {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
core.command_view:enter("Go To Line", function(text, item)
|
core.command_view:enter("Go To Line", {
|
||||||
local line = item and item.line or tonumber(text)
|
submit = function(text, item)
|
||||||
if not line then
|
local line = item and item.line or tonumber(text)
|
||||||
core.error("Invalid line number or unmatched string")
|
if not line then
|
||||||
return
|
core.error("Invalid line number or unmatched string")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
dv.doc:set_selection(line, 1 )
|
||||||
|
dv:scroll_to_line(line, true)
|
||||||
|
end,
|
||||||
|
suggest = function(text)
|
||||||
|
if not text:find("^%d*$") then
|
||||||
|
init_items()
|
||||||
|
return common.fuzzy_match(items, text)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
dv.doc:set_selection(line, 1 )
|
})
|
||||||
dv:scroll_to_line(line, true)
|
|
||||||
|
|
||||||
end, function(text)
|
|
||||||
if not text:find("^%d*$") then
|
|
||||||
init_items()
|
|
||||||
return common.fuzzy_match(items, text)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:toggle-line-ending"] = function()
|
["doc:toggle-line-ending"] = function()
|
||||||
|
@ -452,11 +454,14 @@ local commands = {
|
||||||
local dirname, filename = core.last_active_view.doc.abs_filename:match("(.*)[/\\](.+)$")
|
local dirname, filename = core.last_active_view.doc.abs_filename:match("(.*)[/\\](.+)$")
|
||||||
core.command_view:set_text(core.normalize_to_project_dir(dirname) .. PATHSEP)
|
core.command_view:set_text(core.normalize_to_project_dir(dirname) .. PATHSEP)
|
||||||
end
|
end
|
||||||
core.command_view:enter("Save As", function(filename)
|
core.command_view:enter("Save As", {
|
||||||
save(common.home_expand(filename))
|
submit = function(filename)
|
||||||
end, function (text)
|
save(common.home_expand(filename))
|
||||||
return common.home_encode_list(common.path_suggest(common.home_expand(text)))
|
end,
|
||||||
end)
|
suggest = function (text)
|
||||||
|
return common.home_encode_list(common.path_suggest(common.home_expand(text)))
|
||||||
|
end
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:save"] = function()
|
["doc:save"] = function()
|
||||||
|
@ -478,15 +483,18 @@ local commands = {
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
core.command_view:set_text(old_filename)
|
core.command_view:set_text(old_filename)
|
||||||
core.command_view:enter("Rename", function(filename)
|
core.command_view:enter("Rename", {
|
||||||
save(common.home_expand(filename))
|
submit = function(filename)
|
||||||
core.log("Renamed \"%s\" to \"%s\"", old_filename, filename)
|
save(common.home_expand(filename))
|
||||||
if filename ~= old_filename then
|
core.log("Renamed \"%s\" to \"%s\"", old_filename, filename)
|
||||||
os.remove(old_filename)
|
if filename ~= old_filename then
|
||||||
|
os.remove(old_filename)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
suggest = function (text)
|
||||||
|
return common.home_encode_list(common.path_suggest(common.home_expand(text)))
|
||||||
end
|
end
|
||||||
end, function (text)
|
})
|
||||||
return common.home_encode_list(common.path_suggest(common.home_expand(text)))
|
|
||||||
end)
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,13 @@ local common = require "core.common"
|
||||||
|
|
||||||
command.add(nil, {
|
command.add(nil, {
|
||||||
["files:create-directory"] = function()
|
["files:create-directory"] = function()
|
||||||
core.command_view:enter("New directory name", function(text)
|
core.command_view:enter("New directory name", {
|
||||||
local success, err, path = common.mkdirp(text)
|
submit = function(text)
|
||||||
if not success then
|
local success, err, path = common.mkdirp(text)
|
||||||
core.error("cannot create directory %q: %s", path, err)
|
if not success then
|
||||||
|
core.error("cannot create directory %q: %s", path, err)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
})
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
@ -62,27 +62,31 @@ local function find(label, search_fn)
|
||||||
core.status_view:show_tooltip(get_find_tooltip())
|
core.status_view:show_tooltip(get_find_tooltip())
|
||||||
|
|
||||||
core.command_view:set_hidden_suggestions()
|
core.command_view:set_hidden_suggestions()
|
||||||
core.command_view:enter(label, function(text, item)
|
core.command_view:enter(label, {
|
||||||
insert_unique(core.previous_find, text)
|
submit = function(text, item)
|
||||||
core.status_view:remove_tooltip()
|
insert_unique(core.previous_find, text)
|
||||||
if found_expression then
|
core.status_view:remove_tooltip()
|
||||||
|
if found_expression then
|
||||||
|
last_fn, last_text = search_fn, text
|
||||||
|
else
|
||||||
|
core.error("Couldn't find %q", text)
|
||||||
|
last_view.doc:set_selection(table.unpack(last_sel))
|
||||||
|
last_view:scroll_to_make_visible(table.unpack(last_sel))
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
suggest = function(text)
|
||||||
|
update_preview(last_sel, search_fn, text)
|
||||||
last_fn, last_text = search_fn, text
|
last_fn, last_text = search_fn, text
|
||||||
else
|
return core.previous_find
|
||||||
core.error("Couldn't find %q", text)
|
end,
|
||||||
last_view.doc:set_selection(table.unpack(last_sel))
|
cancel = function(explicit)
|
||||||
last_view:scroll_to_make_visible(table.unpack(last_sel))
|
core.status_view:remove_tooltip()
|
||||||
|
if explicit then
|
||||||
|
last_view.doc:set_selection(table.unpack(last_sel))
|
||||||
|
last_view:scroll_to_make_visible(table.unpack(last_sel))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end, function(text)
|
})
|
||||||
update_preview(last_sel, search_fn, text)
|
|
||||||
last_fn, last_text = search_fn, text
|
|
||||||
return core.previous_find
|
|
||||||
end, function(explicit)
|
|
||||||
core.status_view:remove_tooltip()
|
|
||||||
if explicit then
|
|
||||||
last_view.doc:set_selection(table.unpack(last_sel))
|
|
||||||
last_view:scroll_to_make_visible(table.unpack(last_sel))
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,25 +95,31 @@ local function replace(kind, default, fn)
|
||||||
|
|
||||||
core.status_view:show_tooltip(get_find_tooltip())
|
core.status_view:show_tooltip(get_find_tooltip())
|
||||||
core.command_view:set_hidden_suggestions()
|
core.command_view:set_hidden_suggestions()
|
||||||
core.command_view:enter("Find To Replace " .. kind, function(old)
|
core.command_view:enter("Find To Replace " .. kind, {
|
||||||
insert_unique(core.previous_find, old)
|
submit = function(old)
|
||||||
core.command_view:set_text(old, true)
|
insert_unique(core.previous_find, old)
|
||||||
|
core.command_view:set_text(old, true)
|
||||||
|
|
||||||
local s = string.format("Replace %s %q With", kind, old)
|
local s = string.format("Replace %s %q With", kind, old)
|
||||||
core.command_view:set_hidden_suggestions()
|
core.command_view:set_hidden_suggestions()
|
||||||
core.command_view:enter(s, function(new)
|
core.command_view:enter(s, {
|
||||||
|
submit = function(new)
|
||||||
|
core.status_view:remove_tooltip()
|
||||||
|
insert_unique(core.previous_replace, new)
|
||||||
|
local n = doc():replace(function(text)
|
||||||
|
return fn(text, old, new)
|
||||||
|
end)
|
||||||
|
core.log("Replaced %d instance(s) of %s %q with %q", n, kind, old, new)
|
||||||
|
end,
|
||||||
|
suggest = function() return core.previous_replace end, function()
|
||||||
|
core.status_view:remove_tooltip()
|
||||||
|
end
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
suggest = function() return core.previous_find end, function()
|
||||||
core.status_view:remove_tooltip()
|
core.status_view:remove_tooltip()
|
||||||
insert_unique(core.previous_replace, new)
|
end
|
||||||
local n = doc():replace(function(text)
|
})
|
||||||
return fn(text, old, new)
|
|
||||||
end)
|
|
||||||
core.log("Replaced %d instance(s) of %s %q with %q", n, kind, old, new)
|
|
||||||
end, function() return core.previous_replace end, function()
|
|
||||||
core.status_view:remove_tooltip()
|
|
||||||
end)
|
|
||||||
end, function() return core.previous_find end, function()
|
|
||||||
core.status_view:remove_tooltip()
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function has_selection()
|
local function has_selection()
|
||||||
|
|
|
@ -50,20 +50,20 @@ command.add(nil, {
|
||||||
core.status_view:display_messages(true)
|
core.status_view:display_messages(true)
|
||||||
end,
|
end,
|
||||||
["status-bar:hide-item"] = function()
|
["status-bar:hide-item"] = function()
|
||||||
core.command_view:enter("Status bar item to hide",
|
core.command_view:enter("Status bar item to hide", {
|
||||||
function(text, item)
|
submit = function(text, item)
|
||||||
core.status_view:hide_items(item.name)
|
core.status_view:hide_items(item.name)
|
||||||
end,
|
end,
|
||||||
status_view_get_items
|
suggest = status_view_get_items
|
||||||
)
|
})
|
||||||
end,
|
end,
|
||||||
["status-bar:show-item"] = function()
|
["status-bar:show-item"] = function()
|
||||||
core.command_view:enter("Status bar item to show",
|
core.command_view:enter("Status bar item to show", {
|
||||||
function(text, item)
|
submit = function(text, item)
|
||||||
core.status_view:show_items(item.name)
|
core.status_view:show_items(item.name)
|
||||||
end,
|
end,
|
||||||
status_view_get_items
|
suggest = status_view_get_items
|
||||||
)
|
})
|
||||||
end,
|
end,
|
||||||
["status-bar:reset-items"] = function()
|
["status-bar:reset-items"] = function()
|
||||||
core.status_view:show_items()
|
core.status_view:show_items()
|
||||||
|
|
|
@ -65,19 +65,22 @@ end
|
||||||
function DocView:try_close(do_close)
|
function DocView:try_close(do_close)
|
||||||
if self.doc:is_dirty()
|
if self.doc:is_dirty()
|
||||||
and #core.get_views_referencing_doc(self.doc) == 1 then
|
and #core.get_views_referencing_doc(self.doc) == 1 then
|
||||||
core.command_view:enter("Unsaved Changes; Confirm Close", function(_, item)
|
core.command_view:enter("Unsaved Changes; Confirm Close", {
|
||||||
if item.text:match("^[cC]") then
|
submit = function(_, item)
|
||||||
do_close()
|
if item.text:match("^[cC]") then
|
||||||
elseif item.text:match("^[sS]") then
|
do_close()
|
||||||
self.doc:save()
|
elseif item.text:match("^[sS]") then
|
||||||
do_close()
|
self.doc:save()
|
||||||
|
do_close()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
suggest = function(text)
|
||||||
|
local items = {}
|
||||||
|
if not text:find("^[^cC]") then table.insert(items, "Close Without Saving") end
|
||||||
|
if not text:find("^[^sS]") then table.insert(items, "Save And Close") end
|
||||||
|
return items
|
||||||
end
|
end
|
||||||
end, function(text)
|
})
|
||||||
local items = {}
|
|
||||||
if not text:find("^[^cC]") then table.insert(items, "Close Without Saving") end
|
|
||||||
if not text:find("^[^sS]") then table.insert(items, "Save And Close") end
|
|
||||||
return items
|
|
||||||
end)
|
|
||||||
else
|
else
|
||||||
do_close()
|
do_close()
|
||||||
end
|
end
|
||||||
|
|
|
@ -300,22 +300,20 @@ local function set_indent_type(doc, type)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function set_indent_type_command()
|
local function set_indent_type_command()
|
||||||
core.command_view:enter(
|
core.command_view:enter("Specify indent style for this file", {
|
||||||
"Specify indent style for this file",
|
submit = function(value)
|
||||||
function(value) -- submit
|
|
||||||
local doc = core.active_view.doc
|
local doc = core.active_view.doc
|
||||||
value = value:lower()
|
value = value:lower()
|
||||||
set_indent_type(doc, value == "tabs" and "hard" or "soft")
|
set_indent_type(doc, value == "tabs" and "hard" or "soft")
|
||||||
end,
|
end,
|
||||||
function(text) -- suggest
|
suggest = function(text)
|
||||||
return common.fuzzy_match({"tabs", "spaces"}, text)
|
return common.fuzzy_match({"tabs", "spaces"}, text)
|
||||||
end,
|
end,
|
||||||
nil, -- cancel
|
validate = function(text)
|
||||||
function(text) -- validate
|
|
||||||
local t = text:lower()
|
local t = text:lower()
|
||||||
return t == "tabs" or t == "spaces"
|
return t == "tabs" or t == "spaces"
|
||||||
end
|
end
|
||||||
)
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -330,20 +328,17 @@ local function set_indent_size(doc, size)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function set_indent_size_command()
|
local function set_indent_size_command()
|
||||||
core.command_view:enter(
|
core.command_view:enter("Specify indent size for current file", {
|
||||||
"Specify indent size for current file",
|
submit = function(value)
|
||||||
function(value) -- submit
|
|
||||||
value = math.floor(tonumber(value))
|
value = math.floor(tonumber(value))
|
||||||
local doc = core.active_view.doc
|
local doc = core.active_view.doc
|
||||||
set_indent_size(doc, value)
|
set_indent_size(doc, value)
|
||||||
end,
|
end,
|
||||||
nil, -- suggest
|
validate = function(value)
|
||||||
nil, -- cancel
|
|
||||||
function(value) -- validate
|
|
||||||
value = tonumber(value)
|
value = tonumber(value)
|
||||||
return value ~= nil and value >= 1
|
return value ~= nil and value >= 1
|
||||||
end
|
end
|
||||||
)
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -244,30 +244,36 @@ end
|
||||||
command.add(nil, {
|
command.add(nil, {
|
||||||
["project-search:find"] = function()
|
["project-search:find"] = function()
|
||||||
set_command_view_text()
|
set_command_view_text()
|
||||||
core.command_view:enter("Find Text In Project", function(text)
|
core.command_view:enter("Find Text In Project", {
|
||||||
text = text:lower()
|
submit = function(text)
|
||||||
begin_search(text, function(line_text)
|
text = text:lower()
|
||||||
return line_text:lower():find(text, nil, true)
|
begin_search(text, function(line_text)
|
||||||
end)
|
return line_text:lower():find(text, nil, true)
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["project-search:find-regex"] = function()
|
["project-search:find-regex"] = function()
|
||||||
core.command_view:enter("Find Regex In Project", function(text)
|
core.command_view:enter("Find Regex In Project", {
|
||||||
local re = regex.compile(text, "i")
|
submit = function(text)
|
||||||
begin_search(text, function(line_text)
|
local re = regex.compile(text, "i")
|
||||||
return regex.cmatch(re, line_text)
|
begin_search(text, function(line_text)
|
||||||
end)
|
return regex.cmatch(re, line_text)
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["project-search:fuzzy-find"] = function()
|
["project-search:fuzzy-find"] = function()
|
||||||
set_command_view_text()
|
set_command_view_text()
|
||||||
core.command_view:enter("Fuzzy Find Text In Project", function(text)
|
core.command_view:enter("Fuzzy Find Text In Project", {
|
||||||
begin_search(text, function(line_text)
|
submit = function(text)
|
||||||
return common.fuzzy_match(line_text, text) and 1
|
begin_search(text, function(line_text)
|
||||||
end)
|
return common.fuzzy_match(line_text, text) and 1
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -42,20 +42,22 @@ end
|
||||||
|
|
||||||
command.add("core.docview", {
|
command.add("core.docview", {
|
||||||
["tabularize:tabularize"] = function()
|
["tabularize:tabularize"] = function()
|
||||||
core.command_view:enter("Tabularize On Delimiter", function(delim)
|
core.command_view:enter("Tabularize On Delimiter", {
|
||||||
if delim == "" then delim = " " end
|
submit = function(delim)
|
||||||
|
if delim == "" then delim = " " end
|
||||||
|
|
||||||
local doc = core.active_view.doc
|
local doc = core.active_view.doc
|
||||||
local line1, col1, line2, col2, swap = doc:get_selection(true)
|
local line1, col1, line2, col2, swap = doc:get_selection(true)
|
||||||
line1, col1 = doc:position_offset(line1, col1, translate.start_of_line)
|
line1, col1 = doc:position_offset(line1, col1, translate.start_of_line)
|
||||||
line2, col2 = doc:position_offset(line2, col2, translate.end_of_line)
|
line2, col2 = doc:position_offset(line2, col2, translate.end_of_line)
|
||||||
doc:set_selection(line1, col1, line2, col2, swap)
|
doc:set_selection(line1, col1, line2, col2, swap)
|
||||||
|
|
||||||
doc:replace(function(text)
|
doc:replace(function(text)
|
||||||
local lines = gmatch_to_array(text, "[^\n]*\n?")
|
local lines = gmatch_to_array(text, "[^\n]*\n?")
|
||||||
tabularize_lines(lines, delim)
|
tabularize_lines(lines, delim)
|
||||||
return table.concat(lines)
|
return table.concat(lines)
|
||||||
end)
|
end)
|
||||||
end)
|
end
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
@ -690,48 +690,57 @@ command.add(function() return treeitem() ~= nil end, {
|
||||||
local old_filename = treeitem().filename
|
local old_filename = treeitem().filename
|
||||||
local old_abs_filename = treeitem().abs_filename
|
local old_abs_filename = treeitem().abs_filename
|
||||||
core.command_view:set_text(old_filename)
|
core.command_view:set_text(old_filename)
|
||||||
core.command_view:enter("Rename", function(filename)
|
core.command_view:enter("Rename", {
|
||||||
filename = core.normalize_to_project_dir(filename)
|
submit = function(filename)
|
||||||
local abs_filename = core.project_absolute_path(filename)
|
filename = core.normalize_to_project_dir(filename)
|
||||||
local res, err = os.rename(old_abs_filename, abs_filename)
|
local abs_filename = core.project_absolute_path(filename)
|
||||||
if res then -- successfully renamed
|
local res, err = os.rename(old_abs_filename, abs_filename)
|
||||||
for _, doc in ipairs(core.docs) do
|
if res then -- successfully renamed
|
||||||
if doc.abs_filename and old_abs_filename == doc.abs_filename then
|
for _, doc in ipairs(core.docs) do
|
||||||
doc:set_filename(filename, abs_filename) -- make doc point to the new filename
|
if doc.abs_filename and old_abs_filename == doc.abs_filename then
|
||||||
doc:reset_syntax()
|
doc:set_filename(filename, abs_filename) -- make doc point to the new filename
|
||||||
break -- only first needed
|
doc:reset_syntax()
|
||||||
|
break -- only first needed
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
core.log("Renamed \"%s\" to \"%s\"", old_filename, filename)
|
||||||
|
else
|
||||||
|
core.error("Error while renaming \"%s\" to \"%s\": %s", old_abs_filename, abs_filename, err)
|
||||||
end
|
end
|
||||||
core.log("Renamed \"%s\" to \"%s\"", old_filename, filename)
|
end,
|
||||||
else
|
suggest = common.path_suggest
|
||||||
core.error("Error while renaming \"%s\" to \"%s\": %s", old_abs_filename, abs_filename, err)
|
})
|
||||||
end
|
|
||||||
end, common.path_suggest)
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["treeview:new-file"] = function()
|
["treeview:new-file"] = function()
|
||||||
if not is_project_folder(treeitem().abs_filename) then
|
if not is_project_folder(treeitem().abs_filename) then
|
||||||
core.command_view:set_text(treeitem().filename .. "/")
|
core.command_view:set_text(treeitem().filename .. "/")
|
||||||
end
|
end
|
||||||
core.command_view:enter("Filename", function(filename)
|
core.command_view:enter("Filename", {
|
||||||
local doc_filename = core.project_dir .. PATHSEP .. filename
|
submit = function(filename)
|
||||||
local file = io.open(doc_filename, "a+")
|
local doc_filename = core.project_dir .. PATHSEP .. filename
|
||||||
file:write("")
|
local file = io.open(doc_filename, "a+")
|
||||||
file:close()
|
file:write("")
|
||||||
core.root_view:open_doc(core.open_doc(doc_filename))
|
file:close()
|
||||||
core.log("Created %s", doc_filename)
|
core.root_view:open_doc(core.open_doc(doc_filename))
|
||||||
end, common.path_suggest)
|
core.log("Created %s", doc_filename)
|
||||||
|
end,
|
||||||
|
suggest = common.path_suggest
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["treeview:new-folder"] = function()
|
["treeview:new-folder"] = function()
|
||||||
if not is_project_folder(treeitem().abs_filename) then
|
if not is_project_folder(treeitem().abs_filename) then
|
||||||
core.command_view:set_text(treeitem().filename .. "/")
|
core.command_view:set_text(treeitem().filename .. "/")
|
||||||
end
|
end
|
||||||
core.command_view:enter("Folder Name", function(filename)
|
core.command_view:enter("Folder Name", {
|
||||||
local dir_path = core.project_dir .. PATHSEP .. filename
|
submit = function(filename)
|
||||||
common.mkdirp(dir_path)
|
local dir_path = core.project_dir .. PATHSEP .. filename
|
||||||
core.log("Created %s", dir_path)
|
common.mkdirp(dir_path)
|
||||||
end, common.path_suggest)
|
core.log("Created %s", dir_path)
|
||||||
|
end,
|
||||||
|
suggest = common.path_suggest
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["treeview:open-in-system"] = function()
|
["treeview:open-in-system"] = function()
|
||||||
|
|
Loading…
Reference in New Issue