1 ## Copyright (C) 2006 Søren Hauberg
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} zenity_file_selection(@var{title}, @var{option1}, ...)
18 ## Opens a file selection dialog.
19 ## The variable @var{title} sets the title of the file selection window.
20 ## The optional string arguments can be
23 ## The file selection dialog is a dialog for saving files.
25 ## It is possible to select multiple files.
27 ## It is possible to select directories as well as files.
28 ## @item Anything else
29 ## The argument will be the default selected file.
33 ## @seealso{zenity_calendar, zenity_list, zenity_progress, zenity_entry, zenity_message,
34 ## zenity_text_info, zenity_notification}
37 function files = zenity_file_selection(title, varargin)
39 save = multiple = directory = filename = title = "";
40 if (nargin == 0 || isempty(title)), title = "Select a file"; endif
41 for i = 1:length(varargin)
44 if (isc && strcmpi(option, "save"))
46 elseif (isc && strcmpi(option, "multiple"))
47 multiple = "--multiple";
48 elseif (isc && strcmpi(option, "directory"))
49 directory = "--directory";
51 filename = sprintf('--filename="%s"', varargin{i});
53 error("zenity_file_selection: unsupported option");
57 cmd = sprintf('zenity --file-selection --title="%s" --separator=":" %s %s %s %s', ...
58 title, save, multiple, directory, filename);
59 [status, output] = system(cmd);
61 if (length(output) > 0 && output(end) == "\n")
62 output = output(1:end-1);
64 idx = strfind(output, ":");
65 idx = [0, idx, length(output)+1];
72 files{i} = output((idx(i)+1):(idx(i+1)-1));
78 error("zenity_file_selection: %s", output);