]> git.lyx.org Git - lyx.git/blobdiff - src/menus.C
Baruch's graphic-inset patch.
[lyx.git] / src / menus.C
index a42aae24819287ae466f0743cd2fc9009129ee1e..2816cd216a4b78d323092b96c58e36e5be399fc6 100644 (file)
@@ -26,6 +26,8 @@
 #pragma implementation
 #endif
 
+#include <algorithm>
+
 #include "menus.h"
 #include "version.h"
 #include "lyxfont.h"
 #include "lyxtext.h"
 #include "gettext.h"
 #include "layout.h"
+#include "lyx_cb.h"
+#include "bufferview_funcs.h"
+#include "insets/insetref.h"
+#include "insets/insettabular.h"
+#include "tabular.h"
+
+#include "frontends/Dialogs.h"
 
 using std::vector;
 using std::endl;
+using std::max;
+using std::min;
+using std::sort;
 
 extern FD_form_screen * fd_form_screen;
 extern BufferList bufferlist;
@@ -56,11 +68,6 @@ extern BufferList bufferlist;
 
 extern void MenuLayoutSave();
 extern void ShowCredits();
-extern void ShowCopyright();
-extern void show_symbols_form(LyXFunc *);
-extern void ProhibitInput();
-extern void AllowInput();
-extern void LaTeXOptions(BufferView *);
 
 // A bunch of wrappers
 
@@ -79,6 +86,16 @@ extern "C" void C_Menus_ShowEditMenu(FL_OBJECT * ob, long data)
        Menus::ShowEditMenu(ob, data);
 }
 
