11283
|
1 ## Copyright (C) 2010 Kai Habel |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
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. |
|
9 ## |
|
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. |
|
14 ## |
|
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/>. |
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt}, @var{dialog_name}, @var{default_file}) |
|
21 ## @deftypefnx {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt}, @var{dialog_name}) |
|
22 ## @deftypefnx {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt}) |
|
23 ## @deftypefnx {Function File} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile ()) |
|
24 ## Open a GUI dialog to select a file. @var{flt} contains a (list of) file |
|
25 ## filter string(s) in one of the following formats: |
|
26 ## |
|
27 ## @table @code |
|
28 ## @item "/path/to/filename.ext" |
|
29 ## If a filename is given the file extension is |
|
30 ## extracted and used as filter. |
|
31 ## In addtion the path is selected as current path and the filname is selected |
|
32 ## as default file. |
|
33 ## Example: uiputfile("myfun.m"); |
|
34 ## |
|
35 ## @item "*.ext" |
|
36 ## A single file extension. |
|
37 ## Example: uiputfile("*.ext"); |
|
38 ## |
|
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"@}); |
|
43 ## @end table |
|
44 ## |
|
45 ## The filter string can also contain a semicolon separated list of filter |
|
46 ## extensions. |
|
47 ## Example: uiputfile(@{"*.gif;*.png;*.jpg", "Supported Picture Formats"@}); |
|
48 ## |
|
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 addtion a path is given it is also used as current path. |
|
52 ## @end deftypefn |
|
53 |
|
54 ## Author: Kai Habel |
|
55 |
|
56 function [retfile, retpath, retindex] = uiputfile (varargin) |
|
57 |
|
58 |
|
59 if (nargin <= 3) |
|
60 |
|
61 defaultvals = {"All Files(*)", #FLTK File Filter |
|
62 "Save File?", #Dialog Title |
|
63 "", #FLTK default file name |
|
64 [240, 120], #Dialog Position (pixel x/y) |
|
65 "create"}; |
|
66 |
|
67 outargs = cell(5, 1); |
|
68 for i = 1 : 5 |
|
69 outargs{i} = defaultvals{i}; |
|
70 endfor |
|
71 |
|
72 if (nargin > 0) |
|
73 file_filter = varargin{1}; |
|
74 outargs{1} = __fltk_file_filter__ (file_filter); |
|
75 if (ischar (file_filter)) |
|
76 outargs{3} = file_filter; |
|
77 endif |
|
78 endif |
|
79 |
|
80 if (nargin > 1) |
|
81 outargs{2} = varargin{2}; |
|
82 endif |
|
83 |
|
84 if (nargin > 2) |
|
85 outargs{3} = varargin{3}; |
|
86 endif |
|
87 |
|
88 else |
|
89 error ("Number of input arguments must be less than four."); |
|
90 endif |
|
91 |
|
92 if (any (cellfun(@(x)strcmp (x, "fltk"), available_backends))) |
|
93 [retfile, retpath, retindex] = __fltk_uigetfile__ (outargs{:}); |
|
94 else |
|
95 error ("uiputfile requires fltk backend."); |
|
96 endif |
|
97 |
|
98 endfunction |
|
99 |
|
100 %!demo |
|
101 %! uiputfile({"*.gif;*.png;*.jpg", "Supported Picture Formats"}) |