Mercurial Hosting > luan
changeset 1979:f2a2f3246426 default tip
choose multiple files
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 26 Jun 2025 23:12:52 -0600 |
parents | 5662a997c180 |
children | |
files | src/luan/modules/swing/File_chooser.luan |
diffstat | 1 files changed, 19 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/modules/swing/File_chooser.luan Thu Jun 26 16:22:06 2025 -0600 +++ b/src/luan/modules/swing/File_chooser.luan Thu Jun 26 23:12:52 2025 -0600 @@ -1,5 +1,6 @@ local Luan = require "luan:Luan.luan" local error = Luan.error +local ipairs = Luan.ipairs or error() local Io = require "luan:Io.luan" local new_file = Io.schemes.file or error() local Utils = require "luan:swing/Utils.luan" @@ -9,6 +10,8 @@ local FileDialog = require "java:java.awt.FileDialog" local JFileChooser = require "java:javax.swing.JFileChooser" --local JFileChooser = require "java:com.formdev.flatlaf.util.SystemFileChooser" +local Logging = require "luan:logging/Logging.luan" +local logger = Logging.logger "swing/File_chooser" local File_chooser = {} @@ -24,23 +27,27 @@ local file_dialog = FileDialog.new(parent) local directory = remove(props,"directory") if directory~=nil then file_dialog.setDirectory(directory.to_string()) end + local multiple = remove(props,"multiple") + if multiple~=nil then file_dialog.setMultipleMode(multiple) end local action = remove(props,"action") or error[["action" property required]] action = awt_actions[action] or error[["action" property must be "load" or "save"]] check_empty(props) file_dialog.setMode(action) file_dialog.setVisible(true) - local file = file_dialog.getFile() - if file == nil then - return nil + local files = {file_dialog.getFiles()} + local rtn = {nil} + for _, file in ipairs(files) do + rtn[#rtn+1] = new_file(file) end - local dir = file_dialog.getDirectory() - return new_file(dir..file) + return rtn end function File_chooser.swing_choose_file(props) local file_chooser = JFileChooser.new() local directory = remove(props,"directory") if directory~=nil then file_chooser.setCurrentDirectory(directory.java.file) end + local multiple = remove(props,"multiple") + if multiple~=nil then file_chooser.setMultiSelectionEnabled(multiple) end local parent = remove(props,"parent") parent = parent and parent.java local action = remove(props,"action") or error[["action" property required]] @@ -54,9 +61,14 @@ error[["action" property must be "load" or "save"]] end if state ~= JFileChooser.APPROVE_OPTION then - return nil + return {} end - return new_file( file_chooser.getSelectedFile() ) + local files = multiple and {file_chooser.getSelectedFiles()} or {file_chooser.getSelectedFile()} + local rtn = {nil} + for _, file in ipairs(files) do + rtn[#rtn+1] = new_file(file) + end + return rtn end return File_chooser