+extern "C" void C_Menus_ShowTocMenu(FL_OBJECT * ob, long data)
+{
+       Menus::ShowTocMenu(ob, data);
+}
+
+extern "C" void C_Menus_ShowRefsMenu(FL_OBJECT * ob, long data)
+{
+       Menus::ShowRefsMenu(ob, data);
+}
+
 extern "C" void C_Menus_ShowLayoutMenu(FL_OBJECT * ob, long data)
 {
        Menus::ShowLayoutMenu(ob, data);
@@ -118,6 +135,8 @@ Menus::Menus(LyXView * view, int air)
        fl_set_object_shortcut(menu_file, "", 1);
        fl_set_object_shortcut(menu_file2, "", 1);
        fl_set_object_shortcut(menu_edit, "", 1);
+       fl_set_object_shortcut(menu_toc, "", 1);
+       fl_set_object_shortcut(menu_refs, "", 1);
        fl_set_object_shortcut(menu_layout, "", 1);
        fl_set_object_shortcut(menu_math, "", 1);
        fl_set_object_shortcut(menu_insert, "", 1);
@@ -164,6 +183,10 @@ void Menus::openByName(string const & menuName)
                        ShowFileMenu(menu_file, 0);
                else if (menuName == _("Edit"))
                        ShowEditMenu(menu_edit, 0);
+               else if (menuName == _("TOC"))
+                       ShowTocMenu(menu_toc, 0);
+               else if (menuName == _("Refs"))
+                       ShowRefsMenu(menu_refs, 0);
                else if (menuName == _("Layout"))
                        ShowLayoutMenu(menu_layout, 0);
                else if (menuName == _("Insert"))
@@ -242,6 +265,34 @@ void Menus::create_menus(int air)
        fl_set_object_callback(obj, C_Menus_ShowEditMenu, 0);
        obj->u_vdata = this;
        
+       /// TOC menu button
+       menu_toc = obj = 
+               fl_add_button(FL_TOUCH_BUTTON,
+                             moffset, yloc,
+                             fl_get_string_width(FL_BOLD_STYLE,
+                                                 MENU_LABEL_SIZE,
+                                                 _("TOC"),
+                                                 strlen(_("TOC"))) + mbadd,
+                             mbheight, _("TOC"));
+       moffset += obj->w + air;
+       fl_set_object_shortcut(obj, scex(_("MB|#T")), 1);
+       fl_set_object_callback(obj, C_Menus_ShowTocMenu, 0);
+       obj->u_vdata = this;
+
+       /// Refs menu button
+       menu_refs = obj = 
+               fl_add_button(FL_TOUCH_BUTTON,
+                             moffset, yloc,
+                             fl_get_string_width(FL_BOLD_STYLE,
+                                                 MENU_LABEL_SIZE,
+                                                 _("Refs"),
+                                                 strlen(_("Refs"))) + mbadd,
+                             mbheight, _("Refs"));
+       moffset += obj->w + air;
+       fl_set_object_shortcut(obj, scex(_("MB|#R")), 1);
+       fl_set_object_callback(obj, C_Menus_ShowRefsMenu, 0);
+       obj->u_vdata = this;
+
        // Layout menu button
        menu_layout = obj = 
                fl_add_button(FL_TOUCH_BUTTON,
@@ -611,10 +662,10 @@ void Menus::ShowFileMenu(FL_OBJECT * ob, long)
 
        // make the lastfiles menu
        int ii = 1;
-       for (LastFiles::Files::const_iterator cit = lastfiles->begin();
+       for (LastFiles::const_iterator cit = lastfiles->begin();
             cit != lastfiles->end() && ii < 10; ++cit, ++ii) {
                string tmp = tostr(ii);
-               string tmp2 = tmp + "#" + tmp;;
+               string tmp2 = tmp + "#" + tmp;
                tmp += ". " + MakeDisplayPath((*cit), 30);
                fl_addtopup(FileMenu, tmp.c_str());
                fl_setpup_shortcut(FileMenu, 18 - 1 + ii, tmp2.c_str());
@@ -674,13 +725,7 @@ void Menus::ShowFileMenu(FL_OBJECT * ob, long)
                break;
        case 43: tmpfunc->Dispatch(LFUN_EXPORT, "ascii");
                break;
-       case 44:
-               if (!LinuxDoc && !DocBook)
-                       tmpfunc->Dispatch(LFUN_EXPORT, "html");
-               else if(LinuxDoc)
-                       tmpfunc->Dispatch(LFUN_EXPORT, "html-linuxdoc");
-               else
-                       tmpfunc->Dispatch(LFUN_EXPORT, "html-docbook");
+       case 44: tmpfunc->Dispatch(LFUN_EXPORT, "html");
                break;
        case 45: tmpfunc->Dispatch(LFUN_EXPORT, "custom"); 
                break;
@@ -697,7 +742,7 @@ void Menus::ShowFileMenu(FL_OBJECT * ob, long)
        fl_freepup(SubFileExport);
        fl_freepup(FileMenu);
 
-       AllowInput();
+       AllowInput(men->currentView());
 }
 
 
@@ -762,10 +807,10 @@ void Menus::ShowFileMenu2(FL_OBJECT * ob, long)
        
        // make the lastfiles menu
        int ii = 1;
-       for (LastFiles::Files::const_iterator cit = lastfiles->begin();
+       for (LastFiles::const_iterator cit = lastfiles->begin();
             cit != lastfiles->end() && ii < 10; ++cit, ++ii) {
                string tmp = tostr(ii);
-               string tmp2 = tmp + "#" + tmp;;
+               string tmp2 = tmp + "#" + tmp;
                tmp += ". " + MakeDisplayPath((*cit), 30);
                fl_addtopup(FileMenu, tmp.c_str());
                fl_setpup_shortcut(FileMenu, 18 - 1 + ii, tmp2.c_str());
@@ -819,7 +864,7 @@ void Menus::ShowFileMenu2(FL_OBJECT * ob, long)
 
        fl_freepup(SubFileImport);
        fl_freepup(FileMenu);
-       AllowInput();
+       AllowInput(men->currentView());
        return;
 }
 
@@ -857,73 +902,70 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
 
        // Table submenu
        int SubEditTable = fl_newpup(FL_ObjWin(ob));
+#ifndef NEW_TABULAR
        if (men->currentView()->available() && 
-           men->currentView()->text->cursor.par->table &&
+           men->currentView()->text->cursor.par()->table &&
            !tmpbuffer->isReadonly()){
+               LyXTable * table = men->currentView()->text->cursor.par()->table;
 
                fl_addtopup(SubEditTable, _("Table%t"));
 
-               if (men->currentView()->text->cursor.par->table->
-                   IsMultiColumn(men->currentView()->text->
-                                 NumberOfCell(men->currentView()->
-                                              text->cursor.par, 
-                                              men->currentView()->
-                                              text->cursor.pos)))
+               if (table->IsMultiColumn(men->currentView()->text->
+                                        NumberOfCell(men->currentView()->
+                                                     text->cursor.par(), 
+                                                     men->currentView()->
+                                                     text->cursor.pos())))
                        fl_addtopup(SubEditTable, _("|Multicolumn%B%x44%l"));
                else
                        fl_addtopup(SubEditTable, _("|Multicolumn%b%x44%l"));
                fl_setpup_shortcut(SubEditTable, 44, scex(_("EMT|Mm#m#M")));
      
-               if (men->currentView()->text->cursor.par->table->
-                   TopLine(men->currentView()->text->
-                           NumberOfCell(men->currentView()->
-                                        text->cursor.par, 
-                                        men->currentView()->text->
-                                        cursor.pos)))
+               if (table->TopLine(men->currentView()->text->
+                                  NumberOfCell(men->currentView()->
+                                               text->cursor.par(), 
+                                               men->currentView()->text->
+                                               cursor.pos())))
                        fl_addtopup(SubEditTable, _("|Line Top%B%x36"));
                else
                        fl_addtopup(SubEditTable, _("|Line Top%b%x36"));
                fl_setpup_shortcut(SubEditTable, 36, scex(_("EMT|Tt#t#T")));
      
-               if (men->currentView()->text->cursor.par->table->
-                   BottomLine(men->currentView()->text->
-                              NumberOfCell(men->currentView()->
-                                           text->cursor.par, 
-                                           men->currentView()->
-                                           text->cursor.pos)))
+               if (table->BottomLine(men->currentView()->text->
+                                     NumberOfCell(men->currentView()->
+                                                  text->cursor.par(), 
+                                                  men->currentView()->
+                                                  text->cursor.pos())))
                        fl_addtopup(SubEditTable, _("|Line Bottom%B%x37"));
                else
                        fl_addtopup(SubEditTable, _("|Line Bottom%b%x37"));
                fl_setpup_shortcut(SubEditTable, 37, scex(_("EMT|Bb#b#B")));
 
-               if (men->currentView()->text->cursor.par->table->
-                   LeftLine(men->currentView()->text->
-                            NumberOfCell(men->currentView()->
-                                         text->cursor.par, 
-                                         men->currentView()->
-                                         text->cursor.pos)))
+               if (table->LeftLine(men->currentView()->text->
+                                   NumberOfCell(men->currentView()->
+                                                text->cursor.par(), 
+                                                men->currentView()->
+                                                text->cursor.pos())))
                        fl_addtopup(SubEditTable, _("|Line Left%B%x38"));
                else
                        fl_addtopup(SubEditTable, _("|Line Left%b%x38"));
                fl_setpup_shortcut(SubEditTable, 38, scex(_("EMT|Ll#l#L")));
 
-               if (men->currentView()->text->cursor.par->table->
-                   RightLine(men->currentView()->text->
-                             NumberOfCell(men->currentView()->
-                                          text->cursor.par, 
-                                          men->currentView()->
-                                          text->cursor.pos)))
+               if (table->RightLine(men->currentView()->text->
+                                    NumberOfCell(men->currentView()->
+                                                 text->cursor.par(), 
+                                                 men->currentView()->
+                                                 text->cursor.pos())))
                        fl_addtopup(SubEditTable, _("|Line Right%B%x39%l"));
                else
                        fl_addtopup(SubEditTable, _("|Line Right%b%x39%l"));
                fl_setpup_shortcut(SubEditTable, 39, scex(_("EMT|Rr#r#R")));
 
-               int align = men->currentView()->text->cursor.par->
+               int align =
                        table->GetAlignment(men->currentView()->text->
                                            NumberOfCell(men->currentView()->
-                                                        text->cursor.par, 
+                                                        text->cursor.par()
                                                         men->currentView()->
-                                                        text->cursor.pos));
+                                                        text->cursor.pos()));
                if (align == LYX_ALIGN_LEFT)
                        fl_addtopup(SubEditTable, _("|Align Left%R%x40"));
                else
@@ -957,8 +999,82 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
                // xgettext:no-c-format
                fl_addtopup(SubEditTable, _("|Delete Table%x43"));
                fl_setpup_shortcut(SubEditTable, 43, scex(_("EMT|Dd#d#D")));
-       }
-       else {
+       } else
+#endif
+               if (men->currentView()->the_locking_inset &&
+                  (men->currentView()->the_locking_inset->LyxCode() ==
+                   Inset::TABULAR_CODE) &&
+                  !tmpbuffer->isReadonly()) {
+               InsetTabular * inset = static_cast<InsetTabular *>(men->currentView()->the_locking_inset);
+               LyXTabular * table = inset->tabular;
+
+               fl_addtopup(SubEditTable, _("Table%t"));
+
+               if (table->IsMultiColumn(inset->GetActCell()))
+                       fl_addtopup(SubEditTable, _("|Multicolumn%B%x44%l"));
+               else
+                       fl_addtopup(SubEditTable, _("|Multicolumn%b%x44%l"));
+               fl_setpup_shortcut(SubEditTable, 44, scex(_("EMT|Mm#m#M")));
+
+               if (table->TopLine(inset->GetActCell()))
+                       fl_addtopup(SubEditTable, _("|Line Top%B%x36"));
+               else
+                       fl_addtopup(SubEditTable, _("|Line Top%b%x36"));
+               fl_setpup_shortcut(SubEditTable, 36, scex(_("EMT|Tt#t#T")));
+     
+               if (table->BottomLine(inset->GetActCell()))
+                       fl_addtopup(SubEditTable, _("|Line Bottom%B%x37"));
+               else
+                       fl_addtopup(SubEditTable, _("|Line Bottom%b%x37"));
+               fl_setpup_shortcut(SubEditTable, 37, scex(_("EMT|Bb#b#B")));
+
+               if (table->LeftLine(inset->GetActCell()))
+                       fl_addtopup(SubEditTable, _("|Line Left%B%x38"));
+               else
+                       fl_addtopup(SubEditTable, _("|Line Left%b%x38"));
+               fl_setpup_shortcut(SubEditTable, 38, scex(_("EMT|Ll#l#L")));
+
+               if (table->RightLine(inset->GetActCell()))
+                       fl_addtopup(SubEditTable, _("|Line Right%B%x39%l"));
+               else
+                       fl_addtopup(SubEditTable, _("|Line Right%b%x39%l"));
+               fl_setpup_shortcut(SubEditTable, 39, scex(_("EMT|Rr#r#R")));
+
+               int align = table->GetAlignment(inset->GetActCell());
+               if (align == LYX_ALIGN_LEFT)
+                       fl_addtopup(SubEditTable, _("|Align Left%R%x40"));
+               else
+                       fl_addtopup(SubEditTable, _("|Align Left%r%x40"));
+               fl_setpup_shortcut(SubEditTable, 40, scex(_("EMT|eE#e#E")));
+
+               if (align == LYX_ALIGN_RIGHT)
+                       fl_addtopup(SubEditTable, _("|Align Right%R%x41"));
+               else
+                       fl_addtopup(SubEditTable, _("|Align Right%r%x41"));
+               fl_setpup_shortcut(SubEditTable, 41, scex(_("EMT|iI#i#I")));
+
+               if (align == LYX_ALIGN_CENTER)
+                       fl_addtopup(SubEditTable, _("|Align Center%R%x42%l"));
+               else
+                       fl_addtopup(SubEditTable, _("|Align Center%r%x42%l"));
+               fl_setpup_shortcut(SubEditTable, 42, scex(_("EMT|Cc#c#C")));
+
+               // xgettext:no-c-format
+               fl_addtopup(SubEditTable, _("|Append Row%x32"));
+               fl_setpup_shortcut(SubEditTable, 32, scex(_("EMT|oO#o#O")));
+               // xgettext:no-c-format
+               fl_addtopup(SubEditTable, _("|Append Column%x33%l"));
+               fl_setpup_shortcut(SubEditTable, 33, scex(_("EMT|uU#u#U")));
+               // xgettext:no-c-format
+               fl_addtopup(SubEditTable, _("|Delete Row%x34"));
+               fl_setpup_shortcut(SubEditTable, 34, scex(_("EMT|wW#w#W")));
+               // xgettext:no-c-format
+               fl_addtopup(SubEditTable, _("|Delete Column%x35%l"));
+               fl_setpup_shortcut(SubEditTable, 35, scex(_("EMT|nN#n#N")));
+               // xgettext:no-c-format
+               fl_addtopup(SubEditTable, _("|Delete Table%x43"));
+               fl_setpup_shortcut(SubEditTable, 43, scex(_("EMT|Dd#d#D")));
+       } else {
                fl_addtopup(SubEditTable, _("Table%t"));
                // xgettext:no-c-format
                fl_addtopup(SubEditTable, _("|Insert table%x31"));
@@ -1014,7 +1130,10 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
                                  "|Table%m"
                                  "|Spellchecker...."
                                  "|Check TeX"
-                                 "|Table of Contents...%l"
+                                 "|Table of Contents..."
+                                 "|List of Figures..."
+                                 "|List of Tables..."
+                                 "|List of Algorithms...%l"
                                  "|Version Control%m%l"
                                  "|View LaTeX log file%l"
                                  "|Paste Primary Selection as Lines"
@@ -1030,14 +1149,17 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
        fl_setpup_shortcut(EditMenu, 7, scex(_("EM|Ee#e#E")));
        fl_setpup_shortcut(EditMenu, 8, scex(_("EM|Nn#n#N")));
        fl_setpup_shortcut(EditMenu, 9, scex(_("EM|Ii#i#I")));
-       fl_setpup_shortcut(EditMenu, 10, scex(_("EM|Tt#t#T")));
+       //fl_setpup_shortcut(EditMenu, 10, scex(_("EM|Tt#t#T")));
        fl_setpup_shortcut(EditMenu, 11, scex(_("EM|Ss#s#S")));
        fl_setpup_shortcut(EditMenu, 12, scex(_("EM|hH#h#H")));
-       fl_setpup_shortcut(EditMenu, 13, scex(_("EM|aA#a#A")));
-       fl_setpup_shortcut(EditMenu, 14, scex(_("EM|Vv#v#V")));
-       fl_setpup_shortcut(EditMenu, 15, scex(_("EM|wW#w#W")));
-       fl_setpup_shortcut(EditMenu, 16, scex(_("EM|Ll#l#L")));
-       fl_setpup_shortcut(EditMenu, 17, scex(_("EM|gG#g#G")));
+       fl_setpup_shortcut(EditMenu, 13, scex(_("EM|Tt#t#T")));
+       //fl_setpup_shortcut(EditMenu, 14, scex(_("EM|Ff#f#F")));
+       //fl_setpup_shortcut(EditMenu, 15, scex(_("EM|bB#b#B")));
+       //fl_setpup_shortcut(EditMenu, 16, scex(_("EM|mM#m#M")));
+       fl_setpup_shortcut(EditMenu, 17, scex(_("EM|Vv#v#V")));
+       fl_setpup_shortcut(EditMenu, 18, scex(_("EM|wW#w#W")));
+       fl_setpup_shortcut(EditMenu, 19, scex(_("EM|Ll#l#L")));
+       fl_setpup_shortcut(EditMenu, 20, scex(_("EM|gG#g#G")));
       
        // disable unavailable entries.
        if(tmpbuffer->undostack.empty())
@@ -1054,8 +1176,8 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
                 fl_setpup_mode(EditMenu, 2, FL_PUP_GREY); 
                 fl_setpup_mode(EditMenu, 3, FL_PUP_GREY); 
                 fl_setpup_mode(EditMenu, 5, FL_PUP_GREY); 
-                fl_setpup_mode(EditMenu, 16, FL_PUP_GREY); 
-                fl_setpup_mode(EditMenu, 17, FL_PUP_GREY);
+                fl_setpup_mode(EditMenu, 19, FL_PUP_GREY); 
+                fl_setpup_mode(EditMenu, 20, FL_PUP_GREY);
        }
        
        fl_setpup_position(men->_view->getForm()->x + ob->x,
@@ -1084,13 +1206,17 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
        case 11: tmpfunc->Dispatch(LFUN_SPELLCHECK); break;
        case 12: tmpfunc->Dispatch(LFUN_RUNCHKTEX); break;
        case 13: tmpfunc->Dispatch(LFUN_TOCVIEW); break;
-       case 14: // version control
+       case 14: tmpfunc->Dispatch(LFUN_LOFVIEW); break;
+       case 15: tmpfunc->Dispatch(LFUN_LOTVIEW); break;
+       case 16: tmpfunc->Dispatch(LFUN_LOAVIEW); break;
+       case 17: // version control
                break;
-       case 15: tmpfunc->Dispatch(LFUN_LATEX_LOG); break;
-       case 16: tmpfunc->Dispatch(LFUN_PASTESELECTION, "line"); break;
-       case 17: tmpfunc->Dispatch(LFUN_PASTESELECTION, "paragraph"); break;
+       case 18: tmpfunc->Dispatch(LFUN_LATEX_LOG); break;
+       case 19: tmpfunc->Dispatch(LFUN_PASTESELECTION, "line"); break;
+       case 20: tmpfunc->Dispatch(LFUN_PASTESELECTION, "paragraph"); break;
 
-               // floats & insets sub-menu
+#ifndef NEW_INSETS
+       // floats & insets sub-menu
        case 21: men->currentView()->toggleFloat(); break;
        case 22: tmpfunc->Dispatch(LFUN_MELT); break;
        case 23: men->currentView()->allFloats(1, 0); break;
@@ -1098,7 +1224,7 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
        case 25: men->currentView()->allFloats(1, 1); break;
        case 26: men->currentView()->allFloats(0, 1); break;
        case 27: tmpfunc->Dispatch(LFUN_REMOVEERRORS); break;
-
+#endif
        case 31: tmpfunc->Dispatch(LFUN_TABLE); break;
                // this is really temporary. We need new function in keybind.C
                // These should set the minibuffer, too.
@@ -1111,11 +1237,23 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
                        men->currentView()->hideCursor();
                        if (!men->currentView()->text->selection){
                                men->currentView()->beforeChange(); 
-                               men->currentView()->update(-2);
+                               men->currentView()->update(BufferView::SELECT|BufferView::FITCUR);
+                       }
+                       if (men->currentView()->the_locking_inset &&
+                           (men->currentView()->the_locking_inset->LyxCode()
+                            == Inset::TABULAR_CODE)) {
+                               InsetTabular * inset =
+                                   static_cast<InsetTabular *>
+                                      (men->currentView()->the_locking_inset);
+                               inset->TabularFeatures(men->currentView(), choice - 32);
+                       }
+#ifndef NEW_TABULAR
+                       else {
+                               men->currentView()->text->
+                                       TableFeatures(men->currentView(), choice - 32);
+                               men->currentView()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
                        }
-                       men->currentView()->text->
-                               TableFeatures(choice - 32);
-                       men->currentView()->update(1);
+#endif
                }
                break;
                // version control sub-menu
@@ -1145,6 +1283,298 @@ void Menus::ShowEditMenu(FL_OBJECT * ob, long)
        fl_freepup(SubVersionControl);
 }
 
+vector<int>::size_type const max_number_of_menus = 32;
+unsigned int const max_number_of_items = 25;
+
+string Limit_string_length(string const & str) {
+       string::size_type const max_item_length = 45;
+
+       if (str.size() > max_item_length)
+               return str.substr(0, max_item_length-3) + "...";
+       else
+               return str;
+}
+
+void Add_to_toc_menu(vector<Buffer::TocItem> const & toclist, 
+                    unsigned int from, unsigned int to, int depth,
+                    int menu, vector<int> & menus, FL_OBJECT * ob)
+{
+       if (to - from <= max_number_of_items) {
+               for (unsigned int i = from; i < to; ++i) {
+                       string entry(4 * max(0, toclist[i].depth - depth),' ');
+                       entry += toclist[i].str;
+                       entry = Limit_string_length(entry);
+                       entry += "%x" + tostr(i + 1);
+                       fl_addtopup(menu, entry.c_str());
+               }
+       } else {
+               unsigned int pos = from;
+               unsigned int count = 0;
+               while (pos < to) {
+                       ++count;
+                       if (count > max_number_of_items) {
+                               fl_addtopup(menu, ". . .%d");
+                               break;
+                       }
+                       unsigned int new_pos = pos+1;
+                       while (new_pos < to &&
+                              toclist[new_pos].depth > depth)
+                               ++new_pos;
+
+                       string entry(4 * max(0, toclist[pos].depth - depth), ' ');
+                       entry += toclist[pos].str;
+                       entry = Limit_string_length(entry);
+
+                       if (new_pos == pos + 1) {
+                               entry += "%x";
+                               entry += tostr(pos + 1);
+                               fl_addtopup(menu, entry.c_str());
+                       } else if (menus.size() < max_number_of_menus) {
+                               int menu2 = fl_newpup(FL_ObjWin(ob));
+                               menus.push_back(menu2);
+                               Add_to_toc_menu(toclist, pos, new_pos,
+                                               depth + 1, menu2, menus,ob);
+                               entry += "%m";
+                               fl_addtopup(menu, entry.c_str(), menu2);
+                       } else {
+                               entry += "%d";
+                               fl_addtopup(menu, entry.c_str());
+                       }
+                       pos = new_pos;
+               }
+       }
+}
+
+int const BIG_NUM = 1048576;
+
+void Menus::ShowTocMenu(FL_OBJECT * ob, long)
+{
+       Menus * men = static_cast<Menus*>(ob->u_vdata);
+       vector<int> menus;
+
+       // set the pseudo menu-button
+       fl_set_object_boxtype(ob, FL_UP_BOX);
+       fl_set_button(ob, 0);
+       fl_redraw_object(ob);
+   
+       int TocMenu = fl_newpup(FL_ObjWin(ob));
+       menus.push_back(TocMenu);
+       vector<vector<Buffer::TocItem> > toclist =
+               men->currentView()->buffer()->getTocList();
+
+       //xgettext:no-c-format
+       static char const * MenuNames[3] = { N_("List of Figures%m"),
+       //xgettext:no-c-format
+                                            N_("List of Tables%m"),
+       //xgettext:no-c-format
+                                            N_("List of Algorithms%m") };
+
+       int max_nonempty = 0;
+       for (int j = 1; j <= 3; ++j)
+               if (!toclist[j].empty())
+                       max_nonempty = j;
+
+       for (int j = 1; j <= 3; ++j)
+               if (!toclist[j].empty()) {
+                       int menu2 = fl_newpup(FL_ObjWin(ob));
+                       menus.push_back(menu2);
+                       for (unsigned int i = 0; i < toclist[j].size(); ++i) {
+                               if (i > max_number_of_items) {
+                                       fl_addtopup(menu2, ". . .%d");
+                                       break;
+                               }
+                               string entry = Limit_string_length(toclist[j][i].str);
+                               entry += "%x" + tostr(i+1+j*BIG_NUM);
+                               fl_addtopup(menu2, entry.c_str());
+                       }
+                       if (j == max_nonempty) {
+                               string tmp = _(MenuNames[j-1]);
+                               tmp += "%l";
+                               fl_addtopup(TocMenu, tmp.c_str(), menu2);
+                       } else
+                               fl_addtopup(TocMenu, _(MenuNames[j-1]), menu2);
+               }
+
+       Add_to_toc_menu(toclist[0], 0, toclist[0].size(), 0,
+                       TocMenu, menus, ob);
+
+       fl_setpup_position(
+               men->_view->getForm()->x + ob->x,
+               men->_view->getForm()->y + ob->y + ob->h + 10);   
+       int choice = fl_dopup(TocMenu);
+       XFlush(fl_display);
+
+       // set the pseudo menu-button back
+       fl_set_object_boxtype(ob, FL_FLAT_BOX);
+       fl_redraw_object(ob);
+       if (choice == 0)
+               men->_view->getLyXFunc()->Dispatch(LFUN_TOCVIEW);
+       else if (choice > 0) {
+               int type = choice / BIG_NUM;
+               int num = (choice % BIG_NUM) - 1;
+               BufferView *bv = men->currentView();
+               bv->beforeChange();
+               bv->text->SetCursor(bv, toclist[type][num].par, 0);
+               bv->text->sel_cursor = bv->text->cursor;
+               bv->update(BufferView::SELECT|BufferView::FITCUR);
+       }
+       for (unsigned int i = 0; i < menus.size(); ++i)
+               fl_freepup(menus[i]);
+}
+
+void Add_to_refs_menu(vector<string> const & label_list, int offset,
+                    int menu, vector<int> & menus, FL_OBJECT * ob)
+{
+       typedef vector<string>::size_type size_type;
+       size_type const max_number_of_items = 25;
+       size_type const max_number_of_items2 = 20;
+       string::size_type const max_item_length = 40;
+       string::size_type const max_item_length2 = 20;
+
+       if (label_list.size() <= max_number_of_items)
+               for (size_type i = 0; i < label_list.size(); ++i) {
+                       string entry = label_list[i];
+                       if (entry.size() > max_item_length)
+                               entry = entry.substr(0, max_item_length-1) + "$";
+                       entry += "%x" + tostr(i+offset);
+                       fl_addtopup(menu, entry.c_str());
+               }
+       else {
+               size_type count = 0;
+               for (size_type i = 0; i < label_list.size();
+                    i += max_number_of_items2) {
+                       ++count;
+                       if (count > max_number_of_items) {
+                               fl_addtopup(menu, ". . .%d");
+                               break;
+                       }
+                       size_type j = min(label_list.size(),
+                                         i+max_number_of_items2);
+
+                       string entry;
+                       if (label_list[i].size() > max_item_length2)
+                               entry += label_list[i].substr(0, max_item_length2-1) + "$";
+                       else
+                               entry += label_list[i];
+                       entry += "..";
+                       if (label_list[j-1].size() > max_item_length2)
+                               entry += label_list[j-1].substr(0, max_item_length2-1) + "$";
+                       else
+                               entry += label_list[j-1];
+
+                       if (menus.size() < max_number_of_menus) {
+                               int menu2 = fl_newpup(FL_ObjWin(ob));
+                               menus.push_back(menu2);
+                               for (size_type k = i;  k < j; ++k) {
+                                       string entry2 = label_list[k];
+                                       if (entry2.size() > max_item_length)
+                                               entry2 = entry2.substr(0, max_item_length-1) + "$";
+                                       entry2 += "%x" + tostr(k+offset);
+                                       fl_addtopup(menu2, entry2.c_str());
+                               }
+                               entry += "%m";
+                               fl_addtopup(menu, entry.c_str(), menu2);
+                       } else {
+                               entry += "%d";
+                               fl_addtopup(menu, entry.c_str());
+                       }
+               }
+       }
+}
+
+void Menus::ShowRefsMenu(FL_OBJECT * ob, long)
+{
+       vector<int> menus;
+
+       Menus * men = static_cast<Menus*>(ob->u_vdata);
+
+       // set the pseudo menu-button
+       fl_set_object_boxtype(ob, FL_UP_BOX);
+       fl_set_button(ob, 0);
+       fl_redraw_object(ob);
+   
+       int RefsMenu = fl_newpup(FL_ObjWin(ob));
+       menus.push_back(RefsMenu);
+       Buffer * buffer = men->currentView()->buffer();
+       vector<string> label_list = buffer->getLabelList();
+       sort(label_list.begin(), label_list.end());
+
+       //xgettext:no-c-format
+       static char const * MenuNames[6] = { N_("Insert Reference%m"),
+       //xgettext:no-c-format
+                                            N_("Insert Page Number%m"),
+       //xgettext:no-c-format
+                                            N_("Insert vref%m"),
+       //xgettext:no-c-format
+                                            N_("Insert vpageref%m"),
+       //xgettext:no-c-format
+                                            N_("Insert Pretty Ref%m"),
+       //xgettext:no-c-format
+                                            N_("Goto Reference%m") };
+
+       for (int j = 0; j < 6; ++j) {
+               if (menus.size() < max_number_of_menus) {
+                       int menu2 = fl_newpup(FL_ObjWin(ob));
+                       menus.push_back(menu2);
+                       Add_to_refs_menu(label_list, (j+1)*BIG_NUM, menu2, menus, ob);
+                       fl_addtopup(RefsMenu, _(MenuNames[j]), menu2);
+               } else {
+                       string tmp = _(MenuNames[j]);
+                       tmp += "%d";
+                       fl_addtopup(RefsMenu, tmp.c_str());     
+               }
+       }
+       fl_addtopup(RefsMenu, _("Go Back"));
+
+       bool empty = label_list.empty();
+       bool sgml = buffer->isSGML();
+       bool readonly = buffer->isReadonly();
+
+       if (empty)
+               fl_setpup_mode(RefsMenu, 6, FL_PUP_GREY);
+       if (empty || readonly) {
+               fl_setpup_mode(RefsMenu, 1, FL_PUP_GREY);
+               fl_setpup_mode(RefsMenu, 2, FL_PUP_GREY);
+       }
+       if (empty || readonly || sgml) {
+               fl_setpup_mode(RefsMenu, 3, FL_PUP_GREY);
+               fl_setpup_mode(RefsMenu, 4, FL_PUP_GREY);
+               fl_setpup_mode(RefsMenu, 5, FL_PUP_GREY);
+       }
+       if (men->currentView()->NoSavedPositions())
+               fl_setpup_mode(RefsMenu, 7, FL_PUP_GREY);       
+
+       fl_setpup_position(
+               men->_view->getForm()->x + ob->x,
+               men->_view->getForm()->y + ob->y + ob->h + 10);   
+       int choice = fl_dopup(RefsMenu);
+       XFlush(fl_display);
+
+       // set the pseudo menu-button back
+       fl_set_object_boxtype(ob, FL_FLAT_BOX);
+       fl_redraw_object(ob);
+
+       if (choice == 7)
+               men->_view->getLyXFunc()->Dispatch(LFUN_REFBACK);
+       else if (choice >= BIG_NUM) {
+               int type = (choice / BIG_NUM) - 1;
+               int num = choice % BIG_NUM;
+               if (type >= 5)
+                       men->_view->getLyXFunc()->Dispatch(LFUN_REFGOTO,
+                                                          label_list[num].c_str());
+               else {
+                       static string const cmdname[5]
+                               = { "ref", "pageref", "vref", "vpageref", "prettyref"};
+                       InsetCommandParams p( cmdname[type] );
+                       p.setContents( label_list[num] );
+                       men->currentView()->insertInset(new InsetRef(p, buffer));
+               }
+       }
+
+       for (unsigned int i = 0; i < menus.size(); ++i)
+               fl_freepup(menus[i]);
+}
+
 
 void Menus::ShowLayoutMenu(FL_OBJECT * ob, long)
 {
@@ -1171,9 +1601,10 @@ void Menus::ShowLayoutMenu(FL_OBJECT * ob, long)
                                  "|Emphasize Style%b"
                                  "|Noun Style%b"
                                  "|Bold Style%b"
-                                 "|TeX Style%b"
+                                 "|TeX Style%b%l"
                                  "|Change Environment Depth"
-                                 "|LaTeX Preamble...%l"
+                                 "|LaTeX Preamble..."
+                                 "|Start of Appendix%l"
                                  "|Save layout as default"));
        fl_setpup_shortcut(LayoutMenu, 1, scex(_("LM|Cc#c#C")));
        fl_setpup_shortcut(LayoutMenu, 2, scex(_("LM|Pp#p#P")));
