]> git.lyx.org Git - lyx.git/blob - src/filedlg.C
Angus's 23rd November patch
[lyx.git] / src / filedlg.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *        
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2000 The LyX Team.
9  *
10  * ====================================================== */
11
12 #include <config.h>
13
14 #include <unistd.h>
15 #include <cstdlib>
16 #include <pwd.h>
17 #include <grp.h>
18 #include <cstring>
19 #include <map>
20 #include <algorithm>
21
22 using std::map;
23 using std::max;
24 using std::sort;
25
26 #include "lyx_gui_misc.h" // CancelCloseCB
27 #include "support/FileInfo.h"
28 #include "support/lyxlib.h"
29 #include "gettext.h"
30 #include "frontends/Dialogs.h"
31
32 #ifdef HAVE_ERRNO_H
33 #include <cerrno>
34 #endif
35
36 #if HAVE_DIRENT_H
37 # include <dirent.h>
38 # define NAMLEN(dirent) strlen((dirent)->d_name)
39 #else
40 # define dirent direct
41 # define NAMLEN(dirent) (dirent)->d_namlen
42 # if HAVE_SYS_NDIR_H
43 #  include <sys/ndir.h>
44 # endif
45 # if HAVE_SYS_DIR_H
46 #  include <sys/dir.h>
47 # endif
48 # if HAVE_NDIR_H
49 #  include <ndir.h>
50 # endif
51 #endif
52
53 #if TIME_WITH_SYS_TIME
54 # include <sys/time.h>
55 # include <ctime>
56 #else
57 # if HAVE_SYS_TIME_H
58 #  include <sys/time.h>
59 # else
60 #  include <ctime>
61 # endif
62 #endif
63
64 #ifdef BROKEN_HEADERS
65 extern "C" int gettimeofday(struct timeval *, struct timezone *);
66 #endif
67
68 #ifdef __GNUG__
69 #pragma implementation
70 #endif
71
72 #include "support/filetools.h"
73 #include "filedlg.h"
74
75 // six months, in seconds
76 static const long SIX_MONTH_SEC = 6L * 30L * 24L * 60L * 60L;
77 static const long ONE_HOUR_SEC = 60L * 60L;
78
79 // *** User cache class implementation
80 /// User cache class definition
81 class UserCache {
82 public:
83         /// seeks user name from group ID
84         string const & find(uid_t ID) const {
85                 Users::const_iterator cit = users.find(ID);
86                 if (cit == users.end()) {
87                         add(ID);
88                         return users[ID];
89                 }
90                 return (*cit).second;
91         }
92 private:
93         ///
94         void add(uid_t ID) const;
95         ///
96         typedef map<uid_t, string> Users;
97         ///
98         mutable Users users;
99 };
100
101
102 void UserCache::add(uid_t ID) const 
103 {
104         string pszNewName;
105         struct passwd * pEntry;
106         
107         // gets user name
108         if ((pEntry = getpwuid(ID)))
109                 pszNewName = pEntry->pw_name;
110         else {
111                 pszNewName = tostr(ID);
112         }
113         
114         // adds new node
115         users[ID] = pszNewName;
116 }       
117
118
119 /// Group cache class definition
120 class GroupCache {
121 public:
122         /// seeks group name from group ID
123         string const & find(gid_t ID) const ;
124 private:
125         ///
126         void add(gid_t ID) const;
127         ///
128         typedef map<gid_t, string> Groups;
129         ///
130         mutable Groups groups;
131 };
132
133
134 string const & GroupCache::find(gid_t ID) const 
135 {
136         Groups::const_iterator cit = groups.find(ID);
137         if (cit == groups.end()) {
138                 add(ID);
139                 return groups[ID];
140         }
141         return (*cit).second;
142 }
143
144
145 void GroupCache::add(gid_t ID) const 
146 {
147         string pszNewName;
148         struct group * pEntry;
149         
150         // gets user name
151         if ((pEntry = getgrgid(ID))) pszNewName = pEntry->gr_name;
152         else {
153                 pszNewName = tostr(ID);
154         }
155         // adds new node
156         groups[ID] = pszNewName;
157 }
158
159
160 // static instances
161 static UserCache lyxUserCache;
162 static GroupCache lyxGroupCache;
163
164
165 // some "C" wrappers around callbacks
166 extern "C" void C_LyXFileDlg_FileDlgCB(FL_OBJECT *, long lArgument);
167 extern "C" void C_LyXFileDlg_DoubleClickCB(FL_OBJECT *, long);
168 extern "C" int C_LyXFileDlg_CancelCB(FL_FORM *, void *);
169
170
171 // compares two LyXDirEntry objects content (used for sort)
172 class comp_direntry {
173 public:
174         int operator()(LyXDirEntry const & r1,
175                        LyXDirEntry const & r2) const ;
176 };
177         int comp_direntry::operator()(LyXDirEntry const & r1,
178                        LyXDirEntry const & r2) const {
179                 bool r1d = suffixIs(r1.pszName, '/');
180                 bool r2d = suffixIs(r2.pszName, '/');
181                 if (r1d && !r2d) return 1;
182                 if (!r1d && r2d) return 0;
183                 return r1.pszName < r2.pszName;
184         }
185
186
187 // *** LyXFileDlg class implementation
188
189 // static members
190 FD_FileDlg * LyXFileDlg::pFileDlgForm = 0;
191 LyXFileDlg * LyXFileDlg::pCurrentDlg = 0;
192
193
194 // Reread: updates dialog list to match class directory
195 void LyXFileDlg::Reread()
196 {
197         // Opens directory
198         DIR * pDirectory = ::opendir(pszDirectory.c_str());
199         if (!pDirectory) {
200                 WriteFSAlert(_("Warning! Couldn't open directory."), 
201                              pszDirectory);
202                 pszDirectory = lyx::getcwd();
203                 pDirectory = ::opendir(pszDirectory.c_str());
204         }
205
206         // Clear the present namelist
207         direntries.clear();
208
209         // Updates display
210         fl_hide_object(pFileDlgForm->List);
211         fl_clear_browser(pFileDlgForm->List);
212         fl_set_input(pFileDlgForm->DirBox, pszDirectory.c_str());
213
214         // Splits complete directory name into directories and compute depth
215         iDepth = 0;
216         string line, Temp;
217         char szMode[15];
218         FileInfo fileInfo;
219         string File = pszDirectory;
220         if (File != "/") {
221                 File = split(File, Temp, '/');
222         }
223         while (!File.empty() || !Temp.empty()) {
224                 string dline = "@b"+line + Temp + '/';          
225                 fl_add_browser_line(pFileDlgForm->List, dline.c_str());
226                 File = split(File, Temp, '/');
227                 line += ' ';
228                 ++iDepth;
229         }
230
231         // Parses all entries of the given subdirectory
232         time_t curTime = time(0);
233         rewinddir(pDirectory);
234         struct dirent * pDirEntry;
235         while ((pDirEntry = readdir(pDirectory))) {
236                 bool isLink = false, isDir = false;
237
238                 // If the pattern doesn't start with a dot, skip hidden files
239                 if (!pszMask.empty() && pszMask[0] != '.' && 
240                     pDirEntry->d_name[0] == '.')
241                         continue;
242
243                 // Gets filename
244                 string fname = pDirEntry->d_name;
245
246                 // Under all circumstances, "." and ".." are not wanted
247                 if (fname == "." || fname == "..")
248                         continue;
249
250                 // gets file status
251                 File = AddName(pszDirectory, fname);
252
253                 fileInfo.newFile(File, true);
254                 fileInfo.modeString(szMode);
255                 unsigned int nlink = fileInfo.getNumberOfLinks();
256                 string user =   lyxUserCache.find(fileInfo.getUid());
257                 string group = lyxGroupCache.find(fileInfo.getGid());
258
259                 time_t modtime = fileInfo.getModificationTime();
260                 string Time = ctime(&modtime);
261                 
262                 if (curTime > fileInfo.getModificationTime() + SIX_MONTH_SEC
263                     || curTime < fileInfo.getModificationTime()
264                     + ONE_HOUR_SEC) {
265                         // The file is fairly old or in the future. POSIX says
266                         // the cutoff is 6 months old. Allow a 1 hour slop
267                         // factor for what is considered "the future", to
268                         // allow for NFS server/client clock disagreement.
269                         // Show the year instead of the time of day.
270                         Time.erase(10, 9);
271                         Time.erase(15, string::npos);
272                 } else {
273                         Time.erase(16, string::npos);
274                 }
275
276                 string Buffer = string(szMode) + ' ' +
277                         tostr(nlink) + ' ' +
278                         user + ' ' +
279                         group + ' ' +
280                         Time.substr(4, string::npos) + ' ';
281
282                 Buffer += pDirEntry->d_name;
283                 Buffer += fileInfo.typeIndicator();
284
285                 if ((isLink = fileInfo.isLink())) {
286                         string Link;
287
288                         if (LyXReadLink(File, Link)) {
289                                 Buffer += " -> ";
290                                 Buffer += Link;
291
292                                 // This gives the FileType of the file that
293                                 // is really pointed too after resolving all
294                                 // symlinks. This is not necessarily the same
295                                 // as the type of Link (which could again be a
296                                 // link). Is that intended?
297                                 //                              JV 199902
298                                 fileInfo.newFile(File);
299                                 Buffer += fileInfo.typeIndicator();
300                         }
301                 }
302
303                 // filters files according to pattern and type
304                 if (fileInfo.isRegular()
305                     || fileInfo.isChar()
306                     || fileInfo.isBlock()
307                     || fileInfo.isFifo()) {
308                         if (!regexMatch(fname, pszMask))
309                                 continue;
310                 } else if (!(isDir = fileInfo.isDir()))
311                         continue;
312
313                 LyXDirEntry tmp;
314
315                 // Note pszLsEntry is an string!
316                 tmp.pszLsEntry = Buffer;
317                 // creates used name
318                 string temp = fname;
319                 if (isDir) temp += '/';
320
321                 tmp.pszName = temp;
322                 // creates displayed name
323                 temp = pDirEntry->d_name;
324                 if (isLink)
325                         temp += '@';
326                 else
327                         temp += fileInfo.typeIndicator();
328                 tmp.pszDisplayed = temp;
329
330                 direntries.push_back(tmp);
331         }
332
333         closedir(pDirectory);
334
335         // Sort the names
336         sort(direntries.begin(), direntries.end(), comp_direntry());
337         
338         // Add them to directory box
339         for (DirEntries::const_iterator cit = direntries.begin();
340              cit != direntries.end(); ++cit) {
341                 string const temp = line + (*cit).pszDisplayed;
342                 fl_add_browser_line(pFileDlgForm->List, temp.c_str());
343         }
344         fl_set_browser_topline(pFileDlgForm->List, iDepth);
345         fl_show_object(pFileDlgForm->List);
346         iLastSel = -1;
347 }
348
349
350 // SetDirectory: sets dialog current directory
351 void LyXFileDlg::SetDirectory(string const & Path)
352 {
353         if (!pszDirectory.empty()) {
354                 string TempPath = ExpandPath(Path); // Expand ~/
355                 TempPath = MakeAbsPath(TempPath, pszDirectory);
356                 pszDirectory = MakeAbsPath(TempPath);
357         } else pszDirectory = MakeAbsPath(Path);
358 }
359
360
361 // SetMask: sets dialog file mask
362 void LyXFileDlg::SetMask(string const & NewMask)
363 {
364         pszMask = NewMask;
365         fl_set_input(pFileDlgForm->PatBox, pszMask.c_str());
366 }
367
368
369 // SetInfoLine: sets dialog information line
370 void LyXFileDlg::SetInfoLine(string const & Line)
371 {
372         pszInfoLine = Line;
373         fl_set_object_label(pFileDlgForm->FileInfo, pszInfoLine.c_str());
374 }
375
376
377 LyXFileDlg::LyXFileDlg()
378 {
379         pszDirectory = MakeAbsPath(string("."));
380         pszMask = '*';
381
382         // Creates form if necessary. 
383         if (!pFileDlgForm) {
384                 pFileDlgForm = create_form_FileDlg();
385                 // Set callbacks. This means that we don't need a patch file
386                 fl_set_object_callback(pFileDlgForm->DirBox,
387                                        C_LyXFileDlg_FileDlgCB, 0);
388                 fl_set_object_callback(pFileDlgForm->PatBox,
389                                        C_LyXFileDlg_FileDlgCB, 1);
390                 fl_set_object_callback(pFileDlgForm->List,
391                                        C_LyXFileDlg_FileDlgCB, 2);
392                 fl_set_object_callback(pFileDlgForm->Filename,
393                                        C_LyXFileDlg_FileDlgCB, 3);
394                 fl_set_object_callback(pFileDlgForm->Rescan,
395                                        C_LyXFileDlg_FileDlgCB, 10);
396                 fl_set_object_callback(pFileDlgForm->Home,
397                                        C_LyXFileDlg_FileDlgCB, 11);
398                 fl_set_object_callback(pFileDlgForm->User1,
399                                        C_LyXFileDlg_FileDlgCB, 12);
400                 fl_set_object_callback(pFileDlgForm->User2,
401                                        C_LyXFileDlg_FileDlgCB, 13);
402                 
403                 // Make sure pressing the close box doesn't crash LyX. (RvdK)
404                 fl_set_form_atclose(pFileDlgForm->FileDlg, 
405                                     C_LyXFileDlg_CancelCB, 0);
406                 // Register doubleclick callback
407                 fl_set_browser_dblclick_callback(pFileDlgForm->List,
408                                                  C_LyXFileDlg_DoubleClickCB,
409                                                  0);
410         }
411         fl_hide_object(pFileDlgForm->User1);
412         fl_hide_object(pFileDlgForm->User2);
413
414         r_ = Dialogs::redrawGUI.connect(SigC::slot(this, &LyXFileDlg::redraw));
415 }
416
417
418 LyXFileDlg::~LyXFileDlg()
419 {
420         r_.disconnect();
421 }
422
423
424 void LyXFileDlg::redraw()
425 {
426         if (pFileDlgForm->FileDlg && pFileDlgForm->FileDlg->visible)
427                 fl_redraw_form(pFileDlgForm->FileDlg);
428 }
429
430
431 // SetButton: sets file selector user button action
432 void LyXFileDlg::SetButton(int iIndex, string const & pszName, 
433                            string const & pszPath)
434 {
435         FL_OBJECT * pObject;
436         string * pTemp;
437
438         if (iIndex == 0) {
439                 pObject = pFileDlgForm->User1;
440                 pTemp = &pszUserPath1;
441         } else if (iIndex == 1) {                       
442                 pObject = pFileDlgForm->User2;
443                 pTemp = &pszUserPath2;
444         } else return;
445
446         if (!pszName.empty() && !pszPath.empty()) {
447                 fl_set_object_label(pObject, pszName.c_str());
448                 fl_show_object(pObject);
449                 *pTemp = pszPath;
450         } else {
451                 fl_hide_object(pObject);
452                 (*pTemp).erase();
453         }
454 }
455
456
457 // GetDirectory: gets last dialog directory
458 string const LyXFileDlg::GetDirectory() const
459 {
460         if (!pszDirectory.empty())
461                 return pszDirectory;
462         else
463                 return string(".");
464 }
465
466
467 // RunDialog: handle dialog during file selection
468 bool LyXFileDlg::RunDialog()
469 {
470         force_cancel = false;
471         force_ok = false;
472         
473         // event loop
474         while(true) {
475                 FL_OBJECT * pObject = fl_do_forms();
476
477                 if (pObject == pFileDlgForm->Ready) {
478                         if (HandleOK())
479                                 return true;
480                 } else if (pObject == pFileDlgForm->Cancel 
481                            || force_cancel) 
482                         return false;
483                 else if (force_ok)
484                         return true;
485         }
486 }
487
488
489 // XForms objects callback (static)
490 void LyXFileDlg::FileDlgCB(FL_OBJECT *, long lArgument)
491 {
492         if (!pCurrentDlg) return;
493
494         switch (lArgument) {
495
496         case 0: // get directory
497                 pCurrentDlg->SetDirectory(fl_get_input(pFileDlgForm->DirBox));
498                 pCurrentDlg->Reread();
499                 break;
500
501         case 1: // get mask
502                 pCurrentDlg->SetMask(fl_get_input(pFileDlgForm->PatBox));
503                 pCurrentDlg->Reread();
504                 break;
505
506         case 2: // list
507                 pCurrentDlg->HandleListHit();
508                 break;  
509
510         case 10: // rescan
511                 pCurrentDlg->SetDirectory(fl_get_input(pFileDlgForm->DirBox));
512                 pCurrentDlg->SetMask(fl_get_input(pFileDlgForm->PatBox));
513                 pCurrentDlg->Reread();
514                 break;
515
516         case 11: // home
517                 pCurrentDlg->SetDirectory(GetEnvPath("HOME"));
518                 pCurrentDlg->SetMask(fl_get_input(pFileDlgForm->PatBox));
519                 pCurrentDlg->Reread();
520                 break;
521
522         case 12: // user button 1
523                 if (!pCurrentDlg->pszUserPath1.empty()) {
524                         pCurrentDlg->SetDirectory(pCurrentDlg->pszUserPath1);
525                         pCurrentDlg->SetMask(fl_get_input(pFileDlgForm
526                                                           ->PatBox));
527                         pCurrentDlg->Reread();
528                 }
529                 break;
530
531         case 13: // user button 2
532                 if (!pCurrentDlg->pszUserPath2.empty()) {
533                         pCurrentDlg->SetDirectory(pCurrentDlg->pszUserPath2);
534                         pCurrentDlg->SetMask(fl_get_input(pFileDlgForm
535                                                           ->PatBox));
536                         pCurrentDlg->Reread();
537                 }
538                 break;
539
540         }
541 }
542
543
544 extern "C" void C_LyXFileDlg_FileDlgCB(FL_OBJECT * ob, long data) 
545 {
546         LyXFileDlg::FileDlgCB(ob, data);
547 }
548
549
550 // Handle callback from list
551 void LyXFileDlg::HandleListHit()
552 {
553         // set info line
554         int const iSelect = fl_get_browser(pFileDlgForm->List);
555         if (iSelect > iDepth)  {
556                 SetInfoLine(direntries[iSelect - iDepth - 1].pszLsEntry);
557         } else {
558                 SetInfoLine(string());
559         }
560 }
561
562
563 // Callback for double click in list
564 void LyXFileDlg::DoubleClickCB(FL_OBJECT *, long)
565 {
566         if (pCurrentDlg->HandleDoubleClick())
567                 // Simulate click on OK button
568                 pCurrentDlg->Force(false);
569 }
570
571
572 extern "C" void C_LyXFileDlg_DoubleClickCB(FL_OBJECT * ob, long data)
573 {
574         LyXFileDlg::DoubleClickCB(ob, data);
575 }
576
577
578 // Handle double click from list
579 bool LyXFileDlg::HandleDoubleClick()
580 {
581         string pszTemp;
582
583         // set info line
584         bool isDir = true;
585         int const iSelect = fl_get_browser(pFileDlgForm->List);
586         if (iSelect > iDepth)  {
587                 pszTemp = direntries[iSelect - iDepth - 1].pszName;
588                 SetInfoLine(direntries[iSelect - iDepth - 1].pszLsEntry);
589                 if (!suffixIs(pszTemp, '/')) {
590                         isDir = false;
591                         fl_set_input(pFileDlgForm->Filename, pszTemp.c_str());
592                 }
593         } else if (iSelect != 0) {
594                 SetInfoLine(string());
595         } else
596                 return true;
597
598         // executes action
599         if (isDir) {
600                 string Temp;
601
602                 // builds new directory name
603                 if (iSelect > iDepth) {
604                         // Directory deeper down
605                         // First, get directory with trailing /
606                         Temp = fl_get_input(pFileDlgForm->DirBox);
607                         if (!suffixIs(Temp, '/'))
608                                 Temp += '/';
609                         Temp += pszTemp;
610                 } else {
611                         // Directory higher up
612                         Temp.erase();
613                         for (int i = 0; i < iSelect; ++i) {
614                                 string piece = fl_get_browser_line(pFileDlgForm->List, i+1);
615                                 // The '+2' is here to count the '@b' (JMarc)
616                                 Temp += piece.substr(i + 2);
617                         }
618                 }
619
620                 // assigns it
621                 SetDirectory(Temp);
622                 Reread();
623                 return false;
624         }
625         return true;
626 }
627
628
629 // Handle OK button call
630 bool LyXFileDlg::HandleOK()
631 {
632         // mask was changed
633         string pszTemp = fl_get_input(pFileDlgForm->PatBox);
634         if (pszTemp != pszMask) {
635                 SetMask(pszTemp);
636                 Reread();
637                 return false;
638         }
639
640         // directory was changed
641         pszTemp = fl_get_input(pFileDlgForm->DirBox);
642         if (pszTemp!= pszDirectory) {
643                 SetDirectory(pszTemp);
644                 Reread();
645                 return false;
646         }
647         
648         // Handle return from list
649         int const select = fl_get_browser(pFileDlgForm->List);
650         if (select > iDepth) {
651                 string const temp = direntries[select - iDepth - 1].pszName;
652                 if (!suffixIs(temp, '/')) {
653                         // If user didn't type anything, use browser
654                         string const name =
655                                 fl_get_input(pFileDlgForm->Filename);
656                         if (name.empty()) {
657                                 fl_set_input(pFileDlgForm->Filename, temp.c_str());
658                         }
659                         return true;
660                 }
661         }
662
663         // Emulate a doubleclick
664         return HandleDoubleClick();
665 }
666
667
668 // Handle Cancel CB from WM close
669 int LyXFileDlg::CancelCB(FL_FORM *, void *)
670 {
671         // Simulate a click on the cancel button
672         pCurrentDlg->Force(true);
673         return FL_IGNORE;
674 }
675
676
677 extern "C" int C_LyXFileDlg_CancelCB(FL_FORM *fl, void *xev)
678 {
679         return LyXFileDlg::CancelCB(fl, xev);
680 }
681
682
683 // Simulates a click on OK/Cancel
684 void LyXFileDlg::Force(bool cancel)
685 {
686         if (cancel) {
687                 force_cancel = true;
688                 fl_set_button(pFileDlgForm->Cancel, 1);
689         } else {
690                 force_ok = true;
691                 fl_set_button(pFileDlgForm->Ready, 1);
692         }
693         // Start timer to break fl_do_forms loop soon
694         fl_set_timer(pFileDlgForm->timer, 0.1);
695 }
696
697
698 // Select: launches dialog and returns selected file
699 string const LyXFileDlg::Select(string const & title, string const & path, 
700                                 string const & mask, string const & suggested)
701 {
702         // handles new mask and path
703         bool isOk = true;
704         if (!mask.empty()) {
705                 SetMask(mask);
706                 isOk = false;
707         }
708         if (!path.empty()) {
709                 SetDirectory(path);
710                 isOk = false;
711         }
712         if (!isOk) Reread();
713
714         // highlight the suggested file in the browser, if it exists.
715         int sel = 0;
716         string const filename = OnlyFilename(suggested);
717         if (!filename.empty()) {
718                 for (int i = 0; 
719                      i < fl_get_browser_maxline(pFileDlgForm->List); ++i) {
720                         string s =
721                                 fl_get_browser_line(pFileDlgForm->List, i + 1);
722                         s = strip(frontStrip(s));
723                         if (s == filename) {
724                                 sel = i + 1;
725                                 break;
726                         }
727                 }
728         }
729         
730         if (sel != 0) fl_select_browser_line(pFileDlgForm->List, sel);
731         int const top = max(sel - 5, 1);
732         fl_set_browser_topline(pFileDlgForm->List, top);
733
734         // checks whether dialog can be started
735         if (pCurrentDlg) return string();
736         pCurrentDlg = this;
737
738         // runs dialog
739         SetInfoLine(string());
740         fl_set_input(pFileDlgForm->Filename, suggested.c_str());
741         fl_set_button(pFileDlgForm->Cancel, 0);
742         fl_set_button(pFileDlgForm->Ready, 0);
743         fl_set_focus_object(pFileDlgForm->FileDlg, pFileDlgForm->Filename);
744         fl_deactivate_all_forms();
745         fl_show_form(pFileDlgForm->FileDlg, 
746                      FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
747                      title.c_str());
748
749         isOk = RunDialog();
750         
751         fl_hide_form(pFileDlgForm->FileDlg);
752         fl_activate_all_forms();
753         pCurrentDlg = 0;
754
755         // Returns filename or string() if no valid selection was made
756         if (!isOk || !fl_get_input(pFileDlgForm->Filename)[0]) return string();
757
758         pszFileName = fl_get_input(pFileDlgForm->Filename);
759
760         if (!AbsolutePath(pszFileName)) {
761                 pszFileName = AddName(fl_get_input(pFileDlgForm->DirBox), 
762                                       pszFileName);
763         }
764         return pszFileName;
765 }