mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-21 23:09:40 +00:00
LFUN_EXTERNAL_EDIT.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7144 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
e3e2a6941d
commit
822efad779
@ -1,3 +1,10 @@
|
||||
2003-06-10 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* lfuns.h:
|
||||
* LyXAction.C (init): new LFUN_EXTERNAL_EDIT.
|
||||
|
||||
* lyxfunc.C (dispatch): invoke it.
|
||||
|
||||
2003-06-11 Lars Gullik Bjønnes <larsbj@gullik.net>
|
||||
|
||||
* main.C: protect <ios> with HAVE_IOS
|
||||
|
@ -325,6 +325,7 @@ void LyXAction::init()
|
||||
{ LFUN_INSET_SETTINGS, "inset-settings", ReadOnly },
|
||||
{ LFUN_PARAGRAPH_APPLY, "paragraph-params-apply", Noop },
|
||||
{ LFUN_PARAGRAPH_UPDATE, "", Noop },
|
||||
{ LFUN_EXTERNAL_EDIT, "external-edit", Noop },
|
||||
{ LFUN_NOACTION, "", Noop }
|
||||
};
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
2003-06-10 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* ControlExternal.C (editExternal): invokes new LFUN_EXTERNAL_EDIT rather
|
||||
than generate a new inset itself.
|
||||
|
||||
2003-06-06 John Levon <levon@movementarian.org>
|
||||
|
||||
* ControlDocument.C: make sure a language change
|
||||
|
@ -70,10 +70,8 @@ void ControlExternal::editExternal()
|
||||
lyx::Assert(params_.get());
|
||||
|
||||
dialog().view().apply();
|
||||
InsetExternal inset;
|
||||
inset.setParams(*params_, kernel().buffer()->filePath());
|
||||
inset.cache(kernel().bufferview());
|
||||
inset.editExternal();
|
||||
string const lfun = InsetExternalMailer::params2string(params());
|
||||
kernel().dispatch(FuncRequest(LFUN_EXTERNAL_EDIT, lfun));
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,6 +2,17 @@
|
||||
|
||||
* insettext.C (appendParagraphs): remove some commented code.
|
||||
|
||||
2003-06-10 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* graphicinset.[Ch] (view): removed the publicly accessible function to set
|
||||
the cache.
|
||||
|
||||
* insetexternal.[Ch]: move tempname_ into the Params struct.
|
||||
(Params d-tor): new function, to clean-up this temp file.
|
||||
(localDispatch): dispatch LFUN_EXTERNAL_EDIT.
|
||||
(cache): removed.
|
||||
(editExternal, doSubstitution): move out of class.
|
||||
|
||||
2003-06-10 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* graphicinset.[Ch] (params): removed.
|
||||
|
@ -60,13 +60,6 @@ bool GraphicInset::hasFileChanged() const
|
||||
}
|
||||
|
||||
|
||||
void GraphicInset::view(BufferView * bv) const
|
||||
{
|
||||
if (bv)
|
||||
view_ = bv->owner()->view();
|
||||
}
|
||||
|
||||
|
||||
BufferView * GraphicInset::view() const
|
||||
{
|
||||
return view_.lock().get();
|
||||
@ -184,8 +177,8 @@ void GraphicInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
|
||||
void GraphicInset::draw(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
// Cache the BufferView.
|
||||
view(pi.base.bv);
|
||||
if (pi.base.bv)
|
||||
view_ = pi.base.bv->owner()->view();
|
||||
|
||||
#if 0
|
||||
// Comment this out and see if anything goes wrong.
|
||||
|
@ -51,8 +51,6 @@ public:
|
||||
|
||||
/// Is the stored checksum different to that of the graphics loader?
|
||||
bool hasFileChanged() const;
|
||||
/// Set the cached store.
|
||||
void view(BufferView *) const;
|
||||
/// An accessor function to the cached store.
|
||||
BufferView * view() const;
|
||||
|
||||
|
@ -54,13 +54,31 @@ grfx::DisplayType const defaultDisplayType = grfx::NoDisplay;
|
||||
|
||||
unsigned int defaultLyxScale = 100;
|
||||
|
||||
/// Substitute meta-variables in string s, makeing use of params and buffer.
|
||||
string const doSubstitution(InsetExternal::Params const & params,
|
||||
Buffer const * buffer, string const & s);
|
||||
|
||||
/// Invoke the external editor.
|
||||
void editExternal(InsetExternal::Params const & params, Buffer const * buffer);
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
InsetExternal::Params::Params()
|
||||
: display(defaultDisplayType),
|
||||
lyxscale(defaultLyxScale)
|
||||
{}
|
||||
{
|
||||
tempname = lyx::tempName(string(), "lyxext");
|
||||
lyx::unlink(tempname);
|
||||
// must have an extension for the converter code to work correctly.
|
||||
tempname += ".tmp";
|
||||
}
|
||||
|
||||
|
||||
InsetExternal::Params::~Params()
|
||||
{
|
||||
lyx::unlink(tempname);
|
||||
}
|
||||
|
||||
|
||||
InsetExternal::InsetExternal()
|
||||
@ -90,8 +108,6 @@ Inset * InsetExternal::clone() const
|
||||
|
||||
InsetExternal::~InsetExternal()
|
||||
{
|
||||
if (!tempname_.empty())
|
||||
lyx::unlink(tempname_);
|
||||
InsetExternalMailer(*this).hideDialog();
|
||||
}
|
||||
|
||||
@ -114,7 +130,18 @@ dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd)
|
||||
{
|
||||
switch (cmd.action) {
|
||||
|
||||
case LFUN_EXTERNAL_EDIT: {
|
||||
lyx::Assert(cmd.view());
|
||||
|
||||
InsetExternal::Params p;
|
||||
InsetExternalMailer::string2params(cmd.argument, p);
|
||||
editExternal(p, cmd.view()->buffer());
|
||||
return DISPATCHED_NOUPDATE;
|
||||
}
|
||||
|
||||
case LFUN_INSET_MODIFY: {
|
||||
lyx::Assert(cmd.view());
|
||||
|
||||
InsetExternal::Params p;
|
||||
InsetExternalMailer::string2params(cmd.argument, p);
|
||||
setParams(p, cmd.view()->buffer()->filePath());
|
||||
@ -137,12 +164,6 @@ dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd)
|
||||
}
|
||||
|
||||
|
||||
void InsetExternal::cache(BufferView * bv) const
|
||||
{
|
||||
renderer_->view(bv);
|
||||
}
|
||||
|
||||
|
||||
void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
{
|
||||
renderer_->metrics(mi, dim);
|
||||
@ -193,14 +214,14 @@ void InsetExternal::setParams(Params const & p, string const & filepath)
|
||||
// Update the display using the new parameters.
|
||||
if (params_.filename.empty() || !filepath.empty())
|
||||
renderer_->update(get_grfx_params(params_, filepath));
|
||||
string const msg = doSubstitution(0, params_.templ.guiName);
|
||||
string const msg = doSubstitution(params_, 0, params_.templ.guiName);
|
||||
renderer_->setNoDisplayMessage(msg);
|
||||
}
|
||||
|
||||
|
||||
string const InsetExternal::editMessage() const
|
||||
{
|
||||
return doSubstitution(0, params_.templ.guiName);
|
||||
return doSubstitution(params_, 0, params_.templ.guiName);
|
||||
}
|
||||
|
||||
|
||||
@ -311,7 +332,7 @@ void InsetExternal::read(Buffer const * buffer, LyXLex & lex)
|
||||
// Update the display using the new parameters.
|
||||
if (buffer)
|
||||
renderer_->update(get_grfx_params(params_, buffer->filePath()));
|
||||
string const msg = doSubstitution(0, params_.templ.guiName);
|
||||
string const msg = doSubstitution(params_, 0, params_.templ.guiName);
|
||||
renderer_->setNoDisplayMessage(msg);
|
||||
}
|
||||
|
||||
@ -331,7 +352,7 @@ int InsetExternal::write(string const & format,
|
||||
}
|
||||
|
||||
updateExternal(format, buf, external_in_tmpdir);
|
||||
string const str = doSubstitution(buf, cit->second.product);
|
||||
string const str = doSubstitution(params_, buf, cit->second.product);
|
||||
os << str;
|
||||
return int(lyx::count(str.begin(), str.end(),'\n') + 1);
|
||||
}
|
||||
@ -397,56 +418,6 @@ void InsetExternal::validate(LaTeXFeatures & features) const
|
||||
}
|
||||
|
||||
|
||||
string const InsetExternal::doSubstitution(Buffer const * buffer,
|
||||
string const & s) const
|
||||
{
|
||||
string result;
|
||||
string const basename = ChangeExtension(params_.filename, string());
|
||||
string filepath;
|
||||
bool external_in_tmpdir = false;
|
||||
if (buffer && !buffer->tmppath.empty() && !buffer->niceFile) {
|
||||
filepath = buffer->filePath();
|
||||
if (lyxrc.use_tempdir)
|
||||
external_in_tmpdir = true;
|
||||
}
|
||||
if (tempname_.empty()) {
|
||||
string const path = external_in_tmpdir ? buffer->tmppath : string();
|
||||
tempname_ = lyx::tempName(path, "lyxext");
|
||||
lyx::unlink(tempname_);
|
||||
// must have an extension for the converter code to work correctly.
|
||||
tempname_ += ".tmp";
|
||||
}
|
||||
result = subst(s, "$$FName", params_.filename);
|
||||
result = subst(result, "$$Basename", basename);
|
||||
result = subst(result, "$$FPath", filepath);
|
||||
result = subst(result, "$$Tempname", tempname_);
|
||||
result = subst(result, "$$Sysdir", system_lyxdir);
|
||||
|
||||
// Handle the $$Contents(filename) syntax
|
||||
if (contains(result, "$$Contents(\"")) {
|
||||
|
||||
string::size_type const pos = result.find("$$Contents(\"");
|
||||
string::size_type const end = result.find("\")", pos);
|
||||
string const file = result.substr(pos + 12, end - (pos + 12));
|
||||
string contents;
|
||||
if (buffer) {
|
||||
Path p(buffer->filePath());
|
||||
if (!IsFileReadable(file))
|
||||
Path p(buffer->tmppath);
|
||||
if (IsFileReadable(file))
|
||||
contents = GetFileContents(file);
|
||||
} else {
|
||||
contents = GetFileContents(file);
|
||||
}
|
||||
result = subst(result,
|
||||
("$$Contents(\"" + file + "\")").c_str(),
|
||||
contents);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void InsetExternal::updateExternal(string const & format,
|
||||
Buffer const * buf,
|
||||
bool external_in_tmpdir) const
|
||||
@ -499,7 +470,8 @@ void InsetExternal::updateExternal(string const & format,
|
||||
return;
|
||||
}
|
||||
|
||||
string const to_file = doSubstitution(buf, outputFormat.updateResult);
|
||||
string const to_file = doSubstitution(params_, buf,
|
||||
outputFormat.updateResult);
|
||||
|
||||
FileInfo fi(from_file);
|
||||
string abs_to_file = to_file;
|
||||
@ -517,18 +489,57 @@ void InsetExternal::updateExternal(string const & format,
|
||||
}
|
||||
|
||||
|
||||
void InsetExternal::editExternal() const
|
||||
{
|
||||
ExternalTemplate const & et = params_.templ;
|
||||
if (et.editCommand.empty())
|
||||
return;
|
||||
namespace {
|
||||
|
||||
BufferView const * bv = renderer_->view();
|
||||
Buffer const * buffer = bv ? bv->buffer() : 0;
|
||||
/// Substitute meta-variables in this string
|
||||
string const doSubstitution(InsetExternal::Params const & params,
|
||||
Buffer const * buffer, string const & s)
|
||||
{
|
||||
string result;
|
||||
string const basename = ChangeExtension(params.filename, string());
|
||||
string filepath;
|
||||
|
||||
result = subst(s, "$$FName", params.filename);
|
||||
result = subst(result, "$$Basename", basename);
|
||||
result = subst(result, "$$FPath", filepath);
|
||||
result = subst(result, "$$Tempname", params.tempname);
|
||||
result = subst(result, "$$Sysdir", system_lyxdir);
|
||||
|
||||
// Handle the $$Contents(filename) syntax
|
||||
if (contains(result, "$$Contents(\"")) {
|
||||
|
||||
string::size_type const pos = result.find("$$Contents(\"");
|
||||
string::size_type const end = result.find("\")", pos);
|
||||
string const file = result.substr(pos + 12, end - (pos + 12));
|
||||
string contents;
|
||||
if (buffer) {
|
||||
Path p(buffer->filePath());
|
||||
if (!IsFileReadable(file))
|
||||
Path p(buffer->tmppath);
|
||||
if (IsFileReadable(file))
|
||||
contents = GetFileContents(file);
|
||||
} else {
|
||||
contents = GetFileContents(file);
|
||||
}
|
||||
result = subst(result,
|
||||
("$$Contents(\"" + file + "\")").c_str(),
|
||||
contents);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void editExternal(InsetExternal::Params const & params, Buffer const * buffer)
|
||||
{
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
string const command = doSubstitution(buffer, et.editCommand);
|
||||
ExternalTemplate const & et = params.templ;
|
||||
if (et.editCommand.empty())
|
||||
return;
|
||||
|
||||
string const command = doSubstitution(params, buffer, et.editCommand);
|
||||
|
||||
Path p(buffer->filePath());
|
||||
Forkedcall call;
|
||||
@ -539,6 +550,7 @@ void InsetExternal::editExternal() const
|
||||
call.startscript(Forkedcall::DontWait, command);
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
string const InsetExternalMailer::name_("external");
|
||||
|
||||
|
@ -29,8 +29,11 @@ public:
|
||||
/// hold parameters settable from the GUI
|
||||
struct Params {
|
||||
Params();
|
||||
~Params();
|
||||
/// the filename
|
||||
string filename;
|
||||
/// The name of the tempfile used for manipulations.
|
||||
string tempname;
|
||||
/// the current template used
|
||||
ExternalTemplate templ;
|
||||
/// how the inset is displayed by LyX
|
||||
@ -46,10 +49,6 @@ public:
|
||||
virtual ~InsetExternal();
|
||||
///
|
||||
virtual dispatch_result localDispatch(FuncRequest const & cmd);
|
||||
/** Would not be needed if editExternal were dispatched properly from
|
||||
* the frontends rather than being invoked directly.
|
||||
*/
|
||||
virtual void cache(BufferView *) const;
|
||||
///
|
||||
void metrics(MetricsInfo &, Dimension &) const;
|
||||
///
|
||||
@ -97,9 +96,6 @@ public:
|
||||
void updateExternal(string const &, Buffer const *,
|
||||
bool external_in_tmpdir) const;
|
||||
|
||||
/// edit file of this template
|
||||
void editExternal() const;
|
||||
|
||||
/// return a copy of our current params
|
||||
Params const & params() const;
|
||||
|
||||
@ -117,15 +113,9 @@ private:
|
||||
int write(string const & format, Buffer const *, std::ostream &,
|
||||
bool external_in_tmpdir = false) const;
|
||||
|
||||
/// Substitute meta-variables in this string
|
||||
string const doSubstitution(Buffer const *, string const & s) const;
|
||||
|
||||
/// the current params
|
||||
Params params_;
|
||||
|
||||
/// A temp filename
|
||||
mutable string tempname_;
|
||||
|
||||
/// The thing that actually draws the image on LyX's screen.
|
||||
boost::scoped_ptr<GraphicInset> const renderer_;
|
||||
};
|
||||
|
@ -335,6 +335,7 @@ enum kb_action {
|
||||
// 255
|
||||
LFUN_PARAGRAPH_APPLY,
|
||||
LFUN_PARAGRAPH_UPDATE,
|
||||
LFUN_EXTERNAL_EDIT,
|
||||
|
||||
LFUN_LASTACTION // end of the table
|
||||
};
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "ParagraphParameters.h"
|
||||
|
||||
#include "insets/insetcommand.h"
|
||||
#include "insets/insetexternal.h"
|
||||
#include "insets/insettabular.h"
|
||||
|
||||
#include "mathed/formulamacro.h"
|
||||
@ -1588,6 +1589,12 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
|
||||
owner->getDialogs().toggleTooltips();
|
||||
break;
|
||||
|
||||
case LFUN_EXTERNAL_EDIT: {
|
||||
InsetExternal()
|
||||
.localDispatch(FuncRequest(view(), action, argument));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
// Then if it was none of the above
|
||||
// Trying the BufferView::pimpl dispatch:
|
||||
|
Loading…
x
Reference in New Issue
Block a user