* ControlGraphics.[Ch]: replace checkFilename with isFilenameValid.
+ * ControlGraphics.C (applyParamsToInset): pass filepath to
+ InsetGraphics::updateInset.
+
2002-03-21 Lars Gullik Bjønnes <larsbj@birdstep.com>
* most files: ws cleanup
{
// Set the parameters in the inset, it also returns true if the new
// parameters are different from what was in the inset already.
- bool changed = inset()->setParams(params());
+ bool changed = inset()->setParams(params(), lv_.buffer()->filePath());
// Tell LyX we've got a change, and mark the document dirty,
// if it changed.
lv_.view()->updateInset(inset(), changed);
+2002-03-22 Angus Leeming <a.leeming@ic.ac.uk>
+
+ * GraphicsCache.[Ch] (update): now passed filepath to determine absolute
+ path to graphics file.
+
+ * GraphicsParams.[Ch] (c-tor): now passed filepath.
+
2002-03-21 Lars Gullik Bjønnes <larsbj@birdstep.com>
* most files: ws cleanup
}
-void GCache::update(InsetGraphics const & inset)
+void GCache::update(InsetGraphics const & inset, string const & filepath)
{
// A subset only of InsetGraphicsParams is needed for display purposes.
// The GraphicsParams c-tor also interrogates lyxrc to ascertain whether
// to display or not.
- GParams params(inset.params());
+ GParams params(inset.params(), filepath);
// Each inset can reference only one file, so check the cache for any
// graphics files referenced by inset. If the name of this file is
~GCache();
/// Add a file to the cache (or modify an existing image).
- void update(InsetGraphics const &);
+ void update(InsetGraphics const &, string const & filepath);
/** Remove the data associated with this inset.
* Called from the InsetGraphics d-tor.
#include "GraphicsParams.h"
#include "insets/insetgraphicsParams.h"
#include "lyxrc.h"
+#include "support/filetools.h"
#include "support/lstrings.h"
+#include "support/LAssert.h"
namespace grfx {
-GParams::GParams(InsetGraphicsParams const & iparams)
- : filename(iparams.filename),
- width(0),
+GParams::GParams(InsetGraphicsParams const & iparams, string const & filepath)
+ : width(0),
height(0),
scale(0),
angle(0)
{
+ filename = iparams.filename;
+ if (!filepath.empty()) {
+ filename = MakeAbsPath(filename, filepath);
+ }
+
if (iparams.clip)
bb = iparams.bb;
struct GParams
{
- GParams(InsetGraphicsParams const &);
+ GParams(InsetGraphicsParams const &, string const & = string());
/// How is the image to be displayed on the LyX screen?
enum DisplayType {
2002-03-22 Angus Leeming <a.leeming@ic.ac.uk>
+ * insetgraphics.[Ch] (c-tor, setParams, updateInset): passed filepath.
+ Used to determine the absolute path to the graphics file in the
+ graphics cache and only in the graphics cache.
+ (readInsetGraphics, readFigInset) : no longer passed buffer. Do not
+ make graphics file name absolute if it is stored as a relative path.
+
+ * insetgraphicsParams.[Ch] (Read): no longer passed buffer. Do not
+ make graphics file name absolute if it is stored as a relative path.
+
* insettext.C (edit): emit an updateParagraph signal on entering a text
inset. Needs to be emitted when leaving the inset also.
{}
-InsetGraphics::InsetGraphics(InsetGraphics const & ig, bool same_id)
+InsetGraphics::InsetGraphics(InsetGraphics const & ig,
+ string const & filepath,
+ bool same_id)
: Inset(ig, same_id),
SigC::Object(),
graphic_label(unique_id()),
cached_status_(grfx::ErrorUnknown), cache_filled_(false), old_asc(0)
{
- setParams(ig.params());
+ setParams(ig.params(), filepath);
}
// Update the inset after parameters changed (read from file or changed in
// dialog. The grfx::GCache makes the decisions about whether or not to draw
// (interogates lyxrc, ascertains whether file exists etc)
-void InsetGraphics::updateInset() const
+void InsetGraphics::updateInset(string const & filepath) const
{
grfx::GCache & gc = grfx::GCache::get();
- gc.update(*this);
+ gc.update(*this, filepath);
}
string const token = lex.getString();
if (token == "Graphics")
- readInsetGraphics(buf, lex);
+ readInsetGraphics(lex);
else if (token == "Figure") // Compatibility reading of FigInset figures.
- readFigInset(buf, lex);
+ readFigInset(lex);
else
lyxerr[Debug::GRAPHICS] << "Not a Graphics or Figure inset!\n";
- updateInset();
+ updateInset(buf->filePath());
}
-void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex)
+void InsetGraphics::readInsetGraphics(LyXLex & lex)
{
bool finished = false;
// TODO: Possibly open up a dialog?
}
else {
- if (! params_.Read(buf, lex, token))
+ if (! params_.Read(lex, token))
lyxerr << "Unknown token, " << token << ", skipping."
<< std::endl;
}
}
// FormatVersion < 1.0 (LyX < 1.2)
-void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex)
+void InsetGraphics::readFigInset(LyXLex & lex)
{
std::vector<string> const oldUnits =
getVectorFromString("pt,cm,in,p%,c%");
finished = true;
} else if (token == "file") {
if (lex.next()) {
- string const name = lex.getString();
- string const path = buf->filePath();
- params_.filename = MakeAbsPath(name, path);
+ params_.filename = lex.getString();
}
} else if (token == "extra") {
if (lex.next());
}
-bool InsetGraphics::setParams(InsetGraphicsParams const & p)
+bool InsetGraphics::setParams(InsetGraphicsParams const & p,
+ string const & filepath)
{
// If nothing is changed, just return and say so.
if (params() == p && !p.filename.empty()) {
params_ = p;
// Update the inset with the new parameters.
- updateInset();
+ updateInset(filepath);
// We have changed data, report it.
return true;
}
-Inset * InsetGraphics::clone(Buffer const &, bool same_id) const
+Inset * InsetGraphics::clone(Buffer const & buffer, bool same_id) const
{
- return new InsetGraphics(*this, same_id);
+ return new InsetGraphics(*this, buffer.filePath(), same_id);
}
///
InsetGraphics();
///
- InsetGraphics(InsetGraphics const &, bool same_id = false);
+ InsetGraphics(InsetGraphics const &, string const & filepath,
+ bool same_id = false);
///
~InsetGraphics();
///
/** Set the inset parameters, used by the GUIndependent dialog.
Return true of new params are different from what was so far.
*/
- bool setParams(InsetGraphicsParams const & params);
+ bool setParams(InsetGraphicsParams const & params,
+ string const & filepath);
/// Get the inset parameters, used by the GUIndependent dialog.
InsetGraphicsParams const & params() const;
bool drawImage() const;
/// Read the inset native format
- void readInsetGraphics(Buffer const * buf, LyXLex & lex);
+ void readInsetGraphics(LyXLex & lex);
/// Read the FigInset file format
- void readFigInset(Buffer const * buf, LyXLex & lex);
+ void readFigInset(LyXLex & lex);
/// Update the inset after parameter change.
- void updateInset() const;
+ void updateInset(string const & filepath) const;
/// Get the status message, depends on the image loading status.
string const statusMessage() const;
/// Create the options for the latex command.
}
-bool InsetGraphicsParams::Read(Buffer const * buf, LyXLex & lex,
- string const& token)
+bool InsetGraphicsParams::Read(LyXLex & lex, string const& token)
{
if (token == "filename") {
lex.next();
filename = lex.getString();
- if (!filename.empty()) {
- // Make the filename with absolute directory.
- filename = MakeAbsPath(filename, buf->filePath());
- }
} else if (token == "BoundingBox") {
for (int i=0; i<4 ;i++) {
lex.next();
/// Save the parameters in the LyX format stream.
void Write(Buffer const * buf, std::ostream & os) const;
/// If the token belongs to our parameters, read it.
- bool Read(Buffer const * buf, LyXLex & lex, string const & token);
+ bool Read(LyXLex & lex, string const & token);
private:
/// Initialize the object to a default status.