]> git.lyx.org Git - lyx.git/blobdiff - src/MenuBackend.C
Make string conversion work with non-ucs2-characters if using qt 4.2
[lyx.git] / src / MenuBackend.C
index 7397fcee3498a54ecd0cb49966ec03e568491b4d..c2e107f22455c1924a9e824cb3c71fd930d8366b 100644 (file)
@@ -35,6 +35,7 @@
 #include "lyx_main.h" // for lastfiles
 #include "lyxfunc.h"
 #include "lyxlex.h"
+#include "paragraph.h"
 #include "TocBackend.h"
 #include "ToolbarBackend.h"
 
@@ -274,7 +275,7 @@ Menu & Menu::read(LyXLex & lex)
                        // fallback to md_item
                case md_item: {
                        lex.next(true);
-                       docstring const name = _(lex.getString());
+                       docstring const name = translateIfPossible(lex.getDocString());
                        lex.next(true);
                        string const command = lex.getString();
                        FuncRequest func = lyxaction.lookupFunc(command);
@@ -348,9 +349,9 @@ Menu & Menu::read(LyXLex & lex)
                        // fallback to md_submenu
                case md_submenu: {
                        lex.next(true);
-                       docstring const mlabel = _(lex.getString());
+                       docstring const mlabel = translateIfPossible(lex.getDocString());
                        lex.next(true);
-                       docstring const mname = from_utf8(lex.getString());
+                       docstring const mname = lex.getDocString();
                        add(MenuItem(MenuItem::Submenu, mlabel, mname,
                                     optional));
                        optional = false;
@@ -447,10 +448,11 @@ void expandLastfiles(Menu & tomenu)
        int ii = 1;
 
        for (; lfit != lf.end() && ii < 10; ++lfit, ++ii) {
+               string const file = lfit->absFilename();
                docstring const label = convert<docstring>(ii) + ". "
-                       + makeDisplayPath((*lfit), 30)
+                       + makeDisplayPath(file, 30)
                        + char_type('|') + convert<docstring>(ii);
-               tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, (*lfit))));
+               tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_FILE_OPEN, file)));
        }
 }
 
@@ -485,7 +487,7 @@ void expandBookmarks(Menu & tomenu)
        for (size_t i = 1; i <= bm.size(); ++i) {
                if (bm.isValid(i)) {
                        docstring const label = convert<docstring>(i) + ". "
-                               + makeDisplayPath(bm.bookmark(i).filename, 20)
+                               + makeDisplayPath(bm.bookmark(i).filename.absFilename(), 20)
                                + char_type('|') + convert<docstring>(i);
                        tomenu.add(MenuItem(MenuItem::Command, label, FuncRequest(LFUN_BOOKMARK_GOTO, 
                                convert<docstring>(i))));
@@ -633,22 +635,22 @@ void expandCharStyleInsert(Menu & tomenu, Buffer const * buf)
 Menu::size_type const max_number_of_items = 25;
 
 void expandToc2(Menu & tomenu,
-               TocBackend::Toc const & toc_list,
-               TocBackend::Toc::size_type from,
-               TocBackend::Toc::size_type to, int depth)
+               Toc const & toc_list,
+               Toc::size_type from,
+               Toc::size_type to, int depth)
 {
        int shortcut_count = 0;
 
        // check whether depth is smaller than the smallest depth in toc.
        int min_depth = 1000;
-       for (TocBackend::Toc::size_type i = from; i < to; ++i)
+       for (Toc::size_type i = from; i < to; ++i)
                min_depth = std::min(min_depth, toc_list[i].depth());
        if (min_depth > depth)
                depth = min_depth;
 
 
        if (to - from <= max_number_of_items) {
-               for (TocBackend::Toc::size_type i = from; i < to; ++i) {
+               for (Toc::size_type i = from; i < to; ++i) {
                        docstring label(4 * max(0, toc_list[i].depth() - depth), char_type(' '));
                        label += limit_string_length(toc_list[i].str());
                        if (toc_list[i].depth() == depth
@@ -660,9 +662,9 @@ void expandToc2(Menu & tomenu,
                                            FuncRequest(toc_list[i].action())));
                }
        } else {
-               TocBackend::Toc::size_type pos = from;
+               Toc::size_type pos = from;
                while (pos < to) {
-                       TocBackend::Toc::size_type new_pos = pos + 1;
+                       Toc::size_type new_pos = pos + 1;
                        while (new_pos < to &&
                               toc_list[new_pos].depth() > depth)
                                ++new_pos;
@@ -704,10 +706,19 @@ void expandToc(Menu & tomenu, Buffer const * buf)
                return;
        }
 
+       // Add an entry for the master doc if this is a child doc
+       Buffer const * const master = buf->getMasterBuffer();
+       if (buf != master) {
+               ParIterator const pit = par_iterator_begin(master->inset());
+               string const arg = convert<string>(pit->id());
+               FuncRequest f(LFUN_PARAGRAPH_GOTO, arg);
+               tomenu.add(MenuItem(MenuItem::Command, _("Master Document"), f));
+       }
+
        FloatList const & floatlist = buf->params().getLyXTextClass().floats();
-       TocBackend::TocList const & toc_list = buf->tocBackend().tocs();
-       TocBackend::TocList::const_iterator cit = toc_list.begin();
-       TocBackend::TocList::const_iterator end = toc_list.end();
+       TocList const & toc_list = buf->tocBackend().tocs();
+       TocList::const_iterator cit = toc_list.begin();
+       TocList::const_iterator end = toc_list.end();
        for (; cit != end; ++cit) {
                // Handle this later
                if (cit->first == "tableofcontents")
@@ -715,8 +726,8 @@ void expandToc(Menu & tomenu, Buffer const * buf)
 
                // All the rest is for floats
                auto_ptr<Menu> menu(new Menu);
-               TocBackend::Toc::const_iterator ccit = cit->second.begin();
-               TocBackend::Toc::const_iterator eend = cit->second.end();
+               TocIterator ccit = cit->second.begin();
+               TocIterator eend = cit->second.end();
                for (; ccit != eend; ++ccit) {
                        docstring const label = limit_string_length(ccit->str());
                        menu->add(MenuItem(MenuItem::Command,
@@ -768,7 +779,7 @@ void expandToolbars(Menu & tomenu)
 
        for (; cit != end; ++cit) {
                docstring label = _(cit->gui_name);
-               // frontends are not supposed to turn on/off toolbars, if they can not
+               // frontends are not supposed to turn on/off toolbars, if they cannot
                // update ToolbarBackend::flags. That is to say, ToolbarsBackend::flags
                // should reflect the true state of toolbars.
                // 
@@ -929,7 +940,7 @@ void MenuBackend::read(LyXLex & lex)
                        break;
                case md_menu: {
                        lex.next(true);
-                       docstring const name = from_utf8(lex.getString());
+                       docstring const name = lex.getDocString();
                        if (hasMenu(name)) {
                                getMenu(name).read(lex);
                        } else {