#include "bufferlist.h"
#include "converter.h"
#include "exporter.h"
+#include "importer.h"
#include "support/filetools.h"
#include "support/lyxfunctional.h"
string const & command, bool optional)
: kind_(kind), label_(label), optional_(optional)
{
- switch(kind) {
+ switch (kind) {
case Separator:
case Documents:
case Lastfiles:
case Toc:
- case References:
case ViewFormats:
case UpdateFormats:
case ExportFormats:
+ case ImportFormats:
break;
case Command:
action_ = lyxaction.LookupFunc(command);
md_documents,
md_endmenu,
md_exportformats,
+ md_importformats,
md_lastfiles,
md_optitem,
- md_references,
md_separator,
md_submenu,
md_toc,
{ "documents", md_documents },
{ "end", md_endmenu },
{ "exportformats", md_exportformats },
+ { "importformats", md_importformats },
{ "item", md_item },
{ "lastfiles", md_lastfiles },
{ "optitem", md_optitem },
- { "references", md_references },
{ "separator", md_separator },
{ "submenu", md_submenu },
{ "toc", md_toc },
bool optional = false;
while (lex.IsOK() && !quit) {
- switch(lex.lex()) {
+ switch (lex.lex()) {
case md_optitem:
optional = true;
// fallback to md_item
add(MenuItem(MenuItem::Toc));
break;
- case md_references:
- add(MenuItem(MenuItem::References));
- break;
-
case md_viewformats:
add(MenuItem(MenuItem::ViewFormats));
break;
add(MenuItem(MenuItem::ExportFormats));
break;
+ case md_importformats:
+ add(MenuItem(MenuItem::ImportFormats));
+ break;
+
case md_submenu: {
lex.next();
string mlabel = _(lex.GetString());
return *this;
}
-struct compare_formatpair {
- bool operator()(FormatPair const & a, FormatPair const & b) {
- return a.format->prettyname < b.format->prettyname;
- }
-};
void Menu::checkShortcuts() const
{
}
}
+class compare_format {
+public:
+ bool operator()(Format const * p1, Format const * p2) {
+ return *p1 < *p2;
+ }
+};
+
void Menu::expand(Menu & tomenu, Buffer * buf) const
{
for (const_iterator cit = begin();
}
break;
+ case MenuItem::ImportFormats:
case MenuItem::ViewFormats:
case MenuItem::UpdateFormats:
case MenuItem::ExportFormats: {
- vector<FormatPair> names;
+ vector<Format const *> formats;
kb_action action;
- if ((*cit).kind() == MenuItem::ViewFormats) {
- names = Exporter::GetViewableFormats(buf);
+ switch ((*cit).kind()) {
+ case MenuItem::ImportFormats:
+ formats = Importer::GetImportableFormats();
+ action = LFUN_IMPORT;
+ break;
+ case MenuItem::ViewFormats:
+ formats = Exporter::GetExportableFormats(buf, true);
action = LFUN_PREVIEW;
- } else if ((*cit).kind() == MenuItem::UpdateFormats) {
- names = Exporter::GetViewableFormats(buf);
+ break;
+ case MenuItem::UpdateFormats:
+ formats = Exporter::GetExportableFormats(buf, true);
action = LFUN_UPDATE;
- } else {
- names = Exporter::GetExportableFormats(buf);
+ break;
+ default:
+ formats = Exporter::GetExportableFormats(buf, false);
action = LFUN_EXPORT;
}
- sort(names.begin(), names.end(), compare_formatpair());
-
- for (vector<FormatPair>::const_iterator fit = names.begin();
- fit != names.end() ; ++fit) {
- string fmt = (*fit).format->name;
- string label = (*fit).format->prettyname;
- bool same_before =
- fit != names.begin() &&
- (*fit).format == (*(fit-1)).format;
- bool same_after =
- fit+1 != names.end() &&
- (*fit).format == (*(fit+1)).format;
- if ((*fit).from &&
- (same_before || same_after)) {
- fmt += ":" + (*fit).from->name;
- string head;
- split((*fit).command, head, ' ');
- label += _(" (using ") + head + ")";
- if (!(*fit).format->shortcut.empty() &&
- !same_before)
- label += "|" + (*fit).format->shortcut;
- } else if (!(*fit).format->shortcut.empty())
- label += "|" + (*fit).format->shortcut;
- int action2 = lyxaction.getPseudoAction(action, fmt);
+ sort(formats.begin(), formats.end(), compare_format());
+
+ for (vector<Format const *>::const_iterator fit = formats.begin();
+ fit != formats.end() ; ++fit) {
+ if ((*fit)->dummy())
+ continue;
+ string label = (*fit)->prettyname();
+ 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 action2 = lyxaction.
+ getPseudoAction(action, (*fit)->name());
tomenu.add(MenuItem(MenuItem::Command,
label, action2));
}
}
break;
-
default:
tomenu.add(*cit);
checkShortcuts();
}
+bool Menu::hasSubmenu(string const & name) const
+{
+ return find_if(begin(), end(),
+ compare_memfun(&MenuItem::submenu, name)) != end();
+}
+
void MenuBackend::read(LyXLex & lex)
{
bool menubar = false;
while (lex.IsOK() && !quit) {
- switch(lex.lex()) {
+ switch (lex.lex()) {
case md_menubar:
menubar = true;
// fallback to md_menu
add(main_nobuffer);
if (lyxerr.debugging(Debug::GUI)) {
- for(const_iterator cit = begin();
+ for (const_iterator cit = begin();
cit != end() ; ++cit)
lyxerr << "Menu name: " << cit->name()
<< ", Menubar: " << cit->menubar()