Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guldoman's Pocket Design #1764

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleaned up propogation.
  • Loading branch information
adamharrison committed Apr 8, 2024
commit 5fa713c542f1ed41ae081e9238a4d4f79b882aaa
19 changes: 2 additions & 17 deletions data/core/commands/root.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,15 @@ local config = require "core.config"
local Node = require "core.node"


local function close_docviews(keep_active)
local root = core.root_view.root_node
root:propogate(function(node)
local i = 1
while i <= #node.views do
local view = node.views[i]
if view.context == "session" and (not keep_active or view ~= node.active_view) then
node:close_view(root, view)
else
i = i + 1
end
end
end)
end

local t = {
["root:close-all"] = function()
core.confirm_close_docs(core.docs, close_docviews)
core.confirm_close_docs(core.docs, core.root_view.close_session_views, 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, close_docviews, true)
core.confirm_close_docs(docs, core.close_session_views, core.root_view, true)
end,

["root:move-tab-left"] = function(node)
Expand Down
2 changes: 1 addition & 1 deletion data/core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ end

function core.open_folder_project(dir_path_abs)
if core.set_project_dir(dir_path_abs, core.on_quit_project) then
core.root_view:close_all_docviews()
core.root_view:close_session_views()
reload_customizations()
update_recents_project("add", dir_path_abs)
core.add_project_directory(dir_path_abs)
Expand Down
19 changes: 15 additions & 4 deletions data/core/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,24 @@ end


function Node:propogate(fn, ...)
if self.type ~= "leaf" then
self.a:propogate(fn, ...)
self.b:propogate(fn, ...)
end
if self.type ~= "leaf" then self.a:propogate(fn, ...) end
if self.type ~= "leaf" then self.b:propogate(fn, ...) end
fn(self, ...)
end

function Node:view_propogate(fn, ...)
self:propogate(function(node)
local i = 1
while i <= #node.views do
local view = node.views[i]
fn(node, view)
if view == node.views[i] then
i = i + 1
end
end
end)
end


---@deprecated
function Node:on_mouse_moved(x, y, ...)
Expand Down
9 changes: 9 additions & 0 deletions data/core/rootview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,13 @@ function RootView:add_view(view, pocket, layout)
end


function RootView:close_session_views(keep_active)
self.root_node:view_propogate(function(node, view)
if view.context == "session" and (not keep_active or view ~= node.active_view) then
node:close_view(self.root_node, view)
end
end)
end


return RootView