@@ -1187,7 +1618,8 @@ void Menus::ShowLayoutMenu(FL_OBJECT * ob, long)
        fl_setpup_shortcut(LayoutMenu, 10, scex(_("LM|Tt#t#T")));
        fl_setpup_shortcut(LayoutMenu, 11, scex(_("LM|vV#v#V")));
        fl_setpup_shortcut(LayoutMenu, 12, scex(_("LM|Ll#l#L")));
-       fl_setpup_shortcut(LayoutMenu, 13, scex(_("LM|Ss#s#S")));
+       fl_setpup_shortcut(LayoutMenu, 13, scex(_("LM|xX#x#X")));
+       fl_setpup_shortcut(LayoutMenu, 14, scex(_("LM|Ss#s#S")));
 
        // Set values of checkboxes according to font
        LyXFont font = men->currentView()->text->real_current_font;
@@ -1199,11 +1631,12 @@ void Menus::ShowLayoutMenu(FL_OBJECT * ob, long)
                fl_setpup_mode(LayoutMenu, 9, FL_PUP_CHECK);
        if (font.latex() == LyXFont::ON)
                fl_setpup_mode(LayoutMenu, 10, FL_PUP_CHECK);
-          
+
        // Grey out unavailable entries
-       if (!men->currentView()->text->cursor.par->table)
+#ifndef NEW_TABULAR
+       if (!men->currentView()->text->cursor.par()->table)
                fl_setpup_mode(LayoutMenu, 5, FL_PUP_GREY);
