From 539f929e306a416a50bab8782ccad2e77aaec11d Mon Sep 17 00:00:00 2001 From: Guldoman Date: Tue, 15 Feb 2022 00:45:59 +0100 Subject: [PATCH] Allow intercepting `filedropped` events The event is first sent to the underlying `View`; if not handled, it's managed as before. --- data/core/init.lua | 22 ++++++++++++---------- data/core/rootview.lua | 6 ++++++ data/core/view.lua | 5 +++++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 7e2612aa..b9b001e2 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -1478,16 +1478,18 @@ function core.on_event(type, ...) elseif type == "minimized" or type == "maximized" or type == "restored" then core.window_mode = type == "restored" and "normal" or type elseif type == "filedropped" then - local filename, mx, my = ... - local info = system.get_file_info(filename) - if info and info.type == "dir" then - system.exec(string.format("%q %q", EXEFILE, filename)) - else - local ok, doc = core.try(core.open_doc, filename) - if ok then - local node = core.root_view.root_node:get_child_overlapping_point(mx, my) - node:set_active_view(node.active_view) - core.root_view:open_doc(doc) + if not core.root_view:on_file_dropped(...) then + local filename, mx, my = ... + local info = system.get_file_info(filename) + if info and info.type == "dir" then + system.exec(string.format("%q %q", EXEFILE, filename)) + else + local ok, doc = core.try(core.open_doc, filename) + if ok then + local node = core.root_view.root_node:get_child_overlapping_point(mx, my) + node:set_active_view(node.active_view) + core.root_view:open_doc(doc) + end end end elseif type == "focuslost" then diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 54de7cfc..863e1fd5 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -272,6 +272,12 @@ function RootView:on_mouse_moved(x, y, dx, dy) end +function RootView:on_file_dropped(filename, x, y) + local node = self.root_node:get_child_overlapping_point(x, y) + return node and node.active_view:on_file_dropped(filename, x, y) +end + + function RootView:on_mouse_wheel(...) local x, y = self.mouse.x, self.mouse.y local node = self.root_node:get_child_overlapping_point(x, y) diff --git a/data/core/view.lua b/data/core/view.lua index 4b787d46..f2c88dc2 100644 --- a/data/core/view.lua +++ b/data/core/view.lua @@ -98,6 +98,11 @@ function View:on_mouse_moved(x, y, dx, dy) end +function View:on_file_dropped(filename, x, y) + return false +end + + function View:on_text_input(text) -- no-op end