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