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;
64 static void listDirectoryOnColumn(WMFilePanel
* panel
, int column
, char *path
);
65 static void browserClick();
66 static void browserDClick();
68 static void fillColumn(WMBrowserDelegate
* self
, WMBrowser
* bPtr
, int column
, WMList
* list
);
70 static void normalizePath(char *s
);
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
);
88 static WMBrowserDelegate browserDelegate
= {
90 fillColumn
, /* createRowsForColumn */
91 NULL
, /* titleOfColumn */
96 static int closestListItem(WMList
* list
, char *text
, Bool exact
)
99 WMArray
*items
= WMGetListItems(list
);
100 int i
, len
= strlen(text
);
105 for (i
= 0; i
< WMGetArrayItemCount(items
); i
++) {
106 item
= WMGetFromArray(items
, i
);
107 if (strlen(item
->text
) >= len
&&
108 ((exact
&& strcmp(item
->text
, text
) == 0) ||
109 (!exact
&& strncmp(item
->text
, text
, len
) == 0))) {
117 static void textChangedObserver(void *observerData
, WMNotification
* notification
)
119 W_FilePanel
*panel
= (W_FilePanel
*) observerData
;
122 int col
= WMGetBrowserNumberOfColumns(panel
->browser
) - 1;
126 if (!(list
= WMGetBrowserListInColumn(panel
->browser
, col
)))
129 text
= WMGetTextFieldText(panel
->fileField
);
130 textEvent
= (uintptr_t)WMGetNotificationClientData(notification
);
132 if (panel
->flags
.autoCompletion
&& textEvent
!= WMDeleteTextEvent
)
133 i
= closestListItem(list
, text
, False
);
135 i
= closestListItem(list
, text
, True
);
137 WMSelectListItem(list
, i
);
138 if (i
>= 0 && panel
->flags
.autoCompletion
) {
139 WMListItem
*item
= WMGetListItem(list
, i
);
140 int textLen
= strlen(text
), itemTextLen
= strlen(item
->text
);
141 int visibleItems
= WMWidgetHeight(list
) / WMGetListItemHeight(list
);
143 WMSetListPosition(list
, i
- visibleItems
/ 2);
145 if (textEvent
!= WMDeleteTextEvent
) {
148 WMInsertTextFieldText(panel
->fileField
, &item
->text
[textLen
], textLen
);
149 range
.position
= textLen
;
150 range
.count
= itemTextLen
- textLen
;
151 WMSelectTextFieldRange(panel
->fileField
, range
);
152 /*WMSetTextFieldCursorPosition(panel->fileField, itemTextLen); */
159 static void textEditedObserver(void *observerData
, WMNotification
* notification
)
161 W_FilePanel
*panel
= (W_FilePanel
*) observerData
;
163 if ((uintptr_t)WMGetNotificationClientData(notification
) == WMReturnTextMovement
) {
164 WMPerformButtonClick(panel
->okButton
);
168 static WMFilePanel
*makeFilePanel(WMScreen
* scrPtr
, char *name
, char *title
)
174 fPtr
= wmalloc(sizeof(WMFilePanel
));
176 fPtr
->win
= WMCreateWindowWithStyle(scrPtr
, name
, WMTitledWindowMask
| WMResizableWindowMask
);
177 WMResizeWidget(fPtr
->win
, PWIDTH
, PHEIGHT
);
178 WMSetWindowTitle(fPtr
->win
, "");
180 WMCreateEventHandler(WMWidgetView(fPtr
->win
), StructureNotifyMask
, handleEvents
, fPtr
);
181 WMSetWindowMinSize(fPtr
->win
, PWIDTH
, PHEIGHT
);
183 fPtr
->iconLabel
= WMCreateLabel(fPtr
->win
);
184 WMResizeWidget(fPtr
->iconLabel
, 64, 64);
185 WMMoveWidget(fPtr
->iconLabel
, 0, 0);
186 WMSetLabelImagePosition(fPtr
->iconLabel
, WIPImageOnly
);
187 icon
= WMCreateApplicationIconBlendedPixmap(scrPtr
, (RColor
*) NULL
);
189 WMSetLabelImage(fPtr
->iconLabel
, icon
);
190 WMReleasePixmap(icon
);
192 WMSetLabelImage(fPtr
->iconLabel
, scrPtr
->applicationIconPixmap
);
195 fPtr
->titleLabel
= WMCreateLabel(fPtr
->win
);
196 WMResizeWidget(fPtr
->titleLabel
, PWIDTH
- 64, 64);
197 WMMoveWidget(fPtr
->titleLabel
, 64, 0);
198 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
199 WMSetLabelFont(fPtr
->titleLabel
, largeFont
);
200 WMReleaseFont(largeFont
);
201 WMSetLabelText(fPtr
->titleLabel
, title
);
203 fPtr
->line
= WMCreateFrame(fPtr
->win
);
204 WMMoveWidget(fPtr
->line
, 0, 64);
205 WMResizeWidget(fPtr
->line
, PWIDTH
, 2);
206 WMSetFrameRelief(fPtr
->line
, WRGroove
);
208 fPtr
->browser
= WMCreateBrowser(fPtr
->win
);
209 WMSetBrowserAllowEmptySelection(fPtr
->browser
, True
);
210 WMSetBrowserDelegate(fPtr
->browser
, &browserDelegate
);
211 WMSetBrowserAction(fPtr
->browser
, browserClick
, fPtr
);
212 WMSetBrowserDoubleAction(fPtr
->browser
, browserDClick
, fPtr
);
213 WMMoveWidget(fPtr
->browser
, 7, 72);
214 WMResizeWidget(fPtr
->browser
, PWIDTH
- 14, 200);
215 WMHangData(fPtr
->browser
, fPtr
);
217 fPtr
->nameLabel
= WMCreateLabel(fPtr
->win
);
218 WMMoveWidget(fPtr
->nameLabel
, 7, 282);
219 WMResizeWidget(fPtr
->nameLabel
, 55, 14);
220 WMSetLabelText(fPtr
->nameLabel
, _("Name:"));
222 fPtr
->fileField
= WMCreateTextField(fPtr
->win
);
223 WMMoveWidget(fPtr
->fileField
, 60, 278);
224 WMResizeWidget(fPtr
->fileField
, PWIDTH
- 60 - 10, 24);
225 WMAddNotificationObserver(textEditedObserver
, fPtr
, WMTextDidEndEditingNotification
, fPtr
->fileField
);
226 WMAddNotificationObserver(textChangedObserver
, fPtr
, WMTextDidChangeNotification
, fPtr
->fileField
);
228 fPtr
->okButton
= WMCreateCommandButton(fPtr
->win
);
229 WMMoveWidget(fPtr
->okButton
, 245, 325);
230 WMResizeWidget(fPtr
->okButton
, 75, 28);
231 WMSetButtonText(fPtr
->okButton
, _("OK"));
232 WMSetButtonImage(fPtr
->okButton
, scrPtr
->buttonArrow
);
233 WMSetButtonAltImage(fPtr
->okButton
, scrPtr
->pushedButtonArrow
);
234 WMSetButtonImagePosition(fPtr
->okButton
, WIPRight
);
235 WMSetButtonAction(fPtr
->okButton
, buttonClick
, fPtr
);
237 fPtr
->cancelButton
= WMCreateCommandButton(fPtr
->win
);
238 WMMoveWidget(fPtr
->cancelButton
, 165, 325);
239 WMResizeWidget(fPtr
->cancelButton
, 75, 28);
240 WMSetButtonText(fPtr
->cancelButton
, _("Cancel"));
241 WMSetButtonAction(fPtr
->cancelButton
, buttonClick
, fPtr
);
243 fPtr
->trashcanButton
= WMCreateCommandButton(fPtr
->win
);
244 WMMoveWidget(fPtr
->trashcanButton
, 7, 325);
245 WMResizeWidget(fPtr
->trashcanButton
, 28, 28);
246 WMSetButtonImagePosition(fPtr
->trashcanButton
, WIPImageOnly
);
247 WMSetButtonImage(fPtr
->trashcanButton
, scrPtr
->trashcanIcon
);
248 WMSetButtonAltImage(fPtr
->trashcanButton
, scrPtr
->altTrashcanIcon
);
249 WMSetButtonAction(fPtr
->trashcanButton
, deleteFile
, fPtr
);
251 fPtr
->createDirButton
= WMCreateCommandButton(fPtr
->win
);
252 WMMoveWidget(fPtr
->createDirButton
, 37, 325);
253 WMResizeWidget(fPtr
->createDirButton
, 28, 28);
254 WMSetButtonImagePosition(fPtr
->createDirButton
, WIPImageOnly
);
255 WMSetButtonImage(fPtr
->createDirButton
, scrPtr
->createDirIcon
);
256 WMSetButtonAltImage(fPtr
->createDirButton
, scrPtr
->altCreateDirIcon
);
257 WMSetButtonAction(fPtr
->createDirButton
, createDir
, fPtr
);
259 fPtr
->homeButton
= WMCreateCommandButton(fPtr
->win
);
260 WMMoveWidget(fPtr
->homeButton
, 67, 325);
261 WMResizeWidget(fPtr
->homeButton
, 28, 28);
262 WMSetButtonImagePosition(fPtr
->homeButton
, WIPImageOnly
);
263 WMSetButtonImage(fPtr
->homeButton
, scrPtr
->homeIcon
);
264 WMSetButtonAltImage(fPtr
->homeButton
, scrPtr
->altHomeIcon
);
265 WMSetButtonAction(fPtr
->homeButton
, goHome
, fPtr
);
267 fPtr
->disketteButton
= WMCreateCommandButton(fPtr
->win
);
268 WMMoveWidget(fPtr
->disketteButton
, 97, 325);
269 WMResizeWidget(fPtr
->disketteButton
, 28, 28);
270 WMSetButtonImagePosition(fPtr
->disketteButton
, WIPImageOnly
);
271 WMSetButtonImage(fPtr
->disketteButton
, scrPtr
->disketteIcon
);
272 WMSetButtonAltImage(fPtr
->disketteButton
, scrPtr
->altDisketteIcon
);
273 WMSetButtonAction(fPtr
->disketteButton
, goFloppy
, fPtr
);
275 fPtr
->unmountButton
= WMCreateCommandButton(fPtr
->win
);
276 WMMoveWidget(fPtr
->unmountButton
, 127, 325);
277 WMResizeWidget(fPtr
->unmountButton
, 28, 28);
278 WMSetButtonImagePosition(fPtr
->unmountButton
, WIPImageOnly
);
279 WMSetButtonImage(fPtr
->unmountButton
, scrPtr
->unmountIcon
);
280 WMSetButtonAltImage(fPtr
->unmountButton
, scrPtr
->altUnmountIcon
);
281 WMSetButtonAction(fPtr
->unmountButton
, goUnmount
, fPtr
);
282 WMSetButtonEnabled(fPtr
->unmountButton
, False
);
284 WMRealizeWidget(fPtr
->win
);
285 WMMapSubwidgets(fPtr
->win
);
287 WMSetFocusToWidget(fPtr
->fileField
);
288 WMSetTextFieldCursorPosition(fPtr
->fileField
, 0);
290 WMLoadBrowserColumnZero(fPtr
->browser
);
292 WMSetWindowInitialPosition(fPtr
->win
,
293 (scrPtr
->rootView
->size
.width
- WMWidgetWidth(fPtr
->win
)) / 2,
294 (scrPtr
->rootView
->size
.height
- WMWidgetHeight(fPtr
->win
)) / 2);
296 fPtr
->flags
.canChooseFiles
= 1;
297 fPtr
->flags
.canChooseDirectories
= 1;
298 fPtr
->flags
.autoCompletion
= 1;
303 WMOpenPanel
*WMGetOpenPanel(WMScreen
* scrPtr
)
307 if (scrPtr
->sharedOpenPanel
)
308 return scrPtr
->sharedOpenPanel
;
310 panel
= makeFilePanel(scrPtr
, "openFilePanel", _("Open"));
311 panel
->flags
.fileMustExist
= 1;
312 panel
->flags
.panelType
= WP_OPEN
;
314 scrPtr
->sharedOpenPanel
= panel
;
319 WMSavePanel
*WMGetSavePanel(WMScreen
* scrPtr
)
323 if (scrPtr
->sharedSavePanel
)
324 return scrPtr
->sharedSavePanel
;
326 panel
= makeFilePanel(scrPtr
, "saveFilePanel", _("Save"));
327 panel
->flags
.fileMustExist
= 0;
328 panel
->flags
.panelType
= WP_SAVE
;
330 scrPtr
->sharedSavePanel
= panel
;
335 void WMFreeFilePanel(WMFilePanel
* panel
)
337 if (panel
== WMWidgetScreen(panel
->win
)->sharedSavePanel
) {
338 WMWidgetScreen(panel
->win
)->sharedSavePanel
= NULL
;
340 if (panel
== WMWidgetScreen(panel
->win
)->sharedOpenPanel
) {
341 WMWidgetScreen(panel
->win
)->sharedOpenPanel
= NULL
;
343 WMRemoveNotificationObserver(panel
);
344 WMUnmapWidget(panel
->win
);
345 WMDestroyWidget(panel
->win
);
350 WMRunModalFilePanelForDirectory(WMFilePanel
* panel
, WMWindow
* owner
, char *path
, char *name
, char **fileTypes
)
352 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
354 if (name
&& !owner
) {
355 WMSetWindowTitle(panel
->win
, name
);
358 WMChangePanelOwner(panel
->win
, owner
);
360 WMSetFilePanelDirectory(panel
, path
);
362 switch (panel
->flags
.panelType
) {
365 panel
->flags
.filtered
= 1;
366 panel
->fileTypes
= fileTypes
;
371 panel
->fileTypes
= NULL
;
372 panel
->flags
.filtered
= 0;
380 WMSetLabelText(panel
->titleLabel
, name
);
382 WMMapWidget(panel
->win
);
384 WMRunModalLoop(scr
, W_VIEW(panel
->win
));
386 /* Must withdraw window because the next time we map
387 * it, it might have a different transient owner.
389 WMCloseWindow(panel
->win
);
391 return (panel
->flags
.canceled
? False
: True
);
394 void WMSetFilePanelDirectory(WMFilePanel
* panel
, char *path
)
401 rest
= WMSetBrowserPath(panel
->browser
, path
);
402 if (strcmp(path
, "/") == 0)
405 col
= WMGetBrowserSelectedColumn(panel
->browser
);
406 list
= WMGetBrowserListInColumn(panel
->browser
, col
);
407 if (list
&& (item
= WMGetListSelectedItem(list
))) {
408 if (item
->isBranch
) {
409 WMSetTextFieldText(panel
->fileField
, rest
);
411 WMSetTextFieldText(panel
->fileField
, item
->text
);
414 WMSetTextFieldText(panel
->fileField
, rest
);
418 void WMSetFilePanelCanChooseDirectories(WMFilePanel
* panel
, Bool flag
)
420 panel
->flags
.canChooseDirectories
= ((flag
== 0) ? 0 : 1);
423 void WMSetFilePanelCanChooseFiles(WMFilePanel
* panel
, Bool flag
)
425 panel
->flags
.canChooseFiles
= ((flag
== 0) ? 0 : 1);
428 void WMSetFilePanelAutoCompletion(WMFilePanel
* panel
, Bool flag
)
430 panel
->flags
.autoCompletion
= ((flag
== 0) ? 0 : 1);
433 char *WMGetFilePanelFileName(WMFilePanel
* panel
)
435 return getCurrentFileName(panel
);
438 void WMSetFilePanelAccessoryView(WMFilePanel
* panel
, WMView
* view
)
442 panel
->accessoryView
= view
;
444 v
= WMWidgetView(panel
->win
);
446 W_ReparentView(view
, v
, 0, 0);
448 W_MoveView(view
, (v
->size
.width
- v
->size
.width
) / 2, 300);
451 WMView
*WMGetFilePanelAccessoryView(WMFilePanel
* panel
)
453 return panel
->accessoryView
;
456 static char *get_name_from_path(char *path
)
460 assert(path
!= NULL
);
464 /* remove trailing / */
465 while (size
> 0 && path
[size
- 1] == '/')
467 /* directory was root */
471 while (size
> 0 && path
[size
- 1] != '/')
474 return wstrdup(&(path
[size
]));
477 static int filterFileName(WMFilePanel
* panel
, char *file
, Bool isDirectory
)
482 #define CAST(item) (*((WMListItem**)item))
483 static int comparer(const void *a
, const void *b
)
485 if (CAST(a
)->isBranch
== CAST(b
)->isBranch
)
486 return (strcmp(CAST(a
)->text
, CAST(b
)->text
));
487 if (CAST(a
)->isBranch
)
494 static void listDirectoryOnColumn(WMFilePanel
* panel
, int column
, char *path
)
496 WMBrowser
*bPtr
= panel
->browser
;
497 struct dirent
*dentry
;
499 struct stat stat_buf
;
500 char pbuf
[PATH_MAX
+ 16];
504 assert(path
!= NULL
);
506 /* put directory name in the title */
507 name
= get_name_from_path(path
);
508 WMSetBrowserColumnTitle(bPtr
, column
, name
);
515 printf(_("WINGs: could not open directory %s\n"), path
);
520 /* list contents in the column */
521 while ((dentry
= readdir(dir
))) {
522 if (strcmp(dentry
->d_name
, ".") == 0 || strcmp(dentry
->d_name
, "..") == 0)
526 if (strcmp(path
, "/") != 0)
528 strcat(pbuf
, dentry
->d_name
);
530 if (stat(pbuf
, &stat_buf
) != 0) {
532 printf(_("WINGs: could not stat %s\n"), pbuf
);
538 isDirectory
= S_ISDIR(stat_buf
.st_mode
);
540 if (filterFileName(panel
, dentry
->d_name
, isDirectory
))
541 WMInsertBrowserItem(bPtr
, column
, -1, dentry
->d_name
, isDirectory
);
544 WMSortBrowserColumnWithComparer(bPtr
, column
, comparer
);
549 static void fillColumn(WMBrowserDelegate
* self
, WMBrowser
* bPtr
, int column
, WMList
* list
)
555 path
= WMGetBrowserPathToColumn(bPtr
, column
- 1);
560 panel
= WMGetHangedData(bPtr
);
561 listDirectoryOnColumn(panel
, column
, path
);
565 static void browserDClick(WMBrowser
* bPtr
, WMFilePanel
* panel
)
567 WMPerformButtonClick(panel
->okButton
);
570 static void browserClick(WMBrowser
* bPtr
, WMFilePanel
* panel
)
572 int col
= WMGetBrowserSelectedColumn(bPtr
);
573 WMListItem
*item
= WMGetBrowserSelectedItemInColumn(bPtr
, col
);
575 if (!item
|| item
->isBranch
)
576 WMSetTextFieldText(panel
->fileField
, NULL
);
578 WMSetTextFieldText(panel
->fileField
, item
->text
);
582 static void showError(WMScreen
* scr
, WMWindow
* owner
, char *s
, char *file
)
587 errStr
= wmalloc(strlen(file
) + strlen(s
));
588 sprintf(errStr
, s
, file
);
592 WMRunAlertPanel(scr
, owner
, _("Error"), errStr
, _("OK"), NULL
, NULL
);
596 static void createDir(WMButton
* bPre
, WMFilePanel
* panel
)
598 char *dirName
, *directory
, *file
;
600 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
602 dirName
= WMRunInputPanel(scr
, panel
->win
, _("Create Directory"),
603 _("Enter directory name"), "", _("OK"), _("Cancel"));
607 /* if `dirName' is an absolute path, don't mind `directory'.
608 * normalize as needed (possibly not needed at all?) */
609 normalizePath(dirName
);
610 if (*dirName
!= '/') {
611 directory
= getCurrentFileName(panel
);
612 normalizePath(directory
);
617 slen
= strlen(dirName
) + (directory
? strlen(directory
) + 1 /* "/" */ : 0) + 1 /* NULL */;
618 file
= wmalloc(slen
);
621 strncpy(file
, directory
, slen
- 1);
622 strncat(file
, "/", slen
- strlen(file
));
625 strncat(file
, dirName
, slen
- strlen(file
));
627 if (mkdir(file
, 00777) != 0) {
628 #define __msgbufsize__ 512
629 char *buffer
= wmalloc(__msgbufsize__
);
630 snprintf(buffer
, __msgbufsize__
, _("Can not create %s: %s"), file
, strerror(errno
));
631 showError(scr
, panel
->win
, buffer
, NULL
);
633 #undef __msgbufsize__
635 WMSetFilePanelDirectory(panel
, file
);
647 *----------------------------------------------------------------------
649 * Remove multiple consecutive and any trailing slashes from
651 *----------------------------------------------------------------------
653 static void normalizePath(char *s
)
658 for (i
= 0; s
[i
]; !found
&& i
++) {
660 if (s
[i
] == '/' && s
[i
+1] == '/') {
664 while (s
[i
+nslash
] == '/')
666 for (j
= 0; s
[i
+j
+nslash
]; j
++)
667 s
[i
+j
] = s
[i
+j
+nslash
];
671 if (i
> 1 && s
[--i
] == '/')
676 static void deleteFile(WMButton
* bPre
, WMFilePanel
* panel
)
679 struct stat filestat
;
680 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
681 #define __msgbufsize__ 512
683 buffer
= wmalloc(__msgbufsize__
);
684 file
= getCurrentFileName(panel
);
687 if (stat(file
, &filestat
) == -1) {
688 snprintf(buffer
, __msgbufsize__
, _("Can not find %s: %s"), file
, strerror(errno
));
689 showError(scr
, panel
->win
, buffer
, NULL
);
693 snprintf(buffer
, __msgbufsize__
, _("Delete %s %s?"),
694 S_ISDIR(filestat
.st_mode
) ? _("directory") : _("file"), file
);
696 if (!WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
697 _("Warning"), buffer
, _("OK"), _("Cancel"), NULL
)) {
699 if (remove(file
) == -1) {
700 snprintf(buffer
, __msgbufsize__
, _("Removing %s failed: %s"), file
, strerror(errno
));
701 showError(scr
, panel
->win
, buffer
, NULL
);
703 char *s
= strrchr(file
, '/');
706 WMSetFilePanelDirectory(panel
, file
);
715 #undef __msgbufsize__
718 static void goUnmount(WMButton
* bPtr
, WMFilePanel
* panel
)
722 static void goFloppy(WMButton
* bPtr
, WMFilePanel
* panel
)
724 struct stat filestat
;
725 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
727 if (stat(WINGsConfiguration
.floppyPath
, &filestat
)) {
728 showError(scr
, panel
->win
, _("An error occured browsing '%s'."), WINGsConfiguration
.floppyPath
);
730 } else if (!S_ISDIR(filestat
.st_mode
)) {
731 showError(scr
, panel
->win
, _("'%s' is not a directory."), WINGsConfiguration
.floppyPath
);
735 WMSetFilePanelDirectory(panel
, WINGsConfiguration
.floppyPath
);
738 static void goHome(WMButton
* bPtr
, WMFilePanel
* panel
)
742 /* home is statically allocated. Don't free it! */
743 home
= wgethomedir();
747 WMSetFilePanelDirectory(panel
, home
);
750 static void handleEvents(XEvent
* event
, void *data
)
752 W_FilePanel
*pPtr
= (W_FilePanel
*) data
;
753 W_View
*view
= WMWidgetView(pPtr
->win
);
755 if (event
->type
== ConfigureNotify
) {
756 if (event
->xconfigure
.width
!= view
->size
.width
|| event
->xconfigure
.height
!= view
->size
.height
) {
757 unsigned int newWidth
= event
->xconfigure
.width
;
758 unsigned int newHeight
= event
->xconfigure
.height
;
761 W_ResizeView(view
, newWidth
, newHeight
);
762 WMResizeWidget(pPtr
->line
, newWidth
, 2);
763 WMResizeWidget(pPtr
->browser
, newWidth
- 14, newHeight
- (PHEIGHT
- 200));
764 WMResizeWidget(pPtr
->fileField
, newWidth
- 60 - 10, 24);
765 WMMoveWidget(pPtr
->nameLabel
, 7, newHeight
- (PHEIGHT
- 282));
766 WMMoveWidget(pPtr
->fileField
, 60, newHeight
- (PHEIGHT
- 278));
767 WMMoveWidget(pPtr
->okButton
, newWidth
- (PWIDTH
- 245), newHeight
- (PHEIGHT
- 325));
768 WMMoveWidget(pPtr
->cancelButton
, newWidth
- (PWIDTH
- 165), newHeight
- (PHEIGHT
- 325));
770 WMMoveWidget(pPtr
->trashcanButton
, 7, newHeight
- (PHEIGHT
- 325));
771 WMMoveWidget(pPtr
->createDirButton
, 37, newHeight
- (PHEIGHT
- 325));
772 WMMoveWidget(pPtr
->homeButton
, 67, newHeight
- (PHEIGHT
- 325));
773 WMMoveWidget(pPtr
->disketteButton
, 97, newHeight
- (PHEIGHT
- 325));
774 WMMoveWidget(pPtr
->unmountButton
, 127, newHeight
- (PHEIGHT
- 325));
776 newColumnCount
= (newWidth
- 14) / 140;
777 WMSetBrowserMaxVisibleColumns(pPtr
->browser
, newColumnCount
);
782 static char *getCurrentFileName(WMFilePanel
* panel
)
789 path
= WMGetBrowserPath(panel
->browser
);
792 if (path
[len
- 1] == '/') {
793 file
= WMGetTextFieldText(panel
->fileField
);
794 tmp
= wmalloc(strlen(path
) + strlen(file
) + 8);
795 if (file
[0] != '/') {
809 static Bool
validOpenFile(WMFilePanel
* panel
)
812 int col
, haveFile
= 0;
813 char *file
= WMGetTextFieldText(panel
->fileField
);
819 col
= WMGetBrowserSelectedColumn(panel
->browser
);
820 item
= WMGetBrowserSelectedItemInColumn(panel
->browser
, col
);
822 if (item
->isBranch
&& !panel
->flags
.canChooseDirectories
&& !haveFile
)
824 else if (!item
->isBranch
&& !panel
->flags
.canChooseFiles
)
829 /* we compute for / here */
830 if (!panel
->flags
.canChooseDirectories
&& !haveFile
)
838 static void buttonClick(WMButton
* bPtr
, WMFilePanel
* panel
)
842 if (bPtr
== panel
->okButton
) {
843 if (!validOpenFile(panel
))
845 if (panel
->flags
.fileMustExist
) {
848 file
= getCurrentFileName(panel
);
849 if (access(file
, F_OK
) != 0) {
850 WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
851 _("Error"), _("File does not exist."), _("OK"), NULL
, NULL
);
857 panel
->flags
.canceled
= 0;
859 panel
->flags
.canceled
= 1;
861 range
.count
= range
.position
= 0;
862 WMSelectTextFieldRange(panel
->fileField
, range
);
863 WMBreakModalLoop(WMWidgetScreen(bPtr
));