]> 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 03b6dba6beaac3ada8e895a91960e8af23be4cc9..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>
- * \author Herbert Voss <voss@lyx.org>
+ * 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 "BufferView.h"
+#include "bufferparams.h"
+
 #include "lyxrc.h"
 #include "helper_funcs.h"
+#include "tex_helpers.h"
 #include "gettext.h"
 
-using SigC::slot;
+#include "support/filefilterlist.h"
+#include "support/filetools.h"
+
 using std::pair;
-using std::make_pair;
+using std::string;
+using std::vector;
+
+
+namespace lyx {
 
-ControlBibtex::ControlBibtex(LyXView & lv, Dialogs & d)
-       : ControlCommand(lv, d)
+using support::FileFilterList;
+using support::OnlyFilename;
+
+namespace frontend {
+
+
+ControlBibtex::ControlBibtex(Dialog & d)
+       : ControlCommand(d, "bibtex")
+{}
+
+
+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();
+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());
+}
 
 
-string const ControlBibtex::Browse(string const & in_name, 
-                                   string const & title,
-                                  string const & pattern)
+void ControlBibtex::rescanBibStyles() const
 {
-       pair<string, string> dir1(N_("Documents"), string(lyxrc.document_path));
-       return browseFile(&lv_, in_name, title, pattern, 
-                         dir1,make_pair(string(), string()));
+       rescanTexStyles();
 }
+
+
+bool ControlBibtex::usingBibtopic() const
+{
+    return kernel().buffer().params().use_bibtopic;
+}
+
+} // namespace frontend
+} // namespace lyx