]> git.lyx.org Git - lyx.git/blobdiff - src/MenuBackend.C
Point fix, earlier forgotten
[lyx.git] / src / MenuBackend.C
index 9a506537b07022445ae917812f37f949a463f6f5..ef780bbc7aa32a43a7d0de61181733588cb57e58 100644 (file)
@@ -1,13 +1,17 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file MenuBackend.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Asger Alstrup
+ * \author Lars Gullik Bjønnes
+ * \author Jean-Marc Lasgouttes
+ * \author André Pönitz
+ * \author Dekel Tsur
+ * \author Martin Vermeer
  *
- *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2001 The LyX Team.
- *
- *
- * ====================================================== */
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
@@ -27,6 +31,7 @@
 #include "importer.h"
 #include "FloatList.h"
 #include "toc.h"
+#include "CutAndPaste.h"
 #include "frontends/LyXView.h"
 #include "support/LAssert.h"
 #include "support/filetools.h"
@@ -39,6 +44,8 @@
 extern BufferList bufferlist;
 extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
+using namespace lyx::support;
+
 using std::endl;
 using std::vector;
 using std::max;
@@ -65,6 +72,8 @@ MenuItem::MenuItem(Kind kind, string const & label,
        case ImportFormats:
        case FloatListInsert:
        case FloatInsert:
+       case PasteRecent:
+       case Branches:
                break;
        case Command:
                action_ = lyxaction.LookupFunc(command);
@@ -185,6 +194,7 @@ Menu & Menu::read(LyXLex & lex)
 {
        enum Menutags {
                md_item = 1,
+               md_branches,
                md_documents,
                md_endmenu,
                md_exportformats,
@@ -199,10 +209,12 @@ Menu & Menu::read(LyXLex & lex)
                md_viewformats,
                md_floatlistinsert,
                md_floatinsert,
+               md_pasterecent,
                md_last
        };
 
        struct keyword_item menutags[md_last - 1] = {
+               { "branches", md_branches },
                { "documents", md_documents },
                { "end", md_endmenu },
                { "exportformats", md_exportformats },
@@ -213,6 +225,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 },
@@ -283,6 +296,14 @@ Menu & Menu::read(LyXLex & lex)
                        add(MenuItem(MenuItem::FloatInsert));
                        break;
 
+               case md_pasterecent:
+                       add(MenuItem(MenuItem::PasteRecent));
+                       break;
+
+               case md_branches:
+                       add(MenuItem(MenuItem::Branches));
+                       break;
+
                case md_optsubmenu:
                        optional = true;
                        // fallback to md_submenu
@@ -315,7 +336,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())
@@ -324,7 +345,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 "
@@ -419,15 +440,15 @@ void expandFormats(MenuItem::Kind kind, Menu & tomenu, LyXView const * view)
                action = LFUN_IMPORT;
                break;
        case MenuItem::ViewFormats:
-               formats = Exporter::GetExportableFormats(view->buffer(), true);
+               formats = Exporter::GetExportableFormats(*view->buffer(), true);
                action = LFUN_PREVIEW;
                break;
        case MenuItem::UpdateFormats:
-               formats = Exporter::GetExportableFormats(view->buffer(), true);
+               formats = Exporter::GetExportableFormats(*view->buffer(), true);
                action = LFUN_UPDATE;
                break;
        default:
-               formats = Exporter::GetExportableFormats(view->buffer(), false);
+               formats = Exporter::GetExportableFormats(*view->buffer(), false);
                action = LFUN_EXPORT;
        }
        sort(formats.begin(), formats.end(), compare_format());
@@ -511,12 +532,14 @@ void expandFloatInsert(Menu & tomenu, LyXView const * view)
 
 Menu::size_type const max_number_of_items = 25;
 
