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 */
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 WMBag
*items
= WMGetListItems(list
);
105 int len
= strlen(text
);
110 WM_ITERATE_BAG(items
, item
, i
) {
111 if (strlen(item
->text
) >= len
&&
112 ((exact
&& strcmp(item
->text
, text
)==0) ||
113 (!exact
&& strncmp(item
->text
, text
, len
)==0))) {
114 return WMBagIndexForIterator(items
, i
);
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
)
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 WMSetLabelImage(fPtr
->iconLabel
, scrPtr
->applicationIcon
);
203 fPtr
->titleLabel
= WMCreateLabel(fPtr
->win
);
204 WMResizeWidget(fPtr
->titleLabel
, PWIDTH
-64, 64);
205 WMMoveWidget(fPtr
->titleLabel
, 64, 0);
206 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
207 WMSetLabelFont(fPtr
->titleLabel
, largeFont
);
208 WMReleaseFont(largeFont
);
209 WMSetLabelText(fPtr
->titleLabel
, title
);
211 fPtr
->line
= WMCreateFrame(fPtr
->win
);
212 WMMoveWidget(fPtr
->line
, 0, 64);
213 WMResizeWidget(fPtr
->line
, PWIDTH
, 2);
214 WMSetFrameRelief(fPtr
->line
, WRGroove
);
216 fPtr
->browser
= WMCreateBrowser(fPtr
->win
);
217 WMSetBrowserDelegate(fPtr
->browser
, &browserDelegate
);
218 WMSetBrowserAction(fPtr
->browser
, browserClick
, fPtr
);
219 WMSetBrowserDoubleAction(fPtr
->browser
, browserDClick
, fPtr
);
220 WMMoveWidget(fPtr
->browser
, 7, 72);
221 WMResizeWidget(fPtr
->browser
, PWIDTH
-14,200);
222 WMHangData(fPtr
->browser
, fPtr
);
224 fPtr
->nameLabel
= WMCreateLabel(fPtr
->win
);
225 WMMoveWidget(fPtr
->nameLabel
, 7, 282);
226 WMResizeWidget(fPtr
->nameLabel
, 55, 14);
227 WMSetLabelText(fPtr
->nameLabel
, "Name:");
229 fPtr
->fileField
= WMCreateTextField(fPtr
->win
);
230 WMMoveWidget(fPtr
->fileField
, 60, 278);
231 WMResizeWidget(fPtr
->fileField
, PWIDTH
-60-10, 24);
232 WMAddNotificationObserver(textEditedObserver
, fPtr
,
233 WMTextDidEndEditingNotification
,
235 WMAddNotificationObserver(textChangedObserver
, fPtr
,
236 WMTextDidChangeNotification
,
239 fPtr
->okButton
= WMCreateCommandButton(fPtr
->win
);
240 WMMoveWidget(fPtr
->okButton
, 245, 325);
241 WMResizeWidget(fPtr
->okButton
, 75, 28);
242 WMSetButtonText(fPtr
->okButton
, "OK");
243 WMSetButtonImage(fPtr
->okButton
, scrPtr
->buttonArrow
);
244 WMSetButtonAltImage(fPtr
->okButton
, scrPtr
->pushedButtonArrow
);
245 WMSetButtonImagePosition(fPtr
->okButton
, WIPRight
);
246 WMSetButtonAction(fPtr
->okButton
, buttonClick
, fPtr
);
248 fPtr
->cancelButton
= WMCreateCommandButton(fPtr
->win
);
249 WMMoveWidget(fPtr
->cancelButton
, 165, 325);
250 WMResizeWidget(fPtr
->cancelButton
, 75, 28);
251 WMSetButtonText(fPtr
->cancelButton
, "Cancel");
252 WMSetButtonAction(fPtr
->cancelButton
, buttonClick
, fPtr
);
254 fPtr
->trashcanButton
= WMCreateCommandButton(fPtr
->win
);
255 WMMoveWidget(fPtr
->trashcanButton
, 7, 325);
256 WMResizeWidget(fPtr
->trashcanButton
, 28, 28);
257 WMSetButtonImagePosition(fPtr
->trashcanButton
, WIPImageOnly
);
258 WMSetButtonImage(fPtr
->trashcanButton
, scrPtr
->trashcanIcon
);
259 WMSetButtonAltImage(fPtr
->trashcanButton
, scrPtr
->altTrashcanIcon
);
260 WMSetButtonAction(fPtr
->trashcanButton
, deleteFile
, fPtr
);
262 fPtr
->createDirButton
= WMCreateCommandButton(fPtr
->win
);
263 WMMoveWidget(fPtr
->createDirButton
, 37, 325);
264 WMResizeWidget(fPtr
->createDirButton
, 28, 28);
265 WMSetButtonImagePosition(fPtr
->createDirButton
, WIPImageOnly
);
266 WMSetButtonImage(fPtr
->createDirButton
, scrPtr
->createDirIcon
);
267 WMSetButtonAltImage(fPtr
->createDirButton
, scrPtr
->altCreateDirIcon
);
268 WMSetButtonAction(fPtr
->createDirButton
, createDir
, fPtr
);
270 fPtr
->homeButton
= WMCreateCommandButton(fPtr
->win
);
271 WMMoveWidget(fPtr
->homeButton
, 67, 325);
272 WMResizeWidget(fPtr
->homeButton
, 28, 28);
273 WMSetButtonImagePosition(fPtr
->homeButton
, WIPImageOnly
);
274 WMSetButtonImage(fPtr
->homeButton
, scrPtr
->homeIcon
);
275 WMSetButtonAltImage(fPtr
->homeButton
, scrPtr
->altHomeIcon
);
276 WMSetButtonAction(fPtr
->homeButton
, goHome
, fPtr
);
278 fPtr
->disketteButton
= WMCreateCommandButton(fPtr
->win
);
279 WMMoveWidget(fPtr
->disketteButton
, 97, 325);
280 WMResizeWidget(fPtr
->disketteButton
, 28, 28);
281 WMSetButtonImagePosition(fPtr
->disketteButton
, WIPImageOnly
);
282 WMSetButtonImage(fPtr
->disketteButton
, scrPtr
->disketteIcon
);
283 WMSetButtonAltImage(fPtr
->disketteButton
, scrPtr
->altDisketteIcon
);
284 WMSetButtonAction(fPtr
->disketteButton
, goFloppy
, fPtr
);
286 fPtr
->unmountButton
= WMCreateCommandButton(fPtr
->win
);
287 WMMoveWidget(fPtr
->unmountButton
, 127, 325);
288 WMResizeWidget(fPtr
->unmountButton
, 28, 28);
289 WMSetButtonImagePosition(fPtr
->unmountButton
, WIPImageOnly
);
290 WMSetButtonImage(fPtr
->unmountButton
, scrPtr
->unmountIcon
);
291 WMSetButtonAltImage(fPtr
->unmountButton
, scrPtr
->altUnmountIcon
);
292 WMSetButtonAction(fPtr
->unmountButton
, goUnmount
, fPtr
);
293 WMSetButtonEnabled(fPtr
->unmountButton
, False
);
296 WMRealizeWidget(fPtr
->win
);
297 WMMapSubwidgets(fPtr
->win
);
299 WMSetFocusToWidget(fPtr
->fileField
);
300 WMSetTextFieldCursorPosition(fPtr
->fileField
, 0);
302 WMLoadBrowserColumnZero(fPtr
->browser
);
304 WMSetWindowInitialPosition(fPtr
->win
,
305 (scrPtr
->rootView
->size
.width
- WMWidgetWidth(fPtr
->win
))/2,
306 (scrPtr
->rootView
->size
.height
- WMWidgetHeight(fPtr
->win
))/2);
308 fPtr
->flags
.canChooseFiles
= 1;
309 fPtr
->flags
.canChooseDirectories
= 1;
310 fPtr
->flags
.autoCompletion
= 1;
317 WMGetOpenPanel(WMScreen
*scrPtr
)
321 if (scrPtr
->sharedOpenPanel
)
322 return scrPtr
->sharedOpenPanel
;
324 panel
= makeFilePanel(scrPtr
, "openFilePanel", "Open");
325 panel
->flags
.fileMustExist
= 1;
326 panel
->flags
.panelType
= WP_OPEN
;
328 scrPtr
->sharedOpenPanel
= panel
;
335 WMGetSavePanel(WMScreen
*scrPtr
)
339 if (scrPtr
->sharedSavePanel
)
340 return scrPtr
->sharedSavePanel
;
342 panel
= makeFilePanel(scrPtr
, "saveFilePanel", "Save");
343 panel
->flags
.fileMustExist
= 0;
344 panel
->flags
.panelType
= WP_SAVE
;
346 scrPtr
->sharedSavePanel
= panel
;
353 WMFreeFilePanel(WMFilePanel
*panel
)
355 if (panel
== WMWidgetScreen(panel
->win
)->sharedSavePanel
) {
356 WMWidgetScreen(panel
->win
)->sharedSavePanel
= NULL
;
358 if (panel
== WMWidgetScreen(panel
->win
)->sharedOpenPanel
) {
359 WMWidgetScreen(panel
->win
)->sharedOpenPanel
= NULL
;
361 WMRemoveNotificationObserver(panel
);
362 WMUnmapWidget(panel
->win
);
363 WMDestroyWidget(panel
->win
);
369 WMRunModalFilePanelForDirectory(WMFilePanel
*panel
, WMWindow
*owner
,
370 char *path
, char *name
, char **fileTypes
)
372 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
375 if (name
&& !owner
) {
376 WMSetWindowTitle(panel
->win
, name
);
379 WMChangePanelOwner(panel
->win
, owner
);
381 WMSetFilePanelDirectory(panel
, path
);
383 panel
->flags
.done
= 0;
384 switch(panel
->flags
.panelType
) {
387 panel
->flags
.filtered
= 1;
388 panel
->fileTypes
= fileTypes
;
393 panel
->fileTypes
= NULL
;
394 panel
->flags
.filtered
= 0;
402 WMSetLabelText(panel
->titleLabel
, name
);
404 scr
->modalView
= W_VIEW(panel
->win
);
405 WMMapWidget(panel
->win
);
408 while (!panel
->flags
.done
) {
409 WMNextEvent(scr
->display
, &event
);
410 WMHandleEvent(&event
);
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
;
458 WMSetFilePanelCanChooseFiles(WMFilePanel
*panel
, Bool flag
)
460 panel
->flags
.canChooseFiles
= flag
;
465 WMSetFilePanelAutoCompletion(WMFilePanel
*panel
, Bool flag
)
467 panel
->flags
.autoCompletion
= flag
;
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];
553 assert(path
!= NULL
);
555 /* put directory name in the title */
556 WMSetBrowserColumnTitle(bPtr
, column
, get_name_from_path(path
));
562 printf("WINGs: could not open directory %s\n", path
);
567 /* list contents in the column */
568 while ((dentry
= readdir(dir
))) {
569 if (strcmp(dentry
->d_name
, ".")==0 ||
570 strcmp(dentry
->d_name
, "..")==0)
574 if (strcmp(path
, "/")!=0)
576 strcat(pbuf
, dentry
->d_name
);
578 if (stat(pbuf
, &stat_buf
)!=0) {
580 printf("WINGs: could not stat %s\n", pbuf
);
586 isDirectory
= S_ISDIR(stat_buf
.st_mode
);
588 if (filterFileName(panel
, dentry
->d_name
, isDirectory
))
589 WMInsertBrowserItem(bPtr
, column
, -1, dentry
->d_name
, isDirectory
);
592 WMSortBrowserColumnWithComparer(bPtr
, column
, comparer
);
599 fillColumn(WMBrowserDelegate
*self
, WMBrowser
*bPtr
, int column
, WMList
*list
)
605 path
= WMGetBrowserPathToColumn(bPtr
, column
-1);
610 panel
= WMGetHangedData(bPtr
);
611 listDirectoryOnColumn(panel
, column
, path
);
617 browserDClick(WMBrowser
*bPtr
, WMFilePanel
*panel
)
619 WMPerformButtonClick(panel
->okButton
);
623 browserClick(WMBrowser
*bPtr
, WMFilePanel
*panel
)
625 int col
= WMGetBrowserSelectedColumn(bPtr
);
626 WMListItem
*item
= WMGetBrowserSelectedItemInColumn(bPtr
, col
);
628 if (!item
|| item
->isBranch
)
629 WMSetTextFieldText(panel
->fileField
, NULL
);
631 WMSetTextFieldText(panel
->fileField
, item
->text
);
637 showError(WMScreen
*scr
, WMWindow
*owner
, char *s
, char *file
)
642 errStr
= wmalloc(strlen(file
)+strlen(s
));
643 sprintf(errStr
, s
, file
);
647 WMRunAlertPanel(scr
, owner
, "Error", errStr
, "OK", NULL
, NULL
);
653 createDir(WMButton
*bPre
, WMFilePanel
*panel
)
655 char *directory_name
;
659 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
660 WMInputPanel
*_panel
;
662 _panel
= WMCreateInputPanel(scr
, panel
->win
,
663 "Create Directory", "Enter directory name", "", "OK", "Cancel");
664 scr
->modalView
= W_VIEW(_panel
->win
);
665 WMMapWidget(_panel
->win
);
667 while (!_panel
->done
|| WMScreenPending(scr
)) {
669 WMNextEvent(scr
->display
, &event
);
670 WMHandleEvent(&event
);
674 if (_panel
->result
== WAPRDefault
)
675 directory_name
= WMGetTextFieldText(_panel
->text
);
677 WMDestroyInputPanel(_panel
);
681 WMDestroyInputPanel(_panel
);
683 directory
= getCurrentFileName(panel
);
685 char *s
= strrchr(directory
,'/');
689 if (directory_name
[0] == '/') {
692 while ((s
= strstr(directory
,"//"))) {
694 for (i
= 2;s
[i
] == '/';i
++);
697 if ((s
= strrchr(directory
, '/')) && !s
[1]) s
[0] = 0;
699 while ((s
= strstr(directory_name
,"//"))) {
701 for (i
= 2;s
[i
] == '/';i
++);
704 if ((s
= strrchr(directory_name
, '/')) && !s
[1]) s
[0] = 0;
706 file
= wmalloc(strlen(directory_name
)+strlen(directory
)+1);
707 sprintf(file
, "%s/%s", directory
, directory_name
);
708 while ((s
= strstr(file
,"//"))) {
710 for (i
= 2;s
[i
] == '/';i
++);
714 if (mkdir(file
,0xfff) != 0) {
717 showError(scr
, panel
->win
, "Permission denied.", NULL
);
720 showError(scr
, panel
->win
, "'%s' already existes.", file
);
723 showError(scr
, panel
->win
, "Path does not exist.", NULL
);
726 else WMSetFilePanelDirectory(panel
, file
);
728 wfree(directory_name
);
735 deleteFile(WMButton
*bPre
, WMFilePanel
*panel
)
739 struct stat filestat
;
740 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
742 file
= getCurrentFileName(panel
);
744 while ((s
= strstr(file
,"//"))) {
746 for (i
= 2;s
[i
] == '/';i
++);
749 if (strlen(file
) > 1 && (s
= strrchr(file
, '/')) && !s
[1]) s
[0] = 0;
751 if (stat(file
,&filestat
)) {
754 showError(scr
, panel
->win
, "'%s' does not exist.", file
);
757 showError(scr
, panel
->win
, "Permission denied.", NULL
);
760 showError(scr
, panel
->win
,
761 "Insufficient memory available.", NULL
);
764 showError(scr
, panel
->win
,
765 "'%s' is on a read-only filesystem.", file
);
768 showError(scr
, panel
->win
, "Can not delete '%s'.", file
);
772 } else if (S_ISDIR(filestat
.st_mode
)) {
773 buffer
= wmalloc(strlen(file
)+20);
774 sprintf(buffer
,"Delete directory %s ?",file
);
776 buffer
= wmalloc(strlen(file
)+15);
777 sprintf(buffer
,"Delete file %s ?",file
);
780 if (!WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
781 "Warning", buffer
, "OK", "Cancel", NULL
)) {
782 if (S_ISDIR(filestat
.st_mode
)) {
783 if (rmdir(file
) != 0) {
786 showError(scr
, panel
->win
, "Permission denied.", NULL
);
789 showError(scr
, panel
->win
, "Directory '%s' does not exist.", file
);
792 showError(scr
, panel
->win
, "Directory '%s' is not empty.", file
);
795 showError(scr
, panel
->win
, "Directory '%s' is busy.", file
);
798 showError(scr
, panel
->win
, "Can not delete '%s'.", file
);
801 char *s
= strrchr(file
,'/');
803 WMSetFilePanelDirectory(panel
, file
);
805 } else if (remove(file
) != 0) {
808 showError(scr
, panel
->win
, "'%s' is a directory.", file
);
811 showError(scr
, panel
->win
, "'%s' does not exist.", file
);
814 showError(scr
, panel
->win
, "Permission denied.", NULL
);
817 showError(scr
, panel
->win
,
818 "Insufficient memory available.", NULL
);
821 showError(scr
, panel
->win
,
822 "'%s' is on a read-only filesystem.", file
);
825 showError(scr
, panel
->win
, "Can not delete '%s'.", file
);
828 char *s
= strrchr(file
,'/');
830 WMSetFilePanelDirectory(panel
, file
);
838 goUnmount(WMButton
*bPtr
, WMFilePanel
*panel
)
844 goFloppy(WMButton
*bPtr
, WMFilePanel
*panel
)
846 struct stat filestat
;
847 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
849 if (stat(WINGsConfiguration
.floppyPath
, &filestat
)) {
850 showError(scr
, panel
->win
, "An error occured browsing '%s'.",
851 WINGsConfiguration
.floppyPath
);
853 } else if (!S_ISDIR(filestat
.st_mode
)) {
854 showError(scr
, panel
->win
, "'%s' is not a directory.",
855 WINGsConfiguration
.floppyPath
);
859 WMSetFilePanelDirectory(panel
, WINGsConfiguration
.floppyPath
);
864 goHome(WMButton
*bPtr
, WMFilePanel
*panel
)
868 /* home is statically allocated. Don't free it! */
869 home
= wgethomedir();
873 WMSetFilePanelDirectory(panel
, home
);
878 handleEvents(XEvent
*event
, void *data
)
880 W_FilePanel
*pPtr
= (W_FilePanel
*)data
;
881 W_View
*view
= WMWidgetView(pPtr
->win
);
883 if (event
->type
== ConfigureNotify
) {
884 if (event
->xconfigure
.width
!= view
->size
.width
885 || event
->xconfigure
.height
!= view
->size
.height
) {
886 unsigned int newWidth
= event
->xconfigure
.width
;
887 unsigned int newHeight
= event
->xconfigure
.height
;
890 W_ResizeView(view
, newWidth
, newHeight
);
891 WMResizeWidget(pPtr
->line
, newWidth
, 2);
892 WMResizeWidget(pPtr
->browser
, newWidth
-14,
893 newHeight
-(PHEIGHT
-200));
894 WMResizeWidget(pPtr
->fileField
, newWidth
-60-10, 24);
895 WMMoveWidget(pPtr
->nameLabel
, 7, newHeight
-(PHEIGHT
-282));
896 WMMoveWidget(pPtr
->fileField
, 60, newHeight
-(PHEIGHT
-278));
897 WMMoveWidget(pPtr
->okButton
, newWidth
-(PWIDTH
-245),
898 newHeight
-(PHEIGHT
-325));
899 WMMoveWidget(pPtr
->cancelButton
, newWidth
-(PWIDTH
-165),
900 newHeight
-(PHEIGHT
-325));
902 WMMoveWidget(pPtr
->trashcanButton
, 7, newHeight
-(PHEIGHT
-325));
903 WMMoveWidget(pPtr
->createDirButton
, 37, newHeight
-(PHEIGHT
-325));
904 WMMoveWidget(pPtr
->homeButton
, 67, newHeight
-(PHEIGHT
-325));
905 WMMoveWidget(pPtr
->disketteButton
, 97, newHeight
-(PHEIGHT
-325));
906 WMMoveWidget(pPtr
->unmountButton
, 127, newHeight
-(PHEIGHT
-325));
908 newColumnCount
= (newWidth
- 14) / 140;
909 WMSetBrowserMaxVisibleColumns(pPtr
->browser
, newColumnCount
);
916 getCurrentFileName(WMFilePanel
*panel
)
923 path
= WMGetBrowserPath(panel
->browser
);
926 if (path
[len
-1]=='/') {
927 file
= WMGetTextFieldText(panel
->fileField
);
928 tmp
= wmalloc(strlen(path
)+strlen(file
)+8);
946 validOpenFile(WMFilePanel
*panel
)
949 int col
, haveFile
= 0;
950 char *file
= WMGetTextFieldText(panel
->fileField
);
956 col
= WMGetBrowserSelectedColumn(panel
->browser
);
957 item
= WMGetBrowserSelectedItemInColumn(panel
->browser
, col
);
959 if (item
->isBranch
&& !panel
->flags
.canChooseDirectories
&& !haveFile
)
961 else if (!item
->isBranch
&& !panel
->flags
.canChooseFiles
)
966 /* we compute for / here */
967 if (!panel
->flags
.canChooseDirectories
&& !haveFile
)
978 buttonClick(WMButton
*bPtr
, WMFilePanel
*panel
)
982 if (bPtr
== panel
->okButton
) {
983 if (!validOpenFile(panel
))
985 if (panel
->flags
.fileMustExist
) {
988 file
= getCurrentFileName(panel
);
989 if (access(file
, F_OK
)!=0) {
990 WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
991 "Error", "File does not exist.",
998 panel
->flags
.canceled
= 0;
1000 panel
->flags
.canceled
= 1;
1002 range
.count
= range
.position
= 0;
1003 WMSelectTextFieldRange(panel
->fileField
, range
);
1004 panel
->flags
.done
= 1;