From 851dc0740812c60ec74d7f098d17bf463d948515 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 10 Aug 2021 23:14:40 -0400 Subject: [PATCH 1/3] Added in close others, and refactored close all. --- data/core/commands/core.lua | 2 +- data/core/commands/root.lua | 8 +++++++- data/core/init.lua | 6 +++--- data/core/rootview.lua | 13 +++++++------ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index ac30fe2..d7d0f1a 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -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, diff --git a/data/core/commands/root.lua b/data/core/commands/root.lua index 7bc1328..1375fe8 100644 --- a/data/core/commands/root.lua +++ b/data/core/commands/root.lua @@ -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 k, v in pairs(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) diff --git a/data/core/init.lua b/data/core/init.lua index 6fbdde4..5c893d8 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -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 diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 3ef2217..c53d40d 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -594,12 +594,13 @@ function Node:is_empty() end -function Node:close_all_docviews() +function Node:close_all_docviews(keep_inactive) 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_inactive 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_inactive) + self.b:close_all_docviews(keep_inactive) 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_inactive) + self.root_node:close_all_docviews(keep_inactive) end From 40c68ffcc6a42a3e13862096fadbfa004bd41a9c Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 10 Aug 2021 23:18:30 -0400 Subject: [PATCH 2/3] Pairs -> IPairs --- data/core/commands/root.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/commands/root.lua b/data/core/commands/root.lua index 1375fe8..e41c723 100644 --- a/data/core/commands/root.lua +++ b/data/core/commands/root.lua @@ -26,7 +26,7 @@ local t = { ["root:close-all-others"] = function() local active_doc, docs = core.active_view and core.active_view.doc, {} - for k, v in pairs(core.docs) do if v ~= active_doc then table.insert(docs, v) end end + 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, From c644ca7df6dcd7a25c5b3caa58eb33a7121a9c73 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 10 Aug 2021 23:29:39 -0400 Subject: [PATCH 3/3] keep_inactive -> keep_active --- data/core/rootview.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index c53d40d..7b13487 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -594,13 +594,13 @@ function Node:is_empty() end -function Node:close_all_docviews(keep_inactive) +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) and - (not keep_inactive or view ~= self.active_view) then + (not keep_active or view ~= self.active_view) then table.remove(self.views, i) else i = i + 1 @@ -610,8 +610,8 @@ function Node:close_all_docviews(keep_inactive) self:add_view(EmptyView()) end else - self.a:close_all_docviews(keep_inactive) - self.b:close_all_docviews(keep_inactive) + 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 @@ -737,8 +737,8 @@ function RootView:open_doc(doc) end -function RootView:close_all_docviews(keep_inactive) - self.root_node:close_all_docviews(keep_inactive) +function RootView:close_all_docviews(keep_active) + self.root_node:close_all_docviews(keep_active) end