]> git.lyx.org Git - features.git/commitdiff
Factorize out some code between TocModel.cpp and Menus.cpp.
authorAbdelrazak Younes <younes@lyx.org>
Fri, 16 May 2008 13:49:49 +0000 (13:49 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Fri, 16 May 2008 13:49:49 +0000 (13:49 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24801 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/Menus.cpp
src/frontends/qt4/TocModel.cpp
src/frontends/qt4/TocModel.h
src/frontends/qt4/qt_helpers.cpp
src/frontends/qt4/qt_helpers.h

index a75ebc252ab871b23b154176688504063aad78d3..1217dfb043fecfff0127aa99c778874057a55100 100644 (file)
@@ -951,45 +951,13 @@ void MenuDefinition::expandToc(Buffer const * buf)
                if (cit->first == "tableofcontents")
                        continue;
 
-               string const & floatName = floatlist.getType(cit->first).listName();
-               QString label;
-               bool in_other_list = true;
-               if (!floatName.empty()) {
-                       label = qt_(floatName);
-                       in_other_list = false;
-               }
-               else if (cit->first == "child") {
-                       label = qt_("Child Documents");
-                       in_other_list = false;
-               } else if (cit->first == "graphics")
-                       label = qt_("List of Graphics");
-               else if (cit->first == "equation")
-                       label = qt_("List of Equations");
-               else if (cit->first == "index")
-                       label = qt_("List of Indexes");
-               else if (cit->first == "listing") {
+               if (cit->first == "listing") {
                        // FIXME: the listing navigate menu causes a crash for unknown
                        // reason. See http://bugzilla.lyx.org/show_bug.cgi?id=4613
-                       // This is a temporary fix:
-                       //label = qt_("List of Listings");
                        continue;
                }
-               else if (cit->first == "marginalnote")
-                       label = qt_("List of Marginal notes");
-               else if (cit->first == "note")
-                       label = qt_("List of Notes");
-               else if (cit->first == "footnote")
-                       label = qt_("List of Footnotes");
-               else if (cit->first == "label")
-                       label = qt_("Labels and References");
-               else if (cit->first == "citation")
-                       label = qt_("List of Citations");
-               else
-                       // This should not happen unless the entry is missing above.
-                       label = qt_("Other floats: ") + toqstr(cit->first);
 
                MenuDefinition submenu;
-
                if (cit->second.size() >= 30) {
                        FuncRequest f(LFUN_DIALOG_SHOW, "toc " + cit->first);
                        submenu.add(MenuItem(MenuItem::Command, qt_("Open Navigator..."), f));
@@ -997,20 +965,20 @@ void MenuDefinition::expandToc(Buffer const * buf)
                        TocIterator ccit = cit->second.begin();
                        TocIterator eend = cit->second.end();
                        for (; ccit != eend; ++ccit) {
-                               QString const label = limitStringLength(ccit->str());
-                               submenu.add(MenuItem(MenuItem::Command, label,
+                               submenu.add(MenuItem(MenuItem::Command,
+                                       limitStringLength(ccit->str()),
                                        FuncRequest(ccit->action())));
                        }
                }
 
-               MenuItem item(MenuItem::Submenu, label);
+               MenuItem item(MenuItem::Submenu, guiName(cit->first, buf->params()));
                item.setSubmenu(submenu);
-               if (in_other_list)
-                       other_lists.add(item);
-               else {
+               if (floatlist.typeExist(cit->first) || cit->first == "child") {
+                       // Those two types deserve to be in the main menu.
                        item.setSubmenu(submenu);
                        add(item);
-               }
+               } else
+                       other_lists.add(item);
        }
        if (!other_lists.empty()) {
                MenuItem item(MenuItem::Submenu, qt_("Other Lists"));
@@ -1018,16 +986,14 @@ void MenuDefinition::expandToc(Buffer const * buf)
                add(item);
        }
 
-
        // Handle normal TOC
        cit = toc_list.find("tableofcontents");
        if (cit == end) {
                addWithStatusCheck(MenuItem(MenuItem::Command,
                                    qt_("No Table of contents"),
                                    FuncRequest()));
-       } else {
+       } else
                expandToc2(cit->second, 0, cit->second.size(), 0);
-       }
 }
 
 
index 6d6198ed718505bcc4710a0d0e90b5affa6724bf..ce23f24dc42489d9b791c50a5dbdfdef0a4a4d0a 100644 (file)
 #include "TocModel.h"
 
 #include "Buffer.h"
-#include "BufferParams.h"
 #include "BufferView.h"
-#include "DocIterator.h"
 #include "Cursor.h"
-#include "FloatList.h"
+#include "DocIterator.h"
 #include "FuncRequest.h"
 #include "LyXFunc.h"
-#include "TextClass.h"
 
 #include "support/convert.h"
 #include "support/debug.h"
@@ -232,39 +229,6 @@ void TocModels::updateBackend() const
 }
 
 
-QString TocModels::guiName(string const & type) const
-{
-       if (type == "tableofcontents")
-               return qt_("Table of Contents");
-       if (type == "child")
-               return qt_("Child Documents");
-       if (type == "graphics")
-               return qt_("List of Graphics");
-       if (type == "equation")
-               return qt_("List of Equations");
-       if (type == "footnote")
-               return qt_("List of Footnotes");
-       if (type == "listing")
-               return qt_("List of Listings");
-       if (type == "index")
-               return qt_("List of Indexes");
-       if (type == "marginalnote")
-               return qt_("List of Marginal notes");
-       if (type == "note")
-               return qt_("List of Notes");
-       if (type == "citation")
-               return qt_("List of Citations");
-       if (type == "label")
-               return qt_("Labels and References");
-
-       FloatList const & floats = bv_->buffer().params().documentClass().floats();
-       if (floats.typeExist(type))
-               return qt_(floats.getType(type).listName());
-
-       return qt_(type);
-}
-
-
 void TocModels::reset(BufferView const * bv)
 {
        bv_ = bv;
@@ -277,7 +241,7 @@ void TocModels::reset(BufferView const * bv)
        TocList::const_iterator end = tocs.end();
        for (; it != end; ++it) {
                types_.push_back(toqstr(it->first));
-               type_names_.push_back(guiName(it->first));
+               type_names_.push_back(guiName(it->first, bv->buffer().params()));
                models_.push_back(new TocModel(it->second));
        }
 }
index 393577e11ac13d9ec415ef46ec8017a4d3558222..2bf4c43282ac4f593b0718666f71f6c0f415714e 100644 (file)
@@ -98,8 +98,6 @@ Q_SIGNALS:
 private:
        ///
        void clear();
-       /// Return the guiname from a given cmdName of the TOC param
-       QString guiName(std::string const & type) const;
        ///
        BufferView const * bv_;
        ///
index 05841fd392183ad2682e0b377cc527a2f6af628d..df24f8870ebe80b7d583d894bbc59df8924dd06f 100644 (file)
 
 #include "frontends/alert.h"
 
+#include "BufferParams.h"
+#include "FloatList.h"
 #include "Language.h"
 #include "Length.h"
+#include "TextClass.h"
 
 #include "support/debug.h"
 #include "support/filetools.h"
@@ -474,4 +477,38 @@ QStringList fileFilters(QString const & desc)
        return list;
 }
 
