Do not duplicate RootView method in contextmenu

The method RootView:on_mouse_pressed was copied in the contextmenu plugin with
a small modification to intercept the mouse clicks of the active view.

This approach is problematic because a relatively large portion of code is
duplicated.

We introduced a function named RootView.on_view_mouse_pressed to let plugins
like contextmenu intercepts mouse clicks in the active area without duplicating
the function RootView:on_mouse_pressed.
This commit is contained in:
Francesco Abbate
2021-06-17 10:22:31 +02:00
parent 2fc245eb69
commit b39db791f9
2 changed files with 16 additions and 31 deletions
+9 -1
View File
@@ -738,6 +738,12 @@ function RootView:close_all_docviews()
end
-- Function to intercept mouse pressed events on the active view.
-- Do nothing by default.
function RootView.on_view_mouse_pressed(button, x, y, clicks)
end
function RootView:on_mouse_pressed(button, x, y, clicks)
local div = self.root_node:get_divider_overlapping_point(x, y)
if div then
@@ -759,7 +765,9 @@ function RootView:on_mouse_pressed(button, x, y, clicks)
end
else
core.set_active_view(node.active_view)
node.active_view:on_mouse_pressed(button, x, y, clicks)
if not self.on_view_mouse_pressed(button, x, y, clicks) then
node.active_view:on_mouse_pressed(button, x, y, clicks)
end
end
end