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;
55 string const LOCAL_CONFIGURE_PREFIX("FormCitation");
57 string const CONF_PANE_INFO("paneinfo");
58 string const CONF_PANE_INFO_DEFAULT("=300");
60 string const CONF_COLUMN("column");
61 string const CONF_COLUMN_DEFAULT("=50");
63 string const CONF_REGEXP("regexp");
64 string const CONF_REGEXP_DEFAULT("=0");
66 string const CONF_SEARCH("FormCitation_search");
67 string const CONF_TEXTAFTER("FormCitation_textafter");
72 FormCitation::FormCitation(LyXView * lv, Dialogs * d)
73 : lv_(lv), d_(d), inset_(0), u_(0), h_(0), ih_(0)
75 // let the dialog be shown
76 // These are permanent connections so we won't bother
77 // storing a copy because we won't be disconnecting.
78 d->showCitation.connect(SigC::slot(this, &FormCitation::showInset));
79 d->createCitation.connect(SigC::slot(this, &FormCitation::createInset));
84 FormCitation::~FormCitation()
89 void FormCitation::showInset( InsetCommand * const inset )
91 if( dialog_!=0 || inset == 0 ) return;
94 ih_ = inset_->hideDialog.connect(SigC::slot(this, &FormCitation::hide));
96 u_ = d_->updateBufferDependent.connect(SigC::slot(this, &FormCitation::updateSlot));
97 h_ = d_->hideBufferDependent.connect(SigC::slot(this, &FormCitation::hide));
99 params = inset->params();
101 if ( params.getContents().empty() ) showStageSearch();
102 else showStageAction();
106 void FormCitation::createInset( string const & arg )
108 if( dialog_!=0 ) return;
110 u_ = d_->updateBufferDependent.connect(SigC::slot(this, &FormCitation::updateSlot));
111 h_ = d_->hideBufferDependent.connect(SigC::slot(this, &FormCitation::hide));
113 params.setFromString( arg );
120 void parseBibTeX(string const & dat,
121 string const & findkey,
129 for (i=0; i<data.length(); ++i)
130 if (data[i]=='\n' || data[i]=='\t')
133 data = frontStrip(data);
136 && (data.find(' ')!=string::npos ||
137 data.find('=')!=string::npos) )
139 unsigned int keypos = min(data.find(' '), data.find('='));
140 string key = lowercase( data.substr(0, keypos) );
145 data = data.substr(keypos, data.length()-1);
146 data = frontStrip(strip(data));
147 if (data.length() > 1 && data[0]=='=')
149 data = frontStrip(data.substr(1, data.length()-1));
153 if (data[0]=='{') enclosing = '}';
154 else if (data[0]=='"') enclosing = '"';
155 else { keypos=0; enclosing=' '; }
158 data.find(enclosing)!=string::npos &&
161 tmp = data.substr(keypos, data.length()-1);
162 while (tmp.find('{')!=string::npos &&
163 tmp.find('}')!=string::npos &&
164 tmp.find('{') < tmp.find('}') &&
165 tmp.find('{') < tmp.find(enclosing))
167 keypos += tmp.find('{')+1;
168 tmp = data.substr(keypos, data.length()-1);
169 keypos += tmp.find('}')+1;
170 tmp = data.substr(keypos, data.length()-1);
173 if (tmp.find(enclosing)==string::npos) return;
176 keypos += tmp.find(enclosing);
177 tmp = data.substr(keypos, data.length()-1);
180 value = data.substr(1, keypos-1);
182 if (keypos+1<data.length()-1) data = frontStrip(data.substr(keypos+1, data.length()-1));
188 ) // numerical value ?
190 keypos = data.length()-1;
191 if (data.find(' ')!=string::npos) keypos = data.find(' ');
192 if (data.find(',')!=string::npos &&
193 keypos > data.find(','))
194 keypos = data.find(',');
196 value = data.substr(0, keypos);
198 if (keypos+1<data.length()-1) data = frontStrip(data.substr(keypos+1, data.length()-1));
203 if (findkey == key) { keyvalue = value; return; }
205 data = frontStrip(frontStrip(data,','));
215 void FormCitation::cleanupWidgets()
223 button_unselect_ = 0;
233 void FormCitation::initWidgets()
235 string const path = PACKAGE "/" + LOCAL_CONFIGURE_PREFIX;
237 if (search_text_ != 0)
239 search_text_->set_history_id(CONF_SEARCH);
240 search_text_->set_max_saved(10);
241 search_text_->load_history();
242 search_text_->set_use_arrows_always(true);
245 if (text_after_ != 0 )
247 text_after_->set_history_id(CONF_TEXTAFTER);
248 text_after_->set_max_saved(10);
249 text_after_->load_history();
250 text_after_->set_use_arrows_always(true);
251 text_after_->get_entry()->set_text(params.getOptions());
254 if (button_regexp_ != 0)
256 string w = path + "/" + CONF_REGEXP + CONF_REGEXP_DEFAULT;
257 button_regexp_->set_active( (gnome_config_get_int(w.c_str()) > 0) );
260 if (paned_info_ != 0)
262 string w = path + "/" + CONF_PANE_INFO + CONF_PANE_INFO_DEFAULT;
263 paned_info_->set_position( gnome_config_get_int(w.c_str()) );
269 clist_bib_->column(0).set_visiblity(false);
270 clist_bib_->set_selection_mode(GTK_SELECTION_BROWSE);
272 // setting up sizes of columns
274 int sz = clist_bib_->columns().size();
275 for (int i = 0; i < sz; ++i)
277 w = path + "/" + CONF_COLUMN + "_" + tostr(i) + CONF_COLUMN_DEFAULT;
278 clist_bib_->column(i).set_width( gnome_config_get_int(w.c_str()) );
282 vector<pair<string,string> > blist = lv_->buffer()->getBibkeyList();
285 for (int i = 0; i < sz; ++i )
287 bibkeys.push_back(blist[i].first);
288 bibkeysInfo.push_back(blist[i].second);
296 if (clist_bib_->rows().size() > 0)
298 clist_bib_->rows()[0].select();
299 selectionToggled(0, 0, 0, true, false);
303 if (clist_selected_ != 0)
305 clist_selected_->set_selection_mode(GTK_SELECTION_BROWSE);
307 // populating clist_selected_
309 string tmp, keys( params.getContents() );
310 keys = frontStrip( split(keys, tmp, ',') );
311 while( !tmp.empty() )
315 clist_selected_->rows().push_back(r);
317 keys = frontStrip( split(keys, tmp, ',') );
320 if (clist_selected_->rows().size() > 0)
322 clist_selected_->rows()[0].select();
323 selectionToggled(0, 0, 0, true, true);
331 void FormCitation::storeWidgets()
333 string const path = PACKAGE "/" + LOCAL_CONFIGURE_PREFIX;
335 if (search_text_ != 0) search_text_->save_history();
337 if (text_after_ != 0) text_after_->save_history();
339 if (button_regexp_ != 0)
341 string w = path + "/" + CONF_REGEXP;
342 gnome_config_set_int(w.c_str(), button_regexp_->get_active());
345 if (paned_info_ != 0)
347 string w = path + "/" + CONF_PANE_INFO;
348 gnome_config_set_int(w.c_str(), paned_info_->width() - info_->width());
354 int const sz = clist_bib_->columns().size();
355 for (int i = 0; i < sz; ++i)
357 w = path + "/" + CONF_COLUMN + "_" + tostr(i);
358 gnome_config_set_int(w.c_str(), clist_bib_->get_column_width(i));
366 void FormCitation::showStageAction()
370 using namespace Gtk::Box_Helpers;
372 Gtk::Alignment * mbox = manage( new Gtk::Alignment(0.5, 0.5, 0, 0) );
373 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
375 string const addlabel = _("_Add new citation");
376 string const editlabel = _("_Edit/remove citation(s)");
378 Gnome::PixButton * b_add = manage(new Gnome::PixButton(addlabel, GNOME_STOCK_PIXMAP_NEW));
379 Gnome::PixButton * b_edit = manage(new Gnome::PixButton(editlabel, GNOME_STOCK_PIXMAP_PROPERTIES));
381 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
384 bbox->set_spacing(4);
385 bbox->set_layout(GTK_BUTTONBOX_SPREAD);
387 bbox->children().push_back(Element(*b_add, false, false));
388 bbox->children().push_back(Element(*b_edit, false, false));
389 bbox->children().push_back(Element(*b_cancel, false, false));
394 Gtk::AccelGroup * accel = Gtk::AccelGroup::create();
396 b_add->add_accelerator("clicked", *accel, b_add->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
397 b_edit->add_accelerator("clicked", *accel, b_edit->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
399 // packing dialog to main window
401 mainAppWin->add_action(*dialog_, _(" Citation: Select action "), false, accel);
406 gtk_widget_grab_focus (GTK_WIDGET(b_add->gtkobj()));
408 // connecting signals
409 b_add->clicked.connect(slot(this, &FormCitation::moveFromActionToSearch));
410 b_edit->clicked.connect(slot(this, &FormCitation::moveFromActionToEdit));
412 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
414 dialog_->destroy.connect(slot(this, &FormCitation::free));
419 void FormCitation::moveFromActionToSearch()
421 // stores configuration and cleans all widgets
425 // moves to stage "search"
426 mainAppWin->remove_action();
431 void FormCitation::moveFromActionToEdit()
433 // stores configuration and cleans all widgets
437 // moves to stage "edit"
438 mainAppWin->remove_action();
443 void FormCitation::showStageSearch()
447 using namespace Gtk::Box_Helpers;
449 Gtk::Box * mbox = manage( new Gtk::HBox() );
450 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
451 Gtk::Separator * sep = manage( new Gtk::VSeparator() );
453 search_text_ = manage( new Gnome::Entry() );
455 button_regexp_ = manage( new Gtk::CheckButton(_("Use Regular Expression")) );
457 b_ok = manage( new Gtk::Button(_("Search")) );
458 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
461 mbox->set_spacing(4);
462 bbox->set_spacing(4);
465 bbox->children().push_back(Element(*b_ok, false, false));
466 bbox->children().push_back(Element(*b_cancel, false, false));
468 mbox->children().push_back(Element(*search_text_, true, true));
469 mbox->children().push_back(Element(*button_regexp_, false, false));
470 mbox->children().push_back(Element(*sep, false, false));
471 mbox->children().push_back(Element(*bbox, false, false));
473 // packing dialog to main window
475 mainAppWin->add_action(*dialog_, _(" Insert Citation: Enter keyword(s) or regular expression "));
480 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(search_text_->get_entry()->gtkobj()), GTK_CAN_DEFAULT);
481 gtk_widget_grab_focus (GTK_WIDGET(search_text_->get_entry()->gtkobj()));
482 gtk_widget_grab_default (GTK_WIDGET(search_text_->get_entry()->gtkobj()));
484 // connecting signals
485 b_ok->clicked.connect(SigC::slot(this, &FormCitation::moveFromSearchToSelect));
486 search_text_->get_entry()->activate.connect(SigC::slot(this, &FormCitation::moveFromSearchToSelect));
488 b_cancel->clicked.connect(SigC::slot(mainAppWin, &GLyxAppWin::remove_action));
489 dialog_->destroy.connect(SigC::slot(this, &FormCitation::free));
493 void FormCitation::moveFromSearchToSelect()
495 search_string_ = search_text_->get_entry()->get_text();
496 use_regexp_ = button_regexp_->get_active();
498 // stores configuration and cleans all widgets
502 // moves to stage "select"
503 mainAppWin->remove_action();
507 void FormCitation::showStageSelect()
511 using namespace Gtk::Box_Helpers;
513 Gtk::Box * mbox = manage( new Gtk::VBox() );
514 Gtk::Box * tbox = manage( new Gtk::HBox() );
515 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
516 Gtk::Separator * sep = manage( new Gtk::HSeparator() );
517 Gtk::ScrolledWindow * sw = manage( new Gtk::ScrolledWindow() );
519 info_ = manage( new Gnome::Less() );
520 paned_info_ = manage( new Gtk::HPaned() );
521 text_after_ = manage( new Gnome::Entry() );
523 b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
524 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
526 sw->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
528 // constructing CList
529 vector<string> colnames;
530 colnames.push_back("INVISIBLE");
531 colnames.push_back(_("Key"));
532 colnames.push_back(_("Author(s)"));
533 colnames.push_back(_("Title"));
534 colnames.push_back(_("Year"));
535 colnames.push_back(_("Journal"));
536 clist_bib_ = manage( new Gtk::CList(colnames) );
538 bbox->set_layout(GTK_BUTTONBOX_END);
541 mbox->set_spacing(4);
542 bbox->set_spacing(4);
543 tbox->set_spacing(4);
546 sw->add(*clist_bib_);
547 paned_info_->add1(*sw);
548 paned_info_->add2(*info_);
550 bbox->children().push_back(Element(*b_ok, false, false));
551 bbox->children().push_back(Element(*b_cancel, false, false));
553 tbox->children().push_back(Element(*manage(new Gtk::Label(_("Text after"))), false, false));
554 tbox->children().push_back(Element(*text_after_, true, true));
555 tbox->children().push_back(Element(*manage(new Gtk::VSeparator()), false, false));
556 tbox->children().push_back(Element(*bbox, false, false));
558 mbox->children().push_back(Element(*paned_info_,true,true));
559 mbox->children().push_back(Element(*sep, false, false));
560 mbox->children().push_back(Element(*tbox, false, false));
562 // packing dialog to main window
564 mainAppWin->add_action(*dialog_, _(" Insert Citation: Select citation "), true);
569 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_ok->gtkobj()), GTK_CAN_DEFAULT);
570 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_cancel->gtkobj()), GTK_CAN_DEFAULT);
571 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(clist_bib_->gtkobj()), GTK_CAN_DEFAULT);
572 gtk_widget_grab_focus (GTK_WIDGET(clist_bib_->gtkobj()));
573 gtk_widget_grab_default (GTK_WIDGET(b_ok->gtkobj()));
575 // connecting signals
576 b_ok->clicked.connect(SigC::slot(this, &FormCitation::applySelect));
577 text_after_->get_entry()->activate.connect(SigC::slot(this, &FormCitation::applySelect));
579 b_cancel->clicked.connect(SigC::slot(mainAppWin, &GLyxAppWin::remove_action));
581 dialog_->destroy.connect(SigC::slot(this, &FormCitation::free));
583 clist_bib_->click_column.connect(SigC::slot(this, &FormCitation::sortBibList));
584 clist_bib_->select_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
586 clist_bib_->unselect_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
591 void FormCitation::showStageEdit()
595 using namespace Gtk::Box_Helpers;
597 Gtk::Box * mbox = manage( new Gtk::VBox() );
598 Gtk::Box * tbox = manage( new Gtk::HBox() );
599 Gtk::Box * t2box = manage( new Gtk::HBox() );
600 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
601 Gtk::ButtonBox * actbbox = manage( new Gtk::VButtonBox() );
602 Gtk::ScrolledWindow * sw = manage( new Gtk::ScrolledWindow() );
604 vector<string> colnames;
605 colnames.push_back(" ");
606 clist_selected_ = manage( new Gtk::CList(colnames) );
607 clist_selected_->column_titles_hide();
609 text_after_ = manage( new Gnome::Entry() );
611 button_unselect_ = manage( new Gnome::PixButton( _("_Remove"), GNOME_STOCK_PIXMAP_TRASH ) );
612 button_up_ = manage( new Gnome::PixButton( _("_Up"), GNOME_STOCK_PIXMAP_UP ) );
613 button_down_ = manage( new Gnome::PixButton( _("_Down"), GNOME_STOCK_PIXMAP_DOWN ) );
615 b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
616 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
618 sw->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
620 bbox->set_layout(GTK_BUTTONBOX_END);
621 actbbox->set_layout(GTK_BUTTONBOX_START);
624 mbox->set_spacing(4);
625 bbox->set_spacing(4);
626 actbbox->set_spacing(4);
627 tbox->set_spacing(4);
628 t2box->set_spacing(4);
631 sw->add(*clist_selected_);
633 bbox->children().push_back(Element(*b_ok, false, false));
634 bbox->children().push_back(Element(*b_cancel, false, false));
636 actbbox->children().push_back(Element(*button_unselect_, false, false));
637 actbbox->children().push_back(Element(*button_up_, false, false));
638 actbbox->children().push_back(Element(*button_down_, false, false));
640 t2box->children().push_back(Element(*sw, true, true));
641 t2box->children().push_back(Element(*actbbox, false, false));
643 tbox->children().push_back(Element(*manage(new Gtk::Label(_("Text after"))), false, false));
644 tbox->children().push_back(Element(*text_after_, true, true));
645 tbox->children().push_back(Element(*manage(new Gtk::VSeparator()), false, false));
646 tbox->children().push_back(Element(*bbox, false, false));
648 mbox->children().push_back(Element(*t2box,true,true));
649 mbox->children().push_back(Element(*manage(new Gtk::HSeparator()), false, false));
650 mbox->children().push_back(Element(*tbox, false, false));
653 Gtk::AccelGroup * accel = Gtk::AccelGroup::create();
655 button_unselect_->add_accelerator("clicked", *accel, button_unselect_->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
656 button_up_->add_accelerator("clicked", *accel, button_up_->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
657 button_down_->add_accelerator("clicked", *accel, button_down_->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
659 // packing dialog to main window
661 mainAppWin->add_action(*dialog_, _(" Citation: Edit "), true, accel);
666 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_ok->gtkobj()), GTK_CAN_DEFAULT);
667 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_cancel->gtkobj()), GTK_CAN_DEFAULT);
668 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(clist_selected_->gtkobj()), GTK_CAN_DEFAULT);
669 gtk_widget_grab_focus (GTK_WIDGET(clist_selected_->gtkobj()));
670 gtk_widget_grab_default (GTK_WIDGET(b_ok->gtkobj()));
672 // connecting signals
673 b_ok->clicked.connect(SigC::slot(this, &FormCitation::applyEdit));
674 text_after_->get_entry()->activate.connect(SigC::slot(this, &FormCitation::applyEdit));
676 b_cancel->clicked.connect(SigC::slot(mainAppWin, &GLyxAppWin::remove_action));
678 dialog_->destroy.connect(SigC::slot(this, &FormCitation::free));
680 button_unselect_->clicked.connect(SigC::slot(this, &FormCitation::removeCitation));
681 button_up_->clicked.connect(SigC::slot(this, &FormCitation::moveCitationUp));
682 button_down_->clicked.connect(SigC::slot(this, &FormCitation::moveCitationDown));
684 clist_selected_->select_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
686 clist_selected_->unselect_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
692 void FormCitation::addItemToBibList(int i)
699 info = bibkeysInfo[i];
701 // don't change the order of these first two items:
702 // callback functions depend on the data stored in the first column (its hided)
703 // and in the second column (shown to user)
704 r.push_back( tostr(i) );
707 // this can be changed (configured by user?)
708 parseBibTeX( info, "author", val); r.push_back(val);
709 parseBibTeX( info, "title", val); r.push_back(val);
710 parseBibTeX( info, "year", val); r.push_back(val);
711 parseBibTeX( info, "journal", val); r.push_back(val);
713 clist_bib_->rows().push_back(r);
717 void FormCitation::updateButtons()
719 if (button_unselect_ != 0) // => button_up_ and button_down_ are != 0
723 sens = (clist_selected_->selection().size()>0);
724 button_unselect_->set_sensitive(sens);
725 button_up_->set_sensitive(sens &&
726 clist_selected_->selection()[0].get_row_num()>0);
727 button_down_->set_sensitive(sens &&
728 clist_selected_->selection()[0].get_row_num() <
729 clist_selected_->rows().size()-1);
734 void FormCitation::updateSlot(bool buffchanged)
736 if (buffchanged) hide();
740 void FormCitation::selectionToggled(gint row,
750 bool keyfound = false;
753 // the first column in clist_bib_ contains the index
755 info = bibkeysInfo[ strToInt(clist_bib_->cell(row,0).get_text()) ];
758 info_->show_string(info);
760 info_->show_string(_("--- No such key in the database ---"));
764 info_->show_string("");
771 void FormCitation::removeCitation()
773 clist_selected_->rows().remove(clist_selected_->selection()[0]);
777 void FormCitation::moveCitationUp()
779 int i = clist_selected_->selection()[0].get_row_num();
780 clist_selected_->swap_rows( i-1, i );
781 clist_selected_->row(i-1).select();
785 void FormCitation::moveCitationDown()
787 int i = clist_selected_->selection()[0].get_row_num();
788 clist_selected_->swap_rows( i+1, i );
789 clist_selected_->row(i+1).select();
793 void FormCitation::hide()
795 if (dialog_!=0) mainAppWin->remove_action();
798 void FormCitation::free()
811 void FormCitation::applySelect()
813 if( lv_->buffer()->isReadonly() ) return;
815 string contents = frontStrip( strip(params.getContents()) );
816 if (!contents.empty()) contents += ", ";
818 int sz = clist_bib_->selection().size();
819 for (int i=0; i < sz; ++i)
821 if (i > 0) contents += ", ";
822 contents += clist_bib_->selection()[i][1].get_text();
825 params.setContents( contents );
826 params.setOptions( text_after_->get_entry()->get_text() );
830 // Only update if contents have changed
831 if( params != inset_->params() )
833 inset_->setParams( params );
834 lv_->view()->updateInset( inset_, true );
839 lv_->getLyXFunc()->Dispatch( LFUN_CITATION_INSERT,
840 params.getAsString() );
848 void FormCitation::applyEdit()
850 if( lv_->buffer()->isReadonly() ) return;
853 int const sz = clist_selected_->rows().size();
854 for( int i = 0; i < sz; ++i )
856 if (i > 0) contents += ", ";
857 contents += clist_selected_->cell(i, 0).get_text();
860 params.setContents( contents );
861 params.setOptions( text_after_->get_entry()->get_text() );
865 // Only update if contents have changed
866 if( params != inset_->params() )
868 inset_->setParams( params );
869 lv_->view()->updateInset( inset_, true );
874 lv_->getLyXFunc()->Dispatch( LFUN_CITATION_INSERT,
875 params.getAsString() );
883 void FormCitation::sortBibList(gint col)
885 clist_bib_->set_sort_column(col);
889 void FormCitation::search()
891 if (use_regexp_) searchReg();
895 // looking for entries which match regexp
896 void FormCitation::searchReg()
898 string rexptxt(search_string_);
899 rexptxt = frontStrip( strip( rexptxt ) );
903 // populating clist_bib_
904 clist_bib_->rows().clear();
906 clist_bib_->freeze();
908 int const sz = bibkeys.size();
910 for ( int i = 0; i < sz; ++i )
912 string const data = bibkeys[i] + bibkeysInfo[i];
914 if (rexptxt.empty()) additem = true;
915 else additem = (reg.exec(data).size() > 0);
917 if ( additem ) addItemToBibList(i);
924 // looking for entries which contain all the words specified in search_text entry
925 void FormCitation::searchSimple()
927 vector<string> searchwords;
929 string stext(search_string_);
930 stext = frontStrip( strip( stext ) );
931 stext = frontStrip( split(stext, tmp, ' ') );
932 while ( !tmp.empty() )
934 searchwords.push_back(tmp);
935 stext = frontStrip( split(stext, tmp, ' ') );
938 // populating clist_bib_
939 clist_bib_->rows().clear();
941 clist_bib_->freeze();
943 int const sz = bibkeys.size();
944 for (int i = 0; i < sz; ++i) {
945 string const data = bibkeys[i] + bibkeysInfo[i];
949 int const szs = searchwords.size();
950 for (int j = 0; additem && j < szs; ++j)
951 if (data.find(searchwords[j]) == string::npos)
954 if (additem) addItemToBibList(i);