-
+#endif
        if (tmpbuffer->isReadonly()) {
                fl_setpup_mode(LayoutMenu, 1, FL_PUP_GREY);
                fl_setpup_mode(LayoutMenu, 6, FL_PUP_GREY);
@@ -1233,7 +1666,8 @@ void Menus::ShowLayoutMenu(FL_OBJECT * ob, long)
        case 10: tmpfunc->Dispatch(LFUN_TEX); break;
        case 11: tmpfunc->Dispatch(LFUN_DEPTH_PLUS); break;
        case 12: tmpfunc->Dispatch(LFUN_LAYOUT_PREAMBLE); break;
-       case 13: tmpfunc->Dispatch(LFUN_LAYOUT_SAVE_DEFAULT); break;
+       case 13: tmpfunc->Dispatch(LFUN_APPENDIX); break;
+       case 14: tmpfunc->Dispatch(LFUN_LAYOUT_SAVE_DEFAULT); break;
        }
        fl_freepup(LayoutMenu); 
 }
@@ -1314,7 +1748,8 @@ void Menus::ShowInsertMenu(FL_OBJECT * ob, long)
                                     "|Table...%l"
                                     "|Include File..." 
                                     "|Import ASCII File%m"
-                                    "|Insert LyX File...%l"
+                                    "|Insert LyX File..."
+                                    "|Insert external material...%l"
                                     "|Footnote"
                                     "|Margin Note"
                                     "|Floats%m%l"      
