Mercurial > octave
annotate scripts/gui/uiputfile.m @ 25054:6652d3823428 stable
maint: Update copyright dates in all source files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 30 Mar 2018 09:19:05 -0400 |
parents | 194eb4bd202b |
children | e04c56bbbace |
rev | line source |
---|---|
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1 ## Copyright (C) 2010-2018 Kai Habel |
11283 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
5 ## Octave is free software: you can redistribute it and/or modify it |
11283 | 6 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
7 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
8 ## (at your option) any later version. |
11283 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## GNU General Public License for more details. |
11283 | 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 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
17 ## <https://www.gnu.org/licenses/>. |
11283 | 18 |
19 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20778
diff
changeset
|
20 ## @deftypefn {} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile () |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20778
diff
changeset
|
21 ## @deftypefnx {} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20778
diff
changeset
|
22 ## @deftypefnx {} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt}, @var{dialog_name}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20778
diff
changeset
|
23 ## @deftypefnx {} {[@var{fname}, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt}, @var{dialog_name}, @var{default_file}) |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19799
diff
changeset
|
24 ## Open a GUI dialog for selecting a file. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19799
diff
changeset
|
25 ## |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19799
diff
changeset
|
26 ## @var{flt} contains a (list of) file filter string(s) in one of the following |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19799
diff
changeset
|
27 ## formats: |
11283 | 28 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16581
diff
changeset
|
29 ## @table @asis |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16581
diff
changeset
|
30 ## @item @qcode{"/path/to/filename.ext"} |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16581
diff
changeset
|
31 ## If a filename is given the file extension is extracted and used as filter. |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16581
diff
changeset
|
32 ## In addition the path is selected as current path and the filename is |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16581
diff
changeset
|
33 ## selected as default file. Example: @code{uiputfile ("myfun.m")} |
11283 | 34 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16581
diff
changeset
|
35 ## @item @qcode{"*.ext"} |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11583
diff
changeset
|
36 ## A single file extension. |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16581
diff
changeset
|
37 ## Example: @code{uiputfile ("*.ext")} |
11283 | 38 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16581
diff
changeset
|
39 ## @item @code{@{"*.ext", "My Description"@}} |
11283 | 40 ## A 2-column cell array containing the file extension in the 1st column and |
41 ## a brief description in the 2nd column. | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16581
diff
changeset
|
42 ## Example: @code{uiputfile (@{"*.ext","My Description";"*.xyz", |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16581
diff
changeset
|
43 ## "XYZ-Format"@})} |
11283 | 44 ## @end table |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11583
diff
changeset
|
45 ## |
11283 | 46 ## The filter string can also contain a semicolon separated list of filter |
47 ## extensions. | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16581
diff
changeset
|
48 ## Example: @code{uiputfile (@{"*.gif;*.png;*.jpg", |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16581
diff
changeset
|
49 ## "Supported Picture Formats"@})} |
11283 | 50 ## |
51 ## @var{dialog_name} can be used to customize the dialog title. | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11583
diff
changeset
|
52 ## If @var{default_file} is given it is preselected in the GUI dialog. |
12522
33bbae85769a
Add uimenu, uigetdir, uigetfile, and uiputfile to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12183
diff
changeset
|
53 ## If, in addition, a path is given it is also used as current path. |
15532
95d7475a0a89
doc: Add seealso links between uigetfile, uiputfile, uigetdir.
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
54 ## @seealso{uigetfile, uigetdir} |
11283 | 55 ## @end deftypefn |
56 | |
57 ## Author: Kai Habel | |
58 | |
59 function [retfile, retpath, retindex] = uiputfile (varargin) | |
60 | |
12522
33bbae85769a
Add uimenu, uigetdir, uigetfile, and uiputfile to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12183
diff
changeset
|
61 if (nargin > 3) |
33bbae85769a
Add uimenu, uigetdir, uigetfile, and uiputfile to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12183
diff
changeset
|
62 print_usage (); |
11283 | 63 endif |
64 | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19799
diff
changeset
|
65 ## Preset default values |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19799
diff
changeset
|
66 outargs = {cell(0, 2), # File Filter |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19799
diff
changeset
|
67 "Save File", # Dialog Title |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
19848
diff
changeset
|
68 "", # Default filename |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19799
diff
changeset
|
69 [240, 120], # Dialog Position (pixel x/y) |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19799
diff
changeset
|
70 "create", |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19799
diff
changeset
|
71 pwd}; # Default directory |
12522
33bbae85769a
Add uimenu, uigetdir, uigetfile, and uiputfile to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12183
diff
changeset
|
72 |
33bbae85769a
Add uimenu, uigetdir, uigetfile, and uiputfile to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12183
diff
changeset
|
73 if (nargin > 0) |
21843
f7a57b07c81d
Overhaul uigetfile, uiputfile, __file_filter__ (bug #48183).
Rik <rik@octave.org>
parents:
21841
diff
changeset
|
74 [outargs{1}, outargs{3}, defdir] = __file_filter__ ("uiputfile", |
f7a57b07c81d
Overhaul uigetfile, uiputfile, __file_filter__ (bug #48183).
Rik <rik@octave.org>
parents:
21841
diff
changeset
|
75 varargin{1}); |
f7a57b07c81d
Overhaul uigetfile, uiputfile, __file_filter__ (bug #48183).
Rik <rik@octave.org>
parents:
21841
diff
changeset
|
76 if (! isempty (defdir)) |
13697
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
77 outargs{6} = defdir; |
12522
33bbae85769a
Add uimenu, uigetdir, uigetfile, and uiputfile to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12183
diff
changeset
|
78 endif |
13697
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
79 else |
21843
f7a57b07c81d
Overhaul uigetfile, uiputfile, __file_filter__ (bug #48183).
Rik <rik@octave.org>
parents:
21841
diff
changeset
|
80 outargs{1} = __file_filter__ ("uiputfile", outargs{1}); |
11283 | 81 endif |
82 | |
12522
33bbae85769a
Add uimenu, uigetdir, uigetfile, and uiputfile to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12183
diff
changeset
|
83 if (nargin > 1) |
13697
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
84 if (ischar (varargin{2})) |
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
85 outargs{2} = varargin{2}; |
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
86 elseif (! isempty (varargin{2})) |
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
87 print_usage (); |
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
88 endif |
12522
33bbae85769a
Add uimenu, uigetdir, uigetfile, and uiputfile to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12183
diff
changeset
|
89 endif |
33bbae85769a
Add uimenu, uigetdir, uigetfile, and uiputfile to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12183
diff
changeset
|
90 |
33bbae85769a
Add uimenu, uigetdir, uigetfile, and uiputfile to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12183
diff
changeset
|
91 if (nargin > 2) |
13697
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
92 if (ischar (varargin{3})) |
19740
ca6fc882177d
Fix working directory of Figure Save dialog between CLI and GUI (bug #44175).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
93 if (isdir (varargin{3})) |
ca6fc882177d
Fix working directory of Figure Save dialog between CLI and GUI (bug #44175).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
94 fdir = varargin{3}; |
ca6fc882177d
Fix working directory of Figure Save dialog between CLI and GUI (bug #44175).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
95 fname = fext = ""; |
ca6fc882177d
Fix working directory of Figure Save dialog between CLI and GUI (bug #44175).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
96 else |
ca6fc882177d
Fix working directory of Figure Save dialog between CLI and GUI (bug #44175).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
97 [fdir, fname, fext] = fileparts (varargin{3}); |
ca6fc882177d
Fix working directory of Figure Save dialog between CLI and GUI (bug #44175).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
98 endif |
13697
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
99 if (! isempty (fdir)) |
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
100 outargs{6} = fdir; |
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
101 endif |
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
102 if (! isempty (fname) || ! isempty (fext)) |
20778
8513c84a13cb
Use parser string concatenation rather than strcat() for performance in m-files.
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
103 outargs{3} = [fname fext]; |
13697
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
104 endif |
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
105 elseif (! isempty (varargin{3})) |
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
106 print_usage (); |
0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13215
diff
changeset
|
107 endif |
12522
33bbae85769a
Add uimenu, uigetdir, uigetfile, and uiputfile to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12183
diff
changeset
|
108 endif |
33bbae85769a
Add uimenu, uigetdir, uigetfile, and uiputfile to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12183
diff
changeset
|
109 |
19848
9b7ca334a104
Backout cset a9952a647d52 and use __octave_link_enabled__ rather than isguirunning.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
110 if (__octave_link_enabled__ ()) |
16581
fa4a035e0cf4
Add octave_link uiputfile implementation
John Donoghue <john.donoghue@ieee.org>
parents:
15532
diff
changeset
|
111 [retfile, retpath, retindex] = __octave_link_file_dialog__ (outargs{:}); |
fa4a035e0cf4
Add octave_link uiputfile implementation
John Donoghue <john.donoghue@ieee.org>
parents:
15532
diff
changeset
|
112 else |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19799
diff
changeset
|
113 funcname = __get_funcname__ (mfilename ()); |
16581
fa4a035e0cf4
Add octave_link uiputfile implementation
John Donoghue <john.donoghue@ieee.org>
parents:
15532
diff
changeset
|
114 [retfile, retpath, retindex] = feval (funcname, outargs{:}); |
fa4a035e0cf4
Add octave_link uiputfile implementation
John Donoghue <john.donoghue@ieee.org>
parents:
15532
diff
changeset
|
115 endif |
12522
33bbae85769a
Add uimenu, uigetdir, uigetfile, and uiputfile to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12183
diff
changeset
|
116 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19799
diff
changeset
|
117 ## Append extension to the name if it isn't already added. |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19799
diff
changeset
|
118 if (ischar (retfile)) |
21841
cf690a73a186
uiputfile.m: Correctly handle '*.*' filter type (bug #48182).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
119 [~, ~, ext] = fileparts (retfile); |
cf690a73a186
uiputfile.m: Correctly handle '*.*' filter type (bug #48182).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
120 if (isempty (ext)) |
cf690a73a186
uiputfile.m: Correctly handle '*.*' filter type (bug #48182).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
121 ext = outargs{1}{retindex}; |
cf690a73a186
uiputfile.m: Correctly handle '*.*' filter type (bug #48182).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
122 ext = strrep (ext, "*", ""); |
21843
f7a57b07c81d
Overhaul uigetfile, uiputfile, __file_filter__ (bug #48183).
Rik <rik@octave.org>
parents:
21841
diff
changeset
|
123 if (! strcmp (ext, '.')) |
21841
cf690a73a186
uiputfile.m: Correctly handle '*.*' filter type (bug #48182).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
124 [~, ~, ext] = fileparts (ext); # paranoid checking of extension |
19362
7c31a83e25bc
uiputfile: add extension to file name (Bug #43687)
John Donoghue <john.donoghue@ieee.org>
parents:
17744
diff
changeset
|
125 retfile = [retfile ext]; |
7c31a83e25bc
uiputfile: add extension to file name (Bug #43687)
John Donoghue <john.donoghue@ieee.org>
parents:
17744
diff
changeset
|
126 endif |
7c31a83e25bc
uiputfile: add extension to file name (Bug #43687)
John Donoghue <john.donoghue@ieee.org>
parents:
17744
diff
changeset
|
127 endif |
7c31a83e25bc
uiputfile: add extension to file name (Bug #43687)
John Donoghue <john.donoghue@ieee.org>
parents:
17744
diff
changeset
|
128 endif |
7c31a83e25bc
uiputfile: add extension to file name (Bug #43687)
John Donoghue <john.donoghue@ieee.org>
parents:
17744
diff
changeset
|
129 |
11283 | 130 endfunction |
131 | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
132 |
11583
c4c2cd67c440
Fixes for ui file functions, bug#32190
Kai Habel <kai.habel@gmx.de>
parents:
11576
diff
changeset
|
133 %!demo |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
134 %! uiputfile ({'*.gif;*.png;*.jpg', 'Supported Picture Formats'}); |
13215 | 135 |
136 ## Remove from test statistics. No real tests possible. | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
137 %!assert (1) |