Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/__fltk_uigetfile__.cc @ 12263:c626741871a0 release-3-4-x
Allow ui file function to work if gnuplot is the selected toolkit and fltk is available
author | Kai Habel <kai.habel@gmx.de> |
---|---|
date | Thu, 27 Jan 2011 17:58:19 +0100 |
parents | |
children | 03c7fdee3d36 |
comparison
equal
deleted
inserted
replaced
12262:b22c00315df5 | 12263:c626741871a0 |
---|---|
1 /* | |
2 | |
3 Copyright (C) 2010-2011 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 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #if defined (HAVE_FLTK) | |
28 | |
29 #include <FL/Fl.H> | |
30 #include <Fl/Fl_File_Chooser.H> | |
31 #include "defun-dld.h" | |
32 #include "file-ops.h" | |
33 | |
34 | |
35 DEFUN_DLD (__fltk_uigetfile__, args, , | |
36 "-*- texinfo -*-\n\ | |
37 @deftypefn {Built-in Function} {} __fltk_uigetfile__ (@dots{})\n\ | |
38 Undocumented internal function.\n\ | |
39 @end deftypefn") | |
40 { | |
41 | |
42 // Expected argument list | |
43 // args(0) ... FileFilter in fltk format | |
44 // args(1) ... Title | |
45 // args(2) ... Default Filename | |
46 // args(3) ... PostionValue [x,y] | |
47 // args(4) ... SelectValue "on"/"off"/"dir"/"create" | |
48 | |
49 octave_value_list fargs, retval; | |
50 | |
51 std::string file_filter = args(0).string_value(); | |
52 std::string title = args(1).string_value(); | |
53 std::string default_name = args(2).string_value(); | |
54 Matrix pos = args(3).matrix_value(); | |
55 | |
56 int multi_type = Fl_File_Chooser::SINGLE; | |
57 std::string flabel = "Filename:"; | |
58 | |
59 std::string multi = args(4).string_value(); | |
60 if (multi == "on") | |
61 multi_type = Fl_File_Chooser::MULTI; | |
62 else if (multi == "dir") | |
63 { | |
64 multi_type = Fl_File_Chooser::DIRECTORY; | |
65 flabel = "Directory:"; | |
66 } | |
67 else if (multi == "create") | |
68 multi_type = Fl_File_Chooser::CREATE; | |
69 | |
70 Fl_File_Chooser::filename_label = flabel.c_str (); | |
71 Fl_File_Chooser *fc = new Fl_File_Chooser (default_name.c_str (), file_filter.c_str (), multi_type, title.c_str ()); | |
72 fc->preview (0); | |
73 | |
74 if (multi_type == Fl_File_Chooser::CREATE) | |
75 fc->ok_label ("Save"); | |
76 | |
77 fc->show (); | |
78 | |
79 while (fc->shown ()) | |
80 Fl::wait (); | |
81 | |
82 retval(0) = octave_value(0); | |
83 retval(1) = octave_value(0); | |
84 retval(2) = octave_value(0); | |
85 | |
86 if (fc->value()) | |
87 { | |
88 int file_count = fc->count (); | |
89 std::string fname; | |
90 std::string sep = file_ops::dir_sep_str (); | |
91 std::size_t idx; | |
92 | |
93 if (file_count == 1 && multi_type != Fl_File_Chooser::DIRECTORY) | |
94 { | |
95 fname = fc->value (); | |
96 idx = fname.find_last_of (sep); | |
97 retval(0) = fname.substr (idx + 1); | |
98 } | |
99 else | |
100 { | |
101 Cell file_cell = Cell(file_count, 1); | |
102 for (octave_idx_type n = 1; n <= file_count; n++) | |
103 { | |
104 fname = fc->value (n); | |
105 idx = fname.find_last_of (sep); | |
106 file_cell(n - 1) = fname.substr (idx + 1); | |
107 } | |
108 retval(0) = file_cell; | |
109 } | |
110 | |
111 if (multi_type == Fl_File_Chooser::DIRECTORY) | |
112 retval(0) = std::string (fc->value ()); | |
113 else | |
114 { | |
115 retval(1) = std::string (fc->directory ()) + sep; | |
116 retval(2) = fc->filter_value (); | |
117 } | |
118 } | |
119 | |
120 fc->hide (); | |
121 Fl::flush (); | |
122 delete fc; | |
123 | |
124 return retval; | |
125 } | |
126 | |
127 #endif |