]> git.lyx.org Git - features.git/commitdiff
(J��rgen Spitzm��ller): implement a BrowseDir capablility in the File Dialog.
authorAngus Leeming <leeming@lyx.org>
Tue, 14 Jan 2003 21:51:34 +0000 (21:51 +0000)
committerAngus Leeming <leeming@lyx.org>
Tue, 14 Jan 2003 21:51:34 +0000 (21:51 +0000)
Fixes bug 824.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5955 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/frontends/ChangeLog
src/frontends/FileDialog.h
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlPrefs.C
src/frontends/controllers/ControlPrefs.h
src/frontends/controllers/helper_funcs.C
src/frontends/controllers/helper_funcs.h
src/frontends/qt2/ChangeLog
src/frontends/qt2/FileDialog.C
src/frontends/qt2/QPrefsDialog.C
src/frontends/xforms/FileDialog.C
src/frontends/xforms/FormFiledialog.C
src/frontends/xforms/FormFiledialog.h
src/frontends/xforms/FormPreferences.C

index ed7fe8902c63a45b9d8ea791b3d90bb7aa32c36c..e6c9967f3e8330ecaf026e5ac18a0d48f89ea815 100644 (file)
@@ -1,3 +1,7 @@
+2003-01-11  Juergen Spitzmueller  <j.spitzmueller@gmx.de>
+
+       * FileDialog.h: implement opendir (browse directory) [bug 824]
+
 2003-01-12  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * Makefile.am (LIBS): delete
index 633eba4401042f1196c683a0253b35ff6411eeb0..0ac2899f7f08c80d995810a4fc47131b4be9269f 100644 (file)
@@ -77,6 +77,13 @@ public:
        Result const open(string const & path = string(),
                string const & mask = string(),
                string const & suggested = string());
+               
+       /**
+        * Choose a directory, starting in directory \param
+        * path.
+        */
+       Result const opendir(string const & path = string(),
+               string const & suggested = string());
 
        /**
         * Choose a file for saving, starting in directory \param
index 8665b2c666f24597f7cb1844f983b180afe8a668..1c29e38de942b06961e0b14bb6fea5d57f54cd8b 100644 (file)
@@ -1,3 +1,9 @@
+2003-01-11  Juergen Spitzmueller  <j.spitzmueller@gmx.de>
+
+       * helper_funcs.[Ch]: implement browseDir (browse directory) [bug 824]
+       
+       * ControlPrefs.[Ch]: implement browsedir for the use of use browseDir.
+
 2002-12-02  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * ControlDocument.C: use BoostFormat.h instead of boost/format.hpp
index fea1d823c1aa8d58005b65a859ade660588e1ce3..660149bc9fa3dd8cf7a9c9dd58a1a0c50553aec2 100644 (file)
@@ -110,6 +110,12 @@ string const ControlPrefs::browse(string const & file, string const & title)
 }
 
 
+string const ControlPrefs::browsedir(string const & path, string const & title)
+{
+       return browseDir(&lv_, path, title);
+}
+
+
 void ControlPrefs::redrawGUI()
 {
        // we must be sure to get the new values first
index 0d110aa89ea31ce20a60ae3157254fbd553e8c06..10d9a74e5cfdc60cb64ebd7eba2b3743b88a4bad 100644 (file)
@@ -47,6 +47,9 @@ public:
 
        /// general browse
        string const browse(string const & file, string const & title);
+       
+       /// browse directory
+       string const browsedir(string const & path, string const & title);
 
        /// redraw widgets (for xforms color change)
        void redrawGUI();
index e853bb6cdcfa59da6382bad2193f8f559fc28bd7..8fa6d4d9d436d83700cc1d55c19abe0f78d039b2 100644 (file)
@@ -89,6 +89,40 @@ string const browseRelFile(LyXView * lv, string const & filename,
 }
 
 
+string const browseDir(LyXView * lv, string const & pathname,
+                       string const & title,
+                       pair<string,string> const & dir1,
+                       pair<string,string> const & dir2)
+{
+       string lastPath(".");
+       if (!pathname.empty())
+               lastPath = OnlyPath(pathname);
+
+       FileDialog fileDlg(lv, title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
+
+       FileDialog::Result result;
+
+       while (true) {
+               result = fileDlg.opendir(lastPath,
+                               OnlyFilename(pathname));
+
+               if (result.second.empty())
+                       return result.second;
+
+               lastPath = OnlyPath(result.second);
+
+               if (result.second.find_first_of("#~$% ") == string::npos)
+                       break;
+
+               Alert::alert(_("directory name can't contain any "
+                       "of these characters:"),
+                       _("space, '#', '~', '$' or '%'."));
+       }
+
+       return result.second;
+}
+
+
 // sorry this is just a temporary hack we should include vspace.h! (Jug)
 extern const char * stringFromUnit(int);
 
index fa1e689e052ee22d4e00cbc1ea1ba32e46ad5ae1..ea84e07dd423d0922592668c87fc8d094d1a5fb5 100644 (file)
@@ -58,6 +58,20 @@ browseRelFile(LyXView * lv, string const & filename,
              std::make_pair(string(), string()));
 
 
+/** Launch a file dialog and return the chosen directory.
+    pathname: a suggested pathname.
+    title: the title of the dialog.
+    dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
+*/
+string const
+browseDir(LyXView * lv, string const & pathname,
+          string const & title,
+          std::pair<string,string> const & dir1 =
+          std::make_pair(string(), string()),
+          std::pair<string,string> const & dir2 =
+          std::make_pair(string(), string()));
+
+
 /// Returns a vector of units that can be used to create a valid LaTeX length.
 std::vector<string> const getLatexUnits();
 
