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;
53 static string const LOCAL_CONFIGURE_PREFIX("FormCitation");
55 static string const CONF_PANE_INFO("paneinfo");
56 static string const CONF_PANE_INFO_DEFAULT("=300");
58 static string const CONF_COLUMN("column");
59 static string const CONF_COLUMN_DEFAULT("=50");
61 static string const CONF_REGEXP("regexp");
62 static string const CONF_REGEXP_DEFAULT("=0");
64 static string const CONF_SEARCH("FormCitation_search");
65 static string const CONF_TEXTAFTER("FormCitation_textafter");
67 FormCitation::FormCitation(LyXView * lv, Dialogs * d)
68 : lv_(lv), d_(d), inset_(0), u_(0), h_(0), ih_(0)
70 // let the dialog be shown
71 // These are permanent connections so we won't bother
72 // storing a copy because we won't be disconnecting.
73 d->showCitation.connect(SigC::slot(this, &FormCitation::showInset));
74 d->createCitation.connect(SigC::slot(this, &FormCitation::createInset));
79 FormCitation::~FormCitation()
84 void FormCitation::showInset( InsetCommand * const inset )
86 if( dialog_!=0 || inset == 0 ) return;
89 ih_ = inset_->hideDialog.connect(SigC::slot(this, &FormCitation::hide));
91 u_ = d_->updateBufferDependent.connect(SigC::slot(this, &FormCitation::updateSlot));
92 h_ = d_->hideBufferDependent.connect(SigC::slot(this, &FormCitation::hide));
94 params = inset->params();
96 if ( params.getContents().empty() ) showStageSearch();
97 else showStageAction();
101 void FormCitation::createInset( string const & arg )
103 if( dialog_!=0 ) return;
105 u_ = d_->updateBufferDependent.connect(SigC::slot(this, &FormCitation::updateSlot));
106 h_ = d_->hideBufferDependent.connect(SigC::slot(this, &FormCitation::hide));
108 params.setFromString( arg );
114 void parseBibTeX(string const & dat,
115 string const & findkey,
123 for (i=0; i<data.length(); ++i)
124 if (data[i]=='\n' || data[i]=='\t')
127 data = frontStrip(data);
130 && (data.find(' ')!=string::npos ||
131 data.find('=')!=string::npos) )
133 unsigned int keypos = min(data.find(' '), data.find('='));
134 string key = lowercase( data.substr(0, keypos) );
139 data = data.substr(keypos, data.length()-1);
140 data = frontStrip(strip(data));
141 if (data.length() > 1 && data[0]=='=')
143 data = frontStrip(data.substr(1, data.length()-1));
147 if (data[0]=='{') enclosing = '}';
148 else if (data[0]=='"') enclosing = '"';
149 else { keypos=0; enclosing=' '; }
152 data.find(enclosing)!=string::npos &&
155 tmp = data.substr(keypos, data.length()-1);
156 while (tmp.find('{')!=string::npos &&
157 tmp.find('}')!=string::npos &&
158 tmp.find('{') < tmp.find('}') &&
159 tmp.find('{') < tmp.find(enclosing))
161 keypos += tmp.find('{')+1;
162 tmp = data.substr(keypos, data.length()-1);
163 keypos += tmp.find('}')+1;
164 tmp = data.substr(keypos, data.length()-1);
167 if (tmp.find(enclosing)==string::npos) return;
170 keypos += tmp.find(enclosing);
171 tmp = data.substr(keypos, data.length()-1);
174 value = data.substr(1, keypos-1);
176 if (keypos+1<data.length()-1) data = frontStrip(data.substr(keypos+1, data.length()-1));
182 ) // numerical value ?
184 keypos = data.length()-1;
185 if (data.find(' ')!=string::npos) keypos = data.find(' ');
186 if (data.find(',')!=string::npos &&
187 keypos > data.find(','))
188 keypos = data.find(',');
190 value = data.substr(0, keypos);
192 if (keypos+1<data.length()-1) data = frontStrip(data.substr(keypos+1, data.length()-1));
197 if (findkey == key) { keyvalue = value; return; }
199 data = frontStrip(frontStrip(data,','));
207 void FormCitation::cleanupWidgets()
215 button_unselect_ = 0;
225 void FormCitation::initWidgets()
227 string const path = PACKAGE "/" + LOCAL_CONFIGURE_PREFIX;
229 if (search_text_ != 0)
231 search_text_->set_history_id(CONF_SEARCH);
232 search_text_->set_max_saved(10);
233 search_text_->load_history();
234 search_text_->set_use_arrows_always(true);
237 if (text_after_ != 0 )
239 text_after_->set_history_id(CONF_TEXTAFTER);
240 text_after_->set_max_saved(10);
241 text_after_->load_history();
242 text_after_->set_use_arrows_always(true);
243 text_after_->get_entry()->set_text(params.getOptions());
246 if (button_regexp_ != 0)
248 string w = path + "/" + CONF_REGEXP + CONF_REGEXP_DEFAULT;
249 button_regexp_->set_active( (gnome_config_get_int(w.c_str()) > 0) );
252 if (paned_info_ != 0)
254 string w = path + "/" + CONF_PANE_INFO + CONF_PANE_INFO_DEFAULT;
255 paned_info_->set_position( gnome_config_get_int(w.c_str()) );
261 clist_bib_->column(0).set_visiblity(false);
262 clist_bib_->set_selection_mode(GTK_SELECTION_BROWSE);
264 // setting up sizes of columns
266 int sz = clist_bib_->columns().size();
267 for (int i = 0; i < sz; ++i)
269 w = path + "/" + CONF_COLUMN + "_" + tostr(i) + CONF_COLUMN_DEFAULT;
270 clist_bib_->column(i).set_width( gnome_config_get_int(w.c_str()) );
274 vector<pair<string,string> > blist = lv_->buffer()->getBibkeyList();
277 for (int i = 0; i < sz; ++i )
279 bibkeys.push_back(blist[i].first);
280 bibkeysInfo.push_back(blist[i].second);
288 if (clist_bib_->rows().size() > 0)
290 clist_bib_->rows()[0].select();
291 selectionToggled(0, 0, 0, true, false);
295 if (clist_selected_ != 0)
297 clist_selected_->set_selection_mode(GTK_SELECTION_BROWSE);
299 // populating clist_selected_
301 string tmp, keys( params.getContents() );
302 keys = frontStrip( split(keys, tmp, ',') );
303 while( !tmp.empty() )
307 clist_selected_->rows().push_back(r);
309 keys = frontStrip( split(keys, tmp, ',') );
312 if (clist_selected_->rows().size() > 0)
314 clist_selected_->rows()[0].select();
315 selectionToggled(0, 0, 0, true, true);
323 void FormCitation::storeWidgets()
325 string const path = PACKAGE "/" + LOCAL_CONFIGURE_PREFIX;
327 if (search_text_ != 0) search_text_->save_history();
329 if (text_after_ != 0) text_after_->save_history();
331 if (button_regexp_ != 0)
333 string w = path + "/" + CONF_REGEXP;
334 gnome_config_set_int(w.c_str(), button_regexp_->get_active());
337 if (paned_info_ != 0)
339 string w = path + "/" + CONF_PANE_INFO;
340 gnome_config_set_int(w.c_str(), paned_info_->width() - info_->width());
346 int const sz = clist_bib_->columns().size();
347 for (int i = 0; i < sz; ++i)
349 w = path + "/" + CONF_COLUMN + "_" + tostr(i);
350 gnome_config_set_int(w.c_str(), clist_bib_->get_column_width(i));
358 void FormCitation::showStageAction()
362 using namespace Gtk::Box_Helpers;
364 Gtk::Alignment * mbox = manage( new Gtk::Alignment(0.5, 0.5, 0, 0) );
365 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
367 string const addlabel = _("_Add new citation");
368 string const editlabel = _("_Edit/remove citation(s)");
370 Gnome::PixButton * b_add = manage(new Gnome::PixButton(addlabel, GNOME_STOCK_PIXMAP_NEW));
371 Gnome::PixButton * b_edit = manage(new Gnome::PixButton(editlabel, GNOME_STOCK_PIXMAP_PROPERTIES));
373 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
376 bbox->set_spacing(4);
377 bbox->set_layout(GTK_BUTTONBOX_SPREAD);
379 bbox->children().push_back(Element(*b_add, false, false));
380 bbox->children().push_back(Element(*b_edit, false, false));
381 bbox->children().push_back(Element(*b_cancel, false, false));
386 Gtk::AccelGroup * accel = Gtk::AccelGroup::create();
388 b_add->add_accelerator("clicked", *accel, b_add->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
389 b_edit->add_accelerator("clicked", *accel, b_edit->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
391 // packing dialog to main window
393 mainAppWin->add_action(*dialog_, _(" Citation: Select action "), false, accel);
398 gtk_widget_grab_focus (GTK_WIDGET(b_add->gtkobj()));
400 // connecting signals
401 b_add->clicked.connect(slot(this, &FormCitation::moveFromActionToSearch));
402 b_edit->clicked.connect(slot(this, &FormCitation::moveFromActionToEdit));
404 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
406 dialog_->destroy.connect(slot(this, &FormCitation::free));
411 void FormCitation::moveFromActionToSearch()
413 // stores configuration and cleans all widgets
417 // moves to stage "search"
418 mainAppWin->remove_action();
423 void FormCitation::moveFromActionToEdit()
425 // stores configuration and cleans all widgets
429 // moves to stage "edit"
430 mainAppWin->remove_action();
435 void FormCitation::showStageSearch()
439 using namespace Gtk::Box_Helpers;
441 Gtk::Box * mbox = manage( new Gtk::HBox() );
442 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
443 Gtk::Separator * sep = manage( new Gtk::VSeparator() );
445 search_text_ = manage( new Gnome::Entry() );
447 button_regexp_ = manage( new Gtk::CheckButton(_("Use Regular Expression")) );
449 b_ok = manage( new Gtk::Button(_("Search")) );
450 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
453 mbox->set_spacing(4);
454 bbox->set_spacing(4);
457 bbox->children().push_back(Element(*b_ok, false, false));
458 bbox->children().push_back(Element(*b_cancel, false, false));
460 mbox->children().push_back(Element(*search_text_, true, true));
461 mbox->children().push_back(Element(*button_regexp_, false, false));
462 mbox->children().push_back(Element(*sep, false, false));
463 mbox->children().push_back(Element(*bbox, false, false));
465 // packing dialog to main window
467 mainAppWin->add_action(*dialog_, _(" Insert Citation: Enter keyword(s) or regular expression "));
472 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(search_text_->get_entry()->gtkobj()), GTK_CAN_DEFAULT);
473 gtk_widget_grab_focus (GTK_WIDGET(search_text_->get_entry()->gtkobj()));
474 gtk_widget_grab_default (GTK_WIDGET(search_text_->get_entry()->gtkobj()));
476 // connecting signals
477 b_ok->clicked.connect(SigC::slot(this, &FormCitation::moveFromSearchToSelect));
478 search_text_->get_entry()->activate.connect(SigC::slot(this, &FormCitation::moveFromSearchToSelect));
480 b_cancel->clicked.connect(SigC::slot(mainAppWin, &GLyxAppWin::remove_action));
481 dialog_->destroy.connect(SigC::slot(this, &FormCitation::free));
485 void FormCitation::moveFromSearchToSelect()
487 search_string_ = search_text_->get_entry()->get_text();
488 use_regexp_ = button_regexp_->get_active();
490 // stores configuration and cleans all widgets
494 // moves to stage "select"
495 mainAppWin->remove_action();
499 void FormCitation::showStageSelect()
503 using namespace Gtk::Box_Helpers;
505 Gtk::Box * mbox = manage( new Gtk::VBox() );
506 Gtk::Box * tbox = manage( new Gtk::HBox() );
507 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
508 Gtk::Separator * sep = manage( new Gtk::HSeparator() );
509 Gtk::ScrolledWindow * sw = manage( new Gtk::ScrolledWindow() );
511 info_ = manage( new Gnome::Less() );
512 paned_info_ = manage( new Gtk::HPaned() );
513 text_after_ = manage( new Gnome::Entry() );
515 b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
516 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
518 sw->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
520 // constructing CList
521 vector<string> colnames;
522 colnames.push_back("INVISIBLE");
523 colnames.push_back(_("Key"));
524 colnames.push_back(_("Author(s)"));
525 colnames.push_back(_("Title"));
526 colnames.push_back(_("Year"));
527 colnames.push_back(_("Journal"));
528 clist_bib_ = manage( new Gtk::CList(colnames) );
530 bbox->set_layout(GTK_BUTTONBOX_END);
533 mbox->set_spacing(4);
534 bbox->set_spacing(4);
535 tbox->set_spacing(4);
538 sw->add(*clist_bib_);
539 paned_info_->add1(*sw);
540 paned_info_->add2(*info_);
542 bbox->children().push_back(Element(*b_ok, false, false));
543 bbox->children().push_back(Element(*b_cancel, false, false));
545 tbox->children().push_back(Element(*manage(new Gtk::Label(_("Text after"))), false, false));
546 tbox->children().push_back(Element(*text_after_, true, true));
547 tbox->children().push_back(Element(*manage(new Gtk::VSeparator()), false, false));
548 tbox->children().push_back(Element(*bbox, false, false));
550 mbox->children().push_back(Element(*paned_info_,true,true));
551 mbox->children().push_back(Element(*sep, false, false));
552 mbox->children().push_back(Element(*tbox, false, false));
554 // packing dialog to main window
556 mainAppWin->add_action(*dialog_, _(" Insert Citation: Select citation "), true);
561 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_ok->gtkobj()), GTK_CAN_DEFAULT);
562 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_cancel->gtkobj()), GTK_CAN_DEFAULT);
563 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(clist_bib_->gtkobj()), GTK_CAN_DEFAULT);
564 gtk_widget_grab_focus (GTK_WIDGET(clist_bib_->gtkobj()));
565 gtk_widget_grab_default (GTK_WIDGET(b_ok->gtkobj()));
567 // connecting signals
568 b_ok->clicked.connect(SigC::slot(this, &FormCitation::applySelect));
569 text_after_->get_entry()->activate.connect(SigC::slot(this, &FormCitation::applySelect));
571 b_cancel->clicked.connect(SigC::slot(mainAppWin, &GLyxAppWin::remove_action));
573 dialog_->destroy.connect(SigC::slot(this, &FormCitation::free));
575 clist_bib_->click_column.connect(SigC::slot(this, &FormCitation::sortBibList));
576 clist_bib_->select_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
578 clist_bib_->unselect_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
583 void FormCitation::showStageEdit()
587 using namespace Gtk::Box_Helpers;
589 Gtk::Box * mbox = manage( new Gtk::VBox() );
590 Gtk::Box * tbox = manage( new Gtk::HBox() );
591 Gtk::Box * t2box = manage( new Gtk::HBox() );
592 Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
593 Gtk::ButtonBox * actbbox = manage( new Gtk::VButtonBox() );
594 Gtk::ScrolledWindow * sw = manage( new Gtk::ScrolledWindow() );
596 vector<string> colnames;
597 colnames.push_back(" ");
598 clist_selected_ = manage( new Gtk::CList(colnames) );
599 clist_selected_->column_titles_hide();
601 text_after_ = manage( new Gnome::Entry() );
603 button_unselect_ = manage( new Gnome::PixButton( _("_Remove"), GNOME_STOCK_PIXMAP_TRASH ) );
604 button_up_ = manage( new Gnome::PixButton( _("_Up"), GNOME_STOCK_PIXMAP_UP ) );
605 button_down_ = manage( new Gnome::PixButton( _("_Down"), GNOME_STOCK_PIXMAP_DOWN ) );
607 b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
608 b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
610 sw->set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
612 bbox->set_layout(GTK_BUTTONBOX_END);
613 actbbox->set_layout(GTK_BUTTONBOX_START);
616 mbox->set_spacing(4);
617 bbox->set_spacing(4);
618 actbbox->set_spacing(4);
619 tbox->set_spacing(4);
620 t2box->set_spacing(4);
623 sw->add(*clist_selected_);
625 bbox->children().push_back(Element(*b_ok, false, false));
626 bbox->children().push_back(Element(*b_cancel, false, false));
628 actbbox->children().push_back(Element(*button_unselect_, false, false));
629 actbbox->children().push_back(Element(*button_up_, false, false));
630 actbbox->children().push_back(Element(*button_down_, false, false));
632 t2box->children().push_back(Element(*sw, true, true));
633 t2box->children().push_back(Element(*actbbox, false, false));
635 tbox->children().push_back(Element(*manage(new Gtk::Label(_("Text after"))), false, false));
636 tbox->children().push_back(Element(*text_after_, true, true));
637 tbox->children().push_back(Element(*manage(new Gtk::VSeparator()), false, false));
638 tbox->children().push_back(Element(*bbox, false, false));
640 mbox->children().push_back(Element(*t2box,true,true));
641 mbox->children().push_back(Element(*manage(new Gtk::HSeparator()), false, false));
642 mbox->children().push_back(Element(*tbox, false, false));
645 Gtk::AccelGroup * accel = Gtk::AccelGroup::create();
647 button_unselect_->add_accelerator("clicked", *accel, button_unselect_->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
648 button_up_->add_accelerator("clicked", *accel, button_up_->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
649 button_down_->add_accelerator("clicked", *accel, button_down_->get_accelkey(), 0, GTK_ACCEL_VISIBLE);
651 // packing dialog to main window
653 mainAppWin->add_action(*dialog_, _(" Citation: Edit "), true, accel);
658 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_ok->gtkobj()), GTK_CAN_DEFAULT);
659 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(b_cancel->gtkobj()), GTK_CAN_DEFAULT);
660 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(clist_selected_->gtkobj()), GTK_CAN_DEFAULT);
661 gtk_widget_grab_focus (GTK_WIDGET(clist_selected_->gtkobj()));
662 gtk_widget_grab_default (GTK_WIDGET(b_ok->gtkobj()));
664 // connecting signals
665 b_ok->clicked.connect(SigC::slot(this, &FormCitation::applyEdit));
666 text_after_->get_entry()->activate.connect(SigC::slot(this, &FormCitation::applyEdit));
668 b_cancel->clicked.connect(SigC::slot(mainAppWin, &GLyxAppWin::remove_action));
670 dialog_->destroy.connect(SigC::slot(this, &FormCitation::free));
672 button_unselect_->clicked.connect(SigC::slot(this, &FormCitation::removeCitation));
673 button_up_->clicked.connect(SigC::slot(this, &FormCitation::moveCitationUp));
674 button_down_->clicked.connect(SigC::slot(this, &FormCitation::moveCitationDown));
676 clist_selected_->select_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
678 clist_selected_->unselect_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
684 void FormCitation::addItemToBibList(int i)
691 info = bibkeysInfo[i];
693 // don't change the order of these first two items:
694 // callback functions depend on the data stored in the first column (its hided)
695 // and in the second column (shown to user)
696 r.push_back( tostr(i) );
699 // this can be changed (configured by user?)
700 parseBibTeX( info, "author", val); r.push_back(val);
701 parseBibTeX( info, "title", val); r.push_back(val);
702 parseBibTeX( info, "year", val); r.push_back(val);
703 parseBibTeX( info, "journal", val); r.push_back(val);
705 clist_bib_->rows().push_back(r);
709 void FormCitation::updateButtons()
711 if (button_unselect_ != 0) // => button_up_ and button_down_ are != 0
715 sens = (clist_selected_->selection().size()>0);
716 button_unselect_->set_sensitive(sens);
717 button_up_->set_sensitive(sens &&
718 clist_selected_->selection()[0].get_row_num()>0);
719 button_down_->set_sensitive(sens &&
720 clist_selected_->selection()[0].get_row_num() <
721 clist_selected_->rows().size()-1);
726 void FormCitation::updateSlot(bool buffchanged)
728 if (buffchanged) hide();
732 void FormCitation::selectionToggled(gint row,
742 bool keyfound = false;
745 // the first column in clist_bib_ contains the index
747 info = bibkeysInfo[ strToInt(clist_bib_->cell(row,0).get_text()) ];
750 info_->show_string(info);
752 info_->show_string(_("--- No such key in the database ---"));
756 info_->show_string("");
763 void FormCitation::removeCitation()
765 clist_selected_->rows().remove(clist_selected_->selection()[0]);
769 void FormCitation::moveCitationUp()
771 int i = clist_selected_->selection()[0].get_row_num();
772 clist_selected_->swap_rows( i-1, i );
773 clist_selected_->row(i-1).select();
777 void FormCitation::moveCitationDown()
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::hide()
787 if (dialog_!=0) mainAppWin->remove_action();
790 void FormCitation::free()
803 void FormCitation::applySelect()
805 if( lv_->buffer()->isReadonly() ) return;
807 string contents = frontStrip( strip(params.getContents()) );
808 if (!contents.empty()) contents += ", ";
810 int sz = clist_bib_->selection().size();
811 for (int i=0; i < sz; ++i)
813 if (i > 0) contents += ", ";
814 contents += clist_bib_->selection()[i][1].get_text();
817 params.setContents( contents );
818 params.setOptions( text_after_->get_entry()->get_text() );
822 // Only update if contents have changed
823 if( params != inset_->params() )
825 inset_->setParams( params );
826 lv_->view()->updateInset( inset_, true );
831 lv_->getLyXFunc()->Dispatch( LFUN_CITATION_INSERT,
832 params.getAsString() );
840 void FormCitation::applyEdit()
842 if( lv_->buffer()->isReadonly() ) return;
845 int const sz = clist_selected_->rows().size();
846 for( int i = 0; i < sz; ++i )
848 if (i > 0) contents += ", ";
849 contents += clist_selected_->cell(i, 0).get_text();
852 params.setContents( contents );
853 params.setOptions( text_after_->get_entry()->get_text() );
857 // Only update if contents have changed
858 if( params != inset_->params() )
860 inset_->setParams( params );
861 lv_->view()->updateInset( inset_, true );
866 lv_->getLyXFunc()->Dispatch( LFUN_CITATION_INSERT,
867 params.getAsString() );
875 void FormCitation::sortBibList(gint col)
877 clist_bib_->set_sort_column(col);
881 void FormCitation::search()
883 if (use_regexp_) searchReg();
887 // looking for entries which match regexp
888 void FormCitation::searchReg()
890 string rexptxt(search_string_);
891 rexptxt = frontStrip( strip( rexptxt ) );
895 // populating clist_bib_
896 clist_bib_->rows().clear();
898 clist_bib_->freeze();
900 int const sz = bibkeys.size();
902 for ( int i = 0; i < sz; ++i )
904 string const data = bibkeys[i] + bibkeysInfo[i];
906 if (rexptxt.empty()) additem = true;
907 else additem = (reg.exec(data).size() > 0);
909 if ( additem ) addItemToBibList(i);
916 // looking for entries which contain all the words specified in search_text entry
917 void FormCitation::searchSimple()
919 vector<string> searchwords;
921 string stext(search_string_);
922 stext = frontStrip( strip( stext ) );
923 stext = frontStrip( split(stext, tmp, ' ') );
924 while ( !tmp.empty() )
926 searchwords.push_back(tmp);
927 stext = frontStrip( split(stext, tmp, ' ') );
930 // populating clist_bib_
931 clist_bib_->rows().clear();
933 clist_bib_->freeze();
935 int const sz = bibkeys.size();
936 for (int i = 0; i < sz; ++i) {
937 string const data = bibkeys[i] + bibkeysInfo[i];
941 int const szs = searchwords.size();
942 for (int j = 0; additem && j < szs; ++j)
943 if (data.find(searchwords[j]) == string::npos)
946 if (additem) addItemToBibList(i);