@@ -1336,25 +1771,26 @@ void Menus::ShowInsertMenu(FL_OBJECT * ob, long)
        fl_setpup_shortcut(InsertMenu, 3, scex(_("IM|cC#c#C")));
        fl_setpup_shortcut(InsertMenu, 4, scex(_("IM|Aa#a#A")));
        fl_setpup_shortcut(InsertMenu, 5, scex(_("IM|Xx#x#X")));
-       fl_setpup_shortcut(InsertMenu, 6, scex(_("IM|Ff#f#F")));
-       fl_setpup_shortcut(InsertMenu, 7, scex(_("IM|Mm#m#M")));
-       fl_setpup_shortcut(InsertMenu, 8, scex(_("IM|oO#o#O")));
-       fl_setpup_shortcut(InsertMenu, 9, scex(_("IM|Tt#t#T")));
-       fl_setpup_shortcut(InsertMenu, 10, scex(_("IM|Ss#s#S")));
-       fl_setpup_shortcut(InsertMenu, 11, scex(_("IM|Nn#n#N")));
-       fl_setpup_shortcut(InsertMenu, 12, scex(_("IM|Ll#l#L")));
-       fl_setpup_shortcut(InsertMenu, 13, scex(_("IM|rR#r#R")));     
-       fl_setpup_shortcut(InsertMenu, 14, scex(_("IM|iI#i#I")));
-       fl_setpup_shortcut(InsertMenu, 15, scex(_("IM|dD#d#D")));
-       fl_setpup_shortcut(InsertMenu, 16, scex(_("IM|wW#w#W")));
+       fl_setpup_shortcut(InsertMenu, 6, scex(_("IM|Ee#e#E")));
+       fl_setpup_shortcut(InsertMenu, 7, scex(_("IM|Ff#f#F")));
+       fl_setpup_shortcut(InsertMenu, 8, scex(_("IM|Mm#m#M")));
+       fl_setpup_shortcut(InsertMenu, 9, scex(_("IM|oO#o#O")));
+       fl_setpup_shortcut(InsertMenu, 10, scex(_("IM|Tt#t#T")));
+       fl_setpup_shortcut(InsertMenu, 11, scex(_("IM|Ss#s#S")));
+       fl_setpup_shortcut(InsertMenu, 12, scex(_("IM|Nn#n#N")));
+       fl_setpup_shortcut(InsertMenu, 13, scex(_("IM|Ll#l#L")));
+       fl_setpup_shortcut(InsertMenu, 14, scex(_("IM|rR#r#R")));     
+       fl_setpup_shortcut(InsertMenu, 15, scex(_("IM|iI#i#I")));
+       fl_setpup_shortcut(InsertMenu, 16, scex(_("IM|dD#d#D")));
+       fl_setpup_shortcut(InsertMenu, 17, scex(_("IM|wW#w#W")));
 
        fl_addtopup(InsertMenu, _("|URL..."));
