2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * ======================================================
17 #pragma implementation
23 #include "FormCitation.h"
27 #include "support/filetools.h"
28 #include "support/LRegex.h"
30 #include <gtk--/scrolledwindow.h>
31 #include <gnome--/pixmap.h>
32 #include <gtk--/label.h>
33 #include <gtk--/box.h>
34 #include <gtk--/buttonbox.h>
35 #include <gnome--/entry.h>
36 #include <gnome--/stock.h>
37 #include <gtk--/separator.h>
38 #include <libgnome/gnome-config.h>
39 #include <gtk--/alignment.h>
40 #include "pixbutton.h"
42 // temporary solution for LyXView
44 extern GLyxAppWin * mainAppWin;
52 #ifdef SIGC_CXX_NAMESPACES
59 static string const LOCAL_CONFIGURE_PREFIX("FormCitation");
61 static string const CONF_PANE_INFO("paneinfo");
62 static string const CONF_PANE_INFO_DEFAULT("=300");
64 static string const CONF_COLUMN("column");
65 static string const CONF_COLUMN_DEFAULT("=50");
67 static string const CONF_REGEXP("regexp");
68 static string const CONF_REGEXP_DEFAULT("=0");
70 static string const CONF_SEARCH("FormCitation_search");
71 static string const CONF_TEXTAFTER("FormCitation_textafter");
73 FormCitation::FormCitation(LyXView * lv, Dialogs * d)
74 : lv_(lv), d_(d), inset_(0), u_(0), h_(0), ih_(0)
76 // let the dialog be shown
77 // These are permanent connections so we won't bother
78 // storing a copy because we won't be disconnecting.
79 d->showCitation.connect(slot(this, &FormCitation::showInset));
80 d->createCitation.connect(slot(this, &FormCitation::createInset));
85 FormCitation::~FormCitation()
90 void FormCitation::showInset( InsetCommand * const inset )
92 if( dialog_!=0 || inset == 0 ) return;
95 ih_ = inset_->hideDialog.connect(slot(this, &FormCitation::hide));
97 u_ = d_->updateBufferDependent.connect(slot(this, &FormCitation::updateSlot));
98 h_ = d_->hideBufferDependent.connect(slot(this, &FormCitation::hide));
100 params = inset->params();
102 if ( params.getContents().empty() ) showStageSearch();
103 else showStageAction();
107 void FormCitation::createInset( string const & arg )
109 if( dialog_!=0 ) return;
111 u_ = d_->updateBufferDependent.connect(slot(this, &FormCitation::updateSlot));
112 h_ = d_->hideBufferDependent.connect(slot(this, &FormCitation::hide));
114 params.setFromString( arg );
120 void parseBibTeX(string data,
121 string const & findkey,
128 for (i=0; i<data.length(); ++i)
129 if (data[i]=='\n' || data[i]=='\t')
132 data = frontStrip(data);
135 && (data.find(' ')!=string::npos ||
136 data.find('=')!=string::npos) )
138 unsigned int keypos = min(data.find(' '), data.find('='));
139 string key = lowercase( data.substr(0, keypos) );
143 data = data.substr(keypos, data.length()-1);
144 data = frontStrip(strip(data));
145 if (data.length() > 1 && data[0]=='=')
147 data = frontStrip(data.substr(1, data.length()-1));
151 if (data[0]=='{') enclosing = '}';
152 else if (data[0]=='"') enclosing = '"';
153 else { keypos=0; enclosing=' '; }
156 data.find(enclosing)!=string::npos &&
159 tmp = data.substr(keypos, data.length()-1);
160 while (tmp.find('{')!=string::npos &&
161 tmp.find('}')!=string::npos &&
162 tmp.find('{') < tmp.find('}') &&
163 tmp.find('{') < tmp.find(enclosing))
165 keypos += tmp.find('{')+1;
166 tmp = data.substr(keypos, data.length()-1);
167 keypos += tmp.find('}')+1;
168 tmp = data.substr(keypos, data.length()-1);
171 if (tmp.find(enclosing)==string::npos) return;
174 keypos += tmp.find(enclosing);
175 tmp = data.substr(keypos, data.length()-1);
178 value = data.substr(1, keypos-1);
180 if (keypos+1<data.length()-1) data = frontStrip(data.substr(keypos+1, data.length()-1));
186 ) // numerical value ?
188 keypos = data.length()-1;
189 if (data.find(' ')!=string::npos) keypos = data.find(' ');
190 if (data.find(',')!=string::npos &&
191 keypos > data.find(','))
192 keypos = data.find(',');
194 value = data.substr(0, keypos);
196 if (keypos+1<data.length()-1) data = frontStrip(data.substr(keypos+1, data.length()-1));
201 if (findkey == key) { keyvalue = value; return; }
203 data = frontStrip(frontStrip(data,','));
211 void FormCitation::cleanupWidgets()
219 button_unselect_ = 0;
229 void FormCitation::initWidgets()
231 string const path = PACKAGE "/" + LOCAL_CONFIGURE_PREFIX;
233 if (search_text_ != 0)
235 search_text_->set_history_id(CONF_SEARCH);
236 search_text_->set_max_saved(10);
237 search_text_->load_history();
238 search_text_->set_use_arrows_always(true);
241 if (text_after_ != 0 )
243 text_after_->set_history_id(CONF_TEXTAFTER);
244 text_after_->set_max_saved(10);
245 text_after_->load_history();
246 text_after_->set_use_arrows_always(true);
247 text_after_->get_entry()->set_text(params.getOptions());
250 if (button_regexp_ != 0)
252 string w = path + "/" + CONF_REGEXP + CONF_REGEXP_DEFAULT;
253 button_regexp_->set_active( (gnome_config_get_int(w.c_str()) > 0) );
256 if (paned_info_ != 0)
258 string w = path + "/" + CONF_PANE_INFO + CONF_PANE_INFO_DEFAULT;
259 paned_info_->set_position( gnome_config_get_int(w.c_str()) );
265 clist_bib_->column(0).set_visiblity(false);
266 clist_bib_->set_selection_mode(GTK_SELECTION_BROWSE);
268 // setting up sizes of columns
270 int sz = clist_bib_->columns().size();
271 for (int i = 0; i < sz; ++i)
273 w = path + "/" + CONF_COLUMN + "_" + tostr(i) + CONF_COLUMN_DEFAULT;
274 clist_bib_->column(i).set_width( gnome_config_get_int(w.c_str()) );
278 vector<pair<string,string> > blist = lv_->buffer()->getBibkeyList();
281 for (int i = 0; i < sz; ++i )
283 bibkeys.push_back(blist[i].first);
284 bibkeysInfo.push_back(blist[i].second);
292 if (clist_bib_->rows().size() > 0)
294 clist_bib_->rows()[0].select();
295 selectionToggled(0, 0, 0, true, false);
299 if (clist_selected_ != 0)
301 clist_selected_->set_selection_mode(GTK_SELECTION_BROWSE);
303 // populating clist_selected_
305 string tmp, keys( params.getContents() );
306 keys = frontStrip( split(keys, tmp, ',') );
307 while( !tmp.empty() )
311 clist_selected_->rows().push_back(r);
313 keys = frontStrip( split(keys, tmp, ',') );
316 if (clist_selected_->rows().size() > 0)
318 clist_selected_->rows()[0].select();
319 selectionToggled(0, 0, 0, true, true);
327 void FormCitation::storeWidgets()
329 string const path = PACKAGE "/" + LOCAL_CONFIGURE_PREFIX;
331 if (search_text_ != 0) search_text_->save_history();
333 if (text_after_ != 0) text_after_->save_history();
335 if (button_regexp_ != 0)
337 string w = path + "/" + CONF_REGEXP;
338 gnome_config_set_int(w.c_str(), button_regexp_->get_active());
341 if (paned_info_ != 0)
343 string w = path + "/" + CONF_PANE_INFO;
344 gnome_config_set_int(w.c_str(), paned_info_->width() - info_->width());
350 int const sz = clist_bib_->columns().size();
351 for (int i = 0; i < sz; ++i)
353 w = path + "/" + CONF_COLUMN + "_" + tostr(i);
354 gnome_config_set_int(w.c_str(), clist_bib_->get_column_width(i));
362 void FormCitation::showStageAction()
366 using namespace Gtk::Box_Helpers;
368 Gtk::Alignment * mbox = manage( new Gtk::Alignment(0.5, 0.5, 0, 0) );
369 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
371 string const addlabel = _("_Add new citation");
372 string const editlabel = _("_Edit/remove citation(s)");
374 Gnome::PixButton * b_add = manage(new Gnome::PixButton(addlabel, GNOME_STOCK_PIXMAP_NEW));
375 Gnome::PixButton * b_edit = manage(new Gnome::PixButton(editlabel, GNOME_STOCK_PIXMAP_PROPERTIES));
377 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
380 bbox->set_spacing(4);
381 bbox->set_layout(GTK_BUTTONBOX_SPREAD);
383 bbox->children().push_back(Element(*b_add, false, false));
384 bbox->children().push_back(Element(*b_edit, false, false));
385 bbox->children().push_back(Element(*b_cancel, false, false));
390 Gtk::AccelGroup * accel = Gtk::AccelGroup::create();
392 b_add->add_accelerator("clicked", *accel, b_add->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
393 b_edit->add_accelerator("clicked", *accel, b_edit->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
395 // packing dialog to main window
397 mainAppWin->add_action(*dialog_, _(" Citation: Select action "), false, accel);
402 gtk_widget_grab_focus (GTK_WIDGET(b_add->gtkobj()));
404 // connecting signals
405 b_add->clicked.connect(slot(this, &FormCitation::moveFromActionToSearch));
406 b_edit->clicked.connect(slot(this, &FormCitation::moveFromActionToEdit));
408 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
410 dialog_->destroy.connect(slot(this, &FormCitation::free));
415 void FormCitation::moveFromActionToSearch()
417 // stores configuration and cleans all widgets
421 // moves to stage "search"
422 mainAppWin->remove_action();
427 void FormCitation::moveFromActionToEdit()
429 // stores configuration and cleans all widgets
433 // moves to stage "edit"
434 mainAppWin->remove_action();
439 void FormCitation::showStageSearch()
443 using namespace Gtk::Box_Helpers;
445 Gtk::Box * mbox = manage( new Gtk::HBox() );
446 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
447 Gtk::Separator * sep = manage( new Gtk::VSeparator() );
449 search_text_ = manage( new Gnome::Entry() );
451 button_regexp_ = manage( new Gtk::CheckButton(_("Use Regular Expression")) );
453 b_ok = manage( new Gtk::Button(_("Search")) );
454 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
457 mbox->set_spacing(4);
458 bbox->set_spacing(4);
461 bbox->children().push_back(Element(*b_ok, false, false));
462 bbox->children().push_back(Element(*b_cancel, false, false));
464 mbox->children().push_back(Element(*search_text_, true, true));
465 mbox->children().push_back(Element(*button_regexp_, false, false));
466 mbox->children().push_back(Element(*sep, false, false));
467 mbox->children().push_back(Element(*bbox, false, false));
469 // packing dialog to main window
471 mainAppWin->add_action(*dialog_, _(" Insert Citation: Enter keyword(s) or regular expression "));
476 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(search_text_->get_entry()->gtkobj()), GTK_CAN_DEFAULT);
477 gtk_widget_grab_focus (GTK_WIDGET(search_text_->get_entry()->gtkobj()));
478 gtk_widget_grab_default (GTK_WIDGET(search_text_->get_entry()->gtkobj()));
480 // connecting signals
481 b_ok->clicked.connect(slot(this, &FormCitation::moveFromSearchToSelect));
482 search_text_->get_entry()->activate.connect(slot(this, &FormCitation::moveFromSearchToSelect));
484 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
485 dialog_->destroy.connect(slot(this, &FormCitation::free));
489 void FormCitation::moveFromSearchToSelect()
491 search_string_ = search_text_->get_entry()->get_text();
492 use_regexp_ = button_regexp_->get_active();
494 // stores configuration and cleans all widgets
498 // moves to stage "select"
499 mainAppWin->remove_action();
503 void FormCitation::showStageSelect()
507 using namespace Gtk::Box_Helpers;
509 Gtk::Box * mbox = manage( new Gtk::VBox() );
510 Gtk::Box * tbox = manage( new Gtk::HBox() );
511 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
512 Gtk::Separator * sep = manage( new Gtk::HSeparator() );
513 Gtk::ScrolledWindow * sw = manage( new Gtk::ScrolledWindow() );
515 info_ = manage( new Gnome::Less() );
516 paned_info_ = manage( new Gtk::HPaned() );
517 text_after_ = manage( new Gnome::Entry() );
519 b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
520 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
522 sw->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
524 // constructing CList
525 vector<string> colnames;
526 colnames.push_back("INVISIBLE");
527 colnames.push_back(_("Key"));
528 colnames.push_back(_("Author(s)"));
529 colnames.push_back(_("Title"));
530 colnames.push_back(_("Year"));
531 colnames.push_back(_("Journal"));
532 clist_bib_ = manage( new Gtk::CList(colnames) );
534 bbox->set_layout(GTK_BUTTONBOX_END);
537 mbox->set_spacing(4);
538 bbox->set_spacing(4);
539 tbox->set_spacing(4);
542 sw->add(*clist_bib_);
543 paned_info_->add1(*sw);
544 paned_info_->add2(*info_);
546 bbox->children().push_back(Element(*b_ok, false, false));
547 bbox->children().push_back(Element(*b_cancel, false, false));
549 tbox->children().push_back(Element(*manage(new Gtk::Label(_("Text after"))), false, false));
550 tbox->children().push_back(Element(*text_after_, true, true));
551 tbox->children().push_back(Element(*manage(new Gtk::VSeparator()), false, false));
552 tbox->children().push_back(Element(*bbox, false, false));
554 mbox->children().push_back(Element(*paned_info_,true,true));
555 mbox->children().push_back(Element(*sep, false, false));
556 mbox->children().push_back(Element(*tbox, false, false));
558 // packing dialog to main window
560 mainAppWin->add_action(*dialog_, _(" Insert Citation: Select citation "), true);
565 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_ok->gtkobj()), GTK_CAN_DEFAULT);
566 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_cancel->gtkobj()), GTK_CAN_DEFAULT);
567 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(clist_bib_->gtkobj()), GTK_CAN_DEFAULT);
568 gtk_widget_grab_focus (GTK_WIDGET(clist_bib_->gtkobj()));
569 gtk_widget_grab_default (GTK_WIDGET(b_ok->gtkobj()));
571 // connecting signals
572 b_ok->clicked.connect(slot(this, &FormCitation::applySelect));
573 text_after_->get_entry()->activate.connect(slot(this, &FormCitation::applySelect));
575 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
577 dialog_->destroy.connect(slot(this, &FormCitation::free));
579 clist_bib_->click_column.connect(slot(this, &FormCitation::sortBibList));
580 clist_bib_->select_row.connect(bind(slot(this, &FormCitation::selectionToggled),
582 clist_bib_->unselect_row.connect(bind(slot(this, &FormCitation::selectionToggled),
587 void FormCitation::showStageEdit()
591 using namespace Gtk::Box_Helpers;
593 Gtk::Box * mbox = manage( new Gtk::VBox() );
594 Gtk::Box * tbox = manage( new Gtk::HBox() );
595 Gtk::Box * t2box = manage( new Gtk::HBox() );
596 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
597 Gtk::ButtonBox * actbbox = manage( new Gtk::VButtonBox() );
598 Gtk::ScrolledWindow * sw = manage( new Gtk::ScrolledWindow() );
600 vector<string> colnames;
601 colnames.push_back(" ");
602 clist_selected_ = manage( new Gtk::CList(colnames) );
603 clist_selected_->column_titles_hide();
605 text_after_ = manage( new Gnome::Entry() );
607 button_unselect_ = manage( new Gnome::PixButton( _("_Remove"), GNOME_STOCK_PIXMAP_TRASH ) );
608 button_up_ = manage( new Gnome::PixButton( _("_Up"), GNOME_STOCK_PIXMAP_UP ) );
609 button_down_ = manage( new Gnome::PixButton( _("_Down"), GNOME_STOCK_PIXMAP_DOWN ) );
611 b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
612 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
614 sw->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
616 bbox->set_layout(GTK_BUTTONBOX_END);
617 actbbox->set_layout(GTK_BUTTONBOX_START);
620 mbox->set_spacing(4);
621 bbox->set_spacing(4);
622 actbbox->set_spacing(4);
623 tbox->set_spacing(4);
624 t2box->set_spacing(4);
627 sw->add(*clist_selected_);
629 bbox->children().push_back(Element(*b_ok, false, false));
630 bbox->children().push_back(Element(*b_cancel, false, false));
632 actbbox->children().push_back(Element(*button_unselect_, false, false));
633 actbbox->children().push_back(Element(*button_up_, false, false));
634 actbbox->children().push_back(Element(*button_down_, false, false));
636 t2box->children().push_back(Element(*sw, true, true));
637 t2box->children().push_back(Element(*actbbox, false, false));
639 tbox->children().push_back(Element(*manage(new Gtk::Label(_("Text after"))), false, false));
640 tbox->children().push_back(Element(*text_after_, true, true));
641 tbox->children().push_back(Element(*manage(new Gtk::VSeparator()), false, false));
642 tbox->children().push_back(Element(*bbox, false, false));
644 mbox->children().push_back(Element(*t2box,true,true));
645 mbox->children().push_back(Element(*manage(new Gtk::HSeparator()), false, false));
646 mbox->children().push_back(Element(*tbox, false, false));
649 Gtk::AccelGroup * accel = Gtk::AccelGroup::create();
651 button_unselect_->add_accelerator("clicked", *accel, button_unselect_->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
652 button_up_->add_accelerator("clicked", *accel, button_up_->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
653 button_down_->add_accelerator("clicked", *accel, button_down_->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
655 // packing dialog to main window
657 mainAppWin->add_action(*dialog_, _(" Citation: Edit "), true, accel);
662 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_ok->gtkobj()), GTK_CAN_DEFAULT);
663 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_cancel->gtkobj()), GTK_CAN_DEFAULT);
664 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(clist_selected_->gtkobj()), GTK_CAN_DEFAULT);
665 gtk_widget_grab_focus (GTK_WIDGET(clist_selected_->gtkobj()));
666 gtk_widget_grab_default (GTK_WIDGET(b_ok->gtkobj()));
668 // connecting signals
669 b_ok->clicked.connect(slot(this, &FormCitation::applyEdit));
670 text_after_->get_entry()->activate.connect(slot(this, &FormCitation::applyEdit));
672 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
674 dialog_->destroy.connect(slot(this, &FormCitation::free));
676 button_unselect_->clicked.connect(slot(this, &FormCitation::removeCitation));
677 button_up_->clicked.connect(slot(this, &FormCitation::moveCitationUp));
678 button_down_->clicked.connect(slot(this, &FormCitation::moveCitationDown));
680 clist_selected_->select_row.connect(bind(slot(this, &FormCitation::selectionToggled),
682 clist_selected_->unselect_row.connect(bind(slot(this, &FormCitation::selectionToggled),
688 void FormCitation::addItemToBibList(int i)
695 info = bibkeysInfo[i];
697 // don't change the order of these first two items:
698 // callback functions depend on the data stored in the first column (its hided)
699 // and in the second column (shown to user)
700 r.push_back( tostr(i) );
703 // this can be changed (configured by user?)
704 parseBibTeX( info, "author", val); r.push_back(val);
705 parseBibTeX( info, "title", val); r.push_back(val);
706 parseBibTeX( info, "year", val); r.push_back(val);
707 parseBibTeX( info, "journal", val); r.push_back(val);
709 clist_bib_->rows().push_back(r);
713 void FormCitation::updateButtons()
715 if (button_unselect_ != 0) // => button_up_ and button_down_ are != 0
719 sens = (clist_selected_->selection().size()>0);
720 button_unselect_->set_sensitive(sens);
721 button_up_->set_sensitive(sens &&
722 clist_selected_->selection()[0].get_row_num()>0);
723 button_down_->set_sensitive(sens &&
724 clist_selected_->selection()[0].get_row_num() <
725 clist_selected_->rows().size()-1);
730 void FormCitation::updateSlot(bool buffchanged)
732 if (buffchanged) hide();
736 void FormCitation::selectionToggled(gint row,
746 bool keyfound = false;
749 // the first column in clist_bib_ contains the index
751 info = bibkeysInfo[ strToInt(clist_bib_->cell(row,0).get_text()) ];
754 info_->show_string(info);
756 info_->show_string(_("--- No such key in the database ---"));
760 info_->show_string("");
767 void FormCitation::removeCitation()
769 clist_selected_->rows().remove(clist_selected_->selection()[0]);
773 void FormCitation::moveCitationUp()
775 int i = clist_selected_->selection()[0].get_row_num();
776 clist_selected_->swap_rows( i-1, i );
777 clist_selected_->row(i-1).select();
781 void FormCitation::moveCitationDown()
783 int i = clist_selected_->selection()[0].get_row_num();
784 clist_selected_->swap_rows( i+1, i );
785 clist_selected_->row(i+1).select();
789 void FormCitation::hide()
791 if (dialog_!=0) mainAppWin->remove_action();
794 void FormCitation::free()
807 void FormCitation::applySelect()
809 if( lv_->buffer()->isReadonly() ) return;
814 contents = frontStrip( strip(params.getContents()) );
815 if (!contents.empty()) contents += ", ";
817 sz = clist_bib_->selection().size();
818 for (int i=0; i < sz; ++i)
820 if (i > 0) contents += ", ";
821 contents += clist_bib_->selection()[i][1].get_text();
824 params.setContents( contents );
825 params.setOptions( text_after_->get_entry()->get_text() );
829 // Only update if contents have changed
830 if( params != inset_->params() )
832 inset_->setParams( params );
833 lv_->view()->updateInset( inset_, true );
838 lv_->getLyXFunc()->Dispatch( LFUN_CITATION_INSERT,
839 params.getAsString() );
847 void FormCitation::applyEdit()
849 if( lv_->buffer()->isReadonly() ) return;
852 int const sz = clist_selected_->rows().size();
853 for( int i = 0; i < sz; ++i )
855 if (i > 0) contents += ", ";
856 contents += clist_selected_->cell(i, 0).get_text();
859 params.setContents( contents );
860 params.setOptions( text_after_->get_entry()->get_text() );
864 // Only update if contents have changed
865 if( params != inset_->params() )
867 inset_->setParams( params );
868 lv_->view()->updateInset( inset_, true );
873 lv_->getLyXFunc()->Dispatch( LFUN_CITATION_INSERT,
874 params.getAsString() );
882 void FormCitation::sortBibList(gint col)
884 clist_bib_->set_sort_column(col);
888 void FormCitation::search()
890 if (use_regexp_) searchReg();
894 // looking for entries which match regexp
895 void FormCitation::searchReg()
897 string tmp, rexptxt( search_string_ );
898 rexptxt = frontStrip( strip( rexptxt ) );
902 // populating clist_bib_
903 clist_bib_->rows().clear();
905 clist_bib_->freeze();
907 int const sz = bibkeys.size();
909 for ( int i = 0; i < sz; ++i )
911 string data = bibkeys[i] + bibkeysInfo[i];
913 if (rexptxt.empty()) additem = true;
914 else additem = (reg.exec(data).size() > 0);
916 if ( additem ) addItemToBibList(i);
923 // looking for entries which contain all the words specified in search_text entry
924 void FormCitation::searchSimple()
926 vector<string> searchwords;
928 string stext(search_string_);
929 stext = frontStrip( strip( stext ) );
930 stext = frontStrip( split(stext, tmp, ' ') );
931 while ( !tmp.empty() )
933 searchwords.push_back(tmp);
934 stext = frontStrip( split(stext, tmp, ' ') );
937 // populating clist_bib_
938 clist_bib_->rows().clear();
940 clist_bib_->freeze();
942 int const sz = bibkeys.size();
943 for (int i = 0; i < sz; ++i) {
944 string const data = bibkeys[i] + bibkeysInfo[i];
948 int const szs = searchwords.size();
949 for (int j = 0; additem && j < szs; ++j)
950 if (data.find(searchwords[j]) == string::npos)
953 if (additem) addItemToBibList(i);