comparison org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/widgets/FileDialog.d @ 49:7a2dd761a8b2

more work until dmd 2.026 linux segfaults.
author Frank Benoit <benoit@tionex.de>
date Fri, 27 Mar 2009 12:59:54 +0100
parents ddbfe84d86df
children d5075f5226e5
comparison
equal deleted inserted replaced
48:ddbfe84d86df 49:7a2dd761a8b2
21 import org.eclipse.swt.widgets.Shell; 21 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.swt.widgets.Display; 22 import org.eclipse.swt.widgets.Display;
23 import java.lang.all; 23 import java.lang.all;
24 24
25 version(Tango){ 25 version(Tango){
26 static import tango.io.model.IFile; 26 static import tango.io.model.IFile;
27 static import tango.text.Util;
28 } else { // Phobos 27 } else { // Phobos
29 } 28 }
30 29
31 /** 30 /**
32 * Instances of this class allow the user to navigate 31 * Instances of this class allow the user to navigate
56 String[] fileNames; 55 String[] fileNames;
57 String fullPath = ""; 56 String fullPath = "";
58 int filterIndex = -1; 57 int filterIndex = -1;
59 bool overwrite = false; 58 bool overwrite = false;
60 GtkWidget* handle; 59 GtkWidget* handle;
61 static final char SEPARATOR = tango.io.model.IFile.FileConst.PathSeparatorChar; 60 version(Tango){
62 static final char EXTENSION_SEPARATOR = ';'; 61 static const char SEPARATOR = tango.io.model.IFile.FileConst.PathSeparatorChar;
62 } else { // Phobos
63 static const char SEPARATOR = std.path.sep;
64 }
65 static const char EXTENSION_SEPARATOR = ';';
63 66
64 /** 67 /**
65 * Constructs a new instance of this class given only its parent. 68 * Constructs a new instance of this class given only its parent.
66 * 69 *
67 * @param parent a shell which will be the parent of the new instance 70 * @param parent a shell which will be the parent of the new instance
119 uint items_written; 122 uint items_written;
120 char* utf8Ptr = OS.g_filename_to_utf8 (name, -1, null, &items_written, null); 123 char* utf8Ptr = OS.g_filename_to_utf8 (name, -1, null, &items_written, null);
121 OS.g_free (name); 124 OS.g_free (name);
122 if (utf8Ptr !is null) { 125 if (utf8Ptr !is null) {
123 fullPath = utf8Ptr[ 0 .. items_written ].dup; 126 fullPath = utf8Ptr[ 0 .. items_written ].dup;
124 int start = tango.text.Util.locatePrior( fullPath, SEPARATOR); 127 int start = fullPath.lastIndexOf( SEPARATOR);
125 if( start is fullPath.length ) start = -1;
126 fileNames [writePos++] = fullPath[ start + 1 .. $ ].dup; 128 fileNames [writePos++] = fullPath[ start + 1 .. $ ].dup;
127 OS.g_free (utf8Ptr); 129 OS.g_free (utf8Ptr);
128 } 130 }
129 current = OS.g_slist_next (current); 131 current = OS.g_slist_next (current);
130 } 132 }
141 auto utf8Ptr = OS.g_filename_to_utf8 (path, -1, null, &items_written, null); 143 auto utf8Ptr = OS.g_filename_to_utf8 (path, -1, null, &items_written, null);
142 OS.g_free (path); 144 OS.g_free (path);
143 if (utf8Ptr !is null) { 145 if (utf8Ptr !is null) {
144 fullPath = utf8Ptr[ 0 .. items_written ].dup; 146 fullPath = utf8Ptr[ 0 .. items_written ].dup;
145 fileNames = new String [1]; 147 fileNames = new String [1];
146 int start = tango.text.Util.locatePrior( fullPath, SEPARATOR); 148 int start = fullPath.lastIndexOf( SEPARATOR);
147 if( start == fullPath.length ) start = -1;
148 fileNames[0] = fullPath[ start + 1 .. $ ]; 149 fileNames[0] = fullPath[ start + 1 .. $ ];
149 OS.g_free (utf8Ptr); 150 OS.g_free (utf8Ptr);
150 } 151 }
151 } 152 }
152 } 153 }
171 } 172 }
172 } 173 }
173 } 174 }
174 } 175 }
175 if (fullPath !is null) { 176 if (fullPath !is null) {
176 int separatorIndex = tango.text.Util.locatePrior( fullPath, SEPARATOR); 177 int separatorIndex = fullPath.lastIndexOf( SEPARATOR);
177 if( separatorIndex is fullPath.length ) separatorIndex = -1;
178 fileName = fullPath[separatorIndex + 1 .. $ ]; 178 fileName = fullPath[separatorIndex + 1 .. $ ];
179 filterPath = fullPath[0 .. separatorIndex ]; 179 filterPath = fullPath[0 .. separatorIndex ];
180 } 180 }
181 return fullPath; 181 return fullPath;
182 } 182 }
217 auto utf8Ptr = OS.g_filename_to_utf8 (fileNamePtr, -1, null, &items_written, null); 217 auto utf8Ptr = OS.g_filename_to_utf8 (fileNamePtr, -1, null, &items_written, null);
218 String osAnswer = utf8Ptr[ 0 .. items_written ].dup; 218 String osAnswer = utf8Ptr[ 0 .. items_written ].dup;
219 OS.g_free (utf8Ptr); 219 OS.g_free (utf8Ptr);
220 220
221 if (osAnswer.length is 0) return null; 221 if (osAnswer.length is 0) return null;
222 int separatorIndex = tango.text.Util.locatePrior( osAnswer, SEPARATOR); 222 int separatorIndex = osAnswer.lastIndexOf( SEPARATOR);
223 if (separatorIndex is osAnswer.length ) separatorIndex = -1;
224 if (separatorIndex+1 is osAnswer.length ) return null; 223 if (separatorIndex+1 is osAnswer.length ) return null;
225 224
226 String answer = fullPath = osAnswer; 225 String answer = fullPath = osAnswer;
227 fileName = fullPath[ separatorIndex+1 .. $ ]; 226 fileName = fullPath[ separatorIndex+1 .. $ ];
228 filterPath = fullPath[ 0 .. separatorIndex ]; 227 filterPath = fullPath[ 0 .. separatorIndex ];
239 } 238 }
240 fileNames = new String[](length_); 239 fileNames = new String[](length_);
241 for (int i = 0; i < length_; i++) { 240 for (int i = 0; i < length_; i++) {
242 utf8Ptr = OS.g_filename_to_utf8 (namesPtr [i], -1, null, &items_written, null); 241 utf8Ptr = OS.g_filename_to_utf8 (namesPtr [i], -1, null, &items_written, null);
243 String name = utf8Ptr[ 0 .. items_written ].dup; 242 String name = utf8Ptr[ 0 .. items_written ].dup;
244 int start = tango.text.Util.locatePrior( name, SEPARATOR); 243 int start = name.lastIndexOf( SEPARATOR);
245 if( start == name.length ) start = -1;
246 fileNames [i] = name[ start + 1 .. $ ].dup; 244 fileNames [i] = name[ start + 1 .. $ ].dup;
247 OS.g_free (utf8Ptr); 245 OS.g_free (utf8Ptr);
248 } 246 }
249 OS.g_strfreev (namesPtr); 247 OS.g_strfreev (namesPtr);
250 } 248 }
527 } else { 525 } else {
528 char* name = toStringz(filterExtensions [i]); 526 char* name = toStringz(filterExtensions [i]);
529 OS.gtk_file_filter_set_name (filter, name); 527 OS.gtk_file_filter_set_name (filter, name);
530 } 528 }
531 int start = 0; 529 int start = 0;
532 int index = tango.text.Util.locate( filterExtensions [i], EXTENSION_SEPARATOR ); 530 int index = filterExtensions [i].indexOf( EXTENSION_SEPARATOR );
533 while (index !is filterExtensions [i].length ) { 531 while (index !is -1 ) {
534 String current = filterExtensions [i][ start .. index ]; 532 String current = filterExtensions [i][ start .. index ];
535 char* filterString = toStringz(current); 533 char* filterString = toStringz(current);
536 OS.gtk_file_filter_add_pattern (filter, filterString); 534 OS.gtk_file_filter_add_pattern (filter, filterString);
537 start = index + 1; 535 start = index + 1;
538 index = tango.text.Util.locate( filterExtensions [i], EXTENSION_SEPARATOR, start); 536 index = filterExtensions [i].indexOf( EXTENSION_SEPARATOR, start);
539 } 537 }
540 String current = filterExtensions [i][ start .. $ ]; 538 String current = filterExtensions [i][ start .. $ ];
541 char* filterString = toStringz(current); 539 char* filterString = toStringz(current);
542 OS.gtk_file_filter_add_pattern (filter, filterString); 540 OS.gtk_file_filter_add_pattern (filter, filterString);
543 OS.gtk_file_chooser_add_filter (handle, filter); 541 OS.gtk_file_chooser_add_filter (handle, filter);