diff --git a/TODO b/TODO index cb19f52..cfde09f 100644 --- a/TODO +++ b/TODO @@ -15,7 +15,7 @@ [ ] prevent overscrolling on treeview [x] user config file and/or init.lua [ ] change tmp directory to somewhere in /tmp -[ ] save session and restore on reopening +[x] save project directory and restore on reopening [ ] optimize dir tree taking too long to load on big folders [ ] go in background when launching from terminal [ ] some key bindings: @@ -26,7 +26,7 @@ [ ] ctrl+d == duplicate line [ ] ctrl+x == cut line || selection [ ] ctrl+c == copy line || selection - [ ] ctrl+shift+o == change & open project folder -> core:open-project-module + [x] ctrl+shift+o == change & open project folder [x] ctrl+q == quit [x] ctrl+n -> next_find [x] ctrl+shift+n -> prev_find diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index dbe08a4..717cade 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -85,7 +85,7 @@ command.add(nil, { end, ["core:open-user-module"] = function() - core.root_view:open_doc(core.open_doc(EXEDIR .. "/data/user/init.lua")) + core.root_view:open_doc(core.open_doc(USERDIR .. "/user/init.lua")) end, ["core:open-project-module"] = function() @@ -98,4 +98,17 @@ command.add(nil, { doc:save(filename) end end, + + ["core:open-project"] = function() + core.command_view:enter("Project Path", function(text) + if text then + core.log("New project path %s", text) + local info = system.get_file_info(text) + if info and info.type == "dir" then + system.exec(string.format("%q %s", EXEFILE, text)) + core.quit() + end + end + end, common.path_suggest) + end, }) diff --git a/data/core/common.lua b/data/core/common.lua index 1fc91b8..b195cea 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -81,7 +81,7 @@ function common.fuzzy_match(haystack, needle) return system.fuzzy_match(haystack, needle) end - +-- FIXME: why does this crash when specifying path? function common.path_suggest(text) local path, name = text:match("^(.-)([^/\\]*)$") local files = system.list_dir(path == "" and "." or path) or {} diff --git a/data/core/config.lua b/data/core/config.lua index e81a550..663aef1 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -16,5 +16,6 @@ config.line_height = 1.2 config.indent_size = 8 config.tab_type = "hard" config.line_limit = 80 +config.restore_last_dir = true return config diff --git a/data/core/init.lua b/data/core/init.lua index 381b009..7cb64b2 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -82,7 +82,38 @@ function core.init() CommandView = require "core.commandview" Doc = require "core.doc" + -- load config before anything + core.frame_start = 0 + core.clip_rect_stack = {{ 0,0,0,0 }} + core.log_items = {} + core.docs = {} + core.threads = setmetatable({}, { __mode = "k" }) + core.project_files = {} + core.redraw = true + command.add_defaults() + -- FIXME: this can load plugins before any thread is started resulting in + -- their failure + core.try(require, "user") + + -- get the last open dir or open HOME local project_dir = os.getenv("HOME") or '/' + if config.restore_last_dir then + local info = system.get_file_info(USERDIR .. '/last_dir') + if info and info.type == "file" then + local file = io.open(USERDIR .. '/last_dir') + if file then + local last_dir = file:read() + file:close() + if last_dir then + info = system.get_file_info(last_dir) + if info and info.type == "dir" then + project_dir = last_dir + end + end + end + end + end + local files = {} for i = 2, #ARGS do local info = system.get_file_info(ARGS[i]) or {} @@ -93,15 +124,12 @@ function core.init() end end - system.chdir(project_dir) + -- write project dir to log file + local d = io.open(USERDIR .. '/last_dir', "w") + d:write(tostring(system.absolute_path(project_dir))) + d:close() - core.frame_start = 0 - core.clip_rect_stack = {{ 0,0,0,0 }} - core.log_items = {} - core.docs = {} - core.threads = setmetatable({}, { __mode = "k" }) - core.project_files = {} - core.redraw = true + system.chdir(project_dir) core.root_view = RootView() core.command_view = CommandView() @@ -111,9 +139,7 @@ function core.init() core.root_view.root_node.b:split("down", core.status_view, true) core.add_thread(project_scan_thread) - command.add_defaults() local got_plugin_error = not core.load_plugins() - core.try(require, "user") local got_project_error = not core.load_project_module() for _, filename in ipairs(files) do diff --git a/data/core/keymap.lua b/data/core/keymap.lua index a8aef37..3c1a4f1 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -86,6 +86,7 @@ end keymap.add { ["ctrl+shift+p"] = "core:find-command", ["ctrl+p"] = "core:find-file", + ["ctrl+shift+o"] = "core:open-project", ["ctrl+o"] = "core:open-file", ["f3"] = "core:new-doc", ["alt+return"] = "core:toggle-fullscreen",