]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiToolbar.cpp
reduce line noise
[lyx.git] / src / frontends / qt4 / GuiToolbar.cpp
index 9b727beaf78fccf941299997d84e0a79b1cf1e9b..a7e1301a6473ebf1d57942870085002653162a2f 100644 (file)
@@ -23,6 +23,7 @@
 #include "IconPalette.h"
 #include "Layout.h"
 #include "LyXFunc.h"
+#include "TextClass.h"
 #include "ToolbarBackend.h"
 
 #include "GuiView.h"
@@ -32,6 +33,7 @@
 #include "Action.h"
 #include "qt_helpers.h"
 #include "InsertTableWidget.h"
+#include "LyXRC.h"
 
 #include "support/filetools.h"
 #include "support/lstrings.h"
@@ -43,6 +45,8 @@
 #include <QAction>
 #include <QPixmap>
 
+#include <boost/assert.hpp>
+
 
 static void initializeResources()
 {
@@ -157,9 +161,8 @@ string const find_png(string const & name)
                png_name = subst(png_name, "!", "negthinspace");
        }
 
-       LYXERR(Debug::GUI) << "find_png(" << name << ")\n"
-                          << "Looking for math PNG called \""
-                          << png_name << '"' << std::endl;
+       LYXERR(Debug::GUI, "find_png(" << name << ")\n"
+               << "Looking for math PNG called \"" << png_name << '"');
        return png_name;
 }
 
@@ -214,9 +217,9 @@ static QIcon getIcon(FuncRequest const & f, bool unknown)
        if (pm.load(":/images/" + toqstr(path + name2) + ".png"))
                return pm;
 
-       LYXERR(Debug::GUI) << "Cannot find icon for command \""
+       LYXERR(Debug::GUI, "Cannot find icon for command \""
                           << lyxaction.getActionName(f.action)
-                          << '(' << to_utf8(f.argument()) << ")\"" << endl;
+                          << '(' << to_utf8(f.argument()) << ")\"");
        if (unknown)
                pm.load(":/images/unknown.png");
 
@@ -236,7 +239,7 @@ static TextClass const & textClass(LyXView const & lv)
 //
 /////////////////////////////////////////////////////////////////////
 
-GuiLayoutBox::GuiLayoutBox(GuiViewBase & owner)
+GuiLayoutBox::GuiLayoutBox(GuiView & owner)
        : owner_(owner)
 {
        setSizeAdjustPolicy(QComboBox::AdjustToContents);
@@ -271,6 +274,29 @@ void GuiLayoutBox::set(docstring const & layout)
 }
 
 
+void GuiLayoutBox::addItemSort(QString const & item, bool sorted)
+{
+       int const end = count();
+       if (!sorted || end < 2 || item[0].category() != QChar::Letter_Uppercase) {
+               addItem(item);
+               return;
+       }
+
+       // Let the default one be at the beginning
+       int i = 1;
+       for (setCurrentIndex(i); currentText() < item;) {
+               // e.g. --Separator--
+               if (currentText()[0].category() != QChar::Letter_Uppercase)
+                       break;
+               if (++i == end)
+                       break;
+               setCurrentIndex(i);
+       }
+
+       insertItem(i, item);
+}
+
+
 void GuiLayoutBox::updateContents()
 {
        TextClass const & tc = textClass(owner_);
@@ -282,9 +308,11 @@ void GuiLayoutBox::updateContents()
        TextClass::const_iterator const end = tc.end();
        for (; it != end; ++it) {
                // ignore obsolete entries
-               addItem(toqstr(translateIfPossible((*it)->name())));
+               addItemSort(toqstr(translateIfPossible((*it)->name())), lyxrc.sort_layouts);
        }
 
+       setCurrentIndex(0);
+
        // needed to recalculate size hint
        hide();
        setMinimumWidth(sizeHint().width());
@@ -322,7 +350,7 @@ void GuiLayoutBox::selected(const QString & str)
 /////////////////////////////////////////////////////////////////////
 
 
-GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiViewBase & owner)
+GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
        : QToolBar(qt_(tbinfo.gui_name), &owner), owner_(owner),
          layout_(0), command_buffer_(0)
 {