From 5a714d510d5b1f0eab2a93c7df26246c4db70a43 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Wed, 23 Jul 2003 09:17:04 +0000 Subject: [PATCH] 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 --- src/ChangeLog | 5 ++ src/factory.C | 7 ++- src/frontends/qt2/ChangeLog | 9 +++ src/frontends/qt2/QExternal.C | 7 ++- src/frontends/qt2/QGraphics.C | 6 +- src/frontends/xforms/ChangeLog | 9 +++ src/frontends/xforms/FormExternal.C | 7 ++- src/frontends/xforms/FormGraphics.C | 5 +- src/insets/ChangeLog | 5 ++ src/insets/insetexternal.C | 86 ++++++++++++++++------------- src/insets/insetexternal.h | 19 ++++--- 11 files changed, 106 insertions(+), 59 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b01306b81b..0845afc92e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2003-07-23 Angus Leeming + + * factory.C (createInset): pass a + Buffer const * parameter to InsetExternalMailer's string2params. + 2003-07-22 John Levon * Thesaurus.h: include the right aiksaurus header diff --git a/src/factory.C b/src/factory.C index e9a22511a9..fa2fef5543 100644 --- a/src/factory.C +++ b/src/factory.C @@ -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") { diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 467838439d..d0a687d2e0 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,12 @@ +2003-07-23 Angus Leeming + + * 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 * QGraphics.C (apply, update_contents): diff --git a/src/frontends/qt2/QExternal.C b/src/frontends/qt2/QExternal.C index db265b3c4b..5e34a4100b 100644 --- a/src/frontends/qt2/QExternal.C +++ b/src/frontends/qt2/QExternal.C @@ -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; diff --git a/src/frontends/qt2/QGraphics.C b/src/frontends/qt2/QGraphics.C index 49d314be0e..2528fc6a80 100644 --- a/src/frontends/qt2/QGraphics.C +++ b/src/frontends/qt2/QGraphics.C @@ -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(); diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 09961a5774..b7dbd42fa5 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,12 @@ +2003-07-23 Angus Leeming + + * 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 * FormGraphics.C (apply, update): diff --git a/src/frontends/xforms/FormExternal.C b/src/frontends/xforms/FormExternal.C index 353784986b..c59471daa9 100644 --- a/src/frontends/xforms/FormExternal.C +++ b/src/frontends/xforms/FormExternal.C @@ -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; diff --git a/src/frontends/xforms/FormGraphics.C b/src/frontends/xforms/FormGraphics.C index b884829301..dcdc701fd2 100644 --- a/src/frontends/xforms/FormGraphics.C +++ b/src/frontends/xforms/FormGraphics.C @@ -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()); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 22407f3e7e..839830b0a7 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2003-07-23 Angus Leeming + + * insetexternal.[Ch]: store the external file name in a FileName + member variable rather than a string + associated changes. + 2003-07-21 Angus Leeming * insetgraphicsParams.[Ch]: store the graphics file name in diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 037d452cae..de1ae3c924 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -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()); } diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index 919a9ab4be..8f71ff7636 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -14,6 +14,7 @@ #include "inset.h" #include "graphics/GraphicsTypes.h" +#include "support/filename.h" #include "LString.h" #include @@ -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_;