16 #define FLOPPY_PATH "/floppy"
19 typedef struct W_FilePanel
{
31 WMButton
*cancelButton
;
34 WMButton
*trashcanButton
;
35 WMButton
*createDirButton
;
36 WMButton
*disketteButton
;
37 WMButton
*unmountButton
;
39 WMView
*accessoryView
;
41 WMTextField
*fileField
;
46 unsigned int canExit
:1;
47 unsigned int canceled
:1; /* clicked on cancel */
49 unsigned int filtered
:1;
50 unsigned int canChooseFiles
:1;
51 unsigned int canChooseDirectories
:1;
52 unsigned int autoCompletion
:1;
53 unsigned int showAllFiles
:1;
54 unsigned int canFreeFileTypes
:1;
55 unsigned int fileMustExist
:1;
56 unsigned int panelType
:1;
68 static void listDirectoryOnColumn(WMFilePanel
*panel
, int column
, char *path
);
69 static void browserClick();
70 static void browserDClick();
72 static void fillColumn(WMBrowserDelegate
*self
, WMBrowser
*bPtr
, int column
,
75 static void deleteFile();
77 static void createDir();
81 static void goFloppy();
83 static void goUnmount();
85 static void buttonClick();
87 static char *getCurrentFileName(WMFilePanel
*panel
);
89 static void handleEvents(XEvent
*event
, void *data
);
93 static WMBrowserDelegate browserDelegate
= {
95 fillColumn
, /* createRowsForColumn */
96 NULL
, /* titleOfColumn */
103 closestListItem(WMList
*list
, char *text
, Bool exact
)
105 WMListItem
*item
= WMGetListItem(list
, 0);
107 int len
= strlen(text
);
113 if (strlen(item
->text
) >= len
&&
114 ((exact
&& strcmp(item
->text
, text
)==0) ||
115 (!exact
&& strncmp(item
->text
, text
, len
)==0))) {
118 item
= item
->nextPtr
;
126 textChangedObserver(void *observerData
, WMNotification
*notification
)
128 W_FilePanel
*panel
= (W_FilePanel
*)observerData
;
131 int col
= WMGetBrowserNumberOfColumns(panel
->browser
) - 1;
134 if (!(list
= WMGetBrowserListInColumn(panel
->browser
, col
)))
137 text
= WMGetTextFieldText(panel
->fileField
);
138 textEvent
= (int)WMGetNotificationClientData(notification
);
140 if (panel
->flags
.autoCompletion
&& textEvent
!=WMDeleteTextEvent
)
141 i
= closestListItem(list
, text
, False
);
143 i
= closestListItem(list
, text
, True
);
145 WMSelectListItem(list
, i
);
146 if (i
>=0 && panel
->flags
.autoCompletion
) {
147 WMListItem
*item
= WMGetListItem(list
, i
);
148 int textLen
= strlen(text
), itemTextLen
= strlen(item
->text
);
149 int visibleItems
= WMWidgetHeight(list
)/WMGetListItemHeight(list
);
151 WMSetListPosition(list
, i
- visibleItems
/2);
153 if (textEvent
!=WMDeleteTextEvent
) {
156 WMInsertTextFieldText(panel
->fileField
, &item
->text
[textLen
],
158 WMSetTextFieldCursorPosition(panel
->fileField
, itemTextLen
);
159 range
.position
= textLen
;
160 range
.count
= itemTextLen
- textLen
;
161 WMSelectTextFieldRange(panel
->fileField
, range
);
170 textEditedObserver(void *observerData
, WMNotification
*notification
)
172 W_FilePanel
*panel
= (W_FilePanel
*)observerData
;
174 if ((int)WMGetNotificationClientData(notification
)==WMReturnTextMovement
) {
175 WMPerformButtonClick(panel
->okButton
);
182 makeFilePanel(WMScreen
*scrPtr
, char *name
, char *title
)
187 fPtr
= wmalloc(sizeof(WMFilePanel
));
188 memset(fPtr
, 0, sizeof(WMFilePanel
));
190 fPtr
->win
= WMCreateWindowWithStyle(scrPtr
, name
, WMTitledWindowMask
191 |WMResizableWindowMask
);
192 WMResizeWidget(fPtr
->win
, PWIDTH
, PHEIGHT
);
193 WMSetWindowTitle(fPtr
->win
, "");
195 WMCreateEventHandler(WMWidgetView(fPtr
->win
), StructureNotifyMask
,
197 WMSetWindowMinSize(fPtr
->win
, PWIDTH
, PHEIGHT
);
200 fPtr
->iconLabel
= WMCreateLabel(fPtr
->win
);
201 WMResizeWidget(fPtr
->iconLabel
, 64, 64);
202 WMMoveWidget(fPtr
->iconLabel
, 0, 0);
203 WMSetLabelImagePosition(fPtr
->iconLabel
, WIPImageOnly
);
204 WMSetLabelImage(fPtr
->iconLabel
, scrPtr
->applicationIcon
);
206 fPtr
->titleLabel
= WMCreateLabel(fPtr
->win
);
207 WMResizeWidget(fPtr
->titleLabel
, PWIDTH
-64, 64);
208 WMMoveWidget(fPtr
->titleLabel
, 64, 0);
209 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
210 WMSetLabelFont(fPtr
->titleLabel
, largeFont
);
211 WMReleaseFont(largeFont
);
212 WMSetLabelText(fPtr
->titleLabel
, title
);
214 fPtr
->line
= WMCreateFrame(fPtr
->win
);
215 WMMoveWidget(fPtr
->line
, 0, 64);
216 WMResizeWidget(fPtr
->line
, PWIDTH
, 2);
217 WMSetFrameRelief(fPtr
->line
, WRGroove
);
219 fPtr
->browser
= WMCreateBrowser(fPtr
->win
);
220 WMSetBrowserDelegate(fPtr
->browser
, &browserDelegate
);
221 WMSetBrowserAction(fPtr
->browser
, browserClick
, fPtr
);
222 WMSetBrowserDoubleAction(fPtr
->browser
, browserDClick
, fPtr
);
223 WMMoveWidget(fPtr
->browser
, 7, 72);
224 WMResizeWidget(fPtr
->browser
, PWIDTH
-14,200);
225 WMHangData(fPtr
->browser
, fPtr
);
227 fPtr
->nameLabel
= WMCreateLabel(fPtr
->win
);
228 WMMoveWidget(fPtr
->nameLabel
, 7, 282);
229 WMResizeWidget(fPtr
->nameLabel
, 55, 14);
230 WMSetLabelText(fPtr
->nameLabel
, "Name:");
232 fPtr
->fileField
= WMCreateTextField(fPtr
->win
);
233 WMMoveWidget(fPtr
->fileField
, 60, 278);
234 WMResizeWidget(fPtr
->fileField
, PWIDTH
-60-10, 24);
235 WMAddNotificationObserver(textEditedObserver
, fPtr
,
236 WMTextDidEndEditingNotification
,
238 WMAddNotificationObserver(textChangedObserver
, fPtr
,
239 WMTextDidChangeNotification
,
242 fPtr
->okButton
= WMCreateCommandButton(fPtr
->win
);
243 WMMoveWidget(fPtr
->okButton
, 245, 325);
244 WMResizeWidget(fPtr
->okButton
, 75, 28);
245 WMSetButtonText(fPtr
->okButton
, "OK");
246 WMSetButtonImage(fPtr
->okButton
, scrPtr
->buttonArrow
);
247 WMSetButtonAltImage(fPtr
->okButton
, scrPtr
->pushedButtonArrow
);
248 WMSetButtonImagePosition(fPtr
->okButton
, WIPRight
);
249 WMSetButtonAction(fPtr
->okButton
, buttonClick
, fPtr
);
251 fPtr
->cancelButton
= WMCreateCommandButton(fPtr
->win
);
252 WMMoveWidget(fPtr
->cancelButton
, 165, 325);
253 WMResizeWidget(fPtr
->cancelButton
, 75, 28);
254 WMSetButtonText(fPtr
->cancelButton
, "Cancel");
255 WMSetButtonAction(fPtr
->cancelButton
, buttonClick
, fPtr
);
257 fPtr
->trashcanButton
= WMCreateCommandButton(fPtr
->win
);
258 WMMoveWidget(fPtr
->trashcanButton
, 7, 325);
259 WMResizeWidget(fPtr
->trashcanButton
, 28, 28);
260 WMSetButtonImagePosition(fPtr
->trashcanButton
, WIPImageOnly
);
261 WMSetButtonImage(fPtr
->trashcanButton
, scrPtr
->trashcanIcon
);
262 WMSetButtonAltImage(fPtr
->trashcanButton
, scrPtr
->altTrashcanIcon
);
263 WMSetButtonAction(fPtr
->trashcanButton
, deleteFile
, fPtr
);
265 fPtr
->createDirButton
= WMCreateCommandButton(fPtr
->win
);
266 WMMoveWidget(fPtr
->createDirButton
, 37, 325);
267 WMResizeWidget(fPtr
->createDirButton
, 28, 28);
268 WMSetButtonImagePosition(fPtr
->createDirButton
, WIPImageOnly
);
269 WMSetButtonImage(fPtr
->createDirButton
, scrPtr
->createDirIcon
);
270 WMSetButtonAltImage(fPtr
->createDirButton
, scrPtr
->altCreateDirIcon
);
271 WMSetButtonAction(fPtr
->createDirButton
, createDir
, fPtr
);
273 fPtr
->homeButton
= WMCreateCommandButton(fPtr
->win
);
274 WMMoveWidget(fPtr
->homeButton
, 67, 325);
275 WMResizeWidget(fPtr
->homeButton
, 28, 28);
276 WMSetButtonImagePosition(fPtr
->homeButton
, WIPImageOnly
);
277 WMSetButtonImage(fPtr
->homeButton
, scrPtr
->homeIcon
);
278 WMSetButtonAltImage(fPtr
->homeButton
, scrPtr
->altHomeIcon
);
279 WMSetButtonAction(fPtr
->homeButton
, goHome
, fPtr
);
281 fPtr
->disketteButton
= WMCreateCommandButton(fPtr
->win
);
282 WMMoveWidget(fPtr
->disketteButton
, 97, 325);
283 WMResizeWidget(fPtr
->disketteButton
, 28, 28);
284 WMSetButtonImagePosition(fPtr
->disketteButton
, WIPImageOnly
);
285 WMSetButtonImage(fPtr
->disketteButton
, scrPtr
->disketteIcon
);
286 WMSetButtonAltImage(fPtr
->disketteButton
, scrPtr
->altDisketteIcon
);
287 WMSetButtonAction(fPtr
->disketteButton
, goFloppy
, fPtr
);
289 fPtr
->unmountButton
= WMCreateCommandButton(fPtr
->win
);
290 WMMoveWidget(fPtr
->unmountButton
, 127, 325);
291 WMResizeWidget(fPtr
->unmountButton
, 28, 28);
292 WMSetButtonImagePosition(fPtr
->unmountButton
, WIPImageOnly
);
293 WMSetButtonImage(fPtr
->unmountButton
, scrPtr
->unmountIcon
);
294 WMSetButtonAltImage(fPtr
->unmountButton
, scrPtr
->altUnmountIcon
);
295 WMSetButtonAction(fPtr
->unmountButton
, goUnmount
, fPtr
);
296 WMSetButtonEnabled(fPtr
->unmountButton
, False
);
299 WMRealizeWidget(fPtr
->win
);
300 WMMapSubwidgets(fPtr
->win
);
302 WMSetFocusToWidget(fPtr
->fileField
);
303 WMSetTextFieldCursorPosition(fPtr
->fileField
, 0);
305 WMLoadBrowserColumnZero(fPtr
->browser
);
307 fPtr
->flags
.canChooseFiles
= 1;
308 fPtr
->flags
.canChooseDirectories
= 1;
309 fPtr
->flags
.autoCompletion
= 1;
316 WMGetOpenPanel(WMScreen
*scrPtr
)
320 if (scrPtr
->sharedOpenPanel
)
321 return scrPtr
->sharedOpenPanel
;
323 panel
= makeFilePanel(scrPtr
, "openFilePanel", "Open");
324 panel
->flags
.fileMustExist
= 1;
325 panel
->flags
.panelType
= WP_OPEN
;
327 scrPtr
->sharedOpenPanel
= panel
;
334 WMGetSavePanel(WMScreen
*scrPtr
)
338 if (scrPtr
->sharedSavePanel
)
339 return scrPtr
->sharedSavePanel
;
341 panel
= makeFilePanel(scrPtr
, "saveFilePanel", "Save");
342 panel
->flags
.fileMustExist
= 0;
343 panel
->flags
.panelType
= WP_SAVE
;
345 scrPtr
->sharedSavePanel
= panel
;
352 WMFreeFilePanel(WMFilePanel
*panel
)
354 if (panel
== WMWidgetScreen(panel
->win
)->sharedSavePanel
) {
355 WMWidgetScreen(panel
->win
)->sharedSavePanel
= NULL
;
357 if (panel
== WMWidgetScreen(panel
->win
)->sharedOpenPanel
) {
358 WMWidgetScreen(panel
->win
)->sharedOpenPanel
= NULL
;
360 WMRemoveNotificationObserver(panel
);
361 WMUnmapWidget(panel
->win
);
362 WMDestroyWidget(panel
->win
);
368 WMRunModalFilePanelForDirectory(WMFilePanel
*panel
, WMWindow
*owner
,
369 char *path
, char *name
, char **fileTypes
)
371 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
374 if (name
&& !owner
) {
375 WMSetWindowTitle(panel
->win
, name
);
378 WMChangePanelOwner(panel
->win
, owner
);
380 WMSetFilePanelDirectory(panel
, path
);
382 panel
->flags
.done
= 0;
383 switch(panel
->flags
.panelType
) {
386 panel
->flags
.filtered
= 1;
387 panel
->fileTypes
= fileTypes
;
392 panel
->fileTypes
= NULL
;
393 panel
->flags
.filtered
= 0;
401 WMSetWindowInitialPosition(panel
->win
,
402 (scr
->rootView
->size
.width
- WMWidgetWidth(panel
->win
))/2,
403 (scr
->rootView
->size
.height
- WMWidgetHeight(panel
->win
))/2);
404 WMSetLabelText(panel
->titleLabel
, name
);
406 scr
->modalView
= W_VIEW(panel
->win
);
407 WMMapWidget(panel
->win
);
410 while (!panel
->flags
.done
) {
411 WMNextEvent(scr
->display
, &event
);
412 WMHandleEvent(&event
);
416 /* Must withdraw window because the next time we map
417 * it, it might have a different transient owner.
419 WMCloseWindow(panel
->win
);
421 return (panel
->flags
.canceled
? False
: True
);
428 WMSetFilePanelDirectory(WMFilePanel
*panel
, char *path
)
435 rest
= WMSetBrowserPath(panel
->browser
, path
);
436 if (strcmp(path
, "/")==0)
439 col
= WMGetBrowserSelectedColumn(panel
->browser
);
440 list
= WMGetBrowserListInColumn(panel
->browser
, col
);
441 if (list
&& (item
= WMGetListSelectedItem(list
))) {
442 if (item
->isBranch
) {
443 WMSetTextFieldText(panel
->fileField
, rest
);
445 WMSetTextFieldText(panel
->fileField
, item
->text
);
448 WMSetTextFieldText(panel
->fileField
, rest
);
454 WMSetFilePanelCanChooseDirectories(WMFilePanel
*panel
, Bool flag
)
456 panel
->flags
.canChooseDirectories
= flag
;
460 WMSetFilePanelCanChooseFiles(WMFilePanel
*panel
, Bool flag
)
462 panel
->flags
.canChooseFiles
= flag
;
467 WMSetFilePanelAutoCompletion(WMFilePanel
*panel
, Bool flag
)
469 panel
->flags
.autoCompletion
= flag
;
474 WMGetFilePanelFileName(WMFilePanel
*panel
)
476 return getCurrentFileName(panel
);
481 WMSetFilePanelAccessoryView(WMFilePanel
*panel
, WMView
*view
)
485 panel
->accessoryView
= view
;
487 v
= WMWidgetView(panel
->win
);
489 W_ReparentView(view
, v
, 0, 0);
491 W_MoveView(view
, (v
->size
.width
- v
->size
.width
)/2, 300);
496 WMGetFilePanelAccessoryView(WMFilePanel
*panel
)
498 return panel
->accessoryView
;
503 get_name_from_path(char *path
)
511 /* remove trailing / */
512 while (size
> 0 && path
[size
-1]=='/')
514 /* directory was root */
518 while (size
> 0 && path
[size
-1] != '/')
521 return wstrdup(&(path
[size
]));
526 filterFileName(WMFilePanel
*panel
, char *file
, Bool isDirectory
)
533 listDirectoryOnColumn(WMFilePanel
*panel
, int column
, char *path
)
535 WMBrowser
*bPtr
= panel
->browser
;
536 struct dirent
*dentry
;
538 struct stat stat_buf
;
539 char pbuf
[PATH_MAX
+16];
542 assert(path
!= NULL
);
544 /* put directory name in the title */
545 WMSetBrowserColumnTitle(bPtr
, column
, get_name_from_path(path
));
551 printf("WINGs: could not open directory %s\n", path
);
556 /* list contents in the column */
557 while ((dentry
= readdir(dir
))) {
558 if (strcmp(dentry
->d_name
, ".")==0 ||
559 strcmp(dentry
->d_name
, "..")==0)
563 if (strcmp(path
, "/")!=0)
565 strcat(pbuf
, dentry
->d_name
);
567 if (stat(pbuf
, &stat_buf
)!=0) {
569 printf("WINGs: could not stat %s\n", pbuf
);
575 isDirectory
= S_ISDIR(stat_buf
.st_mode
);
577 if (filterFileName(panel
, dentry
->d_name
, isDirectory
))
578 WMAddSortedBrowserItem(bPtr
, column
, dentry
->d_name
,
588 fillColumn(WMBrowserDelegate
*self
, WMBrowser
*bPtr
, int column
, WMList
*list
)
594 path
= WMGetBrowserPathToColumn(bPtr
, column
-1);
599 panel
= WMGetHangedData(bPtr
);
600 listDirectoryOnColumn(panel
, column
, path
);
606 browserDClick(WMBrowser
*bPtr
, WMFilePanel
*panel
)
608 WMPerformButtonClick(panel
->okButton
);
612 browserClick(WMBrowser
*bPtr
, WMFilePanel
*panel
)
614 int col
= WMGetBrowserSelectedColumn(bPtr
);
615 WMListItem
*item
= WMGetBrowserSelectedItemInColumn(bPtr
, col
);
617 if (!item
|| item
->isBranch
)
618 WMSetTextFieldText(panel
->fileField
, NULL
);
620 WMSetTextFieldText(panel
->fileField
, item
->text
);
626 showError(WMScreen
*scr
, WMWindow
*owner
, char *s
, char *file
)
631 errStr
= wmalloc(strlen(file
)+strlen(s
));
632 sprintf(errStr
, s
, file
);
636 WMRunAlertPanel(scr
, owner
, "Error", errStr
, "OK", NULL
, NULL
);
642 createDir(WMButton
*bPre
, WMFilePanel
*panel
)
644 char *directory_name
;
649 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
650 WMInputPanel
*_panel
;
652 _panel
= WMCreateInputPanel(scr
, panel
->win
,
653 "Create Directory", "Enter directory name", "", "OK", "Cancel");
654 scr
->modalView
= W_VIEW(_panel
->win
);
655 WMMapWidget(_panel
->win
);
657 while (!_panel
->done
|| WMScreenPending(scr
)) {
659 WMNextEvent(scr
->display
, &event
);
660 WMHandleEvent(&event
);
664 if (_panel
->result
== WAPRDefault
)
665 directory_name
= WMGetTextFieldText(_panel
->text
);
667 WMDestroyInputPanel(_panel
);
671 WMDestroyInputPanel(_panel
);
673 directory
= getCurrentFileName(panel
);
675 char *s
= strrchr(directory
,'/');
679 if (directory_name
[0] == '/') {
682 while (s
= strstr(directory
,"//")) {
684 for (i
= 2;s
[i
] == '/';i
++);
687 if ((s
= strrchr(directory
, '/')) && !s
[1]) s
[0] = 0;
689 while (s
= strstr(directory_name
,"//")) {
691 for (i
= 2;s
[i
] == '/';i
++);
694 if ((s
= strrchr(directory_name
, '/')) && !s
[1]) s
[0] = 0;
696 file
= wmalloc(strlen(directory_name
)+strlen(directory
)+1);
697 sprintf(file
, "%s/%s", directory
, directory_name
);
698 while (s
= strstr(file
,"//")) {
700 for (i
= 2;s
[i
] == '/';i
++);
704 if (mkdir(file
,0xfff) != 0) {
707 showError(scr
, panel
->win
, "Permission denied.", NULL
);
710 showError(scr
, panel
->win
, "'%s' already existes.", file
);
713 showError(scr
, panel
->win
, "Path does not exist.", NULL
);
716 else WMSetFilePanelDirectory(panel
, file
);
718 free(directory_name
);
725 deleteFile(WMButton
*bPre
, WMFilePanel
*panel
)
730 struct stat filestat
;
731 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
733 file
= getCurrentFileName(panel
);
735 while (s
= strstr(file
,"//")) {
737 for (i
= 2;s
[i
] == '/';i
++);
740 if (strlen(file
) > 1 && (s
= strrchr(file
, '/')) && !s
[1]) s
[0] = 0;
742 if (stat(file
,&filestat
)) {
745 showError(scr
, panel
->win
, "'%s' does not exist.", file
);
748 showError(scr
, panel
->win
, "Permission denied.", NULL
);
751 showError(scr
, panel
->win
,
752 "Insufficient memory available.", NULL
);
755 showError(scr
, panel
->win
,
756 "'%s' is on a read-only filesystem.", file
);
759 showError(scr
, panel
->win
, "Can not delete '%s'.", file
);
763 } else if (S_ISDIR(filestat
.st_mode
)) {
764 buffer
= wmalloc(strlen(file
)+20);
765 sprintf(buffer
,"Delete directory %s ?",file
);
767 buffer
= wmalloc(strlen(file
)+15);
768 sprintf(buffer
,"Delete file %s ?",file
);
771 if (!WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
772 "Warning", buffer
, "OK", "Cancel", NULL
)) {
773 if (S_ISDIR(filestat
.st_mode
)) {
774 if (rmdir(file
) != 0) {
777 showError(scr
, panel
->win
, "Permission denied.", NULL
);
780 showError(scr
, panel
->win
, "Directory '%s' does not exist.", file
);
783 showError(scr
, panel
->win
, "Directory '%s' is not empty.", file
);
786 showError(scr
, panel
->win
, "Directory '%s' is busy.", file
);
789 showError(scr
, panel
->win
, "Can not delete '%s'.", file
);
792 char *s
= strrchr(file
,'/');
794 WMSetFilePanelDirectory(panel
, file
);
796 } else if (remove(file
) != 0) {
799 showError(scr
, panel
->win
, "'%s' is a directory.", file
);
802 showError(scr
, panel
->win
, "'%s' does not exist.", file
);
805 showError(scr
, panel
->win
, "Permission denied.", NULL
);
808 showError(scr
, panel
->win
,
809 "Insufficient memory available.", NULL
);
812 showError(scr
, panel
->win
,
813 "'%s' is on a read-only filesystem.", file
);
816 showError(scr
, panel
->win
, "Can not delete '%s'.", file
);
819 char *s
= strrchr(file
,'/');
821 WMSetFilePanelDirectory(panel
, file
);
829 goUnmount(WMButton
*bPtr
, WMFilePanel
*panel
)
835 goFloppy(WMButton
*bPtr
, WMFilePanel
*panel
)
837 char *file
, *err_str
;
838 struct stat filestat
;
839 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
842 if (stat(FLOPPY_PATH
,&filestat
)) {
843 showError(scr
, panel
->win
, "An error occured browsing '%s'.", file
);
845 } else if (!S_ISDIR(filestat
.st_mode
)) {
846 showError(scr
, panel
->win
, "'%s' is not a directory.", file
);
850 WMSetFilePanelDirectory(panel
, FLOPPY_PATH
);
855 goHome(WMButton
*bPtr
, WMFilePanel
*panel
)
859 /* home is statically allocated. Don't free it! */
860 home
= wgethomedir();
864 WMSetFilePanelDirectory(panel
, home
);
869 handleEvents(XEvent
*event
, void *data
)
871 W_FilePanel
*pPtr
= (W_FilePanel
*)data
;
872 W_View
*view
= WMWidgetView(pPtr
->win
);
874 if (event
->type
== ConfigureNotify
) {
875 if (event
->xconfigure
.width
!= view
->size
.width
876 || event
->xconfigure
.height
!= view
->size
.height
) {
877 unsigned int newWidth
= event
->xconfigure
.width
;
878 unsigned int newHeight
= event
->xconfigure
.height
;
881 W_ResizeView(view
, newWidth
, newHeight
);
882 WMResizeWidget(pPtr
->line
, newWidth
, 2);
883 WMResizeWidget(pPtr
->browser
, newWidth
-14,
884 newHeight
-(PHEIGHT
-200));
885 WMResizeWidget(pPtr
->fileField
, newWidth
-60-10, 24);
886 WMMoveWidget(pPtr
->nameLabel
, 7, newHeight
-(PHEIGHT
-282));
887 WMMoveWidget(pPtr
->fileField
, 60, newHeight
-(PHEIGHT
-278));
888 WMMoveWidget(pPtr
->okButton
, newWidth
-(PWIDTH
-245),
889 newHeight
-(PHEIGHT
-325));
890 WMMoveWidget(pPtr
->cancelButton
, newWidth
-(PWIDTH
-165),
891 newHeight
-(PHEIGHT
-325));
893 WMMoveWidget(pPtr
->trashcanButton
, 7, newHeight
-(PHEIGHT
-325));
894 WMMoveWidget(pPtr
->createDirButton
, 37, newHeight
-(PHEIGHT
-325));
895 WMMoveWidget(pPtr
->homeButton
, 67, newHeight
-(PHEIGHT
-325));
896 WMMoveWidget(pPtr
->disketteButton
, 97, newHeight
-(PHEIGHT
-325));
897 WMMoveWidget(pPtr
->unmountButton
, 127, newHeight
-(PHEIGHT
-325));
899 newColumnCount
= (newWidth
- 14) / 140;
900 WMSetBrowserMaxVisibleColumns(pPtr
->browser
, newColumnCount
);
907 getCurrentFileName(WMFilePanel
*panel
)
914 path
= WMGetBrowserPath(panel
->browser
);
917 if (path
[len
-1]=='/') {
918 file
= WMGetTextFieldText(panel
->fileField
);
919 tmp
= wmalloc(strlen(path
)+strlen(file
)+8);
937 validOpenFile(WMFilePanel
*panel
)
940 int col
, haveFile
= 0;
941 char *file
= WMGetTextFieldText(panel
->fileField
);
947 col
= WMGetBrowserSelectedColumn(panel
->browser
);
948 item
= WMGetBrowserSelectedItemInColumn(panel
->browser
, col
);
950 if (item
->isBranch
&& !panel
->flags
.canChooseDirectories
&& !haveFile
)
952 else if (!item
->isBranch
&& !panel
->flags
.canChooseFiles
)
957 /* we compute for / here */
958 if (!panel
->flags
.canChooseDirectories
&& !haveFile
)
969 buttonClick(WMButton
*bPtr
, WMFilePanel
*panel
)
973 if (bPtr
== panel
->okButton
) {
974 if (!validOpenFile(panel
))
976 if (panel
->flags
.fileMustExist
) {
979 file
= getCurrentFileName(panel
);
980 if (access(file
, F_OK
)!=0) {
981 WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
982 "Error", "File does not exist.",
989 panel
->flags
.canceled
= 0;
991 panel
->flags
.canceled
= 1;
993 range
.count
= range
.position
= 0;
994 WMSelectTextFieldRange(panel
->fileField
, range
);
995 panel
->flags
.done
= 1;