Fix project search and status view for new add directory feature
This commit is contained in:
parent
e4fa196b33
commit
df74781da8
|
@ -73,7 +73,7 @@ command.add(nil, {
|
||||||
|
|
||||||
["core:find-file"] = function()
|
["core:find-file"] = function()
|
||||||
local files = {}
|
local files = {}
|
||||||
for dir, item in core.project_files() do
|
for dir, item in core.get_project_files() do
|
||||||
if item.type == "file" then
|
if item.type == "file" then
|
||||||
local filename = dir == core.project_dir and item.filename:match('^[/\\](.+)') or dir .. item.filename
|
local filename = dir == core.project_dir and item.filename:match('^[/\\](.+)') or dir .. item.filename
|
||||||
table.insert(files, common.home_encode(filename))
|
table.insert(files, common.home_encode(filename))
|
||||||
|
|
|
@ -155,12 +155,22 @@ local function project_files_iter(state)
|
||||||
return dir.name, dir.files[state.file_index]
|
return dir.name, dir.files[state.file_index]
|
||||||
end
|
end
|
||||||
|
|
||||||
function core.project_files()
|
|
||||||
|
function core.get_project_files()
|
||||||
local state = { dir_index = 1, file_index = 0 }
|
local state = { dir_index = 1, file_index = 0 }
|
||||||
return project_files_iter, state
|
return project_files_iter, state
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function core.project_files_number()
|
||||||
|
local n = 0
|
||||||
|
for i = 1, #core.project_directories do
|
||||||
|
n = n + #core.project_directories[i].files
|
||||||
|
end
|
||||||
|
return n
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- create a directory using mkdir but may need to create the parent
|
-- create a directory using mkdir but may need to create the parent
|
||||||
-- directories as well.
|
-- directories as well.
|
||||||
local function create_user_directory()
|
local function create_user_directory()
|
||||||
|
|
|
@ -120,9 +120,7 @@ function StatusView:get_items()
|
||||||
style.icon_font, "g",
|
style.icon_font, "g",
|
||||||
style.font, style.dim, self.separator2,
|
style.font, style.dim, self.separator2,
|
||||||
#core.docs, style.text, " / ",
|
#core.docs, style.text, " / ",
|
||||||
-- FIXME: the number of file should be calculated
|
core.project_files_number(), " files"
|
||||||
-- across directories.
|
|
||||||
#core.project_directories[1].files, " files"
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -49,11 +49,13 @@ function ResultsView:begin_search(text, fn)
|
||||||
self.selected_idx = 0
|
self.selected_idx = 0
|
||||||
|
|
||||||
core.add_thread(function()
|
core.add_thread(function()
|
||||||
for i, file in ipairs(core.project_files) do
|
local i = 1
|
||||||
|
for dir_name, file in core.get_project_files() do
|
||||||
if file.type == "file" then
|
if file.type == "file" then
|
||||||
find_all_matches_in_file(self.results, file.filename, fn)
|
find_all_matches_in_file(self.results, dir_name .. file.filename, fn)
|
||||||
end
|
end
|
||||||
self.last_file_idx = i
|
self.last_file_idx = i
|
||||||
|
i = i + 1
|
||||||
end
|
end
|
||||||
self.searching = false
|
self.searching = false
|
||||||
self.brightness = 100
|
self.brightness = 100
|
||||||
|
@ -162,11 +164,12 @@ function ResultsView:draw()
|
||||||
-- status
|
-- status
|
||||||
local ox, oy = self:get_content_offset()
|
local ox, oy = self:get_content_offset()
|
||||||
local x, y = ox + style.padding.x, oy + style.padding.y
|
local x, y = ox + style.padding.x, oy + style.padding.y
|
||||||
local per = self.last_file_idx / #core.project_files
|
local files_number = core.project_files_number()
|
||||||
|
local per = self.last_file_idx / files_number
|
||||||
local text
|
local text
|
||||||
if self.searching then
|
if self.searching then
|
||||||
text = string.format("Searching %d%% (%d of %d files, %d matches) for %q...",
|
text = string.format("Searching %d%% (%d of %d files, %d matches) for %q...",
|
||||||
per * 100, self.last_file_idx, #core.project_files,
|
per * 100, self.last_file_idx, files_number,
|
||||||
#self.results, self.query)
|
#self.results, self.query)
|
||||||
else
|
else
|
||||||
text = string.format("Found %d matches for %q",
|
text = string.format("Found %d matches for %q",
|
||||||
|
|
Loading…
Reference in New Issue