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
This commit is contained in:
Pavel Sanda 2007-11-10 00:21:42 +00:00
parent 0f9f633968
commit 87bd0e79ad
14 changed files with 75 additions and 15 deletions

View 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;

View 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

View 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;
};

View 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;

View 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);
}

View 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)

View 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());

View 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);

View 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;

View 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();

View 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();
}

View 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);

View 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();

View File

@ -315,7 +315,7 @@
<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>
@ -337,6 +337,13 @@
</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>