Mercurial > hg > octave-lyh
comparison src/DLD-FUNCTIONS/__fltk_uigetfile__.cc @ 12286:45c97076c161 release-3-4-x
__fltk_uigetfile__.cc: style fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 29 Jan 2011 13:05:18 -0500 |
parents | db14b8095edd |
children | 67f98480b181 |
comparison
equal
deleted
inserted
replaced
12285:db14b8095edd | 12286:45c97076c161 |
---|---|
36 #undef Complex | 36 #undef Complex |
37 | 37 |
38 #include "defun-dld.h" | 38 #include "defun-dld.h" |
39 #include "file-ops.h" | 39 #include "file-ops.h" |
40 | 40 |
41 | |
42 DEFUN_DLD (__fltk_uigetfile__, args, , | 41 DEFUN_DLD (__fltk_uigetfile__, args, , |
43 "-*- texinfo -*-\n\ | 42 "-*- texinfo -*-\n\ |
44 @deftypefn {Built-in Function} {} __fltk_uigetfile__ (@dots{})\n\ | 43 @deftypefn {Built-in Function} {} __fltk_uigetfile__ (@dots{})\n\ |
45 Undocumented internal function.\n\ | 44 Undocumented internal function.\n\ |
46 @end deftypefn") | 45 @end deftypefn") |
47 { | 46 { |
48 | 47 // Expected argument list: |
49 // Expected argument list | 48 // |
50 // args(0) ... FileFilter in fltk format | 49 // args(0) ... FileFilter in fltk format |
51 // args(1) ... Title | 50 // args(1) ... Title |
52 // args(2) ... Default Filename | 51 // args(2) ... Default Filename |
53 // args(3) ... PostionValue [x,y] | 52 // args(3) ... PostionValue [x,y] |
54 // args(4) ... SelectValue "on"/"off"/"dir"/"create" | 53 // args(4) ... SelectValue "on"/"off"/"dir"/"create" |
55 | 54 |
56 octave_value_list fargs, retval; | 55 octave_value_list retval (3, octave_value (0)); |
57 | 56 |
58 std::string file_filter = args(0).string_value(); | 57 std::string file_filter = args(0).string_value(); |
59 std::string title = args(1).string_value(); | 58 std::string title = args(1).string_value(); |
60 std::string default_name = args(2).string_value(); | 59 std::string default_name = args(2).string_value(); |
61 Matrix pos = args(3).matrix_value(); | 60 Matrix pos = args(3).matrix_value(); |
62 | 61 |
63 int multi_type = Fl_File_Chooser::SINGLE; | 62 int multi_type = Fl_File_Chooser::SINGLE; |
64 std::string flabel = "Filename:"; | 63 std::string flabel = "Filename:"; |
65 | 64 |
66 std::string multi = args(4).string_value(); | 65 std::string multi = args(4).string_value(); |
67 if (multi == "on") | 66 if (multi == "on") |
68 multi_type = Fl_File_Chooser::MULTI; | 67 multi_type = Fl_File_Chooser::MULTI; |
69 else if (multi == "dir") | 68 else if (multi == "dir") |
70 { | 69 { |
73 } | 72 } |
74 else if (multi == "create") | 73 else if (multi == "create") |
75 multi_type = Fl_File_Chooser::CREATE; | 74 multi_type = Fl_File_Chooser::CREATE; |
76 | 75 |
77 Fl_File_Chooser::filename_label = flabel.c_str (); | 76 Fl_File_Chooser::filename_label = flabel.c_str (); |
78 Fl_File_Chooser *fc = new Fl_File_Chooser (default_name.c_str (), file_filter.c_str (), multi_type, title.c_str ()); | 77 |
79 fc->preview (0); | 78 Fl_File_Chooser fc (default_name.c_str (), file_filter.c_str (), |
79 multi_type, title.c_str ()); | |
80 | |
81 fc.preview (0); | |
80 | 82 |
81 if (multi_type == Fl_File_Chooser::CREATE) | 83 if (multi_type == Fl_File_Chooser::CREATE) |
82 fc->ok_label ("Save"); | 84 fc.ok_label ("Save"); |
83 | 85 |
84 fc->show (); | 86 fc.show (); |
85 | 87 |
86 while (fc->shown ()) | 88 while (fc.shown ()) |
87 Fl::wait (); | 89 Fl::wait (); |
88 | 90 |
89 retval(0) = octave_value(0); | 91 if (fc.value()) |
90 retval(1) = octave_value(0); | |
91 retval(2) = octave_value(0); | |
92 | |
93 if (fc->value()) | |
94 { | 92 { |
95 int file_count = fc->count (); | 93 int file_count = fc.count (); |
96 std::string fname; | 94 std::string fname; |
97 std::string sep = file_ops::dir_sep_str (); | 95 std::string sep = file_ops::dir_sep_str (); |
98 std::size_t idx; | 96 std::size_t idx; |
99 | 97 |
100 if (file_count == 1 && multi_type != Fl_File_Chooser::DIRECTORY) | 98 if (file_count == 1 && multi_type != Fl_File_Chooser::DIRECTORY) |
101 { | 99 { |
102 fname = fc->value (); | 100 fname = fc.value (); |
103 idx = fname.find_last_of (sep); | 101 idx = fname.find_last_of (sep); |
104 retval(0) = fname.substr (idx + 1); | 102 retval(0) = fname.substr (idx + 1); |
105 } | 103 } |
106 else | 104 else |
107 { | 105 { |
108 Cell file_cell = Cell(file_count, 1); | 106 Cell file_cell = Cell(file_count, 1); |
109 for (octave_idx_type n = 1; n <= file_count; n++) | 107 for (octave_idx_type n = 1; n <= file_count; n++) |
110 { | 108 { |
111 fname = fc->value (n); | 109 fname = fc.value (n); |
112 idx = fname.find_last_of (sep); | 110 idx = fname.find_last_of (sep); |
113 file_cell(n - 1) = fname.substr (idx + 1); | 111 file_cell(n - 1) = fname.substr (idx + 1); |
114 } | 112 } |
115 retval(0) = file_cell; | 113 retval(0) = file_cell; |
116 } | 114 } |
117 | 115 |
118 if (multi_type == Fl_File_Chooser::DIRECTORY) | 116 if (multi_type == Fl_File_Chooser::DIRECTORY) |
119 retval(0) = std::string (fc->value ()); | 117 retval(0) = std::string (fc.value ()); |
120 else | 118 else |
121 { | 119 { |
122 retval(1) = std::string (fc->directory ()) + sep; | 120 retval(1) = std::string (fc.directory ()) + sep; |
123 retval(2) = fc->filter_value () + 1; | 121 retval(2) = fc.filter_value () + 1; |
124 } | 122 } |
125 } | 123 } |
126 | 124 |
127 fc->hide (); | 125 fc.hide (); |
128 Fl::flush (); | 126 Fl::flush (); |
129 delete fc; | |
130 | 127 |
131 return retval; | 128 return retval; |
132 } | 129 } |
133 | 130 |
134 #endif | 131 #endif |