Use a FileName variable in the external inset too.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7350 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-07-23 09:17:04 +00:00
parent c52a93b038
commit 5a714d510d
11 changed files with 106 additions and 59 deletions

View File

@ -1,3 +1,8 @@
2003-07-23 Angus Leeming <leeming@lyx.org>
* factory.C (createInset): pass a
Buffer const * parameter to InsetExternalMailer's string2params.
2003-07-22 John Levon <levon@movementarian.org>
* Thesaurus.h: include the right aiksaurus header

View File

@ -198,11 +198,12 @@ Inset * createInset(FuncRequest const & cmd)
return inset;
} else if (name == "external") {
Buffer const * buffer = cmd.view()->buffer();
InsetExternal::Params iep;
InsetExternalMailer::string2params(cmd.argument, iep);
InsetExternalMailer::string2params(cmd.argument,
buffer, iep);
InsetExternal * inset = new InsetExternal;
string const fpath = cmd.view()->buffer()->filePath();
inset->setParams(iep, fpath);
inset->setParams(iep);
return inset;
} else if (name == "graphics") {

View File

@ -1,3 +1,12 @@
2003-07-23 Angus Leeming <leeming@lyx.org>
* QExternal.C (apply, update_contents):
changes due to the use of the FileName class to store the external
file name.
* QGraphics.C (apply, update_contents): use Kernel::bufferFilepath()
wrapper.
2003-07-21 Angus Leeming <leeming@lyx.org>
* QGraphics.C (apply, update_contents):

View File

@ -67,7 +67,9 @@ void QExternal::update_contents()
{
InsetExternal::Params const & params = controller().params();
dialog_->fileED->setText(toqstr(params.filename));
string const name =
params.filename.outputFilename(kernel().bufferFilepath());
dialog_->fileED->setText(toqstr(name));
dialog_->externalCO->setCurrentItem(controller().getTemplateNumber(params.templatename));
dialog_->externalTV->setText(toqstr(helpText()));
@ -104,7 +106,8 @@ void QExternal::apply()
{
InsetExternal::Params params = controller().params();
params.filename = fromqstr(dialog_->fileED->text());
params.filename.set(fromqstr(dialog_->fileED->text()),
kernel().bufferFilepath());
params.templatename =
controller().getTemplate(dialog_->externalCO->currentItem()).lyxName;

View File

@ -21,7 +21,7 @@
#include "support/filetools.h"
#include "support/lyxlib.h"
#include "insets/insetgraphicsParams.h"
#include "buffer.h"
#include "bufferparams.h"
#include "lyxrc.h"
#include "lengthcombo.h"
#include "qt_helpers.h"
@ -161,7 +161,7 @@ void QGraphics::update_contents()
}
string const name =
igp.filename.outputFilename(kernel().buffer()->filePath());
igp.filename.outputFilename(kernel().bufferFilepath());
dialog_->filename->setText(toqstr(name));
// set the bounding box values
@ -303,7 +303,7 @@ void QGraphics::apply()
InsetGraphicsParams & igp = controller().params();
igp.filename.set(fromqstr(dialog_->filename->text()),
kernel().buffer()->filePath());
kernel().bufferFilepath());
// the bb section
igp.bb.erase();

View File

@ -1,3 +1,12 @@
2003-07-23 Angus Leeming <leeming@lyx.org>
* FormExternal.C (apply, update):
changes due to the use of the FileName class to store the external
file name.
* FormGraphics.C (apply, update): use Kernel::bufferFilepath()
wrapper.
2003-07-21 Angus Leeming <leeming@lyx.org>
* FormGraphics.C (apply, update):

View File

@ -43,7 +43,8 @@ void FormExternal::apply()
{
InsetExternal::Params params = controller().params();
params.filename = fl_get_input(dialog_->input_filename);
string const buffer_path = kernel().bufferFilepath();
params.filename.set(getString(dialog_->input_filename), buffer_path);
int const choice = fl_get_choice(dialog_->choice_template) - 1;
params.templatename = controller().getTemplate(choice).lyxName;
@ -122,7 +123,9 @@ void FormExternal::update()
{
InsetExternal::Params const & params = controller().params();
fl_set_input(dialog_->input_filename, params.filename.c_str());
string const buffer_path = kernel().bufferFilepath();
string const name = params.filename.outputFilename(buffer_path);
fl_set_input(dialog_->input_filename, name.c_str());
int ID = controller().getTemplateNumber(params.templatename);
if (ID < 0) ID = 0;

View File

@ -22,7 +22,6 @@
#include "Tooltips.h"
#include "xforms_helpers.h"
#include "buffer.h"
#include "debug.h" // for lyxerr
#include "lyxrc.h" // for lyxrc.display_graphics
@ -294,7 +293,7 @@ void FormGraphics::apply()
// the file section
igp.filename.set(getString(file_->input_filename),
kernel().buffer()->filePath());
kernel().bufferFilepath());
igp.lyxscale = strToInt(getString(file_->input_lyxscale));
if (igp.lyxscale == 0) {
@ -427,7 +426,7 @@ void FormGraphics::update() {
// the file section
string const name =
igp.filename.outputFilename(kernel().buffer()->filePath());
igp.filename.outputFilename(kernel().bufferFilepath());
fl_set_input(file_->input_filename, name.c_str());
fl_set_input(file_->input_lyxscale, tostr(igp.lyxscale).c_str());

View File

@ -1,3 +1,8 @@
2003-07-23 Angus Leeming <leeming@lyx.org>
* insetexternal.[Ch]: store the external file name in a FileName
member variable rather than a string + associated changes.
2003-07-21 Angus Leeming <leeming@lyx.org>
* insetgraphicsParams.[Ch]: store the graphics file name in

View File

@ -121,12 +121,6 @@ void InsetExternal::statusChanged()
}
InsetExternal::Params const & InsetExternal::params() const
{
return params_;
}
dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd)
{
switch (cmd.action) {
@ -134,18 +128,20 @@ dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd)
case LFUN_EXTERNAL_EDIT: {
Assert(cmd.view());
Buffer const * buffer = cmd.view()->buffer();
InsetExternal::Params p;
InsetExternalMailer::string2params(cmd.argument, p);
editExternal(p, cmd.view()->buffer());
InsetExternalMailer::string2params(cmd.argument, buffer, p);
editExternal(p, buffer);
return DISPATCHED_NOUPDATE;
}
case LFUN_INSET_MODIFY: {
Assert(cmd.view());
Buffer const * buffer = cmd.view()->buffer();
InsetExternal::Params p;
InsetExternalMailer::string2params(cmd.argument, p);
setParams(p, cmd.view()->buffer()->filePath());
InsetExternalMailer::string2params(cmd.argument, buffer, p);
setParams(p);
cmd.view()->updateInset(this);
return DISPATCHED;
}
@ -180,16 +176,11 @@ void InsetExternal::draw(PainterInfo & pi, int x, int y) const
namespace {
lyx::graphics::Params get_grfx_params(InsetExternal::Params const & eparams,
string const & filepath)
lyx::graphics::Params get_grfx_params(InsetExternal::Params const & eparams)
{
lyx::graphics::Params gparams;
if (!eparams.filename.empty()) {
Assert(AbsolutePath(filepath));
gparams.filename = MakeAbsPath(eparams.filename, filepath);
}
gparams.filename = eparams.filename.absFilename();
gparams.scale = eparams.lyxscale;
gparams.display = eparams.display;
@ -226,7 +217,13 @@ string const getScreenLabel(InsetExternal::Params const & params)
} // namespace anon
void InsetExternal::setParams(Params const & p, string const & filepath)
InsetExternal::Params const & InsetExternal::params() const
{
return params_;
}
void InsetExternal::setParams(Params const & p)
{
// The stored params; what we would like to happen in an ideal world.
params_.filename = p.filename;
@ -237,7 +234,6 @@ void InsetExternal::setParams(Params const & p, string const & filepath)
// We display the inset as a button by default.
bool display_button = (!getTemplatePtr(params_) ||
params_.filename.empty() ||
filepath.empty() ||
params_.display == lyx::graphics::NoDisplay);
if (display_button) {
@ -260,24 +256,32 @@ void InsetExternal::setParams(Params const & p, string const & filepath)
renderer_.reset(graphic_ptr);
}
graphic_ptr->update(get_grfx_params(params_, filepath));
graphic_ptr->update(get_grfx_params(params_));
}
}
BufferView * InsetExternal::view() const
{
return renderer_->view();
}
string const InsetExternal::editMessage() const
{
return getScreenLabel(params_);
}
void InsetExternal::write(Buffer const *, ostream & os) const
void InsetExternal::write(Buffer const * buffer, ostream & os) const
{
os << "External\n"
<< "\ttemplate " << params_.templatename << '\n';
if (!params_.filename.empty())
os << "\tfilename " << params_.filename << '\n';
os << "\tfilename "
<< params_.filename.outputFilename(buffer->filePath())
<< '\n';
if (params_.display != defaultDisplayType)
os << "\tdisplay " << lyx::graphics::displayTranslator.find(params_.display)
@ -323,7 +327,7 @@ void InsetExternal::read(Buffer const * buffer, LyXLex & lex)
case EX_FILENAME: {
lex.next();
string const name = lex.getString();
params.filename = name;
params.filename.set(name, buffer->filePath());
break;
}
@ -363,15 +367,14 @@ void InsetExternal::read(Buffer const * buffer, LyXLex & lex)
lex.popTable();
// Replace the inset's store
string const path = buffer ? buffer->filePath() : string();
setParams(params, path);
setParams(params);
lyxerr[Debug::INFO] << "InsetExternal::Read: "
<< "template: '" << params_.templatename
<< "' filename: '" << params_.filename
<< "' display: '" << params_.display
<< "' scale: '" << params_.lyxscale
<< '\'' << endl;
<< "template: '" << params_.templatename
<< "' filename: '" << params_.filename.absFilename()
<< "' display: '" << params_.display
<< "' scale: '" << params_.lyxscale
<< '\'' << endl;
}
@ -493,8 +496,7 @@ void InsetExternal::updateExternal(string const & format,
if (from_format.empty())
return;
string from_file = params_.filename.empty() ?
string() : MakeAbsPath(params_.filename, buf->filePath());
string from_file = params_.filename.absFilename();
if (from_format == "*") {
if (from_file.empty())
@ -550,10 +552,11 @@ string const doSubstitution(InsetExternal::Params const & params,
Buffer const * buffer, string const & s)
{
string result;
string const basename = ChangeExtension(params.filename, string());
string const absfilename = params.filename.absFilename();
string const basename = ChangeExtension(absfilename, string());
string filepath;
result = subst(s, "$$FName", params.filename);
result = subst(s, "$$FName", absfilename);
result = subst(result, "$$Basename", basename);
result = subst(result, "$$FPath", filepath);
result = subst(result, "$$Tempname", params.tempname);
@ -619,11 +622,15 @@ InsetExternalMailer::InsetExternalMailer(InsetExternal & inset)
string const InsetExternalMailer::inset2string() const
{
return params2string(inset_.params());
BufferView * bv = inset_.view();
if (!bv)
return string();
return params2string(inset_.params(), bv->buffer());
}
void InsetExternalMailer::string2params(string const & in,
Buffer const * buffer,
InsetExternal::Params & params)
{
params = InsetExternal::Params();
@ -653,20 +660,21 @@ void InsetExternalMailer::string2params(string const & in,
if (lex.isOK()) {
InsetExternal inset;
inset.read(0, lex);
inset.read(buffer, lex);
params = inset.params();
}
}
string const
InsetExternalMailer::params2string(InsetExternal::Params const & params)
InsetExternalMailer::params2string(InsetExternal::Params const & params,
Buffer const * buffer)
{
InsetExternal inset;
inset.setParams(params, string());
inset.setParams(params);
ostringstream data;
data << name_ << ' ';
inset.write(0, data);
inset.write(buffer, data);
data << "\\end_inset\n";
return STRCONV(data.str());
}

View File

@ -14,6 +14,7 @@
#include "inset.h"
#include "graphics/GraphicsTypes.h"
#include "support/filename.h"
#include "LString.h"
#include <boost/scoped_ptr.hpp>
@ -30,7 +31,7 @@ public:
Params();
~Params();
/// the filename
string filename;
lyx::support::FileName filename;
/// the current template used
string templatename;
/// The name of the tempfile used for manipulations.
@ -85,8 +86,13 @@ public:
///
virtual InsetBase * clone() const;
/// return a copy of our current params
Params const & params() const;
/// Set the inset parameters.
virtual void setParams(Params const &, string const & filepath);
virtual void setParams(Params const &);
virtual BufferView * view() const;
/** update the file represented by the template.
If \param external_in_tmpdir == true, then the generated file is
@ -95,9 +101,6 @@ public:
void updateExternal(string const &, Buffer const *,
bool external_in_tmpdir) const;
/// return a copy of our current params
Params const & params() const;
private:
/** This method is connected to the graphics loader, so we are
* informed when the image has been loaded.
@ -133,9 +136,11 @@ public:
///
virtual string const inset2string() const;
///
static void string2params(string const &, InsetExternal::Params &);
static void string2params(string const &, Buffer const *,
InsetExternal::Params &);
///
static string const params2string(InsetExternal::Params const &);
static string const params2string(InsetExternal::Params const &,
Buffer const *);
private:
///
static string const name_;