2022-03-24 16:57:26 +01:00
|
|
|
-- mod-version:3 -- lite-xl 2.1
|
2021-06-03 22:49:37 +02:00
|
|
|
local core = require "core"
|
|
|
|
local command = require "core.command"
|
|
|
|
local keymap = require "core.keymap"
|
2021-06-24 20:07:50 +02:00
|
|
|
local ContextMenu = require "core.contextmenu"
|
2021-06-03 22:49:37 +02:00
|
|
|
local RootView = require "core.rootview"
|
|
|
|
|
|
|
|
local menu = ContextMenu()
|
2021-06-17 10:13:04 +02:00
|
|
|
local on_view_mouse_pressed = RootView.on_view_mouse_pressed
|
|
|
|
local on_mouse_moved = RootView.on_mouse_moved
|
2021-06-03 22:49:37 +02:00
|
|
|
local root_view_update = RootView.update
|
|
|
|
local root_view_draw = RootView.draw
|
|
|
|
|
|
|
|
function RootView:on_mouse_moved(...)
|
2021-06-05 02:51:17 +02:00
|
|
|
if menu:on_mouse_moved(...) then return end
|
2021-06-17 10:13:04 +02:00
|
|
|
on_mouse_moved(self, ...)
|
2021-06-03 22:49:37 +02:00
|
|
|
end
|
|
|
|
|
2021-06-17 10:13:04 +02:00
|
|
|
function RootView.on_view_mouse_pressed(button, x, y, clicks)
|
|
|
|
-- We give the priority to the menu to process mouse pressed events.
|
|
|
|
local handled = menu:on_mouse_pressed(button, x, y, clicks)
|
|
|
|
return handled or on_view_mouse_pressed(button, x, y, clicks)
|
2021-06-03 22:49:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function RootView:update(...)
|
|
|
|
root_view_update(self, ...)
|
|
|
|
menu:update()
|
|
|
|
end
|
|
|
|
|
|
|
|
function RootView:draw(...)
|
|
|
|
root_view_draw(self, ...)
|
|
|
|
menu:draw()
|
|
|
|
end
|
|
|
|
|
2022-05-15 23:17:28 +02:00
|
|
|
command.add("core.docview!", {
|
2021-06-03 22:49:37 +02:00
|
|
|
["context:show"] = function()
|
|
|
|
menu:show(core.active_view.position.x, core.active_view.position.y)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
keymap.add {
|
|
|
|
["menu"] = "context:show"
|
|
|
|
}
|
|
|
|
|
2022-01-28 19:08:54 +01:00
|
|
|
command.add(function() return menu.show_context_menu == true end, {
|
|
|
|
["context:focus-previous"] = function()
|
|
|
|
menu:focus_previous()
|
|
|
|
end,
|
|
|
|
["context:focus-next"] = function()
|
|
|
|
menu:focus_next()
|
|
|
|
end,
|
|
|
|
["context:hide"] = function()
|
|
|
|
menu:hide()
|
|
|
|
end,
|
|
|
|
["context:on-selected"] = function()
|
|
|
|
menu:call_selected_item()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
keymap.add { ["return"] = "context:on-selected" }
|
|
|
|
keymap.add { ["up"] = "context:focus-previous" }
|
|
|
|
keymap.add { ["down"] = "context:focus-next" }
|
|
|
|
keymap.add { ["escape"] = "context:hide" }
|
|
|
|
|
2021-06-03 22:49:37 +02:00
|
|
|
if require("plugins.scale") then
|
|
|
|
menu:register("core.docview", {
|
2021-11-24 03:03:38 +01:00
|
|
|
{ text = "Cut", command = "doc:cut" },
|
|
|
|
{ text = "Copy", command = "doc:copy" },
|
|
|
|
{ text = "Paste", command = "doc:paste" },
|
|
|
|
{ text = "Font +", command = "scale:increase" },
|
|
|
|
{ text = "Font -", command = "scale:decrease" },
|
|
|
|
{ text = "Font Reset", command = "scale:reset" },
|
2021-06-24 20:07:50 +02:00
|
|
|
ContextMenu.DIVIDER,
|
2021-11-24 03:03:38 +01:00
|
|
|
{ text = "Find", command = "find-replace:find" },
|
|
|
|
{ text = "Replace", command = "find-replace:replace" }
|
2021-06-03 22:49:37 +02:00
|
|
|
})
|
|
|
|
end
|
2021-06-05 02:47:32 +02:00
|
|
|
|
|
|
|
return menu
|