#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;
case ImportFormats:
case FloatListInsert:
case FloatInsert:
+ case PasteRecent:
break;
case Command:
action_ = lyxaction.LookupFunc(command);
md_viewformats,
md_floatlistinsert,
md_floatinsert,
+ md_pasterecent,
md_last
};
{ "lastfiles", md_lastfiles },
{ "optitem", md_optitem },
{ "optsubmenu", md_optsubmenu },
+ { "pasterecent", md_pasterecent },
{ "separator", md_separator },
{ "submenu", md_submenu },
{ "toc", md_toc },
add(MenuItem(MenuItem::FloatInsert));
break;
+ case md_pasterecent:
+ add(MenuItem(MenuItem::PasteRecent));
+ break;
+
case md_optsubmenu:
optional = true;
// fallback to md_submenu
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())
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 "
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);
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);
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;
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")
// 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,
}
+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
expandFloatInsert(tomenu, view);
break;
+ case MenuItem::PasteRecent:
+ expandPasteRecent(tomenu, view);
+ break;
+
case MenuItem::Toc:
expandToc(tomenu, view);
break;
tomenu.items_.pop_back();
// Check whether the shortcuts are unique
- if (lyxerr.debugging(Debug::GUI))
- tomenu.checkShortcuts();
+ tomenu.checkShortcuts();
}
}
-void MenuBackend::defaults()
-{
- menulist_.clear();
-
- lyxerr[Debug::GUI] << "MenuBackend::defaults: using default values"
- << endl;
-
- Menu file("file");
- file
- .add(MenuItem(MenuItem::Command, _("New...|N"), "buffer-new"))
- .add(MenuItem(MenuItem::Command, _("Open...|O"), "file-open"))
- .add(MenuItem(MenuItem::Submenu, _("Import|I"), "import"))
- .add(MenuItem(MenuItem::Command, _("Quit|Q"), "lyx-quit"))
- .add(MenuItem(MenuItem::Separator))
- .add(MenuItem(MenuItem::Lastfiles));
- add(file);
-
- Menu import("import");
- import
- .add(MenuItem(MenuItem::Command,
- _("LaTeX...|L"), "buffer-import latex"))
- .add(MenuItem(MenuItem::Command,
- _("LinuxDoc...|L"), "buffer-import linuxdoc"));
- add(import);
-
- Menu edit("edit");
- edit
- .add(MenuItem(MenuItem::Command, _("Cut"), "cut"))
- .add(MenuItem(MenuItem::Command, _("Copy"), "copy"))
- .add(MenuItem(MenuItem::Command, _("Paste"), "paste"))
- .add(MenuItem(MenuItem::Command, _("Emphasize"), "font-emph"));
- add(edit);
-
- Menu documents("documents");
- documents.add(MenuItem(MenuItem::Documents));
- add(documents);
-
- menubar_.add(MenuItem(MenuItem::Submenu, _("File|F"), "file"))
- .add(MenuItem(MenuItem::Submenu, _("Edit|E"), "edit"))
- .add(MenuItem(MenuItem::Submenu,
- _("Documents|D"), "documents"));
-
-}
-
-
void MenuBackend::add(Menu const & menu)
{
menulist_.push_back(menu);
lyx::compare_memfun(&Menu::name, name));
if (cit == end())
lyxerr << "No submenu named " << name << endl;
- lyx::Assert(cit != end());
+ Assert(cit != end());
return (*cit);
}
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);
}