-       fl_setpup_shortcut(InsertMenu, 17, scex(_("IM|Uu#u#U")));
+       fl_setpup_shortcut(InsertMenu, 18, scex(_("IM|Uu#u#U")));
 
        if (tmpbuffer->isReadonly()) {
-                for (int ii = 1; ii <= 16; ++ii)
+                for (int ii = 1; ii <= 17; ++ii)
                        fl_setpup_mode(InsertMenu, ii, FL_PUP_GREY);
-               fl_setpup_mode(InsertMenu, 17, FL_PUP_GREY);
+               fl_setpup_mode(InsertMenu, 18, FL_PUP_GREY);
        }
 
        fl_setpup_position(
@@ -1382,28 +1818,65 @@ void Menus::ShowInsertMenu(FL_OBJECT * ob, long)
                case 43: 
                        break;
 
-               case 6: tmpfunc->Dispatch(LFUN_FOOTMELT); break
-                                                                 ;
-               case 7: tmpfunc->Dispatch(LFUN_MARGINMELT); break;
+               case 6: tmpfunc->Dispatch(LFUN_INSET_EXTERNAL); break;
+
+               case 7:
+#ifndef NEW_INSETS
+                       tmpfunc->Dispatch(LFUN_FOOTMELT); break;
+#else
+                       tmpfunc->Dispatch(LFUN_INSET_FOOTNOTE);
+                       break;
+#endif
+               case 8:
+#ifndef NEW_INSETS
+                       tmpfunc->Dispatch(LFUN_MARGINMELT); break;
+#else
+                       tmpfunc->Dispatch(LFUN_INSET_MARGINAL);
+                       break;
+#endif
   
-               case 8: // Float sub-menu
+               case 9: // Float sub-menu
                 case 71:
+#ifndef NEW_INSETS
                        tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "figure");
                        break;