index 618d2fc19b8db3ce707055468200a5fb604dab18..9afe657fb30c623e5eb64c9734bb73d295263c40 100644 (file)
@@ -1,3 +1,9 @@
+2003-01-11  Juergen Spitzmueller  <j.spitzmueller@gmx.de>
+
+       * FileDialog.C: implement opendir [bug 824], fix mask.
+
+       * QPrefsDialog.C: use browsedir for paths [bug 824]
+
 2003-01-13  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * qgridview.cpp: rename to...
@@ -53,6 +59,7 @@
 
        * QtView.h:
        * QtView.C:
+
 2003-01-04  Juergen Spitzmueller  <j.spitzmueller@gmx.de>
 
        * QURL.C: isValid(): fix validation.
index 28a5342392e0753ae27672f9192bb6fa572ced66..de126c81f65c02f9c1f2d885fb7cb5b0a9338b07 100644 (file)
@@ -88,7 +88,7 @@ FileDialog::Result const FileDialog::open(string const & path,
 {
        string filter(mask);
        if (mask.empty())
-               filter = _("*|All files");
+               filter = _("All files (*)");
 
        LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
        lyxerr[Debug::GUI] << "Select with path \"" << path
@@ -108,3 +108,29 @@ FileDialog::Result const FileDialog::open(string const & path,
        dlg.hide();
        return result;
 }
+
+
+FileDialog::Result const FileDialog::opendir(string const & path,
+                                           string const & suggested)
+{
+       string filter = _("Directories");
+
+       LyXFileDialog dlg(path, filter, title_, private_->b1, private_->b2);
+       lyxerr[Debug::GUI] << "Select with path \"" << path
+                          << "\", suggested \"" << suggested << endl;
+
+       dlg.setMode(QFileDialog::DirectoryOnly);
+
+       if (!suggested.empty())
+               dlg.setSelection(toqstr(suggested));
+
+       FileDialog::Result result;
+       lyxerr[Debug::GUI] << "Synchronous FileDialog: " << endl;
+       result.first = FileDialog::Chosen;
+       int res = dlg.exec();
+       lyxerr[Debug::GUI] << "result " << res << endl;
+       if (res == QDialog::Accepted)
+               result.second = string(dlg.selectedFile().data());
+       dlg.hide();
+       return result;
+}
\ No newline at end of file
index 25f1058c754685b9f8b19d6dd4597c783a682e27..3fef978421a31c3f7c4cda7e2c9de8c77cd8df0d 100644 (file)
@@ -545,7 +545,7 @@ void QPrefsDialog::select_dict()
 
 void QPrefsDialog::select_templatedir()
 {
-       string file(form_->controller().browse(fromqstr(pathsModule->templateDirED->text()), _("Select a document templates directory")));
+       string file(form_->controller().browsedir(fromqstr(pathsModule->templateDirED->text()), _("Select a document templates directory")));
        if (!file.empty())
                pathsModule->templateDirED->setText(toqstr(file));
 }
@@ -553,7 +553,7 @@ void QPrefsDialog::select_templatedir()
 
 void QPrefsDialog::select_tempdir()
 {
-       string file(form_->controller().browse(fromqstr(pathsModule->tempDirED->text()), _("Select a temporary directory")));
+       string file(form_->controller().browsedir(fromqstr(pathsModule->tempDirED->text()), _("Select a temporary directory")));
        if (!file.empty())
                pathsModule->tempDirED->setText(toqstr(file));
 }
@@ -561,7 +561,7 @@ void QPrefsDialog::select_tempdir()
 
 void QPrefsDialog::select_backupdir()
 {
-       string file(form_->controller().browse(fromqstr(pathsModule->backupDirED->text()), _("Select a backups directory")));
+       string file(form_->controller().browsedir(fromqstr(pathsModule->backupDirED->text()), _("Select a backups directory")));
        if (!file.empty())
                pathsModule->backupDirED->setText(toqstr(file));
 }
@@ -569,7 +569,7 @@ void QPrefsDialog::select_backupdir()
 
 void QPrefsDialog::select_workingdir()
 {
-       string file(form_->controller().browse(fromqstr(pathsModule->workingDirED->text()), _("Select a document directory")));
+       string file(form_->controller().browsedir(fromqstr(pathsModule->workingDirED->text()), _("Select a document directory")));
        if (!file.empty())
                pathsModule->workingDirED->setText(toqstr(file));
 }
index e629237bf3af7ce5ea26d8a4a2735a700a70b1a6..23306538e2d9850ee74a1dbcf21a34603ff051f8 100644 (file)
@@ -54,6 +54,26 @@ FileDialog::Result const FileDialog::save(string const & path, string const & ma
 }
 
 
+FileDialog::Result const FileDialog::opendir(string const & path, string const & suggested)
+{
+       lyxerr[Debug::GUI] << "filedialog open  with path \"" << path << "\", suggested \"" 
+               << suggested << '"' << endl;
+
+       // no support for asynchronous selection yet
+
+       lv_->prohibitInput();
+
+       FileDialog::Result result;
+
+       result.first = FileDialog::Chosen;
+       result.second = private_->SelectDir(title_, path, suggested);
+
+       lv_->allowInput();
+
+       return result;
+}
+
+
 FileDialog::Result const FileDialog::open(string const & path, string const & mask, string const & suggested)
 {
        string filter = mask;
index 029fcff83361411d91665b38d8cbc35f8d4081d4..027ee217f24a01e30d8b7e877a360793e5817919 100644 (file)
@@ -29,6 +29,7 @@ using std::sort;
 #include "gettext.h"
 #include "frontends/Dialogs.h"
 #include "forms_gettext.h"
+#include "xforms_helpers.h"
 
 #include <boost/bind.hpp>
 
@@ -736,6 +737,7 @@ string const FileDialog::Private::Select(string const & title,
 
        // runs dialog
        SetInfoLine(string());
+       setEnabled(file_dlg_form_->Filename, true);
        fl_set_input(file_dlg_form_->Filename, suggested.c_str());
        fl_set_button(file_dlg_form_->Cancel, 0);
        fl_set_button(file_dlg_form_->Ready, 0);
@@ -767,3 +769,65 @@ string const FileDialog::Private::Select(string const & title,
                file_name_ = AddName(fl_get_input(file_dlg_form_->DirBox), file_name_);
        return file_name_;
 }
+
+
+// SelectDir: launches dialog and returns selected directory
+string const FileDialog::Private::SelectDir(string const & title,
+                                        string const & path,
+                                        string const & suggested)
+{
+       SetMask("*/");
+       // handles new path
+       bool isOk = true;
+       if (!path.empty()) {
+               // handle case where path does not end with "/"
+               // remerge path+suggested and check if it is a valid path
+               if (!suggested.empty()) {
+                       string tmp = suggested;
+                       if (!suffixIs(tmp, '/'))
+                               tmp += '/';
+                       string full_path = path;
+                       full_path += tmp;
+                       // check if this is really a directory
+                       DIR * dir = ::opendir(full_path.c_str());
+                       if (dir)
+                               SetDirectory(full_path);
+                       else
+                               SetDirectory(path);
+               } else
+                       SetDirectory(path);
+               isOk = false;
+       }
+       if (!isOk)
+               Reread();
+
+       // checks whether dialog can be started
+       if (current_dlg_)
+               return string();
+       current_dlg_ = this;
+
+       // runs dialog
+       SetInfoLine(string());
+       fl_set_input(file_dlg_form_->Filename, "");
+       setEnabled(file_dlg_form_->Filename, false);
+       fl_set_button(file_dlg_form_->Cancel, 0);
+       fl_set_button(file_dlg_form_->Ready, 0);
+       fl_set_focus_object(file_dlg_form_->form, file_dlg_form_->DirBox);
+       fl_deactivate_all_forms();
+       fl_show_form(file_dlg_form_->form,
+                    FL_PLACE_MOUSE | FL_FREE_SIZE, 0,
+                    title.c_str());
+
+       isOk = RunDialog();
+
+       fl_hide_form(file_dlg_form_->form);
+       fl_activate_all_forms();
+       current_dlg_ = 0;
+
+       // Returns directory or string() if no valid selection was made
+       if (!isOk)
+               return string();
+
+       file_name_ = fl_get_input(file_dlg_form_->DirBox);
+       return file_name_;
+}
index 02228445080a2fe595dd62773b40a319a440ddbb..8dbc73ab6f18df5cd45b1ea316a5418e9022898e 100644 (file)
@@ -69,6 +69,10 @@ public:
                       string const & pszPath = string(),
                       string const & pszMask = string(),
                       string const & pszSuggested = string());
+       /// launches dialog and returns selected directory
+       string const SelectDir(string const & pszTitle = string(),
+                      string const & pszPath = string(),
+                      string const & pszSuggested = string());
        /// XForms objects callback (static)
        static void FileDlgCB(FL_OBJECT *, long);
        /// Callback for double click in list
index 4e50c2d4c4255cf2bc784f5969f2021eb02b9500..9321ef1c7e6a1ec2781148f19a3d1d4a1405a425 100644 (file)
@@ -2186,29 +2186,35 @@ bool FormPreferences::Paths::input(FL_OBJECT const * const ob)
        }
 
        if (ob == dialog_->button_default_path_browse) {
-               string f = parent_.controller().browse(
+               string f = parent_.controller().browsedir(
                        fl_get_input(dialog_->input_default_path), _("Default path"));
-               fl_set_input(dialog_->input_default_path, f.c_str());
+               if (!f.empty())
+                       fl_set_input(dialog_->input_default_path, f.c_str());
        } else if (ob == dialog_->button_template_path_browse) {
-               string f = parent_.controller().browse(
+               string f = parent_.controller().browsedir(
                        fl_get_input(dialog_->input_template_path), _("Template path"));
-               fl_set_input(dialog_->input_template_path, f.c_str());
+               if (!f.empty())
+                       fl_set_input(dialog_->input_template_path, f.c_str());
        } else if (ob == dialog_->button_temp_dir_browse) {
-               string f = parent_.controller().browse(
+               string f = parent_.controller().browsedir(
                        fl_get_input(dialog_->input_temp_dir), _("Temporary dir"));
-               fl_set_input(dialog_->input_temp_dir, f.c_str());
+               if (!f.empty())
+                       fl_set_input(dialog_->input_temp_dir, f.c_str());
        } else if (ob == dialog_->button_lastfiles_browse) {
                string f = parent_.controller().browse(
                        fl_get_input(dialog_->input_lastfiles), _("Last files"));
-               fl_set_input(dialog_->input_lastfiles, f.c_str());
+               if (!f.empty())
+                       fl_set_input(dialog_->input_lastfiles, f.c_str());
        } else if (ob == dialog_->button_backup_path_browse) {
-               string f = parent_.controller().browse(
+               string f = parent_.controller().browsedir(
                        fl_get_input(dialog_->input_backup_path), _("Backup path"));
-               fl_set_input(dialog_->input_backup_path, f.c_str());
+               if (!f.empty())
+                       fl_set_input(dialog_->input_backup_path, f.c_str());
        } else if (ob == dialog_->button_serverpipe_browse) {
                string f = parent_.controller().browse(
                        fl_get_input(dialog_->input_serverpipe), _("LyX server pipes"));
-               fl_set_input(dialog_->input_serverpipe, f.c_str());
+               if (!f.empty())
+                       fl_set_input(dialog_->input_serverpipe, f.c_str());
        }
 
        return activate;