16 typedef struct W_FilePanel
{
28 WMButton
*cancelButton
;
31 WMButton
*trashcanButton
;
32 WMButton
*createDirButton
;
33 WMButton
*disketteButton
;
34 WMButton
*unmountButton
;
36 WMView
*accessoryView
;
38 WMTextField
*fileField
;
43 unsigned int canExit
:1;
44 unsigned int canceled
:1; /* clicked on cancel */
45 unsigned int filtered
:1;
46 unsigned int canChooseFiles
:1;
47 unsigned int canChooseDirectories
:1;
48 unsigned int autoCompletion
:1;
49 unsigned int showAllFiles
:1;
50 unsigned int canFreeFileTypes
:1;
51 unsigned int fileMustExist
:1;
52 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
,
71 static void deleteFile();
73 static void createDir();
77 static void goFloppy();
79 static void goUnmount();
81 static void buttonClick();
83 static char *getCurrentFileName(WMFilePanel
*panel
);
85 static void handleEvents(XEvent
*event
, void *data
);
89 static WMBrowserDelegate browserDelegate
= {
91 fillColumn
, /* createRowsForColumn */
92 NULL
, /* titleOfColumn */
99 closestListItem(WMList
*list
, char *text
, Bool exact
)
102 WMArray
*items
= WMGetListItems(list
);
103 int i
, len
= strlen(text
);
108 for(i
=0; i
<WMGetArrayItemCount(items
); i
++) {
109 item
= WMGetFromArray(items
, i
);
110 if (strlen(item
->text
) >= len
&&
111 ((exact
&& strcmp(item
->text
, text
)==0) ||
112 (!exact
&& strncmp(item
->text
, text
, len
)==0))) {
122 textChangedObserver(void *observerData
, WMNotification
*notification
)
124 W_FilePanel
*panel
= (W_FilePanel
*)observerData
;
127 int col
= WMGetBrowserNumberOfColumns(panel
->browser
) - 1;
130 if (!(list
= WMGetBrowserListInColumn(panel
->browser
, col
)))
133 text
= WMGetTextFieldText(panel
->fileField
);
134 textEvent
= (int)WMGetNotificationClientData(notification
);
136 if (panel
->flags
.autoCompletion
&& textEvent
!=WMDeleteTextEvent
)
137 i
= closestListItem(list
, text
, False
);
139 i
= closestListItem(list
, text
, True
);
141 WMSelectListItem(list
, i
);
142 if (i
>=0 && panel
->flags
.autoCompletion
) {
143 WMListItem
*item
= WMGetListItem(list
, i
);
144 int textLen
= strlen(text
), itemTextLen
= strlen(item
->text
);
145 int visibleItems
= WMWidgetHeight(list
)/WMGetListItemHeight(list
);
147 WMSetListPosition(list
, i
- visibleItems
/2);
149 if (textEvent
!=WMDeleteTextEvent
) {
152 WMInsertTextFieldText(panel
->fileField
, &item
->text
[textLen
],
154 range
.position
= textLen
;
155 range
.count
= itemTextLen
- textLen
;
156 WMSelectTextFieldRange(panel
->fileField
, range
);
157 /*WMSetTextFieldCursorPosition(panel->fileField, itemTextLen);*/
166 textEditedObserver(void *observerData
, WMNotification
*notification
)
168 W_FilePanel
*panel
= (W_FilePanel
*)observerData
;
170 if ((int)WMGetNotificationClientData(notification
)==WMReturnTextMovement
) {
171 WMPerformButtonClick(panel
->okButton
);
178 makeFilePanel(WMScreen
*scrPtr
, char *name
, char *title
)
184 fPtr
= wmalloc(sizeof(WMFilePanel
));
185 memset(fPtr
, 0, sizeof(WMFilePanel
));
187 fPtr
->win
= WMCreateWindowWithStyle(scrPtr
, name
, WMTitledWindowMask
188 |WMResizableWindowMask
);
189 WMResizeWidget(fPtr
->win
, PWIDTH
, PHEIGHT
);
190 WMSetWindowTitle(fPtr
->win
, "");
192 WMCreateEventHandler(WMWidgetView(fPtr
->win
), StructureNotifyMask
,
194 WMSetWindowMinSize(fPtr
->win
, PWIDTH
, PHEIGHT
);
197 fPtr
->iconLabel
= WMCreateLabel(fPtr
->win
);
198 WMResizeWidget(fPtr
->iconLabel
, 64, 64);
199 WMMoveWidget(fPtr
->iconLabel
, 0, 0);
200 WMSetLabelImagePosition(fPtr
->iconLabel
, WIPImageOnly
);
201 icon
= WMGetApplicationIconBlendedPixmap(scrPtr
, (RColor
*)NULL
);
203 WMSetLabelImage(fPtr
->iconLabel
, icon
);
204 WMReleasePixmap(icon
);
206 WMSetLabelImage(fPtr
->iconLabel
, scrPtr
->applicationIconPixmap
);
209 fPtr
->titleLabel
= WMCreateLabel(fPtr
->win
);
210 WMResizeWidget(fPtr
->titleLabel
, PWIDTH
-64, 64);
211 WMMoveWidget(fPtr
->titleLabel
, 64, 0);
212 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
213 WMSetLabelFont(fPtr
->titleLabel
, largeFont
);
214 WMReleaseFont(largeFont
);
215 WMSetLabelText(fPtr
->titleLabel
, title
);
217 fPtr
->line
= WMCreateFrame(fPtr
->win
);
218 WMMoveWidget(fPtr
->line
, 0, 64);
219 WMResizeWidget(fPtr
->line
, PWIDTH
, 2);
220 WMSetFrameRelief(fPtr
->line
, WRGroove
);
222 fPtr
->browser
= WMCreateBrowser(fPtr
->win
);
223 WMSetBrowserAllowEmptySelection(fPtr
->browser
, True
);
224 WMSetBrowserDelegate(fPtr
->browser
, &browserDelegate
);
225 WMSetBrowserAction(fPtr
->browser
, browserClick
, fPtr
);
226 WMSetBrowserDoubleAction(fPtr
->browser
, browserDClick
, fPtr
);
227 WMMoveWidget(fPtr
->browser
, 7, 72);
228 WMResizeWidget(fPtr
->browser
, PWIDTH
-14,200);
229 WMHangData(fPtr
->browser
, fPtr
);
231 fPtr
->nameLabel
= WMCreateLabel(fPtr
->win
);
232 WMMoveWidget(fPtr
->nameLabel
, 7, 282);
233 WMResizeWidget(fPtr
->nameLabel
, 55, 14);
234 WMSetLabelText(fPtr
->nameLabel
, "Name:");
236 fPtr
->fileField
= WMCreateTextField(fPtr
->win
);
237 WMMoveWidget(fPtr
->fileField
, 60, 278);
238 WMResizeWidget(fPtr
->fileField
, PWIDTH
-60-10, 24);
239 WMAddNotificationObserver(textEditedObserver
, fPtr
,
240 WMTextDidEndEditingNotification
,
242 WMAddNotificationObserver(textChangedObserver
, fPtr
,
243 WMTextDidChangeNotification
,
246 fPtr
->okButton
= WMCreateCommandButton(fPtr
->win
);
247 WMMoveWidget(fPtr
->okButton
, 245, 325);
248 WMResizeWidget(fPtr
->okButton
, 75, 28);
249 WMSetButtonText(fPtr
->okButton
, "OK");
250 WMSetButtonImage(fPtr
->okButton
, scrPtr
->buttonArrow
);
251 WMSetButtonAltImage(fPtr
->okButton
, scrPtr
->pushedButtonArrow
);
252 WMSetButtonImagePosition(fPtr
->okButton
, WIPRight
);
253 WMSetButtonAction(fPtr
->okButton
, buttonClick
, fPtr
);
255 fPtr
->cancelButton
= WMCreateCommandButton(fPtr
->win
);
256 WMMoveWidget(fPtr
->cancelButton
, 165, 325);
257 WMResizeWidget(fPtr
->cancelButton
, 75, 28);
258 WMSetButtonText(fPtr
->cancelButton
, "Cancel");
259 WMSetButtonAction(fPtr
->cancelButton
, buttonClick
, fPtr
);
261 fPtr
->trashcanButton
= WMCreateCommandButton(fPtr
->win
);
262 WMMoveWidget(fPtr
->trashcanButton
, 7, 325);
263 WMResizeWidget(fPtr
->trashcanButton
, 28, 28);
264 WMSetButtonImagePosition(fPtr
->trashcanButton
, WIPImageOnly
);
265 WMSetButtonImage(fPtr
->trashcanButton
, scrPtr
->trashcanIcon
);
266 WMSetButtonAltImage(fPtr
->trashcanButton
, scrPtr
->altTrashcanIcon
);
267 WMSetButtonAction(fPtr
->trashcanButton
, deleteFile
, fPtr
);
269 fPtr
->createDirButton
= WMCreateCommandButton(fPtr
->win
);
270 WMMoveWidget(fPtr
->createDirButton
, 37, 325);
271 WMResizeWidget(fPtr
->createDirButton
, 28, 28);
272 WMSetButtonImagePosition(fPtr
->createDirButton
, WIPImageOnly
);
273 WMSetButtonImage(fPtr
->createDirButton
, scrPtr
->createDirIcon
);
274 WMSetButtonAltImage(fPtr
->createDirButton
, scrPtr
->altCreateDirIcon
);
275 WMSetButtonAction(fPtr
->createDirButton
, createDir
, fPtr
);
277 fPtr
->homeButton
= WMCreateCommandButton(fPtr
->win
);
278 WMMoveWidget(fPtr
->homeButton
, 67, 325);
279 WMResizeWidget(fPtr
->homeButton
, 28, 28);
280 WMSetButtonImagePosition(fPtr
->homeButton
, WIPImageOnly
);
281 WMSetButtonImage(fPtr
->homeButton
, scrPtr
->homeIcon
);
282 WMSetButtonAltImage(fPtr
->homeButton
, scrPtr
->altHomeIcon
);
283 WMSetButtonAction(fPtr
->homeButton
, goHome
, fPtr
);
285 fPtr
->disketteButton
= WMCreateCommandButton(fPtr
->win
);
286 WMMoveWidget(fPtr
->disketteButton
, 97, 325);
287 WMResizeWidget(fPtr
->disketteButton
, 28, 28);
288 WMSetButtonImagePosition(fPtr
->disketteButton
, WIPImageOnly
);
289 WMSetButtonImage(fPtr
->disketteButton
, scrPtr
->disketteIcon
);
290 WMSetButtonAltImage(fPtr
->disketteButton
, scrPtr
->altDisketteIcon
);
291 WMSetButtonAction(fPtr
->disketteButton
, goFloppy
, fPtr
);
293 fPtr
->unmountButton
= WMCreateCommandButton(fPtr
->win
);
294 WMMoveWidget(fPtr
->unmountButton
, 127, 325);
295 WMResizeWidget(fPtr
->unmountButton
, 28, 28);
296 WMSetButtonImagePosition(fPtr
->unmountButton
, WIPImageOnly
);
297 WMSetButtonImage(fPtr
->unmountButton
, scrPtr
->unmountIcon
);
298 WMSetButtonAltImage(fPtr
->unmountButton
, scrPtr
->altUnmountIcon
);
299 WMSetButtonAction(fPtr
->unmountButton
, goUnmount
, fPtr
);
300 WMSetButtonEnabled(fPtr
->unmountButton
, False
);
303 WMRealizeWidget(fPtr
->win
);
304 WMMapSubwidgets(fPtr
->win
);
306 WMSetFocusToWidget(fPtr
->fileField
);
307 WMSetTextFieldCursorPosition(fPtr
->fileField
, 0);
309 WMLoadBrowserColumnZero(fPtr
->browser
);
311 WMSetWindowInitialPosition(fPtr
->win
,
312 (scrPtr
->rootView
->size
.width
- WMWidgetWidth(fPtr
->win
))/2,
313 (scrPtr
->rootView
->size
.height
- WMWidgetHeight(fPtr
->win
))/2);
315 fPtr
->flags
.canChooseFiles
= 1;
316 fPtr
->flags
.canChooseDirectories
= 1;
317 fPtr
->flags
.autoCompletion
= 1;
324 WMGetOpenPanel(WMScreen
*scrPtr
)
328 if (scrPtr
->sharedOpenPanel
)
329 return scrPtr
->sharedOpenPanel
;
331 panel
= makeFilePanel(scrPtr
, "openFilePanel", "Open");
332 panel
->flags
.fileMustExist
= 1;
333 panel
->flags
.panelType
= WP_OPEN
;
335 scrPtr
->sharedOpenPanel
= panel
;
342 WMGetSavePanel(WMScreen
*scrPtr
)
346 if (scrPtr
->sharedSavePanel
)
347 return scrPtr
->sharedSavePanel
;
349 panel
= makeFilePanel(scrPtr
, "saveFilePanel", "Save");
350 panel
->flags
.fileMustExist
= 0;
351 panel
->flags
.panelType
= WP_SAVE
;
353 scrPtr
->sharedSavePanel
= panel
;
360 WMFreeFilePanel(WMFilePanel
*panel
)
362 if (panel
== WMWidgetScreen(panel
->win
)->sharedSavePanel
) {
363 WMWidgetScreen(panel
->win
)->sharedSavePanel
= NULL
;
365 if (panel
== WMWidgetScreen(panel
->win
)->sharedOpenPanel
) {
366 WMWidgetScreen(panel
->win
)->sharedOpenPanel
= NULL
;
368 WMRemoveNotificationObserver(panel
);
369 WMUnmapWidget(panel
->win
);
370 WMDestroyWidget(panel
->win
);
376 WMRunModalFilePanelForDirectory(WMFilePanel
*panel
, WMWindow
*owner
,
377 char *path
, char *name
, char **fileTypes
)
379 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
381 if (name
&& !owner
) {
382 WMSetWindowTitle(panel
->win
, name
);
385 WMChangePanelOwner(panel
->win
, owner
);
387 WMSetFilePanelDirectory(panel
, path
);
389 switch(panel
->flags
.panelType
) {
392 panel
->flags
.filtered
= 1;
393 panel
->fileTypes
= fileTypes
;
398 panel
->fileTypes
= NULL
;
399 panel
->flags
.filtered
= 0;
407 WMSetLabelText(panel
->titleLabel
, name
);
409 WMMapWidget(panel
->win
);
411 WMRunModalLoop(scr
, W_VIEW(panel
->win
));
413 /* Must withdraw window because the next time we map
414 * it, it might have a different transient owner.
416 WMCloseWindow(panel
->win
);
418 return (panel
->flags
.canceled
? False
: True
);
425 WMSetFilePanelDirectory(WMFilePanel
*panel
, char *path
)
432 rest
= WMSetBrowserPath(panel
->browser
, path
);
433 if (strcmp(path
, "/")==0)
436 col
= WMGetBrowserSelectedColumn(panel
->browser
);
437 list
= WMGetBrowserListInColumn(panel
->browser
, col
);
438 if (list
&& (item
= WMGetListSelectedItem(list
))) {
439 if (item
->isBranch
) {
440 WMSetTextFieldText(panel
->fileField
, rest
);
442 WMSetTextFieldText(panel
->fileField
, item
->text
);
445 WMSetTextFieldText(panel
->fileField
, rest
);
451 WMSetFilePanelCanChooseDirectories(WMFilePanel
*panel
, Bool flag
)
453 panel
->flags
.canChooseDirectories
= flag
;
457 WMSetFilePanelCanChooseFiles(WMFilePanel
*panel
, Bool flag
)
459 panel
->flags
.canChooseFiles
= flag
;
464 WMSetFilePanelAutoCompletion(WMFilePanel
*panel
, Bool flag
)
466 panel
->flags
.autoCompletion
= flag
;
471 WMGetFilePanelFileName(WMFilePanel
*panel
)
473 return getCurrentFileName(panel
);
478 WMSetFilePanelAccessoryView(WMFilePanel
*panel
, WMView
*view
)
482 panel
->accessoryView
= view
;
484 v
= WMWidgetView(panel
->win
);
486 W_ReparentView(view
, v
, 0, 0);
488 W_MoveView(view
, (v
->size
.width
- v
->size
.width
)/2, 300);
493 WMGetFilePanelAccessoryView(WMFilePanel
*panel
)
495 return panel
->accessoryView
;
500 get_name_from_path(char *path
)
508 /* remove trailing / */
509 while (size
> 0 && path
[size
-1]=='/')
511 /* directory was root */
515 while (size
> 0 && path
[size
-1] != '/')
518 return wstrdup(&(path
[size
]));
523 filterFileName(WMFilePanel
*panel
, char *file
, Bool isDirectory
)
529 #define CAST(item) (*((WMListItem**)item))
531 comparer(const void *a
, const void *b
)
533 if (CAST(a
)->isBranch
== CAST(b
)->isBranch
)
534 return (strcmp(CAST(a
)->text
, CAST(b
)->text
));
535 if (CAST(a
)->isBranch
)
543 listDirectoryOnColumn(WMFilePanel
*panel
, int column
, char *path
)
545 WMBrowser
*bPtr
= panel
->browser
;
546 struct dirent
*dentry
;
548 struct stat stat_buf
;
549 char pbuf
[PATH_MAX
+16];
552 assert(path
!= NULL
);
554 /* put directory name in the title */
555 WMSetBrowserColumnTitle(bPtr
, column
, get_name_from_path(path
));
561 printf("WINGs: could not open directory %s\n", path
);
566 /* list contents in the column */
567 while ((dentry
= readdir(dir
))) {
568 if (strcmp(dentry
->d_name
, ".")==0 ||
569 strcmp(dentry
->d_name
, "..")==0)
573 if (strcmp(path
, "/")!=0)
575 strcat(pbuf
, dentry
->d_name
);
577 if (stat(pbuf
, &stat_buf
)!=0) {
579 printf("WINGs: could not stat %s\n", pbuf
);
585 isDirectory
= S_ISDIR(stat_buf
.st_mode
);
587 if (filterFileName(panel
, dentry
->d_name
, isDirectory
))
588 WMInsertBrowserItem(bPtr
, column
, -1, dentry
->d_name
, isDirectory
);
591 WMSortBrowserColumnWithComparer(bPtr
, column
, comparer
);
598 fillColumn(WMBrowserDelegate
*self
, WMBrowser
*bPtr
, int column
, WMList
*list
)
604 path
= WMGetBrowserPathToColumn(bPtr
, column
-1);
609 panel
= WMGetHangedData(bPtr
);
610 listDirectoryOnColumn(panel
, column
, path
);
616 browserDClick(WMBrowser
*bPtr
, WMFilePanel
*panel
)
618 WMPerformButtonClick(panel
->okButton
);
622 browserClick(WMBrowser
*bPtr
, WMFilePanel
*panel
)
624 int col
= WMGetBrowserSelectedColumn(bPtr
);
625 WMListItem
*item
= WMGetBrowserSelectedItemInColumn(bPtr
, col
);
627 if (!item
|| item
->isBranch
)
628 WMSetTextFieldText(panel
->fileField
, NULL
);
630 WMSetTextFieldText(panel
->fileField
, item
->text
);
636 showError(WMScreen
*scr
, WMWindow
*owner
, char *s
, char *file
)
641 errStr
= wmalloc(strlen(file
)+strlen(s
));
642 sprintf(errStr
, s
, file
);
646 WMRunAlertPanel(scr
, owner
, "Error", errStr
, "OK", NULL
, NULL
);
652 createDir(WMButton
*bPre
, WMFilePanel
*panel
)
654 char *dirName
, *directory
, *file
, *s
;
655 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
657 dirName
= WMRunInputPanel(scr
, panel
->win
, "Create Directory",
658 "Enter directory name", "", "OK", "Cancel");
662 directory
= getCurrentFileName(panel
);
663 s
= strrchr(directory
,'/');
666 if (dirName
[0] == '/') {
669 while ((s
= strstr(directory
,"//"))) {
671 for (i
= 2;s
[i
] == '/';i
++);
674 if ((s
= strrchr(directory
, '/')) && !s
[1]) s
[0] = 0;
676 while ((s
= strstr(dirName
,"//"))) {
678 for (i
= 2;s
[i
] == '/';i
++);
681 if ((s
= strrchr(dirName
, '/')) && !s
[1]) s
[0] = 0;
683 file
= wmalloc(strlen(dirName
)+strlen(directory
)+1);
684 sprintf(file
, "%s/%s", directory
, dirName
);
685 while ((s
= strstr(file
,"//"))) {
687 for (i
= 2;s
[i
] == '/';i
++);
691 if (mkdir(file
,0xfff) != 0) {
694 showError(scr
, panel
->win
, "Permission denied.", NULL
);
697 showError(scr
, panel
->win
, "'%s' already existes.", file
);
700 showError(scr
, panel
->win
, "Path does not exist.", NULL
);
703 else WMSetFilePanelDirectory(panel
, file
);
711 deleteFile(WMButton
*bPre
, WMFilePanel
*panel
)
715 struct stat filestat
;
716 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
718 file
= getCurrentFileName(panel
);
720 while ((s
= strstr(file
,"//"))) {
722 for (i
= 2;s
[i
] == '/';i
++);
725 if (strlen(file
) > 1 && (s
= strrchr(file
, '/')) && !s
[1]) s
[0] = 0;
727 if (stat(file
,&filestat
)) {
730 showError(scr
, panel
->win
, "'%s' does not exist.", file
);
733 showError(scr
, panel
->win
, "Permission denied.", NULL
);
736 showError(scr
, panel
->win
,
737 "Insufficient memory available.", NULL
);
740 showError(scr
, panel
->win
,
741 "'%s' is on a read-only filesystem.", file
);
744 showError(scr
, panel
->win
, "Can not delete '%s'.", file
);
748 } else if (S_ISDIR(filestat
.st_mode
)) {
749 buffer
= wmalloc(strlen(file
)+20);
750 sprintf(buffer
,"Delete directory %s ?",file
);
752 buffer
= wmalloc(strlen(file
)+15);
753 sprintf(buffer
,"Delete file %s ?",file
);
756 if (!WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
757 "Warning", buffer
, "OK", "Cancel", NULL
)) {
758 if (S_ISDIR(filestat
.st_mode
)) {
759 if (rmdir(file
) != 0) {
762 showError(scr
, panel
->win
, "Permission denied.", NULL
);
765 showError(scr
, panel
->win
, "Directory '%s' does not exist.", file
);
768 showError(scr
, panel
->win
, "Directory '%s' is not empty.", file
);
771 showError(scr
, panel
->win
, "Directory '%s' is busy.", file
);
774 showError(scr
, panel
->win
, "Can not delete '%s'.", file
);
777 char *s
= strrchr(file
,'/');
779 WMSetFilePanelDirectory(panel
, file
);
781 } else if (remove(file
) != 0) {
784 showError(scr
, panel
->win
, "'%s' is a directory.", file
);
787 showError(scr
, panel
->win
, "'%s' does not exist.", file
);
790 showError(scr
, panel
->win
, "Permission denied.", NULL
);
793 showError(scr
, panel
->win
,
794 "Insufficient memory available.", NULL
);
797 showError(scr
, panel
->win
,
798 "'%s' is on a read-only filesystem.", file
);
801 showError(scr
, panel
->win
, "Can not delete '%s'.", file
);
804 char *s
= strrchr(file
,'/');
806 WMSetFilePanelDirectory(panel
, file
);
814 goUnmount(WMButton
*bPtr
, WMFilePanel
*panel
)
820 goFloppy(WMButton
*bPtr
, WMFilePanel
*panel
)
822 struct stat filestat
;
823 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
825 if (stat(WINGsConfiguration
.floppyPath
, &filestat
)) {
826 showError(scr
, panel
->win
, "An error occured browsing '%s'.",
827 WINGsConfiguration
.floppyPath
);
829 } else if (!S_ISDIR(filestat
.st_mode
)) {
830 showError(scr
, panel
->win
, "'%s' is not a directory.",
831 WINGsConfiguration
.floppyPath
);
835 WMSetFilePanelDirectory(panel
, WINGsConfiguration
.floppyPath
);
840 goHome(WMButton
*bPtr
, WMFilePanel
*panel
)
844 /* home is statically allocated. Don't free it! */
845 home
= wgethomedir();
849 WMSetFilePanelDirectory(panel
, home
);
854 handleEvents(XEvent
*event
, void *data
)
856 W_FilePanel
*pPtr
= (W_FilePanel
*)data
;
857 W_View
*view
= WMWidgetView(pPtr
->win
);
859 if (event
->type
== ConfigureNotify
) {
860 if (event
->xconfigure
.width
!= view
->size
.width
861 || event
->xconfigure
.height
!= view
->size
.height
) {
862 unsigned int newWidth
= event
->xconfigure
.width
;
863 unsigned int newHeight
= event
->xconfigure
.height
;
866 W_ResizeView(view
, newWidth
, newHeight
);
867 WMResizeWidget(pPtr
->line
, newWidth
, 2);
868 WMResizeWidget(pPtr
->browser
, newWidth
-14,
869 newHeight
-(PHEIGHT
-200));
870 WMResizeWidget(pPtr
->fileField
, newWidth
-60-10, 24);
871 WMMoveWidget(pPtr
->nameLabel
, 7, newHeight
-(PHEIGHT
-282));
872 WMMoveWidget(pPtr
->fileField
, 60, newHeight
-(PHEIGHT
-278));
873 WMMoveWidget(pPtr
->okButton
, newWidth
-(PWIDTH
-245),
874 newHeight
-(PHEIGHT
-325));
875 WMMoveWidget(pPtr
->cancelButton
, newWidth
-(PWIDTH
-165),
876 newHeight
-(PHEIGHT
-325));
878 WMMoveWidget(pPtr
->trashcanButton
, 7, newHeight
-(PHEIGHT
-325));
879 WMMoveWidget(pPtr
->createDirButton
, 37, newHeight
-(PHEIGHT
-325));
880 WMMoveWidget(pPtr
->homeButton
, 67, newHeight
-(PHEIGHT
-325));
881 WMMoveWidget(pPtr
->disketteButton
, 97, newHeight
-(PHEIGHT
-325));
882 WMMoveWidget(pPtr
->unmountButton
, 127, newHeight
-(PHEIGHT
-325));
884 newColumnCount
= (newWidth
- 14) / 140;
885 WMSetBrowserMaxVisibleColumns(pPtr
->browser
, newColumnCount
);
892 getCurrentFileName(WMFilePanel
*panel
)
899 path
= WMGetBrowserPath(panel
->browser
);
902 if (path
[len
-1]=='/') {
903 file
= WMGetTextFieldText(panel
->fileField
);
904 tmp
= wmalloc(strlen(path
)+strlen(file
)+8);
922 validOpenFile(WMFilePanel
*panel
)
925 int col
, haveFile
= 0;
926 char *file
= WMGetTextFieldText(panel
->fileField
);
932 col
= WMGetBrowserSelectedColumn(panel
->browser
);
933 item
= WMGetBrowserSelectedItemInColumn(panel
->browser
, col
);
935 if (item
->isBranch
&& !panel
->flags
.canChooseDirectories
&& !haveFile
)
937 else if (!item
->isBranch
&& !panel
->flags
.canChooseFiles
)
942 /* we compute for / here */
943 if (!panel
->flags
.canChooseDirectories
&& !haveFile
)
954 buttonClick(WMButton
*bPtr
, WMFilePanel
*panel
)
958 if (bPtr
== panel
->okButton
) {
959 if (!validOpenFile(panel
))
961 if (panel
->flags
.fileMustExist
) {
964 file
= getCurrentFileName(panel
);
965 if (access(file
, F_OK
)!=0) {
966 WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
967 "Error", "File does not exist.",
974 panel
->flags
.canceled
= 0;
976 panel
->flags
.canceled
= 1;
978 range
.count
= range
.position
= 0;
979 WMSelectTextFieldRange(panel
->fileField
, range
);
980 WMBreakModalLoop(WMWidgetScreen(bPtr
));