1 ## Copyright (C) 2010-2012 Kai Habel
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile ()
21 ## @deftypefnx {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt})
22 ## @deftypefnx {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt}, @var{dialog_name})
23 ## @deftypefnx {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt}, @var{dialog_name}, @var{default_file})
24 ## Open a GUI dialog for selecting a file. @var{flt} contains a (list of) file
25 ## filter string(s) in one of the following formats:
28 ## @item "/path/to/filename.ext"
29 ## If a filename is given the file extension is
30 ## extracted and used as filter.
31 ## In addition the path is selected as current path and the filename is selected
33 ## Example: uiputfile("myfun.m");
36 ## A single file extension.
37 ## Example: uiputfile("*.ext");
39 ## @item @{"*.ext","My Description"@}
40 ## A 2-column cell array containing the file extension in the 1st column and
41 ## a brief description in the 2nd column.
42 ## Example: uiputfile(@{"*.ext","My Description";"*.xyz","XYZ-Format"@});
45 ## The filter string can also contain a semicolon separated list of filter
47 ## Example: uiputfile(@{"*.gif;*.png;*.jpg", "Supported Picture Formats"@});
49 ## @var{dialog_name} can be used to customize the dialog title.
50 ## If @var{default_file} is given it is preselected in the GUI dialog.
51 ## If, in addition, a path is given it is also used as current path.
56 function [retfile, retpath, retindex] = uiputfile (varargin)
58 defaulttoolkit = get (0, "defaultfigure__graphics_toolkit__");
59 funcname = ["__uiputfile_", defaulttoolkit, "__"];
60 functype = exist (funcname);
61 if (! __is_function__ (funcname))
62 funcname = "__uiputfile_fltk__";
63 if (! __is_function__ (funcname))
64 error ("uiputfile: fltk graphics toolkit required");
65 elseif (! strcmp (defaulttoolkit, "gnuplot"))
66 warning ("uiputfile: no implementation for toolkit `%s', using `fltk' instead",
75 defaultvals = {cell(0, 2), # File Filter
76 "Save File", # Dialog Title
77 "", # Default file name
78 [240, 120], # Dialog Position (pixel x/y)
80 pwd}; # Default directory
84 outargs{i} = defaultvals{i};
88 file_filter = varargin{1};
89 [outargs{1}, outargs{3}, defdir] = __file_filter__ (file_filter);
90 if (length (defdir) > 0)
94 outargs{1} = __file_filter__ (outargs{1});
98 if (ischar (varargin{2}))
99 outargs{2} = varargin{2};
100 elseif (! isempty (varargin{2}))
106 if (ischar (varargin{3}))
107 [fdir, fname, fext] = fileparts (varargin{3});
108 if (! isempty (fdir))
111 if (! isempty (fname) || ! isempty (fext))
112 outargs{3} = strcat (fname, fext);
114 elseif (! isempty (varargin{3}))
119 [retfile, retpath, retindex] = feval (funcname, outargs{:});
124 %! uiputfile({"*.gif;*.png;*.jpg", "Supported Picture Formats"})
126 ## Remove from test statistics. No real tests possible.