]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlBibtex.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / ControlBibtex.C
index 3a10c45255146d0eb10ec43d011bc2b352de0c97..0573d240042379777aeb64ffba5574fa0dcd3f5f 100644 (file)
-/* This file is part of
- * ====================================================== 
- *
- *           LyX, The Document Processor
- *
- *           Copyright 2001 The LyX Team.
+/**
+ * \file ControlBibtex.C
+ * 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ß
  *
- * \file ControlBibtex.C
- * \author John Levon, moz@compsoc.man.ac.uk
- * \author Angus Leeming <a.leeming@ic.ac.uk>
+ * Full author contact details are available in file CREDITS.
  */
 
-#include <algorithm>
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include <config.h>
-#include "ViewBase.h"
-#include "ButtonControllerBase.h"
+
 #include "ControlBibtex.h"
-#include "Dialogs.h"
-#include "LyXView.h"
+
 #include "buffer.h"
+#include "bufferparams.h"
+
+#include "lyxrc.h"
+#include "helper_funcs.h"
+#include "tex_helpers.h"
+#include "gettext.h"
+
+#include "support/filefilterlist.h"
+#include "support/filetools.h"
+
+using std::pair;
+using std::string;
+using std::vector;
+
+
+namespace lyx {
+
+using support::FileFilterList;
+using support::OnlyFilename;
+
+namespace frontend {
+
+
+ControlBibtex::ControlBibtex(Dialog & d)
+       : ControlCommand(d, "bibtex")
+{}
 
-using SigC::slot;
 
-ControlBibtex::ControlBibtex(LyXView & lv, Dialogs & d)
-       : ControlCommand(lv, d)
+string const ControlBibtex::browseBib(string const & in_name) const
 {
-       d_.showBibtex.connect(slot(this, &ControlBibtex::showInset));
+       pair<string, string> dir1(_("Documents|#o#O"),
+                                 string(lyxrc.document_path));
+       FileFilterList const filter(_("BibTeX Databases (*.bib)"));
+       return browseRelFile(in_name, kernel().bufferFilepath(),
+                            _("Select a BibTeX database to add"),
+                            filter, false, dir1);
 }
 
-void ControlBibtex::applyParamsToInset()
+
+string const ControlBibtex::browseBst(string const & in_name) const
 {
-       if (params().getContents() != inset()->params().getContents())
-               lv_.view()->ChangeCitationsIfUnique(inset()->params().getContents(),
-                                                   params().getContents());
+       pair<string, string> dir1(_("Documents|#o#O"),
+                                 string(lyxrc.document_path));
+       FileFilterList const filter(_("BibTeX Styles (*.bst)"));
+       return browseRelFile(in_name, kernel().bufferFilepath(),
+                            _("Select a BibTeX style"), filter, false, dir1);
+}
 
-       inset()->setParams(params());
-       lv_.view()->updateInset(inset(), true);
 
-       // We need to do a redraw because the maximum
-       // InsetBibKey width could have changed
-       lv_.view()->redraw();
-       lv_.view()->fitCursor(lv_.view()->getLyXText());
+void ControlBibtex::getBibStyles(vector<string> & 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<string>::iterator it  = data.begin();
+       vector<string>::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::applyParamsNoInset()
-{}
+void ControlBibtex::getBibFiles(vector<string> & 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<string>::iterator it  = data.begin();
+       vector<string>::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 kernel().buffer().params().use_bibtopic;
+}
+
+} // namespace frontend
+} // namespace lyx