+#else
+                       tmpfunc->Dispatch(LFUN_INSET_FLOAT, "figure");
+                       break;
+#endif
                case 72:
+#ifndef NEW_INSETS
                        tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "table");
                        break;
+#else
+                       tmpfunc->Dispatch(LFUN_INSET_FLOAT, "table");
+                       break;
+#endif
                case 73:
+#ifndef NEW_INSETS
                        tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "wide-fig");
                        break;
+#else
+                       tmpfunc->Dispatch(LFUN_INSET_FLOAT, "figure");
+                       break;
+#endif
                case 74:
+#ifndef NEW_INSETS
                        tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "wide-tab");
                        break;
+#else
+                       tmpfunc->Dispatch(LFUN_INSET_FLOAT, "table");
+                       break;
+#endif
                case 75:
+#ifndef NEW_INSETS
                        tmpfunc->Dispatch(LFUN_INSERTFOOTNOTE, "algorithm");
                        break;
-
-               case 9: // Table/List submenu
+#else
+                       tmpfunc->Dispatch(LFUN_INSET_FLOAT, "algorithm");
+                       break;
+#endif
+               case 10: // Table/List submenu
                        break;
                case 21: tmpfunc->Dispatch(LFUN_TOC_INSERT); break;
                case 22: tmpfunc->Dispatch(LFUN_LOF_INSERT); break;
@@ -1412,7 +1885,7 @@ void Menus::ShowInsertMenu(FL_OBJECT * ob, long)
                case 25: tmpfunc->Dispatch(LFUN_INDEX_PRINT); break;
                case 26: tmpfunc->Dispatch(LFUN_INSERT_BIBTEX); break;
 
-               case 10: // Special Character submenu
+               case 11: // Special Character submenu
                        break;
                case 31: tmpfunc->Dispatch(LFUN_HFILL); break;
                case 32: tmpfunc->Dispatch(LFUN_HYPHENATION); break;
@@ -1423,13 +1896,13 @@ void Menus::ShowInsertMenu(FL_OBJECT * ob, long)
                case 37: tmpfunc->Dispatch(LFUN_QUOTE); break;
                case 38: tmpfunc->Dispatch(LFUN_MENU_SEPARATOR); break;
 
-               case 11: tmpfunc->Dispatch(LFUN_INSERT_NOTE); break;
-               case 12: tmpfunc->Dispatch(LFUN_INSERT_LABEL); break;
-               case 13: tmpfunc->Dispatch(LFUN_INSERT_REF); break;
-               case 14: tmpfunc->Dispatch(LFUN_INSERT_CITATION); break;
-               case 15: tmpfunc->Dispatch(LFUN_INDEX_INSERT); break;
-               case 16: tmpfunc->Dispatch(LFUN_INDEX_INSERT_LAST); break;
-               case 17: tmpfunc->Dispatch(LFUN_URL); break;
+               case 12: tmpfunc->Dispatch(LFUN_INSERT_NOTE); break;
+               case 13: tmpfunc->Dispatch(LFUN_INSERT_LABEL); break;
+               case 14: tmpfunc->Dispatch(LFUN_INSERT_REF); break;
+               case 15: tmpfunc->Dispatch(LFUN_CITATION_CREATE); break;
+               case 16: tmpfunc->Dispatch(LFUN_INDEX_CREATE); break;
+               case 17: tmpfunc->Dispatch(LFUN_INDEX_INSERT_LAST); break;
+               case 18: tmpfunc->Dispatch(LFUN_URL); break;
                }
        }
        fl_freepup(InsertMenu);
