]> 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 b2cd38c6fcb6e74cff3018c29dbcf20792d24288..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");
 
-static string const  CONF_PANE_INFO("paneinfo");
-static string const  CONF_PANE_INFO_DEFAULT("=300");
+string const  CONF_COLUMN("column");
+string const  CONF_COLUMN_DEFAULT("=50");
 
-static string const  CONF_COLUMN("column");
-static string const  CONF_COLUMN_DEFAULT("=50");
+string const  CONF_REGEXP("regexp");
+string const  CONF_REGEXP_DEFAULT("=0");
 
-static string const  CONF_REGEXP("regexp");
-static string const  CONF_REGEXP_DEFAULT("=0");
+string const CONF_SEARCH("FormCitation_search");
+string const CONF_TEXTAFTER("FormCitation_textafter");
+
+} // 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,13 +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));
 
-  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();
 
@@ -106,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)
@@ -137,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);
@@ -207,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;
 }
 
 
@@ -230,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);
@@ -238,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);
@@ -247,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);
@@ -292,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);
 
@@ -316,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);
        }
     }
 
@@ -328,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();
@@ -478,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));
     }
 }
 
@@ -569,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));
     }
 }
@@ -666,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));
     }
 }
@@ -712,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;
 
@@ -727,7 +730,7 @@ void FormCitation::updateButtons()
 }
 
 
-void FormCitation::update(bool buffchanged)
+void FormCitation::updateSlot(bool buffchanged)
 {
   if (buffchanged) hide();
 }
@@ -788,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();
@@ -808,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 += ", ";
@@ -894,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);
@@ -908,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);
@@ -924,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, ' ') );
@@ -939,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();