]> git.lyx.org Git - features.git/blobdiff - src/insets/insetbib.C
read the Changelog
[features.git] / src / insets / insetbib.C
index bee2a4745eb9d2196199f99df34749dd08f71dff..73ac251a42d689b985b5dcd9b10c74645a7fe18c 100644 (file)
@@ -34,32 +34,14 @@ FD_bibitem_form * bibitem_form = 0;
 FD_bibitem_form * create_form_bibitem_form(void);
 
 
-extern "C" void bibitem_cb(FL_OBJECT *, long data)
+extern "C"
+void bibitem_cb(FL_OBJECT *, long data)
 {
-       switch (data)
-       {
-       case 1:
-       {
-               InsetBibKey::Holder * holder =
-                       static_cast<InsetBibKey::Holder*>
-                       (bibitem_form->bibitem_form->u_vdata);
-               
-               if(!holder->view->buffer()->isReadonly())
-               {
-                       InsetBibKey * inset = holder->inset;
-                       inset->setContents(fl_get_input(bibitem_form->key));
-                       inset->setOptions(fl_get_input(bibitem_form->label));
-                       fl_hide_form(bibitem_form->bibitem_form);
-                       // Does look like a hack? It is! (but will change at 0.13)
-                       holder->view->text->RedoParagraph(holder->view);
-                       holder->view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
-                       break;
-               } // fall through to Cancel on RO-mode
-       }
-       case 0:
-               fl_hide_form(bibitem_form->bibitem_form);
-               break;
-        }
+       InsetBibKey::Holder * holder =
+               static_cast<InsetBibKey::Holder*>
+               (bibitem_form->bibitem_form->u_vdata);
+       
+       holder->inset->callback( bibitem_form, data );
 }
 
 
@@ -91,8 +73,8 @@ FD_bibitem_form * create_form_bibitem_form(void)
 }
 
 
-InsetBibKey::InsetBibKey(string const & key, string const & label):
-       InsetCommand("bibitem", key, label)
+InsetBibKey::InsetBibKey(string const & key, string const & label)
+       InsetCommand("bibitem", key, label)
 {
        counter = 1;
        if (key.empty())
@@ -100,8 +82,8 @@ InsetBibKey::InsetBibKey(string const & key, string const & label):
 }
 
 
-InsetBibKey::InsetBibKey(InsetBibKey const * b):
-       InsetCommand("bibitem", b->getContents(), b->getOptions())
+InsetBibKey::InsetBibKey(InsetBibKey const * b)
+       InsetCommand("bibitem", b->getContents(), b->getOptions())
 {
        counter = b->counter;
 }
@@ -115,6 +97,25 @@ InsetBibKey::~InsetBibKey()
                fl_hide_form(bibitem_form->bibitem_form);
 }
 
+
+void InsetBibKey::callback( FD_bibitem_form * form, long data )
+{
+       switch (data) {
+       case 1:
+               if(!holder.view->buffer()->isReadonly()) {
+                       setContents(fl_get_input(form->key));
+                       setOptions(fl_get_input(form->label));
+                       // shouldn't mark the buffer dirty unless
+                       // something was actually altered
+                       holder.view->updateInset( this, true );
+               } // fall through to Cancel
+       case 0:
+               fl_hide_form(form->bibitem_form);
+               break;
+        }
+}
+
+
 void InsetBibKey::setCounter(int c) 
 { 
        counter = c; 
@@ -140,6 +141,20 @@ void InsetBibKey::Write(Buffer const *, ostream & os) const
 }
 
 
+// This is necessary here because this is written without begin_inset
+// This should be changed!!! (Jug)
+void InsetBibKey::Read(Buffer const *, LyXLex & lex)
+{    
+       string token;
+
+       if (lex.EatLine()) {
+               token = lex.GetString();
+               scanCommand(token);
+       } else
+               lex.printError("InsetCommand: Parse error: `$$Token'");
+}
+
+
 string InsetBibKey::getScreenLabel() const
 {
        if (! getOptions().empty())
@@ -149,7 +164,7 @@ string InsetBibKey::getScreenLabel() const
 }
 
 
-/*
+/**
   The value in "Key:" isn't allways set right after a few bibkey insets have
   been added/removed.  Perhaps the wrong object is deleted/used somewhere
   upwards?
@@ -190,8 +205,8 @@ void InsetBibKey::Edit(BufferView * bv, int, int, unsigned int)
 InsetBibtex::InsetBibtex(string const & dbase, string const & style,
                         Buffer * o)
        : InsetCommand("BibTeX", dbase, style), owner(o)
-{
-}
+{}
+
 
 InsetBibtex::~InsetBibtex()
 {