From 5361bfaf9c8ca6440eccd66422ccd2cf0834ffaa Mon Sep 17 00:00:00 2001 From: rxi Date: Wed, 6 May 2020 14:46:56 +0100 Subject: [PATCH] Added open-[project|user]-module commands, renamed command/file finder commands --- data/core/commands/core.lua | 29 ++++++++++++++++++++++------- data/core/init.lua | 6 +++--- data/core/keymap.lua | 4 ++-- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index 3b3b15e..5c9d622 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -35,7 +35,7 @@ command.add(nil, { end) end, - ["core:do-command"] = function() + ["core:command-finder"] = function() local commands = command.get_all_valid() core.command_view:enter("Do Command", function(text, item) if item then @@ -54,12 +54,8 @@ command.add(nil, { end) end, - ["core:new-doc"] = function() - core.root_view:open_doc(core.open_doc()) - end, - - ["core:open-project-file"] = function() - core.command_view:enter("Open Project File", function(text, item) + ["core:file-finder"] = function() + core.command_view:enter("Open File From Project", function(text, item) text = core.project_dir .. PATHSEP .. (item and item.text or text) core.root_view:open_doc(core.open_doc(text)) end, function(text) @@ -73,6 +69,10 @@ command.add(nil, { end) end, + ["core:new-doc"] = function() + core.root_view:open_doc(core.open_doc()) + end, + ["core:open-file"] = function() core.command_view:enter("Open File", function(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() node:add_view(LogView()) 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, }) diff --git a/data/core/init.lua b/data/core/init.lua index 004f813..04284b2 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -103,7 +103,7 @@ function core.init() command.add_defaults() local got_plugin_error = not core.load_plugins() 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 local filename = ARGS[i] @@ -161,12 +161,12 @@ function core.load_plugins() end -function core.load_project_file() +function core.load_project_module() local filename = core.project_dir .. "/.lite_project.lua" if system.get_file_info(filename) then return core.try(function() 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() end) end diff --git a/data/core/keymap.lua b/data/core/keymap.lua index f60d350..ab5fa38 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -84,8 +84,8 @@ end keymap.add { - ["ctrl+shift+p"] = "core:do-command", - ["ctrl+p"] = "core:open-project-file", + ["ctrl+shift+p"] = "core:command-finder", + ["ctrl+p"] = "core:file-finder", ["ctrl+o"] = "core:open-file", ["ctrl+n"] = "core:new-doc", ["alt+return"] = "core:toggle-fullscreen",