GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
__fltk_uigetfile__.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2010-2017 Kai Habel
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #if defined (HAVE_FLTK)
28 
29 #if defined (WIN32)
30 # define WIN32_LEAN_AND_MEAN
31 #endif
32 
33 #include <FL/Fl.H>
34 #include <FL/Fl_File_Chooser.H>
35 
36 // FLTK headers may include X11/X.h which defines Complex, and that
37 // conflicts with Octave's Complex typedef. We don't need the X11
38 // Complex definition in this file, so remove it before including Octave
39 // headers which may require Octave's Complex typedef.
40 #undef Complex
41 
42 #endif
43 
44 #include "defun-dld.h"
45 #include "errwarn.h"
46 #include "file-ops.h"
47 
48 DEFUN_DLD (__fltk_uigetfile__, args, ,
49  doc: /* -*- texinfo -*-
50 @deftypefn {} {} __fltk_uigetfile__ (@dots{})
51 Undocumented internal function.
52 @end deftypefn */)
53 {
54 #if defined (HAVE_FLTK)
55 
56  // Expected argument list:
57  //
58  // args(0) ... FileFilter in fltk format
59  // args(1) ... Title
60  // args(2) ... Default Filename
61  // args(3) ... PositionValue [x,y]
62  // args(4) ... SelectValue "on"/"off"/"dir"/"create"
63 
65 
66  std::string file_filter = args(0).string_value ();
67  std::string title = args(1).string_value ();
68  std::string default_name = args(2).string_value ();
69  Matrix pos = args(3).matrix_value ();
70 
71  int multi_type = Fl_File_Chooser::SINGLE;
72  std::string flabel = "Filename:";
73 
74  std::string multi = args(4).string_value ();
75  if (multi == "on")
76  multi_type = Fl_File_Chooser::MULTI;
77  else if (multi == "dir")
78  {
79  multi_type = Fl_File_Chooser::DIRECTORY;
80  flabel = "Directory:";
81  }
82  else if (multi == "create")
83  multi_type = Fl_File_Chooser::CREATE;
84 
85  Fl_File_Chooser::filename_label = flabel.c_str ();
86 
87  Fl_File_Chooser fc (default_name.c_str (), file_filter.c_str (),
88  multi_type, title.c_str ());
89 
90  fc.preview (0);
91 
92  if (multi_type == Fl_File_Chooser::CREATE)
93  fc.ok_label ("Save");
94 
95  fc.show ();
96 
97  while (fc.shown ())
98  Fl::wait ();
99 
100  if (fc.value ())
101  {
102  int file_count = fc.count ();
104 
105  //fltk uses forward slash even for windows
106  std::string sep = "/";
107  size_t idx;
108 
109  if (file_count == 1 && multi_type != Fl_File_Chooser::DIRECTORY)
110  {
111  fname = fc.value ();
112  idx = fname.find_last_of (sep);
113  retval(0) = fname.substr (idx + 1);
114  }
115  else
116  {
117  Cell file_cell = Cell (file_count, 1);
118  for (octave_idx_type n = 1; n <= file_count; n++)
119  {
120  fname = fc.value (n);
121  idx = fname.find_last_of (sep);
122  file_cell(n - 1) = fname.substr (idx + 1);
123  }
124  retval(0) = file_cell;
125  }
126 
127  if (multi_type == Fl_File_Chooser::DIRECTORY)
129  std::string (fc.value ()));
130  else
131  {
133  std::string (fc.directory ()) + sep);
134  retval(2) = fc.filter_value () + 1;
135  }
136  }
137 
138  fc.hide ();
139  Fl::flush ();
140 
141  return retval;
142 
143 #else
144 
145  octave_unused_parameter (args);
146 
147  err_disabled_feature ("__fltk_uigetfile__", "OpenGL and FLTK");
148 
149 #endif
150 }
151 
152 /*
153 ## No test needed for internal helper function.
154 %!assert (1)
155 */
Definition: Cell.h:37
fname
Definition: load-save.cc:754
JNIEnv void * args
Definition: ov-java.cc:67
octave_value retval
Definition: data.cc:6294
Definition: dMatrix.h:37
static std::string native_separator_path(const std::string &path)
Definition: file-ops.cc:385
#define DEFUN_DLD(name, args_name, nargout_name, doc)
Definition: defun-dld.h:45
void err_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
Definition: errwarn.cc:50
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854