diff --git a/src/LyX.cpp b/src/LyX.cpp index efb1237950..b6d1df8d4b 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -48,7 +48,6 @@ #include "frontends/alert.h" #include "frontends/Application.h" -#include "frontends/Gui.h" #include "frontends/LyXView.h" #include "support/environment.h" @@ -375,22 +374,6 @@ void LyX::setGuiLanguage(std::string const & language) } -Buffer const * LyX::updateInset(Inset const * inset) const -{ - if (quitting || !inset) - return 0; - return application().gui().updateInset(inset); -} - - -void LyX::hideDialogs(std::string const & name, Inset * inset) const -{ - if (quitting || !use_gui) - return; - application().gui().hideDialogs(name, inset); -} - - int LyX::exec(int & argc, char * argv[]) { // Here we need to parse the command line. At least diff --git a/src/LyX.h b/src/LyX.h index f02ea652df..25529e55d5 100644 --- a/src/LyX.h +++ b/src/LyX.h @@ -101,13 +101,6 @@ public: /// frontend::LyXView * newLyXView(); - /** redraw \c inset in all the BufferViews in which it is currently - * visible. If successful return a pointer to the owning Buffer. - */ - Buffer const * updateInset(Inset const *) const; - - void hideDialogs(std::string const & name, Inset * inset) const; - /// Execute batch commands if available. void execBatchCommands(); diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 557e7148e6..28ff404be2 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -1562,7 +1562,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd) } case LFUN_DIALOG_HIDE: { - LyX::cref().hideDialogs(argument, 0); + if (quitting || !use_gui) + break; + theApp()->gui().hideDialogs(argument, 0); break; } diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp index 5f0754b8e6..b8e6c7cb51 100644 --- a/src/insets/Inset.cpp +++ b/src/insets/Inset.cpp @@ -33,6 +33,8 @@ #include "MetricsInfo.h" #include "frontends/Painter.h" +#include "frontends/Application.h" +#include "frontends/Gui.h" #include "support/convert.h" @@ -44,10 +46,11 @@ namespace lyx { +extern bool quitting; + class InsetName { public: - InsetName(std::string const & n, InsetCode c) - : name(n), code(c) {} + InsetName(std::string const & n, InsetCode c) : name(n), code(c) {} std::string name; InsetCode code; }; @@ -382,4 +385,12 @@ void Inset::setDimCache(MetricsInfo const & mi, Dimension const & dim) const mi.base.bv->coordCache().insets().add(this, dim); } + +Buffer const * Inset::updateFrontend() const +{ + if (quitting) + return 0; + return theApp()->gui().updateInset(this); +} + } // namespace lyx diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 2caf998873..14bd75fa39 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -353,6 +353,8 @@ public: /// Update the counters of this inset and of its contents virtual void updateLabels(Buffer const &, ParIterator const &) {} + /// Updates the inset's dialog + virtual Buffer const * updateFrontend() const; public: /// returns LyX code associated with the inset. Used for TOC, ...) diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp index 2ca4511163..75aeb66580 100644 --- a/src/insets/InsetExternal.cpp +++ b/src/insets/InsetExternal.cpp @@ -26,7 +26,6 @@ #include "FuncRequest.h" #include "gettext.h" #include "LaTeXFeatures.h" -#include "LyX.h" #include "Lexer.h" #include "LyXRC.h" #include "MetricsInfo.h" @@ -65,6 +64,8 @@ string defaultTemplateName; namespace lyx { +extern bool use_gui; + namespace external { TempName::TempName() @@ -89,8 +90,7 @@ TempName::~TempName() } -TempName & -TempName::operator=(TempName const & other) +TempName & TempName::operator=(TempName const & other) { if (this != &other) tempname_ = TempName()(); @@ -385,8 +385,7 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex) break; default: - lex.printError("ExternalInset::read: " - "Wrong tag: $$Token"); + lex.printError("ExternalInset::read: Wrong tag: $$Token"); read_error = true; break; } @@ -437,7 +436,7 @@ InsetExternal::~InsetExternal() void InsetExternal::statusChanged() const { - LyX::cref().updateInset(this); + updateFrontend(); } @@ -633,8 +632,9 @@ void InsetExternal::setParams(InsetExternalParams const & p, button_ptr->update(getScreenLabel(params_, buffer), true); break; + } - } case RENDERGRAPHIC: { + case RENDERGRAPHIC: { RenderGraphic * graphic_ptr = renderer_->asGraphic(); if (!graphic_ptr) { renderer_.reset(new RenderGraphic(this)); @@ -644,8 +644,9 @@ void InsetExternal::setParams(InsetExternalParams const & p, graphic_ptr->update(get_grfx_params(params_)); break; + } - } case RENDERPREVIEW: { + case RENDERPREVIEW: { RenderMonitoredPreview * preview_ptr = renderer_->asMonitoredPreview(); if (!preview_ptr) { @@ -667,16 +668,15 @@ void InsetExternal::setParams(InsetExternalParams const & p, void InsetExternal::fileChanged() const { - Buffer const * const buffer_ptr = LyX::cref().updateInset(this); - if (!buffer_ptr) + Buffer const * const buffer = updateFrontend(); + if (!buffer) return; RenderMonitoredPreview * const ptr = renderer_->asMonitoredPreview(); BOOST_ASSERT(ptr); - Buffer const & buffer = *buffer_ptr; - ptr->removePreview(buffer); - add_preview_and_start_loading(*ptr, *this, buffer); + ptr->removePreview(*buffer); + add_preview_and_start_loading(*ptr, *this, *buffer); } diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index ecab91e252..bfc286de5d 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -770,14 +770,13 @@ Inset::DisplayType InsetInclude::display() const void InsetInclude::fileChanged() const { - Buffer const * const buffer_ptr = LyX::cref().updateInset(this); - if (!buffer_ptr) + Buffer const * const buffer = updateFrontend(); + if (!buffer) return; - Buffer const & buffer = *buffer_ptr; - preview_->removePreview(buffer); - add_preview(*preview_.get(), *this, buffer); - preview_->startLoading(buffer); + preview_->removePreview(*buffer); + add_preview(*preview_.get(), *this, *buffer); + preview_->startLoading(*buffer); } diff --git a/src/insets/MailInset.cpp b/src/insets/MailInset.cpp index 3babfeaa1e..a7a843845c 100644 --- a/src/insets/MailInset.cpp +++ b/src/insets/MailInset.cpp @@ -14,7 +14,9 @@ #include "BufferView.h" #include "debug.h" -#include "LyX.h" + +#include "frontends/Application.h" +#include "frontends/Gui.h" #include @@ -40,7 +42,7 @@ void MailInset::updateDialog(BufferView * bv) const void MailInset::hideDialog() const { - LyX::cref().hideDialogs(name(), &inset()); + theApp()->gui().hideDialogs(name(), &inset()); } diff --git a/src/insets/RenderGraphic.cpp b/src/insets/RenderGraphic.cpp index dbc3fd21ff..74e3181989 100644 --- a/src/insets/RenderGraphic.cpp +++ b/src/insets/RenderGraphic.cpp @@ -31,26 +31,17 @@ namespace lyx { -using support::onlyFilename; - -using std::string; - RenderGraphic::RenderGraphic(Inset const * inset) { - loader_.connect(boost::bind(&LyX::updateInset, - boost::cref(LyX::cref()), inset)); + loader_.connect(boost::bind(&Inset::updateFrontend, inset)); } -RenderGraphic::RenderGraphic(RenderGraphic const & other, - Inset const * inset) - : RenderBase(other), - loader_(other.loader_), - params_(other.params_) +RenderGraphic::RenderGraphic(RenderGraphic const & other, Inset const * inset) + : RenderBase(other), loader_(other.loader_), params_(other.params_) { - loader_.connect(boost::bind(&LyX::updateInset, - boost::cref(LyX::cref()), inset)); + loader_.connect(boost::bind(&Inset::updateFrontend, inset)); } @@ -64,9 +55,8 @@ void RenderGraphic::update(graphics::Params const & params) { params_ = params; - if (!params_.filename.empty()) { + if (!params_.filename.empty()) loader_.reset(params_.filename, params_); - } } @@ -155,12 +145,10 @@ void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const msgFont.setFamily(SANS_FAMILY); // FIXME UNICODE - docstring const justname = - from_utf8(onlyFilename(params_.filename.absFilename())); + docstring const justname = from_utf8(params_.filename.onlyFileName()); if (!justname.empty()) { msgFont.setSize(FONT_SIZE_FOOTNOTE); - font_width = theFontMetrics(msgFont) - .width(justname); + font_width = theFontMetrics(msgFont).width(justname); } docstring const msg = statusMessage(params_, loader_.status()); @@ -206,7 +194,7 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const // Print the file name. FontInfo msgFont = pi.base.font; msgFont.setFamily(SANS_FAMILY); - string const justname = onlyFilename(params_.filename.absFilename()); + std::string const justname = params_.filename.onlyFileName(); if (!justname.empty()) { msgFont.setSize(FONT_SIZE_FOOTNOTE); diff --git a/src/insets/RenderPreview.cpp b/src/insets/RenderPreview.cpp index d21f638eee..81a48f5946 100644 --- a/src/insets/RenderPreview.cpp +++ b/src/insets/RenderPreview.cpp @@ -240,13 +240,12 @@ void RenderPreview::imageReady(graphics::PreviewImage const & pimage) { // Check the current snippet is the same as that previewed. if (snippet_ == pimage.snippet()) - LyX::cref().updateInset(parent_); + parent_->updateFrontend(); } RenderMonitoredPreview::RenderMonitoredPreview(Inset const * inset) - : RenderPreview(inset), - monitor_(FileName(), 2000) + : RenderPreview(inset), monitor_(FileName(), 2000) {}