]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/gnome/Menubar_pimpl.C
Clean-up of the button controller.
[lyx.git] / src / frontends / gnome / Menubar_pimpl.C
index 624d12af4869bc50b80c50e3e23dd12b2381f611..e5eb7d8c8ce3e52d5f7be174e4f3a414f4211c8a 100644 (file)
@@ -1,4 +1,3 @@
-// -*- C++ -*-
 /* This file is part of
  * ====================================================== 
  * 
 
 #include <gtk--/menu.h>
 
-using SigC::slot;
-using SigC::bind;
-
 using std::endl;
 
 // temporary solution for LyXView
 extern GLyxAppWin * mainAppWin;
 
 // Some constants
-extern kb_keymap * toplevel_keymap;
+extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 extern LyXAction lyxaction;
 extern BufferList bufferlist;
 extern LastFiles * lastfiles; 
@@ -66,7 +62,7 @@ Menubar::Pimpl::~Pimpl()
 void Menubar::Pimpl::set(string const & menu_name) 
 {
   // if (current_menu_name_ != menu_name)  // disabled until Lastfiles and Documents are added dynamically to menu
-    {
+       //{
       current_menu_name_ = menu_name;
 
       // clean up the lists
@@ -90,20 +86,26 @@ void Menubar::Pimpl::set(string const & menu_name)
       // update state of the items
       update();
       updateAllLists();
-    }
+      //}
 }
 
 void Menubar::Pimpl::updateAllLists()
 {
+#ifdef WITH_WARNINGS
+#warning Implement me! (be 20010324)
+#endif
+#if 0
   // update lists
   if (toc_.size() > 0)
     {
       vector<Buffer::TocItem> toclist = (owner_->view()->buffer()->getTocList())[Buffer::TOC_TOC];
       updateList(&toclist, &toc_);
     }
+#endif
 }
 
 int const max_number_of_items = 25;
+
 void Menubar::Pimpl::updateList(vector<Buffer::TocItem> * toclist, vector<ListsHolder> * pgui) 
 {
   vector<ListsHolder> & gui = *pgui;
@@ -116,7 +118,7 @@ void Menubar::Pimpl::updateList(vector<Buffer::TocItem> * toclist, vector<ListsH
       string label;
 
       menu.push_back(Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_MENU_REFRESH),
-                                    N_("Refresh"), slot(this, &Menubar::Pimpl::updateAllLists)));
+                                    _("Refresh"), SigC::slot(this, &Menubar::Pimpl::updateAllLists)));
 
       if (toclist->size() > max_number_of_items)
        composeTocUIInfo(menu, *toclist, toclist->begin(), 0);
@@ -130,7 +132,7 @@ void Menubar::Pimpl::updateList(vector<Buffer::TocItem> * toclist, vector<ListsH
              label = string(4*(*it).depth,' ')+(*it).str;
              
              menu.push_back(Gnome::UI::Item(label,
-                                            bind<Buffer::TocItem>(slot(this, &Menubar::Pimpl::callbackToc), (*it)),
+                                            SigC::bind<Buffer::TocItem>(SigC::slot(this, &Menubar::Pimpl::callbackToc), (*it)),
                                             label));
            }
        }
@@ -146,7 +148,7 @@ Menubar::Pimpl::composeTocUIInfo(vector<Gnome::UI::Info> & menu,
                                 vector<Buffer::TocItem>::const_iterator begin,
                                 int mylevel)
 {
-  string label = N_("<No Name>");
+  string label = _("<No Name>");
 
   vector<Buffer::TocItem>::const_iterator end = toclist.end();
   vector<Buffer::TocItem>::const_iterator it;
@@ -157,7 +159,7 @@ Menubar::Pimpl::composeTocUIInfo(vector<Gnome::UI::Info> & menu,
        {
          label = (*it).str;
          menu.push_back(Gnome::UI::Item(label,
-                                      bind<Buffer::TocItem>(slot(this, &Menubar::Pimpl::callbackToc), (*it)),
+                                      SigC::bind<Buffer::TocItem>(SigC::slot(this, &Menubar::Pimpl::callbackToc), (*it)),
                                         label));
        }
       else
@@ -167,7 +169,7 @@ Menubar::Pimpl::composeTocUIInfo(vector<Gnome::UI::Info> & menu,
            {
              label = (*it).str;
              submenu.push_back(Gnome::UI::Item(label,
-                                               bind<Buffer::TocItem>(slot(this, &Menubar::Pimpl::callbackToc), (*it)),
+                                               SigC::bind<Buffer::TocItem>(SigC::slot(this, &Menubar::Pimpl::callbackToc), (*it)),
                                                label));
              ++it;    
            }
@@ -191,12 +193,16 @@ void Menubar::Pimpl::callback(int action)
 
 void Menubar::Pimpl::callbackToc(Buffer::TocItem tg)
 {
+#if 0 
   if (!owner_->view()->available()) return;
   
   owner_->view()->beforeChange();
   owner_->view()->text->SetCursor( owner_->view(), tg.par, 0 );
   owner_->view()->text->sel_cursor = owner_->view()->text->cursor;
   owner_->view()->update(BufferView::SELECT|BufferView::FITCUR);
+#endif
+
+  owner_->getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tg.str);
 }
 
 void Menubar::Pimpl::composeUIInfo(string const & menu_name, vector<Gnome::UI::Info> & Menus, string rootpath)
@@ -210,7 +216,8 @@ void Menubar::Pimpl::composeUIInfo(string const & menu_name, vector<Gnome::UI::I
       return;
     }
 
-  Menu menu = menubackend_->getMenu(menu_name);
+  Menu menu = Menu();
+  menubackend_->getMenu(menu_name).expand(menu, owner_->buffer());
 
   for (Menu::const_iterator i = menu.begin(); i != menu.end(); ++i)
     {
@@ -228,7 +235,7 @@ void Menubar::Pimpl::composeUIInfo(string const & menu_name, vector<Gnome::UI::I
        LyXFunc::func_status flag = owner_->getLyXFunc()->getStatus(item.action());
 
        Gnome::UI::Info gitem;
-       SigC::Slot0<void> cback = bind<int>(slot(this, &Menubar::Pimpl::callback),item.action());
+       SigC::Slot0<void> cback = SigC::bind<int>(SigC::slot(this, &Menubar::Pimpl::callback),item.action());
 
        {
          using namespace Gnome::MenuItems;
@@ -241,7 +248,7 @@ void Menubar::Pimpl::composeUIInfo(string const & menu_name, vector<Gnome::UI::I
            action = static_cast<kb_action>(ac);
 
          switch(action) {
-         case LFUN_MENUOPEN:
+         case LFUN_FILE_OPEN:
            gitem = Open(cback);
            break;
          case LFUN_QUIT:
@@ -253,7 +260,7 @@ void Menubar::Pimpl::composeUIInfo(string const & menu_name, vector<Gnome::UI::I
          case LFUN_MENUWRITE:
            gitem = Save(cback);
            break;
-         case LFUN_MENUWRITEAS:
+         case LFUN_WRITEAS:
            gitem = SaveAs(cback);
            break;
          case LFUN_BUFFER_PRINT:
@@ -333,43 +340,6 @@ void Menubar::Pimpl::composeUIInfo(string const & menu_name, vector<Gnome::UI::I
        break;
       }
 
-      case MenuItem::Lastfiles: {
-       int ii = 1;
-       for (LastFiles::const_iterator cit = lastfiles->begin();
-            cit != lastfiles->end() && ii < 10; ++cit, ++ii)
-         {
-           int action = lyxaction.getPseudoAction(LFUN_FILE_OPEN, (*cit));
-           string label = tostr(ii) + ". " + MakeDisplayPath((*cit),30);
-
-           path = rootpath + label;
-           label = "_" + label;
-           
-           Menus.push_back(Gnome::UI::Item(label,
-                                           bind<int>(slot(this, &Menubar::Pimpl::callback), action),
-                                           label));
-         }
-       break;
-      }
-      
-      case MenuItem::Documents: {
-       std::vector<string> names = bufferlist.getFileNames();
-
-       for (std::vector<string>::const_iterator cit = names.begin();
-            cit != names.end() ; ++cit)
-         {
-           int action = lyxaction.getPseudoAction(LFUN_SWITCHBUFFER, *cit);
-           string label = MakeDisplayPath(*cit, 30);
-
-           path = rootpath + label;
-           
-           Menus.push_back(Gnome::UI::Item(label,
-                                           bind<int>(slot(this, &Menubar::Pimpl::callback), action),
-                                           label));
-           
-         }
-       break;
-      }
-
       case MenuItem::Toc: {
        ListsHolder t;
        t.path = path;
@@ -377,51 +347,27 @@ void Menubar::Pimpl::composeUIInfo(string const & menu_name, vector<Gnome::UI::I
        break;
       }
       
-      case MenuItem::ViewFormats: {
-       add_formats(Menus, LFUN_PREVIEW, true);
-       break;
-      }
-       
-      case MenuItem::UpdateFormats: {
-       add_formats(Menus, LFUN_UPDATE, true);
-       break;  
-      }
-       
-      case MenuItem::ExportFormats: {
-       add_formats(Menus, LFUN_EXPORT, false);
-       break;
-      }
+      case MenuItem::Documents: 
+      case MenuItem::Lastfiles: 
+      case MenuItem::ViewFormats:
+      case MenuItem::UpdateFormats:
+      case MenuItem::ExportFormats:
+                       lyxerr << "Menubar::Pimpl::create_submenu: "
+                         "this should not happen" << endl;
+                       break;
       }
     }
 }
 
-void Menubar::Pimpl::add_formats(vector<Gnome::UI::Info> & Menus, kb_action action, bool viewable)
-{
-  vector<pair<string,string> > names = 
-    viewable
-    ? Exporter::GetViewableFormats(owner_->buffer())
-    : Exporter::GetExportableFormats(owner_->buffer());
-  
-  for (vector<pair<string,string> >::const_iterator cit = names.begin();
-       cit != names.end() ; ++cit) {
-    int action2 = lyxaction.getPseudoAction(action, (*cit).first);
-    string label = (*cit).second;
-
-    Menus.push_back(Gnome::UI::Item(label,
-                                   bind<int>(slot(this, &Menubar::Pimpl::callback), action2),
-                                   label));
-  }
-}
-
 void Menubar::Pimpl::connectWidgetToAction(GnomeUIInfo * guinfo)
 {
   for (; guinfo->type !=  GnomeUIInfoType(GNOME_APP_UI_ENDOFINFO); ++guinfo)
     {
       if ( ( guinfo->type == GnomeUIInfoType(GNOME_APP_UI_ITEM) ||
             guinfo->type == GnomeUIInfoType(GNOME_APP_UI_TOGGLEITEM) ) &&
-          guinfo->moreinfo != NULL )
+          guinfo->moreinfo != 0 )
        {
-         (*((void(*)(void *, void *))(guinfo->moreinfo)))(NULL, guinfo->user_data);
+         (*((void(*)(void *, void *))(guinfo->moreinfo)))(0, guinfo->user_data);
          wid_act_.push_back( GtkWidgetToAction( guinfo->widget, action_ ) );
        }
       else if ( guinfo->type == GnomeUIInfoType(GNOME_APP_UI_SUBTREE) ||