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;
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 WMArray
*items
= WMGetListItems(list
);
104 int i
, len
= strlen(text
);
109 for(i
=0; i
<WMGetArrayItemCount(items
); i
++) {
110 item
= WMGetFromArray(items
, i
);
111 if (strlen(item
->text
) >= len
&&
112 ((exact
&& strcmp(item
->text
, text
)==0) ||
113 (!exact
&& strncmp(item
->text
, text
, len
)==0))) {
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
)
185 fPtr
= wmalloc(sizeof(WMFilePanel
));
186 memset(fPtr
, 0, sizeof(WMFilePanel
));
188 fPtr
->win
= WMCreateWindowWithStyle(scrPtr
, name
, WMTitledWindowMask
189 |WMResizableWindowMask
);
190 WMResizeWidget(fPtr
->win
, PWIDTH
, PHEIGHT
);
191 WMSetWindowTitle(fPtr
->win
, "");
193 WMCreateEventHandler(WMWidgetView(fPtr
->win
), StructureNotifyMask
,
195 WMSetWindowMinSize(fPtr
->win
, PWIDTH
, PHEIGHT
);
198 fPtr
->iconLabel
= WMCreateLabel(fPtr
->win
);
199 WMResizeWidget(fPtr
->iconLabel
, 64, 64);
200 WMMoveWidget(fPtr
->iconLabel
, 0, 0);
201 WMSetLabelImagePosition(fPtr
->iconLabel
, WIPImageOnly
);
202 icon
= WMCreateApplicationIconBlendedPixmap(scrPtr
, (RColor
*)NULL
);
204 WMSetLabelImage(fPtr
->iconLabel
, icon
);
205 WMReleasePixmap(icon
);
207 WMSetLabelImage(fPtr
->iconLabel
, scrPtr
->applicationIconPixmap
);
210 fPtr
->titleLabel
= WMCreateLabel(fPtr
->win
);
211 WMResizeWidget(fPtr
->titleLabel
, PWIDTH
-64, 64);
212 WMMoveWidget(fPtr
->titleLabel
, 64, 0);
213 largeFont
= WMBoldSystemFontOfSize(scrPtr
, 24);
214 WMSetLabelFont(fPtr
->titleLabel
, largeFont
);
215 WMReleaseFont(largeFont
);
216 WMSetLabelText(fPtr
->titleLabel
, title
);
218 fPtr
->line
= WMCreateFrame(fPtr
->win
);
219 WMMoveWidget(fPtr
->line
, 0, 64);
220 WMResizeWidget(fPtr
->line
, PWIDTH
, 2);
221 WMSetFrameRelief(fPtr
->line
, WRGroove
);
223 fPtr
->browser
= WMCreateBrowser(fPtr
->win
);
224 WMSetBrowserAllowEmptySelection(fPtr
->browser
, True
);
225 WMSetBrowserDelegate(fPtr
->browser
, &browserDelegate
);
226 WMSetBrowserAction(fPtr
->browser
, browserClick
, fPtr
);
227 WMSetBrowserDoubleAction(fPtr
->browser
, browserDClick
, fPtr
);
228 WMMoveWidget(fPtr
->browser
, 7, 72);
229 WMResizeWidget(fPtr
->browser
, PWIDTH
-14,200);
230 WMHangData(fPtr
->browser
, fPtr
);
232 fPtr
->nameLabel
= WMCreateLabel(fPtr
->win
);
233 WMMoveWidget(fPtr
->nameLabel
, 7, 282);
234 WMResizeWidget(fPtr
->nameLabel
, 55, 14);
235 WMSetLabelText(fPtr
->nameLabel
, _("Name:"));
237 fPtr
->fileField
= WMCreateTextField(fPtr
->win
);
238 WMMoveWidget(fPtr
->fileField
, 60, 278);
239 WMResizeWidget(fPtr
->fileField
, PWIDTH
-60-10, 24);
240 WMAddNotificationObserver(textEditedObserver
, fPtr
,
241 WMTextDidEndEditingNotification
,
243 WMAddNotificationObserver(textChangedObserver
, fPtr
,
244 WMTextDidChangeNotification
,
247 fPtr
->okButton
= WMCreateCommandButton(fPtr
->win
);
248 WMMoveWidget(fPtr
->okButton
, 245, 325);
249 WMResizeWidget(fPtr
->okButton
, 75, 28);
250 WMSetButtonText(fPtr
->okButton
, _("OK"));
251 WMSetButtonImage(fPtr
->okButton
, scrPtr
->buttonArrow
);
252 WMSetButtonAltImage(fPtr
->okButton
, scrPtr
->pushedButtonArrow
);
253 WMSetButtonImagePosition(fPtr
->okButton
, WIPRight
);
254 WMSetButtonAction(fPtr
->okButton
, buttonClick
, fPtr
);
256 fPtr
->cancelButton
= WMCreateCommandButton(fPtr
->win
);
257 WMMoveWidget(fPtr
->cancelButton
, 165, 325);
258 WMResizeWidget(fPtr
->cancelButton
, 75, 28);
259 WMSetButtonText(fPtr
->cancelButton
, _("Cancel"));
260 WMSetButtonAction(fPtr
->cancelButton
, buttonClick
, fPtr
);
262 fPtr
->trashcanButton
= WMCreateCommandButton(fPtr
->win
);
263 WMMoveWidget(fPtr
->trashcanButton
, 7, 325);
264 WMResizeWidget(fPtr
->trashcanButton
, 28, 28);
265 WMSetButtonImagePosition(fPtr
->trashcanButton
, WIPImageOnly
);
266 WMSetButtonImage(fPtr
->trashcanButton
, scrPtr
->trashcanIcon
);
267 WMSetButtonAltImage(fPtr
->trashcanButton
, scrPtr
->altTrashcanIcon
);
268 WMSetButtonAction(fPtr
->trashcanButton
, deleteFile
, fPtr
);
270 fPtr
->createDirButton
= WMCreateCommandButton(fPtr
->win
);
271 WMMoveWidget(fPtr
->createDirButton
, 37, 325);
272 WMResizeWidget(fPtr
->createDirButton
, 28, 28);
273 WMSetButtonImagePosition(fPtr
->createDirButton
, WIPImageOnly
);
274 WMSetButtonImage(fPtr
->createDirButton
, scrPtr
->createDirIcon
);
275 WMSetButtonAltImage(fPtr
->createDirButton
, scrPtr
->altCreateDirIcon
);
276 WMSetButtonAction(fPtr
->createDirButton
, createDir
, fPtr
);
278 fPtr
->homeButton
= WMCreateCommandButton(fPtr
->win
);
279 WMMoveWidget(fPtr
->homeButton
, 67, 325);
280 WMResizeWidget(fPtr
->homeButton
, 28, 28);
281 WMSetButtonImagePosition(fPtr
->homeButton
, WIPImageOnly
);
282 WMSetButtonImage(fPtr
->homeButton
, scrPtr
->homeIcon
);
283 WMSetButtonAltImage(fPtr
->homeButton
, scrPtr
->altHomeIcon
);
284 WMSetButtonAction(fPtr
->homeButton
, goHome
, fPtr
);
286 fPtr
->disketteButton
= WMCreateCommandButton(fPtr
->win
);
287 WMMoveWidget(fPtr
->disketteButton
, 97, 325);
288 WMResizeWidget(fPtr
->disketteButton
, 28, 28);
289 WMSetButtonImagePosition(fPtr
->disketteButton
, WIPImageOnly
);
290 WMSetButtonImage(fPtr
->disketteButton
, scrPtr
->disketteIcon
);
291 WMSetButtonAltImage(fPtr
->disketteButton
, scrPtr
->altDisketteIcon
);
292 WMSetButtonAction(fPtr
->disketteButton
, goFloppy
, fPtr
);
294 fPtr
->unmountButton
= WMCreateCommandButton(fPtr
->win
);
295 WMMoveWidget(fPtr
->unmountButton
, 127, 325);
296 WMResizeWidget(fPtr
->unmountButton
, 28, 28);
297 WMSetButtonImagePosition(fPtr
->unmountButton
, WIPImageOnly
);
298 WMSetButtonImage(fPtr
->unmountButton
, scrPtr
->unmountIcon
);
299 WMSetButtonAltImage(fPtr
->unmountButton
, scrPtr
->altUnmountIcon
);
300 WMSetButtonAction(fPtr
->unmountButton
, goUnmount
, fPtr
);
301 WMSetButtonEnabled(fPtr
->unmountButton
, False
);
304 WMRealizeWidget(fPtr
->win
);
305 WMMapSubwidgets(fPtr
->win
);
307 WMSetFocusToWidget(fPtr
->fileField
);
308 WMSetTextFieldCursorPosition(fPtr
->fileField
, 0);
310 WMLoadBrowserColumnZero(fPtr
->browser
);
312 WMSetWindowInitialPosition(fPtr
->win
,
313 (scrPtr
->rootView
->size
.width
- WMWidgetWidth(fPtr
->win
))/2,
314 (scrPtr
->rootView
->size
.height
- WMWidgetHeight(fPtr
->win
))/2);
316 fPtr
->flags
.canChooseFiles
= 1;
317 fPtr
->flags
.canChooseDirectories
= 1;
318 fPtr
->flags
.autoCompletion
= 1;
325 WMGetOpenPanel(WMScreen
*scrPtr
)
329 if (scrPtr
->sharedOpenPanel
)
330 return scrPtr
->sharedOpenPanel
;
332 panel
= makeFilePanel(scrPtr
, "openFilePanel", _("Open"));
333 panel
->flags
.fileMustExist
= 1;
334 panel
->flags
.panelType
= WP_OPEN
;
336 scrPtr
->sharedOpenPanel
= panel
;
343 WMGetSavePanel(WMScreen
*scrPtr
)
347 if (scrPtr
->sharedSavePanel
)
348 return scrPtr
->sharedSavePanel
;
350 panel
= makeFilePanel(scrPtr
, "saveFilePanel", _("Save"));
351 panel
->flags
.fileMustExist
= 0;
352 panel
->flags
.panelType
= WP_SAVE
;
354 scrPtr
->sharedSavePanel
= panel
;
361 WMFreeFilePanel(WMFilePanel
*panel
)
363 if (panel
== WMWidgetScreen(panel
->win
)->sharedSavePanel
) {
364 WMWidgetScreen(panel
->win
)->sharedSavePanel
= NULL
;
366 if (panel
== WMWidgetScreen(panel
->win
)->sharedOpenPanel
) {
367 WMWidgetScreen(panel
->win
)->sharedOpenPanel
= NULL
;
369 WMRemoveNotificationObserver(panel
);
370 WMUnmapWidget(panel
->win
);
371 WMDestroyWidget(panel
->win
);
377 WMRunModalFilePanelForDirectory(WMFilePanel
*panel
, WMWindow
*owner
,
378 char *path
, char *name
, char **fileTypes
)
380 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
382 if (name
&& !owner
) {
383 WMSetWindowTitle(panel
->win
, name
);
386 WMChangePanelOwner(panel
->win
, owner
);
388 WMSetFilePanelDirectory(panel
, path
);
390 switch(panel
->flags
.panelType
) {
393 panel
->flags
.filtered
= 1;
394 panel
->fileTypes
= fileTypes
;
399 panel
->fileTypes
= NULL
;
400 panel
->flags
.filtered
= 0;
408 WMSetLabelText(panel
->titleLabel
, name
);
410 WMMapWidget(panel
->win
);
412 WMRunModalLoop(scr
, W_VIEW(panel
->win
));
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 *dirName
, *directory
, *file
, *s
;
656 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
658 dirName
= WMRunInputPanel(scr
, panel
->win
, _("Create Directory"),
659 _("Enter directory name"), "", _("OK"), _("Cancel"));
663 directory
= getCurrentFileName(panel
);
664 s
= strrchr(directory
,'/');
667 if (dirName
[0] == '/') {
670 while ((s
= strstr(directory
,"//"))) {
672 for (i
= 2;s
[i
] == '/';i
++);
675 if ((s
= strrchr(directory
, '/')) && !s
[1]) s
[0] = 0;
677 while ((s
= strstr(dirName
,"//"))) {
679 for (i
= 2;s
[i
] == '/';i
++);
682 if ((s
= strrchr(dirName
, '/')) && !s
[1]) s
[0] = 0;
684 file
= wmalloc(strlen(dirName
)+strlen(directory
)+4);
685 sprintf(file
, "%s/%s", directory
, dirName
);
686 while ((s
= strstr(file
,"//"))) {
688 for (i
= 2;s
[i
] == '/';i
++);
692 if (mkdir(file
,0xfff) != 0) {
695 showError(scr
, panel
->win
, _("Permission denied."), NULL
);
698 showError(scr
, panel
->win
, _("'%s' already exists."), file
);
701 showError(scr
, panel
->win
, _("Path does not exist."), NULL
);
704 else WMSetFilePanelDirectory(panel
, file
);
712 deleteFile(WMButton
*bPre
, WMFilePanel
*panel
)
716 struct stat filestat
;
717 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
719 file
= getCurrentFileName(panel
);
721 while ((s
= strstr(file
,"//"))) {
723 for (i
= 2;s
[i
] == '/';i
++);
726 if (strlen(file
) > 1 && (s
= strrchr(file
, '/')) && !s
[1]) s
[0] = 0;
728 if (stat(file
,&filestat
)) {
731 showError(scr
, panel
->win
, _("'%s' does not exist."), file
);
734 showError(scr
, panel
->win
, _("Permission denied."), NULL
);
737 showError(scr
, panel
->win
,
738 _("Insufficient memory available."), NULL
);
741 showError(scr
, panel
->win
,
742 _("'%s' is on a read-only filesystem."), file
);
745 showError(scr
, panel
->win
, _("Can not delete '%s'."), file
);
749 } else if (S_ISDIR(filestat
.st_mode
)) {
750 int len
= strlen(file
)+20;
751 buffer
= wmalloc(len
);
752 snprintf(buffer
,len
,_("Delete directory %s ?"),file
);
754 int len
= strlen(file
)+15;
755 buffer
= wmalloc(len
);
756 snprintf(buffer
,len
,_("Delete file %s ?"),file
);
759 if (!WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
760 _("Warning"), buffer
, _("OK"), _("Cancel"), NULL
)) {
761 if (S_ISDIR(filestat
.st_mode
)) {
762 if (rmdir(file
) != 0) {
765 showError(scr
, panel
->win
, _("Permission denied."), NULL
);
768 showError(scr
, panel
->win
, _("Directory '%s' does not exist."), file
);
771 showError(scr
, panel
->win
, _("Directory '%s' is not empty."), file
);
774 showError(scr
, panel
->win
, _("Directory '%s' is busy."), file
);
777 showError(scr
, panel
->win
, _("Can not delete '%s'."), file
);
780 char *s
= strrchr(file
,'/');
782 WMSetFilePanelDirectory(panel
, file
);
784 } else if (remove(file
) != 0) {
787 showError(scr
, panel
->win
, _("'%s' is a directory."), file
);
790 showError(scr
, panel
->win
, _("'%s' does not exist."), file
);
793 showError(scr
, panel
->win
, _("Permission denied."), NULL
);
796 showError(scr
, panel
->win
,
797 _("Insufficient memory available."), NULL
);
800 showError(scr
, panel
->win
,
801 _("'%s' is on a read-only filesystem."), file
);
804 showError(scr
, panel
->win
, _("Can not delete '%s'."), file
);
807 char *s
= strrchr(file
,'/');
809 WMSetFilePanelDirectory(panel
, file
);
817 goUnmount(WMButton
*bPtr
, WMFilePanel
*panel
)
823 goFloppy(WMButton
*bPtr
, WMFilePanel
*panel
)
825 struct stat filestat
;
826 WMScreen
*scr
= WMWidgetScreen(panel
->win
);
828 if (stat(WINGsConfiguration
.floppyPath
, &filestat
)) {
829 showError(scr
, panel
->win
, _("An error occured browsing '%s'."),
830 WINGsConfiguration
.floppyPath
);
832 } else if (!S_ISDIR(filestat
.st_mode
)) {
833 showError(scr
, panel
->win
, _("'%s' is not a directory."),
834 WINGsConfiguration
.floppyPath
);
838 WMSetFilePanelDirectory(panel
, WINGsConfiguration
.floppyPath
);
843 goHome(WMButton
*bPtr
, WMFilePanel
*panel
)
847 /* home is statically allocated. Don't free it! */
848 home
= wgethomedir();
852 WMSetFilePanelDirectory(panel
, home
);
857 handleEvents(XEvent
*event
, void *data
)
859 W_FilePanel
*pPtr
= (W_FilePanel
*)data
;
860 W_View
*view
= WMWidgetView(pPtr
->win
);
862 if (event
->type
== ConfigureNotify
) {
863 if (event
->xconfigure
.width
!= view
->size
.width
864 || event
->xconfigure
.height
!= view
->size
.height
) {
865 unsigned int newWidth
= event
->xconfigure
.width
;
866 unsigned int newHeight
= event
->xconfigure
.height
;
869 W_ResizeView(view
, newWidth
, newHeight
);
870 WMResizeWidget(pPtr
->line
, newWidth
, 2);
871 WMResizeWidget(pPtr
->browser
, newWidth
-14,
872 newHeight
-(PHEIGHT
-200));
873 WMResizeWidget(pPtr
->fileField
, newWidth
-60-10, 24);
874 WMMoveWidget(pPtr
->nameLabel
, 7, newHeight
-(PHEIGHT
-282));
875 WMMoveWidget(pPtr
->fileField
, 60, newHeight
-(PHEIGHT
-278));
876 WMMoveWidget(pPtr
->okButton
, newWidth
-(PWIDTH
-245),
877 newHeight
-(PHEIGHT
-325));
878 WMMoveWidget(pPtr
->cancelButton
, newWidth
-(PWIDTH
-165),
879 newHeight
-(PHEIGHT
-325));
881 WMMoveWidget(pPtr
->trashcanButton
, 7, newHeight
-(PHEIGHT
-325));
882 WMMoveWidget(pPtr
->createDirButton
, 37, newHeight
-(PHEIGHT
-325));
883 WMMoveWidget(pPtr
->homeButton
, 67, newHeight
-(PHEIGHT
-325));
884 WMMoveWidget(pPtr
->disketteButton
, 97, newHeight
-(PHEIGHT
-325));
885 WMMoveWidget(pPtr
->unmountButton
, 127, newHeight
-(PHEIGHT
-325));
887 newColumnCount
= (newWidth
- 14) / 140;
888 WMSetBrowserMaxVisibleColumns(pPtr
->browser
, newColumnCount
);
895 getCurrentFileName(WMFilePanel
*panel
)
902 path
= WMGetBrowserPath(panel
->browser
);
905 if (path
[len
-1]=='/') {
906 file
= WMGetTextFieldText(panel
->fileField
);
907 tmp
= wmalloc(strlen(path
)+strlen(file
)+8);
925 validOpenFile(WMFilePanel
*panel
)
928 int col
, haveFile
= 0;
929 char *file
= WMGetTextFieldText(panel
->fileField
);
935 col
= WMGetBrowserSelectedColumn(panel
->browser
);
936 item
= WMGetBrowserSelectedItemInColumn(panel
->browser
, col
);
938 if (item
->isBranch
&& !panel
->flags
.canChooseDirectories
&& !haveFile
)
940 else if (!item
->isBranch
&& !panel
->flags
.canChooseFiles
)
945 /* we compute for / here */
946 if (!panel
->flags
.canChooseDirectories
&& !haveFile
)
957 buttonClick(WMButton
*bPtr
, WMFilePanel
*panel
)
961 if (bPtr
== panel
->okButton
) {
962 if (!validOpenFile(panel
))
964 if (panel
->flags
.fileMustExist
) {
967 file
= getCurrentFileName(panel
);
968 if (access(file
, F_OK
)!=0) {
969 WMRunAlertPanel(WMWidgetScreen(panel
->win
), panel
->win
,
970 _("Error"), _("File does not exist."),
971 _("OK"), NULL
, NULL
);
977 panel
->flags
.canceled
= 0;
979 panel
->flags
.canceled
= 1;
981 range
.count
= range
.position
= 0;
982 WMSelectTextFieldRange(panel
->fileField
, range
);
983 WMBreakModalLoop(WMWidgetScreen(bPtr
));