# HG changeset patch
# User Kai Habel
# Date 1289767775 -3600
# Node ID 9393c5084f08339d5503333da898d5c2a5b93e28
# Parent ab1f780b67582fd2a1a7895ef86dadf26da183ef
ui file functions
diff -r ab1f780b6758 -r 9393c5084f08 scripts/plot/private/__fltk_file_filter__.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/private/__fltk_file_filter__.m Sun Nov 14 21:49:35 2010 +0100
@@ -0,0 +1,70 @@
+## Copyright (C) 2010 Kai Habel
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING. If not, see
+## .
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} __axis_label__ (@var{caller}, @var{txt}, @dots{})
+## Undocumented internal function.
+## @end deftypefn
+
+## Author: Kai Habel
+
+function retval = __fltk_file_filter__ (file_filter)
+## converts octaves file filter format into fltk's.
+ if (iscell (file_filter))
+ [r, c] = size (file_filter);
+ if ((c == 0) || (c > 2))
+ error ("expecting 1 or to 2 columns for file filter cell.");
+ endif
+ fltk_str = "";
+ for idx = 1 : r
+
+ curr_ext = file_filter{idx, 1};
+ curr_ext = strsplit (curr_ext, ";");
+
+ if (length (curr_ext) > 1)
+ curr_ext = regexprep (curr_ext, '\*\.', ',');
+ curr_ext = strcat (curr_ext{:})(2 : end);
+ curr_ext = strcat ("*.{", curr_ext, "}");
+ else
+ curr_ext = curr_ext{:};
+ endif
+
+ curr_desc = strcat (curr_ext(3:end), "-Files");
+
+ if (c == 2)
+ curr_desc = file_filter{idx, 2};
+ curr_desc = regexprep (curr_desc, '\(', '<');
+ curr_desc = regexprep (curr_desc, '\)', '>');
+ endif
+
+ if (length (fltk_str) > 0)
+ fltk_str = strcat (fltk_str, "\t", curr_desc, " (", curr_ext, ")");
+ else
+ fltk_str = strcat (curr_desc, " (", curr_ext, ")");
+ endif
+
+ endfor
+ retval = fltk_str;
+ elseif (ischar (file_filter))
+ outargs{3} = file_filter;
+ [fdir, fname, fext] = fileparts (file_filter);
+ if (length (fext) > 0)
+ retval = strcat ("*", fext, "\t*");
+ endif
+ endif
+endfunction
diff -r ab1f780b6758 -r 9393c5084f08 scripts/plot/uigetdir.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/uigetdir.m Sun Nov 14 21:49:35 2010 +0100
@@ -0,0 +1,50 @@
+## Copyright (C) 2010 Kai Habel
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING. If not, see
+## .
+
+## -*- texinfo -*-
+## @deftypefn {Function File} address@hidden =} uigetdir (@var{init_path}, @var{dialog_name})
+## @deftypefnx {Function File} address@hidden =} uigetdir (@var{init_path})
+## @deftypefnx {Function File} address@hidden =} uigetdir ()
+## Open a GUI dialog to select a directory. If @var{init_path} is not given
+## the working directory is taken. @var{dialog_name} can be used to
+## customize the dialog title.
+## @end deftypefn
+
+## Author: Kai Habel
+
+function [retdir] = uigetdir (init_path = pwd, name = "Choose directory?")
+
+ if (!ischar(init_path) || !ischar(name))
+ error ("Expecting string arguments.");
+ endif
+
+ if (nargin > 2)
+ print_usage ();
+ endif
+
+ if (any (cellfun(@(x)strcmp (x, "fltk"), available_backends)))
+ init_path = fileparts (init_path);
+ retdir = __fltk_uigetfile__("", name, init_path, [240, 120], "dir");
+ else
+ error ("uigetdir requires fltk backend.");
+ endif
+
+endfunction
+
+%!demo
+%! uigetdir(pwd);
diff -r ab1f780b6758 -r 9393c5084f08 scripts/plot/uigetfile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/uigetfile.m Sun Nov 14 21:49:35 2010 +0100
@@ -0,0 +1,155 @@
+## Copyright (C) 2010 Kai Habel
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING. If not, see
+## .
+
+## -*- texinfo -*-
+## @deftypefn {Function File} address@hidden, @var{fpath}, @var{fltidx}] =} uigetfile (@var{flt})
+## @deftypefnx {Function File} address@hidden =} uigetfile (@var{flt}, @var{dialog_name}, @var{default_file})
+## @deftypefnx {Function File} address@hidden =} uigetfile (@var{flt}, @var{dialog_name})
+## @deftypefnx {Function File} address@hidden =} uigetfile (@dots{},"Position",address@hidden, @var{py}])
+## @deftypefnx {Function File} address@hidden =} uigetfile (@dots{},"Multiselect",@var{mode})
+##
+## Opens a GUI dialog to select a file. It returns the filename @var{fname},
+## the path to this file @var{fpath} and the filter index @var{fltidx}.
+## @var{flt} contains a (list of) file filter string(s) in one of the following
+## formats:
+##
+## @table @code
+## @item "/path/to/filename.ext"
+## If a filename is given the file extension is extracted and used as filter.
+## In addtion the path is selected as current path and the filname is selected
+## as default file.
+## Example: uigetfile("myfun.m");
+##
+## @item A single file extension "*.ext".
+## Example: uigetfile("*.ext");
+##
+## @item A 2-column cell array,
+## containing the file extension in the 1st column and a brief description
+## in the 2nd column.
+## Example: uigetfile(@{"*.ext","My Description";"*.xyz","XYZ-Format"@});
+##
+## The filter string can also contain a semicolon separated list of filter
+## extensions.
+## Example: uigetfile(@{"*.gif;*.png;*.jpg", "Supported Picture Formats"@});
+## @end table
+##
+## @var{dialog_name} can be used to customize the dialog title.
+## If @var{default_file} is given it is selected in the GUI dialog.
+## If in addtion a path is given it is also used as current path.
+##
+## The screen position of the GUI dialog can be set by using the "Position" key
+## and a 2-valued vector containing the pixel coordinates.
+## Two or more files can be selected when setting the "Multiselect" key to "on".
+## In that case @var{fname} is a cell array containing the files.
+## @end deftypefn
+
+## Author: Kai Habel
+
+function [retfile, retpath, retindex] = uigetfile (varargin)
+
+ if (nargin <= 7)
+
+ defaultvals = {"All Files(*)", #FLTK File Filter
+ "Open File?", #Dialog Title
+ "", #FLTK default file name
+ [240, 120], #Dialog Position (pixel x/y)
+ "off"}; #Multiselect on/off
+
+ outargs = cell (5, 1);
+ for i = 1 : 5
+ outargs{i} = defaultvals{i};
+ endfor
+
+ idx1 = idx2 = [];
+ if (length (varargin) > 0)
+ for i = 1 : length (varargin)
+ val = varargin{i};
+ if (ischar (val))
+ if (strncmp (tolower (val), "multiselect", 11))
+ idx1 = i;
+ elseif (strncmp(tolower (val), "position", 8))
+ idx2 = i;
+ endif
+ endif
+ endfor
+ endif
+
+ stridx = [idx1, idx2, 0];
+ if (length (stridx) > 1)
+ stridx = min (stridx(1 : end - 1));
+ endif
+
+ args = varargin;
+ if (stridx)
+ args = varargin(1 : stridx - 1);
+ endif
+
+ len = length (args);
+ if (len > 0)
+ file_filter = args{1};
+ outargs{1} = __fltk_file_filter__ (file_filter);
+ if (ischar (file_filter))
+ outargs{3} = file_filter;
+ endif
+ endif
+
+ if (len > 1)
+ outargs{2} = args{2};
+ endif
+
+ if (len > 2)
+ outargs{3} = args{3};
+ endif
+
+ if (stridx)
+ ## we have string arguments ("position" or "multiselect")
+
+ ## check for even number of remaining arguments, prop/value pair(s)
+ if (rem (nargin - stridx + 1, 2))
+ error ("expecting property/value pairs");
+ endif
+
+ for i = stridx : 2 : nargin
+ prop = varargin{i};
+ val = varargin{i + 1};
+ if (strncmp (tolower (prop), "position", 8))
+ if (ismatrix (val) && length(val) == 2)
+ outargs{4} = val;
+ else
+ error ("expecting 2-element vector for position argument")
+ endif
+ elseif (strncmp (tolower (prop), "multiselect", 11))
+ if (ischar (val))
+ outargs{5} = tolower (val);
+ else
+ error ("expecting string argument (on/off) for multiselect")
+ endif
+ else
+ error ("unknown argument");
+ endif
+ endfor
+ endif
+ else
+ error ("number of input arguments must be less than eight");
+ endif
+
+ [retfile, retpath, retindex] = __fltk_uigetfile__(outargs{:});
+endfunction
+
+%!demo
+%! uigetfile({"*.gif;*.png;*.jpg", "Supported Picture Formats"});
diff -r ab1f780b6758 -r 9393c5084f08 scripts/plot/uiputfile.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/uiputfile.m Sun Nov 14 21:49:35 2010 +0100
@@ -0,0 +1,96 @@
+## Copyright (C) 2010 Kai Habel
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING. If not, see
+## .
+
+## -*- texinfo -*-
+## @deftypefn {Function File} address@hidden, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt}, @var{dialog_name}, @var{default_file})
+## @deftypefnx {Function File} address@hidden, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt}, @var{dialog_name})
+## @deftypefnx {Function File} address@hidden, @var{fpath}, @var{fltidx}] =} uiputfile (@var{flt})
+## @deftypefnx {Function File} address@hidden, @var{fpath}, @var{fltidx}] =} uiputfile ())
+## Opens a GUI dialog to select a file. @var{flt} contains a (list of) file
+## filter string(s) in one of the following formats:
+##
+## @table @code
+## @item "/path/to/filename.ext"
+## If a filename is given the file extension is
+## extracted and used as filter.
+## In addtion the path is selected as current path and the filname is selected
+## as default file.
+## Example: uiputfile("myfun.m");
+##
+## @item "*.ext"
+## A single file extension.
+## Example: uiputfile("*.ext");
+##
+## @item @{"*.ext","My Description"@}
+## A 2-column cell array containing the file extension in the 1st column and
+## a brief description in the 2nd column.
+## Example: uiputfile(@{"*.ext","My Description";"*.xyz","XYZ-Format"@});
+## @end table
+##
+## The filter string can also contain a semicolon separated list of filter
+## extensions.
+## Example: uiputfile(@{"*.gif;*.png;*.jpg", "Supported Picture Formats"@});
+##
+## @var{dialog_name} can be used to customize the dialog title.
+## If @var{default_file} is given it is preselected in the GUI dialog.
+## If in addtion a path is given it is also used as current path.
+## @end deftypefn
+
+## Author: Kai Habel
+
+function [retfile, retpath, retindex] = uiputfile (varargin)
+
+
+ if (nargin <= 3)
+
+ defaultvals = {"All Files(*)", #FLTK File Filter
+ "Save File?", #Dialog Title
+ "", #FLTK default file name
+ [240, 120], #Dialog Position (pixel x/y)
+ "create"};
+
+ outargs = cell(5, 1);
+ for i = 1 : 5
+ outargs{i} = defaultvals{i};
+ endfor
+
+ if (nargin > 0)
+ file_filter = varargin{1};
+ outargs{1} = __fltk_file_filter__ (file_filter);
+ if (ischar (file_filter))
+ outargs{3} = file_filter;
+ endif
+ endif
+
+ if (nargin > 1)
+ outargs{2} = varargin{2};
+ endif
+
+ if (nargin > 2)
+ outargs{3} = varargin{3};
+ endif
+
+ else
+ error ("Number of input arguments must be less than four.");
+ endif
+
+ [retfile, retpath, retindex] = __fltk_uigetfile__(outargs{:});
+endfunction
+
+%!demo
+%! uiputfile({"*.gif;*.png;*.jpg", "Supported Picture Formats"});
diff -r ab1f780b6758 -r 9393c5084f08 src/DLD-FUNCTIONS/fltk_backend.cc
--- a/src/DLD-FUNCTIONS/fltk_backend.cc Sat Nov 13 01:29:10 2010 -0500
+++ b/src/DLD-FUNCTIONS/fltk_backend.cc Sun Nov 14 21:49:35 2010 +0100
@@ -1970,4 +1970,106 @@
return retval;
}
+#include "file-ops.h"
+DEFUN_DLD (__fltk_uigetfile__, args, nargout,
+ "-*- texinfo -*-\n\
address@hidden {Built-in Function} {} __fltk_uigetfile__ (address@hidden)\n\
+Internal Function.\n\
+\n\
+\n\
address@hidden deftypefn")
+{
+ // This function should be called by uigetfile.m
+ // Error checking should be done in uigetfile.m!
+ //
+ // Expected argument list
+ // args(0) ... FileFilter in fltk format
+ // args(1) ... Title
+ // args(2) ... Default Filename
+ // args(3) ... PostionValue [x,y]
+ // args(4) ... SelectValue "on"/"off"/"dir"/"create"
+
+ std::string file_filter, title, default_name, multi;
+ if (args(0).is_string ())
+ file_filter = args(0).string_value();
+
+ if (args(1).is_string ())
+ title = args(1).string_value();
+
+ if (args(2).is_string ())
+ default_name = args(2).string_value();
+
+ if (args(3).is_real_matrix ())
+ Matrix pos = args(3).matrix_value();
+
+ int multi_type = Fl_File_Chooser::SINGLE;
+ std::string flabel = "Filename:";
+ if (args(4).is_string ())
+ {
+ multi = args(4).string_value();
+ if (multi == "on")
+ multi_type = Fl_File_Chooser::MULTI;
+ else if (multi == "dir")
+ {
+ multi_type = Fl_File_Chooser::DIRECTORY;
+ flabel = "Directory:";
+ }
+ else if (multi == "create")
+ multi_type = Fl_File_Chooser::CREATE;
+ }
+
+ Fl_File_Chooser::filename_label = flabel.c_str ();
+ Fl_File_Chooser *fc = new Fl_File_Chooser(default_name.c_str (), file_filter.c_str (), multi_type, title.c_str ());
+ fc->preview(0);
+
+ if (multi_type == Fl_File_Chooser::CREATE)
+ fc->ok_label("Save");
+
+ fc->show();
+ while (fc->shown ())
+ { Fl::wait (); }
+
+ octave_value_list fargs, retval;
+
+ retval(0) = octave_value(0);
+ retval(1) = octave_value(0);
+ retval(2) = octave_value(0);
+
+ if (fc->value() != NULL)
+ {
+ int file_count = fc->count ();
+ std::string fname;
+ std::string sep = file_ops::dir_sep_str ();
+ std::size_t idx;
+
+ if ((file_count == 1) && (multi_type != Fl_File_Chooser::DIRECTORY))
+ {
+ fname = fc->value ();
+ idx = fname.find_last_of(sep);
+ retval(0) = fname.substr(idx + 1);
+ }
+ else
+ {
+ Cell file_cell = Cell(file_count, 1);
+ for (octave_idx_type n = 1; n <= file_count; n++)
+ {
+ fname = fc->value (n);
+ idx = fname.find_last_of(sep);
+ file_cell(n - 1) = fname.substr(idx + 1);
+ }
+ retval(0) = file_cell;
+ }
+
+ if (multi_type == Fl_File_Chooser::DIRECTORY)
+ retval(0) = std::string(fc->value ());
+ else
+ {
+ retval(1) = std::string(fc->directory ());
+ retval(2) = fc->filter_value();
+ }
+ }
+
+ return retval;
+}
+
#endif