Files
OpenSpace/scripts/drag_drop_handler.lua
Ylva Selling 1cae99ebfc Issue/2000 automatically update gui (#3289)
* Make it possible to query a propertyowner by uri with the getpropertytopic

* Remove automatic reloading of ui from drag and drop script

* Add function for uri for propertyowners

* Add uri to the to_json for the propertyowner

* Add comment for the propertyOwner function and update the comment for the property function to clearer distinguish between uris and identifiers

* Go back to the old events but with uris instead as their member

* Apply feedback from PR

* Address PR comments

---------

Co-authored-by: Ylva Selling <ylva.selling@liu.se>
2024-06-04 18:32:41 +02:00

75 lines
2.8 KiB
Lua

-- This script gets two parameters in its global scope:
-- filename: The full path for the file that was dropped on the application.
-- Example: C:/OpenSpace/openspace.cfg
-- basename: Only the name of the actual file with extension, but without the full rest
-- of the path.
-- Example: openspace.cfg
-- extension: The extention of the file
-- Example: .cfg
--
-- From this script, we need to return the script that we want to be executed in response
-- to the drag event. If we don't want anything to happen, don't return anything or
-- return an empty string
if filename == nil or filename == "" or
basename == nil or basename == "" or
extension == nil or extension == "" then
do return "" end
end
-- Lua doesn't enjoy \ that are used by Windows extensively. So we convert all \ into /
filename = filename:gsub("\\", "/")
basename = basename:gsub("\\", "/")
basename_without_extension = basename:sub(0, #basename - extension:len())
local is_image_file = function(extension)
return extension == ".png" or extension == ".jpg" or extension == ".jpeg" or
extension == ".tif" or extension == ".tga" or extension == ".bmp" or
extension == ".psd" or extension == ".gif" or extension == ".hdr" or
extension == ".pic" or extension == ".pnm"
end
local is_video_file = function(extension)
return extension == ".mp4" or extension == ".webm" or extension == ".mkv" or
extension == ".avi" or extension == ".mov" or extension == ".wmv" or
extension == ".mpg" or extension == ".m4v"
end
local is_asset_file = function(extension)
return extension == ".asset"
end
local is_recording_file = function(extension)
return extension == ".osrec" or extension == ".osrectxt"
end
local is_geojson_file = function(extension)
return extension == ".geojson"
end
if is_image_file(extension) then
return [[
openspace.addScreenSpaceRenderable({
Identifier = openspace.makeIdentifier("]] .. basename_without_extension .. [["),
Type = "ScreenSpaceImageLocal",
TexturePath = "]] .. filename .. [["
});]]
elseif is_video_file(extension) then
return [[
openspace.addScreenSpaceRenderable({
Identifier = openspace.makeIdentifier("]] .. basename_without_extension .. [["),
Type = "ScreenSpaceVideo",
Video = "]] .. filename .. [["
});]]
elseif is_asset_file(extension) then
return [[
if openspace.asset.isLoaded("]] .. filename .. [[") ~= true then
openspace.printInfo("Adding asset: ']] .. filename .. [[' (drag-and-drop)");
end
openspace.asset.add("]] .. filename .. '");'
elseif is_recording_file(extension) then
return 'openspace.sessionRecording.startPlayback("' .. filename .. '")'
elseif is_geojson_file(extension) then
return 'openspace.globebrowsing.addGeoJsonFromFile("' .. filename .. '")'
end