From 87bd0e79ad5fdbac1ee254601d28eb7cc5511a2b Mon Sep 17 00:00:00 2001 From: Pavel Sanda Date: Sat, 10 Nov 2007 00:21:42 +0000 Subject: [PATCH] Fix bug 2739: Option for alphabetical sorting of environments in the toolbar git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21536 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyXFunc.cpp | 6 +++++- src/LyXRC.cpp | 16 +++++++++++++++- src/LyXRC.h | 3 +++ src/frontends/LyXView.h | 2 +- src/frontends/WorkArea.cpp | 4 ++-- src/frontends/qt4/GuiPrefs.cpp | 4 ++++ src/frontends/qt4/GuiToolbar.cpp | 28 +++++++++++++++++++++++++++- src/frontends/qt4/GuiToolbar.h | 2 ++ src/frontends/qt4/GuiToolbars.cpp | 4 ++-- src/frontends/qt4/GuiToolbars.h | 2 +- src/frontends/qt4/GuiView.cpp | 6 +++--- src/frontends/qt4/GuiView.h | 2 +- src/frontends/qt4/GuiWorkArea.cpp | 2 +- src/frontends/qt4/ui/PrefUi.ui | 9 ++++++++- 14 files changed, 75 insertions(+), 15 deletions(-) diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index baeebe77c3..51d5fe591c 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -2013,6 +2013,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 @@ -2098,7 +2101,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) theSelection().haveSelection(view()->cursor().selection()); if (view()->cursor().inTexted()) { - lyx_view_->updateLayoutChoice(); + lyx_view_->updateLayoutChoice(false); } } } @@ -2587,6 +2590,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) case LyXRC::RC_USE_PIXMAP_CACHE: 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 70f2233e9d..7c75f2175d 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 }, @@ -269,6 +270,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; @@ -1178,6 +1180,11 @@ int LyXRC::read(Lexer & lexrc) convert(lexrc.getString()); break; + case RC_SORT_LAYOUTS: + if (lexrc.next()) + sort_layouts = lexrc.getBool(); + break; + case RC_LAST: break; // this is just a dummy } } @@ -1340,7 +1347,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(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 e5c5958c1b..5a2a94bc5f 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -79,6 +79,7 @@ public: RC_LANGUAGE_GLOBAL_OPTIONS, RC_LANGUAGE_PACKAGE, RC_LANGUAGE_USE_BABEL, + RC_SORT_LAYOUTS, RC_USELASTFILEPOS, RC_LOADSESSION, RC_MAKE_BACKUP, @@ -375,6 +376,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 f2dd2c6c1f..29508f2ef3 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 06f22e096b..c791877ac6 100644 --- a/src/frontends/WorkArea.cpp +++ b/src/frontends/WorkArea.cpp @@ -206,7 +206,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(); } @@ -230,7 +230,7 @@ void WorkArea::resizeBufferView() // We are already inside a paint event. lyx_view_->setBusy(true); buffer_view_->resize(width(), height()); - lyx_view_->updateLayoutChoice(); + lyx_view_->updateLayoutChoice(false); lyx_view_->setBusy(false); } diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 5c6fdcee6e..ed6343cf91 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -1619,6 +1619,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()), @@ -1645,6 +1647,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(); @@ -1665,6 +1668,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 28884b0f1e..23715a0a3a 100644 --- a/src/frontends/qt4/GuiToolbar.cpp +++ b/src/frontends/qt4/GuiToolbar.cpp @@ -33,6 +33,7 @@ #include "Action.h" #include "qt_helpers.h" #include "InsertTableWidget.h" +#include "LyXRC.h" #include "support/filetools.h" #include "support/lstrings.h" @@ -274,6 +275,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_); @@ -285,9 +309,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()); diff --git a/src/frontends/qt4/GuiToolbar.h b/src/frontends/qt4/GuiToolbar.h index 4657424105..ee5476b9c0 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 d368b57e84..4a403d586f 100644 --- a/src/frontends/qt4/GuiToolbars.cpp +++ b/src/frontends/qt4/GuiToolbars.cpp @@ -295,10 +295,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 090c2f6d8a..d7fc02fdc8 100644 --- a/src/frontends/qt4/GuiToolbars.h +++ b/src/frontends/qt4/GuiToolbars.h @@ -65,7 +65,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 f57c564427..65175f56fa 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -611,7 +611,7 @@ void GuiView::on_currentWorkAreaChanged(GuiWorkArea * wa) // require bv_->text. getDialogs().updateBufferDependent(true); updateToolbars(); - updateLayoutChoice(); + updateLayoutChoice(false); updateWindowTitle(); updateStatusBar(); } @@ -888,7 +888,7 @@ void GuiView::openLayoutList() } -void GuiView::updateLayoutChoice() +void GuiView::updateLayoutChoice(bool force) { // Don't show any layouts without a buffer if (!buffer()) { @@ -897,7 +897,7 @@ void GuiView::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 27933e9521..125e446374 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 4e6eaf160a..a6206460bf 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -256,7 +256,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 7df98c6a49..d8cc082e47 100644 --- a/src/frontends/qt4/ui/PrefUi.ui +++ b/src/frontends/qt4/ui/PrefUi.ui @@ -315,7 +315,7 @@ - Scrolling + Editing Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop @@ -337,6 +337,13 @@ + + + + Sort &Environments alphabetically + + +