1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
8 * ======================================================
16 #pragma implementation
22 #include "FormCitation.h"
26 #include "support/filetools.h"
27 #include "support/LRegex.h"
29 #include <gtk--/scrolledwindow.h>
30 #include <gnome--/pixmap.h>
31 #include <gtk--/label.h>
32 #include <gtk--/box.h>
33 #include <gtk--/buttonbox.h>
34 #include <gnome--/entry.h>
35 #include <gnome--/stock.h>
36 #include <gtk--/separator.h>
37 #include <libgnome/gnome-config.h>
38 #include <gtk--/alignment.h>
39 #include "pixbutton.h"
41 // temporary solution for LyXView
43 extern GLyxAppWin * mainAppWin;
54 string const LOCAL_CONFIGURE_PREFIX("FormCitation");
56 string const CONF_PANE_INFO("paneinfo");
57 string const CONF_PANE_INFO_DEFAULT("=300");
59 string const CONF_COLUMN("column");
60 string const CONF_COLUMN_DEFAULT("=50");
62 string const CONF_REGEXP("regexp");
63 string const CONF_REGEXP_DEFAULT("=0");
65 string const CONF_SEARCH("FormCitation_search");
66 string const CONF_TEXTAFTER("FormCitation_textafter");
71 FormCitation::FormCitation(LyXView * lv, Dialogs * d)
72 : lv_(lv), d_(d), inset_(0), u_(0), h_(0), ih_(0)
74 // let the dialog be shown
75 // These are permanent connections so we won't bother
76 // storing a copy because we won't be disconnecting.
77 d->showCitation.connect(SigC::slot(this, &FormCitation::showInset));
78 d->createCitation.connect(SigC::slot(this, &FormCitation::createInset));
83 FormCitation::~FormCitation()
88 void FormCitation::showInset( InsetCommand * const inset )
90 if( dialog_!=0 || inset == 0 ) return;
93 ih_ = inset_->hideDialog.connect(SigC::slot(this, &FormCitation::hide));
95 u_ = d_->updateBufferDependent.connect(SigC::slot(this, &FormCitation::updateSlot));
96 h_ = d_->hideBufferDependent.connect(SigC::slot(this, &FormCitation::hide));
98 params = inset->params();
100 if ( params.getContents().empty() ) showStageSearch();
101 else showStageAction();
105 void FormCitation::createInset( string const & arg )
107 if( dialog_!=0 ) return;
109 u_ = d_->updateBufferDependent.connect(SigC::slot(this, &FormCitation::updateSlot));
110 h_ = d_->hideBufferDependent.connect(SigC::slot(this, &FormCitation::hide));
112 params.setFromString( arg );
119 void parseBibTeX(string const & dat,
120 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) );
144 data = data.substr(keypos, data.length()-1);
145 data = frontStrip(strip(data));
146 if (data.length() > 1 && data[0]=='=')
148 data = frontStrip(data.substr(1, data.length()-1));
152 if (data[0]=='{') enclosing = '}';
153 else if (data[0]=='"') enclosing = '"';
154 else { keypos=0; enclosing=' '; }
157 data.find(enclosing)!=string::npos &&
160 tmp = data.substr(keypos, data.length()-1);
161 while (tmp.find('{')!=string::npos &&
162 tmp.find('}')!=string::npos &&
163 tmp.find('{') < tmp.find('}') &&
164 tmp.find('{') < tmp.find(enclosing))
166 keypos += tmp.find('{')+1;
167 tmp = data.substr(keypos, data.length()-1);
168 keypos += tmp.find('}')+1;
169 tmp = data.substr(keypos, data.length()-1);
172 if (tmp.find(enclosing)==string::npos) return;
175 keypos += tmp.find(enclosing);
176 tmp = data.substr(keypos, data.length()-1);
179 value = data.substr(1, keypos-1);
181 if (keypos+1<data.length()-1) data = frontStrip(data.substr(keypos+1, data.length()-1));
187 ) // numerical value ?
189 keypos = data.length()-1;
190 if (data.find(' ')!=string::npos) keypos = data.find(' ');
191 if (data.find(',')!=string::npos &&
192 keypos > data.find(','))
193 keypos = data.find(',');
195 value = data.substr(0, keypos);
197 if (keypos+1<data.length()-1) data = frontStrip(data.substr(keypos+1, data.length()-1));
202 if (findkey == key) { keyvalue = value; return; }
204 data = frontStrip(frontStrip(data,','));
214 void FormCitation::cleanupWidgets()
222 button_unselect_ = 0;
232 void FormCitation::initWidgets()
234 string const path = PACKAGE "/" + LOCAL_CONFIGURE_PREFIX;
236 if (search_text_ != 0)
238 search_text_->set_history_id(CONF_SEARCH);
239 search_text_->set_max_saved(10);
240 search_text_->load_history();
241 search_text_->set_use_arrows_always(true);
244 if (text_after_ != 0 )
246 text_after_->set_history_id(CONF_TEXTAFTER);
247 text_after_->set_max_saved(10);
248 text_after_->load_history();
249 text_after_->set_use_arrows_always(true);
250 text_after_->get_entry()->set_text(params.getOptions());
253 if (button_regexp_ != 0)
255 string w = path + "/" + CONF_REGEXP + CONF_REGEXP_DEFAULT;
256 button_regexp_->set_active( (gnome_config_get_int(w.c_str()) > 0) );
259 if (paned_info_ != 0)
261 string w = path + "/" + CONF_PANE_INFO + CONF_PANE_INFO_DEFAULT;
262 paned_info_->set_position( gnome_config_get_int(w.c_str()) );
268 clist_bib_->column(0).set_visiblity(false);
269 clist_bib_->set_selection_mode(GTK_SELECTION_BROWSE);
271 // setting up sizes of columns
273 int sz = clist_bib_->columns().size();
274 for (int i = 0; i < sz; ++i)
276 w = path + "/" + CONF_COLUMN + "_" + tostr(i) + CONF_COLUMN_DEFAULT;
277 clist_bib_->column(i).set_width( gnome_config_get_int(w.c_str()) );
281 vector<pair<string,string> > blist = lv_->buffer()->getBibkeyList();
284 for (int i = 0; i < sz; ++i )
286 bibkeys.push_back(blist[i].first);
287 bibkeysInfo.push_back(blist[i].second);
295 if (clist_bib_->rows().size() > 0)
297 clist_bib_->rows()[0].select();
298 selectionToggled(0, 0, 0, true, false);
302 if (clist_selected_ != 0)
304 clist_selected_->set_selection_mode(GTK_SELECTION_BROWSE);
306 // populating clist_selected_
308 string tmp, keys( params.getContents() );
309 keys = frontStrip( split(keys, tmp, ',') );
310 while( !tmp.empty() )
314 clist_selected_->rows().push_back(r);
316 keys = frontStrip( split(keys, tmp, ',') );
319 if (clist_selected_->rows().size() > 0)
321 clist_selected_->rows()[0].select();
322 selectionToggled(0, 0, 0, true, true);
330 void FormCitation::storeWidgets()
332 string const path = PACKAGE "/" + LOCAL_CONFIGURE_PREFIX;
334 if (search_text_ != 0) search_text_->save_history();
336 if (text_after_ != 0) text_after_->save_history();
338 if (button_regexp_ != 0)
340 string w = path + "/" + CONF_REGEXP;
341 gnome_config_set_int(w.c_str(), button_regexp_->get_active());
344 if (paned_info_ != 0)
346 string w = path + "/" + CONF_PANE_INFO;
347 gnome_config_set_int(w.c_str(), paned_info_->width() - info_->width());
353 int const sz = clist_bib_->columns().size();
354 for (int i = 0; i < sz; ++i)
356 w = path + "/" + CONF_COLUMN + "_" + tostr(i);
357 gnome_config_set_int(w.c_str(), clist_bib_->get_column_width(i));
365 void FormCitation::showStageAction()
369 using namespace Gtk::Box_Helpers;
371 Gtk::Alignment * mbox = manage( new Gtk::Alignment(0.5, 0.5, 0, 0) );
372 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
374 string const addlabel = _("_Add new citation");
375 string const editlabel = _("_Edit/remove citation(s)");
377 Gnome::PixButton * b_add = manage(new Gnome::PixButton(addlabel, GNOME_STOCK_PIXMAP_NEW));
378 Gnome::PixButton * b_edit = manage(new Gnome::PixButton(editlabel, GNOME_STOCK_PIXMAP_PROPERTIES));
380 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
383 bbox->set_spacing(4);
384 bbox->set_layout(GTK_BUTTONBOX_SPREAD);
386 bbox->children().push_back(Element(*b_add, false, false));
387 bbox->children().push_back(Element(*b_edit, false, false));
388 bbox->children().push_back(Element(*b_cancel, false, false));
393 Gtk::AccelGroup * accel = Gtk::AccelGroup::create();
395 b_add->add_accelerator("clicked", *accel, b_add->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
396 b_edit->add_accelerator("clicked", *accel, b_edit->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
398 // packing dialog to main window
400 mainAppWin->add_action(*dialog_, _(" Citation: Select action "), false, accel);
405 gtk_widget_grab_focus (GTK_WIDGET(b_add->gtkobj()));
407 // connecting signals
408 b_add->clicked.connect(slot(this, &FormCitation::moveFromActionToSearch));
409 b_edit->clicked.connect(slot(this, &FormCitation::moveFromActionToEdit));
411 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
413 dialog_->destroy.connect(slot(this, &FormCitation::free));
418 void FormCitation::moveFromActionToSearch()
420 // stores configuration and cleans all widgets
424 // moves to stage "search"
425 mainAppWin->remove_action();
430 void FormCitation::moveFromActionToEdit()
432 // stores configuration and cleans all widgets
436 // moves to stage "edit"
437 mainAppWin->remove_action();
442 void FormCitation::showStageSearch()
446 using namespace Gtk::Box_Helpers;
448 Gtk::Box * mbox = manage( new Gtk::HBox() );
449 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
450 Gtk::Separator * sep = manage( new Gtk::VSeparator() );
452 search_text_ = manage( new Gnome::Entry() );
454 button_regexp_ = manage( new Gtk::CheckButton(_("Use Regular Expression")) );
456 b_ok = manage( new Gtk::Button(_("Search")) );
457 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
460 mbox->set_spacing(4);
461 bbox->set_spacing(4);
464 bbox->children().push_back(Element(*b_ok, false, false));
465 bbox->children().push_back(Element(*b_cancel, false, false));
467 mbox->children().push_back(Element(*search_text_, true, true));
468 mbox->children().push_back(Element(*button_regexp_, false, false));
469 mbox->children().push_back(Element(*sep, false, false));
470 mbox->children().push_back(Element(*bbox, false, false));
472 // packing dialog to main window
474 mainAppWin->add_action(*dialog_, _(" Insert Citation: Enter keyword(s) or regular expression "));
479 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(search_text_->get_entry()->gtkobj()), GTK_CAN_DEFAULT);
480 gtk_widget_grab_focus (GTK_WIDGET(search_text_->get_entry()->gtkobj()));
481 gtk_widget_grab_default (GTK_WIDGET(search_text_->get_entry()->gtkobj()));
483 // connecting signals
484 b_ok->clicked.connect(SigC::slot(this, &FormCitation::moveFromSearchToSelect));
485 search_text_->get_entry()->activate.connect(SigC::slot(this, &FormCitation::moveFromSearchToSelect));
487 b_cancel->clicked.connect(SigC::slot(mainAppWin, &GLyxAppWin::remove_action));
488 dialog_->destroy.connect(SigC::slot(this, &FormCitation::free));
492 void FormCitation::moveFromSearchToSelect()
494 search_string_ = search_text_->get_entry()->get_text();
495 use_regexp_ = button_regexp_->get_active();
497 // stores configuration and cleans all widgets
501 // moves to stage "select"
502 mainAppWin->remove_action();
506 void FormCitation::showStageSelect()
510 using namespace Gtk::Box_Helpers;
512 Gtk::Box * mbox = manage( new Gtk::VBox() );
513 Gtk::Box * tbox = manage( new Gtk::HBox() );
514 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
515 Gtk::Separator * sep = manage( new Gtk::HSeparator() );
516 Gtk::ScrolledWindow * sw = manage( new Gtk::ScrolledWindow() );
518 info_ = manage( new Gnome::Less() );
519 paned_info_ = manage( new Gtk::HPaned() );
520 text_after_ = manage( new Gnome::Entry() );
522 b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
523 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
525 sw->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
527 // constructing CList
528 vector<string> colnames;
529 colnames.push_back("INVISIBLE");
530 colnames.push_back(_("Key"));
531 colnames.push_back(_("Author(s)"));
532 colnames.push_back(_("Title"));
533 colnames.push_back(_("Year"));
534 colnames.push_back(_("Journal"));
535 clist_bib_ = manage( new Gtk::CList(colnames) );
537 bbox->set_layout(GTK_BUTTONBOX_END);
540 mbox->set_spacing(4);
541 bbox->set_spacing(4);
542 tbox->set_spacing(4);
545 sw->add(*clist_bib_);
546 paned_info_->add1(*sw);
547 paned_info_->add2(*info_);
549 bbox->children().push_back(Element(*b_ok, false, false));
550 bbox->children().push_back(Element(*b_cancel, false, false));
552 tbox->children().push_back(Element(*manage(new Gtk::Label(_("Text after"))), false, false));
553 tbox->children().push_back(Element(*text_after_, true, true));
554 tbox->children().push_back(Element(*manage(new Gtk::VSeparator()), false, false));
555 tbox->children().push_back(Element(*bbox, false, false));
557 mbox->children().push_back(Element(*paned_info_,true,true));
558 mbox->children().push_back(Element(*sep, false, false));
559 mbox->children().push_back(Element(*tbox, false, false));
561 // packing dialog to main window
563 mainAppWin->add_action(*dialog_, _(" Insert Citation: Select citation "), true);
568 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_ok->gtkobj()), GTK_CAN_DEFAULT);
569 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_cancel->gtkobj()), GTK_CAN_DEFAULT);
570 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(clist_bib_->gtkobj()), GTK_CAN_DEFAULT);
571 gtk_widget_grab_focus (GTK_WIDGET(clist_bib_->gtkobj()));
572 gtk_widget_grab_default (GTK_WIDGET(b_ok->gtkobj()));
574 // connecting signals
575 b_ok->clicked.connect(SigC::slot(this, &FormCitation::applySelect));
576 text_after_->get_entry()->activate.connect(SigC::slot(this, &FormCitation::applySelect));
578 b_cancel->clicked.connect(SigC::slot(mainAppWin, &GLyxAppWin::remove_action));
580 dialog_->destroy.connect(SigC::slot(this, &FormCitation::free));
582 clist_bib_->click_column.connect(SigC::slot(this, &FormCitation::sortBibList));
583 clist_bib_->select_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
585 clist_bib_->unselect_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
590 void FormCitation::showStageEdit()
594 using namespace Gtk::Box_Helpers;
596 Gtk::Box * mbox = manage( new Gtk::VBox() );
597 Gtk::Box * tbox = manage( new Gtk::HBox() );
598 Gtk::Box * t2box = manage( new Gtk::HBox() );
599 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
600 Gtk::ButtonBox * actbbox = manage( new Gtk::VButtonBox() );
601 Gtk::ScrolledWindow * sw = manage( new Gtk::ScrolledWindow() );
603 vector<string> colnames;
604 colnames.push_back(" ");
605 clist_selected_ = manage( new Gtk::CList(colnames) );
606 clist_selected_->column_titles_hide();
608 text_after_ = manage( new Gnome::Entry() );
610 button_unselect_ = manage( new Gnome::PixButton( _("_Remove"), GNOME_STOCK_PIXMAP_TRASH ) );
611 button_up_ = manage( new Gnome::PixButton( _("_Up"), GNOME_STOCK_PIXMAP_UP ) );
612 button_down_ = manage( new Gnome::PixButton( _("_Down"), GNOME_STOCK_PIXMAP_DOWN ) );
614 b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
615 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
617 sw->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
619 bbox->set_layout(GTK_BUTTONBOX_END);
620 actbbox->set_layout(GTK_BUTTONBOX_START);
623 mbox->set_spacing(4);
624 bbox->set_spacing(4);
625 actbbox->set_spacing(4);
626 tbox->set_spacing(4);
627 t2box->set_spacing(4);
630 sw->add(*clist_selected_);
632 bbox->children().push_back(Element(*b_ok, false, false));
633 bbox->children().push_back(Element(*b_cancel, false, false));
635 actbbox->children().push_back(Element(*button_unselect_, false, false));
636 actbbox->children().push_back(Element(*button_up_, false, false));
637 actbbox->children().push_back(Element(*button_down_, false, false));
639 t2box->children().push_back(Element(*sw, true, true));
640 t2box->children().push_back(Element(*actbbox, false, false));
642 tbox->children().push_back(Element(*manage(new Gtk::Label(_("Text after"))), false, false));
643 tbox->children().push_back(Element(*text_after_, true, true));
644 tbox->children().push_back(Element(*manage(new Gtk::VSeparator()), false, false));
645 tbox->children().push_back(Element(*bbox, false, false));
647 mbox->children().push_back(Element(*t2box,true,true));
648 mbox->children().push_back(Element(*manage(new Gtk::HSeparator()), false, false));
649 mbox->children().push_back(Element(*tbox, false, false));
652 Gtk::AccelGroup * accel = Gtk::AccelGroup::create();
654 button_unselect_->add_accelerator("clicked", *accel, button_unselect_->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
655 button_up_->add_accelerator("clicked", *accel, button_up_->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
656 button_down_->add_accelerator("clicked", *accel, button_down_->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
658 // packing dialog to main window
660 mainAppWin->add_action(*dialog_, _(" Citation: Edit "), true, accel);
665 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_ok->gtkobj()), GTK_CAN_DEFAULT);
666 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_cancel->gtkobj()), GTK_CAN_DEFAULT);
667 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(clist_selected_->gtkobj()), GTK_CAN_DEFAULT);
668 gtk_widget_grab_focus (GTK_WIDGET(clist_selected_->gtkobj()));
669 gtk_widget_grab_default (GTK_WIDGET(b_ok->gtkobj()));
671 // connecting signals
672 b_ok->clicked.connect(SigC::slot(this, &FormCitation::applyEdit));
673 text_after_->get_entry()->activate.connect(SigC::slot(this, &FormCitation::applyEdit));
675 b_cancel->clicked.connect(SigC::slot(mainAppWin, &GLyxAppWin::remove_action));
677 dialog_->destroy.connect(SigC::slot(this, &FormCitation::free));
679 button_unselect_->clicked.connect(SigC::slot(this, &FormCitation::removeCitation));
680 button_up_->clicked.connect(SigC::slot(this, &FormCitation::moveCitationUp));
681 button_down_->clicked.connect(SigC::slot(this, &FormCitation::moveCitationDown));
683 clist_selected_->select_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
685 clist_selected_->unselect_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
691 void FormCitation::addItemToBibList(int i)
698 info = bibkeysInfo[i];
700 // don't change the order of these first two items:
701 // callback functions depend on the data stored in the first column (its hided)
702 // and in the second column (shown to user)
703 r.push_back( tostr(i) );
706 // this can be changed (configured by user?)
707 parseBibTeX( info, "author", val); r.push_back(val);
708 parseBibTeX( info, "title", val); r.push_back(val);
709 parseBibTeX( info, "year", val); r.push_back(val);
710 parseBibTeX( info, "journal", val); r.push_back(val);
712 clist_bib_->rows().push_back(r);
716 void FormCitation::updateButtons()
718 if (button_unselect_ != 0) // => button_up_ and button_down_ are != 0
722 sens = (clist_selected_->selection().size()>0);
723 button_unselect_->set_sensitive(sens);
724 button_up_->set_sensitive(sens &&
725 clist_selected_->selection()[0].get_row_num()>0);
726 button_down_->set_sensitive(sens &&
727 clist_selected_->selection()[0].get_row_num() <
728 clist_selected_->rows().size()-1);
733 void FormCitation::updateSlot(bool buffchanged)
735 if (buffchanged) hide();
739 void FormCitation::selectionToggled(gint row,
749 bool keyfound = false;
752 // the first column in clist_bib_ contains the index
754 info = bibkeysInfo[ strToInt(clist_bib_->cell(row,0).get_text()) ];
757 info_->show_string(info);
759 info_->show_string(_("--- No such key in the database ---"));
763 info_->show_string("");
770 void FormCitation::removeCitation()
772 clist_selected_->rows().remove(clist_selected_->selection()[0]);
776 void FormCitation::moveCitationUp()
778 int i = clist_selected_->selection()[0].get_row_num();
779 clist_selected_->swap_rows( i-1, i );
780 clist_selected_->row(i-1).select();
784 void FormCitation::moveCitationDown()
786 int i = clist_selected_->selection()[0].get_row_num();
787 clist_selected_->swap_rows( i+1, i );
788 clist_selected_->row(i+1).select();
792 void FormCitation::hide()
794 if (dialog_!=0) mainAppWin->remove_action();
797 void FormCitation::free()
810 void FormCitation::applySelect()
812 if( lv_->buffer()->isReadonly() ) return;
814 string contents = frontStrip( strip(params.getContents()) );
815 if (!contents.empty()) contents += ", ";
817 int 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 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 const 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);