Added core.set_active_view(); removed focusable boolean from View
This commit is contained in:
+13
-13
@@ -77,17 +77,18 @@ end
|
||||
local type_map = { up="vsplit", down="vsplit", left="hsplit", right="hsplit" }
|
||||
|
||||
function Node:split(dir, view, locked)
|
||||
assert(self.type == "leaf", "tried to split non-leaf node")
|
||||
local type = assert(type_map[dir], "invalid direction")
|
||||
assert(self.type == "leaf", "Tried to split non-leaf node")
|
||||
local type = assert(type_map[dir], "Invalid direction")
|
||||
local last_active = core.active_view
|
||||
local child = Node()
|
||||
child:consume(self)
|
||||
self:consume(Node(type))
|
||||
self.a = child
|
||||
self.b = Node()
|
||||
self.b.locked = locked
|
||||
if view then self.b:add_view(view) end
|
||||
if not self.b.active_view.focusable then
|
||||
self.a:set_active_view(self.a.active_view)
|
||||
if locked then
|
||||
self.b.locked = locked
|
||||
core.set_active_view(last_active)
|
||||
end
|
||||
if dir == "up" or dir == "left" then
|
||||
self.a, self.b = self.b, self.a
|
||||
@@ -118,13 +119,15 @@ function Node:close_active_view(root)
|
||||
p:set_active_view(p.active_view)
|
||||
end
|
||||
end
|
||||
core.last_active_view = nil
|
||||
end
|
||||
self.active_view:try_close(do_close)
|
||||
end
|
||||
|
||||
|
||||
function Node:add_view(view)
|
||||
assert(self.type == "leaf", "tried to add view to non-leaf node")
|
||||
assert(self.type == "leaf", "Tried to add view to non-leaf node")
|
||||
assert(not self.locked, "Tried to add view to locked node")
|
||||
if self.views[1] and self.views[1]:is(EmptyView) then
|
||||
table.remove(self.views)
|
||||
end
|
||||
@@ -134,9 +137,9 @@ end
|
||||
|
||||
|
||||
function Node:set_active_view(view)
|
||||
assert(self.type == "leaf", "tried to set active view on non-leaf node")
|
||||
assert(self.type == "leaf", "Tried to set active view on non-leaf node")
|
||||
self.active_view = view
|
||||
core.active_view = view
|
||||
core.set_active_view(view)
|
||||
end
|
||||
|
||||
|
||||
@@ -377,8 +380,7 @@ end
|
||||
|
||||
|
||||
function RootView:get_active_node()
|
||||
local node = self.root_node:get_node_for_view(core.active_view)
|
||||
return node or self.root_node.a
|
||||
return self.root_node:get_node_for_view(core.active_view)
|
||||
end
|
||||
|
||||
|
||||
@@ -413,9 +415,7 @@ function RootView:on_mouse_pressed(button, x, y, clicks)
|
||||
node:close_active_view(self.root_node)
|
||||
end
|
||||
else
|
||||
if node.active_view.focusable then
|
||||
core.active_view = node.active_view
|
||||
end
|
||||
core.set_active_view(node.active_view)
|
||||
node.active_view:on_mouse_pressed(button, x, y, clicks)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user