project directory changes

add binding to change project directory: ctrl+shift+o
save and restore previous direcotry, toggle behaviour with:
	config.restore_last_dir
core:open_user_module now opens the right path
master
Alessandro Mauri 3 years ago
parent 6a853dfa12
commit 364df2e1c8
  1. 4
      TODO
  2. 15
      data/core/commands/core.lua
  3. 2
      data/core/common.lua
  4. 1
      data/core/config.lua
  5. 46
      data/core/init.lua
  6. 1
      data/core/keymap.lua

@ -15,7 +15,7 @@
[ ] prevent overscrolling on treeview [ ] prevent overscrolling on treeview
[x] user config file and/or init.lua [x] user config file and/or init.lua
[ ] change tmp directory to somewhere in /tmp [ ] 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 [ ] optimize dir tree taking too long to load on big folders
[ ] go in background when launching from terminal [ ] go in background when launching from terminal
[ ] some key bindings: [ ] some key bindings:
@ -26,7 +26,7 @@
[ ] ctrl+d == duplicate line [ ] ctrl+d == duplicate line
[ ] ctrl+x == cut line || selection [ ] ctrl+x == cut line || selection
[ ] ctrl+c == copy 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+q == quit
[x] ctrl+n -> next_find [x] ctrl+n -> next_find
[x] ctrl+shift+n -> prev_find [x] ctrl+shift+n -> prev_find

@ -85,7 +85,7 @@ command.add(nil, {
end, end,
["core:open-user-module"] = function() ["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, end,
["core:open-project-module"] = function() ["core:open-project-module"] = function()
@ -98,4 +98,17 @@ command.add(nil, {
doc:save(filename) doc:save(filename)
end end
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,
}) })

@ -81,7 +81,7 @@ function common.fuzzy_match(haystack, needle)
return system.fuzzy_match(haystack, needle) return system.fuzzy_match(haystack, needle)
end end
-- FIXME: why does this crash when specifying path?
function common.path_suggest(text) function common.path_suggest(text)
local path, name = text:match("^(.-)([^/\\]*)$") local path, name = text:match("^(.-)([^/\\]*)$")
local files = system.list_dir(path == "" and "." or path) or {} local files = system.list_dir(path == "" and "." or path) or {}

@ -16,5 +16,6 @@ config.line_height = 1.2
config.indent_size = 8 config.indent_size = 8
config.tab_type = "hard" config.tab_type = "hard"
config.line_limit = 80 config.line_limit = 80
config.restore_last_dir = true
return config return config

@ -82,7 +82,38 @@ function core.init()
CommandView = require "core.commandview" CommandView = require "core.commandview"
Doc = require "core.doc" 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 '/' 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 = {} local files = {}
for i = 2, #ARGS do for i = 2, #ARGS do
local info = system.get_file_info(ARGS[i]) or {} local info = system.get_file_info(ARGS[i]) or {}
@ -93,15 +124,12 @@ function core.init()
end end
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 system.chdir(project_dir)
core.clip_rect_stack = {{ 0,0,0,0 }}
core.log_items = {}
core.docs = {}
core.threads = setmetatable({}, { __mode = "k" })
core.project_files = {}
core.redraw = true
core.root_view = RootView() core.root_view = RootView()
core.command_view = CommandView() core.command_view = CommandView()
@ -111,9 +139,7 @@ function core.init()
core.root_view.root_node.b:split("down", core.status_view, true) core.root_view.root_node.b:split("down", core.status_view, true)
core.add_thread(project_scan_thread) core.add_thread(project_scan_thread)
command.add_defaults()
local got_plugin_error = not core.load_plugins() local got_plugin_error = not core.load_plugins()
core.try(require, "user")
local got_project_error = not core.load_project_module() local got_project_error = not core.load_project_module()
for _, filename in ipairs(files) do for _, filename in ipairs(files) do

@ -86,6 +86,7 @@ end
keymap.add { keymap.add {
["ctrl+shift+p"] = "core:find-command", ["ctrl+shift+p"] = "core:find-command",
["ctrl+p"] = "core:find-file", ["ctrl+p"] = "core:find-file",
["ctrl+shift+o"] = "core:open-project",
["ctrl+o"] = "core:open-file", ["ctrl+o"] = "core:open-file",
["f3"] = "core:new-doc", ["f3"] = "core:new-doc",
["alt+return"] = "core:toggle-fullscreen", ["alt+return"] = "core:toggle-fullscreen",

Loading…
Cancel
Save