2000-06-12 11:27:15 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-2000 The LyX Team.
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
#include <cstdio>
|
2001-03-07 14:25:31 +00:00
|
|
|
#include <utility>
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
#include "insetexternal.h"
|
|
|
|
#include "ExternalTemplate.h"
|
|
|
|
#include "lyx_gui_misc.h" // CancelCloseBoxCB
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "buffer.h"
|
2001-03-07 14:25:31 +00:00
|
|
|
#include "frontends/FileDialog.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
#include "lyx_main.h"
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/path.h"
|
|
|
|
#include "support/syscall.h"
|
2000-11-28 06:46:06 +00:00
|
|
|
#include "frontends/Dialogs.h" // redrawGUI
|
|
|
|
|
|
|
|
#ifdef SIGC_CXX_NAMESPACES
|
|
|
|
using SigC::slot;
|
|
|
|
#endif
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
using std::endl;
|
2001-03-07 14:25:31 +00:00
|
|
|
using std::pair;
|
|
|
|
using std::make_pair;
|
2000-06-15 15:44:39 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
InsetExternal::InsetExternal()
|
|
|
|
: form_external(0)
|
|
|
|
{
|
2001-01-08 09:37:13 +00:00
|
|
|
tempname = lyx::tempName(string(), "lyxext");
|
2000-11-28 06:46:06 +00:00
|
|
|
r_ = Dialogs::redrawGUI.connect(slot(this, &InsetExternal::redraw));
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
|
|
|
|
InsetExternal::~InsetExternal()
|
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
lyx::unlink(tempname);
|
2000-11-28 06:46:06 +00:00
|
|
|
r_.disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::redraw()
|
|
|
|
{
|
|
|
|
if (form_external && form_external->form_external->visible)
|
|
|
|
fl_redraw_form(form_external->form_external);
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
extern "C"
|
|
|
|
void ExternalTemplateCB(FL_OBJECT * ob, long data)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
InsetExternal::templateCB(ob, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
extern "C"
|
|
|
|
void ExternalBrowseCB(FL_OBJECT * ob, long data)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
InsetExternal::browseCB(ob, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
extern "C"
|
|
|
|
void ExternalEditCB(FL_OBJECT * ob, long data)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
InsetExternal::editCB(ob, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
extern "C"
|
|
|
|
void ExternalViewCB(FL_OBJECT * ob, long data)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
InsetExternal::viewCB(ob, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
extern "C"
|
|
|
|
void ExternalUpdateCB(FL_OBJECT * ob, long data)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
InsetExternal::updateCB(ob, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
extern "C"
|
|
|
|
void ExternalOKCB(FL_OBJECT * ob, long data)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
InsetExternal::okCB(ob, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
extern "C"
|
|
|
|
void ExternalCancelCB(FL_OBJECT * ob, long data)
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
InsetExternal::cancelCB(ob, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::templateCB(FL_OBJECT * ob, long)
|
|
|
|
{
|
|
|
|
Holder * holder = static_cast<Holder*>(ob->form->u_vdata);
|
|
|
|
InsetExternal * inset = holder->inset;
|
|
|
|
ExternalTemplate et = inset->getTemplate(inset->getCurrentTemplate());
|
|
|
|
// Update the help text
|
|
|
|
fl_clear_browser(inset->form_external->helptext);
|
|
|
|
fl_addto_browser(inset->form_external->helptext, et.helpText.c_str());
|
|
|
|
fl_set_browser_topline(inset->form_external->helptext, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::browseCB(FL_OBJECT * ob, long)
|
|
|
|
{
|
|
|
|
Holder * holder = static_cast<Holder*>(ob->form->u_vdata);
|
|
|
|
InsetExternal * inset = holder->inset;
|
|
|
|
|
|
|
|
static string current_path;
|
|
|
|
static int once = 0;
|
|
|
|
|
|
|
|
string p = inset->filename;
|
|
|
|
string buf = MakeAbsPath(holder->view->buffer()->fileName());
|
|
|
|
string buf2 = OnlyPath(buf);
|
|
|
|
if (!p.empty()) {
|
|
|
|
buf = MakeAbsPath(p, buf2);
|
|
|
|
buf = OnlyPath(buf);
|
|
|
|
} else {
|
2000-09-26 13:54:57 +00:00
|
|
|
buf = OnlyPath(holder->view->buffer()->fileName());
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
2001-03-07 14:25:31 +00:00
|
|
|
FileDialog fileDlg(holder->view->owner(), _("Select external file"),
|
|
|
|
LFUN_SELECT_FILE_SYNC,
|
|
|
|
make_pair(string(_("Document")), string(buf)));
|
|
|
|
|
|
|
|
// FIXME: should have "nice name" for file type e.g. "Xfig files"
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
/// Determine the template file extension
|
|
|
|
ExternalTemplate et = inset->getTemplate(inset->getCurrentTemplate());
|
|
|
|
string regexp = et.fileRegExp;
|
|
|
|
if (regexp.empty()) {
|
|
|
|
regexp = "*";
|
|
|
|
}
|
|
|
|
|
2001-03-07 14:25:31 +00:00
|
|
|
regexp += "|";
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
bool error = false;
|
|
|
|
do {
|
2001-03-07 14:25:31 +00:00
|
|
|
string const path = (once) ? current_path : buf;
|
|
|
|
FileDialog::Result result = fileDlg.Select(path, regexp);
|
|
|
|
|
|
|
|
if (result.second.empty())
|
|
|
|
return;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
2001-03-07 14:25:31 +00:00
|
|
|
string p = result.second;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
buf = MakeRelPath(p, buf2);
|
|
|
|
current_path = OnlyPath(p);
|
|
|
|
once = 1;
|
|
|
|
|
|
|
|
if (contains(p, "#") || contains(p, "~") || contains(p, "$")
|
|
|
|
|| contains(p, "%")) {
|
|
|
|
WriteAlert(_("Filename can't contain any "
|
|
|
|
"of these characters:"),
|
|
|
|
// xgettext:no-c-format
|
|
|
|
_("'#', '~', '$' or '%'."));
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
} while (error);
|
|
|
|
|
|
|
|
if (inset->form_external)
|
|
|
|
fl_set_input(inset->form_external->filename, buf.c_str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::editCB(FL_OBJECT * ob, long)
|
|
|
|
{
|
|
|
|
Holder * holder = static_cast<Holder*>(ob->form->u_vdata);
|
|
|
|
InsetExternal * inset = holder->inset;
|
|
|
|
inset->doApply(holder->view);
|
|
|
|
inset->doEdit(holder->view);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::viewCB(FL_OBJECT * ob, long)
|
|
|
|
{
|
|
|
|
Holder * holder = static_cast<Holder*>(ob->form->u_vdata);
|
|
|
|
InsetExternal * inset = holder->inset;
|
|
|
|
inset->doApply(holder->view);
|
|
|
|
inset->doView(holder->view);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::updateCB(FL_OBJECT * ob, long)
|
|
|
|
{
|
|
|
|
Holder * holder = static_cast<Holder*>(ob->form->u_vdata);
|
|
|
|
InsetExternal * inset = holder->inset;
|
|
|
|
inset->doApply(holder->view);
|
|
|
|
inset->doUpdate(holder->view);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::okCB(FL_OBJECT * ob, long data)
|
|
|
|
{
|
|
|
|
Holder * holder = static_cast<Holder*>(ob->form->u_vdata);
|
|
|
|
InsetExternal * inset = holder->inset;
|
|
|
|
inset->doApply(holder->view);
|
|
|
|
cancelCB(ob,data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::doApply(BufferView * bufview)
|
|
|
|
{
|
|
|
|
bool update = false;
|
|
|
|
if (templatename != getCurrentTemplate()) {
|
2000-06-15 15:44:39 +00:00
|
|
|
templatename = getCurrentTemplate();
|
2000-06-12 11:27:15 +00:00
|
|
|
update = true;
|
|
|
|
}
|
|
|
|
if (filename != fl_get_input(form_external->filename)) {
|
2000-06-15 15:44:39 +00:00
|
|
|
filename = fl_get_input(form_external->filename);
|
2000-06-12 11:27:15 +00:00
|
|
|
update = true;
|
|
|
|
}
|
|
|
|
if (parameters != fl_get_input(form_external->parameters)) {
|
2000-06-15 15:44:39 +00:00
|
|
|
parameters = fl_get_input(form_external->parameters);
|
2000-06-12 11:27:15 +00:00
|
|
|
update = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update) {
|
2000-06-15 15:44:39 +00:00
|
|
|
// The text might have change,
|
|
|
|
// so we should update the button look
|
|
|
|
bufview->updateInset(this, true);
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::cancelCB(FL_OBJECT * ob, long)
|
|
|
|
{
|
|
|
|
Holder * holder = static_cast<Holder*>(ob->form->u_vdata);
|
|
|
|
|
|
|
|
InsetExternal * inset = holder->inset;
|
2000-06-15 15:44:39 +00:00
|
|
|
// BufferView * bv = holder->view;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
|
|
|
if (inset->form_external) {
|
|
|
|
fl_hide_form(inset->form_external->form_external);
|
|
|
|
fl_free_form(inset->form_external->form_external);
|
|
|
|
inset->form_external = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const InsetExternal::EditMessage() const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
ExternalTemplate const & et = getTemplate(templatename);
|
2000-09-14 17:53:12 +00:00
|
|
|
return doSubstitution(0, et.guiName);
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::Edit(BufferView * bv,
|
|
|
|
int /*x*/, int /*y*/, unsigned int /*button*/)
|
|
|
|
{
|
|
|
|
static int ow = -1, oh;
|
|
|
|
|
|
|
|
if (bv->buffer()->isReadonly())
|
|
|
|
WarnReadonly(bv->buffer()->fileName());
|
|
|
|
|
|
|
|
if (!form_external) {
|
|
|
|
form_external = create_form_form_external();
|
|
|
|
holder.inset = this;
|
|
|
|
// form_external->ok->u_vdata = &holder;
|
|
|
|
form_external->form_external->u_vdata = &holder;
|
|
|
|
fl_set_form_atclose(form_external->form_external,
|
|
|
|
CancelCloseBoxCB, 0);
|
|
|
|
}
|
|
|
|
holder.view = bv;
|
2000-07-15 23:51:46 +00:00
|
|
|
fl_addto_choice(form_external->templatechoice,
|
|
|
|
getTemplateString().c_str());
|
2000-06-12 11:27:15 +00:00
|
|
|
fl_set_input(form_external->filename, filename.c_str());
|
|
|
|
fl_set_input(form_external->parameters, parameters.c_str());
|
|
|
|
if (!templatename.empty()) {
|
2000-06-15 15:44:39 +00:00
|
|
|
fl_set_choice(form_external->templatechoice,
|
|
|
|
getTemplateNumber(templatename));
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
// Update the help text
|
|
|
|
templateCB(form_external->templatechoice, 0);
|
|
|
|
|
|
|
|
ExternalTemplate const & et = getTemplate(templatename);
|
|
|
|
if (et.automaticProduction) {
|
|
|
|
fl_deactivate_object(form_external->update);
|
|
|
|
fl_set_object_lcol(form_external->update, FL_INACTIVE);
|
|
|
|
} else {
|
|
|
|
fl_activate_object(form_external->update);
|
|
|
|
fl_set_object_lcol(form_external->update, FL_BLACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (form_external->form_external->visible) {
|
|
|
|
fl_raise_form(form_external->form_external);
|
|
|
|
} else {
|
|
|
|
fl_show_form(form_external->form_external,
|
2000-11-08 09:39:46 +00:00
|
|
|
FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
|
|
|
|
_("Insert external inset"));
|
2000-06-12 11:27:15 +00:00
|
|
|
if (ow < 0) {
|
|
|
|
ow = form_external->form_external->w;
|
|
|
|
oh = form_external->form_external->h;
|
|
|
|
}
|
|
|
|
fl_set_form_minsize(form_external->form_external, ow, oh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::Write(Buffer const *, std::ostream & os) const
|
|
|
|
{
|
|
|
|
os << "External " << templatename << ",\"" << filename
|
|
|
|
<< "\",\"" << parameters << "\"\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::Read(Buffer const *, LyXLex & lex)
|
|
|
|
{
|
|
|
|
lex.EatLine();
|
2000-09-27 18:13:30 +00:00
|
|
|
string const format = lex.GetString();
|
|
|
|
string::size_type const pos1 = format.find(",");
|
2000-06-12 11:27:15 +00:00
|
|
|
templatename = format.substr(0, pos1);
|
2000-09-27 18:13:30 +00:00
|
|
|
string::size_type const pos2 = format.find("\",\"", pos1);
|
2000-06-12 11:27:15 +00:00
|
|
|
filename = format.substr(pos1 + 2, pos2 - (pos1 + 2));
|
|
|
|
parameters = format.substr(pos2 + 3, format.length() - (pos2 + 4));
|
|
|
|
|
2000-12-28 16:22:28 +00:00
|
|
|
lyxerr[Debug::INFO] << "InsetExternal::Read: " << templatename
|
|
|
|
<< " " << filename
|
|
|
|
<< " " << parameters << endl;
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
|
|
|
|
int InsetExternal::write(string const & format,
|
|
|
|
Buffer const * buf, std::ostream & os) const
|
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
ExternalTemplate const & et = getTemplate(templatename);
|
|
|
|
ExternalTemplate::Formats::const_iterator cit =
|
|
|
|
et.formats.find(format);
|
2000-06-15 15:44:39 +00:00
|
|
|
if (cit == et.formats.end()) {
|
|
|
|
lyxerr << "External template format '" << format
|
|
|
|
<< "' not specified in template " << templatename
|
|
|
|
<< endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
if (et.automaticProduction) {
|
2000-06-15 15:44:39 +00:00
|
|
|
executeCommand(doSubstitution(buf,
|
|
|
|
(*cit).second.updateCommand),
|
|
|
|
buf);
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
os << doSubstitution(buf, (*cit).second.product);
|
|
|
|
return 0; // CHECK
|
|
|
|
}
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
|
|
|
|
int InsetExternal::Latex(Buffer const * buf,
|
|
|
|
std::ostream & os, bool, bool) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
return write("LaTeX", buf, os);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-26 15:25:14 +00:00
|
|
|
int InsetExternal::Ascii(Buffer const * buf, std::ostream & os, int) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
return write("Ascii", buf, os);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetExternal::Linuxdoc(Buffer const * buf, std::ostream & os) const
|
|
|
|
{
|
|
|
|
return write("LinuxDoc", buf, os);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetExternal::DocBook(Buffer const * buf, std::ostream & os) const
|
|
|
|
{
|
|
|
|
return write("DocBook", buf, os);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::Validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
ExternalTemplate const & et = getTemplate(templatename);
|
|
|
|
ExternalTemplate::Formats::const_iterator cit =
|
|
|
|
et.formats.find("LaTeX");
|
2000-06-15 15:44:39 +00:00
|
|
|
if (cit == et.formats.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
if (!(*cit).second.requirement.empty()) {
|
|
|
|
features.require((*cit).second.requirement);
|
|
|
|
}
|
|
|
|
if (!(*cit).second.preamble.empty()) {
|
|
|
|
features.externalPreambles += (*cit).second.preamble + "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-10 11:50:43 +00:00
|
|
|
Inset * InsetExternal::Clone(Buffer const &) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
InsetExternal * inset = new InsetExternal();
|
|
|
|
inset->templatename = templatename;
|
|
|
|
inset->filename = filename;
|
|
|
|
inset->parameters = parameters;
|
|
|
|
return inset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const InsetExternal::getScreenLabel() const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
if (templatename.empty()) {
|
|
|
|
return _("External");
|
|
|
|
} else {
|
|
|
|
ExternalTemplate const & et = getTemplate(templatename);
|
2000-12-17 06:09:35 +00:00
|
|
|
if (et.guiName.empty())
|
|
|
|
return "ext: ???";
|
|
|
|
else
|
|
|
|
return doSubstitution(0, et.guiName);
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::doUpdate(BufferView const * bv) const
|
|
|
|
{
|
|
|
|
ExternalTemplate const & et = getTemplate(getCurrentTemplate());
|
|
|
|
ExternalTemplate::Formats::const_iterator cit =
|
|
|
|
et.formats.find("LaTeX");
|
2000-06-15 15:44:39 +00:00
|
|
|
if (cit == et.formats.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
executeCommand(doSubstitution(bv->buffer(),
|
|
|
|
(*cit).second.updateCommand),
|
|
|
|
bv->buffer());
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::doView(BufferView const * bv) const
|
|
|
|
{
|
|
|
|
automaticUpdate(bv);
|
|
|
|
ExternalTemplate const & et = getTemplate(getCurrentTemplate());
|
2000-06-15 15:44:39 +00:00
|
|
|
executeCommand(doSubstitution(bv->buffer(), et.viewCommand),
|
|
|
|
bv->buffer());
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::doEdit(BufferView const * bv) const
|
|
|
|
{
|
|
|
|
automaticUpdate(bv);
|
|
|
|
ExternalTemplate const & et = getTemplate(getCurrentTemplate());
|
2000-06-15 15:44:39 +00:00
|
|
|
executeCommand(doSubstitution(bv->buffer(), et.editCommand),
|
|
|
|
bv->buffer());
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-15 15:44:39 +00:00
|
|
|
void InsetExternal::executeCommand(string const & s,
|
|
|
|
Buffer const * buffer) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
string buf = MakeAbsPath(buffer->fileName());
|
|
|
|
string path = OnlyPath(buf);
|
|
|
|
Path p(path);
|
|
|
|
Systemcalls one;
|
|
|
|
if (lyxerr.debugging()) {
|
2000-06-15 15:44:39 +00:00
|
|
|
lyxerr << "Executing '" << s << "' in '"
|
|
|
|
<< path << "'" << endl;
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
one.startscript(Systemcalls::Wait, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetExternal::automaticUpdate(BufferView const * bv) const
|
|
|
|
{
|
|
|
|
ExternalTemplate const & et = getTemplate(templatename);
|
|
|
|
if (et.automaticProduction) {
|
|
|
|
doUpdate(bv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const InsetExternal::doSubstitution(Buffer const * buffer,
|
2000-06-15 15:44:39 +00:00
|
|
|
string const & s) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
string result;
|
2000-09-27 18:13:30 +00:00
|
|
|
string const basename = ChangeExtension(filename, string());
|
2000-06-12 11:27:15 +00:00
|
|
|
result = subst(s, "$$FName", filename);
|
|
|
|
result = subst(result, "$$Basename", basename);
|
|
|
|
result = subst(result, "$$Parameters", parameters);
|
|
|
|
result = ReplaceEnvironmentPath(result);
|
|
|
|
result = subst(result, "$$Tempname", tempname);
|
|
|
|
result = subst(result, "$$Sysdir", system_lyxdir);
|
|
|
|
|
|
|
|
// Handle the $$Contents(filename) syntax
|
|
|
|
if (contains(result, "$$Contents(\"")) {
|
|
|
|
|
2000-09-27 18:13:30 +00:00
|
|
|
string::size_type const pos = result.find("$$Contents(\"");
|
|
|
|
string::size_type const end = result.find("\")", pos);
|
2000-09-26 13:54:57 +00:00
|
|
|
string const file = result.substr(pos + 12, end - (pos + 12));
|
2000-06-12 11:27:15 +00:00
|
|
|
string contents;
|
|
|
|
if (buffer) {
|
|
|
|
// Make sure we are in the directory of the buffer
|
2000-09-26 13:54:57 +00:00
|
|
|
string const buf = MakeAbsPath(buffer->fileName());
|
|
|
|
string const path = OnlyPath(buf);
|
2000-06-12 11:27:15 +00:00
|
|
|
Path p(path);
|
|
|
|
contents = GetFileContents(file);
|
|
|
|
} else {
|
|
|
|
contents = GetFileContents(file);
|
|
|
|
}
|
2000-06-15 15:44:39 +00:00
|
|
|
result = subst(result,
|
|
|
|
("$$Contents(\"" + file + "\")").c_str(),
|
|
|
|
contents);
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const InsetExternal::getCurrentTemplate() const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
return getTemplateName(fl_get_choice(form_external->templatechoice));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
ExternalTemplate const InsetExternal::getTemplate(string const & name) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
ExternalTemplateManager::Templates::iterator i =
|
2000-06-12 11:27:15 +00:00
|
|
|
ExternalTemplateManager::get().getTemplates().find(name);
|
|
|
|
// Make sure that the template exists in the map
|
|
|
|
if (i == ExternalTemplateManager::get().getTemplates().end()) {
|
2000-06-15 15:44:39 +00:00
|
|
|
lyxerr << "Unknown external material template: "
|
|
|
|
<< name << endl;
|
2000-06-12 11:27:15 +00:00
|
|
|
return ExternalTemplate();
|
|
|
|
}
|
|
|
|
return (*i).second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetExternal::getTemplateNumber(string const & name) const
|
|
|
|
{
|
|
|
|
int i = 1;
|
|
|
|
ExternalTemplateManager::Templates::const_iterator i1, i2;
|
|
|
|
i1 = ExternalTemplateManager::get().getTemplates().begin();
|
|
|
|
i2 = ExternalTemplateManager::get().getTemplates().end();
|
|
|
|
for (; i1 != i2; ++i1) {
|
|
|
|
if ((*i1).second.lyxName == name)
|
|
|
|
return i;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
// This should never happen
|
2000-12-17 06:09:35 +00:00
|
|
|
/// This can happen if someone sends you a lyx file that uses
|
|
|
|
/// external templates that are defined only on his machine
|
|
|
|
//Assert(false);
|
2000-06-12 11:27:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const InsetExternal::getTemplateName(int i) const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
ExternalTemplateManager::Templates::const_iterator i1;
|
|
|
|
i1 = ExternalTemplateManager::get().getTemplates().begin();
|
|
|
|
for (int n = 1; n < i; ++n) {
|
|
|
|
++i1;
|
|
|
|
}
|
|
|
|
return (*i1).second.lyxName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const InsetExternal::getTemplateString() const
|
2000-06-12 11:27:15 +00:00
|
|
|
{
|
|
|
|
string result;
|
|
|
|
bool first = true;
|
|
|
|
ExternalTemplateManager::Templates::const_iterator i1, i2;
|
|
|
|
i1 = ExternalTemplateManager::get().getTemplates().begin();
|
|
|
|
i2 = ExternalTemplateManager::get().getTemplates().end();
|
|
|
|
for (; i1 != i2; ++i1) {
|
|
|
|
if (!first) {
|
|
|
|
result += "|";
|
|
|
|
} else {
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
result += (*i1).second.lyxName;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|