native.showPopup() — Quick Look

Type function
Library native.*
Revision Release 2024.3703
Keywords native, showPopup, quick look, preview

Overview

Displays the operating system's default popup window for previewing/viewing documents.

Syntax

native.showPopup( name, options )
name (required)

String. The string name of the popup to be shown. For the Quick Look plugin, use "quickLook".

options (required)

Table. A table that specifies the properties for the popup — see the next section for details.

Options Reference

Valid properties in the options table include the following:

files (required)

Table. A table of sub-tables, each specifying a file to view. Within each sub-table, filename indicates the file and baseDir indicates the system directory constant in which the file resides.

files = 
{
    { filename="myFile.txt", baseDir=system.ResourceDirectory },
}
startIndex (optional)

Table. The file index at which the preview will start. For instance, if you have two file sub-tables in the files table and you set this value to 2, it will preview the second file first, as opposed to starting at the first file. Default is 1, indicating the first file.

listener (optional)

Function. Listener function to be called when the popup is dismissed. This function is passed an event table which contains the following properties:

  • event.name (string) — Value of "popup".
  • event.type (string) — Value of "quickLook".
  • event.action (string) — Value of "done".
  • event.file (table) — File table of the last item previewed prior to dismissing.

Example

local function quickLookListener( event )
    print( event.name )    --"popup"
    print( event.type )    --"quickLook"
    print( event.action )  --"done"
    print( event.file )    --file table of last item previewed prior to dismissing, for example: { filename="myFile.txt", baseDir=system.ResourceDirectory }
end

-- Quick Look options
local quickLookOptions = 
{
    files =
    {
        { filename="myPDF.pdf", baseDir=system.ResourceDirectory },
        { filename="myImage.jpg", baseDir=system.ResourceDirectory },
    },
    startIndex = 1,
    listener = quickLookListener
}

native.showPopup( "quickLook", quickLookOptions )