@@ -1517,10 +1990,10 @@ void Menus::ShowMathMenu(FL_OBJECT * ob, long)
                        tmpfunc->Dispatch(LFUN_MATH_DISPLAY);
                        break;
                case 9: /* Panel */
-                       show_symbols_form(tmpfunc);
+                       tmpfunc->Dispatch(LFUN_MATH_PANEL);
                        break;
                }
-               men->currentView()->update(0);
+               men->currentView()->update(BufferView::SELECT|BufferView::FITCUR);
        } 
        fl_freepup(MathMenu);
 }
@@ -1541,15 +2014,15 @@ void Menus::ShowOptionsMenu(FL_OBJECT * ob, long)
        int OptionsMenu = fl_defpup(FL_ObjWin(ob),
                                    _("Screen Fonts..."
                                      "|Spellchecker Options..."
-                                     "|Keyboard..."
-                                     "|LaTeX...%l"
-                                     "|Reconfigure" ));
+                                     "|Keyboard...%l"
+                                     "|Reconfigure"
+                                     "|Preferences"));
 
        fl_setpup_shortcut(OptionsMenu, 1, scex(_("OM|Ff#f#F")));
        fl_setpup_shortcut(OptionsMenu, 2, scex(_("OM|Ss#s#S")));
        fl_setpup_shortcut(OptionsMenu, 3, scex(_("OM|Kk#k#K")));
-       fl_setpup_shortcut(OptionsMenu, 4, scex(_("OM|Ll#l#L")));
-       fl_setpup_shortcut(OptionsMenu, 5, scex(_("OM|Rr#r#R")));
+       fl_setpup_shortcut(OptionsMenu, 4, scex(_("OM|Rr#r#R")));
+       fl_setpup_shortcut(OptionsMenu, 5, scex(_("OM|Pp#p#P")));
 
        if(lyxrc.isp_command == "none") 
                fl_setpup_mode(OptionsMenu, 2, FL_PUP_GREY);
@@ -1567,8 +2040,8 @@ void Menus::ShowOptionsMenu(FL_OBJECT * ob, long)
        case 1: men->ScreenOptions(); break;
        case 2: SpellCheckerOptions(); break;      
        case 3: men->_view->getIntl()->MenuKeymap(); break;
-       case 4: LaTeXOptions(men->_view->view()); break;
-       case 5: tmpfunc->Dispatch(LFUN_RECONFIGURE); break;
+       case 4: tmpfunc->Dispatch(LFUN_RECONFIGURE); break;
+       case 5: men->_view->getDialogs()->showPreferences(); break;
        default: break;
        }   
        fl_freepup(OptionsMenu);
@@ -1615,11 +2088,13 @@ static
 char const * doc_files [] = {"Intro", "Tutorial", 
                             "UserGuide", "Extended",
                             "Customization", "Reference",
-                            "BUGS", "LaTeXConfig"}; 
+                            "FAQ", "TOC",  
+                            "BUGS", "LyXConfig"}; 
 
 void Menus::ShowHelpMenu(FL_OBJECT * ob, long)
 {
        Menus * men = static_cast<Menus*>(ob->u_vdata);
+       LyXFunc * tmpfunc = men->_view->getLyXFunc();
 
        // set the pseudo menu-button
        fl_set_object_boxtype(ob, FL_UP_BOX);
@@ -1633,6 +2108,8 @@ void Menus::ShowHelpMenu(FL_OBJECT * ob, long)
                                   "|Extended Features"
                                   "|Customization"
                                   "|Reference Manual"
+                                  "|FAQ"
+                                  "|Table of Contents"
                                   "|Known Bugs"
                                   "|LaTeX Configuration%l"
                                   "|Copyright and Warranty..."
@@ -1645,11 +2122,13 @@ void Menus::ShowHelpMenu(FL_OBJECT * ob, long)
        fl_setpup_shortcut(HelpMenu,  4, scex(_("HM|xX#x#X")));
        fl_setpup_shortcut(HelpMenu,  5, scex(_("HM|Cc#C#c")));
        fl_setpup_shortcut(HelpMenu,  6, scex(_("HM|Rr#R#r")));
-       fl_setpup_shortcut(HelpMenu,  7, scex(_("HM|Kk#K#k")));
-       fl_setpup_shortcut(HelpMenu,  8, scex(_("HM|Ll#L#l")));
-       fl_setpup_shortcut(HelpMenu,  9, scex(_("HM|oO#o#O")));
-       fl_setpup_shortcut(HelpMenu, 10, scex(_("HM|eE#e#E")));
-       fl_setpup_shortcut(HelpMenu, 11, scex(_("HM|Vv#v#V")));
+       fl_setpup_shortcut(HelpMenu,  7, scex(_("HM|Ff#F#f")));
+       fl_setpup_shortcut(HelpMenu,  8, scex(_("HM|aA#a#A")));
+       fl_setpup_shortcut(HelpMenu,  9, scex(_("HM|Kk#K#k")));
+       fl_setpup_shortcut(HelpMenu, 10, scex(_("HM|Ll#L#l")));
+       fl_setpup_shortcut(HelpMenu, 11, scex(_("HM|oO#o#O")));
+       fl_setpup_shortcut(HelpMenu, 12, scex(_("HM|eE#e#E")));
+       fl_setpup_shortcut(HelpMenu, 13, scex(_("HM|Vv#v#V")));
 
        fl_setpup_position(
                men->_view->getForm()->x + ob->x,
@@ -1663,22 +2142,22 @@ void Menus::ShowHelpMenu(FL_OBJECT * ob, long)
 
        switch (choice) {
        case 1: case 2: case 3: case 4: case 5: 
-       case 6: case 7: case 8:
-               ProhibitInput();
+       case 6: case 7: case 8: case 9: case 10:
+               ProhibitInput(men->currentView());
                men->MenuDocu(doc_files[choice - 1]);
-               AllowInput();
+               AllowInput(men->currentView());
                break;
-       case 9: ShowCopyright(); break;
-       case 10: ShowCredits(); break;
-       case 11:
-               ProhibitInput();
+       case 11: tmpfunc->Dispatch(LFUN_HELP_COPYRIGHT); break;
+       case 12: ShowCredits(); break;
+       case 13:
+               ProhibitInput(men->currentView());
                fl_show_message((string(_("LyX Version ")) + LYX_VERSION 
                                 + _(" of ") + LYX_RELEASE).c_str(),
                                (_("Library directory: ")
                                 + MakeDisplayPath(system_lyxdir)).c_str(),
                                (_("User directory: ") 
                                 + MakeDisplayPath(user_lyxdir)).c_str());
-               AllowInput();
+               AllowInput(men->currentView());
                break;
        }
        fl_freepup(HelpMenu);