Preliminary version of project manager
Adapted from contribute rxi/lite-plugins but changed to avoid restarting the application when switching project. Current problem: - the reload of the treeview take some time without any feedback for the user
This commit is contained in:
+17
-27
@@ -81,7 +81,12 @@ local function project_scan_thread()
|
||||
end
|
||||
|
||||
-- wait for next scan
|
||||
coroutine.yield(config.project_scan_rate)
|
||||
if core.switch_project then
|
||||
system.chdir(core.switch_project)
|
||||
core.switch_project = nil
|
||||
else
|
||||
coroutine.yield(config.project_scan_rate)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -175,6 +180,7 @@ function core.init()
|
||||
core.command_view = CommandView()
|
||||
core.status_view = StatusView()
|
||||
|
||||
core.root_view.root_node.has_documents_view = true
|
||||
core.root_view.root_node:split("down", core.command_view, true)
|
||||
core.root_view.root_node.b:split("down", core.status_view, true)
|
||||
|
||||
@@ -194,30 +200,7 @@ function core.init()
|
||||
end
|
||||
|
||||
|
||||
local temp_uid = (system.get_time() * 1000) % 0xffffffff
|
||||
local temp_file_prefix = string.format(".lite_temp_%08x", temp_uid)
|
||||
local temp_file_counter = 0
|
||||
|
||||
local function delete_temp_files()
|
||||
for _, filename in ipairs(system.list_dir(EXEDIR)) do
|
||||
if filename:find(temp_file_prefix, 1, true) == 1 then
|
||||
os.remove(EXEDIR .. PATHSEP .. filename)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function core.temp_filename(ext)
|
||||
temp_file_counter = temp_file_counter + 1
|
||||
return EXEDIR .. PATHSEP .. temp_file_prefix
|
||||
.. string.format("%06x", temp_file_counter) .. (ext or "")
|
||||
end
|
||||
|
||||
|
||||
function core.quit(force)
|
||||
if force then
|
||||
delete_temp_files()
|
||||
os.exit()
|
||||
end
|
||||
function core.confirm_close_all()
|
||||
local dirty_count = 0
|
||||
local dirty_name
|
||||
for _, doc in ipairs(core.docs) do
|
||||
@@ -234,9 +217,16 @@ function core.quit(force)
|
||||
text = string.format("%d docs have unsaved changes. Quit anyway?", dirty_count)
|
||||
end
|
||||
local confirm = system.show_confirm_dialog("Unsaved Changes", text)
|
||||
if not confirm then return end
|
||||
if not confirm then return false end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
function core.quit(force)
|
||||
if core.confirm_close_all() then
|
||||
os.exit()
|
||||
end
|
||||
core.quit(true)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ local style = require "core.style"
|
||||
local keymap = require "core.keymap"
|
||||
local Object = require "core.object"
|
||||
local View = require "core.view"
|
||||
local CommandView = require "core.commandview"
|
||||
local DocView = require "core.docview"
|
||||
|
||||
|
||||
@@ -376,6 +377,41 @@ function Node:draw()
|
||||
end
|
||||
|
||||
|
||||
function Node:is_empty()
|
||||
if self.type == "leaf" then
|
||||
return #self.views == 0
|
||||
else
|
||||
return self.a:is_empty() and self.b:is_empty()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function Node:close_all_docviews()
|
||||
if self.type == "leaf" then
|
||||
local i = 1
|
||||
while i <= #self.views do
|
||||
local view = self.views[i]
|
||||
if view:is(DocView) and not view:is(CommandView) then
|
||||
table.remove(self.views, i)
|
||||
else
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
if #self.views == 0 and self.has_documents_view then
|
||||
self:add_view(EmptyView())
|
||||
end
|
||||
else
|
||||
self.a:close_all_docviews()
|
||||
self.b:close_all_docviews()
|
||||
if self.a:is_empty() then
|
||||
self:consume(self.b)
|
||||
elseif self.b:is_empty() then
|
||||
self:consume(self.a)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
local RootView = View:extend()
|
||||
|
||||
@@ -437,6 +473,11 @@ function RootView:open_doc(doc)
|
||||
end
|
||||
|
||||
|
||||
function RootView:close_all_docviews()
|
||||
self.root_node:close_all_docviews()
|
||||
end
|
||||
|
||||
|
||||
function RootView:on_mouse_pressed(button, x, y, clicks)
|
||||
local div = self.root_node:get_divider_overlapping_point(x, y)
|
||||
if div then
|
||||
|
||||
Reference in New Issue
Block a user