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