#include "InsetInclude.h"
-#include "LayoutFile.h"
#include "Buffer.h"
#include "buffer_funcs.h"
#include "BufferList.h"
#include "DispatchResult.h"
#include "ErrorList.h"
#include "Exporter.h"
+#include "Format.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "LaTeXFeatures.h"
+#include "LayoutFile.h"
#include "LyX.h"
+#include "LyXFunc.h"
#include "LyXRC.h"
#include "Lexer.h"
#include "MetricsInfo.h"
#include "insets/InsetListingsParams.h"
#include "insets/RenderPreview.h"
-#include "support/assert.h"
+#include "support/convert.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/FileNameList.h"
#include "support/filetools.h"
#include "support/gettext.h"
+#include "support/lassert.h"
#include "support/lstrings.h" // contains
#include "support/lyxalgo.h"
-#include "support/convert.h"
#include <boost/bind.hpp>
InsetInclude::~InsetInclude()
{
delete label_;
- if (isVerbatim(params()) || isListings(params()))
- return;
-
-
- string const parent_filename = buffer().absFileName();
- FileName const included_file = makeAbsPath(to_utf8(params()["filename"]),
- onlyPath(parent_filename));
-
- if (!isLyXFilename(included_file.absFilename()))
- return;
-
- Buffer * child = theBufferList().getBuffer(included_file.absFilename());
- // File not opened, nothing to close.
- if (!child)
- return;
-
- // Child document has a different parent, don't close it.
- if (child->parent() != &buffer())
- return;
-
- //close the buffer.
- theBufferList().release(child);
}
LASSERT(&cur.buffer() == &buffer(), /**/);
switch (cmd.action) {
+ case LFUN_INSET_EDIT: {
+ editIncluded(to_utf8(params()["filename"]));
+ break;
+ }
+
case LFUN_INSET_MODIFY: {
InsetCommandParams p(INCLUDE_CODE);
- InsetCommand::string2params("include", to_utf8(cmd.argument()), p);
+ if (cmd.getArg(0) == "changetype") {
+ InsetCommand::doDispatch(cur, cmd);
+ p = params();
+ } else
+ InsetCommand::string2params("include", to_utf8(cmd.argument()), p);
if (!p.getCmdName().empty()) {
if (isListings(p)){
InsetListingsParams new_params(to_utf8(p["lstparams"]));
}
+void InsetInclude::editIncluded(string const & file)
+{
+ string const ext = support::getExtension(file);
+ if (ext == "lyx") {
+ FuncRequest fr(LFUN_BUFFER_CHILD_OPEN, file);
+ lyx::dispatch(fr);
+ } else
+ // tex file or other text file in verbatim mode
+ formats.edit(buffer(),
+ support::makeAbsPath(file, support::onlyPath(buffer().absFileName())),
+ "text");
+}
+
+
+bool InsetInclude::getStatus(Cursor & cur, FuncRequest const & cmd,
+ FuncStatus & flag) const
+{
+ switch (cmd.action) {
+
+ case LFUN_INSET_EDIT:
+ case LFUN_INSET_MODIFY:
+ flag.setEnabled(true);
+ return true;
+
+ default:
+ return InsetCommand::getStatus(cur, cmd, flag);
+ }
+}
+
+
void InsetInclude::setParams(InsetCommandParams const & p)
{
InsetCommand::setParams(p);
if (!isLyXFilename(included_file.absFilename()))
return 0;
- Buffer * child = theBufferList().getBuffer(included_file.absFilename());
+ Buffer * child = theBufferList().getBuffer(included_file);
if (!child) {
// the readonly flag can/will be wrong, not anymore I think.
if (!included_file.exists())
if (!loadIfNeeded(buffer(), params()))
return false;
- Buffer * tmp = theBufferList().getBuffer(included_file.absFilename());
+ Buffer * tmp = theBufferList().getBuffer(included_file);
if (tmp->params().baseClass() != masterBuffer->params().baseClass()) {
// FIXME UNICODE
DocFileName writefile(changeExtension(included_file, ".sgml"));
if (loadIfNeeded(buffer(), params())) {
- Buffer * tmp = theBufferList().getBuffer(included_file);
+ Buffer * tmp = theBufferList().getBuffer(FileName(included_file));
string const mangled = writefile.mangledFilename();
writefile = makeAbsPath(mangled,
// to be loaded:
if (loadIfNeeded(buffer(), params())) {
// a file got loaded
- Buffer * const tmp = theBufferList().getBuffer(included_file);
+ Buffer * const tmp = theBufferList().getBuffer(FileName(included_file));
// make sure the buffer isn't us
// FIXME RECURSIVE INCLUDES
// This is not sufficient, as recursive includes could be
{
if (loadIfNeeded(buffer(), params())) {
string const included_file = includedFilename(buffer(), params()).absFilename();
- Buffer * tmp = theBufferList().getBuffer(included_file);
- //FIXME This is kind of a dirty hack and should be made reasonable.
- tmp->setParent(0);
- keys.fillWithBibKeys(tmp);
- tmp->setParent(&buffer());
+ Buffer * tmp = theBufferList().getBuffer(FileName(included_file));
+ BiblioInfo const & newkeys = tmp->localBibInfo();
+ keys.mergeBiblioInfo(newkeys);
}
}
}
+docstring InsetInclude::contextMenu(BufferView const &, int, int) const
+{
+ return from_ascii("context-include");
+}
+
+
Inset::DisplayType InsetInclude::display() const
{
return type(params()) == INPUT ? Inline : AlignCenter;
}
-void InsetInclude::addToToc(ParConstIterator const & cpit) const
+void InsetInclude::addToToc(DocIterator const & cpit)
{
TocBackend & backend = buffer().tocBackend();
Toc & toc = backend.toc("listing");
docstring str = convert<docstring>(toc.size() + 1)
+ ". " + from_utf8(caption);
- ParConstIterator pit = cpit;
- pit.push_back(*this);
+ DocIterator pit = cpit;
toc.push_back(TocItem(pit, 0, str));
return;
}
toc.push_back(TocItem(cpit, 0, str));
TocList & toclist = backend.tocs();
+ childbuffer->tocBackend().update();
TocList const & childtoclist = childbuffer->tocBackend().tocs();
TocList::const_iterator it = childtoclist.begin();
TocList::const_iterator const end = childtoclist.end();
InsetListingsParams const par(to_utf8(params()["lstparams"]));
if (par.getParamValue("caption").empty()) {
- listings_label_.clear();
+ listings_label_ = buffer().B_("Program Listing");
return;
}
- Counters & counters = buffer().params().documentClass().counters();
+ Buffer const & master = *buffer().masterBuffer();
+ Counters & counters = master.params().documentClass().counters();
docstring const cnt = from_ascii("listing");
- listings_label_ = buffer().B_("Program Listing");
+ listings_label_ = master.B_("Program Listing");
if (counters.hasCounter(cnt)) {
counters.step(cnt);
listings_label_ += " " + convert<docstring>(counters.value(cnt));