Added open-[project|user]-module commands, renamed command/file finder commands

This commit is contained in:
rxi 2020-05-06 14:46:56 +01:00
parent 271e5434d0
commit 5361bfaf9c
3 changed files with 27 additions and 12 deletions

View File

@ -35,7 +35,7 @@ command.add(nil, {
end) end)
end, end,
["core:do-command"] = function() ["core:command-finder"] = 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", function(text, item)
if item then if item then
@ -54,12 +54,8 @@ command.add(nil, {
end) end)
end, end,
["core:new-doc"] = function() ["core:file-finder"] = function()
core.root_view:open_doc(core.open_doc()) core.command_view:enter("Open File From Project", function(text, item)
end,
["core:open-project-file"] = function()
core.command_view:enter("Open Project File", function(text, item)
text = core.project_dir .. PATHSEP .. (item and item.text or text) text = core.project_dir .. PATHSEP .. (item and item.text or text)
core.root_view:open_doc(core.open_doc(text)) core.root_view:open_doc(core.open_doc(text))
end, function(text) end, function(text)
@ -73,6 +69,10 @@ command.add(nil, {
end) end)
end, end,
["core:new-doc"] = function()
core.root_view:open_doc(core.open_doc())
end,
["core:open-file"] = function() ["core:open-file"] = function()
core.command_view:enter("Open File", function(text) core.command_view:enter("Open File", function(text)
core.root_view:open_doc(core.open_doc(text)) core.root_view:open_doc(core.open_doc(text))
@ -83,4 +83,19 @@ command.add(nil, {
local node = core.root_view:get_active_node() local node = core.root_view:get_active_node()
node:add_view(LogView()) node:add_view(LogView())
end, end,
["core:open-user-module"] = function()
core.root_view:open_doc(core.open_doc(EXEDIR .. "/data/user/init.lua"))
end,
["core:open-project-module"] = function()
local filename = core.project_dir .. "/.lite_project.lua"
if system.get_file_info(filename) then
core.root_view:open_doc(core.open_doc(filename))
else
local doc = core.open_doc()
core.root_view:open_doc(doc)
doc:save(filename)
end
end,
}) })

View File

@ -103,7 +103,7 @@ function core.init()
command.add_defaults() command.add_defaults()
local got_plugin_error = not core.load_plugins() local got_plugin_error = not core.load_plugins()
local got_user_error = not core.try(require, "user") local got_user_error = not core.try(require, "user")
local got_project_error = not core.load_project_file() local got_project_error = not core.load_project_module()
for i = 2, #ARGS do for i = 2, #ARGS do
local filename = ARGS[i] local filename = ARGS[i]
@ -161,12 +161,12 @@ function core.load_plugins()
end end
function core.load_project_file() function core.load_project_module()
local filename = core.project_dir .. "/.lite_project.lua" local filename = core.project_dir .. "/.lite_project.lua"
if system.get_file_info(filename) then if system.get_file_info(filename) then
return core.try(function() return core.try(function()
local fn, err = loadfile(filename) local fn, err = loadfile(filename)
if not fn then error("Error when loading project file:\n\t" .. err) end if not fn then error("Error when loading project module:\n\t" .. err) end
fn() fn()
end) end)
end end

View File

@ -84,8 +84,8 @@ end
keymap.add { keymap.add {
["ctrl+shift+p"] = "core:do-command", ["ctrl+shift+p"] = "core:command-finder",
["ctrl+p"] = "core:open-project-file", ["ctrl+p"] = "core:file-finder",
["ctrl+o"] = "core:open-file", ["ctrl+o"] = "core:open-file",
["ctrl+n"] = "core:new-doc", ["ctrl+n"] = "core:new-doc",
["alt+return"] = "core:toggle-fullscreen", ["alt+return"] = "core:toggle-fullscreen",