+
#include <config.h>
#include <cstdlib>
#include "layout.h"
#include "lyxfunc.h"
+using std::ostream;
+using std::endl;
+using std::vector;
+using std::pair;
+
extern BufferView * current_view;
extern BufferList bufferlist;
FD_include * form = 0;
-extern "C" void include_cb(FL_OBJECT *, long arg)
+extern "C"
+void include_cb(FL_OBJECT *, long arg)
{
InsetInclude * inset = static_cast<InsetInclude*>(form->include->u_vdata);
{
// Should browsing too be disabled in RO-mode?
LyXFileDlg fileDlg;
- string mpath = OnlyPath(inset->getMasterFilename());
+ string const mpath = OnlyPath(inset->getMasterFilename());
string ext;
if (fl_get_button(form->flag2)) // Use Input Button
fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
// Use by default the master's path
- string filename = fileDlg.Select(_("Select Child Document"),
- mpath, ext,
- inset->getContents());
+ string const filename =
+ fileDlg.Select(_("Select Child Document"),
+ mpath, ext,
+ inset->getContents());
XFlush(fl_get_display());
// check selected filename
if (!filename.empty()) {
- string filename2 = MakeRelPath(filename,
- mpath);
+ string const filename2 = MakeRelPath(filename,
+ mpath);
if (prefixIs(filename2, ".."))
fl_set_input(form->input,
filename.c_str());
}
case 1:
- if(!current_view->buffer()->isReadonly()) {
+ if (!current_view->buffer()->isReadonly()) {
inset->setContents(fl_get_input(form->input));
// don't typeset
inset->setNoLoad(fl_get_button(form->flag1));
fl_hide_form(form->include);
break;
case 5:
- if(!current_view->buffer()->isReadonly()) {
+ if (!current_view->buffer()->isReadonly()) {
inset->setContents(fl_get_input(form->input));
inset->setNoLoad(fl_get_button(form->flag1));
if (fl_get_button(form->flag2))
fl_hide_form(form->include);
current_view->updateInset(inset, true);
- current_view->owner()->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, inset->getContents().c_str());
+ current_view->owner()->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, inset->getContents());
}
break;
}
-InsetInclude::InsetInclude(string const & fname, Buffer * bf)
- : InsetCommand("include")
+static inline
+string unique_id() {
+ static unsigned int seed = 1000;
+
+ std::ostringstream ost;
+ ost << "file" << ++seed;
+
+ // Needed if we use lyxstring.
+ return ost.str().c_str();
+}
+
+
+InsetInclude::InsetInclude(InsetCommandParams const & p, Buffer const & bf)
+ : InsetCommand(p), master(&bf)
{
- master = bf;
- setContents(fname);
flag = InsetInclude::INCLUDE;
noload = false;
+ include_label = unique_id();
}
}
-Inset * InsetInclude::Clone() const
+Inset * InsetInclude::Clone(Buffer const & buffer) const
{
- InsetInclude * ii = new InsetInclude (contents, master);
+ InsetInclude * ii = new InsetInclude (params(), buffer);
ii->setNoLoad(isNoLoad());
// By default, the newly created inset is of `include' type,
// so we do not test this case.
void InsetInclude::Edit(BufferView * bv, int, int, unsigned int)
{
- if(bv->buffer()->isReadonly())
+ if (bv->buffer()->isReadonly())
WarnReadonly(bv->buffer()->fileName());
if (!form) {
form = create_form_include();
- fl_set_form_atclose(form->include, IgnoreCloseBoxCB, 0);
+ fl_set_form_atclose(form->include, CancelCloseBoxCB, 0);
}
form->include->u_vdata = this;
- fl_set_input(form->input, contents.c_str());
+ fl_set_input(form->input, getContents().c_str());
fl_set_button(form->flag1, int(isNoLoad()));
fl_set_button(form->flag2, int(isInput()));
fl_set_button(form->flag3, int(isInclude()));
if (form->include->visible) {
fl_raise_form(form->include);
} else {
- fl_show_form(form->include, FL_PLACE_MOUSE, FL_FULLBORDER,
+ fl_show_form(form->include,
+ FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
_("Include"));
}
}
-void InsetInclude::Write(ostream & os) const
+void InsetInclude::Write(Buffer const *, ostream & os) const
{
os << "Include " << getCommand() << "\n";
}
-void InsetInclude::Read(LyXLex & lex)
+void InsetInclude::Read(Buffer const * buf, LyXLex & lex)
{
- InsetCommand::Read(lex);
+ InsetCommand::Read(buf, lex);
if (getCmdName() == "include")
setInclude();
}
-string InsetInclude::getScreenLabel() const
+bool InsetInclude::display() const
+{
+ return !isInput();
+}
+
+
+string const InsetInclude::getScreenLabel() const
{
string temp;
if (isInput())
} else temp += _("Include");
temp += ": ";
- if (contents.empty()) {
+ if (getContents().empty()) {
temp+= "???";
} else {
- temp+= contents;
+ temp+= getContents();
}
return temp;
}
+string const InsetInclude::getFileName() const
+{
+ return MakeAbsPath(getContents(),
+ OnlyPath(getMasterFilename()));
+}
+
+
+string const InsetInclude::getMasterFilename() const
+{
+ return master->fileName();
+}
+
+
bool InsetInclude::loadIfNeeded() const
{
if (isNoLoad() || isVerb()) return false;
// the readonly flag can/will be wrong, not anymore I think.
FileInfo finfo(getFileName());
- bool ro = !finfo.writable();
- return ( bufferlist.readFile(getFileName(), ro) != 0 );
+ bool const ro = !finfo.writable();
+ return bufferlist.readFile(getFileName(), ro) != 0;
}
-int InsetInclude::Latex(ostream & os, signed char /*fragile*/, bool /*fs*/) const
+int InsetInclude::Latex(Buffer const * buffer, ostream & os,
+ bool /*fragile*/, bool /*fs*/) const
{
+ string incfile(getContents());
+
// Do nothing if no file name has been specified
- if (contents.empty())
+ if (incfile.empty())
return 0;
- // Use += to force a copy of contents (JMarc)
- // How does that force anything? (Lgb)
- string incfile(contents);
-
if (loadIfNeeded()) {
Buffer * tmp = bufferlist.getBuffer(getFileName());
- if (tmp->params.textclass != master->params.textclass) {
+ if (tmp->params.textclass != buffer->params.textclass) {
lyxerr << "ERROR: Cannot handle include file `"
<< MakeDisplayPath(getFileName())
<< "' which has textclass `"
<< textclasslist.NameOfClass(tmp->params.textclass)
<< "' instead of `"
- << textclasslist.NameOfClass(master->params.textclass)
+ << textclasslist.NameOfClass(buffer->params.textclass)
<< "'." << endl;
return 0;
}
// write it to a file (so far the complete file)
- string writefile = ChangeExtension(getFileName(), ".tex", false);
- if (!master->tmppath.empty()
- && !master->niceFile) {
+ string writefile = ChangeExtension(getFileName(), ".tex");
+ if (!buffer->tmppath.empty()
+ && !buffer->niceFile) {
incfile = subst(incfile, '/','@');
#ifdef __EMX__
incfile = subst(incfile, ':', '$');
#endif
- writefile = AddName(master->tmppath, incfile);
+ writefile = AddName(buffer->tmppath, incfile);
} else
writefile = getFileName();
- writefile = ChangeExtension(writefile, ".tex", false);
+ writefile = ChangeExtension(writefile, ".tex");
lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
- tmp->markDepClean(master->tmppath);
+ tmp->markDepClean(buffer->tmppath);
tmp->makeLaTeXFile(writefile,
OnlyPath(getMasterFilename()),
- master->niceFile, true);
+ buffer->niceFile, true);
}
if (isVerb()) {
- os << '\\' << command << '{' << incfile << '}';
- }
- else if (isInput()) {
+ os << '\\' << getCmdName() << '{' << incfile << '}';
+ } else if (isInput()) {
// \input wants file with extension (default is .tex)
if (!IsLyXFilename(getFileName())) {
- os << '\\' << command << '{' << incfile << '}';
+ os << '\\' << getCmdName() << '{' << incfile << '}';
} else {
- os << '\\' << command << '{'
- << ChangeExtension(incfile, ".tex", false)
+ os << '\\' << getCmdName() << '{'
+ << ChangeExtension(incfile, ".tex")
<< '}';
}
} else {
// \include don't want extension and demands that the
// file really have .tex
- os << '\\' << command << '{'
- << ChangeExtension(incfile, string(), false)
+ os << '\\' << getCmdName() << '{'
+ << ChangeExtension(incfile, string())
<< '}';
}
}
+int InsetInclude::Linuxdoc(Buffer const * buffer, ostream & os) const
+{
+ string incfile(getContents());
+
+ // Do nothing if no file name has been specified
+ if (incfile.empty())
+ return 0;
+
+ if (loadIfNeeded()) {
+ Buffer * tmp = bufferlist.getBuffer(getFileName());
+
+ // write it to a file (so far the complete file)
+ string writefile = ChangeExtension(getFileName(), ".sgml");
+ if (!buffer->tmppath.empty() && !buffer->niceFile) {
+ incfile = subst(incfile, '/','@');
+ writefile = AddName(buffer->tmppath, incfile);
+ } else
+ writefile = getFileName();
+
+ if (IsLyXFilename(getFileName()))
+ writefile = ChangeExtension(writefile, ".sgml");
+
+ lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
+ lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
+
+ tmp->makeLinuxDocFile(writefile, buffer->niceFile, true);
+ }
+
+ if (isVerb()) {
+ os << "<inlinegraphic fileref=\"" << '&' << include_label << ';'
+ << "\" format=\"linespecific\">"
+ << "</inlinegraphic>";
+ } else
+ os << '&' << include_label << ';';
+
+ return 0;
+}
+
+
+int InsetInclude::DocBook(Buffer const * buffer, ostream & os) const
+{
+ string incfile(getContents());
+
+ // Do nothing if no file name has been specified
+ if (incfile.empty())
+ return 0;
+
+ if (loadIfNeeded()) {
+ Buffer * tmp = bufferlist.getBuffer(getFileName());
+
+ // write it to a file (so far the complete file)
+ string writefile = ChangeExtension(getFileName(), ".sgml");
+ if (!buffer->tmppath.empty() && !buffer->niceFile) {
+ incfile = subst(incfile, '/','@');
+ writefile = AddName(buffer->tmppath, incfile);
+ } else
+ writefile = getFileName();
+ if (IsLyXFilename(getFileName()))
+ writefile = ChangeExtension(writefile, ".sgml");
+
+ lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
+ lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
+
+ tmp->makeDocBookFile(writefile, buffer->niceFile, true);
+ }
+
+ if (isVerb()) {
+ os << "<inlinegraphic fileref=\"" << '&' << include_label << ';'
+ << "\" format=\"linespecific\">"
+ << "</inlinegraphic>";
+ } else
+ os << '&' << include_label << ';';
+
+ return 0;
+}
+
+
void InsetInclude::Validate(LaTeXFeatures & features) const
{
+
+ string incfile(getContents());
+ string writefile; // = ChangeExtension(getFileName(), ".sgml");
+
+ if (!master->tmppath.empty() && !master->niceFile) {
+ incfile = subst(incfile, '/','@');
+ writefile = AddName(master->tmppath, incfile);
+ } else
+ writefile = getFileName();
+ // Use the relative path.
+ //writefile = incfile;
+
+ if (IsLyXFilename(getFileName()))
+ writefile = ChangeExtension(writefile, ".sgml");
+
+ features.IncludedFiles[include_label] = writefile;
+
if (isVerb())
features.verbatim = true;
}
-string InsetInclude::getLabel(int) const
+vector<string> const InsetInclude::getLabelList() const
{
- string label;
- string parentname;
-
-
- if (loadIfNeeded()) {
- Buffer * tmp = bufferlist.getBuffer(getFileName());
- tmp->setParentName("");
- label = tmp->getReferenceList('\n');
- tmp->setParentName(getMasterFilename());
- }
-
- return label;
-}
+ vector<string> l;
+ if (loadIfNeeded()) {
+ Buffer * tmp = bufferlist.getBuffer(getFileName());
+ tmp->setParentName("");
+ l = tmp->getLabelList();
+ tmp->setParentName(getMasterFilename());
+ }
-int InsetInclude::GetNumberOfLabels() const
-{
- string label;
-
- if (loadIfNeeded()) {
- Buffer * tmp = bufferlist.getBuffer(getFileName());
- tmp->setParentName("");
- label = tmp->getReferenceList('\n');
- tmp->setParentName(getMasterFilename());
- }
- int nl = (label.empty())? 0: 1;
-
- return nl;
+ return l;
}
-string InsetInclude::getKeys(char delim) const
+vector<pair<string,string> > const InsetInclude::getKeys() const
{
- string lst;
+ vector<pair<string,string> > keys;
if (loadIfNeeded()) {
- Buffer *tmp = bufferlist.getBuffer(getFileName());
+ Buffer * tmp = bufferlist.getBuffer(getFileName());
tmp->setParentName("");
- lst = tmp->getBibkeyList(delim);
+ keys = tmp->getBibkeyList();
tmp->setParentName(getMasterFilename());
}
- return lst;
+ return keys;
}