#include "include_form.h"
#include "support/FileInfo.h"
#include "layout.h"
+#include "lyxfunc.h"
+
+using std::ostream;
+using std::endl;
+using std::vector;
+using std::pair;
extern BufferView * current_view;
-extern LyXRC * lyxrc;
extern BufferList bufferlist;
-extern void UpdateInset(BufferView *, Inset * inset, bool mark_dirty = true);
FD_include * create_form_include(void)
else
ext = "*.lyx";
// launches dialog
- fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
+ fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
// Use by default the master's path
string filename = fileDlg.Select(_("Select Child Document"),
}
fl_hide_form(form->include);
- UpdateInset(current_view, inset);
+ current_view->updateInset(inset, true);
break;
} // fall through
}
fl_hide_form(form->include);
- UpdateInset(current_view, inset);
+ current_view->updateInset(inset, true);
current_view->owner()->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, inset->getContents().c_str());
}
break;
}
+static string unique_id() {
+ static unsigned int seed=1000;
+
+#ifdef HAVE_SSTREAM
+ std::ostringstream ost;
+ ost << "file" << ++seed;
+#else
+ char ctmp[16];
+ ostrstream ost(ctmp,16);
+ ost << "file" << ++seed << '\0';
+#endif
+
+ return ost.str();
+}
+
+
InsetInclude::InsetInclude(string const & fname, Buffer * bf)
: InsetCommand("include")
{
setContents(fname);
flag = InsetInclude::INCLUDE;
noload = false;
+ include_label = unique_id();
}
Inset * InsetInclude::Clone() const
{
- InsetInclude * ii = new InsetInclude (contents, master);
+ InsetInclude * ii = new InsetInclude (getContents(), master);
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)
+void InsetInclude::Edit(BufferView * bv, int, int, unsigned int)
{
if(bv->buffer()->isReadonly())
WarnReadonly(bv->buffer()->fileName());
}
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()));
}
-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();
}
+bool InsetInclude::display() const
+{
+ return !isInput();
+}
+
+
string InsetInclude::getScreenLabel() const
{
string temp;
} else temp += _("Include");
temp += ": ";
- if (contents.empty()) {
+ if (getContents().empty()) {
temp+= "???";
} else {
- temp+= contents;
+ temp+= getContents();
}
return temp;
}
+void InsetInclude::setContents(string const & c)
+{
+ InsetCommand::setContents(c);
+ filename = MakeAbsPath(getContents(),
+ OnlyPath(getMasterFilename()));
+}
+
+
bool InsetInclude::loadIfNeeded() const
{
if (isNoLoad() || isVerb()) return false;
}
-int InsetInclude::Latex(ostream & os, signed char /*fragile*/) const
+int InsetInclude::Latex(Buffer const *, ostream & os,
+ bool /*fragile*/, bool /*fs*/) const
{
- string include_file;
- signed char dummy = 0;
- Latex(include_file, dummy);
- os << include_file;
- return 0;
-}
-
-
-int InsetInclude::Latex(string & file, signed char /*fragile*/) const
-{
- string writefile, incfile;
-
// Do nothing if no file name has been specified
- if (contents.empty())
+ if (getContents().empty())
return 0;
// Use += to force a copy of contents (JMarc)
- incfile += contents;
+ // How does that force anything? (Lgb)
+ string incfile(getContents());
if (loadIfNeeded()) {
Buffer * tmp = bufferlist.getBuffer(getFileName());
}
// write it to a file (so far the complete file)
- writefile = ChangeExtension(getFileName(), ".tex", false);
+ string writefile = ChangeExtension(getFileName(), ".tex");
if (!master->tmppath.empty()
&& !master->niceFile) {
incfile = subst(incfile, '/','@');
writefile = AddName(master->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;
}
if (isVerb()) {
- file += '\\';
- file += command + '{';
- file += incfile + '}';
- }
- else if (isInput()) {
+ os << '\\' << getCmdName() << '{' << incfile << '}';
+ } else if (isInput()) {
// \input wants file with extension (default is .tex)
if (!IsLyXFilename(getFileName())) {
- file += '\\';
- file += command + '{';
- file += incfile + '}';
+ os << '\\' << getCmdName() << '{' << incfile << '}';
} else {
- file += '\\';
- file += command + '{';
- file += ChangeExtension(incfile, ".tex", false)
- + '}';
+ os << '\\' << getCmdName() << '{'
+ << ChangeExtension(incfile, ".tex")
+ << '}';
}
} else {
// \include don't want extension and demands that the
// file really have .tex
- file += '\\';
- file += command + '{';
- file += ChangeExtension(incfile, string(), false)
- + '}';
+ os << '\\' << getCmdName() << '{'
+ << ChangeExtension(incfile, string())
+ << '}';
}
return 0;
}
+int InsetInclude::Linuxdoc(Buffer const *, ostream & os) const
+{
+ // Do nothing if no file name has been specified
+ if (getContents().empty())
+ return 0;
+
+ string incfile(getContents());
+
+ if (loadIfNeeded()) {
+ Buffer * tmp = bufferlist.getBuffer(getFileName());
+
+ // write it to a file (so far the complete file)
+ string writefile = ChangeExtension(getFileName(), ".sgml");
+ if (!master->tmppath.empty() && !master->niceFile) {
+ incfile = subst(incfile, '/','@');
+ writefile = AddName(master->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, master->niceFile, true);
+ }
+
+ if (isVerb()) {
+ os << "<!-- includefile verbatim=\"" << incfile << "\" -->";
+ } else
+ os << '&' << include_label << ';';
+
+ return 0;
+}
+
+
+int InsetInclude::DocBook(Buffer const *, ostream & os) const
+{
+ // Do nothing if no file name has been specified
+ if (getContents().empty())
+ return 0;
+
+ string incfile(getContents());
+
+ if (loadIfNeeded()) {
+ Buffer * tmp = bufferlist.getBuffer(getFileName());
+
+ // write it to a file (so far the complete file)
+ string writefile = ChangeExtension(getFileName(), ".sgml");
+ if (!master->tmppath.empty() && !master->niceFile) {
+ incfile = subst(incfile, '/','@');
+ writefile = AddName(master->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, master->niceFile, true);
+ }
+
+ if (isVerb()) {
+ os << "<!-- includefile verbatim=\"" << incfile << "\" -->";
+ } 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> InsetInclude::getLabelList() const
{
- string label;
+ vector<string> l;
string parentname;
-
-
+
if (loadIfNeeded()) {
Buffer * tmp = bufferlist.getBuffer(getFileName());
tmp->setParentName("");
- label = tmp->getReferenceList('\n');
+ l = tmp->getLabelList();
tmp->setParentName(getMasterFilename());
}
- return label;
-}
-
-
-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> > InsetInclude::getKeys() const
{
- string lst;
+ vector<pair<string,string> > keys;
if (loadIfNeeded()) {
Buffer *tmp = bufferlist.getBuffer(getFileName());
tmp->setParentName("");
- lst = tmp->getBibkeyList(delim);
+ keys = tmp->getBibkeyList();
tmp->setParentName(getMasterFilename());
}
- return lst;
+ return keys;
}