2019-12-28 12:16:32 +01:00
|
|
|
local core = require "core"
|
|
|
|
local common = require "core.common"
|
|
|
|
local command = require "core.command"
|
|
|
|
local keymap = require "core.keymap"
|
|
|
|
local LogView = require "core.logview"
|
|
|
|
|
|
|
|
|
2020-03-25 23:44:59 +01:00
|
|
|
local fullscreen = false
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
command.add(nil, {
|
|
|
|
["core:quit"] = function()
|
|
|
|
core.quit()
|
|
|
|
end,
|
|
|
|
|
|
|
|
["core:force-quit"] = function()
|
|
|
|
core.quit(true)
|
|
|
|
end,
|
|
|
|
|
2020-03-25 23:44:59 +01:00
|
|
|
["core:toggle-fullscreen"] = function()
|
|
|
|
fullscreen = not fullscreen
|
2020-04-07 19:48:57 +02:00
|
|
|
system.set_window_mode(fullscreen and "fullscreen" or "normal")
|
2020-03-25 23:44:59 +01:00
|
|
|
end,
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
["core:reload-module"] = function()
|
|
|
|
core.command_view:enter("Reload Module", function(text, item)
|
|
|
|
local text = item and item.text or text
|
|
|
|
core.reload_module(text)
|
|
|
|
core.log("Reloaded module %q", text)
|
|
|
|
end, function(text)
|
|
|
|
local items = {}
|
|
|
|
for name in pairs(package.loaded) do
|
|
|
|
table.insert(items, name)
|
|
|
|
end
|
|
|
|
return common.fuzzy_match(items, text)
|
|
|
|
end)
|
|
|
|
end,
|
|
|
|
|
2020-05-06 15:46:56 +02:00
|
|
|
["core:command-finder"] = function()
|
2019-12-28 12:16:32 +01:00
|
|
|
local commands = command.get_all_valid()
|
|
|
|
core.command_view:enter("Do Command", function(text, item)
|
|
|
|
if item then
|
|
|
|
command.perform(item.command)
|
|
|
|
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,
|
|
|
|
|
2020-05-06 15:46:56 +02:00
|
|
|
["core:file-finder"] = function()
|
|
|
|
core.command_view:enter("Open File From Project", function(text, item)
|
2020-05-17 17:59:19 +02:00
|
|
|
text = item and item.text or text
|
2019-12-28 12:16:32 +01:00
|
|
|
core.root_view:open_doc(core.open_doc(text))
|
|
|
|
end, function(text)
|
|
|
|
local files = {}
|
|
|
|
for _, item in pairs(core.project_files) do
|
|
|
|
if item.type == "file" then
|
2020-05-17 17:59:19 +02:00
|
|
|
table.insert(files, item.filename)
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return common.fuzzy_match(files, text)
|
|
|
|
end)
|
|
|
|
end,
|
|
|
|
|
2020-05-06 15:46:56 +02:00
|
|
|
["core:new-doc"] = function()
|
|
|
|
core.root_view:open_doc(core.open_doc())
|
|
|
|
end,
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
["core:open-file"] = function()
|
|
|
|
core.command_view:enter("Open File", function(text)
|
|
|
|
core.root_view:open_doc(core.open_doc(text))
|
|
|
|
end, common.path_suggest)
|
|
|
|
end,
|
|
|
|
|
|
|
|
["core:open-log"] = function()
|
|
|
|
local node = core.root_view:get_active_node()
|
|
|
|
node:add_view(LogView())
|
|
|
|
end,
|
2020-05-06 15:46:56 +02:00
|
|
|
|
|
|
|
["core:open-user-module"] = function()
|
|
|
|
core.root_view:open_doc(core.open_doc(EXEDIR .. "/data/user/init.lua"))
|
|
|
|
end,
|
|
|
|
|
|
|
|
["core:open-project-module"] = function()
|
2020-05-17 17:59:19 +02:00
|
|
|
local filename = ".lite_project.lua"
|
2020-05-06 15:46:56 +02:00
|
|
|
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,
|
2019-12-28 12:16:32 +01:00
|
|
|
})
|