diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index 701ffd0b..cf904ccf 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -102,7 +102,15 @@ command.add(nil, { end, ["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, ["core:open-project-module"] = function() @@ -116,8 +124,8 @@ command.add(nil, { end end, - ["core:open-folder"] = function() - core.command_view:enter("Open Folder", function(text) + ["core:change-project-folder"] = function() + core.command_view:enter("Change Project Folder", 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) @@ -130,4 +138,17 @@ command.add(nil, { return text == "" and core.recent_projects or common.dir_path_suggest(text) 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, }) diff --git a/data/core/init.lua b/data/core/init.lua index c3e40e53..0f20576f 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -166,33 +166,46 @@ local function write_user_init_file(init_filename) init_file:write([[ -- put user settings here -- 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 config = require "core.config" local style = require "core.style" -- light theme: --- require "colors.summer" +-- style.load("colors.summer") -- key binding: -- 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() end -local function load_user_directory() - local init_filename = USERDIR .. "/init.lua" - local stat_info_dir = system.get_file_info(USERDIR) - if not stat_info_dir then - create_user_directory() - end - local stat_info_file = system.get_file_info(init_filename) - if not stat_info_file then - write_user_init_file(init_filename) - end - return dofile(init_filename) +function core.load_user_directory() + return core.try(function() + local stat_dir = system.get_file_info(USERDIR) + if not stat_dir then + create_user_directory() + end + local init_filename = USERDIR .. "/init.lua" + local stat_file = system.get_file_info(init_filename) + if not stat_file then + write_user_init_file(init_filename) + end + dofile(init_filename) + end) end @@ -242,7 +255,7 @@ function core.init() core.project_scan_thread_id = core.add_thread(project_scan_thread) command.add_defaults() 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 local pdir, pname = system.absolute_path(project_dir):match("(.*)[/\\\\](.*)") diff --git a/data/core/keymap.lua b/data/core/keymap.lua index 5c715def..3798d4da 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -88,6 +88,8 @@ keymap.add { ["ctrl+p"] = "core:find-file", ["ctrl+o"] = "core:open-file", ["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+shift+j"] = "root:split-left", @@ -181,7 +183,6 @@ keymap.add { ["ctrl+shift+end"] = "doc:select-to-end-of-doc", ["shift+pageup"] = "doc:select-to-previous-page", ["shift+pagedown"] = "doc:select-to-next-page", - ["ctrl+shift+o"] = "core:open-folder", } return keymap diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 834e96c4..f311b11d 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -19,7 +19,8 @@ local function draw_text(x, y, color) local lines = { { 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 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() y = y + (dh - (th + style.padding.y) * #lines) / 2 diff --git a/data/core/style.lua b/data/core/style.lua index e8567de5..e87a8ff6 100644 --- a/data/core/style.lua +++ b/data/core/style.lua @@ -53,4 +53,10 @@ style.syntax["string"] = { common.color "#f7c95c" } style.syntax["operator"] = { 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 diff --git a/data/user/init.lua b/data/user/init.lua index bb7f4b3f..b72bab26 100644 --- a/data/user/init.lua +++ b/data/user/init.lua @@ -1,13 +1,24 @@ -- put user settings here -- 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 config = require "core.config" local style = require "core.style" -- light theme: --- require "colors.summer" +-- style.load("colors.summer") -- key binding: -- 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 +