macos: support drag-and-drop and default file associations (#1822)
* macos: support drag-and-drop and default file associations * resources/macos: use LSItemContentTypes to narrow down files * macos: support opening folders * rootview: workaround macos weird dnd event timing * core/rootview: rename variable and refactor if statement
This commit is contained in:
+1
-14
@@ -1272,20 +1272,7 @@ 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
|
||||
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
|
||||
core.root_view:on_file_dropped(...)
|
||||
elseif type == "focuslost" then
|
||||
core.root_view:on_focus_lost(...)
|
||||
elseif type == "quit" then
|
||||
|
||||
+24
-1
@@ -24,6 +24,7 @@ function RootView:new()
|
||||
base_color = style.drag_overlay_tab,
|
||||
color = { table.unpack(style.drag_overlay_tab) } }
|
||||
self.drag_overlay_tab.to = { x = 0, y = 0, w = 0, h = 0 }
|
||||
self.first_update_done = false
|
||||
end
|
||||
|
||||
|
||||
@@ -319,7 +320,28 @@ end
|
||||
---@return boolean
|
||||
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)
|
||||
local result = node and node.active_view:on_file_dropped(filename, x, y)
|
||||
if result then return result end
|
||||
local info = system.get_file_info(filename)
|
||||
if info and info.type == "dir" then
|
||||
if self.first_update_done then
|
||||
-- first update done, open in new window
|
||||
system.exec(string.format("%q %q", EXEFILE, filename))
|
||||
else
|
||||
-- DND event before first update, this is sent by macOS when folder is dropped into the dock
|
||||
core.confirm_close_docs(core.docs, function(dirpath)
|
||||
core.open_folder_project(dirpath)
|
||||
end, system.absolute_path(filename))
|
||||
end
|
||||
else
|
||||
local ok, doc = core.try(core.open_doc, filename)
|
||||
if ok then
|
||||
local node = core.root_view.root_node:get_child_overlapping_point(x, y)
|
||||
node:set_active_view(node.active_view)
|
||||
core.root_view:open_doc(doc)
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
@@ -363,6 +385,7 @@ function RootView:update()
|
||||
self:update_drag_overlay()
|
||||
self:interpolate_drag_overlay(self.drag_overlay)
|
||||
self:interpolate_drag_overlay(self.drag_overlay_tab)
|
||||
self.first_update_done = true
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,30 @@
|
||||
<string>lite-xl</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>icon.icns</string>
|
||||
<key>CFBundleDocumentTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeExtensions</key>
|
||||
<array>
|
||||
<string>*</string>
|
||||
</array>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
<key>NSDocumentClass</key>
|
||||
<string>NSDocument</string>
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>All Files</string>
|
||||
</dict>
|
||||
</array>
|
||||
<key>LSItemContentTypes</key>
|
||||
<array>
|
||||
<string>public.text</string>
|
||||
<string>public.folder</string>
|
||||
</array>
|
||||
<key>NSExportableTypes</key>
|
||||
<array>
|
||||
<string>public.text</string>
|
||||
</array>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.lite-xl</string>
|
||||
<key>CFBundleName</key>
|
||||
|
||||
Reference in New Issue
Block a user