Made lite set project dir to CWD; removed core.project_dir

Fixes #100
This commit is contained in:
rxi 2020-05-17 16:59:19 +01:00
parent c1f731e5a1
commit 4ae0d477c0
4 changed files with 21 additions and 15 deletions

View File

@ -56,13 +56,13 @@ command.add(nil, {
["core:file-finder"] = function()
core.command_view:enter("Open File From Project", function(text, item)
text = core.project_dir .. PATHSEP .. (item and item.text or text)
text = item and item.text or text
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
table.insert(files, item.filename:sub(#core.project_dir + 2))
table.insert(files, item.filename)
end
end
return common.fuzzy_match(files, text)
@ -89,7 +89,7 @@ command.add(nil, {
end,
["core:open-project-module"] = function()
local filename = core.project_dir .. "/.lite_project.lua"
local filename = ".lite_project.lua"
if system.get_file_info(filename) then
core.root_view:open_doc(core.open_doc(filename))
else

View File

@ -36,7 +36,7 @@ local function project_scan_thread()
for _, file in ipairs(all) do
if not common.match_pattern(file, config.ignore_files) then
local file = path .. PATHSEP .. file
local file = (path ~= "." and path .. PATHSEP or "") .. file
local info = system.get_file_info(file)
if info and info.size < size_limit then
info.filename = file
@ -62,7 +62,7 @@ local function project_scan_thread()
while true do
-- get project files and replace previous table if the new table is
-- different
local t = get_files(core.project_dir)
local t = get_files(".")
if diff_files(core.project_files, t) then
core.project_files = t
core.redraw = true
@ -88,12 +88,6 @@ function core.init()
core.docs = {}
core.threads = setmetatable({}, { __mode = "k" })
core.project_files = {}
core.project_dir = "."
local info = ARGS[2] and system.get_file_info(ARGS[2])
if info and info.type == "dir" then
core.project_dir = ARGS[2]:gsub("[\\/]$", "")
end
core.root_view = RootView()
core.command_view = CommandView()
@ -120,6 +114,9 @@ function core.init()
if got_plugin_error or got_user_error or got_project_error then
command.perform("core:open-log")
end
local info = ARGS[2] and system.get_file_info(ARGS[2])
system.chdir(info and info.type == "dir" and ARGS[2] or ".")
end
@ -166,7 +163,7 @@ end
function core.load_project_module()
local filename = core.project_dir .. "/.lite_project.lua"
local filename = ".lite_project.lua"
if system.get_file_info(filename) then
return core.try(function()
local fn, err = loadfile(filename)

View File

@ -35,7 +35,7 @@ function TreeView:get_cached(item)
t = {}
t.filename = item.filename
t.abs_filename = system.absolute_path(item.filename)
t.path, t.name = t.filename:match("^(.*)[\\/](.+)$")
t.name = t.filename:match("[^\\/]+$")
t.depth = get_depth(t.filename)
t.type = item.type
self.cache[t.filename] = t
@ -143,7 +143,6 @@ function TreeView:draw()
local icon_width = style.icon_font:get_width("D")
local spacing = style.font:get_width(" ") * 2
local root_depth = get_depth(core.project_dir) + 1
local doc = core.active_view.doc
local active_filename = doc and system.absolute_path(doc.filename or "")
@ -163,7 +162,7 @@ function TreeView:draw()
end
-- icons
x = x + (item.depth - root_depth) * style.padding.x + style.padding.x
x = x + item.depth * style.padding.x + style.padding.x
if item.type == "dir" then
local icon1 = item.expanded and "-" or "+"
local icon2 = item.expanded and "D" or "d"

View File

@ -2,6 +2,7 @@
#include <stdbool.h>
#include <ctype.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include "api.h"
@ -216,6 +217,14 @@ static int f_show_confirm_dialog(lua_State *L) {
}
static int f_chdir(lua_State *L) {
const char *path = luaL_checkstring(L, 1);
int err = chdir(path);
if (err) { luaL_error(L, "chdir() failed"); }
return 0;
}
static int f_list_dir(lua_State *L) {
const char *path = luaL_checkstring(L, 1);
@ -370,6 +379,7 @@ static const luaL_Reg lib[] = {
{ "set_window_mode", f_set_window_mode },
{ "window_has_focus", f_window_has_focus },
{ "show_confirm_dialog", f_show_confirm_dialog },
{ "chdir", f_chdir },
{ "list_dir", f_list_dir },
{ "absolute_path", f_absolute_path },
{ "get_file_info", f_get_file_info },