Mercurial > hg > octave-nkf
comparison scripts/plot/uiputfile.m @ 13697:0f8ff98929b2
Allow a toolkit to provide its own version of UI dialogs.
* plot/modules.mk (plot_PRIVATE_FCN_FILES): Add __file_filter__.m,
__is_function__.m, __uigetdir_fltk__.m, __uigetfile_fltk__.m,
__uiputfile_fltk__.m.
* plot/uigetdir.m: Rework to remove FLTK-specific stuffs and allow use of
toolkit-provided dialogs. Fallback to FLTK dialogs.
* plot/uigetfile.m: Likewise.
* plot/uiputfile.m: Likewise.
* plot/private/__fltk_file_filter__.m: Assumes input is now always a cell
array of strings.
* plot/private/__file_filter__.m: New file.
* plot/private/__is_function__.m: Likewise.
* plot/private/uigetdir_fltk__.m: Likewise.
* plot/private/uigetfile_fltk__.m: Likewise.
* plot/private/uiputfile_fltk__.m: Likewise.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Thu, 13 Oct 2011 16:46:28 +0100 |
parents | cb8fd692b600 |
children | 72c96de7a403 |
comparison
equal
deleted
inserted
replaced
13696:d6118a2c0644 | 13697:0f8ff98929b2 |
---|---|
53 | 53 |
54 ## Author: Kai Habel | 54 ## Author: Kai Habel |
55 | 55 |
56 function [retfile, retpath, retindex] = uiputfile (varargin) | 56 function [retfile, retpath, retindex] = uiputfile (varargin) |
57 | 57 |
58 if (exist("__fltk_uigetfile__") != 3) | 58 defaulttoolkit = get (0, "defaultfigure__graphics_toolkit__"); |
59 error ("uiputfile: fltk graphics toolkit required"); | 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", | |
67 defaulttoolkit); | |
68 endif | |
60 endif | 69 endif |
61 | 70 |
62 if (nargin > 3) | 71 if (nargin > 3) |
63 print_usage (); | 72 print_usage (); |
64 endif | 73 endif |
65 | 74 |
66 defaultvals = {"All Files(*)", #FLTK File Filter | 75 defaultvals = {cell(0, 2), # File Filter |
67 "Save File?", #Dialog Title | 76 "Save File", # Dialog Title |
68 pwd, #FLTK default file name | 77 "", # Default file name |
69 [240, 120], #Dialog Position (pixel x/y) | 78 [240, 120], # Dialog Position (pixel x/y) |
70 "create"}; | 79 "create", |
80 pwd}; # Default directory | |
71 | 81 |
72 outargs = cell(5, 1); | 82 outargs = cell(6, 1); |
73 for i = 1 : 5 | 83 for i = 1 : 6 |
74 outargs{i} = defaultvals{i}; | 84 outargs{i} = defaultvals{i}; |
75 endfor | 85 endfor |
76 | 86 |
77 if (nargin > 0) | 87 if (nargin > 0) |
78 file_filter = varargin{1}; | 88 file_filter = varargin{1}; |
79 outargs{1} = __fltk_file_filter__ (file_filter); | 89 [outargs{1}, outargs{3}, defdir] = __file_filter__ (file_filter); |
80 if (ischar (file_filter)) | 90 if (length (defdir) > 0) |
81 outargs{3} = file_filter; | 91 outargs{6} = defdir; |
92 endif | |
93 else | |
94 outargs{1} = __file_filter__ (outargs{1}); | |
95 endif | |
96 | |
97 if (nargin > 1) | |
98 if (ischar (varargin{2})) | |
99 outargs{2} = varargin{2}; | |
100 elseif (! isempty (varargin{2})) | |
101 print_usage (); | |
82 endif | 102 endif |
83 endif | 103 endif |
84 | 104 |
85 if (nargin > 1) | 105 if (nargin > 2) |
86 outargs{2} = varargin{2}; | 106 if (ischar (varargin{3})) |
107 [fdir, fname, fext] = fileparts (varargin{3}); | |
108 if (! isempty (fdir)) | |
109 outargs{6} = fdir; | |
110 endif | |
111 if (! isempty (fname) || ! isempty (fext)) | |
112 outargs{3} = strcat (fname, fext); | |
113 endif | |
114 elseif (! isempty (varargin{3})) | |
115 print_usage (); | |
116 endif | |
87 endif | 117 endif |
88 | 118 |
89 if (nargin > 2) | 119 [retfile, retpath, retindex] = feval (funcname, outargs{:}); |
90 outargs{3} = varargin{3}; | |
91 endif | |
92 | |
93 [retfile, retpath, retindex] = __fltk_uigetfile__ (outargs{:}); | |
94 | 120 |
95 endfunction | 121 endfunction |
96 | 122 |
97 %!demo | 123 %!demo |
98 %! uiputfile({"*.gif;*.png;*.jpg", "Supported Picture Formats"}) | 124 %! uiputfile({"*.gif;*.png;*.jpg", "Supported Picture Formats"}) |