+void Menu::checkShortcuts() const
+{
+ // This is a quadratic algorithm, but we do not care because
+ // it is used for debugging only.
+ for (const_iterator it1 = begin(); it1 != end(); ++it1) {
+ string shortcut = it1->shortcut();
+ if (shortcut.empty())
+ continue;
+ if (!contains(it1->label(), shortcut))
+ lyxerr << "Menu warning: menu entry \""
+ << it1->label()
+ << "\" does not contain shortcut `"
+ << shortcut << '\'' << endl;
+ for (const_iterator it2 = begin(); it2 != it1 ; ++it2) {
+ if (!compare_no_case(it2->shortcut(), shortcut)) {
+ lyxerr << "Menu warning: menu entries "
+ << '"' << it1->fulllabel()
+ << "\" and \"" << it2->fulllabel()
+ << "\" share the same shortcut."
+ << endl;
+ }
+ }
+ }
+}
+
+
+namespace {
+
+class compare_format {
+public:
+ bool operator()(Format const * p1, Format const * p2) {
+ return *p1 < *p2;
+ }
+};
+
+} // namespace anon
+
+
+void Menu::expand(Menu & tomenu, Buffer * buf) const
+{
+ for (const_iterator cit = begin();
+ cit != end() ; ++cit) {
+ switch (cit->kind()) {
+ case MenuItem::Lastfiles: {
+ int ii = 1;
+ LastFiles::const_iterator lfit = lastfiles->begin();
+ LastFiles::const_iterator end = lastfiles->end();
+
+ for (; lfit != end && ii < 10; ++lfit, ++ii) {
+ string const label = tostr(ii) + ". "
+ + MakeDisplayPath((*lfit), 30)
+ + '|' + tostr(ii);
+ int const action = lyxaction.
+ getPseudoAction(LFUN_FILE_OPEN,
+ (*lfit));
+ tomenu.add(MenuItem(MenuItem::Command,
+ label, action));
+ }
+ }
+ break;
+
+ case MenuItem::Documents: {
+ typedef vector<string> Strings;
+
+ Strings const names = bufferlist.getFileNames();
+
+ if (names.empty()) {
+ tomenu.add(MenuItem(MenuItem::Command,
+ _("No Documents Open!"),
+ LFUN_NOACTION));
+ break;
+ }
+
+ Strings::const_iterator docit = names.begin();
+ Strings::const_iterator end = names.end();
+ for (; docit != end ; ++docit) {
+ int const action = lyxaction
+ .getPseudoAction(LFUN_SWITCHBUFFER,
+ *docit);
+ string const label =
+ MakeDisplayPath(*docit, 30);
+ tomenu.add(MenuItem(MenuItem::Command,
+ label, action));
+ }
+ }
+ break;
+
+ case MenuItem::ImportFormats:
+ case MenuItem::ViewFormats:
+ case MenuItem::UpdateFormats:
+ case MenuItem::ExportFormats: {
+
+ if (!buf && cit->kind() != MenuItem::ImportFormats) {
+ tomenu.add(MenuItem(MenuItem::Command,
+ _("No Documents Open!"),
+ LFUN_NOACTION));
+ continue;
+ }
+
+ typedef vector<Format const *> Formats;
+
+ Formats formats;
+
+ kb_action action;
+ switch (cit->kind()) {
+ case MenuItem::ImportFormats:
+ formats = Importer::GetImportableFormats();
+ action = LFUN_IMPORT;
+ break;
+ case MenuItem::ViewFormats:
+ formats = Exporter::GetExportableFormats(buf, true);
+ action = LFUN_PREVIEW;
+ break;
+ case MenuItem::UpdateFormats:
+ formats = Exporter::GetExportableFormats(buf, true);
+ action = LFUN_UPDATE;
+ break;
+ default:
+ formats = Exporter::GetExportableFormats(buf, false);
+ action = LFUN_EXPORT;
+ }
+ sort(formats.begin(), formats.end(), compare_format());
+
+ Formats::const_iterator fit = formats.begin();
+ Formats::const_iterator end = formats.end();
+
+ for (; fit != end ; ++fit) {
+ if ((*fit)->dummy())
+ continue;
+ string label = (*fit)->prettyname();
+ // we need to hide the default graphic export
+ // formats from the external menu, because we
+ // need them only for the internal lyx-view and
+ // external latex run
+ if (label == "EPS" ||
+ label == "XPM" ||
+ label == "PNG")
+ continue;
+
+ if (cit->kind() == MenuItem::ImportFormats)
+ if ((*fit)->name() == "text")
+ label = _("Ascii text as lines");
+ else if ((*fit)->name() == "textparagraph")
+ label = _("Ascii text as paragraphs");
+ if (!(*fit)->shortcut().empty())
+ label += "|" + (*fit)->shortcut();
+ int const action2 = lyxaction.
+ getPseudoAction(action,
+ (*fit)->name());
+ tomenu.add(MenuItem(MenuItem::Command,
+ label, action2));
+ }
+ }
+ break;
+
+ case MenuItem::FloatListInsert:
+ {
+ FloatList::const_iterator cit = floatList.begin();
+ FloatList::const_iterator end = floatList.end();
+ for (; cit != end; ++cit) {
+ int const action = lyxaction
+ .getPseudoAction(LFUN_FLOAT_LIST,
+ cit->second.type());
+ tomenu.add(MenuItem(MenuItem::Command,
+ _(cit->second.listName()),
+ action));
+ }
+ }
+ break;
+
+ case MenuItem::FloatInsert:
+ {
+ FloatList::const_iterator cit = floatList.begin();
+ FloatList::const_iterator end = floatList.end();
+ for (; cit != end; ++cit) {
+ // normal float
+ int const action = lyxaction
+ .getPseudoAction(LFUN_INSET_FLOAT,
+ cit->second.type());
+ string const label = _(cit->second.name());
+ tomenu.add(MenuItem(MenuItem::Command,
+ label, action));
+
+ // and the wide version
+ int const action2 = lyxaction
+ .getPseudoAction(LFUN_INSET_WIDE_FLOAT,
+ cit->second.type());
+ string const label2 = label + _(" (wide)");
+ tomenu.add(MenuItem(MenuItem::Command,
+ label2, action2));
+ }
+ }
+ break;
+
+ default:
+ tomenu.add(*cit);
+ }
+ }
+
+ // Check whether the shortcuts are unique
+ if (lyxerr.debugging(Debug::GUI))
+ checkShortcuts();
+}
+
+
+bool Menu::hasSubmenu(string const & name) const
+{
+ return find_if(begin(), end(),
+ lyx::compare_memfun(&MenuItem::submenu, name)) != end();
+}
+
+