17
typedef struct W_FilePanel {
29
WMButton *cancelButton;
32
WMButton *trashcanButton;
33
WMButton *createDirButton;
34
WMButton *disketteButton;
35
WMButton *unmountButton;
37
WMView *accessoryView;
39
WMTextField *fileField;
44
unsigned int canExit:1;
45
unsigned int canceled:1; /* clicked on cancel */
46
unsigned int filtered:1;
47
unsigned int canChooseFiles:1;
48
unsigned int canChooseDirectories:1;
49
unsigned int autoCompletion:1;
50
unsigned int showAllFiles:1;
51
unsigned int canFreeFileTypes:1;
52
unsigned int fileMustExist:1;
53
unsigned int panelType:1;
65
static void listDirectoryOnColumn(WMFilePanel *panel, int column, char *path);
66
static void browserClick();
67
static void browserDClick();
69
static void fillColumn(WMBrowserDelegate *self, WMBrowser *bPtr, int column,
72
static void deleteFile();
74
static void createDir();
78
static void goFloppy();
80
static void goUnmount();
82
static void buttonClick();
84
static char *getCurrentFileName(WMFilePanel *panel);
86
static void handleEvents(XEvent *event, void *data);
90
static WMBrowserDelegate browserDelegate = {
92
fillColumn, /* createRowsForColumn */
93
NULL, /* titleOfColumn */
100
closestListItem(WMList *list, char *text, Bool exact)
103
WMArray *items = WMGetListItems(list);
104
int i, len = strlen(text);
109
for(i=0; i<WMGetArrayItemCount(items); i++) {
110
item = WMGetFromArray(items, i);
111
if (strlen(item->text) >= len &&
112
((exact && strcmp(item->text, text)==0) ||
113
(!exact && strncmp(item->text, text, len)==0))) {
123
textChangedObserver(void *observerData, WMNotification *notification)
125
W_FilePanel *panel = (W_FilePanel*)observerData;
128
int col = WMGetBrowserNumberOfColumns(panel->browser) - 1;
131
if (!(list = WMGetBrowserListInColumn(panel->browser, col)))
134
text = WMGetTextFieldText(panel->fileField);
135
textEvent = (int)WMGetNotificationClientData(notification);
137
if (panel->flags.autoCompletion && textEvent!=WMDeleteTextEvent)
138
i = closestListItem(list, text, False);
140
i = closestListItem(list, text, True);
142
WMSelectListItem(list, i);
143
if (i>=0 && panel->flags.autoCompletion) {
144
WMListItem *item = WMGetListItem(list, i);
145
int textLen = strlen(text), itemTextLen = strlen(item->text);
146
int visibleItems = WMWidgetHeight(list)/WMGetListItemHeight(list);
148
WMSetListPosition(list, i - visibleItems/2);
150
if (textEvent!=WMDeleteTextEvent) {
153
WMInsertTextFieldText(panel->fileField, &item->text[textLen],
155
range.position = textLen;
156
range.count = itemTextLen - textLen;
157
WMSelectTextFieldRange(panel->fileField, range);
158
/*WMSetTextFieldCursorPosition(panel->fileField, itemTextLen);*/
167
textEditedObserver(void *observerData, WMNotification *notification)
169
W_FilePanel *panel = (W_FilePanel*)observerData;
171
if ((int)WMGetNotificationClientData(notification)==WMReturnTextMovement) {
172
WMPerformButtonClick(panel->okButton);
179
makeFilePanel(WMScreen *scrPtr, char *name, char *title)
185
fPtr = wmalloc(sizeof(WMFilePanel));
186
memset(fPtr, 0, sizeof(WMFilePanel));
188
fPtr->win = WMCreateWindowWithStyle(scrPtr, name, WMTitledWindowMask
189
|WMResizableWindowMask);
190
WMResizeWidget(fPtr->win, PWIDTH, PHEIGHT);
191
WMSetWindowTitle(fPtr->win, "");
193
WMCreateEventHandler(WMWidgetView(fPtr->win), StructureNotifyMask,
195
WMSetWindowMinSize(fPtr->win, PWIDTH, PHEIGHT);
198
fPtr->iconLabel = WMCreateLabel(fPtr->win);
199
WMResizeWidget(fPtr->iconLabel, 64, 64);
200
WMMoveWidget(fPtr->iconLabel, 0, 0);
201
WMSetLabelImagePosition(fPtr->iconLabel, WIPImageOnly);
202
icon = WMCreateApplicationIconBlendedPixmap(scrPtr, (RColor*)NULL);
204
WMSetLabelImage(fPtr->iconLabel, icon);
205
WMReleasePixmap(icon);
207
WMSetLabelImage(fPtr->iconLabel, scrPtr->applicationIconPixmap);
210
fPtr->titleLabel = WMCreateLabel(fPtr->win);
211
WMResizeWidget(fPtr->titleLabel, PWIDTH-64, 64);
212
WMMoveWidget(fPtr->titleLabel, 64, 0);
213
largeFont = WMBoldSystemFontOfSize(scrPtr, 24);
214
WMSetLabelFont(fPtr->titleLabel, largeFont);
215
WMReleaseFont(largeFont);
216
WMSetLabelText(fPtr->titleLabel, title);
218
fPtr->line = WMCreateFrame(fPtr->win);
219
WMMoveWidget(fPtr->line, 0, 64);
220
WMResizeWidget(fPtr->line, PWIDTH, 2);
221
WMSetFrameRelief(fPtr->line, WRGroove);
223
fPtr->browser = WMCreateBrowser(fPtr->win);
224
WMSetBrowserAllowEmptySelection(fPtr->browser, True);
225
WMSetBrowserDelegate(fPtr->browser, &browserDelegate);
226
WMSetBrowserAction(fPtr->browser, browserClick, fPtr);
227
WMSetBrowserDoubleAction(fPtr->browser, browserDClick, fPtr);
228
WMMoveWidget(fPtr->browser, 7, 72);
229
WMResizeWidget(fPtr->browser, PWIDTH-14,200);
230
WMHangData(fPtr->browser, fPtr);
232
fPtr->nameLabel = WMCreateLabel(fPtr->win);
233
WMMoveWidget(fPtr->nameLabel, 7, 282);
234
WMResizeWidget(fPtr->nameLabel, 55, 14);
235
WMSetLabelText(fPtr->nameLabel, _("Name:"));
237
fPtr->fileField = WMCreateTextField(fPtr->win);
238
WMMoveWidget(fPtr->fileField, 60, 278);
239
WMResizeWidget(fPtr->fileField, PWIDTH-60-10, 24);
240
WMAddNotificationObserver(textEditedObserver, fPtr,
241
WMTextDidEndEditingNotification,
243
WMAddNotificationObserver(textChangedObserver, fPtr,
244
WMTextDidChangeNotification,
247
fPtr->okButton = WMCreateCommandButton(fPtr->win);
248
WMMoveWidget(fPtr->okButton, 245, 325);
249
WMResizeWidget(fPtr->okButton, 75, 28);
250
WMSetButtonText(fPtr->okButton, _("OK"));
251
WMSetButtonImage(fPtr->okButton, scrPtr->buttonArrow);
252
WMSetButtonAltImage(fPtr->okButton, scrPtr->pushedButtonArrow);
253
WMSetButtonImagePosition(fPtr->okButton, WIPRight);
254
WMSetButtonAction(fPtr->okButton, buttonClick, fPtr);
256
fPtr->cancelButton = WMCreateCommandButton(fPtr->win);
257
WMMoveWidget(fPtr->cancelButton, 165, 325);
258
WMResizeWidget(fPtr->cancelButton, 75, 28);
259
WMSetButtonText(fPtr->cancelButton, _("Cancel"));
260
WMSetButtonAction(fPtr->cancelButton, buttonClick, fPtr);
262
fPtr->trashcanButton = WMCreateCommandButton(fPtr->win);
263
WMMoveWidget(fPtr->trashcanButton, 7, 325);
264
WMResizeWidget(fPtr->trashcanButton, 28, 28);
265
WMSetButtonImagePosition(fPtr->trashcanButton, WIPImageOnly);
266
WMSetButtonImage(fPtr->trashcanButton, scrPtr->trashcanIcon);
267
WMSetButtonAltImage(fPtr->trashcanButton, scrPtr->altTrashcanIcon);
268
WMSetButtonAction(fPtr->trashcanButton, deleteFile, fPtr);
270
fPtr->createDirButton = WMCreateCommandButton(fPtr->win);
271
WMMoveWidget(fPtr->createDirButton, 37, 325);
272
WMResizeWidget(fPtr->createDirButton, 28, 28);
273
WMSetButtonImagePosition(fPtr->createDirButton, WIPImageOnly);
274
WMSetButtonImage(fPtr->createDirButton, scrPtr->createDirIcon);
275
WMSetButtonAltImage(fPtr->createDirButton, scrPtr->altCreateDirIcon);
276
WMSetButtonAction(fPtr->createDirButton, createDir, fPtr);
278
fPtr->homeButton = WMCreateCommandButton(fPtr->win);
279
WMMoveWidget(fPtr->homeButton, 67, 325);
280
WMResizeWidget(fPtr->homeButton, 28, 28);
281
WMSetButtonImagePosition(fPtr->homeButton, WIPImageOnly);
282
WMSetButtonImage(fPtr->homeButton, scrPtr->homeIcon);
283
WMSetButtonAltImage(fPtr->homeButton, scrPtr->altHomeIcon);
284
WMSetButtonAction(fPtr->homeButton, goHome, fPtr);
286
fPtr->disketteButton = WMCreateCommandButton(fPtr->win);
287
WMMoveWidget(fPtr->disketteButton, 97, 325);
288
WMResizeWidget(fPtr->disketteButton, 28, 28);
289
WMSetButtonImagePosition(fPtr->disketteButton, WIPImageOnly);
290
WMSetButtonImage(fPtr->disketteButton, scrPtr->disketteIcon);
291
WMSetButtonAltImage(fPtr->disketteButton, scrPtr->altDisketteIcon);
292
WMSetButtonAction(fPtr->disketteButton, goFloppy, fPtr);
294
fPtr->unmountButton = WMCreateCommandButton(fPtr->win);
295
WMMoveWidget(fPtr->unmountButton, 127, 325);
296
WMResizeWidget(fPtr->unmountButton, 28, 28);
297
WMSetButtonImagePosition(fPtr->unmountButton, WIPImageOnly);
298
WMSetButtonImage(fPtr->unmountButton, scrPtr->unmountIcon);
299
WMSetButtonAltImage(fPtr->unmountButton, scrPtr->altUnmountIcon);
300
WMSetButtonAction(fPtr->unmountButton, goUnmount, fPtr);
301
WMSetButtonEnabled(fPtr->unmountButton, False);
304
WMRealizeWidget(fPtr->win);
305
WMMapSubwidgets(fPtr->win);
307
WMSetFocusToWidget(fPtr->fileField);
308
WMSetTextFieldCursorPosition(fPtr->fileField, 0);
310
WMLoadBrowserColumnZero(fPtr->browser);
312
WMSetWindowInitialPosition(fPtr->win,
313
(scrPtr->rootView->size.width - WMWidgetWidth(fPtr->win))/2,
314
(scrPtr->rootView->size.height - WMWidgetHeight(fPtr->win))/2);
316
fPtr->flags.canChooseFiles = 1;
317
fPtr->flags.canChooseDirectories = 1;
318
fPtr->flags.autoCompletion = 1;
325
WMGetOpenPanel(WMScreen *scrPtr)
329
if (scrPtr->sharedOpenPanel)
330
return scrPtr->sharedOpenPanel;
332
panel = makeFilePanel(scrPtr, "openFilePanel", _("Open"));
333
panel->flags.fileMustExist = 1;
334
panel->flags.panelType = WP_OPEN;
336
scrPtr->sharedOpenPanel = panel;
343
WMGetSavePanel(WMScreen *scrPtr)
347
if (scrPtr->sharedSavePanel)
348
return scrPtr->sharedSavePanel;
350
panel = makeFilePanel(scrPtr, "saveFilePanel", _("Save"));
351
panel->flags.fileMustExist = 0;
352
panel->flags.panelType = WP_SAVE;
354
scrPtr->sharedSavePanel = panel;
361
WMFreeFilePanel(WMFilePanel *panel)
363
if (panel == WMWidgetScreen(panel->win)->sharedSavePanel) {
364
WMWidgetScreen(panel->win)->sharedSavePanel = NULL;
366
if (panel == WMWidgetScreen(panel->win)->sharedOpenPanel) {
367
WMWidgetScreen(panel->win)->sharedOpenPanel = NULL;
369
WMRemoveNotificationObserver(panel);
370
WMUnmapWidget(panel->win);
371
WMDestroyWidget(panel->win);
377
WMRunModalFilePanelForDirectory(WMFilePanel *panel, WMWindow *owner,
378
char *path, char *name, char **fileTypes)
380
WMScreen *scr = WMWidgetScreen(panel->win);
382
if (name && !owner) {
383
WMSetWindowTitle(panel->win, name);
386
WMChangePanelOwner(panel->win, owner);
388
WMSetFilePanelDirectory(panel, path);
390
switch(panel->flags.panelType) {
393
panel->flags.filtered = 1;
394
panel->fileTypes = fileTypes;
399
panel->fileTypes = NULL;
400
panel->flags.filtered = 0;
408
WMSetLabelText(panel->titleLabel, name);
410
WMMapWidget(panel->win);
412
WMRunModalLoop(scr, W_VIEW(panel->win));
414
/* Must withdraw window because the next time we map
415
* it, it might have a different transient owner.
417
WMCloseWindow(panel->win);
419
return (panel->flags.canceled ? False : True);
426
WMSetFilePanelDirectory(WMFilePanel *panel, char *path)
433
rest = WMSetBrowserPath(panel->browser, path);
434
if (strcmp(path, "/")==0)
437
col = WMGetBrowserSelectedColumn(panel->browser);
438
list = WMGetBrowserListInColumn(panel->browser, col);
439
if (list && (item = WMGetListSelectedItem(list))) {
440
if (item->isBranch) {
441
WMSetTextFieldText(panel->fileField, rest);
443
WMSetTextFieldText(panel->fileField, item->text);
446
WMSetTextFieldText(panel->fileField, rest);
452
WMSetFilePanelCanChooseDirectories(WMFilePanel *panel, Bool flag)
454
panel->flags.canChooseDirectories = ((flag==0) ? 0 : 1);
458
WMSetFilePanelCanChooseFiles(WMFilePanel *panel, Bool flag)
460
panel->flags.canChooseFiles = ((flag==0) ? 0 : 1);
465
WMSetFilePanelAutoCompletion(WMFilePanel *panel, Bool flag)
467
panel->flags.autoCompletion = ((flag==0) ? 0 : 1);
472
WMGetFilePanelFileName(WMFilePanel *panel)
474
return getCurrentFileName(panel);
479
WMSetFilePanelAccessoryView(WMFilePanel *panel, WMView *view)
483
panel->accessoryView = view;
485
v = WMWidgetView(panel->win);
487
W_ReparentView(view, v, 0, 0);
489
W_MoveView(view, (v->size.width - v->size.width)/2, 300);
494
WMGetFilePanelAccessoryView(WMFilePanel *panel)
496
return panel->accessoryView;
501
get_name_from_path(char *path)
509
/* remove trailing / */
510
while (size > 0 && path[size-1]=='/')
512
/* directory was root */
516
while (size > 0 && path[size-1] != '/')
519
return wstrdup(&(path[size]));
524
filterFileName(WMFilePanel *panel, char *file, Bool isDirectory)
530
#define CAST(item) (*((WMListItem**)item))
532
comparer(const void *a, const void *b)
534
if (CAST(a)->isBranch == CAST(b)->isBranch)
535
return (strcmp(CAST(a)->text, CAST(b)->text));
536
if (CAST(a)->isBranch)
544
listDirectoryOnColumn(WMFilePanel *panel, int column, char *path)
546
WMBrowser *bPtr = panel->browser;
547
struct dirent *dentry;
549
struct stat stat_buf;
550
char pbuf[PATH_MAX+16];
554
assert(path != NULL);
556
/* put directory name in the title */
557
name = get_name_from_path(path);
558
WMSetBrowserColumnTitle(bPtr, column, name);
565
printf(_("WINGs: could not open directory %s\n"), path);
570
/* list contents in the column */
571
while ((dentry = readdir(dir))) {
572
if (strcmp(dentry->d_name, ".")==0 ||
573
strcmp(dentry->d_name, "..")==0)
577
if (strcmp(path, "/")!=0)
579
strcat(pbuf, dentry->d_name);
581
if (stat(pbuf, &stat_buf)!=0) {
583
printf(_("WINGs: could not stat %s\n"), pbuf);
589
isDirectory = S_ISDIR(stat_buf.st_mode);
591
if (filterFileName(panel, dentry->d_name, isDirectory))
592
WMInsertBrowserItem(bPtr, column, -1, dentry->d_name, isDirectory);
595
WMSortBrowserColumnWithComparer(bPtr, column, comparer);
602
fillColumn(WMBrowserDelegate *self, WMBrowser *bPtr, int column, WMList *list)
608
path = WMGetBrowserPathToColumn(bPtr, column-1);
613
panel = WMGetHangedData(bPtr);
614
listDirectoryOnColumn(panel, column, path);
620
browserDClick(WMBrowser *bPtr, WMFilePanel *panel)
622
WMPerformButtonClick(panel->okButton);
626
browserClick(WMBrowser *bPtr, WMFilePanel *panel)
628
int col = WMGetBrowserSelectedColumn(bPtr);
629
WMListItem *item = WMGetBrowserSelectedItemInColumn(bPtr, col);
631
if (!item || item->isBranch)
632
WMSetTextFieldText(panel->fileField, NULL);
634
WMSetTextFieldText(panel->fileField, item->text);
640
showError(WMScreen *scr, WMWindow *owner, char *s, char *file)
645
errStr = wmalloc(strlen(file)+strlen(s));
646
sprintf(errStr, s, file);
650
WMRunAlertPanel(scr, owner, _("Error"), errStr, _("OK"), NULL, NULL);
656
createDir(WMButton *bPre, WMFilePanel *panel)
658
char *dirName, *directory, *file, *s;
659
WMScreen *scr = WMWidgetScreen(panel->win);
661
dirName = WMRunInputPanel(scr, panel->win, _("Create Directory"),
662
_("Enter directory name"), "", _("OK"), _("Cancel"));
666
directory = getCurrentFileName(panel);
667
s = strrchr(directory,'/');
670
if (dirName[0] == '/') {
673
while ((s = strstr(directory,"//"))) {
675
for (i = 2;s[i] == '/';i++);
678
if ((s = strrchr(directory, '/')) && !s[1]) s[0] = 0;
680
while ((s = strstr(dirName,"//"))) {
682
for (i = 2;s[i] == '/';i++);
685
if ((s = strrchr(dirName, '/')) && !s[1]) s[0] = 0;
687
file = wmalloc(strlen(dirName)+strlen(directory)+4);
688
sprintf(file, "%s/%s", directory, dirName);
689
while ((s = strstr(file,"//"))) {
691
for (i = 2;s[i] == '/';i++);
695
if (mkdir(file,0xfff) != 0) {
698
showError(scr, panel->win, _("Permission denied."), NULL);
701
showError(scr, panel->win, _("'%s' already exists."), file);
704
showError(scr, panel->win, _("Path does not exist."), NULL);
707
else WMSetFilePanelDirectory(panel, file);
715
deleteFile(WMButton *bPre, WMFilePanel *panel)
719
struct stat filestat;
720
WMScreen *scr = WMWidgetScreen(panel->win);
722
file = getCurrentFileName(panel);
724
while ((s = strstr(file,"//"))) {
726
for (i = 2;s[i] == '/';i++);
729
if (strlen(file) > 1 && (s = strrchr(file, '/')) && !s[1]) s[0] = 0;
731
if (stat(file,&filestat)) {
734
showError(scr, panel->win, _("'%s' does not exist."), file);
737
showError(scr, panel->win, _("Permission denied."), NULL);
740
showError(scr, panel->win,
741
_("Insufficient memory available."), NULL);
744
showError(scr, panel->win,
745
_("'%s' is on a read-only filesystem."), file);
748
showError(scr, panel->win, _("Can not delete '%s'."), file);
752
} else if (S_ISDIR(filestat.st_mode)) {
753
int len = strlen(file)+20;
754
buffer = wmalloc(len);
755
snprintf(buffer,len,_("Delete directory %s ?"),file);
757
int len = strlen(file)+15;
758
buffer = wmalloc(len);
759
snprintf(buffer,len,_("Delete file %s ?"),file);
762
if (!WMRunAlertPanel(WMWidgetScreen(panel->win), panel->win,
763
_("Warning"), buffer, _("OK"), _("Cancel"), NULL)) {
764
if (S_ISDIR(filestat.st_mode)) {
765
if (rmdir(file) != 0) {
768
showError(scr, panel->win, _("Permission denied."), NULL);
771
showError(scr, panel->win, _("Directory '%s' does not exist."), file);
774
showError(scr, panel->win, _("Directory '%s' is not empty."), file);
777
showError(scr, panel->win, _("Directory '%s' is busy."), file);
780
showError(scr, panel->win, _("Can not delete '%s'."), file);
783
char *s = strrchr(file,'/');
785
WMSetFilePanelDirectory(panel, file);
787
} else if (remove(file) != 0) {
790
showError(scr, panel->win, _("'%s' is a directory."), file);
793
showError(scr, panel->win, _("'%s' does not exist."), file);
796
showError(scr, panel->win, _("Permission denied."), NULL);
799
showError(scr, panel->win,
800
_("Insufficient memory available."), NULL);
803
showError(scr, panel->win,
804
_("'%s' is on a read-only filesystem."), file);
807
showError(scr, panel->win, _("Can not delete '%s'."), file);
810
char *s = strrchr(file,'/');
812
WMSetFilePanelDirectory(panel, file);
820
goUnmount(WMButton *bPtr, WMFilePanel *panel)
826
goFloppy(WMButton *bPtr, WMFilePanel *panel)
828
struct stat filestat;
829
WMScreen *scr = WMWidgetScreen(panel->win);
831
if (stat(WINGsConfiguration.floppyPath, &filestat)) {
832
showError(scr, panel->win, _("An error occured browsing '%s'."),
833
WINGsConfiguration.floppyPath);
835
} else if (!S_ISDIR(filestat.st_mode)) {
836
showError(scr, panel->win, _("'%s' is not a directory."),
837
WINGsConfiguration.floppyPath);
841
WMSetFilePanelDirectory(panel, WINGsConfiguration.floppyPath);
846
goHome(WMButton *bPtr, WMFilePanel *panel)
850
/* home is statically allocated. Don't free it! */
851
home = wgethomedir();
855
WMSetFilePanelDirectory(panel, home);
860
handleEvents(XEvent *event, void *data)
862
W_FilePanel *pPtr = (W_FilePanel*)data;
863
W_View *view = WMWidgetView(pPtr->win);
865
if (event->type == ConfigureNotify) {
866
if (event->xconfigure.width != view->size.width
867
|| event->xconfigure.height != view->size.height) {
868
unsigned int newWidth = event->xconfigure.width;
869
unsigned int newHeight = event->xconfigure.height;
872
W_ResizeView(view, newWidth, newHeight);
873
WMResizeWidget(pPtr->line, newWidth, 2);
874
WMResizeWidget(pPtr->browser, newWidth-14,
875
newHeight-(PHEIGHT-200));
876
WMResizeWidget(pPtr->fileField, newWidth-60-10, 24);
877
WMMoveWidget(pPtr->nameLabel, 7, newHeight-(PHEIGHT-282));
878
WMMoveWidget(pPtr->fileField, 60, newHeight-(PHEIGHT-278));
879
WMMoveWidget(pPtr->okButton, newWidth-(PWIDTH-245),
880
newHeight-(PHEIGHT-325));
881
WMMoveWidget(pPtr->cancelButton, newWidth-(PWIDTH-165),
882
newHeight-(PHEIGHT-325));
884
WMMoveWidget(pPtr->trashcanButton, 7, newHeight-(PHEIGHT-325));
885
WMMoveWidget(pPtr->createDirButton, 37, newHeight-(PHEIGHT-325));
886
WMMoveWidget(pPtr->homeButton, 67, newHeight-(PHEIGHT-325));
887
WMMoveWidget(pPtr->disketteButton, 97, newHeight-(PHEIGHT-325));
888
WMMoveWidget(pPtr->unmountButton, 127, newHeight-(PHEIGHT-325));
890
newColumnCount = (newWidth - 14) / 140;
891
WMSetBrowserMaxVisibleColumns(pPtr->browser, newColumnCount);
898
getCurrentFileName(WMFilePanel *panel)
905
path = WMGetBrowserPath(panel->browser);
908
if (path[len-1]=='/') {
909
file = WMGetTextFieldText(panel->fileField);
910
tmp = wmalloc(strlen(path)+strlen(file)+8);
928
validOpenFile(WMFilePanel *panel)
931
int col, haveFile = 0;
932
char *file = WMGetTextFieldText(panel->fileField);
938
col = WMGetBrowserSelectedColumn(panel->browser);
939
item = WMGetBrowserSelectedItemInColumn(panel->browser, col);
941
if (item->isBranch && !panel->flags.canChooseDirectories && !haveFile)
943
else if (!item->isBranch && !panel->flags.canChooseFiles)
948
/* we compute for / here */
949
if (!panel->flags.canChooseDirectories && !haveFile)
960
buttonClick(WMButton *bPtr, WMFilePanel *panel)
964
if (bPtr == panel->okButton) {
965
if (!validOpenFile(panel))
967
if (panel->flags.fileMustExist) {
970
file = getCurrentFileName(panel);
971
if (access(file, F_OK)!=0) {
972
WMRunAlertPanel(WMWidgetScreen(panel->win), panel->win,
973
_("Error"), _("File does not exist."),
974
_("OK"), NULL, NULL);
980
panel->flags.canceled = 0;
982
panel->flags.canceled = 1;
984
range.count = range.position = 0;
985
WMSelectTextFieldRange(panel->fileField, range);
986
WMBreakModalLoop(WMWidgetScreen(bPtr));