]> git.lyx.org Git - lyx.git/blobdiff - src/MenuBackend.C
cosmetic fix
[lyx.git] / src / MenuBackend.C
index a6a47b27d741d4090e17c43b32d02021c6a35401..f8df5e66f3225d461c67a79e96f559a32fc09277 100644 (file)
@@ -11,7 +11,6 @@
 
 #include <config.h>
 
-#include <algorithm>
 #include "MenuBackend.h"
 #include "lyxlex.h"
 #include "LyXAction.h"
 #include "importer.h"
 #include "FloatList.h"
 #include "toc.h"
+#include "CutAndPaste.h"
 #include "frontends/LyXView.h"
 #include "support/LAssert.h"
 #include "support/filetools.h"
 #include "support/lyxfunctional.h"
 #include "support/lstrings.h"
+#include "support/tostr.h"
+
+#include <algorithm>
 
 extern BufferList bufferlist;
 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
+using namespace lyx::support;
+
 using std::endl;
 using std::vector;
 using std::max;
@@ -63,6 +68,7 @@ MenuItem::MenuItem(Kind kind, string const & label,
        case ImportFormats:
        case FloatListInsert:
        case FloatInsert:
+       case PasteRecent:
                break;
        case Command:
                action_ = lyxaction.LookupFunc(command);
@@ -197,6 +203,7 @@ Menu & Menu::read(LyXLex & lex)
                md_viewformats,
                md_floatlistinsert,
                md_floatinsert,
+               md_pasterecent,
                md_last
        };
 
@@ -211,6 +218,7 @@ Menu & Menu::read(LyXLex & lex)
                { "lastfiles", md_lastfiles },
                { "optitem", md_optitem },
                { "optsubmenu", md_optsubmenu },
+               { "pasterecent", md_pasterecent },
                { "separator", md_separator },
                { "submenu", md_submenu },
                { "toc", md_toc },
@@ -281,6 +289,10 @@ Menu & Menu::read(LyXLex & lex)
                        add(MenuItem(MenuItem::FloatInsert));
                        break;
 
+               case md_pasterecent:
+                       add(MenuItem(MenuItem::PasteRecent));
+                       break;
+
                case md_optsubmenu:
                        optional = true;
                        // fallback to md_submenu
@@ -313,7 +325,7 @@ Menu & Menu::read(LyXLex & lex)
 void Menu::checkShortcuts() const
 {
        // This is a quadratic algorithm, but we do not care because
-       // it is used for debugging only.
+       // menus are short enough
        for (const_iterator it1 = begin(); it1 != end(); ++it1) {
                string shortcut = it1->shortcut();
                if (shortcut.empty())
@@ -322,7 +334,7 @@ void Menu::checkShortcuts() const
                        lyxerr << "Menu warning: menu entry \""
                               << it1->label()
                               << "\" does not contain shortcut `"
-                              << shortcut << '\'' << endl;
+                              << shortcut << "'." << endl;
                for (const_iterator it2 = begin(); it2 != it1 ; ++it2) {
                        if (!compare_ascii_no_case(it2->shortcut(), shortcut)) {
                                lyxerr << "Menu warning: menu entries "
@@ -390,7 +402,7 @@ void expandDocuments(Menu & tomenu, LyXView const * view)
        for (; docit != end; ++docit, ++ii) {
                int const action =
                        lyxaction.getPseudoAction(LFUN_SWITCHBUFFER, *docit);
-               string label = MakeDisplayPath(*docit, 30);
+               string label = MakeDisplayPath(*docit, 20);
                if (ii < 10)
                        label = tostr(ii) + ". " + label + '|' + tostr(ii);
                tomenu.add(MenuItem(MenuItem::Command, label, action), view);
@@ -605,6 +617,22 @@ void expandToc(Menu & tomenu, LyXView const * view)
 }
 
 
+void expandPasteRecent(Menu & tomenu, LyXView const * view)
+{
+       vector<string> const selL =
+               CutAndPaste::availableSelections(*view->buffer());
+
+       vector<string>::const_iterator cit = selL.begin();
+       vector<string>::const_iterator end = selL.end();
+
+       for (unsigned int index = 0; cit != end; ++cit, ++index) {
+               int const action = lyxaction.getPseudoAction(LFUN_PASTE,
+                                                            tostr(index));
+               tomenu.add(MenuItem(MenuItem::Command, *cit, action));
+       }
+}
+
+
 } // namespace anon
 
 
@@ -637,6 +665,10 @@ void MenuBackend::expand(Menu const & frommenu, Menu & tomenu,
                        expandFloatInsert(tomenu, view);
                        break;
 
+               case MenuItem::PasteRecent:
+                       expandPasteRecent(tomenu, view);
+                       break;
+
                case MenuItem::Toc:
                        expandToc(tomenu, view);
                        break;
@@ -661,8 +693,7 @@ void MenuBackend::expand(Menu const & frommenu, Menu & tomenu,
                tomenu.items_.pop_back();
 
        // Check whether the shortcuts are unique
-       if (lyxerr.debugging(Debug::GUI))
-               tomenu.checkShortcuts();
+       tomenu.checkShortcuts();
 }
 
 
@@ -750,7 +781,7 @@ Menu const & MenuBackend::getMenu(string const & name) const
                                     lyx::compare_memfun(&Menu::name, name));
        if (cit == end())
                lyxerr << "No submenu named " << name << endl;
-       lyx::Assert(cit != end());
+       Assert(cit != end());
        return (*cit);
 }
 
@@ -760,7 +791,7 @@ Menu & MenuBackend::getMenu(string const & name)
        MenuList::iterator it =
                find_if(menulist_.begin(), menulist_.end(),
                        lyx::compare_memfun(&Menu::name, name));
-       lyx::Assert(it != menulist_.end());
+       Assert(it != menulist_.end());
        return (*it);
 }