-void expandToc2(Menu & tomenu, toc::Toc const & toc_list,
-               toc::Toc::size_type from, toc::Toc::size_type to, int depth)
+void expandToc2(Menu & tomenu,
+               lyx::toc::Toc const & toc_list,
+               lyx::toc::Toc::size_type from,
+               lyx::toc::Toc::size_type to, int depth)
 {
        int shortcut_count = 0;
        if (to - from <= max_number_of_items) {
-               for (toc::Toc::size_type i = from; i < to; ++i) {
+               for (lyx::toc::Toc::size_type i = from; i < to; ++i) {
                        int const action = toc_list[i].action();
                        string label(4 * max(0, toc_list[i].depth - depth),' ');
                        label += limit_string_length(toc_list[i].str);
@@ -527,9 +550,9 @@ void expandToc2(Menu & tomenu, toc::Toc const & toc_list,
                        tomenu.add(MenuItem(MenuItem::Command, label, action));
                }
        } else {
-               toc::Toc::size_type pos = from;
+               lyx::toc::Toc::size_type pos = from;
                while (pos < to) {
-                       toc::Toc::size_type new_pos = pos + 1;
+                       lyx::toc::Toc::size_type new_pos = pos + 1;
                        while (new_pos < to &&
                               toc_list[new_pos].depth > depth)
                                ++new_pos;
@@ -571,9 +594,9 @@ void expandToc(Menu & tomenu, LyXView const * view)
                return;
        }
 
-       toc::TocList toc_list = toc::getTocList(view->buffer());
-       toc::TocList::const_iterator cit = toc_list.begin();
-       toc::TocList::const_iterator end = toc_list.end();
+       lyx::toc::TocList toc_list = lyx::toc::getTocList(*view->buffer());
+       lyx::toc::TocList::const_iterator cit = toc_list.begin();
+       lyx::toc::TocList::const_iterator end = toc_list.end();
        for (; cit != end; ++cit) {
                // Handle this later
                if (cit->first == "TOC")
@@ -581,8 +604,8 @@ void expandToc(Menu & tomenu, LyXView const * view)
 
                // All the rest is for floats
                Menu * menu = new Menu;
-               toc::Toc::const_iterator ccit = cit->second.begin();
-               toc::Toc::const_iterator eend = cit->second.end();
+               lyx::toc::Toc::const_iterator ccit = cit->second.begin();
+               lyx::toc::Toc::const_iterator eend = cit->second.end();
                for (; ccit != eend; ++ccit) {
                        string const label = limit_string_length(ccit->str);
                        menu->add(MenuItem(MenuItem::Command,
@@ -607,6 +630,47 @@ void expandToc(Menu & tomenu, LyXView const * view)
 }
 
 
+void expandPasteRecent(Menu & tomenu, LyXView const * view)
+{
+       if (!view || !view->buffer())
+               return;
+
+       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));
+       }
+}
+
+
+void expandBranches(Menu & tomenu, LyXView const * view)
+{
+       if (!view || !view->buffer())
+               return;
+
+       BufferParams const & params = view->buffer()->params;
+
+       std::list<Branch>::const_iterator cit = params.branchlist.begin();
+       std::list<Branch>::const_iterator end = params.branchlist.end();
+
+       for (int ii = 1; cit != end; ++cit, ++ii) {
+               string label = cit->getBranch();
+               int const action = lyxaction.
+                       getPseudoAction(LFUN_INSERT_BRANCH,
+                                       (cit->getBranch()));
+               if (ii < 10)
+                       label = tostr(ii) + ". " + label + "|" + tostr(ii);
+               tomenu.add(MenuItem(MenuItem::Command, label, action), view);
+       }
+}
+
+
 } // namespace anon
 
 
@@ -639,6 +703,14 @@ void MenuBackend::expand(Menu const & frommenu, Menu & tomenu,
                        expandFloatInsert(tomenu, view);
                        break;
 
+               case MenuItem::PasteRecent:
+                       expandPasteRecent(tomenu, view);
+                       break;
+
+               case MenuItem::Branches:
+                       expandBranches(tomenu, view);
+                       break;
+
                case MenuItem::Toc:
                        expandToc(tomenu, view);
                        break;
@@ -663,8 +735,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();
 }
 
 
@@ -752,7 +823,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);
 }
 
@@ -762,7 +833,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);
 }