diff --git a/src/frontends/controllers/ControlBibtex.cpp b/src/frontends/controllers/ControlBibtex.cpp deleted file mode 100644 index fe14ec9c37..0000000000 --- a/src/frontends/controllers/ControlBibtex.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/** - * \file ControlBibtex.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author John Levon - * \author Angus Leeming - * \author Herbert Voß - * - * Full author contact details are available in file CREDITS. - */ - -#include - -#include "ControlBibtex.h" -#include "frontend_helpers.h" - -#include "Buffer.h" -#include "BufferParams.h" - -#include "LyXRC.h" -#include "gettext.h" - -#include "support/FileFilterList.h" -#include "support/filetools.h" -#include "support/lstrings.h" - -using std::pair; -using std::string; -using std::vector; - - -namespace lyx { - -using support::contains; -using support::FileFilterList; -using support::onlyFilename; -using support::prefixIs; -using support::split; - -namespace frontend { - - -ControlBibtex::ControlBibtex(Dialog & d) - : ControlCommand(d, "bibtex") -{} - - -docstring const ControlBibtex::browseBib(docstring const & in_name) const -{ - // FIXME UNICODE - pair dir1(_("Documents|#o#O"), - from_utf8(lyxrc.document_path)); - FileFilterList const filter(_("BibTeX Databases (*.bib)")); - return browseRelFile(in_name, from_utf8(bufferFilepath()), - _("Select a BibTeX database to add"), - filter, false, dir1); -} - - -docstring const ControlBibtex::browseBst(docstring const & in_name) const -{ - // FIXME UNICODE - pair dir1(_("Documents|#o#O"), - from_utf8(lyxrc.document_path)); - FileFilterList const filter(_("BibTeX Styles (*.bst)")); - return browseRelFile(in_name, from_utf8(bufferFilepath()), - _("Select a BibTeX style"), filter, false, dir1); -} - - -void ControlBibtex::getBibStyles(vector & data) const -{ - data.clear(); - - getTexFileList("bstFiles.lst", data); - // test, if we have a valid list, otherwise run rescan - if (data.empty()) { - rescanBibStyles(); - getTexFileList("bstFiles.lst", data); - } - vector::iterator it = data.begin(); - vector::iterator end = data.end(); - for (; it != end; ++it) { - *it = onlyFilename(*it); - } - // sort on filename only (no path) - std::sort(data.begin(), data.end()); -} - - -void ControlBibtex::getBibFiles(vector & data) const -{ - data.clear(); - - getTexFileList("bibFiles.lst", data); - // test, if we have a valid list, otherwise run rescan - if (data.empty()) { - rescanBibStyles(); - getTexFileList("bibFiles.lst", data); - } - vector::iterator it = data.begin(); - vector::iterator end = data.end(); - for (; it != end; ++it) { - *it = onlyFilename(*it); - } - // sort on filename only (no path) - std::sort(data.begin(), data.end()); -} - - -void ControlBibtex::rescanBibStyles() const -{ - rescanTexStyles(); -} - - -bool ControlBibtex::usingBibtopic() const -{ - return buffer().params().use_bibtopic; -} - - -bool ControlBibtex::bibtotoc() const -{ - return prefixIs(to_utf8(params()["options"]), "bibtotoc"); -} - - -string const ControlBibtex::getStylefile() const -{ - // the different bibtex packages have (and need) their - // own "plain" stylefiles - biblio::CiteEngine const engine = buffer().params().getEngine(); - docstring defaultstyle; - switch (engine) { - case biblio::ENGINE_BASIC: - defaultstyle = from_ascii("plain"); - break; - case biblio::ENGINE_NATBIB_AUTHORYEAR: - defaultstyle = from_ascii("plainnat"); - break; - case biblio::ENGINE_NATBIB_NUMERICAL: - defaultstyle = from_ascii("plainnat"); - break; - case biblio::ENGINE_JURABIB: - defaultstyle = from_ascii("jurabib"); - break; - } - - docstring bst = params()["options"]; - if (bibtotoc()){ - // bibstyle exists? - if (contains(bst, ',')) { - docstring bibtotoc = from_ascii("bibtotoc"); - bst = split(bst, bibtotoc, ','); - } else - bst.erase(); - } - - // propose default style file for new insets - // existing insets might have (legally) no bst files - // (if the class already provides a style) - if (bst.empty() && params()["bibfiles"].empty()) - bst = defaultstyle; - - // FIXME UNICODE - return to_utf8(bst); -} - -} // namespace frontend -} // namespace lyx diff --git a/src/frontends/controllers/ControlBibtex.h b/src/frontends/controllers/ControlBibtex.h deleted file mode 100644 index 956665b28f..0000000000 --- a/src/frontends/controllers/ControlBibtex.h +++ /dev/null @@ -1,60 +0,0 @@ -// -*- C++ -*- -/** - * \file ControlBibtex.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author John Levon - * \author Angus Leeming - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef CONTROLBIBTEX_H -#define CONTROLBIBTEX_H - -#include "ControlCommand.h" - -#include "support/docstring.h" - -#include - -namespace lyx { - -namespace support { class FileFilterList; } - - -namespace frontend { - -/** A controller for Bibtex dialogs. - */ -class ControlBibtex : public ControlCommand { -public: - /// - ControlBibtex(Dialog &); - - /// Browse for a .bib file - docstring const browseBib(docstring const & in_name) const; - - /// Browse for a .bst file - docstring const browseBst(docstring const & in_name) const; - - /// get the list of bst files - void getBibStyles(std::vector & data) const; - /// get the list of bib files - void getBibFiles(std::vector & data) const; - /// build filelists of all availabe bib/bst/cls/sty-files. done through - /// kpsewhich and an external script, saved in *Files.lst - void rescanBibStyles() const; - /// do we use bibtopic (for sectioned bibliography)? - bool usingBibtopic() const; - /// should we put the bibliography to the TOC? - bool bibtotoc() const; - /// which stylefile do we use? - std::string const getStylefile() const; -}; - -} // namespace frontend -} // namespace lyx - -#endif // CONTROLBIBTEX_H diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index a4882ab65c..72812b0a9c 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -9,7 +9,6 @@ noinst_LTLIBRARIES = liblyxcontrollers.la SOURCEFILES = \ Dialog.cpp \ ButtonPolicy.cpp \ - ControlBibtex.cpp \ ControlBox.cpp \ ControlCharacter.cpp \ ControlChanges.cpp \ @@ -37,7 +36,6 @@ SOURCEFILES = \ HEADERFILES = \ ButtonPolicy.h \ - ControlBibtex.h \ ControlBox.h \ ControlCharacter.h \ ControlChanges.h \ diff --git a/src/frontends/qt4/Dialogs.cpp b/src/frontends/qt4/Dialogs.cpp index 307adc0280..a5486392ce 100644 --- a/src/frontends/qt4/Dialogs.cpp +++ b/src/frontends/qt4/Dialogs.cpp @@ -16,9 +16,7 @@ #include "ButtonController.h" #include "DialogView.h" #include "DockView.h" -#include "GuiAbout.h" #include "GuiBibitem.h" -#include "GuiBibtex.h" #include "GuiBox.h" #include "GuiChanges.h" #include "GuiCharacter.h" @@ -154,11 +152,11 @@ Dialog * Dialogs::build(string const & name) GuiViewBase & guiview = static_cast(lyxview_); if (name == "aboutlyx") { - dialog = new GuiAboutDialog(lyxview_); + dialog = createGuiAbout(lyxview_); } else if (name == "bibitem") { dialog = new GuiBibitemDialog(lyxview_); } else if (name == "bibtex") { - dialog = new GuiBibtexDialog(lyxview_); + dialog = createGuiBibtex(lyxview_); } else if (name == "box") { dialog = new GuiBoxDialog(lyxview_); } else if (name == "branch") { diff --git a/src/frontends/qt4/GuiAbout.cpp b/src/frontends/qt4/GuiAbout.cpp index 158457a483..484c06a35d 100644 --- a/src/frontends/qt4/GuiAbout.cpp +++ b/src/frontends/qt4/GuiAbout.cpp @@ -95,23 +95,12 @@ static QString version() } -class ControlAbout : public Controller -{ -public: - ControlAbout(Dialog & parent) : Controller(parent) {} - bool initialiseParams(std::string const &) { return true; } - void clearParams() {} - void dispatchParams() {} - bool isBufferDependent() const { return false; } -}; - - -GuiAboutDialog::GuiAboutDialog(LyXView & lv) - : GuiDialog(lv, "aboutlyx") +GuiAbout::GuiAbout(LyXView & lv) + : GuiDialog(lv, "aboutlyx"), Controller(this) { setupUi(this); setViewTitle(_("About LyX")); - setController(new ControlAbout(*this)); + setController(this, false); connect(closePB, SIGNAL(clicked()), this, SLOT(reject())); @@ -125,6 +114,10 @@ GuiAboutDialog::GuiAboutDialog(LyXView & lv) creditsTB->setHtml(credits()); } + +Dialog * createGuiAbout(LyXView & lv) { return new GuiAbout(lv); } + + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiAbout.h b/src/frontends/qt4/GuiAbout.h index 2567d7ca8a..a68cd6810a 100644 --- a/src/frontends/qt4/GuiAbout.h +++ b/src/frontends/qt4/GuiAbout.h @@ -18,13 +18,19 @@ namespace lyx { namespace frontend { -class GuiAboutDialog : public GuiDialog, public Ui::AboutUi +class GuiAbout : public GuiDialog, public Ui::AboutUi, public Controller { Q_OBJECT public: // Constructor - GuiAboutDialog(LyXView & lv); + GuiAbout(LyXView & lv); + + // Controller stuff + bool initialiseParams(std::string const &) { return true; } + void clearParams() {} + void dispatchParams() {} + bool isBufferDependent() const { return false; } }; } // namespace frontend diff --git a/src/frontends/qt4/GuiBibtex.cpp b/src/frontends/qt4/GuiBibtex.cpp index 4b5fd27721..8e3e49033f 100644 --- a/src/frontends/qt4/GuiBibtex.cpp +++ b/src/frontends/qt4/GuiBibtex.cpp @@ -5,6 +5,7 @@ * * \author John Levon * \author Herbert Voß + * \author Angus Leeming * \author Jürgen Spitzmüller * * Full author contact details are available in file CREDITS. @@ -14,16 +15,23 @@ #include "GuiBibtex.h" +#include "Buffer.h" +#include "BufferParams.h" +#include "debug.h" #include "ui_BibtexAddUi.h" #include "qt_helpers.h" #include "Validator.h" #include "LyXRC.h" +#include "gettext.h" -#include "ControlBibtex.h" #include "ButtonPolicy.h" #include "support/filetools.h" // changeExtension #include "support/lstrings.h" +#include "support/FileFilterList.h" + +#include "frontend_helpers.h" + #include #include @@ -31,29 +39,30 @@ #include #include -#include "debug.h" -#include "support/filetools.h" -#include "support/lstrings.h" - -using std::vector; +using std::pair; using std::string; +using std::vector; namespace lyx { namespace frontend { using support::changeExtension; +using support::contains; +using support::FileFilterList; +using support::onlyFilename; +using support::prefixIs; using support::split; using support::trim; -GuiBibtexDialog::GuiBibtexDialog(LyXView & lv) - : GuiDialog(lv, "bibtex") +GuiBibtex::GuiBibtex(LyXView & lv) + : GuiDialog(lv, "bibtex"), ControlCommand(*this, "bibtex") { setupUi(this); setViewTitle( _("BibTeX Bibliography")); - setController(new ControlBibtex(*this)); + setController(this, false); QDialog::setModal(true); @@ -65,7 +74,7 @@ GuiBibtexDialog::GuiBibtexDialog(LyXView & lv) this, SLOT(browsePressed())); connect(deletePB, SIGNAL(clicked()), this, SLOT(deletePressed())); - connect(styleCB, SIGNAL(editTextChanged(const QString &)), + connect(styleCB, SIGNAL(editTextChanged(QString)), this, SLOT(change_adaptor())); connect(databaseLW, SIGNAL(itemSelectionChanged()), this, SLOT(databaseChanged())); @@ -111,13 +120,7 @@ GuiBibtexDialog::GuiBibtexDialog(LyXView & lv) } -ControlBibtex & GuiBibtexDialog::controller() -{ - return static_cast(GuiDialog::controller()); -} - - -void GuiBibtexDialog::bibEDChanged() +void GuiBibtex::bibEDChanged() { // Indicate to the button controller that the contents have // changed. The actual test of validity is carried out by @@ -126,15 +129,15 @@ void GuiBibtexDialog::bibEDChanged() } -void GuiBibtexDialog::change_adaptor() +void GuiBibtex::change_adaptor() { changed(); } -void GuiBibtexDialog::browsePressed() +void GuiBibtex::browsePressed() { - docstring const file = controller().browseBst(docstring()); + docstring const file = browseBst(docstring()); if (!file.empty()) { // FIXME UNICODE @@ -158,9 +161,9 @@ void GuiBibtexDialog::browsePressed() } -void GuiBibtexDialog::browseBibPressed() +void GuiBibtex::browseBibPressed() { - docstring const file = trim(controller().browseBib(docstring())); + docstring const file = trim(browseBib(docstring())); if (!file.empty()) { // FIXME UNICODE @@ -182,14 +185,14 @@ void GuiBibtexDialog::browseBibPressed() } -void GuiBibtexDialog::addPressed() +void GuiBibtex::addPressed() { add_bc_.setValid(false); add_->exec(); } -void GuiBibtexDialog::addDatabase() +void GuiBibtex::addDatabase() { int const sel = add_->bibLW->currentRow(); docstring const file = trim(qstring_to_ucs4(add_->bibED->text())); @@ -223,7 +226,7 @@ void GuiBibtexDialog::addDatabase() } -void GuiBibtexDialog::deletePressed() +void GuiBibtex::deletePressed() { databaseLW->takeItem(databaseLW->currentRow()); changed(); @@ -231,32 +234,32 @@ void GuiBibtexDialog::deletePressed() -void GuiBibtexDialog::databaseChanged() +void GuiBibtex::databaseChanged() { - deletePB->setEnabled(!controller().isBufferReadonly() && databaseLW->currentRow() != -1); + deletePB->setEnabled(!isBufferReadonly() && databaseLW->currentRow() != -1); } -void GuiBibtexDialog::availableChanged() +void GuiBibtex::availableChanged() { add_bc_.setValid(true); } -void GuiBibtexDialog::closeEvent(QCloseEvent *e) +void GuiBibtex::closeEvent(QCloseEvent *e) { slotClose(); e->accept(); } -void GuiBibtexDialog::updateContents() +void GuiBibtex::updateContents() { - bool bibtopic = controller().usingBibtopic(); + bool bibtopic = usingBibtopic(); databaseLW->clear(); - docstring bibs(controller().params()["bibfiles"]); + docstring bibs = params()["bibfiles"]; docstring bib; while (!bibs.empty()) { @@ -269,19 +272,19 @@ void GuiBibtexDialog::updateContents() add_->bibLW->clear(); vector bib_str; - controller().getBibFiles(bib_str); + getBibFiles(bib_str); for (vector::const_iterator it = bib_str.begin(); it != bib_str.end(); ++it) { string bibItem(changeExtension(*it, "")); add_->bibLW->addItem(toqstr(bibItem)); } - string bibstyle(controller().getStylefile()); + string bibstyle = getStylefile(); - bibtocCB->setChecked(controller().bibtotoc() && !bibtopic); + bibtocCB->setChecked(bibtotoc() && !bibtopic); bibtocCB->setEnabled(!bibtopic); - docstring btprint(controller().params()["btprint"]); + docstring btprint(params()["btprint"]); int btp = 0; if (btprint == "btPrintNotCited") btp = 1; @@ -296,7 +299,7 @@ void GuiBibtexDialog::updateContents() int item_nr(-1); vector str; - controller().getBibStyles(str); + getBibStyles(str); for (vector::const_iterator it = str.begin(); it != str.end(); ++it) { string item(changeExtension(*it, "")); @@ -317,7 +320,7 @@ void GuiBibtexDialog::updateContents() } -void GuiBibtexDialog::applyView() +void GuiBibtex::applyView() { docstring dbs = qstring_to_ucs4(databaseLW->item(0)->text()); @@ -327,22 +330,22 @@ void GuiBibtexDialog::applyView() dbs += qstring_to_ucs4(databaseLW->item(i)->text()); } - controller().params()["bibfiles"] = dbs; + params()["bibfiles"] = dbs; docstring const bibstyle(qstring_to_ucs4(styleCB->currentText())); bool const bibtotoc(bibtocCB->isChecked()); if (bibtotoc && (!bibstyle.empty())) { // both bibtotoc and style - controller().params()["options"] = "bibtotoc," + bibstyle; + params()["options"] = "bibtotoc," + bibstyle; } else if (bibtotoc) { // bibtotoc and no style - controller().params()["options"] = from_ascii("bibtotoc"); + params()["options"] = from_ascii("bibtotoc"); } else { // only style. An empty one is valid, because some // documentclasses have an own \bibliographystyle{} // command! - controller().params()["options"] = bibstyle; + params()["options"] = bibstyle; } // bibtopic allows three kinds of sections: @@ -353,26 +356,153 @@ void GuiBibtexDialog::applyView() switch (btp) { case 0: - controller().params()["btprint"] = from_ascii("btPrintCited"); + params()["btprint"] = from_ascii("btPrintCited"); break; case 1: - controller().params()["btprint"] = from_ascii("btPrintNotCited"); + params()["btprint"] = from_ascii("btPrintNotCited"); break; case 2: - controller().params()["btprint"] = from_ascii("btPrintAll"); + params()["btprint"] = from_ascii("btPrintAll"); break; } - if (!controller().usingBibtopic()) - controller().params()["btprint"] = docstring(); + if (!usingBibtopic()) + params()["btprint"] = docstring(); } -bool GuiBibtexDialog::isValid() +bool GuiBibtex::isValid() { return databaseLW->count() != 0; } + +docstring const GuiBibtex::browseBib(docstring const & in_name) const +{ + // FIXME UNICODE + pair dir1(_("Documents|#o#O"), + from_utf8(lyxrc.document_path)); + FileFilterList const filter(_("BibTeX Databases (*.bib)")); + return browseRelFile(in_name, from_utf8(bufferFilepath()), + _("Select a BibTeX database to add"), + filter, false, dir1); +} + + +docstring const GuiBibtex::browseBst(docstring const & in_name) const +{ + // FIXME UNICODE + pair dir1(_("Documents|#o#O"), + from_utf8(lyxrc.document_path)); + FileFilterList const filter(_("BibTeX Styles (*.bst)")); + return browseRelFile(in_name, from_utf8(bufferFilepath()), + _("Select a BibTeX style"), filter, false, dir1); +} + + +void GuiBibtex::getBibStyles(vector & data) const +{ + data.clear(); + + getTexFileList("bstFiles.lst", data); + // test, if we have a valid list, otherwise run rescan + if (data.empty()) { + rescanBibStyles(); + getTexFileList("bstFiles.lst", data); + } + vector::iterator it = data.begin(); + vector::iterator end = data.end(); + for (; it != end; ++it) { + *it = onlyFilename(*it); + } + // sort on filename only (no path) + std::sort(data.begin(), data.end()); +} + + +void GuiBibtex::getBibFiles(vector & data) const +{ + data.clear(); + + getTexFileList("bibFiles.lst", data); + // test, if we have a valid list, otherwise run rescan + if (data.empty()) { + rescanBibStyles(); + getTexFileList("bibFiles.lst", data); + } + vector::iterator it = data.begin(); + vector::iterator end = data.end(); + for (; it != end; ++it) { + *it = onlyFilename(*it); + } + // sort on filename only (no path) + std::sort(data.begin(), data.end()); +} + + +void GuiBibtex::rescanBibStyles() const +{ + rescanTexStyles(); +} + + +bool GuiBibtex::usingBibtopic() const +{ + return buffer().params().use_bibtopic; +} + + +bool GuiBibtex::bibtotoc() const +{ + return prefixIs(to_utf8(params()["options"]), "bibtotoc"); +} + + +string const GuiBibtex::getStylefile() const +{ + // the different bibtex packages have (and need) their + // own "plain" stylefiles + biblio::CiteEngine const engine = buffer().params().getEngine(); + docstring defaultstyle; + switch (engine) { + case biblio::ENGINE_BASIC: + defaultstyle = from_ascii("plain"); + break; + case biblio::ENGINE_NATBIB_AUTHORYEAR: + defaultstyle = from_ascii("plainnat"); + break; + case biblio::ENGINE_NATBIB_NUMERICAL: + defaultstyle = from_ascii("plainnat"); + break; + case biblio::ENGINE_JURABIB: + defaultstyle = from_ascii("jurabib"); + break; + } + + docstring bst = params()["options"]; + if (bibtotoc()){ + // bibstyle exists? + if (contains(bst, ',')) { + docstring bibtotoc = from_ascii("bibtotoc"); + bst = split(bst, bibtotoc, ','); + } else + bst.erase(); + } + + // propose default style file for new insets + // existing insets might have (legally) no bst files + // (if the class already provides a style) + if (bst.empty() && params()["bibfiles"].empty()) + bst = defaultstyle; + + // FIXME UNICODE + return to_utf8(bst); +} + + +Dialog * createGuiBibtex(LyXView & lv) { return new GuiBibtex(lv); } + + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiBibtex.h b/src/frontends/qt4/GuiBibtex.h index bccbb25c90..656741eed0 100644 --- a/src/frontends/qt4/GuiBibtex.h +++ b/src/frontends/qt4/GuiBibtex.h @@ -5,6 +5,7 @@ * Licence details can be found in the file COPYING. * * \author John Levon + * \author Angus Leeming * * Full author contact details are available in file CREDITS. */ @@ -13,12 +14,20 @@ #define GUIBIBTEX_H #include "GuiDialog.h" -#include "ControlBibtex.h" #include "ButtonController.h" #include "ui_BibtexUi.h" #include "ui_BibtexAddUi.h" +#include "ControlCommand.h" + +#include "support/docstring.h" + +#include + namespace lyx { + +namespace support { class FileFilterList; } + namespace frontend { class GuiBibtexAddDialog : public QDialog, public Ui::BibtexAddUi @@ -32,12 +41,12 @@ public: }; -class GuiBibtexDialog : public GuiDialog, public Ui::BibtexUi +class GuiBibtex : public GuiDialog, public Ui::BibtexUi, public ControlCommand { Q_OBJECT public: - GuiBibtexDialog(LyXView & lv); + GuiBibtex(LyXView & lv); private Q_SLOTS: void change_adaptor(); @@ -55,7 +64,7 @@ private: private: /// parent controller - ControlBibtex & controller(); + Controller & controller() { return *this; } /// virtual bool isValid(); /// Apply changes @@ -63,6 +72,26 @@ private: /// update virtual void updateContents(); + /// Browse for a .bib file + docstring const browseBib(docstring const & in_name) const; + + /// Browse for a .bst file + docstring const browseBst(docstring const & in_name) const; + + /// get the list of bst files + void getBibStyles(std::vector & data) const; + /// get the list of bib files + void getBibFiles(std::vector & data) const; + /// build filelists of all availabe bib/bst/cls/sty-files. done through + /// kpsewhich and an external script, saved in *Files.lst + void rescanBibStyles() const; + /// do we use bibtopic (for sectioned bibliography)? + bool usingBibtopic() const; + /// should we put the bibliography to the TOC? + bool bibtotoc() const; + /// which stylefile do we use? + std::string const getStylefile() const; + /// GuiBibtexAddDialog * add_; ///