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