view libinterp/dldfcn/__fltk_uigetfile__.cc @ 21109:bd1752782e56

Use err_disabled_feature, warn_disabled_feature throughout code base. In liboctave, use the same error text as err_disabled_feature, but call error_handler directly because err_disabled_feature is in libinterp. * errwarn.cc (err_disabled_feature): Don't print leading "%s:" if calling function is "". * errwarn.cc (warn_disabled_feature): New function. Same msg as err_disabled_feature but uses warning rather than error. * errwarn.h (warn_disabled_feature): prototype for new function. * file-io.cc, gl-render.cc, gl2ps-renderer.cc, load-save.cc, ls-mat5.cc, oct-hdf5-types.cc, pt-jit.cc, syscalls.cc, sysdep.cc, toplev.cc, __delaunayn__.cc, __eigs__.cc, __fltk_uigetfile__.cc, __init_fltk__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc, ccolamd.cc, colamd.cc, convhulln.cc, dmperm.cc, fftw.cc, symbfact.cc: Replace calls to error about missing feature with calls to err_disabled_feature. Replace calls to warning about missing feature with calls to warn_disabled_feature. * CSparse.cc, dSparse.cc, SparseCmplxLU.cc, SparseCmplxQR.cc, SparseQR.cc, SparsedbleLU.cc, sparse-base-chol.cc, sparse-dmsolve.cc, oct-shlib.cc: Use same text of message from err_disabled_feature but call (*current_liboctave_error_handler) or (*current_liboctave_warning_with_id_handler).
author Rik <rik@octave.org>
date Tue, 19 Jan 2016 12:44:54 -0800
parents f9a0bf346ec1
children ba0a4b4f021d
line wrap: on
line source

/*

Copyright (C) 2010-2015 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
<http://www.gnu.org/licenses/>.

*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef HAVE_FLTK

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#endif

#include <FL/Fl.H>
#include <FL/Fl_File_Chooser.H>

// FLTK headers may include X11/X.h which defines Complex, and that
// conflicts with Octave's Complex typedef.  We don't need the X11
// Complex definition in this file, so remove it before including Octave
// headers which may require Octave's Complex typedef.
#undef Complex

#endif

#include "defun-dld.h"
#include "file-ops.h"

DEFUN_DLD (__fltk_uigetfile__, args, ,
           "-*- texinfo -*-\n\
@deftypefn {} {} __fltk_uigetfile__ (@dots{})\n\
Undocumented internal function.\n\
@end deftypefn")
{
#ifdef HAVE_FLTK
  // Expected argument list:
  //
  //   args(0) ... FileFilter in fltk format
  //   args(1) ... Title
  //   args(2) ... Default Filename
  //   args(3) ... PositionValue [x,y]
  //   args(4) ... SelectValue "on"/"off"/"dir"/"create"

  octave_value_list retval (3, octave_value (0));

  std::string file_filter = args(0).string_value ();
  std::string title = args(1).string_value ();
  std::string default_name = args(2).string_value ();
  Matrix pos = args(3).matrix_value ();

  int multi_type = Fl_File_Chooser::SINGLE;
  std::string flabel = "Filename:";

  std::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 (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 ();

  if (fc.value ())
    {
      int file_count = fc.count ();
      std::string fname;

      //fltk uses forward slash even for windows
      std::string sep = "/";
      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) = file_ops::native_separator_path (std::string (fc.value ()));
      else
        {
          retval(1) = file_ops::native_separator_path (
                        std::string (fc.directory ()) + sep);
          retval(2) = fc.filter_value () + 1;
        }
    }

  fc.hide ();
  Fl::flush ();

  return retval;

#else
  err_disabled_feature ("__fltk_uigetfile__", "OpenGL and FLTK");
#endif
}

/*
## No test needed for internal helper function.
%!assert (1)
*/