]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/gnome/FormCitation.C
Clean-up of the button controller.
[lyx.git] / src / frontends / gnome / FormCitation.C
index 82ab4be9df039c2a1285d738216d53eee0b6ae15..62f2d2682780b52b2ad5c4b47d0be3f65a0344b4 100644 (file)
@@ -1,4 +1,3 @@
-// -*- C++ -*-
 /* This file is part of
  * ====================================================== 
  *
@@ -49,26 +48,25 @@ using std::max;
 using std::min;
 using std::find;
 
-#ifdef SIGC_CXX_NAMESPACES
-using SigC::slot;
-using SigC::bind;
-#endif
-
+namespace {
 
 // configuration keys
-static string const  LOCAL_CONFIGURE_PREFIX("FormCitation");
+string const  LOCAL_CONFIGURE_PREFIX("FormCitation");
+
+string const  CONF_PANE_INFO("paneinfo");
+string const  CONF_PANE_INFO_DEFAULT("=300");
+
+string const  CONF_COLUMN("column");
+string const  CONF_COLUMN_DEFAULT("=50");
 
-static string const  CONF_PANE_INFO("paneinfo");
-static string const  CONF_PANE_INFO_DEFAULT("=300");
+string const  CONF_REGEXP("regexp");
+string const  CONF_REGEXP_DEFAULT("=0");
 
-static string const  CONF_COLUMN("column");
-static string const  CONF_COLUMN_DEFAULT("=50");
+string const CONF_SEARCH("FormCitation_search");
+string const CONF_TEXTAFTER("FormCitation_textafter");
 
-static string const  CONF_REGEXP("regexp");
-static string const  CONF_REGEXP_DEFAULT("=0");
+} // namespace anon
 
-static string const CONF_SEARCH("FormCitation_search");
-static string const CONF_TEXTAFTER("FormCitation_textafter");
 
 FormCitation::FormCitation(LyXView * lv, Dialogs * d)
   : lv_(lv), d_(d), inset_(0), u_(0), h_(0), ih_(0)
@@ -76,8 +74,8 @@ FormCitation::FormCitation(LyXView * lv, Dialogs * d)
   // let the dialog be shown
   // These are permanent connections so we won't bother
   // storing a copy because we won't be disconnecting.
-  d->showCitation.connect(slot(this, &FormCitation::showInset));
-  d->createCitation.connect(slot(this, &FormCitation::createInset));
+  d->showCitation.connect(SigC::slot(this, &FormCitation::showInset));
+  d->createCitation.connect(SigC::slot(this, &FormCitation::createInset));
 
   cleanupWidgets();
 }
@@ -89,16 +87,13 @@ FormCitation::~FormCitation()
 
 void FormCitation::showInset( InsetCommand * const inset )
 {
-  if( dialog_!=NULL || inset == 0 ) return;
+  if( dialog_!=0 || inset == 0 ) return;
   
   inset_ = inset;
-  ih_ = inset_->hide.connect(slot(this, &FormCitation::hide));
+  ih_ = inset_->hideDialog.connect(SigC::slot(this, &FormCitation::hide));
 
-#ifdef WITH_WARNINGS
-#warning This connection to update will do nothing!
-#endif
-  u_ = d_->updateBufferDependent.connect(slot(this, &FormCitation::update));
-  h_ = d_->hideBufferDependent.connect(slot(this, &FormCitation::hide));
+  u_ = d_->updateBufferDependent.connect(SigC::slot(this, &FormCitation::updateSlot));
+  h_ = d_->hideBufferDependent.connect(SigC::slot(this, &FormCitation::hide));
   
   params = inset->params();
 
@@ -109,23 +104,25 @@ void FormCitation::showInset( InsetCommand * const inset )
 
 void FormCitation::createInset( string const & arg )
 {
-  if( dialog_!=NULL ) return;
+  if( dialog_!=0 ) return;
   
-  u_ = d_->updateBufferDependent.connect(slot(this, &FormCitation::update));
-  h_ = d_->hideBufferDependent.connect(slot(this, &FormCitation::hide));
+  u_ = d_->updateBufferDependent.connect(SigC::slot(this, &FormCitation::updateSlot)); 
+  h_ = d_->hideBufferDependent.connect(SigC::slot(this, &FormCitation::hide));
   
   params.setFromString( arg );
   showStageSearch();
 }
 
 
-static
-void parseBibTeX(string data,
+namespace {
+
+void parseBibTeX(string const & dat,
                 string const & findkey,
                 string & keyvalue)
 {
   unsigned int i;
-
+  string data(dat);
+  
   keyvalue = "";
   
   for (i=0; i<data.length(); ++i)
@@ -140,7 +137,8 @@ void parseBibTeX(string data,
     {
       unsigned int keypos = min(data.find(' '), data.find('='));
       string key = lowercase( data.substr(0, keypos) );
-      string value, tmp;
+      string value;
+      string tmp;
       char enclosing;
       
       data = data.substr(keypos, data.length()-1);
@@ -210,22 +208,24 @@ void parseBibTeX(string data,
     }
 }
 
+} // namespace anon
+
 
 void FormCitation::cleanupWidgets()
 {
-  dialog_ = NULL;
-  b_ok = NULL;
-  b_cancel = NULL;
-  search_text_ = NULL;
-  info_ = NULL;
-  text_after_ = NULL;
-  button_unselect_ = NULL;
-  button_up_ = NULL;
-  button_down_ = NULL;
-  button_regexp_ = NULL;
-  clist_selected_ = NULL;
-  clist_bib_ = NULL;
-  paned_info_ = NULL;
+  dialog_ = 0;
+  b_ok = 0;
+  b_cancel = 0;
+  search_text_ = 0;
+  info_ = 0;
+  text_after_ = 0;
+  button_unselect_ = 0;
+  button_up_ = 0;
+  button_down_ = 0;
+  button_regexp_ = 0;
+  clist_selected_ = 0;
+  clist_bib_ = 0;
+  paned_info_ = 0;
 }
 
 
@@ -233,7 +233,7 @@ void FormCitation::initWidgets()
 {
   string const path = PACKAGE "/" + LOCAL_CONFIGURE_PREFIX;
 
-  if (search_text_ != NULL)
+  if (search_text_ != 0)
     {
       search_text_->set_history_id(CONF_SEARCH);
       search_text_->set_max_saved(10);
@@ -241,7 +241,7 @@ void FormCitation::initWidgets()
       search_text_->set_use_arrows_always(true);
     }
 
-  if (text_after_ != NULL )
+  if (text_after_ != 0 )
     {
       text_after_->set_history_id(CONF_TEXTAFTER);
       text_after_->set_max_saved(10);
@@ -250,19 +250,19 @@ void FormCitation::initWidgets()
       text_after_->get_entry()->set_text(params.getOptions());
     }
 
-  if (button_regexp_ != NULL)
+  if (button_regexp_ != 0)
     {
       string w = path + "/" + CONF_REGEXP + CONF_REGEXP_DEFAULT;
       button_regexp_->set_active( (gnome_config_get_int(w.c_str()) > 0) );
     }
 
-  if (paned_info_ != NULL)
+  if (paned_info_ != 0)
     {
       string w = path + "/" + CONF_PANE_INFO + CONF_PANE_INFO_DEFAULT;
       paned_info_->set_position( gnome_config_get_int(w.c_str()) );
     }
 
-  if (clist_bib_ != NULL)
+  if (clist_bib_ != 0)
     {
       // preferences
       clist_bib_->column(0).set_visiblity(false);
@@ -295,11 +295,11 @@ void FormCitation::initWidgets()
       if (clist_bib_->rows().size() > 0)
        {
          clist_bib_->rows()[0].select();
-         selectionToggled(0, 0, NULL, true, false);
+         selectionToggled(0, 0, 0, true, false);
        }
     }
 
-  if (clist_selected_ != NULL)
+  if (clist_selected_ != 0)
     {
       clist_selected_->set_selection_mode(GTK_SELECTION_BROWSE);
 
@@ -319,7 +319,7 @@ void FormCitation::initWidgets()
       if (clist_selected_->rows().size() > 0)
        {
          clist_selected_->rows()[0].select();
-         selectionToggled(0, 0, NULL, true, true);
+         selectionToggled(0, 0, 0, true, true);
        }
     }
 
@@ -331,23 +331,23 @@ void FormCitation::storeWidgets()
 {
   string const path = PACKAGE "/" + LOCAL_CONFIGURE_PREFIX;
 
-  if (search_text_ != NULL) search_text_->save_history();
+  if (search_text_ != 0) search_text_->save_history();
 
-  if (text_after_ != NULL) text_after_->save_history();
+  if (text_after_ != 0) text_after_->save_history();
 
-  if (button_regexp_ != NULL)
+  if (button_regexp_ != 0)
     {
       string w = path + "/" + CONF_REGEXP;
       gnome_config_set_int(w.c_str(), button_regexp_->get_active());
     }
 
-  if (paned_info_ != NULL
+  if (paned_info_ != 0
     {
       string w = path + "/" + CONF_PANE_INFO;
       gnome_config_set_int(w.c_str(), paned_info_->width() - info_->width());
     }
 
-  if (clist_bib_ != NULL)
+  if (clist_bib_ != 0)
     {
       string w;
       int const sz = clist_bib_->columns().size();
@@ -371,8 +371,8 @@ void FormCitation::showStageAction()
       Gtk::Alignment * mbox = manage( new Gtk::Alignment(0.5, 0.5, 0, 0) );
       Gtk::ButtonBox * bbox = manage( new Gtk::HButtonBox() );
 
-      string const addlabel = N_("_Add new citation");
-      string const editlabel = N_("_Edit/remove citation(s)");
+      string const addlabel = _("_Add new citation");
+      string const editlabel = _("_Edit/remove citation(s)");
 
       Gnome::PixButton * b_add  = manage(new Gnome::PixButton(addlabel, GNOME_STOCK_PIXMAP_NEW));
       Gnome::PixButton * b_edit = manage(new Gnome::PixButton(editlabel, GNOME_STOCK_PIXMAP_PROPERTIES));
@@ -397,7 +397,7 @@ void FormCitation::showStageAction()
       
       // packing dialog to main window
       dialog_ = mbox;
-      mainAppWin->add_action(*dialog_, N_(" Citation: Select action "), false, accel);
+      mainAppWin->add_action(*dialog_, _(" Citation: Select action "), false, accel);
 
       initWidgets();
       
@@ -451,9 +451,9 @@ void FormCitation::showStageSearch()
       
       search_text_ = manage( new Gnome::Entry() );
       
-      button_regexp_ = manage( new Gtk::CheckButton(N_("Use Regular Expression")) );
+      button_regexp_ = manage( new Gtk::CheckButton(_("Use Regular Expression")) );
 
-      b_ok = manage( new Gtk::Button(N_("Search")) );
+      b_ok = manage( new Gtk::Button(_("Search")) );
       b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
       
       // set up spacing
@@ -471,7 +471,7 @@ void FormCitation::showStageSearch()
 
       // packing dialog to main window
       dialog_ = mbox;
-      mainAppWin->add_action(*dialog_, N_(" Insert Citation: Enter keyword(s) or regular expression "));
+      mainAppWin->add_action(*dialog_, _(" Insert Citation: Enter keyword(s) or regular expression "));
 
       initWidgets();
       
@@ -481,11 +481,11 @@ void FormCitation::showStageSearch()
       gtk_widget_grab_default (GTK_WIDGET(search_text_->get_entry()->gtkobj()));
 
       // connecting signals
-      b_ok->clicked.connect(slot(this, &FormCitation::moveFromSearchToSelect));
-      search_text_->get_entry()->activate.connect(slot(this, &FormCitation::moveFromSearchToSelect));
+      b_ok->clicked.connect(SigC::slot(this, &FormCitation::moveFromSearchToSelect));
+      search_text_->get_entry()->activate.connect(SigC::slot(this, &FormCitation::moveFromSearchToSelect));
 
-      b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
-      dialog_->destroy.connect(slot(this, &FormCitation::free));
+      b_cancel->clicked.connect(SigC::slot(mainAppWin, &GLyxAppWin::remove_action));
+      dialog_->destroy.connect(SigC::slot(this, &FormCitation::free));
     }
 }
 
@@ -527,11 +527,11 @@ void FormCitation::showStageSelect()
       // constructing CList
       vector<string> colnames;
       colnames.push_back("INVISIBLE");
-      colnames.push_back(N_("Key"));
-      colnames.push_back(N_("Author(s)"));
-      colnames.push_back(N_("Title"));
-      colnames.push_back(N_("Year"));
-      colnames.push_back(N_("Journal"));
+      colnames.push_back(_("Key"));
+      colnames.push_back(_("Author(s)"));
+      colnames.push_back(_("Title"));
+      colnames.push_back(_("Year"));
+      colnames.push_back(_("Journal"));
       clist_bib_ = manage( new Gtk::CList(colnames) );
 
       bbox->set_layout(GTK_BUTTONBOX_END);
@@ -549,7 +549,7 @@ void FormCitation::showStageSelect()
       bbox->children().push_back(Element(*b_ok, false, false));
       bbox->children().push_back(Element(*b_cancel, false, false));
 
-      tbox->children().push_back(Element(*manage(new Gtk::Label(N_("Text after"))), false, false));
+      tbox->children().push_back(Element(*manage(new Gtk::Label(_("Text after"))), false, false));
       tbox->children().push_back(Element(*text_after_, true, true));
       tbox->children().push_back(Element(*manage(new Gtk::VSeparator()), false, false));
       tbox->children().push_back(Element(*bbox, false, false));
@@ -560,7 +560,7 @@ void FormCitation::showStageSelect()
       
       // packing dialog to main window
       dialog_ = mbox;
-      mainAppWin->add_action(*dialog_, N_(" Insert Citation: Select citation "), true);
+      mainAppWin->add_action(*dialog_, _(" Insert Citation: Select citation "), true);
 
       initWidgets();
       
@@ -572,17 +572,17 @@ void FormCitation::showStageSelect()
       gtk_widget_grab_default (GTK_WIDGET(b_ok->gtkobj()));
 
       // connecting signals
-      b_ok->clicked.connect(slot(this, &FormCitation::applySelect));
-      text_after_->get_entry()->activate.connect(slot(this, &FormCitation::applySelect));
+      b_ok->clicked.connect(SigC::slot(this, &FormCitation::applySelect));
+      text_after_->get_entry()->activate.connect(SigC::slot(this, &FormCitation::applySelect));
 
-      b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
+      b_cancel->clicked.connect(SigC::slot(mainAppWin, &GLyxAppWin::remove_action));
 
-      dialog_->destroy.connect(slot(this, &FormCitation::free));
+      dialog_->destroy.connect(SigC::slot(this, &FormCitation::free));
 
-      clist_bib_->click_column.connect(slot(this, &FormCitation::sortBibList));
-      clist_bib_->select_row.connect(bind(slot(this, &FormCitation::selectionToggled),
+      clist_bib_->click_column.connect(SigC::slot(this, &FormCitation::sortBibList));
+      clist_bib_->select_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
                                          true, false));
-      clist_bib_->unselect_row.connect(bind(slot(this, &FormCitation::selectionToggled),
+      clist_bib_->unselect_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
                                            false, false));
     }
 }
@@ -607,9 +607,9 @@ void FormCitation::showStageEdit()
       
       text_after_ = manage( new Gnome::Entry() );
       
-      button_unselect_ = manage( new Gnome::PixButton( N_("_Remove"), GNOME_STOCK_PIXMAP_TRASH ) );
-      button_up_ = manage( new Gnome::PixButton( N_("_Up"), GNOME_STOCK_PIXMAP_UP ) );
-      button_down_ = manage( new Gnome::PixButton( N_("_Down"), GNOME_STOCK_PIXMAP_DOWN ) );
+      button_unselect_ = manage( new Gnome::PixButton( _("_Remove"), GNOME_STOCK_PIXMAP_TRASH ) );
+      button_up_ = manage( new Gnome::PixButton( _("_Up"), GNOME_STOCK_PIXMAP_UP ) );
+      button_down_ = manage( new Gnome::PixButton( _("_Down"), GNOME_STOCK_PIXMAP_DOWN ) );
 
       b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) );
       b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) );
@@ -639,7 +639,7 @@ void FormCitation::showStageEdit()
       t2box->children().push_back(Element(*sw, true, true));
       t2box->children().push_back(Element(*actbbox, false, false));
 
-      tbox->children().push_back(Element(*manage(new Gtk::Label(N_("Text after"))), false, false));
+      tbox->children().push_back(Element(*manage(new Gtk::Label(_("Text after"))), false, false));
       tbox->children().push_back(Element(*text_after_, true, true));
       tbox->children().push_back(Element(*manage(new Gtk::VSeparator()), false, false));
       tbox->children().push_back(Element(*bbox, false, false));
@@ -657,7 +657,7 @@ void FormCitation::showStageEdit()
 
       // packing dialog to main window
       dialog_ = mbox;
-      mainAppWin->add_action(*dialog_, N_(" Citation: Edit "), true, accel);
+      mainAppWin->add_action(*dialog_, _(" Citation: Edit "), true, accel);
 
       initWidgets();
 
@@ -669,20 +669,20 @@ void FormCitation::showStageEdit()
       gtk_widget_grab_default (GTK_WIDGET(b_ok->gtkobj()));
 
       // connecting signals
-      b_ok->clicked.connect(slot(this, &FormCitation::applyEdit));
-      text_after_->get_entry()->activate.connect(slot(this, &FormCitation::applyEdit));
+      b_ok->clicked.connect(SigC::slot(this, &FormCitation::applyEdit));
+      text_after_->get_entry()->activate.connect(SigC::slot(this, &FormCitation::applyEdit));
 
-      b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action));
+      b_cancel->clicked.connect(SigC::slot(mainAppWin, &GLyxAppWin::remove_action));
 
-      dialog_->destroy.connect(slot(this, &FormCitation::free));
+      dialog_->destroy.connect(SigC::slot(this, &FormCitation::free));
 
-      button_unselect_->clicked.connect(slot(this, &FormCitation::removeCitation));
-      button_up_->clicked.connect(slot(this, &FormCitation::moveCitationUp));
-      button_down_->clicked.connect(slot(this, &FormCitation::moveCitationDown));      
+      button_unselect_->clicked.connect(SigC::slot(this, &FormCitation::removeCitation));
+      button_up_->clicked.connect(SigC::slot(this, &FormCitation::moveCitationUp));
+      button_down_->clicked.connect(SigC::slot(this, &FormCitation::moveCitationDown));      
 
-      clist_selected_->select_row.connect(bind(slot(this, &FormCitation::selectionToggled),
+      clist_selected_->select_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
                                          true, true));
-      clist_selected_->unselect_row.connect(bind(slot(this, &FormCitation::selectionToggled),
+      clist_selected_->unselect_row.connect(SigC::bind(SigC::slot(this, &FormCitation::selectionToggled),
                                            false, true));
     }
 }
@@ -715,7 +715,7 @@ void FormCitation::addItemToBibList(int i)
 
 void FormCitation::updateButtons()
 {
-  if (button_unselect_ != NULL) // => button_up_ and button_down_ are != NULL
+  if (button_unselect_ != 0) // => button_up_ and button_down_ are != 0
     {
       bool sens;
 
@@ -729,6 +729,13 @@ void FormCitation::updateButtons()
     }
 }
 
+
+void FormCitation::updateSlot(bool buffchanged)
+{
+  if (buffchanged) hide();
+}
+
+
 void FormCitation::selectionToggled(gint            row,
                                    gint            ,//column,
                                    GdkEvent        * ,//event,
@@ -749,7 +756,7 @@ void FormCitation::selectionToggled(gint            row,
          if (keyfound)
            info_->show_string(info);
          else
-           info_->show_string(N_("--- No such key in the database ---"));
+           info_->show_string(_("--- No such key in the database ---"));
        }
       else
        {
@@ -784,12 +791,12 @@ void FormCitation::moveCitationDown()
 
 void FormCitation::hide()
 {
-  if (dialog_!=NULL) mainAppWin->remove_action();
+  if (dialog_!=0) mainAppWin->remove_action();
 }
 
 void FormCitation::free()
 {
-  if (dialog_!=NULL)
+  if (dialog_!=0)
     {
       // cleaning up
       cleanupWidgets();
@@ -804,13 +811,10 @@ void FormCitation::applySelect()
 {
   if( lv_->buffer()->isReadonly() ) return;
 
-  string contents;
-  int sz;
-
-  contents = frontStrip( strip(params.getContents()) );
+  string contents = frontStrip( strip(params.getContents()) );
   if (!contents.empty()) contents += ", ";
   
-  sz = clist_bib_->selection().size();
+  int sz = clist_bib_->selection().size();
   for (int i=0; i < sz; ++i)
     {
       if (i > 0) contents += ", ";
@@ -890,7 +894,7 @@ void FormCitation::search()
 // looking for entries which match regexp
 void FormCitation::searchReg()
 {
-  string tmp, rexptxt( search_string_ );
+  string rexptxt(search_string_);
   rexptxt = frontStrip( strip( rexptxt ) );
   
   LRegex reg(rexptxt);
@@ -904,7 +908,7 @@ void FormCitation::searchReg()
   bool additem;
   for ( int i = 0; i < sz; ++i )
     {
-      string data = bibkeys[i] + bibkeysInfo[i];
+      string const data = bibkeys[i] + bibkeysInfo[i];
 
       if (rexptxt.empty()) additem = true;
       else additem = (reg.exec(data).size() > 0);
@@ -920,10 +924,11 @@ void FormCitation::searchReg()
 void FormCitation::searchSimple()
 {
   vector<string> searchwords;
-  string tmp, stext( search_string_ );
+  string tmp;
+  string stext(search_string_);
   stext = frontStrip( strip( stext ) );
   stext = frontStrip( split(stext, tmp, ' ') );
-  while( !tmp.empty() )
+  while ( !tmp.empty() )
     {
       searchwords.push_back(tmp);
       stext = frontStrip( split(stext, tmp, ' ') );
@@ -935,20 +940,17 @@ void FormCitation::searchSimple()
   clist_bib_->freeze();
 
   int const sz = bibkeys.size();
-  bool additem;
-  for ( int i = 0; i < sz; ++i )
-    {
-      string data = bibkeys[i] + bibkeysInfo[i];
+  for (int i = 0; i < sz; ++i) {
+      string const data = bibkeys[i] + bibkeysInfo[i];
 
-      additem = true;
+      bool additem = true;
 
-      int j, szs;
-      for (j = 0, szs = searchwords.size();
-          additem && j < szs; ++j )
-       if ( data.find(searchwords[j]) == string::npos )
-         additem = false;
-            
-      if ( additem ) addItemToBibList(i);
+      int const szs = searchwords.size();
+      for (int j = 0; additem && j < szs; ++j)
+             if (data.find(searchwords[j]) == string::npos)
+                     additem = false;
+      
+      if (additem) addItemToBibList(i);
     }
 
   clist_bib_->sort();