#include "IconPalette.h"
#include "Layout.h"
#include "LyXFunc.h"
+#include "TextClass.h"
#include "ToolbarBackend.h"
#include "GuiView.h"
#include "Action.h"
#include "qt_helpers.h"
#include "InsertTableWidget.h"
+#include "LyXRC.h"
+#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/lyxalgo.h" // sorted
#include <QAction>
#include <QPixmap>
+#include <boost/assert.hpp>
+
static void initializeResources()
{
static bool initialized = false;
if (!initialized) {
- Q_INIT_RESOURCE(Resources);
+ Q_INIT_RESOURCE(Resources);
initialized = true;
}
}
using std::string;
using std::endl;
+using support::libFileSearch;
using support::subst;
using support::compare;
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;
}
QPixmap pm;
string name1;
string name2;
+ string path;
+ string fullname;
switch (f.action) {
case LFUN_MATH_INSERT:
- if (!f.argument().empty())
- name1 = "math/" + find_png(to_utf8(f.argument()).substr(1));
+ if (!f.argument().empty()) {
+ path = "math/";
+ name1 = find_png(to_utf8(f.argument()).substr(1));
+ }
break;
case LFUN_MATH_DELIM:
case LFUN_MATH_BIGDELIM:
- name1 = "math/" + find_png(to_utf8(f.argument()));
+ path = "math/";
+ name1 = find_png(to_utf8(f.argument()));
+ break;
+ case LFUN_CALL:
+ path = "commands/";
+ name1 = to_utf8(f.argument());
break;
default:
name2 = lyxaction.getActionName(f.action);
name1 = subst(name2 + ' ' + to_utf8(f.argument()), ' ', '_');
}
- if (pm.load(":/images/" + toqstr(name1) + ".png"))
+ fullname = libFileSearch("images/" + path, name1, "png").absFilename();
+ if (pm.load(toqstr(fullname)))
+ return pm;
+
+ fullname = libFileSearch("images/" + path, name2, "png").absFilename();
+ if (pm.load(toqstr(fullname)))
+ return pm;
+
+ if (pm.load(":/images/" + toqstr(path + name1) + ".png"))
return pm;
- if (pm.load(":/images/" + toqstr(name2) + ".png"))
+ 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");
//
/////////////////////////////////////////////////////////////////////
-GuiLayoutBox::GuiLayoutBox(GuiViewBase & owner)
+GuiLayoutBox::GuiLayoutBox(GuiView & owner)
: owner_(owner)
{
setSizeAdjustPolicy(QComboBox::AdjustToContents);
}
+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_);
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());
/////////////////////////////////////////////////////////////////////
-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)
{