Merge pull request #378 from adamharrison/close-other-tabs
Added in close others, and refactored close all.
This commit is contained in:
commit
f3e750ccb4
|
@ -155,7 +155,7 @@ command.add(nil, {
|
|||
core.error("Cannot open folder %q", text)
|
||||
return
|
||||
end
|
||||
core.confirm_close_all(core.open_folder_project, text)
|
||||
core.confirm_close_docs(core.docs, core.open_folder_project, text)
|
||||
end, suggest_directory)
|
||||
end,
|
||||
|
||||
|
|
|
@ -21,9 +21,15 @@ local t = {
|
|||
end,
|
||||
|
||||
["root:close-all"] = function()
|
||||
core.confirm_close_all(core.root_view.close_all_docviews, core.root_view)
|
||||
core.confirm_close_docs(core.docs, core.root_view.close_all_docviews, core.root_view)
|
||||
end,
|
||||
|
||||
["root:close-all-others"] = function()
|
||||
local active_doc, docs = core.active_view and core.active_view.doc, {}
|
||||
for i, v in ipairs(core.docs) do if v ~= active_doc then table.insert(docs, v) end end
|
||||
core.confirm_close_docs(docs, core.root_view.close_all_docviews, core.root_view, true)
|
||||
end,
|
||||
|
||||
["root:switch-to-previous-tab"] = function()
|
||||
local node = core.root_view:get_active_node()
|
||||
local idx = node:get_view_idx(core.active_view)
|
||||
|
|
|
@ -564,10 +564,10 @@ function core.init()
|
|||
end
|
||||
|
||||
|
||||
function core.confirm_close_all(close_fn, ...)
|
||||
function core.confirm_close_docs(docs, close_fn, ...)
|
||||
local dirty_count = 0
|
||||
local dirty_name
|
||||
for _, doc in ipairs(core.docs) do
|
||||
for _, doc in ipairs(docs or core.docs) do
|
||||
if doc:is_dirty() then
|
||||
dirty_count = dirty_count + 1
|
||||
dirty_name = doc:get_name()
|
||||
|
@ -627,7 +627,7 @@ local function quit_with_function(quit_fn, force)
|
|||
save_session()
|
||||
quit_fn()
|
||||
else
|
||||
core.confirm_close_all(quit_with_function, quit_fn, true)
|
||||
core.confirm_close_docs(core.docs, quit_with_function, quit_fn, true)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -594,12 +594,13 @@ function Node:is_empty()
|
|||
end
|
||||
|
||||
|
||||
function Node:close_all_docviews()
|
||||
function Node:close_all_docviews(keep_active)
|
||||
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
|
||||
if view:is(DocView) and not view:is(CommandView) and
|
||||
(not keep_active or view ~= self.active_view) then
|
||||
table.remove(self.views, i)
|
||||
else
|
||||
i = i + 1
|
||||
|
@ -609,8 +610,8 @@ function Node:close_all_docviews()
|
|||
self:add_view(EmptyView())
|
||||
end
|
||||
else
|
||||
self.a:close_all_docviews()
|
||||
self.b:close_all_docviews()
|
||||
self.a:close_all_docviews(keep_active)
|
||||
self.b:close_all_docviews(keep_active)
|
||||
if self.a:is_empty() and not self.a.is_primary_node then
|
||||
self:consume(self.b)
|
||||
elseif self.b:is_empty() and not self.b.is_primary_node then
|
||||
|
@ -736,8 +737,8 @@ function RootView:open_doc(doc)
|
|||
end
|
||||
|
||||
|
||||
function RootView:close_all_docviews()
|
||||
self.root_node:close_all_docviews()
|
||||
function RootView:close_all_docviews(keep_active)
|
||||
self.root_node:close_all_docviews(keep_active)
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue