> Looks good. A few comments below. updated patch attached.
> > +void GuiLayoutBox::addSortItem(QString const & item, bool sorted) > > The name is strange. I'd rather keep addItem if possible, or > addSortedItem or addItemSort. (this is a minor complaint...) changed to addItemSort. > > + //set standard as default > > + setCurrentIndex(0); > > I am not sure what you mean by this comment. do you mean "the default > layout" instead of "standard"? i meant setting the active layout to the first one obtained by TextClass iterator, which is by accident 'Standard' in all cases i've seen up to now. changed. > > + { "\\layouts_sorted", LyXRC::RC_LAYOUTS_SORTED }, > > To be more in line with other LyXRC entries, I'd really prefer \sort_layouts. changed. pavel
diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 2471363..f29782e 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -1947,6 +1947,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd) actOnUpdatedPrefs(lyxrc_orig, lyxrc); + if (lyx_view_ && lyx_view_->buffer()) + lyx_view_->updateLayoutChoice(true); + /// We force the redraw in any case because there might be /// some screen font changes. /// FIXME: only the current view will be updated. the Gui @@ -2032,7 +2035,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) theSelection().haveSelection(view()->cursor().selection()); if (view()->cursor().inTexted()) { - lyx_view_->updateLayoutChoice(); + lyx_view_->updateLayoutChoice(false); } } } @@ -2522,6 +2525,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) case LyXRC::RC_USE_PERS_DICT: case LyXRC::RC_USE_SPELL_LIB: case LyXRC::RC_VIEWDVI_PAPEROPTION: + case LyXRC::RC_SORT_LAYOUTS: case LyXRC::RC_VIEWER: case LyXRC::RC_LAST: break; diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index 698a8f2..1554b8d 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -107,6 +107,7 @@ keyword_item lyxrcTags[] = { { "\\language_global_options", LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS }, { "\\language_package", LyXRC::RC_LANGUAGE_PACKAGE }, { "\\language_use_babel", LyXRC::RC_LANGUAGE_USE_BABEL }, + { "\\sort_layouts", LyXRC::RC_SORT_LAYOUTS }, { "\\load_session", LyXRC::RC_LOADSESSION }, { "\\make_backup", LyXRC::RC_MAKE_BACKUP }, { "\\mark_foreign_language", LyXRC::RC_MARK_FOREIGN_LANGUAGE }, @@ -268,6 +269,7 @@ void LyXRC::setDefaults() { language_package = "\\usepackage{babel}"; language_command_begin = "\\selectlanguage{$$lang}"; language_command_local = "\\foreignlanguage{$$lang}{"; + sort_layouts = false; default_language = "english"; show_banner = true; windows_style_tex_paths = false; @@ -1171,6 +1173,11 @@ int LyXRC::read(Lexer & lexrc) convert<unsigned int>(lexrc.getString()); break; + case RC_SORT_LAYOUTS: + if (lexrc.next()) + sort_layouts = lexrc.getBool(); + break; + case RC_LAST: break; // this is just a dummy } } @@ -1332,7 +1339,14 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c } if (tag != RC_LAST) break; - + case RC_SORT_LAYOUTS: + if (ignore_system_lyxrc || + sort_layouts != system_lyxrc.sort_layouts) { + os << "# Sort layouts alphabetically.\n" + << "\\sort_layouts " << convert<string>(sort_layouts) << '\n'; + } + if (tag != RC_LAST) + break; case RC_VIEWDVI_PAPEROPTION: if (ignore_system_lyxrc || view_dvi_paper_option diff --git a/src/LyXRC.h b/src/LyXRC.h index 877c3d9..03f6e85 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -81,6 +81,7 @@ public: RC_LANGUAGE_GLOBAL_OPTIONS, RC_LANGUAGE_PACKAGE, RC_LANGUAGE_USE_BABEL, + RC_SORT_LAYOUTS, RC_USELASTFILEPOS, RC_LOADSESSION, RC_MAKE_BACKUP, @@ -373,6 +374,8 @@ public: bool use_converter_cache; /// The maximum age of cache files in seconds unsigned int converter_cache_maxage; + /// Sort layouts alphabetically + bool sort_layouts; }; diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index 30443e1..cc7d713 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -141,7 +141,7 @@ public: void setBuffer(Buffer * b); ///< \c Buffer to set. /// updates the possible layouts selectable - virtual void updateLayoutChoice() = 0; + virtual void updateLayoutChoice(bool force) = 0; /// update the toolbar virtual void updateToolbars() = 0; diff --git a/src/frontends/WorkArea.cpp b/src/frontends/WorkArea.cpp index 86a4d93..59f41fd 100644 --- a/src/frontends/WorkArea.cpp +++ b/src/frontends/WorkArea.cpp @@ -207,7 +207,7 @@ void WorkArea::dispatch(FuncRequest const & cmd0, KeyModifier mod) // Skip these when selecting if (cmd.action != LFUN_MOUSE_MOTION) { - lyx_view_->updateLayoutChoice(); + lyx_view_->updateLayoutChoice(false); lyx_view_->updateToolbars(); } @@ -231,7 +231,7 @@ void WorkArea::resizeBufferView() // We are already inside a paint event. lyx_view_->busy(true); buffer_view_->resize(width(), height()); - lyx_view_->updateLayoutChoice(); + lyx_view_->updateLayoutChoice(false); lyx_view_->busy(false); } diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 40b82c1..85a2a19 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -1614,6 +1614,8 @@ PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent) this, SIGNAL(changed())); connect(cursorFollowsCB, SIGNAL(clicked()), this, SIGNAL(changed())); + connect(sortEnvironmentsCB, SIGNAL(clicked()), + this, SIGNAL(changed())); connect(autoSaveSB, SIGNAL(valueChanged(int)), this, SIGNAL(changed())); connect(autoSaveCB, SIGNAL(clicked()), @@ -1638,6 +1640,7 @@ void PrefUserInterface::apply(LyXRC & rc) const } rc.geometry_xysaved = loadWindowLocationCB->isChecked(); rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked(); + rc.sort_layouts = sortEnvironmentsCB->isChecked(); rc.autosave = autoSaveSB->value() * 60; rc.make_backup = autoSaveCB->isChecked(); rc.num_lastfiles = lastfilesSB->value(); @@ -1657,6 +1660,7 @@ void PrefUserInterface::update(LyXRC const & rc) } loadWindowLocationCB->setChecked(rc.geometry_xysaved); cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar); + sortEnvironmentsCB->setChecked(rc.sort_layouts); // convert to minutes int mins(rc.autosave / 60); if (rc.autosave && !mins) diff --git a/src/frontends/qt4/GuiToolbar.cpp b/src/frontends/qt4/GuiToolbar.cpp index 9b727be..5889509 100644 --- a/src/frontends/qt4/GuiToolbar.cpp +++ b/src/frontends/qt4/GuiToolbar.cpp @@ -32,6 +32,7 @@ #include "Action.h" #include "qt_helpers.h" #include "InsertTableWidget.h" +#include "LyXRC.h" #include "support/filetools.h" #include "support/lstrings.h" @@ -271,6 +272,28 @@ void GuiLayoutBox::set(docstring const & layout) } +void GuiLayoutBox::addItemSort(QString const & item, bool sorted) +{ + int end = count(); + int i = 1; //Let the default one be at the beginning + + if (!sorted || end<2 || !(item[0].category() == QChar::Letter_Uppercase)) { + addItem(item); + return; + } + + for (setCurrentIndex(i); currentText() < item; ) { + if (! (currentText()[0].category() == QChar::Letter_Uppercase)) + break; //e.g. --Separator-- + if (++i == end) + break; + setCurrentIndex(i); + } + + insertItem(i, item); +} + + void GuiLayoutBox::updateContents() { TextClass const & tc = textClass(owner_); @@ -282,9 +305,12 @@ 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); } + //set default + setCurrentIndex(0); + // needed to recalculate size hint hide(); setMinimumWidth(sizeHint().width()); diff --git a/src/frontends/qt4/GuiToolbar.h b/src/frontends/qt4/GuiToolbar.h index ca4703c..b085e4d 100644 --- a/src/frontends/qt4/GuiToolbar.h +++ b/src/frontends/qt4/GuiToolbar.h @@ -43,6 +43,8 @@ public: void set(docstring const & layout); /// Populate the layout combobox. void updateContents(); + /// Add Item to Layout box according to sorting settings from preferences + void addItemSort(QString const & item, bool sorted); private Q_SLOTS: void selected(const QString & str); diff --git a/src/frontends/qt4/GuiToolbars.cpp b/src/frontends/qt4/GuiToolbars.cpp index c2c26cf..a5671db 100644 --- a/src/frontends/qt4/GuiToolbars.cpp +++ b/src/frontends/qt4/GuiToolbars.cpp @@ -291,10 +291,10 @@ void GuiToolbars::setLayout(docstring const & layout) } -bool GuiToolbars::updateLayoutList(TextClassPtr textclass) +bool GuiToolbars::updateLayoutList(TextClassPtr textclass, bool force) { // update the layout display - if (last_textclass_ != textclass) { + if (last_textclass_ != textclass || force) { if (layout_) layout_->updateContents(); last_textclass_ = textclass; diff --git a/src/frontends/qt4/GuiToolbars.h b/src/frontends/qt4/GuiToolbars.h index af9c4b9..78d91b4 100644 --- a/src/frontends/qt4/GuiToolbars.h +++ b/src/frontends/qt4/GuiToolbars.h @@ -63,7 +63,7 @@ public: /** Populate the layout combox - returns whether we did a full * update or not */ - bool updateLayoutList(TextClassPtr textclass); + bool updateLayoutList(TextClassPtr textclass, bool force); /// Drop down the layout list. void openLayoutList(); diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 703fb2c..edf9c3f 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -610,7 +610,7 @@ void GuiViewBase::on_currentWorkAreaChanged(GuiWorkArea * wa) // require bv_->text. getDialogs().updateBufferDependent(true); updateToolbars(); - updateLayoutChoice(); + updateLayoutChoice(false); updateWindowTitle(); updateStatusBar(); } @@ -887,7 +887,7 @@ void GuiViewBase::openLayoutList() } -void GuiViewBase::updateLayoutChoice() +void GuiViewBase::updateLayoutChoice(bool force) { // Don't show any layouts without a buffer if (!buffer()) { @@ -896,7 +896,7 @@ void GuiViewBase::updateLayoutChoice() } // Update the layout display - if (d.toolbars_->updateLayoutList(buffer()->params().getTextClassPtr())) { + if (d.toolbars_->updateLayoutList(buffer()->params().getTextClassPtr(),force)) { d.current_layout = buffer()->params().getTextClass().defaultLayoutName(); } diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 0b429e1..319507a 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -76,7 +76,7 @@ public: void showMiniBuffer(bool); void openMenu(docstring const &); void openLayoutList(); - void updateLayoutChoice(); + void updateLayoutChoice(bool force); bool isToolbarVisible(std::string const & id); void updateToolbars(); ToolbarInfo * getToolbarInfo(std::string const & name); diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 9c99508..de59eb8 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -257,7 +257,7 @@ void GuiWorkArea::adjustViewWithScrollBar(int action) if (lyxrc.cursor_follows_scrollbar) { buffer_view_->setCursorFromScrollbar(); - lyx_view_->updateLayoutChoice(); + lyx_view_->updateLayoutChoice(false); } // Show the cursor immediately after any operation. startBlinkingCursor(); diff --git a/src/frontends/qt4/ui/PrefUi.ui b/src/frontends/qt4/ui/PrefUi.ui index 4edfe17..8f86387 100644 --- a/src/frontends/qt4/ui/PrefUi.ui +++ b/src/frontends/qt4/ui/PrefUi.ui @@ -6,13 +6,13 @@ <x>0</x> <y>0</y> <width>398</width> - <height>418</height> + <height>492</height> </rect> </property> <property name="sizePolicy" > <sizepolicy> - <hsizetype>1</hsizetype> - <vsizetype>1</vsizetype> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> @@ -43,7 +43,7 @@ <item row="4" column="0" colspan="3" > <widget class="QGroupBox" name="scrollGB" > <property name="title" > - <string>Scrolling</string> + <string>Editing options</string> </property> <property name="alignment" > <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> @@ -65,6 +65,16 @@ </property> </widget> </item> + <item row="1" column="0" > + <widget class="QCheckBox" name="sortEnvironmentsCB" > + <property name="toolTip" > + <string>Alphabetically</string> + </property> + <property name="text" > + <string>&Sort Environments alphabetically</string> + </property> + </widget> + </item> </layout> </widget> </item> @@ -187,8 +197,8 @@ <widget class="QGroupBox" name="GeometryGB" > <property name="sizePolicy" > <sizepolicy> - <hsizetype>5</hsizetype> - <vsizetype>5</vsizetype> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy>