remove data/plugins/contextmenu.lua
moved the code throughout rootview, keymap and commands
This commit is contained in:
parent
084012ed60
commit
e3c42d865e
|
@ -0,0 +1,9 @@
|
||||||
|
local core = require "core"
|
||||||
|
local command = require "core.command"
|
||||||
|
|
||||||
|
|
||||||
|
command.add(nil, {
|
||||||
|
["context-menu:show"] = function()
|
||||||
|
core.context_menu:show(core.active_view.position.x, core.active_view.position.y)
|
||||||
|
end
|
||||||
|
})
|
|
@ -9,6 +9,7 @@ local RootView
|
||||||
local StatusView
|
local StatusView
|
||||||
local TitleView
|
local TitleView
|
||||||
local CommandView
|
local CommandView
|
||||||
|
local ContextMenu
|
||||||
local NagView
|
local NagView
|
||||||
local DocView
|
local DocView
|
||||||
local Doc
|
local Doc
|
||||||
|
@ -417,6 +418,40 @@ local function reload_on_user_module_save()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function find_selected_occurence()
|
||||||
|
local doc = core.active_view.doc
|
||||||
|
if not doc or not doc:has_selection() then return end
|
||||||
|
|
||||||
|
-- get selection. If #358 is merged we won't need this
|
||||||
|
local text = {}
|
||||||
|
for idx, line1, col1, line2, col2 in doc:get_selections() do
|
||||||
|
if line1 ~= line2 or col1 ~= col2 then
|
||||||
|
local t = doc:get_text(line1, col1, line2, col2)
|
||||||
|
if t ~= "" then text[#text + 1] = t end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
text = table.concat(text, "\n")
|
||||||
|
|
||||||
|
command.perform "find-replace:find"
|
||||||
|
core.command_view:set_text(text)
|
||||||
|
core.command_view:submit()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function setup_context_menu()
|
||||||
|
local info = keymap.reverse_map["find-replace:find"]
|
||||||
|
core.context_menu:register("core.docview", {
|
||||||
|
{ text = "Find Occurence...", command = find_selected_occurence, info = info },
|
||||||
|
ContextMenu.DIVIDER,
|
||||||
|
{ text = "Cut", command = "doc:cut" },
|
||||||
|
{ text = "Copy", command = "doc:copy" },
|
||||||
|
{ text = "Paste", command = "doc:paste" },
|
||||||
|
ContextMenu.DIVIDER,
|
||||||
|
{ text = "Command Palette...", command = "core:find-command" }
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function core.init()
|
function core.init()
|
||||||
command = require "core.command"
|
command = require "core.command"
|
||||||
keymap = require "core.keymap"
|
keymap = require "core.keymap"
|
||||||
|
@ -424,6 +459,7 @@ function core.init()
|
||||||
StatusView = require "core.statusview"
|
StatusView = require "core.statusview"
|
||||||
TitleView = require "core.titleview"
|
TitleView = require "core.titleview"
|
||||||
CommandView = require "core.commandview"
|
CommandView = require "core.commandview"
|
||||||
|
ContextMenu = require "core.contextmenu"
|
||||||
NagView = require "core.nagview"
|
NagView = require "core.nagview"
|
||||||
DocView = require "core.docview"
|
DocView = require "core.docview"
|
||||||
Doc = require "core.doc"
|
Doc = require "core.doc"
|
||||||
|
@ -498,6 +534,7 @@ function core.init()
|
||||||
|
|
||||||
core.root_view = RootView()
|
core.root_view = RootView()
|
||||||
core.command_view = CommandView()
|
core.command_view = CommandView()
|
||||||
|
core.context_menu = ContextMenu()
|
||||||
core.status_view = StatusView()
|
core.status_view = StatusView()
|
||||||
core.nag_view = NagView()
|
core.nag_view = NagView()
|
||||||
core.title_view = TitleView()
|
core.title_view = TitleView()
|
||||||
|
@ -560,6 +597,7 @@ function core.init()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
setup_context_menu()
|
||||||
reload_on_user_module_save()
|
reload_on_user_module_save()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,9 @@ keymap.add_direct {
|
||||||
["shift+pageup"] = "doc:select-to-previous-page",
|
["shift+pageup"] = "doc:select-to-previous-page",
|
||||||
["shift+pagedown"] = "doc:select-to-next-page",
|
["shift+pagedown"] = "doc:select-to-next-page",
|
||||||
["ctrl+shift+up"] = "doc:create-cursor-previous-line",
|
["ctrl+shift+up"] = "doc:create-cursor-previous-line",
|
||||||
["ctrl+shift+down"] = "doc:create-cursor-next-line"
|
["ctrl+shift+down"] = "doc:create-cursor-next-line",
|
||||||
|
|
||||||
|
["menu"] = "context-menu:show"
|
||||||
}
|
}
|
||||||
|
|
||||||
return keymap
|
return keymap
|
||||||
|
|
|
@ -741,6 +741,7 @@ end
|
||||||
-- Function to intercept mouse pressed events on the active view.
|
-- Function to intercept mouse pressed events on the active view.
|
||||||
-- Do nothing by default.
|
-- Do nothing by default.
|
||||||
function RootView.on_view_mouse_pressed(button, x, y, clicks)
|
function RootView.on_view_mouse_pressed(button, x, y, clicks)
|
||||||
|
return core.context_menu:on_mouse_pressed(button, x, y, clicks)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -801,6 +802,8 @@ function RootView:on_mouse_moved(x, y, dx, dy)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if core.context_menu:on_mouse_moved(x, y, dx, dy) then return end
|
||||||
|
|
||||||
if self.dragged_divider then
|
if self.dragged_divider then
|
||||||
local node = self.dragged_divider
|
local node = self.dragged_divider
|
||||||
if node.type == "hsplit" then
|
if node.type == "hsplit" then
|
||||||
|
@ -874,11 +877,13 @@ function RootView:update()
|
||||||
copy_position_and_size(self.root_node, self)
|
copy_position_and_size(self.root_node, self)
|
||||||
self.root_node:update()
|
self.root_node:update()
|
||||||
self.root_node:update_layout()
|
self.root_node:update_layout()
|
||||||
|
core.context_menu:update()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function RootView:draw()
|
function RootView:draw()
|
||||||
self.root_node:draw()
|
self.root_node:draw()
|
||||||
|
core.context_menu:draw()
|
||||||
while #self.deferred_draws > 0 do
|
while #self.deferred_draws > 0 do
|
||||||
local t = table.remove(self.deferred_draws)
|
local t = table.remove(self.deferred_draws)
|
||||||
t.fn(table.unpack(t))
|
t.fn(table.unpack(t))
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
-- mod-version:1 -- lite-xl 1.16
|
|
||||||
local core = require "core"
|
|
||||||
local command = require "core.command"
|
|
||||||
local keymap = require "core.keymap"
|
|
||||||
local ContextMenu = require "core.contextmenu"
|
|
||||||
local RootView = require "core.rootview"
|
|
||||||
|
|
||||||
local menu = ContextMenu()
|
|
||||||
local on_view_mouse_pressed = RootView.on_view_mouse_pressed
|
|
||||||
local on_mouse_moved = RootView.on_mouse_moved
|
|
||||||
local root_view_update = RootView.update
|
|
||||||
local root_view_draw = RootView.draw
|
|
||||||
|
|
||||||
function RootView:on_mouse_moved(...)
|
|
||||||
if menu:on_mouse_moved(...) then return end
|
|
||||||
on_mouse_moved(self, ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
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)
|
|
||||||
end
|
|
||||||
|
|
||||||
function RootView:update(...)
|
|
||||||
root_view_update(self, ...)
|
|
||||||
menu:update()
|
|
||||||
end
|
|
||||||
|
|
||||||
function RootView:draw(...)
|
|
||||||
root_view_draw(self, ...)
|
|
||||||
menu:draw()
|
|
||||||
end
|
|
||||||
|
|
||||||
command.add(nil, {
|
|
||||||
["context:show"] = function()
|
|
||||||
menu:show(core.active_view.position.x, core.active_view.position.y)
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
keymap.add {
|
|
||||||
["menu"] = "context:show"
|
|
||||||
}
|
|
||||||
|
|
||||||
if require("plugins.scale") then
|
|
||||||
menu:register("core.docview", {
|
|
||||||
{ text = "Font +", command = "scale:increase" },
|
|
||||||
{ text = "Font -", command = "scale:decrease" },
|
|
||||||
{ text = "Font Reset", command = "scale:reset" },
|
|
||||||
ContextMenu.DIVIDER,
|
|
||||||
{ text = "Find", command = "find-replace:find" },
|
|
||||||
{ text = "Replace", command = "find-replace:replace" },
|
|
||||||
ContextMenu.DIVIDER,
|
|
||||||
{ text = "Find Pattern", command = "find-replace:find-pattern" },
|
|
||||||
{ text = "Replace Pattern", command = "find-replace:replace-pattern" },
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
return menu
|
|
Loading…
Reference in New Issue