Allow intercepting `filedropped` events

The event is first sent to the underlying `View`; if not handled, it's 
managed as before.
This commit is contained in:
Guldoman 2022-02-15 00:45:59 +01:00
parent 2079e1f707
commit 539f929e30
No known key found for this signature in database
GPG Key ID: C08A498EC7F1AFDD
3 changed files with 23 additions and 10 deletions

View File

@ -1478,16 +1478,18 @@ function core.on_event(type, ...)
elseif type == "minimized" or type == "maximized" or type == "restored" then elseif type == "minimized" or type == "maximized" or type == "restored" then
core.window_mode = type == "restored" and "normal" or type core.window_mode = type == "restored" and "normal" or type
elseif type == "filedropped" then elseif type == "filedropped" then
local filename, mx, my = ... if not core.root_view:on_file_dropped(...) then
local info = system.get_file_info(filename) local filename, mx, my = ...
if info and info.type == "dir" then local info = system.get_file_info(filename)
system.exec(string.format("%q %q", EXEFILE, filename)) if info and info.type == "dir" then
else system.exec(string.format("%q %q", EXEFILE, filename))
local ok, doc = core.try(core.open_doc, filename) else
if ok then local ok, doc = core.try(core.open_doc, filename)
local node = core.root_view.root_node:get_child_overlapping_point(mx, my) if ok then
node:set_active_view(node.active_view) local node = core.root_view.root_node:get_child_overlapping_point(mx, my)
core.root_view:open_doc(doc) node:set_active_view(node.active_view)
core.root_view:open_doc(doc)
end
end end
end end
elseif type == "focuslost" then elseif type == "focuslost" then

View File

@ -272,6 +272,12 @@ function RootView:on_mouse_moved(x, y, dx, dy)
end 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(...) function RootView:on_mouse_wheel(...)
local x, y = self.mouse.x, self.mouse.y local x, y = self.mouse.x, self.mouse.y
local node = self.root_node:get_child_overlapping_point(x, y) local node = self.root_node:get_child_overlapping_point(x, y)

View File

@ -98,6 +98,11 @@ function View:on_mouse_moved(x, y, dx, dy)
end end
function View:on_file_dropped(filename, x, y)
return false
end
function View:on_text_input(text) function View:on_text_input(text)
-- no-op -- no-op
end end