]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetbib.C
clear()->erase() ; lots of using directives for cxx
[lyx.git] / src / insets / insetbib.C
index 61f71bcb4ad48df8e842e6e0ffeb2ec96258e5a1..7bebfb9d1fba3028f8881902b815f4a3227d342d 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <fstream>
 using std::ifstream;
+using std::getline;
 
 #include <cstdlib>
 
@@ -21,6 +22,9 @@ using std::ifstream;
 #include "lyxtext.h"
 #include "support/filetools.h"
 
+using std::ostream;
+using std::endl;
+
 extern BufferView * current_view;
 
 FD_citation_form * citation_form = 0;
@@ -220,7 +224,8 @@ InsetBibKey::InsetBibKey(InsetBibKey const * b):
 InsetBibKey::~InsetBibKey()
 {
        if(bibitem_form && bibitem_form->bibitem_form
-          && bibitem_form->bibitem_form->visible)
+          && bibitem_form->bibitem_form->visible
+          && bibitem_form->bibitem_form->u_vdata == &holder)
                fl_hide_form(bibitem_form->bibitem_form);
 }
 
@@ -239,14 +244,13 @@ void InsetBibKey::setCounter(int c)
 // of time cause LyX3 won't use lyxlex anyway.  (ale)
 void InsetBibKey::Write(ostream & os) const
 {
-       string s;
+       os << "\\bibitem ";
        if (!options.empty()) {
-               s += '[';
-               s += options + ']';
+               os << '['
+                  << options << ']';
        }
-       s += '{';
-       s += contents + '}';
-       os << "\\bibitem " << s << "\n";
+       os << '{'
+          << contents << "}\n";
 }
 
 
@@ -304,6 +308,14 @@ InsetBibtex::InsetBibtex(string const & dbase, string const & style,
 {
 }
 
+InsetBibtex::~InsetBibtex()
+{
+       if(bibitem_form && bibitem_form->bibitem_form
+          && bibitem_form->bibitem_form->visible
+          && bibitem_form->bibitem_form->u_vdata == &holder)
+               fl_hide_form(bibitem_form->bibitem_form);
+}
+
 
 string InsetBibtex::getScreenLabel() const
 {
@@ -311,9 +323,9 @@ string InsetBibtex::getScreenLabel() const
 }
 
 
-int InsetBibtex::Latex(ostream & os, signed char /*fragile*/) const
+int InsetBibtex::Latex(ostream & os,
+                      bool /*fragile*/, bool/*fs*/) const
 {
-#ifdef USE_OSTREAM_ONLY
        // this looks like an horrible hack and it is :) The problem
        // is that owner is not initialized correctly when the bib
        // inset is cut and pasted. Such hacks will not be needed
@@ -348,60 +360,9 @@ int InsetBibtex::Latex(ostream & os, signed char /*fragile*/) const
        os << "\\bibliographystyle{" << style << "}\n"
           << "\\bibliography{" << db_out << "}\n";
        return 2;
-#else
-       string bib;
-       signed char dummy = 0;
-       int result = Latex(bib, dummy);
-       os << bib;
-       return result;
-#endif
 }
 
 
-#ifndef USE_OSTREAM_ONLY
-int InsetBibtex::Latex(string & file, signed char /*fragile*/) const
-{
-       // this looks like an horrible hack and it is :) The problem
-       // is that owner is not initialized correctly when the bib
-       // inset is cut and pasted. Such hacks will not be needed
-       // later (JMarc)
-       if (!owner) {
-               owner = current_view->buffer();
-       }
-       // If we generate in a temp dir, we might need to give an
-       // absolute path there. This is a bit complicated since we can
-       // have a comma-separated list of bibliographies
-       string adb, db_out;
-       string db_in = getContents();
-       db_in = split(db_in, adb, ',');
-       while(!adb.empty()) {
-               if (!owner->niceFile &&
-                   IsFileReadable(MakeAbsPath(adb, owner->filepath)+".bib")) 
-                       adb = MakeAbsPath(adb, owner->filepath);
-               db_out += adb;
-               db_out += ',';
-               db_in= split(db_in, adb,',');
-       }
-       db_out = strip(db_out, ',');
-       // Idem, but simpler
-       string style;
-       if (!owner->niceFile 
-           && IsFileReadable(MakeAbsPath(getOptions(), owner->filepath)
-                             + ".bst")) 
-               style = MakeAbsPath(getOptions(), owner->filepath);
-       else
-               style = getOptions();
-
-       file += "\\bibliographystyle{";
-       file += style;
-       file += "}\n";
-       file += "\\bibliography{";
-       file += db_out;
-       file += "}\n";
-       return 2;
-}
-#endif
-
 // This method returns a comma separated list of Bibtex entries
 string InsetBibtex::getKeys(char delim)
 {
@@ -457,7 +418,7 @@ string InsetBibtex::getKeys(char delim)
 
 
 // BibTeX should have its own dialog. This is provisional.
-void InsetBibtex::Edit(BufferView *, int, int, unsigned int)
+void InsetBibtex::Edit(BufferView * bv, int, int, unsigned int)
 {
        if (!bibitem_form) {
                bibitem_form = create_form_bibitem_form();
@@ -465,7 +426,10 @@ void InsetBibtex::Edit(BufferView *, int, int, unsigned int)
                                    CancelCloseBoxCB, 0);
        }
 
-       bibitem_form->bibitem_form->u_vdata = this;
+       holder.inset = this;
+       holder.view = bv;
+       bibitem_form->bibitem_form->u_vdata = &holder;
+
        fl_set_object_label(bibitem_form->key, _("Database:"));
        fl_set_object_label(bibitem_form->label, _("Style:  "));
        fl_set_input(bibitem_form->key, getContents().c_str());