mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Code cleanup: get rid of RenderPreview::status()
This method is a proxy for LyXRC::preview that forces to forward declare some wrapper around an enum... Instead, two simple static methods previewMath() and previewText() are introduced, that make the code much easier to follow.
This commit is contained in:
parent
8226453684
commit
275b7af75e
11
src/LyXRC.h
11
src/LyXRC.h
@ -560,17 +560,6 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/** \c LyXRC_PreviewStatus is a wrapper for LyXRC::PreviewStatus.
|
||||
* It can be forward-declared and passed as a function argument without
|
||||
* having to expose LyXRC.h.
|
||||
*/
|
||||
class LyXRC_PreviewStatus {
|
||||
LyXRC::PreviewStatus val_;
|
||||
public:
|
||||
LyXRC_PreviewStatus(LyXRC::PreviewStatus val) : val_(val) {}
|
||||
operator LyXRC::PreviewStatus() const { return val_; }
|
||||
};
|
||||
|
||||
void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new);
|
||||
|
||||
///
|
||||
|
@ -542,8 +542,7 @@ static void add_preview_and_start_loading(RenderMonitoredPreview & renderer,
|
||||
{
|
||||
InsetExternalParams const & params = inset.params();
|
||||
|
||||
if (RenderPreview::status() != LyXRC::PREVIEW_OFF &&
|
||||
isPreviewWanted(params)) {
|
||||
if (RenderPreview::previewText() && isPreviewWanted(params)) {
|
||||
renderer.setAbsFile(params.filename);
|
||||
docstring const snippet = latexString(inset);
|
||||
renderer.addPreview(snippet, buffer);
|
||||
@ -577,7 +576,7 @@ void InsetExternal::setParams(InsetExternalParams const & p)
|
||||
|| !lyxrc.display_graphics
|
||||
|| params_.preview_mode == PREVIEW_OFF
|
||||
|| (params_.preview_mode == PREVIEW_INSTANT
|
||||
&& RenderPreview::status() == LyXRC::PREVIEW_OFF)) {
|
||||
&& !RenderPreview::previewText())) {
|
||||
RenderButton * button_ptr = renderer_->asButton();
|
||||
if (!button_ptr) {
|
||||
renderer_.reset(new RenderButton);
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "FuncStatus.h"
|
||||
#include "LaTeXFeatures.h"
|
||||
#include "Lexer.h"
|
||||
#include "LyXRC.h"
|
||||
#include "MetricsInfo.h"
|
||||
#include "OutputParams.h"
|
||||
#include "RenderPreview.h"
|
||||
@ -122,8 +121,7 @@ void InsetIPA::preparePreview(DocIterator const & pos) const
|
||||
|
||||
bool InsetIPA::previewState(BufferView * bv) const
|
||||
{
|
||||
if (!editing(bv) && (RenderPreview::status() == LyXRC::PREVIEW_ON ||
|
||||
RenderPreview::status() == LyXRC::PREVIEW_NO_MATH)) {
|
||||
if (!editing(bv) && RenderPreview::previewText()) {
|
||||
graphics::PreviewImage const * pimage =
|
||||
preview_->getPreviewImage(bv->buffer());
|
||||
return pimage && pimage->image();
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "LayoutFile.h"
|
||||
#include "LayoutModuleList.h"
|
||||
#include "LyX.h"
|
||||
#include "LyXRC.h"
|
||||
#include "Lexer.h"
|
||||
#include "MetricsInfo.h"
|
||||
#include "output_plaintext.h"
|
||||
@ -989,7 +988,7 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
LBUFERR(mi.base.bv);
|
||||
|
||||
bool use_preview = false;
|
||||
if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
|
||||
if (RenderPreview::previewText()) {
|
||||
graphics::PreviewImage const * pimage =
|
||||
preview_->getPreviewImage(mi.base.bv->buffer());
|
||||
use_preview = pimage && pimage->image();
|
||||
@ -1015,7 +1014,7 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
|
||||
LBUFERR(pi.base.bv);
|
||||
|
||||
bool use_preview = false;
|
||||
if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
|
||||
if (RenderPreview::previewText()) {
|
||||
graphics::PreviewImage const * pimage =
|
||||
preview_->getPreviewImage(pi.base.bv->buffer());
|
||||
use_preview = pimage && pimage->image();
|
||||
@ -1094,8 +1093,7 @@ void add_preview(RenderMonitoredPreview & renderer, InsetInclude const & inset,
|
||||
Buffer const & buffer)
|
||||
{
|
||||
InsetCommandParams const & params = inset.params();
|
||||
if (RenderPreview::status() != LyXRC::PREVIEW_OFF &&
|
||||
preview_wanted(params, buffer)) {
|
||||
if (RenderPreview::previewText() && preview_wanted(params, buffer)) {
|
||||
renderer.setAbsFile(includedFileName(buffer, params));
|
||||
docstring const snippet = latexString(inset);
|
||||
renderer.addPreview(snippet, buffer);
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "BufferView.h"
|
||||
#include "Cursor.h"
|
||||
#include "Lexer.h"
|
||||
#include "LyXRC.h"
|
||||
#include "MetricsInfo.h"
|
||||
#include "OutputParams.h"
|
||||
#include "RenderPreview.h"
|
||||
@ -81,8 +80,7 @@ void InsetPreview::preparePreview(DocIterator const & pos) const
|
||||
|
||||
bool InsetPreview::previewState(BufferView * bv) const
|
||||
{
|
||||
if (!editing(bv) && (RenderPreview::status() == LyXRC::PREVIEW_ON ||
|
||||
RenderPreview::status() == LyXRC::PREVIEW_NO_MATH)) {
|
||||
if (!editing(bv) && RenderPreview::previewText()) {
|
||||
graphics::PreviewImage const * pimage =
|
||||
preview_->getPreviewImage(bv->buffer());
|
||||
return pimage && pimage->image();
|
||||
|
@ -39,9 +39,33 @@ using namespace lyx::support;
|
||||
namespace lyx {
|
||||
|
||||
|
||||
LyXRC_PreviewStatus RenderPreview::status()
|
||||
bool RenderPreview::previewText()
|
||||
{
|
||||
return lyxrc.preview;
|
||||
// Use a switch to trigger a warning if the enum is changed.
|
||||
switch(lyxrc.preview) {
|
||||
case LyXRC::PREVIEW_ON:
|
||||
case LyXRC::PREVIEW_NO_MATH:
|
||||
return true;
|
||||
case LyXRC::PREVIEW_OFF:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool RenderPreview::previewMath()
|
||||
{
|
||||
// Use a switch to trigger a warning if the enum is changed.
|
||||
switch(lyxrc.preview) {
|
||||
case LyXRC::PREVIEW_ON:
|
||||
return true;
|
||||
case LyXRC::PREVIEW_NO_MATH:
|
||||
case LyXRC::PREVIEW_OFF:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -171,7 +195,7 @@ void RenderPreview::draw(PainterInfo & pi, int x, int y) const
|
||||
|
||||
void RenderPreview::startLoading(Buffer const & buffer, bool forexport) const
|
||||
{
|
||||
if (!forexport && (status() == LyXRC::PREVIEW_OFF || snippet_.empty()))
|
||||
if (!forexport && (lyxrc.preview == LyXRC::PREVIEW_OFF || snippet_.empty()))
|
||||
return;
|
||||
|
||||
graphics::PreviewLoader * loader = buffer.loader();
|
||||
@ -184,7 +208,7 @@ void RenderPreview::addPreview(docstring const & latex_snippet,
|
||||
Buffer const & buffer,
|
||||
bool ignore_lyxrc)
|
||||
{
|
||||
if (status() == LyXRC::PREVIEW_OFF && !ignore_lyxrc)
|
||||
if (lyxrc.preview == LyXRC::PREVIEW_OFF && !ignore_lyxrc)
|
||||
return;
|
||||
|
||||
graphics::PreviewLoader * loader = buffer.loader();
|
||||
@ -197,7 +221,7 @@ void RenderPreview::addPreview(docstring const & latex_snippet,
|
||||
graphics::PreviewLoader & ploader,
|
||||
bool ignore_lyxrc)
|
||||
{
|
||||
if (status() == LyXRC::PREVIEW_OFF && !ignore_lyxrc)
|
||||
if (lyxrc.preview == LyXRC::PREVIEW_OFF && !ignore_lyxrc)
|
||||
return;
|
||||
|
||||
// FIXME UNICODE
|
||||
|
@ -44,8 +44,10 @@ class PreviewLoader;
|
||||
|
||||
class RenderPreview : public RenderBase, public boost::signals::trackable {
|
||||
public:
|
||||
/// a wrapper for lyxrc.preview
|
||||
static LyXRC_PreviewStatus status();
|
||||
/// Return true if preview is enabled in text (from LyXRC::preview)
|
||||
static bool previewText();
|
||||
/// Return true if preview is enabled in mathed (from LyXRC::preview)
|
||||
static bool previewMath();
|
||||
|
||||
RenderPreview(Inset const *);
|
||||
RenderPreview(RenderPreview const &, Inset const *);
|
||||
|
@ -413,8 +413,8 @@ ColorCode InsetMathHull::standardColor() const
|
||||
|
||||
bool InsetMathHull::previewState(const BufferView *const bv) const
|
||||
{
|
||||
if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON
|
||||
&& type_ != hullRegexp)
|
||||
if (!editing(bv) && RenderPreview::previewMath()
|
||||
&& type_ != hullRegexp)
|
||||
{
|
||||
graphics::PreviewImage const * pimage =
|
||||
preview_->getPreviewImage(bv->buffer());
|
||||
@ -615,7 +615,7 @@ void InsetMathHull::initUnicodeMath() const
|
||||
void InsetMathHull::addPreview(DocIterator const & inset_pos,
|
||||
graphics::PreviewLoader & /*ploader*/) const
|
||||
{
|
||||
if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
|
||||
if (RenderPreview::previewMath()) {
|
||||
preparePreview(inset_pos);
|
||||
}
|
||||
}
|
||||
@ -626,7 +626,7 @@ void InsetMathHull::preparePreview(DocIterator const & pos,
|
||||
{
|
||||
// there is no need to do all the macro stuff if we're not
|
||||
// actually going to generate the preview.
|
||||
if (RenderPreview::status() != LyXRC::PREVIEW_ON && !forexport)
|
||||
if (!RenderPreview::previewMath() && !forexport)
|
||||
return;
|
||||
|
||||
Buffer const * buffer = pos.buffer();
|
||||
@ -690,7 +690,7 @@ void InsetMathHull::loadPreview(DocIterator const & pos) const
|
||||
|
||||
bool InsetMathHull::notifyCursorLeaves(Cursor const & old, Cursor & cur)
|
||||
{
|
||||
if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
|
||||
if (RenderPreview::previewMath()) {
|
||||
reloadPreview(old);
|
||||
cur.screenUpdateFlags(Update::Force);
|
||||
}
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include "FuncRequest.h"
|
||||
#include "FuncStatus.h"
|
||||
#include "Lexer.h"
|
||||
#include "LyXRC.h"
|
||||
|
||||
#include "frontends/Painter.h"
|
||||
|
||||
@ -833,7 +832,7 @@ void fixMacroInstances(Cursor & cur, DocIterator const & inset_pos,
|
||||
MathMacro * macro = insetMath->asMacro();
|
||||
if (macro && macro->name() == name && macro->folded()) {
|
||||
fix(macro);
|
||||
if (RenderPreview::status() == LyXRC::PREVIEW_ON)
|
||||
if (RenderPreview::previewMath())
|
||||
preview_reload_needed = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user