18 typedef struct W_FilePanel
{
30 WMButton
*cancelButton
;
33 WMButton
*trashcanButton
;
34 WMButton
*createDirButton
;
35 WMButton
*disketteButton
;
36 WMButton
*unmountButton
;
38 WMView
*accessoryView
;
40 WMTextField
*fileField
;
45 unsigned int canExit
:1;
46 unsigned int canceled
:1; /* clicked on cancel */
47 unsigned int filtered
:1;
48 unsigned int canChooseFiles
:1;
49 unsigned int canChooseDirectories
:1;
50 unsigned int autoCompletion
:1;
51 unsigned int showAllFiles
:1;
52 unsigned int canFreeFileTypes
:1;
53 unsigned int fileMustExist
:1;
54 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
, WMList
* list
);
71 static void normalizePath(char *s
);
73 static void deleteFile();
75 static void createDir();
79 static void goFloppy();
81 static void goUnmount();
83 static void buttonClick();
85 static char *getCurrentFileName(WMFilePanel
* panel
);
87 static void handleEvents(XEvent
* event
, void *data
);
89 static WMBrowserDelegate browserDelegate
= {
91 fillColumn
, /* createRowsForColumn */
92 NULL
, /* titleOfColumn */
97 static int closestListItem(WMList
* list
, char *text
, Bool exact
)
100 WMArray
*items
= WMGetListItems(list
);
101 int i
, len
= strlen(text
);
106 for (i
= 0; i
< WMGetArrayItemCount(items
); i
++) {
107 item
= WMGetFromArray(items
, i
);
108 if (strlen(item
->text
) >= len
&&
109 ((exact
&& strcmp(item
->text
, text
) == 0) ||
110 (!exact
&& strncmp(item
->text
, text
, len
) == 0))) {
118 static void textChangedObserver(void *observerData
, WMNotification
* notification
)
120 W_FilePanel
*panel
= (W_FilePanel
*) observerData
;
123 int col
= WMGetBrowserNumberOfColumns(panel
->browser
) - 1;
127 if (!(list
= WMGetBrowserListInColumn(panel
->browser
, col
)))
130 text
= WMGetTextFieldText(panel
->fileField
);
131 textEvent
= (uintptr_t)WMGetNotificationClientData(notification
);
133 if (panel
->flags
.autoCompletion
&& textEvent
!= WMDeleteTextEvent
)
134 i
= closestListItem(list
, text
, False
);
136 i
= closestListItem(list
, text
, True
);
138 WMSelectListItem(list
, i
);
139 if (i
>= 0 && panel
->flags
.autoCompletion
) {
140 WMListItem
*item
= WMGetListItem(list
, i
);
141 int textLen
= strlen(text
), itemTextLen
= strlen(item
->text
);
142 int visibleItems
= WMWidgetHeight(list
) / WMGetListItemHeight(list
);
144 WMSetListPosition(list
, i
- visibleItems
/ 2);
146 if (textEvent
!= WMDeleteTextEvent
) {
149 WMInsertTextFieldText(panel
->fileField
, &item
->text
[textLen
], textLen
);
150 range
.position
= textLen
;
151 range
.count
= itemTextLen
- textLen
;
152 WMSelectTextFieldRange(panel
->fileField
, range
);
153 /*WMSetTextFieldCursorPosition(panel->fileField, itemTextLen); */
160 static void textEditedObserver(void *observerData
, WMNotification
* notification
)
162 W_FilePanel
*panel
= (W_FilePanel
*) observerData
;
164 if ((uintptr_t)WMGetNotificationClientData(notification
) == WMReturnTextMovement
) {
165 WMPerformButtonClick(panel
->okButton
);
169 static WMFilePanel
*makeFilePanel(WMScreen
* scrPtr
, char *name
, char *title
)
175 fPtr
= wmalloc(sizeof(WMFilePanel
));
177 fPtr
->win
= WMCreateWindowWithStyle(scrPtr
, name
, WMTitledWindowMask
| WMResizableWindowMask
);
178 WMResizeWidget(fPtr
->win
, PWIDTH
, PHEIGHT
);
179 WMSetWindowTitle(fPtr
->win
, "");
181 WMCreateEventHandler(WMWidgetView(fPtr
->win
), StructureNotifyMask
, handleEvents
, fPtr
);
182 WMSetWindowMinSize(fPtr
->win
, PWIDTH
, PHEIGHT
);
184 fPtr
->iconLabel
= WMCreateLabel(fPtr
->win
);
185 WMResizeWidget(fPtr
->iconLabel
, 64, 64);
186 WMMoveWidget(fPtr
->iconLabel
, 0, 0);
187 WMSetLabelImagePosition(fPtr
->iconLabel
, WIPImageOnly
);
188 icon
= WMCreateApplicationIconBlendedPixmap(scrPtr
, (RColor
*) NULL
);
190 WMSetLabelImage(fPtr
->iconLabel
, icon
);
191 WMReleasePixmap(icon
);
193 WMSetLabelImage(fPtr
->iconLabel
, scrPtr
->applicationIconPixmap
);
196 fPtr
->titleLabel
= WMCreateLabel(fPtr
->win
);
197 WMResizeWidget(fPtr
->titleLabel
, PWIDTH
- 64, 64);
198 WMMoveWidget(fPtr
->titleLabel
, 64, 0);
199 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
200 WMSetLabelFont(fPtr
->titleLabel
, largeFont
);
201 WMReleaseFont(largeFont
);
202 WMSetLabelText(fPtr
->titleLabel
, title
);
204 fPtr
->line
= WMCreateFrame(fPtr
->win
);
205 WMMoveWidget(fPtr
->line
, 0, 64);
206 WMResizeWidget(fPtr
->line
, PWIDTH
, 2);
207 WMSetFrameRelief(fPtr
->line
, WRGroove
);
209 fPtr
->browser
= WMCreateBrowser(fPtr
->win
);
210 WMSetBrowserAllowEmptySelection(fPtr
->browser
, True
);
211 WMSetBrowserDelegate(fPtr
->browser
, &browserDelegate
);
212 WMSetBrowserAction(fPtr
->browser
, browserClick
, fPtr
);
213 WMSetBrowserDoubleAction(fPtr
->browser
, browserDClick
, fPtr
);
214 WMMoveWidget(fPtr
->browser
, 7, 72);
215 WMResizeWidget(fPtr
->browser
, PWIDTH
- 14, 200);
216 WMHangData(fPtr
->browser
, fPtr
);
218 fPtr
->nameLabel
= WMCreateLabel(fPtr
->win
);
219 WMMoveWidget(fPtr
->nameLabel
, 7, 282);
220 WMResizeWidget(fPtr
->nameLabel
, 55, 14);
221 WMSetLabelText(fPtr
->nameLabel
, _("Name:"));
223 fPtr
->fileField
= WMCreateTextField(fPtr
->win
);
224 WMMoveWidget(fPtr
->fileField
, 60, 278);
225 WMResizeWidget(fPtr
->fileField
, PWIDTH
- 60 - 10, 24);
226 WMAddNotificationObserver(textEditedObserver
, fPtr
, WMTextDidEndEditingNotification
, fPtr
->fileField
);
227 WMAddNotificationObserver(textChangedObserver
, fPtr
, WMTextDidChangeNotification
, fPtr
->fileField
);
229 fPtr
->okButton
= WMCreateCommandButton(fPtr
->win
);
230 WMMoveWidget(fPtr
->okButton
, 245, 325);
231 WMResizeWidget(fPtr
->okButton
, 75, 28);
232 WMSetButtonText(fPtr
->okButton
, _("OK"));
233 WMSetButtonImage(fPtr
->okButton
, scrPtr
->buttonArrow
);
234 WMSetButtonAltImage(fPtr
->okButton
, scrPtr
->pushedButtonArrow
);
235 WMSetButtonImagePosition(fPtr
->okButton
, WIPRight
);
236 WMSetButtonAction(fPtr
->okButton
, buttonClick
, fPtr
);
238 fPtr
->cancelButton
= WMCreateCommandButton(fPtr
->win
);
239 WMMoveWidget(fPtr
->cancelButton
, 165, 325);
240 WMResizeWidget(fPtr
->cancelButton
, 75, 28);
241 WMSetButtonText(fPtr
->cancelButton
, _("Cancel"));
242 WMSetButtonAction(fPtr
->cancelButton
, buttonClick
, fPtr
);
244 fPtr
->trashcanButton
= WMCreateCommandButton(fPtr
->win
);
245 WMMoveWidget(fPtr
->trashcanButton
, 7, 325);
246 WMResizeWidget(fPtr
->trashcanButton
, 28, 28);
247 WMSetButtonImagePosition(fPtr
->trashcanButton
, WIPImageOnly
);
248 WMSetButtonImage(fPtr
->trashcanButton
, scrPtr
->trashcanIcon
);
249 WMSetButtonAltImage(fPtr
->trashcanButton
, scrPtr
->altTrashcanIcon
);
250 WMSetButtonAction(fPtr
->trashcanButton
, deleteFile
, fPtr
);
252 fPtr
->createDirButton
= WMCreateCommandButton(fPtr
->win
);
253 WMMoveWidget(fPtr
->createDirButton
, 37, 325);
254 WMResizeWidget(fPtr
->createDirButton
, 28, 28);
255 WMSetButtonImagePosition(fPtr
->createDirButton
, WIPImageOnly
);
256 WMSetButtonImage(fPtr
->createDirButton
, scrPtr
->createDirIcon
);
257 WMSetButtonAltImage(fPtr
->createDirButton
, scrPtr
->altCreateDirIcon
);
258 WMSetButtonAction(fPtr
->createDirButton
, createDir
, fPtr
);
260 fPtr
->homeButton
= WMCreateCommandButton(fPtr
->win
);
261 WMMoveWidget(fPtr
->homeButton
, 67, 325);
262 WMResizeWidget(fPtr
->homeButton
, 28, 28);
263 WMSetButtonImagePosition(fPtr
->homeButton
, WIPImageOnly
);
264 WMSetButtonImage(fPtr
->homeButton
, scrPtr
->homeIcon
);
265 WMSetButtonAltImage(fPtr
->homeButton
, scrPtr
->altHomeIcon
);
266 WMSetButtonAction(fPtr
->homeButton
, goHome
, fPtr
);
268 fPtr
->disketteButton
= WMCreateCommandButton(fPtr
->win
);
269 WMMoveWidget(fPtr
->disketteButton
, 97, 325);
270 WMResizeWidget(fPtr
->disketteButton
, 28, 28);
271 WMSetButtonImagePosition(fPtr
->disketteButton
, WIPImageOnly
);
272 WMSetButtonImage(fPtr
->disketteButton
, scrPtr
->disketteIcon
);
273 WMSetButtonAltImage(fPtr
->disketteButton
, scrPtr
->altDisketteIcon
);
274 WMSetButtonAction(fPtr
->disketteButton
, goFloppy
, fPtr
);
276 fPtr
->unmountButton
= WMCreateCommandButton(fPtr
->win
);
277 WMMoveWidget(fPtr
->unmountButton
, 127, 325);
278 WMResizeWidget(fPtr
->unmountButton
, 28, 28);
279 WMSetButtonImagePosition(fPtr
->unmountButton
, WIPImageOnly
);
280 WMSetButtonImage(fPtr
->unmountButton
, scrPtr
->unmountIcon
);
281 WMSetButtonAltImage(fPtr
->unmountButton
, scrPtr
->altUnmountIcon
);
282 WMSetButtonAction(fPtr
->unmountButton
, goUnmount
, fPtr
);
283 WMSetButtonEnabled(fPtr
->unmountButton
, False
);
285 WMRealizeWidget(fPtr
->win
);
286 WMMapSubwidgets(fPtr
->win
);
288 WMSetFocusToWidget(fPtr
->fileField
);
289 WMSetTextFieldCursorPosition(fPtr
->fileField
, 0);
291 WMLoadBrowserColumnZero(fPtr
->browser
);
293 WMSetWindowInitialPosition(fPtr
->win
,
294 (scrPtr
->rootView
->size
.width
- WMWidgetWidth(fPtr
->win
)) / 2,
295 (scrPtr
->rootView
->size
.height
- WMWidgetHeight(fPtr
->win
)) / 2);
297 fPtr
->flags
.canChooseFiles
= 1;
298 fPtr
->flags
.canChooseDirectories
= 1;
299 fPtr
->flags
.autoCompletion
= 1;
304 WMOpenPanel
*WMGetOpenPanel(WMScreen
* scrPtr
)
308 if (scrPtr
->sharedOpenPanel
)
309 return scrPtr
->sharedOpenPanel
;
311 panel
= makeFilePanel(scrPtr
, "openFilePanel", _("Open"));
312 panel
->flags
.fileMustExist
= 1;
313 panel
->flags
.panelType
= WP_OPEN
;
315 scrPtr
->sharedOpenPanel
= panel
;
320 WMSavePanel
*WMGetSavePanel(WMScreen
* scrPtr
)
324 if (scrPtr
->sharedSavePanel
)
325 return scrPtr
->sharedSavePanel
;
327 panel
= makeFilePanel(scrPtr
, "saveFilePanel", _("Save"));
328 panel
->flags
.fileMustExist
= 0;
329 panel
->flags
.panelType
= WP_SAVE
;
331 scrPtr
->sharedSavePanel
= panel
;
336 void WMFreeFilePanel(WMFilePanel
* panel
)
338 if (panel
== WMWidgetScreen(panel
->win
)->sharedSavePanel
) {
339 WMWidgetScreen(panel
->win
)->sharedSavePanel
= NULL
;
341 if (panel
== WMWidgetScreen(panel
->win
)->sharedOpenPanel
) {
342 WMWidgetScreen(panel
->win
)->sharedOpenPanel
= NULL
;
344 WMRemoveNotificationObserver(panel
);
345 WMUnmapWidget(panel
->win
);
346 WMDestroyWidget(panel
->win
);
351 WMRunModalFilePanelForDirectory(WMFilePanel
* panel
, WMWindow
* owner
, char *path
, char *name
, char **fileTypes
)
353 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
355 if (name
&& !owner
) {
356 WMSetWindowTitle(panel
->win
, name
);
359 WMChangePanelOwner(panel
->win
, owner
);
361 WMSetFilePanelDirectory(panel
, path
);
363 switch (panel
->flags
.panelType
) {
366 panel
->flags
.filtered
= 1;
367 panel
->fileTypes
= fileTypes
;
372 panel
->fileTypes
= NULL
;
373 panel
->flags
.filtered
= 0;
381 WMSetLabelText(panel
->titleLabel
, name
);
383 WMMapWidget(panel
->win
);
385 WMRunModalLoop(scr
, W_VIEW(panel
->win
));
387 /* Must withdraw window because the next time we map
388 * it, it might have a different transient owner.
390 WMCloseWindow(panel
->win
);
392 return (panel
->flags
.canceled
? False
: True
);
395 void WMSetFilePanelDirectory(WMFilePanel
* panel
, char *path
)
402 rest
= WMSetBrowserPath(panel
->browser
, path
);
403 if (strcmp(path
, "/") == 0)
406 col
= WMGetBrowserSelectedColumn(panel
->browser
);
407 list
= WMGetBrowserListInColumn(panel
->browser
, col
);
408 if (list
&& (item
= WMGetListSelectedItem(list
))) {
409 if (item
->isBranch
) {
410 WMSetTextFieldText(panel
->fileField
, rest
);
412 WMSetTextFieldText(panel
->fileField
, item
->text
);
415 WMSetTextFieldText(panel
->fileField
, rest
);
419 void WMSetFilePanelCanChooseDirectories(WMFilePanel
* panel
, Bool flag
)
421 panel
->flags
.canChooseDirectories
= ((flag
== 0) ? 0 : 1);
424 void WMSetFilePanelCanChooseFiles(WMFilePanel
* panel
, Bool flag
)
426 panel
->flags
.canChooseFiles
= ((flag
== 0) ? 0 : 1);
429 void WMSetFilePanelAutoCompletion(WMFilePanel
* panel
, Bool flag
)
431 panel
->flags
.autoCompletion
= ((flag
== 0) ? 0 : 1);
434 char *WMGetFilePanelFileName(WMFilePanel
* panel
)
436 return getCurrentFileName(panel
);
439 void WMSetFilePanelAccessoryView(WMFilePanel
* panel
, WMView
* view
)
443 panel
->accessoryView
= view
;
445 v
= WMWidgetView(panel
->win
);
447 W_ReparentView(view
, v
, 0, 0);
449 W_MoveView(view
, (v
->size
.width
- v
->size
.width
) / 2, 300);
452 WMView
*WMGetFilePanelAccessoryView(WMFilePanel
* panel
)
454 return panel
->accessoryView
;
457 static char *get_name_from_path(char *path
)
461 assert(path
!= NULL
);
465 /* remove trailing / */
466 while (size
> 0 && path
[size
- 1] == '/')
468 /* directory was root */
472 while (size
> 0 && path
[size
- 1] != '/')
475 return wstrdup(&(path
[size
]));
478 static int filterFileName(WMFilePanel
* panel
, char *file
, Bool isDirectory
)
483 #define CAST(item) (*((WMListItem**)item))
484 static int comparer(const void *a
, const void *b
)
486 if (CAST(a
)->isBranch
== CAST(b
)->isBranch
)
487 return (strcmp(CAST(a
)->text
, CAST(b
)->text
));
488 if (CAST(a
)->isBranch
)
495 static void listDirectoryOnColumn(WMFilePanel
* panel
, int column
, char *path
)
497 WMBrowser
*bPtr
= panel
->browser
;
498 struct dirent
*dentry
;
500 struct stat stat_buf
;
501 char pbuf
[PATH_MAX
+ 16];
505 assert(path
!= NULL
);
507 /* put directory name in the title */
508 name
= get_name_from_path(path
);
509 WMSetBrowserColumnTitle(bPtr
, column
, name
);
516 printf(_("WINGs: could not open directory %s\n"), path
);
521 /* list contents in the column */
522 while ((dentry
= readdir(dir
))) {
523 if (strcmp(dentry
->d_name
, ".") == 0 || strcmp(dentry
->d_name
, "..") == 0)
526 if (wstrlcpy(pbuf
, path
, sizeof(pbuf
)) >= sizeof(pbuf
))
528 if (strcmp(path
, "/") != 0 &&
529 wstrlcat(pbuf
, "/", sizeof(pbuf
)) >= sizeof(pbuf
))
531 if (wstrlcat(pbuf
, dentry
->d_name
, sizeof(pbuf
)) >= sizeof(pbuf
))
534 if (stat(pbuf
, &stat_buf
) != 0) {
536 printf(_("WINGs: could not stat %s\n"), pbuf
);
542 isDirectory
= S_ISDIR(stat_buf
.st_mode
);
544 if (filterFileName(panel
, dentry
->d_name
, isDirectory
))
545 WMInsertBrowserItem(bPtr
, column
, -1, dentry
->d_name
, isDirectory
);
548 WMSortBrowserColumnWithComparer(bPtr
, column
, comparer
);
554 static void fillColumn(WMBrowserDelegate
* self
, WMBrowser
* bPtr
, int column
, WMList
* list
)
560 path
= WMGetBrowserPathToColumn(bPtr
, column
- 1);
565 panel
= WMGetHangedData(bPtr
);
566 listDirectoryOnColumn(panel
, column
, path
);
570 static void browserDClick(WMBrowser
* bPtr
, WMFilePanel
* panel
)
572 WMPerformButtonClick(panel
->okButton
);
575 static void browserClick(WMBrowser
* bPtr
, WMFilePanel
* panel
)
577 int col
= WMGetBrowserSelectedColumn(bPtr
);
578 WMListItem
*item
= WMGetBrowserSelectedItemInColumn(bPtr
, col
);
580 if (!item
|| item
->isBranch
)
581 WMSetTextFieldText(panel
->fileField
, NULL
);
583 WMSetTextFieldText(panel
->fileField
, item
->text
);
587 static void showError(WMScreen
* scr
, WMWindow
* owner
, char *s
, char *file
)
592 errStr
= wmalloc(strlen(file
) + strlen(s
));
593 sprintf(errStr
, s
, file
);
597 WMRunAlertPanel(scr
, owner
, _("Error"), errStr
, _("OK"), NULL
, NULL
);
601 static void createDir(WMButton
* bPre
, WMFilePanel
* panel
)
603 char *dirName
, *directory
, *file
;
605 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
607 dirName
= WMRunInputPanel(scr
, panel
->win
, _("Create Directory"),
608 _("Enter directory name"), "", _("OK"), _("Cancel"));
612 /* if `dirName' is an absolute path, don't mind `directory'.
613 * normalize as needed (possibly not needed at all?) */
614 normalizePath(dirName
);
615 if (*dirName
!= '/') {
616 directory
= getCurrentFileName(panel
);
617 normalizePath(directory
);
622 slen
= strlen(dirName
) + (directory
? strlen(directory
) + 1 /* "/" */ : 0) + 1 /* NULL */;
623 file
= wmalloc(slen
);
626 (wstrlcat(file
, directory
, slen
) >= slen
||
627 wstrlcat(file
, "/", slen
) >= slen
))
630 if (wstrlcat(file
, dirName
, slen
) >= slen
)
633 if (mkdir(file
, 00777) != 0) {
634 #define __msgbufsize__ 512
635 char *buffer
= wmalloc(__msgbufsize__
);
636 snprintf(buffer
, __msgbufsize__
, _("Can not create %s: %s"), file
, strerror(errno
));
637 showError(scr
, panel
->win
, buffer
, NULL
);
639 #undef __msgbufsize__
641 WMSetFilePanelDirectory(panel
, file
);
654 *----------------------------------------------------------------------
656 * Remove multiple consecutive and any trailing slashes from
658 *----------------------------------------------------------------------
660 static void normalizePath(char *s
)
665 for (i
= 0; s
[i
]; (void)(!found
&& i
++)) {
667 if (s
[i
] == '/' && s
[i
+1] == '/') {
671 while (s
[i
+nslash
] == '/')
673 for (j
= 0; s
[i
+j
+nslash
]; j
++)
674 s
[i
+j
] = s
[i
+j
+nslash
];
678 if (i
> 1 && s
[--i
] == '/')
683 static void deleteFile(WMButton
* bPre
, WMFilePanel
* panel
)
686 struct stat filestat
;
687 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
688 #define __msgbufsize__ 512
690 buffer
= wmalloc(__msgbufsize__
);
691 file
= getCurrentFileName(panel
);
694 if (stat(file
, &filestat
) == -1) {
695 snprintf(buffer
, __msgbufsize__
, _("Can not find %s: %s"), file
, strerror(errno
));
696 showError(scr
, panel
->win
, buffer
, NULL
);
700 snprintf(buffer
, __msgbufsize__
, _("Delete %s %s?"),
701 S_ISDIR(filestat
.st_mode
) ? _("directory") : _("file"), file
);
703 if (!WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
704 _("Warning"), buffer
, _("OK"), _("Cancel"), NULL
)) {
706 if (remove(file
) == -1) {
707 snprintf(buffer
, __msgbufsize__
, _("Removing %s failed: %s"), file
, strerror(errno
));
708 showError(scr
, panel
->win
, buffer
, NULL
);
710 char *s
= strrchr(file
, '/');
713 WMSetFilePanelDirectory(panel
, file
);
722 #undef __msgbufsize__
725 static void goUnmount(WMButton
* bPtr
, WMFilePanel
* panel
)
729 static void goFloppy(WMButton
* bPtr
, WMFilePanel
* panel
)
731 struct stat filestat
;
732 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
734 if (stat(WINGsConfiguration
.floppyPath
, &filestat
)) {
735 showError(scr
, panel
->win
, _("An error occured browsing '%s'."), WINGsConfiguration
.floppyPath
);
737 } else if (!S_ISDIR(filestat
.st_mode
)) {
738 showError(scr
, panel
->win
, _("'%s' is not a directory."), WINGsConfiguration
.floppyPath
);
742 WMSetFilePanelDirectory(panel
, WINGsConfiguration
.floppyPath
);
745 static void goHome(WMButton
* bPtr
, WMFilePanel
* panel
)
749 /* home is statically allocated. Don't free it! */
750 home
= wgethomedir();
754 WMSetFilePanelDirectory(panel
, home
);
757 static void handleEvents(XEvent
* event
, void *data
)
759 W_FilePanel
*pPtr
= (W_FilePanel
*) data
;
760 W_View
*view
= WMWidgetView(pPtr
->win
);
762 if (event
->type
== ConfigureNotify
) {
763 if (event
->xconfigure
.width
!= view
->size
.width
|| event
->xconfigure
.height
!= view
->size
.height
) {
764 unsigned int newWidth
= event
->xconfigure
.width
;
765 unsigned int newHeight
= event
->xconfigure
.height
;
768 W_ResizeView(view
, newWidth
, newHeight
);
769 WMResizeWidget(pPtr
->line
, newWidth
, 2);
770 WMResizeWidget(pPtr
->browser
, newWidth
- 14, newHeight
- (PHEIGHT
- 200));
771 WMResizeWidget(pPtr
->fileField
, newWidth
- 60 - 10, 24);
772 WMMoveWidget(pPtr
->nameLabel
, 7, newHeight
- (PHEIGHT
- 282));
773 WMMoveWidget(pPtr
->fileField
, 60, newHeight
- (PHEIGHT
- 278));
774 WMMoveWidget(pPtr
->okButton
, newWidth
- (PWIDTH
- 245), newHeight
- (PHEIGHT
- 325));
775 WMMoveWidget(pPtr
->cancelButton
, newWidth
- (PWIDTH
- 165), newHeight
- (PHEIGHT
- 325));
777 WMMoveWidget(pPtr
->trashcanButton
, 7, newHeight
- (PHEIGHT
- 325));
778 WMMoveWidget(pPtr
->createDirButton
, 37, newHeight
- (PHEIGHT
- 325));
779 WMMoveWidget(pPtr
->homeButton
, 67, newHeight
- (PHEIGHT
- 325));
780 WMMoveWidget(pPtr
->disketteButton
, 97, newHeight
- (PHEIGHT
- 325));
781 WMMoveWidget(pPtr
->unmountButton
, 127, newHeight
- (PHEIGHT
- 325));
783 newColumnCount
= (newWidth
- 14) / 140;
784 WMSetBrowserMaxVisibleColumns(pPtr
->browser
, newColumnCount
);
789 static char *getCurrentFileName(WMFilePanel
* panel
)
796 path
= WMGetBrowserPath(panel
->browser
);
801 if (path
[strlen(path
) -1] != '/')
804 file
= WMGetTextFieldText(panel
->fileField
);
805 slen
= strlen(path
) + strlen(file
) + 1;
809 wstrlcat(ret
, path
, slen
) >= slen
)
812 if (wstrlcat(ret
, file
, slen
) >= slen
)
828 static Bool
validOpenFile(WMFilePanel
* panel
)
831 int col
, haveFile
= 0;
832 char *file
= WMGetTextFieldText(panel
->fileField
);
838 col
= WMGetBrowserSelectedColumn(panel
->browser
);
839 item
= WMGetBrowserSelectedItemInColumn(panel
->browser
, col
);
841 if (item
->isBranch
&& !panel
->flags
.canChooseDirectories
&& !haveFile
)
843 else if (!item
->isBranch
&& !panel
->flags
.canChooseFiles
)
848 /* we compute for / here */
849 if (!panel
->flags
.canChooseDirectories
&& !haveFile
)
857 static void buttonClick(WMButton
* bPtr
, WMFilePanel
* panel
)
861 if (bPtr
== panel
->okButton
) {
862 if (!validOpenFile(panel
))
864 if (panel
->flags
.fileMustExist
) {
867 file
= getCurrentFileName(panel
);
868 if (access(file
, F_OK
) != 0) {
869 WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
870 _("Error"), _("File does not exist."), _("OK"), NULL
, NULL
);
876 panel
->flags
.canceled
= 0;
878 panel
->flags
.canceled
= 1;
880 range
.count
= range
.position
= 0;
881 WMSelectTextFieldRange(panel
->fileField
, range
);
882 WMBreakModalLoop(WMWidgetScreen(bPtr
));