From 880878152037540c4171f011f7316e036cf90747 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Wed, 25 May 2005 11:18:36 +0000 Subject: [PATCH] Fix bug 1272 and return relative paths from the file browser if appropriate. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_3_X@9969 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ChangeLog | 9 ++++++ src/frontends/controllers/ControlBibtex.C | 16 +++++++--- src/frontends/controllers/ControlBibtex.h | 6 ++-- src/frontends/controllers/ControlExternal.C | 3 -- src/frontends/qt2/ChangeLog | 8 +++++ src/frontends/qt2/QBibtexDialog.C | 33 ++++++++++----------- src/frontends/qt2/QExternalDialog.C | 12 +++----- src/frontends/qt2/QGraphicsDialog.C | 6 ++-- src/frontends/qt2/QLPrintDialog.C | 12 +++----- src/frontends/xforms/ChangeLog | 5 ++++ src/frontends/xforms/FormBibtex.C | 9 ++---- 11 files changed, 68 insertions(+), 51 deletions(-) diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 4f6ec6c5ea..3f0a215525 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,12 @@ +2005-05-24 Angus Leeming + + * ControlBibtex.C (browseBib, browseBst): backport 1.4.x code + that defines separate interfaces to the file browser for + .bib and .bst files. + + * ControlExternal.C (Browse): remove hack that adds a '|' to the + list of filters. + 2005-05-23 Angus Leeming * helper_funcs.[Ch] (browseFile, browseRelFile, browseDir): add diff --git a/src/frontends/controllers/ControlBibtex.C b/src/frontends/controllers/ControlBibtex.C index fc0cce18ee..033303ce51 100644 --- a/src/frontends/controllers/ControlBibtex.C +++ b/src/frontends/controllers/ControlBibtex.C @@ -54,14 +54,22 @@ void ControlBibtex::applyParamsNoInset() {} -string const ControlBibtex::Browse(string const & in_name, - string const & title, - string const & pattern) +string const ControlBibtex::browseBib(string const & in_name) const { pair dir1(_("Documents|#o#O"), string(lyxrc.document_path)); return browseRelFile(&lv_, true, in_name, buffer()->filePath(), - title, pattern, false, dir1); + _("Select a BibTeX database to add"), + "*.bib", false, dir1); +} + + +string const ControlBibtex::browseBst(string const & in_name) const +{ + pair dir1(_("Documents|#o#O"), + string(lyxrc.document_path)); + return browseRelFile(&lv_, true, in_name, buffer()->filePath(), + _("Select a BibTeX style"), "*.bst", false, dir1); } diff --git a/src/frontends/controllers/ControlBibtex.h b/src/frontends/controllers/ControlBibtex.h index 693b817182..98e0e436b6 100644 --- a/src/frontends/controllers/ControlBibtex.h +++ b/src/frontends/controllers/ControlBibtex.h @@ -21,8 +21,10 @@ class ControlBibtex : public ControlCommand { public: /// ControlBibtex(LyXView &, Dialogs &); - /// Browse for a file - string const Browse(string const &, string const &, string const &); + /// Browse for a .bib file + std::string const browseBib(std::string const & in_name) const; + /// Browse for a .bst file + std::string const browseBst(std::string const & in_name) const; /// get the list of bst files string const getBibStyles() const; /// build filelists of all availabe bst/cls/sty-files. done through diff --git a/src/frontends/controllers/ControlExternal.C b/src/frontends/controllers/ControlExternal.C index 699e674ba6..57ed476255 100644 --- a/src/frontends/controllers/ControlExternal.C +++ b/src/frontends/controllers/ControlExternal.C @@ -144,9 +144,6 @@ string const ControlExternal::Browse(string const & input) const if (pattern.empty()) pattern = "*"; - // FIXME: a temporary hack until the FileDialog interface is updated - pattern += '|'; - std::pair dir1(N_("Documents|#o#O"), string(lyxrc.document_path)); diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 2b41174766..ef00446e3e 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,11 @@ +2005-05-24 Angus Leeming + + * QExternalDialog.C (browseClicked): + * QBibtexDialog.C (browsePressed, browseBibPressed): + * QLPrintDialog.C (browseClicked): + backport 1.4.x code to use the controller's browse member function + rather than QFileDialog::getOpenFileName + 2005-05-12 Jürgen Spitzmüller * QTabularDialog.C: Fix handling of longtabular lfuns. diff --git a/src/frontends/qt2/QBibtexDialog.C b/src/frontends/qt2/QBibtexDialog.C index 770157e597..853c420f22 100644 --- a/src/frontends/qt2/QBibtexDialog.C +++ b/src/frontends/qt2/QBibtexDialog.C @@ -50,39 +50,35 @@ void QBibtexDialog::change_adaptor() void QBibtexDialog::browsePressed() { - QString const file = - QFileDialog::getOpenFileName(QString::null, - qt_("BibTeX style files (*.bst)"), - this, - 0, - qt_("Select a BibTeX style")); - if (!file.isNull()) { - string const filen = ChangeExtension(fromqstr(file), ""); - bool present = false; - int pres = 0; + string const file = form_->controller().browseBst(""); - for (unsigned int i = 0; i != styleCB->count(); i++) { + if (!file.empty()) { + string const filen = ChangeExtension(file, ""); + bool present = false; + unsigned int pres = 0; + + for (int i = 0; i != styleCB->count(); ++i) { if (fromqstr(styleCB->text(i)) == filen) { present = true; pres = i; } } - if (!present) + if (!present) styleCB->insertItem(toqstr(filen),0); - + styleCB->setCurrentItem(pres); form_->changed(); } } + void QBibtexDialog::browseBibPressed() { - QString const file = QFileDialog::getOpenFileName(QString::null, - qt_("BibTeX database files (*.bib)"), this, 0, qt_("Select a BibTeX database to add")); + string const file = form_->controller().browseBib(""); - if (!file.isNull()) { - string const f = ChangeExtension(fromqstr(file), ""); + if (!file.empty()) { + string const f = ChangeExtension(file, ""); bool present = false; for (unsigned int i = 0; i != databaseLB->count(); i++) { @@ -94,9 +90,12 @@ void QBibtexDialog::browseBibPressed() databaseLB->insertItem(toqstr(f)); form_->changed(); } + + addBibED->setText(toqstr(f)); } } + void QBibtexDialog::addPressed() { QString const file = addBibED->text(); diff --git a/src/frontends/qt2/QExternalDialog.C b/src/frontends/qt2/QExternalDialog.C index 1b9c901594..8b397a86c6 100644 --- a/src/frontends/qt2/QExternalDialog.C +++ b/src/frontends/qt2/QExternalDialog.C @@ -15,7 +15,6 @@ #include #include -#include #include #include #include @@ -80,13 +79,10 @@ void QExternalDialog::updateClicked() void QExternalDialog::browseClicked() { - QString file = - QFileDialog::getOpenFileName(QString::null, - qt_("External material (*)"), - this, 0, - qt_("Select external material")); - if (!file.isNull()) { - fileED->setText(file); + string const str = + form_->controller().Browse(fromqstr(fileED->text())); + if (!str.empty()) { + fileED->setText(toqstr(str)); form_->changed(); } } diff --git a/src/frontends/qt2/QGraphicsDialog.C b/src/frontends/qt2/QGraphicsDialog.C index 488638dda8..ee4419fd0a 100644 --- a/src/frontends/qt2/QGraphicsDialog.C +++ b/src/frontends/qt2/QGraphicsDialog.C @@ -88,8 +88,10 @@ void QGraphicsDialog::browse_clicked() { string const str = form_->controller().Browse(fromqstr(filename->text())); - filename->setText(toqstr(str)); - form_->changed(); + if (!str.empty()) { + filename->setText(toqstr(str)); + form_->changed(); + } } diff --git a/src/frontends/qt2/QLPrintDialog.C b/src/frontends/qt2/QLPrintDialog.C index e50e8e84e9..9634b01148 100644 --- a/src/frontends/qt2/QLPrintDialog.C +++ b/src/frontends/qt2/QLPrintDialog.C @@ -11,9 +11,9 @@ #include +#include "controllers/ControlPrint.h" #include "qt_helpers.h" #include "support/filetools.h" -#include "support/lstrings.h" #include "QPrint.h" #include "QLPrintDialog.h" @@ -46,13 +46,9 @@ void QLPrintDialog::change_adaptor() void QLPrintDialog::browseClicked() { - QString file = - QFileDialog::getOpenFileName(QString::null, - qt_("PostScript files (*.ps)"), - this, 0, - qt_("Select a file to print to")); - if (!file.isNull()) { - fileED->setText(file); + string const file = form_->controller().Browse(""); + if (!file.empty()) { + fileED->setText(toqstr(file)); form_->changed(); } } diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 065e971da2..0c842d8ecf 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2005-05-24 Angus Leeming + + * FormBibtex.C (input): use the broseBib() and browseBst() functions + in the controller, backported from 1.4.x. + 2005-05-09 Angus Leeming * FormPreferences.C (SpellOptions::build): disable the diff --git a/src/frontends/xforms/FormBibtex.C b/src/frontends/xforms/FormBibtex.C index 41886d743d..03c50d820f 100644 --- a/src/frontends/xforms/FormBibtex.C +++ b/src/frontends/xforms/FormBibtex.C @@ -100,10 +100,7 @@ ButtonPolicy::SMInput FormBibtex::input(FL_OBJECT * ob, long) if (ob == dialog_->button_database_browse) { // When browsing, take the first file only string const in_name = getString(dialog_->input_database); - string out_name = - controller().Browse("", - _("Select Database"), - _("*.bib| BibTeX Databases (*.bib)")); + string out_name = controller().browseBib(""); if (!out_name.empty()) { // add the database to any existing ones if (!in_name.empty()) @@ -114,9 +111,7 @@ ButtonPolicy::SMInput FormBibtex::input(FL_OBJECT * ob, long) } else if (ob == dialog_->button_style_browse) { string const in_name = getString(dialog_->input_style); - string const style = controller().Browse(in_name, - _("Select BibTeX-Style"), - _("*.bst| BibTeX Styles (*.bst)")); + string const style = controller().browseBst(in_name); if (!style.empty()) { fl_set_input(dialog_->input_style, style.c_str()); }