+
+QString guiName(string const & type, BufferParams const & bp)
+{
+       if (type == "tableofcontents")
+               return qt_("Table of Contents");
+       if (type == "child")
+               return qt_("Child Documents");
+       if (type == "graphics")
+               return qt_("List of Graphics");
+       if (type == "equation")
+               return qt_("List of Equations");
+       if (type == "footnote")
+               return qt_("List of Footnotes");
+       if (type == "listing")
+               return qt_("List of Listings");
+       if (type == "index")
+               return qt_("List of Indexes");
+       if (type == "marginalnote")
+               return qt_("List of Marginal notes");
+       if (type == "note")
+               return qt_("List of Notes");
+       if (type == "citation")
+               return qt_("List of Citations");
+       if (type == "label")
+               return qt_("Labels and References");
+
+       FloatList const & floats = bp.documentClass().floats();
+       if (floats.typeExist(type))
+               return qt_(floats.getType(type).listName());
+
+       return qt_(type);
+}
+
+
 } // namespace lyx
index 66a9235ef287ed61794e6de120aaf2637a542c83..66ec9e6f96958dfcbcc2a6e1fda7f2b6851ebdda 100644 (file)
@@ -32,6 +32,7 @@ namespace lyx {
 
 namespace support { class FileName; }
 
+class BufferParams;
 class LyXErr;
 
 LyXErr & operator<<(LyXErr &, QString const &);
@@ -121,6 +122,10 @@ QString getExtension(QString const & name);
 QString makeAbsPath(QString const & relpath, QString const & base);
 QString changeExtension(QString const & oldname, QString const & ext);
 
+/// \return the display string associated with given type and buffer
+/// parameter.
+QString guiName(std::string const & type, BufferParams const & bp);
+
 } // namespace lyx
 
 #endif // QTHELPERS_H