Added core.set_active_view(); removed focusable boolean from View

This commit is contained in:
rxi 2020-05-19 12:58:41 +01:00
parent 8ec717f240
commit bc4bf3d384
7 changed files with 27 additions and 21 deletions

View file

@ -94,7 +94,7 @@ for _, dir in ipairs { "left", "right", "up", "down" } do
end
local node = core.root_view.root_node:get_child_overlapping_point(x, y)
if not node:get_locked_size() then
core.active_view = node.active_view
core.set_active_view(node.active_view)
end
end
end

View file

@ -111,9 +111,8 @@ function CommandView:enter(text, submit, suggest, cancel)
submit = submit or noop,
suggest = suggest or noop,
cancel = cancel or noop,
view = core.active_view
}
core.active_view = self
core.set_active_view(self)
self:update_suggestions()
self.gutter_text_brightness = 100
self.label = text .. ": "
@ -122,7 +121,7 @@ end
function CommandView:exit(submitted, inexplicit)
if core.active_view == self then
core.active_view = self.state.view
core.set_active_view(core.last_active_view)
end
local cancel = self.state.cancel
self.state = default_state

View file

@ -100,7 +100,6 @@ function core.init()
core.root_view.root_node:split("down", core.command_view, true)
core.root_view.root_node.b:split("down", core.status_view, true)
core.active_view = core.root_view.root_node.a.active_view
core.add_thread(project_scan_thread)
command.add_defaults()
@ -192,6 +191,15 @@ function core.reload_module(name)
end
function core.set_active_view(view)
assert(view, "Tried to set active view to nil")
if view ~= core.active_view then
core.last_active_view = core.active_view
core.active_view = view
end
end
function core.add_thread(f, weak_ref)
local key = weak_ref or #core.threads + 1
local fn = function() return core.try(f) end

View file

@ -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

View file

@ -16,13 +16,13 @@ StatusView.separator2 = " | "
function StatusView:new()
StatusView.super.new(self)
self.focusable = false
self.message_timeout = 0
self.message = {}
end
function StatusView:on_mouse_pressed()
core.set_active_view(core.last_active_view)
if system.get_time() < self.message_timeout
and not core.active_view:is(LogView) then
command.perform "core:open-log"

View file

@ -14,7 +14,6 @@ function View:new()
self.scroll = { x = 0, y = 0, to = { x = 0, y = 0 } }
self.cursor = "arrow"
self.scrollable = false
self.focusable = true
end

View file

@ -22,7 +22,6 @@ local TreeView = View:extend()
function TreeView:new()
TreeView.super.new(self)
self.scrollable = true
self.focusable = false
self.visible = true
self.init_size = true
self.cache = {}
@ -112,6 +111,7 @@ end
function TreeView:on_mouse_pressed(button, x, y)
core.set_active_view(core.last_active_view)
if not self.hovered_item then
return
elseif self.hovered_item.type == "dir" then