+
#include <config.h>
#include <cstdlib>
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 (getContents(), 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;
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"));
}
}
}
-string InsetInclude::getScreenLabel() const
+string const InsetInclude::getScreenLabel() const
{
string temp;
if (isInput())
}
-void InsetInclude::setContents(string const & c)
+string const InsetInclude::getFileName() const
{
- InsetCommand::setContents(c);
- filename = MakeAbsPath(getContents(),
- OnlyPath(getMasterFilename()));
+ return MakeAbsPath(getContents(),
+ OnlyPath(getMasterFilename()));
+}
+
+
+string const InsetInclude::getMasterFilename() const
+{
+ return master->fileName();
}
// 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(Buffer const *, ostream & os,
+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 (getContents().empty())
+ if (incfile.empty())
return 0;
- // Use += to force a copy of contents (JMarc)
- // How does that force anything? (Lgb)
- string incfile(getContents());
-
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");
- if (!master->tmppath.empty()
- && !master->niceFile) {
+ 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");
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()) {
}
-int InsetInclude::Linuxdoc(Buffer const *, ostream & os) const
+int InsetInclude::Linuxdoc(Buffer const * buffer, ostream & os) const
{
+ string incfile(getContents());
+
// Do nothing if no file name has been specified
- if (getContents().empty())
+ if (incfile.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) {
+ if (!buffer->tmppath.empty() && !buffer->niceFile) {
incfile = subst(incfile, '/','@');
- writefile = AddName(master->tmppath, incfile);
+ writefile = AddName(buffer->tmppath, incfile);
} else
writefile = getFileName();
- if(IsLyXFilename(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);
+ tmp->makeLinuxDocFile(writefile, buffer->niceFile, true);
}
if (isVerb()) {
- os << "<!-- includefile verbatim=\"" << incfile << "\" -->";
+ os << "<inlinegraphic fileref=\"" << '&' << include_label << ';'
+ << "\" format=\"linespecific\">"
+ << "</inlinegraphic>";
} else
os << '&' << include_label << ';';
}
-int InsetInclude::DocBook(Buffer const *, ostream & os) const
+int InsetInclude::DocBook(Buffer const * buffer, ostream & os) const
{
+ string incfile(getContents());
+
// Do nothing if no file name has been specified
- if (getContents().empty())
+ if (incfile.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) {
+ if (!buffer->tmppath.empty() && !buffer->niceFile) {
incfile = subst(incfile, '/','@');
- writefile = AddName(master->tmppath, incfile);
+ writefile = AddName(buffer->tmppath, incfile);
} else
writefile = getFileName();
- if(IsLyXFilename(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);
+ tmp->makeDocBookFile(writefile, buffer->niceFile, true);
}
if (isVerb()) {
- os << "<!-- includefile verbatim=\"" << incfile << "\" -->";
+ os << "<inlinegraphic fileref=\"" << '&' << include_label << ';'
+ << "\" format=\"linespecific\">"
+ << "</inlinegraphic>";
} else
os << '&' << include_label << ';';
}
-static unsigned int unique_id() {
- static unsigned int seed=1000;
-
- return ++seed;
-}
-
-
void InsetInclude::Validate(LaTeXFeatures & features) const
{
-#ifdef HAVE_SSTREAM
- std::ostringstream ost;
- ost << "file" << unique_id();
- include_label = ost.str();
-#else
- char ctmp[16];
- ostrstream ost(ctmp,16);
- ost << "file" << unique_id() << '\0';
- include_label = ost.str();
-#endif
-
string incfile(getContents());
- string writefile = ChangeExtension(getFileName(), ".sgml");
+ string writefile; // = ChangeExtension(getFileName(), ".sgml");
+
if (!master->tmppath.empty() && !master->niceFile) {
incfile = subst(incfile, '/','@');
writefile = AddName(master->tmppath, incfile);
} else
- // writefile = getFileName();
+ writefile = getFileName();
// Use the relative path.
- writefile = incfile;
+ //writefile = incfile;
- if(IsLyXFilename(getFileName()))
+ if (IsLyXFilename(getFileName()))
writefile = ChangeExtension(writefile, ".sgml");
features.IncludedFiles[include_label] = writefile;
}
-vector<string> InsetInclude::getLabelList() const
+vector<string> const InsetInclude::getLabelList() const
{
- vector<string> l;
- string parentname;
+ vector<string> l;
- if (loadIfNeeded()) {
- Buffer * tmp = bufferlist.getBuffer(getFileName());
- tmp->setParentName("");
- l = tmp->getLabelList();
- tmp->setParentName(getMasterFilename());
- }
+ if (loadIfNeeded()) {
+ Buffer * tmp = bufferlist.getBuffer(getFileName());
+ tmp->setParentName("");
+ l = tmp->getLabelList();
+ tmp->setParentName(getMasterFilename());
+ }
- return l;
+ return l;
}
-vector<pair<string,string> > InsetInclude::getKeys() const
+vector<pair<string,string> > const InsetInclude::getKeys() const
{
vector<pair<string,string> > keys;
if (loadIfNeeded()) {
- Buffer *tmp = bufferlist.getBuffer(getFileName());
+ Buffer * tmp = bufferlist.getBuffer(getFileName());
tmp->setParentName("");
- keys = tmp->getBibkeyList();
+ keys = tmp->getBibkeyList();
tmp->setParentName(getMasterFilename());
}