2019-12-28 12:16:32 +01:00
|
|
|
local core = require "core"
|
2020-02-01 15:40:38 +01:00
|
|
|
local style = require "core.style"
|
2019-12-28 12:16:32 +01:00
|
|
|
local DocView = require "core.docview"
|
|
|
|
local command = require "core.command"
|
2020-05-09 15:40:26 +02:00
|
|
|
local common = require "core.common"
|
2021-11-07 21:42:03 +01:00
|
|
|
local config = require "core.config"
|
2023-02-09 17:51:41 +01:00
|
|
|
local Node = require "core.node"
|
2019-12-28 12:16:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
local t = {
|
2022-08-14 01:56:58 +02:00
|
|
|
["root:close"] = function(node)
|
2019-12-28 12:16:32 +01:00
|
|
|
node:close_active_view(core.root_view.root_node)
|
|
|
|
end,
|
|
|
|
|
2022-08-14 01:56:58 +02:00
|
|
|
["root:close-or-quit"] = function(node)
|
2021-06-27 19:18:54 +02:00
|
|
|
if node and (not node:is_empty() or not node.is_primary_node) then
|
|
|
|
node:close_active_view(core.root_view.root_node)
|
|
|
|
else
|
|
|
|
core.quit()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
2021-01-13 16:51:42 +01:00
|
|
|
["root:close-all"] = function()
|
2021-08-11 05:14:40 +02:00
|
|
|
core.confirm_close_docs(core.docs, core.root_view.close_all_docviews, core.root_view)
|
2021-01-13 16:51:42 +01:00
|
|
|
end,
|
|
|
|
|
2021-08-11 05:14:40 +02:00
|
|
|
["root:close-all-others"] = function()
|
|
|
|
local active_doc, docs = core.active_view and core.active_view.doc, {}
|
2021-08-11 05:18:30 +02:00
|
|
|
for i, v in ipairs(core.docs) do if v ~= active_doc then table.insert(docs, v) end end
|
2021-08-11 05:14:40 +02:00
|
|
|
core.confirm_close_docs(docs, core.root_view.close_all_docviews, core.root_view, true)
|
|
|
|
end,
|
2022-02-09 14:58:20 +01:00
|
|
|
|
2022-08-14 01:56:58 +02:00
|
|
|
["root:move-tab-left"] = function(node)
|
2019-12-28 12:16:32 +01:00
|
|
|
local idx = node:get_view_idx(core.active_view)
|
|
|
|
if idx > 1 then
|
|
|
|
table.remove(node.views, idx)
|
|
|
|
table.insert(node.views, idx - 1, core.active_view)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
2022-08-14 01:56:58 +02:00
|
|
|
["root:move-tab-right"] = function(node)
|
2019-12-28 12:16:32 +01:00
|
|
|
local idx = node:get_view_idx(core.active_view)
|
|
|
|
if idx < #node.views then
|
|
|
|
table.remove(node.views, idx)
|
|
|
|
table.insert(node.views, idx + 1, core.active_view)
|
|
|
|
end
|
|
|
|
end,
|
2022-02-09 14:58:20 +01:00
|
|
|
|
2022-08-14 01:56:58 +02:00
|
|
|
["root:shrink"] = function(node)
|
2020-05-09 15:40:26 +02:00
|
|
|
local parent = node:get_parent_node(core.root_view.root_node)
|
|
|
|
local n = (parent.a == node) and -0.1 or 0.1
|
|
|
|
parent.divider = common.clamp(parent.divider + n, 0.1, 0.9)
|
|
|
|
end,
|
|
|
|
|
2022-08-14 01:56:58 +02:00
|
|
|
["root:grow"] = function(node)
|
2020-05-09 15:40:26 +02:00
|
|
|
local parent = node:get_parent_node(core.root_view.root_node)
|
|
|
|
local n = (parent.a == node) and 0.1 or -0.1
|
|
|
|
parent.divider = common.clamp(parent.divider + n, 0.1, 0.9)
|
2021-11-07 21:42:03 +01:00
|
|
|
end
|
2019-12-28 12:16:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for i = 1, 9 do
|
2022-08-14 01:56:58 +02:00
|
|
|
t["root:switch-to-tab-" .. i] = function(node)
|
2019-12-28 12:16:32 +01:00
|
|
|
local view = node.views[i]
|
|
|
|
if view then
|
|
|
|
node:set_active_view(view)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
for _, dir in ipairs { "left", "right", "up", "down" } do
|
2022-08-14 01:56:58 +02:00
|
|
|
t["root:split-" .. dir] = function(node)
|
2019-12-28 12:16:32 +01:00
|
|
|
local av = node.active_view
|
|
|
|
node:split(dir)
|
|
|
|
if av:is(DocView) then
|
|
|
|
core.root_view:open_doc(av.doc)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-14 01:56:58 +02:00
|
|
|
t["root:switch-to-" .. dir] = function(node)
|
2019-12-28 12:16:32 +01:00
|
|
|
local x, y
|
|
|
|
if dir == "left" or dir == "right" then
|
|
|
|
y = node.position.y + node.size.y / 2
|
2020-02-01 15:40:38 +01:00
|
|
|
x = node.position.x + (dir == "left" and -1 or node.size.x + style.divider_size)
|
2019-12-28 12:16:32 +01:00
|
|
|
else
|
|
|
|
x = node.position.x + node.size.x / 2
|
2020-02-01 15:40:38 +01:00
|
|
|
y = node.position.y + (dir == "up" and -1 or node.size.y + style.divider_size)
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
local node = core.root_view.root_node:get_child_overlapping_point(x, y)
|
2021-10-16 02:56:01 +02:00
|
|
|
local sx, sy = node:get_locked_size()
|
|
|
|
if not sx and not sy then
|
2020-05-19 13:58:41 +02:00
|
|
|
core.set_active_view(node.active_view)
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
command.add(function()
|
|
|
|
local node = core.root_view:get_active_node()
|
2021-10-16 02:56:01 +02:00
|
|
|
local sx, sy = node:get_locked_size()
|
2022-08-14 01:56:58 +02:00
|
|
|
return not sx and not sy, node
|
2019-12-28 12:16:32 +01:00
|
|
|
end, t)
|
2021-11-17 01:12:39 +01:00
|
|
|
|
|
|
|
command.add(nil, {
|
|
|
|
["root:scroll"] = function(delta)
|
|
|
|
local view = (core.root_view.overlapping_node and core.root_view.overlapping_node.active_view) or core.active_view
|
|
|
|
if view and view.scrollable then
|
|
|
|
view.scroll.to.y = view.scroll.to.y + delta * -config.mouse_wheel_scroll
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
2022-10-16 02:12:15 +02:00
|
|
|
end,
|
|
|
|
["root:horizontal-scroll"] = function(delta)
|
|
|
|
local view = (core.root_view.overlapping_node and core.root_view.overlapping_node.active_view) or core.active_view
|
|
|
|
if view and view.scrollable then
|
|
|
|
view.scroll.to.x = view.scroll.to.x + delta * -config.mouse_wheel_scroll
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
2021-11-17 01:12:39 +01:00
|
|
|
end
|
|
|
|
})
|
2023-02-09 17:51:41 +01:00
|
|
|
|
|
|
|
command.add(function(node)
|
|
|
|
if not Node:is_extended_by(node) then node = nil end
|
|
|
|
-- No node was specified, use the active one
|
|
|
|
node = node or core.root_view:get_active_node()
|
|
|
|
if not node then return false end
|
|
|
|
return true, node
|
|
|
|
end,
|
|
|
|
{
|
|
|
|
["root:switch-to-previous-tab"] = function(node)
|
|
|
|
local idx = node:get_view_idx(node.active_view)
|
|
|
|
idx = idx - 1
|
|
|
|
if idx < 1 then idx = #node.views end
|
|
|
|
node:set_active_view(node.views[idx])
|
|
|
|
end,
|
|
|
|
|
|
|
|
["root:switch-to-next-tab"] = function(node)
|
|
|
|
local idx = node:get_view_idx(node.active_view)
|
|
|
|
idx = idx + 1
|
|
|
|
if idx > #node.views then idx = 1 end
|
|
|
|
node:set_active_view(node.views[idx])
|
|
|
|
end,
|
|
|
|
|
|
|
|
["root:scroll-tabs-backward"] = function(node)
|
|
|
|
node:scroll_tabs(1)
|
|
|
|
end,
|
|
|
|
|
|
|
|
["root:scroll-tabs-forward"] = function(node)
|
|
|
|
node:scroll_tabs(2)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
command.add(function()
|
|
|
|
local node = core.root_view.overlapping_node
|
|
|
|
if not node then return false end
|
|
|
|
return (node.hovered_tab or node.hovered_scroll_button > 0) and true, node
|
|
|
|
end,
|
|
|
|
{
|
|
|
|
["root:switch-to-hovered-previous-tab"] = function(node)
|
|
|
|
command.perform("root:switch-to-previous-tab", node)
|
|
|
|
end,
|
|
|
|
|
|
|
|
["root:switch-to-hovered-next-tab"] = function(node)
|
|
|
|
command.perform("root:switch-to-next-tab", node)
|
|
|
|
end,
|
|
|
|
|
|
|
|
["root:scroll-hovered-tabs-backward"] = function(node)
|
|
|
|
command.perform("root:scroll-tabs-backward", node)
|
|
|
|
end,
|
|
|
|
|
|
|
|
["root:scroll-hovered-tabs-forward"] = function(node)
|
|
|
|
command.perform("root:scroll-tabs-forward", node)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
)
|