Automatically reload style when saving the project user module
This commit is contained in:
parent
6409b67ea2
commit
9114148b45
|
@ -102,7 +102,15 @@ command.add(nil, {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:open-user-module"] = function()
|
["core:open-user-module"] = function()
|
||||||
core.root_view:open_doc(core.open_doc(USERDIR .. "/init.lua"))
|
local user_module_doc = core.open_doc(USERDIR .. "/init.lua")
|
||||||
|
if not user_module_doc then return end
|
||||||
|
local doc_save = user_module_doc.save
|
||||||
|
user_module_doc.save = function(self)
|
||||||
|
doc_save(self)
|
||||||
|
core.reload_module("core.style")
|
||||||
|
core.load_user_directory()
|
||||||
|
end
|
||||||
|
core.root_view:open_doc(user_module_doc)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:open-project-module"] = function()
|
["core:open-project-module"] = function()
|
||||||
|
@ -116,8 +124,8 @@ command.add(nil, {
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:open-folder"] = function()
|
["core:change-project-folder"] = function()
|
||||||
core.command_view:enter("Open Folder", function(text)
|
core.command_view:enter("Change Project Folder", function(text)
|
||||||
local path_stat = system.get_file_info(text)
|
local path_stat = system.get_file_info(text)
|
||||||
if not path_stat or path_stat.type ~= 'dir' then
|
if not path_stat or path_stat.type ~= 'dir' then
|
||||||
core.error("Cannot open folder %q", text)
|
core.error("Cannot open folder %q", text)
|
||||||
|
@ -130,4 +138,17 @@ command.add(nil, {
|
||||||
return text == "" and core.recent_projects or common.dir_path_suggest(text)
|
return text == "" and core.recent_projects or common.dir_path_suggest(text)
|
||||||
end)
|
end)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
["core:open-project-folder"] = function()
|
||||||
|
core.command_view:enter("Open Project", function(text)
|
||||||
|
local path_stat = system.get_file_info(text)
|
||||||
|
if not path_stat or path_stat.type ~= 'dir' then
|
||||||
|
core.error("Cannot open folder %q", text)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
system.exec(string.format("%q %q", EXEFILE, text))
|
||||||
|
end, function(text)
|
||||||
|
return text == "" and core.recent_projects or common.dir_path_suggest(text)
|
||||||
|
end)
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
@ -166,33 +166,46 @@ local function write_user_init_file(init_filename)
|
||||||
init_file:write([[
|
init_file:write([[
|
||||||
-- put user settings here
|
-- put user settings here
|
||||||
-- this module will be loaded after everything else when the application starts
|
-- this module will be loaded after everything else when the application starts
|
||||||
|
-- it will be automatically reloaded when use save it
|
||||||
|
|
||||||
local keymap = require "core.keymap"
|
local keymap = require "core.keymap"
|
||||||
local config = require "core.config"
|
local config = require "core.config"
|
||||||
local style = require "core.style"
|
local style = require "core.style"
|
||||||
|
|
||||||
-- light theme:
|
-- light theme:
|
||||||
-- require "colors.summer"
|
-- style.load("colors.summer")
|
||||||
|
|
||||||
-- key binding:
|
-- key binding:
|
||||||
-- keymap.add { ["ctrl+escape"] = "core:quit" }
|
-- keymap.add { ["ctrl+escape"] = "core:quit" }
|
||||||
|
|
||||||
|
-- customize fonts:
|
||||||
|
-- style.font = renderer.font.load(DATADIR .. "/fonts/font.ttf", 14 * SCALE)
|
||||||
|
-- style.code_font = renderer.font.load(DATADIR .. "/fonts/monospace.ttf", 13.5 * SCALE)
|
||||||
|
--
|
||||||
|
-- fonts used by the editor:
|
||||||
|
-- style.font : user interface
|
||||||
|
-- style.big_font : big text in welcome screen
|
||||||
|
-- style.icon_font : icons
|
||||||
|
-- style.code_font : code
|
||||||
]])
|
]])
|
||||||
init_file:close()
|
init_file:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function load_user_directory()
|
function core.load_user_directory()
|
||||||
local init_filename = USERDIR .. "/init.lua"
|
return core.try(function()
|
||||||
local stat_info_dir = system.get_file_info(USERDIR)
|
local stat_dir = system.get_file_info(USERDIR)
|
||||||
if not stat_info_dir then
|
if not stat_dir then
|
||||||
create_user_directory()
|
create_user_directory()
|
||||||
end
|
end
|
||||||
local stat_info_file = system.get_file_info(init_filename)
|
local init_filename = USERDIR .. "/init.lua"
|
||||||
if not stat_info_file then
|
local stat_file = system.get_file_info(init_filename)
|
||||||
write_user_init_file(init_filename)
|
if not stat_file then
|
||||||
end
|
write_user_init_file(init_filename)
|
||||||
return dofile(init_filename)
|
end
|
||||||
|
dofile(init_filename)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -242,7 +255,7 @@ function core.init()
|
||||||
core.project_scan_thread_id = core.add_thread(project_scan_thread)
|
core.project_scan_thread_id = core.add_thread(project_scan_thread)
|
||||||
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(load_user_directory)
|
local got_user_error = not core.load_user_directory()
|
||||||
|
|
||||||
do
|
do
|
||||||
local pdir, pname = system.absolute_path(project_dir):match("(.*)[/\\\\](.*)")
|
local pdir, pname = system.absolute_path(project_dir):match("(.*)[/\\\\](.*)")
|
||||||
|
|
|
@ -88,6 +88,8 @@ keymap.add {
|
||||||
["ctrl+p"] = "core:find-file",
|
["ctrl+p"] = "core:find-file",
|
||||||
["ctrl+o"] = "core:open-file",
|
["ctrl+o"] = "core:open-file",
|
||||||
["ctrl+n"] = "core:new-doc",
|
["ctrl+n"] = "core:new-doc",
|
||||||
|
["ctrl+shift+c"] = "core:change-project-folder",
|
||||||
|
["ctrl+shift+o"] = "core:open-project-folder",
|
||||||
["alt+return"] = "core:toggle-fullscreen",
|
["alt+return"] = "core:toggle-fullscreen",
|
||||||
|
|
||||||
["alt+shift+j"] = "root:split-left",
|
["alt+shift+j"] = "root:split-left",
|
||||||
|
@ -181,7 +183,6 @@ keymap.add {
|
||||||
["ctrl+shift+end"] = "doc:select-to-end-of-doc",
|
["ctrl+shift+end"] = "doc:select-to-end-of-doc",
|
||||||
["shift+pageup"] = "doc:select-to-previous-page",
|
["shift+pageup"] = "doc:select-to-previous-page",
|
||||||
["shift+pagedown"] = "doc:select-to-next-page",
|
["shift+pagedown"] = "doc:select-to-next-page",
|
||||||
["ctrl+shift+o"] = "core:open-folder",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return keymap
|
return keymap
|
||||||
|
|
|
@ -19,7 +19,8 @@ local function draw_text(x, y, color)
|
||||||
local lines = {
|
local lines = {
|
||||||
{ fmt = "%s to run a command", cmd = "core:find-command" },
|
{ fmt = "%s to run a command", cmd = "core:find-command" },
|
||||||
{ fmt = "%s to open a file from the project", cmd = "core:find-file" },
|
{ fmt = "%s to open a file from the project", cmd = "core:find-file" },
|
||||||
{ fmt = "%s to change project folder", cmd = "core:open-folder" },
|
{ fmt = "%s to change project folder", cmd = "core:change-project-folder" },
|
||||||
|
{ fmt = "%s to open a project folder", cmd = "core:open-project-folder" },
|
||||||
}
|
}
|
||||||
th = style.font:get_height()
|
th = style.font:get_height()
|
||||||
y = y + (dh - (th + style.padding.y) * #lines) / 2
|
y = y + (dh - (th + style.padding.y) * #lines) / 2
|
||||||
|
|
|
@ -53,4 +53,10 @@ style.syntax["string"] = { common.color "#f7c95c" }
|
||||||
style.syntax["operator"] = { common.color "#93DDFA" }
|
style.syntax["operator"] = { common.color "#93DDFA" }
|
||||||
style.syntax["function"] = { common.color "#93DDFA" }
|
style.syntax["function"] = { common.color "#93DDFA" }
|
||||||
|
|
||||||
|
|
||||||
|
style.load = function(module_name)
|
||||||
|
package.loaded[module_name] = nil
|
||||||
|
require(module_name)
|
||||||
|
end
|
||||||
|
|
||||||
return style
|
return style
|
||||||
|
|
|
@ -1,13 +1,24 @@
|
||||||
-- put user settings here
|
-- put user settings here
|
||||||
-- this module will be loaded after everything else when the application starts
|
-- this module will be loaded after everything else when the application starts
|
||||||
|
-- it will be automatically reloaded when use save it
|
||||||
|
|
||||||
local keymap = require "core.keymap"
|
local keymap = require "core.keymap"
|
||||||
local config = require "core.config"
|
local config = require "core.config"
|
||||||
local style = require "core.style"
|
local style = require "core.style"
|
||||||
|
|
||||||
-- light theme:
|
-- light theme:
|
||||||
-- require "colors.summer"
|
-- style.load("colors.summer")
|
||||||
|
|
||||||
-- key binding:
|
-- key binding:
|
||||||
-- keymap.add { ["ctrl+escape"] = "core:quit" }
|
-- keymap.add { ["ctrl+escape"] = "core:quit" }
|
||||||
|
|
||||||
|
-- customize fonts:
|
||||||
|
-- style.font = renderer.font.load(DATADIR .. "/fonts/font.ttf", 14 * SCALE)
|
||||||
|
-- style.code_font = renderer.font.load(DATADIR .. "/fonts/monospace.ttf", 13.5 * SCALE)
|
||||||
|
--
|
||||||
|
-- fonts used by the editor:
|
||||||
|
-- style.font : user interface
|
||||||
|
-- style.big_font : big text in welcome screen
|
||||||
|
-- style.icon_font : icons
|
||||||
|
-- style.code_font : code
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue