Use new CommandView:enter options table
This commit is contained in:
@@ -300,22 +300,20 @@ local function set_indent_type(doc, type)
|
||||
end
|
||||
|
||||
local function set_indent_type_command()
|
||||
core.command_view:enter(
|
||||
"Specify indent style for this file",
|
||||
function(value) -- submit
|
||||
core.command_view:enter("Specify indent style for this file", {
|
||||
submit = function(value)
|
||||
local doc = core.active_view.doc
|
||||
value = value:lower()
|
||||
set_indent_type(doc, value == "tabs" and "hard" or "soft")
|
||||
end,
|
||||
function(text) -- suggest
|
||||
suggest = function(text)
|
||||
return common.fuzzy_match({"tabs", "spaces"}, text)
|
||||
end,
|
||||
nil, -- cancel
|
||||
function(text) -- validate
|
||||
validate = function(text)
|
||||
local t = text:lower()
|
||||
return t == "tabs" or t == "spaces"
|
||||
end
|
||||
)
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
@@ -330,20 +328,17 @@ local function set_indent_size(doc, size)
|
||||
end
|
||||
|
||||
local function set_indent_size_command()
|
||||
core.command_view:enter(
|
||||
"Specify indent size for current file",
|
||||
function(value) -- submit
|
||||
core.command_view:enter("Specify indent size for current file", {
|
||||
submit = function(value)
|
||||
value = math.floor(tonumber(value))
|
||||
local doc = core.active_view.doc
|
||||
set_indent_size(doc, value)
|
||||
end,
|
||||
nil, -- suggest
|
||||
nil, -- cancel
|
||||
function(value) -- validate
|
||||
validate = function(value)
|
||||
value = tonumber(value)
|
||||
return value ~= nil and value >= 1
|
||||
end
|
||||
)
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -244,30 +244,36 @@ end
|
||||
command.add(nil, {
|
||||
["project-search:find"] = function()
|
||||
set_command_view_text()
|
||||
core.command_view:enter("Find Text In Project", function(text)
|
||||
text = text:lower()
|
||||
begin_search(text, function(line_text)
|
||||
return line_text:lower():find(text, nil, true)
|
||||
end)
|
||||
end)
|
||||
core.command_view:enter("Find Text In Project", {
|
||||
submit = function(text)
|
||||
text = text:lower()
|
||||
begin_search(text, function(line_text)
|
||||
return line_text:lower():find(text, nil, true)
|
||||
end)
|
||||
end
|
||||
})
|
||||
end,
|
||||
|
||||
["project-search:find-regex"] = function()
|
||||
core.command_view:enter("Find Regex In Project", function(text)
|
||||
local re = regex.compile(text, "i")
|
||||
begin_search(text, function(line_text)
|
||||
return regex.cmatch(re, line_text)
|
||||
end)
|
||||
end)
|
||||
core.command_view:enter("Find Regex In Project", {
|
||||
submit = function(text)
|
||||
local re = regex.compile(text, "i")
|
||||
begin_search(text, function(line_text)
|
||||
return regex.cmatch(re, line_text)
|
||||
end)
|
||||
end
|
||||
})
|
||||
end,
|
||||
|
||||
["project-search:fuzzy-find"] = function()
|
||||
set_command_view_text()
|
||||
core.command_view:enter("Fuzzy Find Text In Project", function(text)
|
||||
begin_search(text, function(line_text)
|
||||
return common.fuzzy_match(line_text, text) and 1
|
||||
end)
|
||||
end)
|
||||
core.command_view:enter("Fuzzy Find Text In Project", {
|
||||
submit = function(text)
|
||||
begin_search(text, function(line_text)
|
||||
return common.fuzzy_match(line_text, text) and 1
|
||||
end)
|
||||
end
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
+16
-14
@@ -42,20 +42,22 @@ end
|
||||
|
||||
command.add("core.docview", {
|
||||
["tabularize:tabularize"] = function()
|
||||
core.command_view:enter("Tabularize On Delimiter", function(delim)
|
||||
if delim == "" then delim = " " end
|
||||
core.command_view:enter("Tabularize On Delimiter", {
|
||||
submit = function(delim)
|
||||
if delim == "" then delim = " " end
|
||||
|
||||
local doc = core.active_view.doc
|
||||
local line1, col1, line2, col2, swap = doc:get_selection(true)
|
||||
line1, col1 = doc:position_offset(line1, col1, translate.start_of_line)
|
||||
line2, col2 = doc:position_offset(line2, col2, translate.end_of_line)
|
||||
doc:set_selection(line1, col1, line2, col2, swap)
|
||||
|
||||
doc:replace(function(text)
|
||||
local lines = gmatch_to_array(text, "[^\n]*\n?")
|
||||
tabularize_lines(lines, delim)
|
||||
return table.concat(lines)
|
||||
end)
|
||||
end)
|
||||
local doc = core.active_view.doc
|
||||
local line1, col1, line2, col2, swap = doc:get_selection(true)
|
||||
line1, col1 = doc:position_offset(line1, col1, translate.start_of_line)
|
||||
line2, col2 = doc:position_offset(line2, col2, translate.end_of_line)
|
||||
doc:set_selection(line1, col1, line2, col2, swap)
|
||||
|
||||
doc:replace(function(text)
|
||||
local lines = gmatch_to_array(text, "[^\n]*\n?")
|
||||
tabularize_lines(lines, delim)
|
||||
return table.concat(lines)
|
||||
end)
|
||||
end
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
+37
-28
@@ -690,48 +690,57 @@ command.add(function() return treeitem() ~= nil end, {
|
||||
local old_filename = treeitem().filename
|
||||
local old_abs_filename = treeitem().abs_filename
|
||||
core.command_view:set_text(old_filename)
|
||||
core.command_view:enter("Rename", function(filename)
|
||||
filename = core.normalize_to_project_dir(filename)
|
||||
local abs_filename = core.project_absolute_path(filename)
|
||||
local res, err = os.rename(old_abs_filename, abs_filename)
|
||||
if res then -- successfully renamed
|
||||
for _, doc in ipairs(core.docs) do
|
||||
if doc.abs_filename and old_abs_filename == doc.abs_filename then
|
||||
doc:set_filename(filename, abs_filename) -- make doc point to the new filename
|
||||
doc:reset_syntax()
|
||||
break -- only first needed
|
||||
core.command_view:enter("Rename", {
|
||||
submit = function(filename)
|
||||
filename = core.normalize_to_project_dir(filename)
|
||||
local abs_filename = core.project_absolute_path(filename)
|
||||
local res, err = os.rename(old_abs_filename, abs_filename)
|
||||
if res then -- successfully renamed
|
||||
for _, doc in ipairs(core.docs) do
|
||||
if doc.abs_filename and old_abs_filename == doc.abs_filename then
|
||||
doc:set_filename(filename, abs_filename) -- make doc point to the new filename
|
||||
doc:reset_syntax()
|
||||
break -- only first needed
|
||||
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
|
||||
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, common.path_suggest)
|
||||
end,
|
||||
suggest = common.path_suggest
|
||||
})
|
||||
end,
|
||||
|
||||
["treeview:new-file"] = function()
|
||||
if not is_project_folder(treeitem().abs_filename) then
|
||||
core.command_view:set_text(treeitem().filename .. "/")
|
||||
end
|
||||
core.command_view:enter("Filename", function(filename)
|
||||
local doc_filename = core.project_dir .. PATHSEP .. filename
|
||||
local file = io.open(doc_filename, "a+")
|
||||
file:write("")
|
||||
file:close()
|
||||
core.root_view:open_doc(core.open_doc(doc_filename))
|
||||
core.log("Created %s", doc_filename)
|
||||
end, common.path_suggest)
|
||||
core.command_view:enter("Filename", {
|
||||
submit = function(filename)
|
||||
local doc_filename = core.project_dir .. PATHSEP .. filename
|
||||
local file = io.open(doc_filename, "a+")
|
||||
file:write("")
|
||||
file:close()
|
||||
core.root_view:open_doc(core.open_doc(doc_filename))
|
||||
core.log("Created %s", doc_filename)
|
||||
end,
|
||||
suggest = common.path_suggest
|
||||
})
|
||||
end,
|
||||
|
||||
["treeview:new-folder"] = function()
|
||||
if not is_project_folder(treeitem().abs_filename) then
|
||||
core.command_view:set_text(treeitem().filename .. "/")
|
||||
end
|
||||
core.command_view:enter("Folder Name", function(filename)
|
||||
local dir_path = core.project_dir .. PATHSEP .. filename
|
||||
common.mkdirp(dir_path)
|
||||
core.log("Created %s", dir_path)
|
||||
end, common.path_suggest)
|
||||
core.command_view:enter("Folder Name", {
|
||||
submit = function(filename)
|
||||
local dir_path = core.project_dir .. PATHSEP .. filename
|
||||
common.mkdirp(dir_path)
|
||||
core.log("Created %s", dir_path)
|
||||
end,
|
||||
suggest = common.path_suggest
|
||||
})
|
||||
end,
|
||||
|
||||
["treeview:open-in-system"] = function()
|
||||
|
||||
Reference in New Issue
Block a user