Update previews when turned on in prefs (#9507)

Previews are now generated when previews are turned on in
preferences. This change ensures that when users activate previews
for the first time, they are not confused by no previews showing up
(a restart of LyX or a triggering of each individual preview would
be required).

There was a previously attempted fix for #9507 at 390ae054 which was
reverted at 358745d0 for performance reasons: it updated previews
after every preference change and updating previews is costly (even
if the cache signals there are no changes needed).

This implementation is consistent with what we do for updating the
system fonts in preferences.
This commit is contained in:
Scott Kostyshak 2015-11-22 11:39:15 -05:00
parent 19c6a015fb
commit d887b2a5dc
4 changed files with 38 additions and 3 deletions

View File

@ -344,6 +344,15 @@ void BufferList::recordCurrentAuthor(Author const & author)
}
void BufferList::updatePreviews()
{
BufferStorage::iterator it = bstore.begin();
BufferStorage::iterator end = bstore.end();
for (; it != end; ++it)
(*it)->updatePreviews();
}
int BufferList::bufferNum(FileName const & fname) const
{
FileNameList const buffers(fileNames());

View File

@ -115,6 +115,8 @@ public:
//@{
/// reset current author for all buffers
void recordCurrentAuthor(Author const & author);
/// update previews for all buffers, e.g. for Prefs update
void updatePreviews();
/// Call changed() on all buffers, internal or not
void changed(bool update_metrics) const;
/// emergency save for all buffers

View File

@ -1272,10 +1272,16 @@ void PrefDisplay::applyRC(LyXRC & rc) const
rc.preview = LyXRC::PREVIEW_OFF;
break;
case 1:
rc.preview = LyXRC::PREVIEW_NO_MATH;
if (rc.preview != LyXRC::PREVIEW_NO_MATH) {
rc.preview = LyXRC::PREVIEW_NO_MATH;
form_->updatePreviews();
}
break;
case 2:
rc.preview = LyXRC::PREVIEW_ON;
if (rc.preview != LyXRC::PREVIEW_ON) {
rc.preview = LyXRC::PREVIEW_ON;
form_->updatePreviews();
}
break;
}
@ -3205,7 +3211,8 @@ void PrefIdentity::updateRC(LyXRC const & rc)
/////////////////////////////////////////////////////////////////////
GuiPreferences::GuiPreferences(GuiView & lv)
: GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false)
: GuiDialog(lv, "prefs", qt_("Preferences")), update_screen_font_(false),
update_previews_(false)
{
setupUi(this);
@ -3315,6 +3322,7 @@ bool GuiPreferences::initialiseParams(string const &)
movers_ = theMovers();
colors_.clear();
update_screen_font_ = false;
update_previews_ = false;
updateRC(rc_);
// Make sure that the bc is in the INITIAL state
@ -3359,6 +3367,12 @@ void GuiPreferences::dispatchParams()
update_screen_font_ = false;
}
if (update_previews_) {
// resets flag in case second apply in same dialog
theBufferList().updatePreviews();
update_previews_ = false;
}
// The Save button has been pressed
if (isClosing())
dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
@ -3377,6 +3391,12 @@ void GuiPreferences::updateScreenFonts()
}
void GuiPreferences::updatePreviews()
{
update_previews_ = true;
}
QString GuiPreferences::browsebind(QString const & file) const
{
return browseLibFile("bind", file, "bind", qt_("Choose bind file"),

View File

@ -101,6 +101,9 @@ public:
/// update the screen fonts after change
void updateScreenFonts();
/// update the previews after change
void updatePreviews();
LyXRC & rc() { return rc_; }
Converters & converters() { return converters_; }
Formats & formats() { return formats_; }
@ -123,6 +126,7 @@ private:
std::vector<std::string> colors_;
bool update_screen_font_;
bool update_previews_;
};