hi, one thing which is annoying for me when working with lyx is lenghty locating of a given environement in environment box for certain classes which have many items, even more that i usually use only few of these items.
now i have working skeleton for bug 2739, which introduces two preference options - one for alphabetical sorting and the second which put environment used during the current editation on the top of the envi list. before spending time on some gui coding (which i dont need for myself after all) i would like to get some feedback, whether is this acceptable solution or there is some better way to accomplish that or there is no reason to add this feature into lyx. thanks, pavel
Index: src/LyXRC.h =================================================================== --- src/LyXRC.h (revision 20527) +++ src/LyXRC.h (working copy) @@ -80,6 +80,8 @@ RC_LANGUAGE_GLOBAL_OPTIONS, RC_LANGUAGE_PACKAGE, RC_LANGUAGE_USE_BABEL, + RC_LAYOUTS_SORTED, + RC_LAYOUTS_USED_ON_TOP, RC_USELASTFILEPOS, RC_LOADSESSION, RC_MAKE_BACKUP, @@ -369,6 +371,10 @@ bool use_converter_cache; /// The maximum age of cache files in seconds unsigned int converter_cache_maxage; + /// Sort layouts alphabetically + bool layouts_sorted; + /// Put used layouts on top of the layout list + bool layouts_used_on_top; }; Index: src/frontends/qt4/GuiToolbar.h =================================================================== --- src/frontends/qt4/GuiToolbar.h (revision 20527) +++ src/frontends/qt4/GuiToolbar.h (working copy) @@ -55,6 +55,8 @@ void open(); /// void setEnabled(bool); + /// Add Item to Layout box according to sorting settings from preferences + void addItem(QString const & item, bool sorted); private Q_SLOTS: void selected(const QString & str); Index: src/frontends/qt4/GuiToolbar.cpp =================================================================== --- src/frontends/qt4/GuiToolbar.cpp (revision 20527) +++ src/frontends/qt4/GuiToolbar.cpp (working copy) @@ -31,6 +31,7 @@ #include "Action.h" #include "qt_helpers.h" #include "InsertTableWidget.h" +#include "LyXRC.h" #include "support/filetools.h" #include "support/lstrings.h" @@ -93,10 +94,37 @@ return; } + if (lyxrc.layouts_used_on_top) { + QString sel = combo_->itemText(i); + combo_->removeItem(i); + i=0; + combo_->insertItem(i,sel); + } + combo_->setCurrentIndex(i); } +void GuiLayoutBox::addItem(QString const & item, bool sorted) +{ + int end = combo_->count(); + int i = 1; //Let Standard be at the beginning + + if (!sorted || end<2 || item.contains('-')) { + combo_->addItem(item); + return; + } + + for (combo_->setCurrentIndex(i); combo_->currentText() < item; ) { + if (combo_->currentText().contains('-')) break; //--Separator-- + if (++i == end) break; + combo_->setCurrentIndex(i); + } + + combo_->insertItem(i,item); +} + + void GuiLayoutBox::update() { TextClass const & tc = textClass(owner_); @@ -110,8 +138,11 @@ for (; it != end; ++it) { // ignore obsolete entries if ((*it)->obsoleted_by().empty()) - combo_->addItem(toqstr(translateIfPossible((*it)->name()))); +// combo_->addItem(toqstr(translateIfPossible((*it)->name()))); + addItem(toqstr(translateIfPossible((*it)->name())),/*true*/lyxrc.layouts_sorted); } + //set standard as default + combo_->setCurrentIndex(0); // needed to recalculate size hint combo_->hide(); Index: src/LyXRC.cpp =================================================================== --- src/LyXRC.cpp (revision 20527) +++ src/LyXRC.cpp (working copy) @@ -106,6 +106,8 @@ { "\\language_global_options", LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS }, { "\\language_package", LyXRC::RC_LANGUAGE_PACKAGE }, { "\\language_use_babel", LyXRC::RC_LANGUAGE_USE_BABEL }, + { "\\layouts_sorted", LyXRC::RC_LAYOUTS_SORTED }, + { "\\layouts_used_on_top", LyXRC::RC_LAYOUTS_USED_ON_TOP }, { "\\load_session", LyXRC::RC_LOADSESSION }, { "\\make_backup", LyXRC::RC_MAKE_BACKUP }, { "\\mark_foreign_language", LyXRC::RC_MARK_FOREIGN_LANGUAGE }, @@ -266,6 +268,8 @@ language_package = "\\usepackage{babel}"; language_command_begin = "\\selectlanguage{$$lang}"; language_command_local = "\\foreignlanguage{$$lang}{"; + layouts_sorted = false; + layouts_used_on_top = false; default_language = "english"; show_banner = true; windows_style_tex_paths = false; @@ -1163,6 +1167,16 @@ convert<unsigned int>(lexrc.getString()); break; + case RC_LAYOUTS_SORTED: + if (lexrc.next()) + layouts_sorted = lexrc.getBool(); + break; + + case RC_LAYOUTS_USED_ON_TOP: + if (lexrc.next()) + layouts_used_on_top = lexrc.getBool(); + break; + case RC_LAST: break; // this is just a dummy } } @@ -1294,7 +1308,18 @@ << graphics::displayTranslator().find(display_graphics) << '\n'; } - + case RC_LAYOUTS_SORTED: + if (ignore_system_lyxrc || + layouts_sorted != system_lyxrc.layouts_sorted) { + os << "# Sort layouts alphabetically.\n" + << "\\layouts_sorted " << convert<string>(layouts_sorted) << '\n'; + } + case RC_LAYOUTS_USED_ON_TOP: + if (ignore_system_lyxrc || + layouts_used_on_top != system_lyxrc.layouts_used_on_top) { + os << "# Put used layouts on top of the layout list.\n" + << "\\layouts_used_on_top " << convert<string>(layouts_used_on_top) << '\n'; + } case RC_VIEWDVI_PAPEROPTION: if (ignore_system_lyxrc || view_dvi_paper_option