mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
Enable the graphics inset to work correctly with relative file names.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3816 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
cbc3add7f2
commit
4f9bed1018
@ -6,6 +6,9 @@
|
||||
|
||||
* 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
|
||||
|
@ -66,7 +66,7 @@ void ControlGraphics::applyParamsToInset()
|
||||
{
|
||||
// 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);
|
||||
|
@ -1,3 +1,10 @@
|
||||
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
|
||||
|
@ -50,12 +50,12 @@ GCache::~GCache()
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
~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.
|
||||
|
@ -15,17 +15,23 @@
|
||||
#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;
|
||||
|
||||
|
@ -49,7 +49,7 @@ bool operator!=(BoundingBox const &, BoundingBox const &);
|
||||
|
||||
struct GParams
|
||||
{
|
||||
GParams(InsetGraphicsParams const &);
|
||||
GParams(InsetGraphicsParams const &, string const & = string());
|
||||
|
||||
/// How is the image to be displayed on the LyX screen?
|
||||
enum DisplayType {
|
||||
|
@ -1,5 +1,14 @@
|
||||
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.
|
||||
|
||||
|
@ -147,13 +147,15 @@ InsetGraphics::InsetGraphics()
|
||||
{}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -355,10 +357,10 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font,
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
@ -392,16 +394,16 @@ void InsetGraphics::read(Buffer const * buf, LyXLex & lex)
|
||||
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;
|
||||
|
||||
@ -428,7 +430,7 @@ void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex)
|
||||
// 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;
|
||||
}
|
||||
@ -436,7 +438,7 @@ void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex)
|
||||
}
|
||||
|
||||
// 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%");
|
||||
@ -462,9 +464,7 @@ void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex)
|
||||
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());
|
||||
@ -730,7 +730,8 @@ void InsetGraphics::validate(LaTeXFeatures & features) const
|
||||
}
|
||||
|
||||
|
||||
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()) {
|
||||
@ -741,7 +742,7 @@ bool InsetGraphics::setParams(InsetGraphicsParams const & p)
|
||||
params_ = p;
|
||||
|
||||
// Update the inset with the new parameters.
|
||||
updateInset();
|
||||
updateInset(filepath);
|
||||
|
||||
// We have changed data, report it.
|
||||
return true;
|
||||
@ -754,7 +755,7 @@ InsetGraphicsParams const & InsetGraphics::params() const
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -34,7 +34,8 @@ public:
|
||||
///
|
||||
InsetGraphics();
|
||||
///
|
||||
InsetGraphics(InsetGraphics const &, bool same_id = false);
|
||||
InsetGraphics(InsetGraphics const &, string const & filepath,
|
||||
bool same_id = false);
|
||||
///
|
||||
~InsetGraphics();
|
||||
///
|
||||
@ -83,7 +84,8 @@ public:
|
||||
/** 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;
|
||||
@ -100,12 +102,12 @@ private:
|
||||
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.
|
||||
|
@ -237,16 +237,11 @@ void InsetGraphicsParams::Write(Buffer const * buf, ostream & os) const
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
|
@ -90,7 +90,7 @@ struct InsetGraphicsParams
|
||||
/// 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.
|
||||
|
Loading…
Reference in New Issue
Block a user