]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/TocModel.cpp
fix completion painting for RTL (inline completion and completion list)
[lyx.git] / src / frontends / qt4 / TocModel.cpp
index 670cb5541dab474d4f626077631397a506db1e10..37254dc9a0ef49568ebbe086552ff824ccc534f8 100644 (file)
 #include "TocModel.h"
 
 #include "Buffer.h"
-#include "BufferParams.h"
 #include "BufferView.h"
 #include "Cursor.h"
-#include "FloatList.h"
+#include "DocIterator.h"
 #include "FuncRequest.h"
 #include "LyXFunc.h"
-#include "ParIterator.h"
-#include "TextClass.h"
 
 #include "support/convert.h"
 #include "support/debug.h"
@@ -204,9 +201,9 @@ QModelIndex TocModels::currentIndex(int type) const
        if (type < 0 || !bv_)
                return QModelIndex();
 
-       ParConstIterator it(bv_->cursor());
-       return models_[type]->modelIndex(bv_->buffer().masterBuffer()->
-               tocBackend().item(fromqstr(types_[type]), it));
+       TocIterator const it = bv_->buffer().masterBuffer()->tocBackend().item(
+               fromqstr(types_[type]), bv_->cursor());
+       return models_[type]->modelIndex(it);
 }
 
 
@@ -219,13 +216,9 @@ void TocModels::goTo(int type, QModelIndex const & index) const
        }
 
        LASSERT(type >= 0 && type < int(models_.size()), /**/);
-
        TocIterator const it = models_[type]->tocIterator(index);
-
        LYXERR(Debug::GUI, "TocModels::goTo " << it->str());
-
-       string const tmp = convert<string>(it->id());
-       dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
+       dispatch(it->action());
 }
 
 
@@ -236,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;
@@ -281,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));
        }
 }
@@ -313,7 +273,12 @@ int TocModels::decodeType(QString const & str) const
                // Default to Outliner.
                new_type = "tableofcontents";
        }
-       return types_.indexOf(new_type);
+       int const type = types_.indexOf(new_type);
+       if (type != -1)
+               return type;
+       // If everything else fails, settle on the table of contents which is
+       // guaranted to exist.
+       return types_.indexOf("tableofcontents");
 }
 
 } // namespace frontend