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_!=NULL || inset == 0 ) return;
95 ih_ = inset_->hide.connect(slot(this, &FormCitation::hide));
98 #warning This connection to update will do nothing!
100 u_ = d_->updateBufferDependent.connect(slot(this, &FormCitation::update));
101 h_ = d_->hideBufferDependent.connect(slot(this, &FormCitation::hide));
103 params = inset->params();
105 if ( params.getContents().empty() ) showStageSearch();
106 else showStageAction();
110 void FormCitation::createInset( string const & arg )
112 if( dialog_!=NULL ) return;
114 u_ = d_->updateBufferDependent.connect(slot(this, &FormCitation::update));
115 h_ = d_->hideBufferDependent.connect(slot(this, &FormCitation::hide));
117 params.setFromString( arg );
123 void parseBibTeX(string data,
124 string const & findkey,
131 for (i=0; i<data.length(); ++i)
132 if (data[i]=='\n' || data[i]=='\t')
135 data = frontStrip(data);
138 && (data.find(' ')!=string::npos ||
139 data.find('=')!=string::npos) )
141 unsigned int keypos = min(data.find(' '), data.find('='));
142 string key = lowercase( data.substr(0, keypos) );
146 data = data.substr(keypos, data.length()-1);
147 data = frontStrip(strip(data));
148 if (data.length() > 1 && data[0]=='=')
150 data = frontStrip(data.substr(1, data.length()-1));
154 if (data[0]=='{') enclosing = '}';
155 else if (data[0]=='"') enclosing = '"';
156 else { keypos=0; enclosing=' '; }
159 data.find(enclosing)!=string::npos &&
162 tmp = data.substr(keypos, data.length()-1);
163 while (tmp.find('{')!=string::npos &&
164 tmp.find('}')!=string::npos &&
165 tmp.find('{') < tmp.find('}') &&
166 tmp.find('{') < tmp.find(enclosing))
168 keypos += tmp.find('{')+1;
169 tmp = data.substr(keypos, data.length()-1);
170 keypos += tmp.find('}')+1;
171 tmp = data.substr(keypos, data.length()-1);
174 if (tmp.find(enclosing)==string::npos) return;
177 keypos += tmp.find(enclosing);
178 tmp = data.substr(keypos, data.length()-1);
181 value = data.substr(1, keypos-1);
183 if (keypos+1<data.length()-1) data = frontStrip(data.substr(keypos+1, data.length()-1));
189 ) // numerical value ?
191 keypos = data.length()-1;
192 if (data.find(' ')!=string::npos) keypos = data.find(' ');
193 if (data.find(',')!=string::npos &&
194 keypos > data.find(','))
195 keypos = data.find(',');
197 value = data.substr(0, keypos);
199 if (keypos+1<data.length()-1) data = frontStrip(data.substr(keypos+1, data.length()-1));
204 if (findkey == key) { keyvalue = value; return; }
206 data = frontStrip(frontStrip(data,','));
214 void FormCitation::cleanupWidgets()
222 button_unselect_ = NULL;
225 button_regexp_ = NULL;
226 clist_selected_ = NULL;
232 void FormCitation::initWidgets()
234 string const path = PACKAGE "/" + LOCAL_CONFIGURE_PREFIX;
236 if (search_text_ != NULL)
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_ != NULL )
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_ != NULL)
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_ != NULL)
261 string w = path + "/" + CONF_PANE_INFO + CONF_PANE_INFO_DEFAULT;
262 paned_info_->set_position( gnome_config_get_int(w.c_str()) );
265 if (clist_bib_ != NULL)
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, NULL, true, false);
302 if (clist_selected_ != NULL)
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, NULL, true, true);
330 void FormCitation::storeWidgets()
332 string const path = PACKAGE "/" + LOCAL_CONFIGURE_PREFIX;
334 if (search_text_ != NULL) search_text_->save_history();
336 if (text_after_ != NULL) text_after_->save_history();
338 if (button_regexp_ != NULL)
340 string w = path + "/" + CONF_REGEXP;
341 gnome_config_set_int(w.c_str(), button_regexp_->get_active());
344 if (paned_info_ != NULL)
346 string w = path + "/" + CONF_PANE_INFO;
347 gnome_config_set_int(w.c_str(), paned_info_->width() - info_->width());
350 if (clist_bib_ != NULL)
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 = N_("_Add new citation");
375 string const editlabel = N_("_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_, N_(" 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(N_("Use Regular Expression")) );
456 b_ok = manage( new Gtk::Button(N_("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_, N_(" 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(slot(this, &FormCitation::moveFromSearchToSelect));
485 search_text_->get_entry()->activate.connect(slot(this, &FormCitation::moveFromSearchToSelect));
487 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
488 dialog_->destroy.connect(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(N_("Key"));
531 colnames.push_back(N_("Author(s)"));
532 colnames.push_back(N_("Title"));
533 colnames.push_back(N_("Year"));
534 colnames.push_back(N_("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(N_("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_, N_(" 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(slot(this, &FormCitation::applySelect));
576 text_after_->get_entry()->activate.connect(slot(this, &FormCitation::applySelect));
578 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
580 dialog_->destroy.connect(slot(this, &FormCitation::free));
582 clist_bib_->click_column.connect(slot(this, &FormCitation::sortBibList));
583 clist_bib_->select_row.connect(bind(slot(this, &FormCitation::selectionToggled),
585 clist_bib_->unselect_row.connect(bind(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( N_("_Remove"), GNOME_STOCK_PIXMAP_TRASH ) );
611 button_up_ = manage( new Gnome::PixButton( N_("_Up"), GNOME_STOCK_PIXMAP_UP ) );
612 button_down_ = manage( new Gnome::PixButton( N_("_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(N_("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_, N_(" 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(slot(this, &FormCitation::applyEdit));
673 text_after_->get_entry()->activate.connect(slot(this, &FormCitation::applyEdit));
675 b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
677 dialog_->destroy.connect(slot(this, &FormCitation::free));
679 button_unselect_->clicked.connect(slot(this, &FormCitation::removeCitation));
680 button_up_->clicked.connect(slot(this, &FormCitation::moveCitationUp));
681 button_down_->clicked.connect(slot(this, &FormCitation::moveCitationDown));
683 clist_selected_->select_row.connect(bind(slot(this, &FormCitation::selectionToggled),
685 clist_selected_->unselect_row.connect(bind(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_ != NULL) // => button_up_ and button_down_ are != NULL
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);
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(N_("--- 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_!=NULL) mainAppWin->remove_action();
790 void FormCitation::free()
803 void FormCitation::applySelect()
805 if( lv_->buffer()->isReadonly() ) return;
810 contents = frontStrip( strip(params.getContents()) );
811 if (!contents.empty()) contents += ", ";
813 sz = clist_bib_->selection().size();
814 for (int i=0; i < sz; ++i)
816 if (i > 0) contents += ", ";
817 contents += clist_bib_->selection()[i][1].get_text();
820 params.setContents( contents );
821 params.setOptions( text_after_->get_entry()->get_text() );
825 // Only update if contents have changed
826 if( params != inset_->params() )
828 inset_->setParams( params );
829 lv_->view()->updateInset( inset_, true );
834 lv_->getLyXFunc()->Dispatch( LFUN_CITATION_INSERT,
835 params.getAsString() );
843 void FormCitation::applyEdit()
845 if( lv_->buffer()->isReadonly() ) return;
848 int const sz = clist_selected_->rows().size();
849 for( int i = 0; i < sz; ++i )
851 if (i > 0) contents += ", ";
852 contents += clist_selected_->cell(i, 0).get_text();
855 params.setContents( contents );
856 params.setOptions( text_after_->get_entry()->get_text() );
860 // Only update if contents have changed
861 if( params != inset_->params() )
863 inset_->setParams( params );
864 lv_->view()->updateInset( inset_, true );
869 lv_->getLyXFunc()->Dispatch( LFUN_CITATION_INSERT,
870 params.getAsString() );
878 void FormCitation::sortBibList(gint col)
880 clist_bib_->set_sort_column(col);
884 void FormCitation::search()
886 if (use_regexp_) searchReg();
890 // looking for entries which match regexp
891 void FormCitation::searchReg()
893 string tmp, rexptxt( search_string_ );
894 rexptxt = frontStrip( strip( rexptxt ) );
898 // populating clist_bib_
899 clist_bib_->rows().clear();
901 clist_bib_->freeze();
903 int const sz = bibkeys.size();
905 for ( int i = 0; i < sz; ++i )
907 string data = bibkeys[i] + bibkeysInfo[i];
909 if (rexptxt.empty()) additem = true;
910 else additem = (reg.exec(data).size() > 0);
912 if ( additem ) addItemToBibList(i);
919 // looking for entries which contain all the words specified in search_text entry
920 void FormCitation::searchSimple()
922 vector<string> searchwords;
923 string tmp, stext( search_string_ );
924 stext = frontStrip( strip( stext ) );
925 stext = frontStrip( split(stext, tmp, ' ') );
926 while( !tmp.empty() )
928 searchwords.push_back(tmp);
929 stext = frontStrip( split(stext, tmp, ' ') );
932 // populating clist_bib_
933 clist_bib_->rows().clear();
935 clist_bib_->freeze();
937 int const sz = bibkeys.size();
939 for ( int i = 0; i < sz; ++i )
941 string data = bibkeys[i] + bibkeysInfo[i];
946 for (j = 0, szs = searchwords.size();
947 additem && j < szs; ++j )
948 if ( data.find(searchwords[j]) == string::npos )
951 if ( additem ) addItemToBibList(i);