From 770aa71839511d358c90090c992f33f1a6319f82 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Thu, 13 Aug 2009 17:21:59 +0000 Subject: [PATCH] Fix bug #6134: Reload context menu for graphics inset. This shouldn't be necessary, but sometimes it is. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31014 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ui/stdcontext.inc | 1 + src/FuncCode.h | 1 + src/LyXAction.cpp | 10 ++++++++++ src/graphics/GraphicsCacheItem.cpp | 2 ++ src/graphics/GraphicsLoader.cpp | 6 ++++++ src/graphics/GraphicsLoader.h | 4 ++++ src/insets/InsetGraphics.cpp | 5 +++++ src/insets/RenderGraphic.cpp | 4 ++++ src/insets/RenderGraphic.h | 2 ++ 9 files changed, 35 insertions(+) diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc index aef2b4b719..efb80d526f 100644 --- a/lib/ui/stdcontext.inc +++ b/lib/ui/stdcontext.inc @@ -358,6 +358,7 @@ Menuset Menu "context-graphics" Item "Settings...|S" "inset-settings" + Item "Reload...|U" "graphics-reload" Separator Item "Edit Externally...|x" "inset-edit" Separator diff --git a/src/FuncCode.h b/src/FuncCode.h index 52ee7739b9..b6c984c9a8 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -440,6 +440,7 @@ enum FuncCode // 340 LFUN_BRANCHES_RENAME, // spitz 20090709 LFUN_BUFFER_CLOSE_ALL, // vfr 20090806 + LFUN_GRAPHICS_RELOAD, // vfr 20090810 LFUN_LASTACTION // end of the table }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index e1860cb3ce..b0a3a03571 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -3403,6 +3403,16 @@ void LyXAction::init() */ { LFUN_SECTION_SELECT, "section-select", ReadOnly, Edit }, +/*! + * \var lyx::FuncCode lyx::LFUN_GRAPHICS_RELOAD + * \li Action: Reloads the image if necessary. + * \li Syntax: graphics-reload + * \li Origin: vfr, 10 Aug 2009 + * \endvar + */ + { LFUN_GRAPHICS_RELOAD, "graphics-reload", ReadOnly | AtPoint, Edit }, + + { LFUN_NOACTION, "", Noop, Hidden } #ifndef DOXYGEN_SHOULD_SKIP_THIS }; diff --git a/src/graphics/GraphicsCacheItem.cpp b/src/graphics/GraphicsCacheItem.cpp index 0bac4b559e..b9bc390b52 100644 --- a/src/graphics/GraphicsCacheItem.cpp +++ b/src/graphics/GraphicsCacheItem.cpp @@ -349,6 +349,8 @@ static string const findTargetFormat(string const & from) bool CacheItem::Impl::tryDisplayFormat(FileName & filename, string & from) { // First, check that the file exists! + // force a refresh. + filename_.lastModified(); if (!filename_.isReadableFile()) { if (status_ != ErrorNoFile) { status_ = ErrorNoFile; diff --git a/src/graphics/GraphicsLoader.cpp b/src/graphics/GraphicsLoader.cpp index ecc9cd9e03..ac5d614c6e 100644 --- a/src/graphics/GraphicsLoader.cpp +++ b/src/graphics/GraphicsLoader.cpp @@ -279,6 +279,12 @@ void Loader::startLoading() const } +void Loader::reload() const +{ + pimpl_->cached_item_->startLoading(); +} + + void Loader::startMonitoring() const { if (!pimpl_->cached_item_.get()) diff --git a/src/graphics/GraphicsLoader.h b/src/graphics/GraphicsLoader.h index 43fd85e695..65218505b0 100644 --- a/src/graphics/GraphicsLoader.h +++ b/src/graphics/GraphicsLoader.h @@ -68,6 +68,10 @@ public: */ void startLoading() const; + /** Tries to reload the image. + */ + void reload() const; + /** Monitor any changes to the file. * There is no point monitoring the file before startLoading() is * invoked. diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index 2ef6d47287..686fa47940 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -216,6 +216,10 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd) cur.bv().updateDialog("graphics", params2string(params(), buffer())); break; + case LFUN_GRAPHICS_RELOAD: + graphic_->reload(); + break; + default: Inset::doDispatch(cur, cmd); break; @@ -230,6 +234,7 @@ bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_INSET_EDIT: case LFUN_INSET_MODIFY: case LFUN_INSET_DIALOG_UPDATE: + case LFUN_GRAPHICS_RELOAD: flag.setEnabled(true); return true; diff --git a/src/insets/RenderGraphic.cpp b/src/insets/RenderGraphic.cpp index bca3a518f8..fba651ccdc 100644 --- a/src/insets/RenderGraphic.cpp +++ b/src/insets/RenderGraphic.cpp @@ -52,6 +52,10 @@ RenderBase * RenderGraphic::clone(Inset const * inset) const return new RenderGraphic(*this, inset); } +void RenderGraphic::reload() const +{ + loader_.reload(); +} void RenderGraphic::update(graphics::Params const & params) { diff --git a/src/insets/RenderGraphic.h b/src/insets/RenderGraphic.h index 5edb7ce940..b41b82e61a 100644 --- a/src/insets/RenderGraphic.h +++ b/src/insets/RenderGraphic.h @@ -35,6 +35,8 @@ public: /// Refresh the info about which file to display and how to display it. void update(graphics::Params const & params); + /// Reloads the image if necessary + void reload() const; /// equivalent to dynamic_cast virtual RenderGraphic * asGraphic() { return this; } -- 2.39.2