]> git.lyx.org Git - features.git/commitdiff
Fix bug 2739: Option for alphabetical sorting of environments in the toolbar
authorPavel Sanda <sanda@lyx.org>
Sat, 10 Nov 2007 00:21:42 +0000 (00:21 +0000)
committerPavel Sanda <sanda@lyx.org>
Sat, 10 Nov 2007 00:21:42 +0000 (00:21 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21536 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/LyXFunc.cpp
src/LyXRC.cpp
src/LyXRC.h
src/frontends/LyXView.h
src/frontends/WorkArea.cpp
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/GuiToolbar.cpp
src/frontends/qt4/GuiToolbar.h
src/frontends/qt4/GuiToolbars.cpp
src/frontends/qt4/GuiToolbars.h
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiView.h
src/frontends/qt4/GuiWorkArea.cpp
src/frontends/qt4/ui/PrefUi.ui

index baeebe77c374f1cac27aad54f3046ee3b69a4e50..51d5fe591c0efc70c35eac6d0fc3429d414c5586 100644 (file)
@@ -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;
index 70f2233e9da5b30ceb622748fbc77ddd5415144b..7c75f2175da27a87e78d93a41892887c1ac17b0a 100644 (file)
@@ -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<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
                }
        }
@@ -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<string>(sort_layouts) << '\n';
+               }
+               if (tag != RC_LAST)
+                       break;
        case RC_VIEWDVI_PAPEROPTION:
                if (ignore_system_lyxrc ||
                    view_dvi_paper_option
index e5c5958c1b3488b00cf5627862998e50fe84800f..5a2a94bc5fc0d7425898b0cd02b2bad37414960a 100644 (file)
@@ -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;
 };
 
 
index f2dd2c6c1f6cc80a0d16a861ca44116c7251a85b..29508f2ef3ed14eb52614215fa0cf4446e2b4c49 100644 (file)
@@ -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;
index 06f22e096bdc59387a723d93cde962a013034167..c791877ac660344abfd853aae49a7e030077958b 100644 (file)
@@ -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);
 }
 
index 5c6fdcee6e1079259ba90a2131dc4e1f87360bc6..ed6343cf9149111b4c9245fa3f2681127420a9f7 100644 (file)
@@ -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)
index 28884b0f1e09ed82f302255a4a3fc854832f8c47..23715a0a3ae71cca9a7d534ac1fad51ddd4fea41 100644 (file)
@@ -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());
index 4657424105727a60d2c2c5214938d6b3c2cda4c4..ee5476b9c0e34d28d0a2b7bff11876bc41085034 100644 (file)
@@ -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);
index d368b57e843539567104a7341b9b2b33886c22e5..4a403d586fad4bcebc2e39dc24833dc30051e318 100644 (file)
@@ -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;
index 090c2f6d8a2fc4c20b3cafc1bed8d6c5f3ad9767..d7fc02fdc828ebec2c43f6e4ccd153114cf7539b 100644 (file)
@@ -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();
index f57c564427d18a8bcc68240ead7641bf06f2f86d..65175f56fa5498e27df3cdf3b5ce5618df4ce543 100644 (file)
@@ -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();
        }
 
index 27933e952197bffbacfa10eddac1b4309c4998a4..125e446374f1a6ee9e2588580fa13e5e5ca2cc38 100644 (file)
@@ -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);
index 4e6eaf160a0e2c37a13764497f4cfe6bf787f893..a6206460bf2adb4c726d925f0366c6c1109640b9 100644 (file)
@@ -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();
index 7df98c6a49cc3a11b98ec2a9ea015a5534cbc68d..d8cc082e47a7ab8266091e0e2eef77c6eab89c11 100644 (file)
    <item row="3" column="0" colspan="3" >
     <widget class="QGroupBox" name="scrollGB" >
      <property name="title" >
-      <string>Scrolling</string>
+      <string>Editing</string>
      </property>
      <property name="alignment" >
       <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
         </property>
        </widget>
       </item>
+      <item row="1" column="0" >
+       <widget class="QCheckBox" name="sortEnvironmentsCB" >
+        <property name="text" >
+         <string>Sort &amp;Environments alphabetically</string>
+        </property>
+       </widget>
+      </item>
      </layout>
     </widget>
    </item>