2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
|
* \file InsetInclude.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
#include <config.h>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "InsetInclude.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
2003-06-20 12:46:28 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "BufferList.h"
|
|
|
|
|
#include "BufferParams.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "BufferView.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
|
#include "Cursor.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "DispatchResult.h"
|
|
|
|
|
#include "Exporter.h"
|
|
|
|
|
#include "FuncRequest.h"
|
2005-04-22 08:57:22 +00:00
|
|
|
|
#include "FuncStatus.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "gettext.h"
|
2003-03-05 14:59:37 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyX.h"
|
|
|
|
|
#include "LyXRC.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "MetricsInfo.h"
|
|
|
|
|
#include "OutputParams.h"
|
2006-11-13 16:53:49 +00:00
|
|
|
|
#include "TocBackend.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2007-04-28 20:44:46 +00:00
|
|
|
|
#include "frontends/alert.h"
|
2002-08-01 17:28:59 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2004-04-19 13:05:36 +00:00
|
|
|
|
#include "graphics/PreviewImage.h"
|
2003-10-10 21:08:55 +00:00
|
|
|
|
#include "graphics/PreviewLoader.h"
|
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "insets/RenderPreview.h"
|
Add support for listings package. Two listings command \lstinline, \lstinputlisting and an environment \lstlisting are supported, along with preamble \lstset. \lstinputlisting is implemented through Include dialog, and the other two are implemented with a new inset listings, along with its dialog.
* src/LyXAction.cpp: listing-insert action
* src/insets/Inset.h,cpp: LISTINGS_CODE
* src/insets/InsetInclude.cpp: handle \lstinputlisting
* src/insets/InsetListings.h,cpp: new listings inset
* src/insets/InsetListingsParams.h,cpp: parameters from listings package
* src/insets/InsetCommandParams.h,cpp: handle lstinputlisting option
* src/Bidi.cpp: handle LISTINGS_CODE
* src/frontends/qt4/ui/TextLayoutUi.ui: update UI
* src/frontends/qt4/ui/ListingsUi.ui: new dialog
* src/frontends/qt4/ui/IncludeUi.ui: update UI
* src/frontends/qt4/QInclude.h,cpp: add lstinputlisting
* src/frontends/qt4/QDocument.h,cpp: add textedit for preamble listings_params
* src/frontends/qt4/QListings.h,cpp: new listings inset
* src/frontends/qt4/Dialogs.cpp: new listings dialog
* src/frontends/controllers/ControlInclude.h,cpp: add lstinputlisting
* src/frontends/controllers/ControlListings.h,cpp: new listings inset
* src/LyXFunc.cpp: handle LISTING_CODE
* src/Paragraph.cpp: handle LISTING_CODE
* src/factory.cpp: new listings inset
* src/CutAndPaste.cpp: handle LISTINGS_CODE
* src/LaTeXFeatures.cpp: require listings
* src/Text3.cpp: Handle LISTINGS_CODE
* src/lfuns.h: add LFUN_LISTING_INSERT
* src/Buffer.cpp: change lyx file format to 269
* src/BufferParams.h,cpp: add listings_params to preamble
* lib/lyx2lyx/LyX.py: lyx2lyx
* lib/lyx2lyx/lyx_1_5.py: lyx2lyx
* lib/ui/stdmenus.inc: new menu item (no shortcut!)
* src/insets/Makefile.am: update autotools
* src/frontends/controllers/Makefile.am
* src/frontends/qt4/Makefile.dialogs
* src/frontends/qt4/Makefile.am
* po/POTFILES.in: a few more translatable files.
* development/scons/scons_manifest.py: scons build system
* development/FORMAT: document format changes
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18243 a592a061-630c-0410-9148-cb99ea01b6c8
2007-05-09 19:11:42 +00:00
|
|
|
|
#include "insets/InsetListingsParams.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
|
|
|
|
#include "support/filetools.h"
|
2003-05-13 14:36:24 +00:00
|
|
|
|
#include "support/lstrings.h" // contains
|
2006-10-11 19:40:50 +00:00
|
|
|
|
#include "support/lyxalgo.h"
|
2004-03-25 10:12:44 +00:00
|
|
|
|
#include "support/lyxlib.h"
|
2005-01-06 16:39:35 +00:00
|
|
|
|
#include "support/convert.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2002-08-06 14:02:59 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
2005-01-31 10:42:26 +00:00
|
|
|
|
#include <boost/filesystem/operations.hpp>
|
2002-08-06 14:02:59 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
2007-06-19 14:56:52 +00:00
|
|
|
|
|
|
|
|
|
// Implementation is in LyX.cpp
|
|
|
|
|
extern void dispatch(FuncRequest const & action);
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
using support::addName;
|
|
|
|
|
using support::absolutePath;
|
|
|
|
|
using support::bformat;
|
|
|
|
|
using support::changeExtension;
|
|
|
|
|
using support::contains;
|
|
|
|
|
using support::copy;
|
2006-11-18 12:49:47 +00:00
|
|
|
|
using support::DocFileName;
|
2006-11-26 21:30:39 +00:00
|
|
|
|
using support::FileName;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::getFileContents;
|
2007-05-18 14:40:39 +00:00
|
|
|
|
using support::getVectorFromString;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::isFileReadable;
|
|
|
|
|
using support::isLyXFilename;
|
2007-06-26 16:55:42 +00:00
|
|
|
|
using support::isValidLaTeXFilename;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::latex_path;
|
|
|
|
|
using support::makeAbsPath;
|
|
|
|
|
using support::makeDisplayPath;
|
|
|
|
|
using support::makeRelPath;
|
|
|
|
|
using support::onlyFilename;
|
|
|
|
|
using support::onlyPath;
|
2007-05-18 14:40:39 +00:00
|
|
|
|
using support::prefixIs;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::subst;
|
|
|
|
|
using support::sum;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::ostream;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
2007-05-18 14:40:39 +00:00
|
|
|
|
using std::vector;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace Alert = frontend::Alert;
|
2005-01-31 10:42:26 +00:00
|
|
|
|
namespace fs = boost::filesystem;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2006-10-21 19:40:29 +00:00
|
|
|
|
docstring const uniqueID()
|
2001-03-23 17:09:34 +00:00
|
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
|
static unsigned int seed = 1000;
|
2006-10-21 19:40:29 +00:00
|
|
|
|
return "file" + convert<docstring>(++seed);
|
2000-07-02 09:52:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-05-18 14:40:39 +00:00
|
|
|
|
|
|
|
|
|
bool isListings(InsetCommandParams const & params)
|
|
|
|
|
{
|
|
|
|
|
return params.getCmdName() == "lstinputlisting";
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
2000-07-02 09:52:44 +00:00
|
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
|
InsetInclude::InsetInclude(InsetCommandParams const & p)
|
2002-08-01 17:28:59 +00:00
|
|
|
|
: params_(p), include_label(uniqueID()),
|
2004-04-13 17:25:23 +00:00
|
|
|
|
preview_(new RenderMonitoredPreview(this)),
|
2007-08-12 21:43:58 +00:00
|
|
|
|
set_label_(false)
|
2003-10-09 19:27:07 +00:00
|
|
|
|
{
|
2003-10-10 21:08:55 +00:00
|
|
|
|
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
|
2003-10-09 19:27:07 +00:00
|
|
|
|
}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
|
|
|
|
|
2003-06-12 08:52:36 +00:00
|
|
|
|
InsetInclude::InsetInclude(InsetInclude const & other)
|
2007-04-29 13:39:47 +00:00
|
|
|
|
: Inset(other),
|
2003-06-12 08:52:36 +00:00
|
|
|
|
params_(other.params_),
|
|
|
|
|
include_label(other.include_label),
|
2004-04-13 17:25:23 +00:00
|
|
|
|
preview_(new RenderMonitoredPreview(this)),
|
2007-08-12 21:43:58 +00:00
|
|
|
|
set_label_(false)
|
2003-10-09 19:27:07 +00:00
|
|
|
|
{
|
2003-10-10 21:08:55 +00:00
|
|
|
|
preview_->fileChanged(boost::bind(&InsetInclude::fileChanged, this));
|
2003-10-09 19:27:07 +00:00
|
|
|
|
}
|
2003-06-12 08:52:36 +00:00
|
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
InsetInclude::~InsetInclude()
|
|
|
|
|
{
|
2003-11-28 17:13:41 +00:00
|
|
|
|
InsetIncludeMailer(*this).hideDialog();
|
2003-03-05 14:59:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2003-03-05 14:59:37 +00:00
|
|
|
|
{
|
2003-03-07 15:58:02 +00:00
|
|
|
|
switch (cmd.action) {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
2003-03-07 15:58:02 +00:00
|
|
|
|
case LFUN_INSET_MODIFY: {
|
Rework InsetCommandParams interface and file storage
* src/insets/insetcommandparams.[Ch]:
(operator[]): New, access a parameter
(clear): New, clear all parameters
(info_): New, stire info about this command
(cmdname): Rename to name_
(contents, options, sec_options): Replace with params_. Parameters
are now stored as docstring.
(findInfo): New factor for command info for all commands
(read, write): Use new syntax
(parameter set and get methods): reimplemenmt for new parameter storage
* src/insets/insetcommand.h
(getParam): New, get a parameter
(setParam): New, set a parameter
(parameter set and get methods): Adjust to InsetCommandParams changes
* src/insets/insetbibitem.[Ch]
(write): Remove, not needed anymore
(directWrite): ditto
* src/insets/insetbibitem.C
(InsetBibitem::read): Use InsetCommand::read
* src/insets/insetref.C
(InsetRef::latex): Use new InsetCommandParams interface
* src/mathed/InsetMathHull.C
(InsetMathHull::doDispatch): ditto
* src/text3.C
(LyXText::dispatch): ditto
* src/factory.C
(createInset): Create InsetCommandParams with command name
(readInset): ditto
(readInset): Remove error message for bibitem, since bibitem is
now a normal command inset
* src/buffer.C: Bump file format number
* src/frontends/controllers/ControlCommand.[Ch]
(ControlCommand): take an additional command name parameter
* src/text.C
(readParToken): Remove code for \bibitem
* lib/lyx2lyx/LyX.py: Bump latest file format number
* lib/lyx2lyx/lyx_1_5.py
(convert_bibitem, convert_commandparams): new, convert to new format
(revert_commandparams): new, convert to old format
* development/FORMAT: document new format
* many other files: Adjust to the changes above
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15357 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-17 21:07:16 +00:00
|
|
|
|
InsetCommandParams p("include");
|
2006-10-21 00:16:43 +00:00
|
|
|
|
InsetIncludeMailer::string2params(to_utf8(cmd.argument()), p);
|
2006-04-15 11:46:17 +00:00
|
|
|
|
if (!p.getCmdName().empty()) {
|
2007-05-18 14:40:39 +00:00
|
|
|
|
if (isListings(p)){
|
|
|
|
|
InsetListingsParams par_old(params().getOptions());
|
|
|
|
|
InsetListingsParams par_new(p.getOptions());
|
|
|
|
|
if (par_old.getParamValue("label") !=
|
|
|
|
|
par_new.getParamValue("label")
|
|
|
|
|
&& !par_new.getParamValue("label").empty())
|
2007-08-21 13:03:55 +00:00
|
|
|
|
cur.bv().buffer().changeRefsIfUnique(
|
2007-05-18 14:40:39 +00:00
|
|
|
|
from_utf8(par_old.getParamValue("label")),
|
|
|
|
|
from_utf8(par_new.getParamValue("label")),
|
|
|
|
|
Inset::REF_CODE);
|
|
|
|
|
}
|
2004-04-08 15:03:33 +00:00
|
|
|
|
set(p, cur.buffer());
|
2006-04-15 11:46:17 +00:00
|
|
|
|
cur.buffer().updateBibfilesCache();
|
|
|
|
|
} else
|
2005-05-09 17:29:22 +00:00
|
|
|
|
cur.noUpdate();
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-03-07 15:58:02 +00:00
|
|
|
|
}
|
2003-03-05 14:59:37 +00:00
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
InsetIncludeMailer(*this).updateDialog(&cur.bv());
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-03-07 15:58:02 +00:00
|
|
|
|
|
2003-03-09 09:38:47 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
2007-05-28 22:27:45 +00:00
|
|
|
|
if (!cur.selection())
|
2007-05-23 10:35:57 +00:00
|
|
|
|
InsetIncludeMailer(*this).showDialog(&cur.bv());
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-03-09 09:38:47 +00:00
|
|
|
|
|
2003-03-07 15:58:02 +00:00
|
|
|
|
default:
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-03-07 15:58:02 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
bool InsetInclude::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2005-04-22 08:57:22 +00:00
|
|
|
|
FuncStatus & flag) const
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
|
flag.enabled(true);
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
default:
|
2007-04-29 13:39:47 +00:00
|
|
|
|
return Inset::getStatus(cur, cmd, flag);
|
2005-04-22 08:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
|
InsetCommandParams const & InsetInclude::params() const
|
2001-03-14 10:57:39 +00:00
|
|
|
|
{
|
|
|
|
|
return params_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-18 17:22:36 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
/// the type of inclusion
|
|
|
|
|
enum Types {
|
|
|
|
|
INCLUDE = 0,
|
|
|
|
|
VERB = 1,
|
|
|
|
|
INPUT = 2,
|
Add support for listings package. Two listings command \lstinline, \lstinputlisting and an environment \lstlisting are supported, along with preamble \lstset. \lstinputlisting is implemented through Include dialog, and the other two are implemented with a new inset listings, along with its dialog.
* src/LyXAction.cpp: listing-insert action
* src/insets/Inset.h,cpp: LISTINGS_CODE
* src/insets/InsetInclude.cpp: handle \lstinputlisting
* src/insets/InsetListings.h,cpp: new listings inset
* src/insets/InsetListingsParams.h,cpp: parameters from listings package
* src/insets/InsetCommandParams.h,cpp: handle lstinputlisting option
* src/Bidi.cpp: handle LISTINGS_CODE
* src/frontends/qt4/ui/TextLayoutUi.ui: update UI
* src/frontends/qt4/ui/ListingsUi.ui: new dialog
* src/frontends/qt4/ui/IncludeUi.ui: update UI
* src/frontends/qt4/QInclude.h,cpp: add lstinputlisting
* src/frontends/qt4/QDocument.h,cpp: add textedit for preamble listings_params
* src/frontends/qt4/QListings.h,cpp: new listings inset
* src/frontends/qt4/Dialogs.cpp: new listings dialog
* src/frontends/controllers/ControlInclude.h,cpp: add lstinputlisting
* src/frontends/controllers/ControlListings.h,cpp: new listings inset
* src/LyXFunc.cpp: handle LISTING_CODE
* src/Paragraph.cpp: handle LISTING_CODE
* src/factory.cpp: new listings inset
* src/CutAndPaste.cpp: handle LISTINGS_CODE
* src/LaTeXFeatures.cpp: require listings
* src/Text3.cpp: Handle LISTINGS_CODE
* src/lfuns.h: add LFUN_LISTING_INSERT
* src/Buffer.cpp: change lyx file format to 269
* src/BufferParams.h,cpp: add listings_params to preamble
* lib/lyx2lyx/LyX.py: lyx2lyx
* lib/lyx2lyx/lyx_1_5.py: lyx2lyx
* lib/ui/stdmenus.inc: new menu item (no shortcut!)
* src/insets/Makefile.am: update autotools
* src/frontends/controllers/Makefile.am
* src/frontends/qt4/Makefile.dialogs
* src/frontends/qt4/Makefile.am
* po/POTFILES.in: a few more translatable files.
* development/scons/scons_manifest.py: scons build system
* development/FORMAT: document format changes
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18243 a592a061-630c-0410-9148-cb99ea01b6c8
2007-05-09 19:11:42 +00:00
|
|
|
|
VERBAST = 3,
|
|
|
|
|
LISTINGS = 4,
|
2003-09-18 17:22:36 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
|
Types type(InsetCommandParams const & params)
|
2001-03-14 10:57:39 +00:00
|
|
|
|
{
|
2003-09-19 10:16:33 +00:00
|
|
|
|
string const command_name = params.getCmdName();
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
2003-09-18 17:22:36 +00:00
|
|
|
|
if (command_name == "input")
|
|
|
|
|
return INPUT;
|
|
|
|
|
if (command_name == "verbatiminput")
|
|
|
|
|
return VERB;
|
|
|
|
|
if (command_name == "verbatiminput*")
|
|
|
|
|
return VERBAST;
|
Add support for listings package. Two listings command \lstinline, \lstinputlisting and an environment \lstlisting are supported, along with preamble \lstset. \lstinputlisting is implemented through Include dialog, and the other two are implemented with a new inset listings, along with its dialog.
* src/LyXAction.cpp: listing-insert action
* src/insets/Inset.h,cpp: LISTINGS_CODE
* src/insets/InsetInclude.cpp: handle \lstinputlisting
* src/insets/InsetListings.h,cpp: new listings inset
* src/insets/InsetListingsParams.h,cpp: parameters from listings package
* src/insets/InsetCommandParams.h,cpp: handle lstinputlisting option
* src/Bidi.cpp: handle LISTINGS_CODE
* src/frontends/qt4/ui/TextLayoutUi.ui: update UI
* src/frontends/qt4/ui/ListingsUi.ui: new dialog
* src/frontends/qt4/ui/IncludeUi.ui: update UI
* src/frontends/qt4/QInclude.h,cpp: add lstinputlisting
* src/frontends/qt4/QDocument.h,cpp: add textedit for preamble listings_params
* src/frontends/qt4/QListings.h,cpp: new listings inset
* src/frontends/qt4/Dialogs.cpp: new listings dialog
* src/frontends/controllers/ControlInclude.h,cpp: add lstinputlisting
* src/frontends/controllers/ControlListings.h,cpp: new listings inset
* src/LyXFunc.cpp: handle LISTING_CODE
* src/Paragraph.cpp: handle LISTING_CODE
* src/factory.cpp: new listings inset
* src/CutAndPaste.cpp: handle LISTINGS_CODE
* src/LaTeXFeatures.cpp: require listings
* src/Text3.cpp: Handle LISTINGS_CODE
* src/lfuns.h: add LFUN_LISTING_INSERT
* src/Buffer.cpp: change lyx file format to 269
* src/BufferParams.h,cpp: add listings_params to preamble
* lib/lyx2lyx/LyX.py: lyx2lyx
* lib/lyx2lyx/lyx_1_5.py: lyx2lyx
* lib/ui/stdmenus.inc: new menu item (no shortcut!)
* src/insets/Makefile.am: update autotools
* src/frontends/controllers/Makefile.am
* src/frontends/qt4/Makefile.dialogs
* src/frontends/qt4/Makefile.am
* po/POTFILES.in: a few more translatable files.
* development/scons/scons_manifest.py: scons build system
* development/FORMAT: document format changes
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18243 a592a061-630c-0410-9148-cb99ea01b6c8
2007-05-09 19:11:42 +00:00
|
|
|
|
if (command_name == "lstinputlisting")
|
|
|
|
|
return LISTINGS;
|
2003-09-18 17:22:36 +00:00
|
|
|
|
return INCLUDE;
|
|
|
|
|
}
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
|
bool isVerbatim(InsetCommandParams const & params)
|
2001-03-23 17:09:34 +00:00
|
|
|
|
{
|
2003-09-19 10:16:33 +00:00
|
|
|
|
string const command_name = params.getCmdName();
|
2003-10-13 01:53:45 +00:00
|
|
|
|
return command_name == "verbatiminput" ||
|
2003-09-18 17:22:36 +00:00
|
|
|
|
command_name == "verbatiminput*";
|
2001-03-23 17:09:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
|
|
2007-05-28 22:27:45 +00:00
|
|
|
|
bool isInputOrInclude(InsetCommandParams const & params)
|
2007-05-24 17:17:04 +00:00
|
|
|
|
{
|
|
|
|
|
Types const t = type(params);
|
2007-05-24 19:19:23 +00:00
|
|
|
|
return (t == INPUT) || (t == INCLUDE);
|
2007-05-24 17:17:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
|
string const masterFilename(Buffer const & buffer)
|
2004-03-25 10:12:44 +00:00
|
|
|
|
{
|
|
|
|
|
return buffer.getMasterBuffer()->fileName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const parentFilename(Buffer const & buffer)
|
2003-10-10 21:08:55 +00:00
|
|
|
|
{
|
|
|
|
|
return buffer.fileName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-27 10:56:11 +00:00
|
|
|
|
FileName const includedFilename(Buffer const & buffer,
|
2003-10-10 21:08:55 +00:00
|
|
|
|
InsetCommandParams const & params)
|
|
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
|
return makeAbsPath(to_utf8(params["filename"]),
|
2006-04-08 22:31:11 +00:00
|
|
|
|
onlyPath(parentFilename(buffer)));
|
2003-10-10 21:08:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-22 22:26:47 +00:00
|
|
|
|
void add_preview(RenderMonitoredPreview &, InsetInclude const &, Buffer const &);
|
2003-10-10 21:08:55 +00:00
|
|
|
|
|
2003-09-18 17:22:36 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
|
void InsetInclude::set(InsetCommandParams const & p, Buffer const & buffer)
|
2001-03-23 17:09:34 +00:00
|
|
|
|
{
|
|
|
|
|
params_ = p;
|
2003-09-19 10:16:33 +00:00
|
|
|
|
set_label_ = false;
|
2001-03-23 17:09:34 +00:00
|
|
|
|
|
2002-08-06 14:02:59 +00:00
|
|
|
|
if (preview_->monitoring())
|
|
|
|
|
preview_->stopMonitoring();
|
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
|
if (type(params_) == INPUT)
|
2003-10-22 22:26:47 +00:00
|
|
|
|
add_preview(*preview_, *this, buffer);
|
2001-03-14 10:57:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetInclude::clone() const
|
2001-03-14 10:57:39 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return new InsetInclude(*this);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetInclude::write(Buffer const &, ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
write(os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetInclude::write(ostream & os) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
|
os << "Include " << to_utf8(params_.getCommand()) << '\n'
|
2005-01-06 15:40:49 +00:00
|
|
|
|
<< "preview " << convert<string>(params_.preview()) << '\n';
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
void InsetInclude::read(Buffer const &, Lexer & lex)
|
2003-08-28 07:41:31 +00:00
|
|
|
|
{
|
|
|
|
|
read(lex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
void InsetInclude::read(Lexer & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-11-09 17:45:42 +00:00
|
|
|
|
if (lex.isOK()) {
|
2007-01-25 21:12:12 +00:00
|
|
|
|
lex.eatLine();
|
2006-11-09 17:45:42 +00:00
|
|
|
|
string const command = lex.getString();
|
|
|
|
|
params_.scanCommand(command);
|
|
|
|
|
}
|
|
|
|
|
string token;
|
|
|
|
|
while (lex.isOK()) {
|
2007-01-25 21:12:12 +00:00
|
|
|
|
lex.next();
|
2006-11-09 17:45:42 +00:00
|
|
|
|
token = lex.getString();
|
|
|
|
|
if (token == "\\end_inset")
|
|
|
|
|
break;
|
|
|
|
|
if (token == "preview") {
|
|
|
|
|
lex.next();
|
|
|
|
|
params_.preview(lex.getBool());
|
|
|
|
|
} else
|
|
|
|
|
lex.printError("Unknown parameter name `$$Token' for command " + params_.getCmdName());
|
|
|
|
|
}
|
|
|
|
|
if (token != "\\end_inset") {
|
|
|
|
|
lex.printError("Missing \\end_inset at this point. "
|
2007-05-28 22:27:45 +00:00
|
|
|
|
"Read: `$$Token'");
|
2006-11-09 17:45:42 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-05-01 08:26:40 +00:00
|
|
|
|
docstring const InsetInclude::getScreenLabel(Buffer const & buf) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-09-09 15:27:44 +00:00
|
|
|
|
docstring temp;
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
2003-09-18 17:22:36 +00:00
|
|
|
|
switch (type(params_)) {
|
2006-09-09 15:27:44 +00:00
|
|
|
|
case INPUT:
|
2007-08-12 21:43:58 +00:00
|
|
|
|
temp = buf.B_("Input");
|
2006-09-09 15:27:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case VERB:
|
2007-08-12 21:43:58 +00:00
|
|
|
|
temp = buf.B_("Verbatim Input");
|
2006-09-09 15:27:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case VERBAST:
|
2007-08-12 21:43:58 +00:00
|
|
|
|
temp = buf.B_("Verbatim Input*");
|
2006-09-09 15:27:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case INCLUDE:
|
2007-08-12 21:43:58 +00:00
|
|
|
|
temp = buf.B_("Include");
|
2006-09-09 15:27:44 +00:00
|
|
|
|
break;
|
2007-05-24 14:10:35 +00:00
|
|
|
|
case LISTINGS: {
|
2007-08-12 21:43:58 +00:00
|
|
|
|
temp = listings_label_;
|
2007-05-24 14:10:35 +00:00
|
|
|
|
}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
temp += ": ";
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2006-10-20 16:12:49 +00:00
|
|
|
|
if (params_["filename"].empty())
|
2006-10-11 19:40:50 +00:00
|
|
|
|
temp += "???";
|
2001-03-14 10:57:39 +00:00
|
|
|
|
else
|
2007-01-10 00:30:49 +00:00
|
|
|
|
temp += from_utf8(onlyFilename(to_utf8(params_["filename"])));
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
return temp;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2006-05-19 07:21:43 +00:00
|
|
|
|
/// return the child buffer if the file is a LyX doc and is loaded
|
|
|
|
|
Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params)
|
|
|
|
|
{
|
Add support for listings package. Two listings command \lstinline, \lstinputlisting and an environment \lstlisting are supported, along with preamble \lstset. \lstinputlisting is implemented through Include dialog, and the other two are implemented with a new inset listings, along with its dialog.
* src/LyXAction.cpp: listing-insert action
* src/insets/Inset.h,cpp: LISTINGS_CODE
* src/insets/InsetInclude.cpp: handle \lstinputlisting
* src/insets/InsetListings.h,cpp: new listings inset
* src/insets/InsetListingsParams.h,cpp: parameters from listings package
* src/insets/InsetCommandParams.h,cpp: handle lstinputlisting option
* src/Bidi.cpp: handle LISTINGS_CODE
* src/frontends/qt4/ui/TextLayoutUi.ui: update UI
* src/frontends/qt4/ui/ListingsUi.ui: new dialog
* src/frontends/qt4/ui/IncludeUi.ui: update UI
* src/frontends/qt4/QInclude.h,cpp: add lstinputlisting
* src/frontends/qt4/QDocument.h,cpp: add textedit for preamble listings_params
* src/frontends/qt4/QListings.h,cpp: new listings inset
* src/frontends/qt4/Dialogs.cpp: new listings dialog
* src/frontends/controllers/ControlInclude.h,cpp: add lstinputlisting
* src/frontends/controllers/ControlListings.h,cpp: new listings inset
* src/LyXFunc.cpp: handle LISTING_CODE
* src/Paragraph.cpp: handle LISTING_CODE
* src/factory.cpp: new listings inset
* src/CutAndPaste.cpp: handle LISTINGS_CODE
* src/LaTeXFeatures.cpp: require listings
* src/Text3.cpp: Handle LISTINGS_CODE
* src/lfuns.h: add LFUN_LISTING_INSERT
* src/Buffer.cpp: change lyx file format to 269
* src/BufferParams.h,cpp: add listings_params to preamble
* lib/lyx2lyx/LyX.py: lyx2lyx
* lib/lyx2lyx/lyx_1_5.py: lyx2lyx
* lib/ui/stdmenus.inc: new menu item (no shortcut!)
* src/insets/Makefile.am: update autotools
* src/frontends/controllers/Makefile.am
* src/frontends/qt4/Makefile.dialogs
* src/frontends/qt4/Makefile.am
* po/POTFILES.in: a few more translatable files.
* development/scons/scons_manifest.py: scons build system
* development/FORMAT: document format changes
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18243 a592a061-630c-0410-9148-cb99ea01b6c8
2007-05-09 19:11:42 +00:00
|
|
|
|
if (isVerbatim(params) || isListings(params))
|
2006-05-19 07:21:43 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
2006-12-27 10:56:11 +00:00
|
|
|
|
string const included_file = includedFilename(buffer, params).absFilename();
|
2006-05-19 07:21:43 +00:00
|
|
|
|
if (!isLyXFilename(included_file))
|
|
|
|
|
return 0;
|
|
|
|
|
|
2007-05-21 15:34:29 +00:00
|
|
|
|
Buffer * childBuffer = theBufferList().getBuffer(included_file);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-05-21 15:34:29 +00:00
|
|
|
|
//FIXME RECURSIVE INCLUDES
|
|
|
|
|
if (childBuffer == & buffer)
|
|
|
|
|
return 0;
|
2007-05-26 11:25:41 +00:00
|
|
|
|
else
|
|
|
|
|
return childBuffer;
|
2006-05-19 07:21:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-13 19:40:54 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
/// return true if the file is or got loaded.
|
|
|
|
|
Buffer * loadIfNeeded(Buffer const & parent, InsetCommandParams const & params)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
Add support for listings package. Two listings command \lstinline, \lstinputlisting and an environment \lstlisting are supported, along with preamble \lstset. \lstinputlisting is implemented through Include dialog, and the other two are implemented with a new inset listings, along with its dialog.
* src/LyXAction.cpp: listing-insert action
* src/insets/Inset.h,cpp: LISTINGS_CODE
* src/insets/InsetInclude.cpp: handle \lstinputlisting
* src/insets/InsetListings.h,cpp: new listings inset
* src/insets/InsetListingsParams.h,cpp: parameters from listings package
* src/insets/InsetCommandParams.h,cpp: handle lstinputlisting option
* src/Bidi.cpp: handle LISTINGS_CODE
* src/frontends/qt4/ui/TextLayoutUi.ui: update UI
* src/frontends/qt4/ui/ListingsUi.ui: new dialog
* src/frontends/qt4/ui/IncludeUi.ui: update UI
* src/frontends/qt4/QInclude.h,cpp: add lstinputlisting
* src/frontends/qt4/QDocument.h,cpp: add textedit for preamble listings_params
* src/frontends/qt4/QListings.h,cpp: new listings inset
* src/frontends/qt4/Dialogs.cpp: new listings dialog
* src/frontends/controllers/ControlInclude.h,cpp: add lstinputlisting
* src/frontends/controllers/ControlListings.h,cpp: new listings inset
* src/LyXFunc.cpp: handle LISTING_CODE
* src/Paragraph.cpp: handle LISTING_CODE
* src/factory.cpp: new listings inset
* src/CutAndPaste.cpp: handle LISTINGS_CODE
* src/LaTeXFeatures.cpp: require listings
* src/Text3.cpp: Handle LISTINGS_CODE
* src/lfuns.h: add LFUN_LISTING_INSERT
* src/Buffer.cpp: change lyx file format to 269
* src/BufferParams.h,cpp: add listings_params to preamble
* lib/lyx2lyx/LyX.py: lyx2lyx
* lib/lyx2lyx/lyx_1_5.py: lyx2lyx
* lib/ui/stdmenus.inc: new menu item (no shortcut!)
* src/insets/Makefile.am: update autotools
* src/frontends/controllers/Makefile.am
* src/frontends/qt4/Makefile.dialogs
* src/frontends/qt4/Makefile.am
* po/POTFILES.in: a few more translatable files.
* development/scons/scons_manifest.py: scons build system
* development/FORMAT: document format changes
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18243 a592a061-630c-0410-9148-cb99ea01b6c8
2007-05-09 19:11:42 +00:00
|
|
|
|
if (isVerbatim(params) || isListings(params))
|
2007-08-13 19:40:54 +00:00
|
|
|
|
return 0;
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
string const parent_filename = parent.fileName();
|
|
|
|
|
FileName const included_file = makeAbsPath(to_utf8(params["filename"]),
|
|
|
|
|
onlyPath(parent_filename));
|
|
|
|
|
|
2006-12-27 10:56:11 +00:00
|
|
|
|
if (!isLyXFilename(included_file.absFilename()))
|
2007-08-13 19:40:54 +00:00
|
|
|
|
return 0;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
Buffer * child = theBufferList().getBuffer(included_file.absFilename());
|
|
|
|
|
if (!child) {
|
2004-03-25 10:12:44 +00:00
|
|
|
|
// the readonly flag can/will be wrong, not anymore I think.
|
2006-12-27 10:56:11 +00:00
|
|
|
|
if (!fs::exists(included_file.toFilesystemEncoding()))
|
2007-08-21 07:33:46 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
child = theBufferList().newBuffer(included_file.absFilename());
|
|
|
|
|
if (!loadLyXFile(child, included_file)) {
|
|
|
|
|
//close the buffer we just opened
|
|
|
|
|
theBufferList().close(child, false);
|
|
|
|
|
return 0;
|
2007-07-10 15:07:00 +00:00
|
|
|
|
}
|
2004-03-25 10:12:44 +00:00
|
|
|
|
}
|
2007-08-21 07:33:46 +00:00
|
|
|
|
child->setParentName(parent_filename);
|
|
|
|
|
return child;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetInclude::latex(Buffer const & buffer, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const & runparams) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
|
string incfile(to_utf8(params_["filename"]));
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
// Do nothing if no file name has been specified
|
2000-09-26 13:54:57 +00:00
|
|
|
|
if (incfile.empty())
|
2000-03-02 02:19:43 +00:00
|
|
|
|
return 0;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName const included_file(includedFilename(buffer, params_));
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-05-21 15:34:29 +00:00
|
|
|
|
//Check we're not trying to include ourselves.
|
|
|
|
|
//FIXME RECURSIVE INCLUDE
|
|
|
|
|
//This isn't sufficient, as the inclusion could be downstream.
|
|
|
|
|
//But it'll have to do for now.
|
2007-05-24 17:17:04 +00:00
|
|
|
|
if (isInputOrInclude(params_) &&
|
2007-05-28 22:27:45 +00:00
|
|
|
|
buffer.fileName() == included_file.absFilename())
|
2007-05-24 17:17:04 +00:00
|
|
|
|
{
|
2007-05-28 22:27:45 +00:00
|
|
|
|
Alert::error(_("Recursive input"),
|
|
|
|
|
bformat(_("Attempted to include file %1$s in itself! "
|
|
|
|
|
"Ignoring inclusion."), from_utf8(incfile)));
|
2007-05-21 15:34:29 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-25 10:12:44 +00:00
|
|
|
|
Buffer const * const m_buffer = buffer.getMasterBuffer();
|
|
|
|
|
|
|
|
|
|
// if incfile is relative, make it relative to the master
|
|
|
|
|
// buffer directory.
|
2006-04-08 22:31:11 +00:00
|
|
|
|
if (!absolutePath(incfile)) {
|
2007-03-27 07:24:16 +00:00
|
|
|
|
// FIXME UNICODE
|
|
|
|
|
incfile = to_utf8(makeRelPath(from_utf8(included_file.absFilename()),
|
2007-05-28 22:27:45 +00:00
|
|
|
|
from_utf8(m_buffer->filePath())));
|
2004-03-25 10:12:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// write it to a file (so far the complete file)
|
2006-04-08 22:31:11 +00:00
|
|
|
|
string const exportfile = changeExtension(incfile, ".tex");
|
2007-05-28 22:27:45 +00:00
|
|
|
|
string const mangled =
|
2007-05-24 17:17:04 +00:00
|
|
|
|
DocFileName(changeExtension(included_file.absFilename(),".tex")).
|
|
|
|
|
mangledFilename();
|
2006-11-26 21:30:39 +00:00
|
|
|
|
FileName const writefile(makeAbsPath(mangled, m_buffer->temppath()));
|
2004-03-25 10:12:44 +00:00
|
|
|
|
|
2004-06-01 13:39:33 +00:00
|
|
|
|
if (!runparams.nice)
|
|
|
|
|
incfile = mangled;
|
2007-06-26 16:55:42 +00:00
|
|
|
|
else if (!isValidLaTeXFilename(incfile)) {
|
|
|
|
|
frontend::Alert::warning(_("Invalid filename"),
|
|
|
|
|
_("The following filename is likely to cause trouble "
|
|
|
|
|
"when running the exported file through LaTeX: ") +
|
|
|
|
|
from_utf8(incfile));
|
|
|
|
|
}
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::LATEX) << "incfile:" << incfile << endl;
|
|
|
|
|
LYXERR(Debug::LATEX) << "exportfile:" << exportfile << endl;
|
|
|
|
|
LYXERR(Debug::LATEX) << "writefile:" << writefile << endl;
|
2003-09-19 10:16:33 +00:00
|
|
|
|
|
2007-05-26 17:26:58 +00:00
|
|
|
|
if (runparams.inComment || runparams.dryrun) {
|
|
|
|
|
//Don't try to load or copy the file if we're
|
|
|
|
|
//in a comment or doing a dryrun
|
2007-05-28 22:27:45 +00:00
|
|
|
|
} else if (isInputOrInclude(params_) &&
|
|
|
|
|
isLyXFilename(included_file.absFilename())) {
|
2007-05-26 17:26:58 +00:00
|
|
|
|
//if it's a LyX file and we're inputting or including,
|
2007-05-24 17:17:04 +00:00
|
|
|
|
//try to load it so we can write the associated latex
|
|
|
|
|
if (!loadIfNeeded(buffer, params_))
|
|
|
|
|
return false;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
Buffer * tmp = theBufferList().getBuffer(included_file.absFilename());
|
2000-03-02 02:19:43 +00:00
|
|
|
|
|
This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.
This first patch does some reworking of the infrastructrue. We need to distinguish between the TextClass that a particular document is using and the layout of that document, since modules, in particular, can modify the layout. The solution adopted here is to add a TextClass pointer to BufferParams, which will hold the layout. The layout itself is then constructed from the TextClass the document is using. At present, this is completely trivial, but that will change when modules are added.
The pointer in question is a boost::shared_ptr. This is needed because CutAndPaste saves a copy of the layout with each cut or copied selection. We cannot assume the selection vanishes when the document is closed, so there are two options: (i) keep a list of all the layouts that have ever been used by any document; (ii) used some kind of smart pointer. The latter seems preferable, as the former would waste memory. More importantly, the use of a smart pointer allows modules to be modified on disk and then reloaded while LyX is running, and it will eventually allow the same for layout files.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19756 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-23 16:41:13 +00:00
|
|
|
|
if (tmp->params().getBaseClass() != m_buffer->params().getBaseClass()) {
|
2006-09-09 15:27:44 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-09-11 08:54:10 +00:00
|
|
|
|
docstring text = bformat(_("Included file `%1$s'\n"
|
2006-04-05 23:56:29 +00:00
|
|
|
|
"has textclass `%2$s'\n"
|
2006-09-11 08:54:10 +00:00
|
|
|
|
"while parent file has textclass `%3$s'."),
|
2006-11-26 21:30:39 +00:00
|
|
|
|
makeDisplayPath(included_file.absFilename()),
|
2007-04-29 19:53:54 +00:00
|
|
|
|
from_utf8(tmp->params().getTextClass().name()),
|
|
|
|
|
from_utf8(m_buffer->params().getTextClass().name()));
|
2006-09-11 08:54:10 +00:00
|
|
|
|
Alert::warning(_("Different textclasses"), text);
|
2001-03-13 13:40:08 +00:00
|
|
|
|
//return 0;
|
2000-03-02 02:19:43 +00:00
|
|
|
|
}
|
This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.
This patch adds the backend. The ModuleList class holds a list of the available modules, which are retrieved from lyxmodules.lst, itself generated by configure.py. There are two LFUNs available: modules-clear and module-add, which do the obvious thing; you can test by typing these into the minibuffer, along with the name of one of the available modules: URL (a CharStyle), Endnote (a Custom Inset), and---with the spaces---End To Foot (View>LaTeX and look at the user preamble), which are themselves in lib/layouts. There are some others, too, that allow theorems to be added to classes like article and book.
The GUI will come next.
Issues: (i) The configure.py script could be improved. It'd be nice, for example, if it tested for the presence of the LaTeX packages a particular module needs. But this would mean re-working the LaTeX script, and I don't know how to do that. Note that at present, the packages are ignored. This will change shortly. (ii) I've used std::string in LyXModule, following what seemed to be a precedent in TextClass. If some of these should be docstrings, please let me know, and I'll change them. (iii) There is at present no distinction between LaTeX and DocBook modules. Should there be? That is: Should there be modules that are available when the document class is a LaTeX class and others that are available only when it is DocBook? Or should there just be one set of modules? Each module can of course indicate for what it is suitable in its description.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19893 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-29 17:59:49 +00:00
|
|
|
|
|
|
|
|
|
// Make sure modules used in child are all included in master
|
|
|
|
|
//FIXME It might be worth loading the children's modules into the master
|
|
|
|
|
//over in BufferParams rather than doing this check.
|
|
|
|
|
vector<string> const masterModules = m_buffer->params().getModules();
|
|
|
|
|
vector<string> const childModules = tmp->params().getModules();
|
|
|
|
|
vector<string>::const_iterator it = childModules.begin();
|
|
|
|
|
vector<string>::const_iterator end = childModules.end();
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
string const module = *it;
|
|
|
|
|
vector<string>::const_iterator found =
|
|
|
|
|
find(masterModules.begin(), masterModules.end(), module);
|
|
|
|
|
if (found != masterModules.end()) {
|
|
|
|
|
docstring text = bformat(_("Included file `%1$s'\n"
|
|
|
|
|
"uses module `%2$s'\n"
|
|
|
|
|
"which is not used in parent file."),
|
|
|
|
|
makeDisplayPath(included_file.absFilename()), from_utf8(module));
|
|
|
|
|
Alert::warning(_("Module not found"), text);
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2004-03-25 10:12:44 +00:00
|
|
|
|
tmp->markDepClean(m_buffer->temppath());
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2007-08-10 11:47:12 +00:00
|
|
|
|
// FIXME: handle non existing files
|
|
|
|
|
// FIXME: Second argument is irrelevant!
|
2004-03-25 10:12:44 +00:00
|
|
|
|
// since only_body is true, makeLaTeXFile will not look at second
|
|
|
|
|
// argument. Should we set it to string(), or should makeLaTeXFile
|
|
|
|
|
// make use of it somehow? (JMarc 20031002)
|
2007-03-25 16:31:16 +00:00
|
|
|
|
// The included file might be written in a different encoding
|
|
|
|
|
Encoding const * const oldEnc = runparams.encoding;
|
|
|
|
|
runparams.encoding = &tmp->params().encoding();
|
2006-12-04 15:46:57 +00:00
|
|
|
|
tmp->makeLaTeXFile(writefile,
|
2006-04-08 22:31:11 +00:00
|
|
|
|
onlyPath(masterFilename(buffer)),
|
2003-07-26 21:37:10 +00:00
|
|
|
|
runparams, false);
|
2007-03-25 16:31:16 +00:00
|
|
|
|
runparams.encoding = oldEnc;
|
2004-06-01 13:39:33 +00:00
|
|
|
|
} else {
|
2007-05-26 17:26:58 +00:00
|
|
|
|
// In this case, it's not a LyX file, so we copy the file
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// to the temp dir, so that .aux files etc. are not created
|
|
|
|
|
// in the original dir. Files included by this file will be
|
2007-05-26 17:26:58 +00:00
|
|
|
|
// found via input@path, see ../Buffer.cpp.
|
2004-03-25 10:12:44 +00:00
|
|
|
|
unsigned long const checksum_in = sum(included_file);
|
|
|
|
|
unsigned long const checksum_out = sum(writefile);
|
|
|
|
|
|
|
|
|
|
if (checksum_in != checksum_out) {
|
|
|
|
|
if (!copy(included_file, writefile)) {
|
2006-09-09 15:27:44 +00:00
|
|
|
|
// FIXME UNICODE
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::LATEX)
|
2006-10-21 00:16:43 +00:00
|
|
|
|
<< to_utf8(bformat(_("Could not copy the file\n%1$s\n"
|
2006-09-11 08:54:10 +00:00
|
|
|
|
"into the temporary directory."),
|
2006-11-26 21:30:39 +00:00
|
|
|
|
from_utf8(included_file.absFilename())))
|
2004-03-25 10:12:44 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
}
|
2000-03-02 02:19:43 +00:00
|
|
|
|
|
2006-03-28 18:49:46 +00:00
|
|
|
|
string const tex_format = (runparams.flavor == OutputParams::LATEX) ?
|
|
|
|
|
"latex" : "pdflatex";
|
2003-09-18 17:22:36 +00:00
|
|
|
|
if (isVerbatim(params_)) {
|
2005-04-18 17:43:11 +00:00
|
|
|
|
incfile = latex_path(incfile);
|
2006-10-19 16:51:30 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
os << '\\' << from_ascii(params_.getCmdName()) << '{'
|
|
|
|
|
<< from_utf8(incfile) << '}';
|
2003-09-18 17:22:36 +00:00
|
|
|
|
} else if (type(params_) == INPUT) {
|
2006-03-28 18:49:46 +00:00
|
|
|
|
runparams.exportdata->addExternalFile(tex_format, writefile,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
exportfile);
|
2004-06-01 13:39:33 +00:00
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
// \input wants file with extension (default is .tex)
|
2006-11-26 21:30:39 +00:00
|
|
|
|
if (!isLyXFilename(included_file.absFilename())) {
|
2005-04-18 17:43:11 +00:00
|
|
|
|
incfile = latex_path(incfile);
|
2006-10-19 16:51:30 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
os << '\\' << from_ascii(params_.getCmdName())
|
|
|
|
|
<< '{' << from_utf8(incfile) << '}';
|
2000-03-02 02:19:43 +00:00
|
|
|
|
} else {
|
2006-04-08 22:31:11 +00:00
|
|
|
|
incfile = changeExtension(incfile, ".tex");
|
2005-04-18 17:43:11 +00:00
|
|
|
|
incfile = latex_path(incfile);
|
2006-10-19 16:51:30 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
os << '\\' << from_ascii(params_.getCmdName())
|
|
|
|
|
<< '{' << from_utf8(incfile) << '}';
|
2000-03-02 02:19:43 +00:00
|
|
|
|
}
|
Add support for listings package. Two listings command \lstinline, \lstinputlisting and an environment \lstlisting are supported, along with preamble \lstset. \lstinputlisting is implemented through Include dialog, and the other two are implemented with a new inset listings, along with its dialog.
* src/LyXAction.cpp: listing-insert action
* src/insets/Inset.h,cpp: LISTINGS_CODE
* src/insets/InsetInclude.cpp: handle \lstinputlisting
* src/insets/InsetListings.h,cpp: new listings inset
* src/insets/InsetListingsParams.h,cpp: parameters from listings package
* src/insets/InsetCommandParams.h,cpp: handle lstinputlisting option
* src/Bidi.cpp: handle LISTINGS_CODE
* src/frontends/qt4/ui/TextLayoutUi.ui: update UI
* src/frontends/qt4/ui/ListingsUi.ui: new dialog
* src/frontends/qt4/ui/IncludeUi.ui: update UI
* src/frontends/qt4/QInclude.h,cpp: add lstinputlisting
* src/frontends/qt4/QDocument.h,cpp: add textedit for preamble listings_params
* src/frontends/qt4/QListings.h,cpp: new listings inset
* src/frontends/qt4/Dialogs.cpp: new listings dialog
* src/frontends/controllers/ControlInclude.h,cpp: add lstinputlisting
* src/frontends/controllers/ControlListings.h,cpp: new listings inset
* src/LyXFunc.cpp: handle LISTING_CODE
* src/Paragraph.cpp: handle LISTING_CODE
* src/factory.cpp: new listings inset
* src/CutAndPaste.cpp: handle LISTINGS_CODE
* src/LaTeXFeatures.cpp: require listings
* src/Text3.cpp: Handle LISTINGS_CODE
* src/lfuns.h: add LFUN_LISTING_INSERT
* src/Buffer.cpp: change lyx file format to 269
* src/BufferParams.h,cpp: add listings_params to preamble
* lib/lyx2lyx/LyX.py: lyx2lyx
* lib/lyx2lyx/lyx_1_5.py: lyx2lyx
* lib/ui/stdmenus.inc: new menu item (no shortcut!)
* src/insets/Makefile.am: update autotools
* src/frontends/controllers/Makefile.am
* src/frontends/qt4/Makefile.dialogs
* src/frontends/qt4/Makefile.am
* po/POTFILES.in: a few more translatable files.
* development/scons/scons_manifest.py: scons build system
* development/FORMAT: document format changes
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18243 a592a061-630c-0410-9148-cb99ea01b6c8
2007-05-09 19:11:42 +00:00
|
|
|
|
} else if (type(params_) == LISTINGS) {
|
|
|
|
|
os << '\\' << from_ascii(params_.getCmdName());
|
|
|
|
|
string opt = params_.getOptions();
|
|
|
|
|
// opt is set in QInclude dialog and should have passed validation.
|
|
|
|
|
InsetListingsParams params(opt);
|
|
|
|
|
if (!params.params().empty())
|
2007-05-24 22:19:58 +00:00
|
|
|
|
os << "[" << from_utf8(params.params()) << "]";
|
Add support for listings package. Two listings command \lstinline, \lstinputlisting and an environment \lstlisting are supported, along with preamble \lstset. \lstinputlisting is implemented through Include dialog, and the other two are implemented with a new inset listings, along with its dialog.
* src/LyXAction.cpp: listing-insert action
* src/insets/Inset.h,cpp: LISTINGS_CODE
* src/insets/InsetInclude.cpp: handle \lstinputlisting
* src/insets/InsetListings.h,cpp: new listings inset
* src/insets/InsetListingsParams.h,cpp: parameters from listings package
* src/insets/InsetCommandParams.h,cpp: handle lstinputlisting option
* src/Bidi.cpp: handle LISTINGS_CODE
* src/frontends/qt4/ui/TextLayoutUi.ui: update UI
* src/frontends/qt4/ui/ListingsUi.ui: new dialog
* src/frontends/qt4/ui/IncludeUi.ui: update UI
* src/frontends/qt4/QInclude.h,cpp: add lstinputlisting
* src/frontends/qt4/QDocument.h,cpp: add textedit for preamble listings_params
* src/frontends/qt4/QListings.h,cpp: new listings inset
* src/frontends/qt4/Dialogs.cpp: new listings dialog
* src/frontends/controllers/ControlInclude.h,cpp: add lstinputlisting
* src/frontends/controllers/ControlListings.h,cpp: new listings inset
* src/LyXFunc.cpp: handle LISTING_CODE
* src/Paragraph.cpp: handle LISTING_CODE
* src/factory.cpp: new listings inset
* src/CutAndPaste.cpp: handle LISTINGS_CODE
* src/LaTeXFeatures.cpp: require listings
* src/Text3.cpp: Handle LISTINGS_CODE
* src/lfuns.h: add LFUN_LISTING_INSERT
* src/Buffer.cpp: change lyx file format to 269
* src/BufferParams.h,cpp: add listings_params to preamble
* lib/lyx2lyx/LyX.py: lyx2lyx
* lib/lyx2lyx/lyx_1_5.py: lyx2lyx
* lib/ui/stdmenus.inc: new menu item (no shortcut!)
* src/insets/Makefile.am: update autotools
* src/frontends/controllers/Makefile.am
* src/frontends/qt4/Makefile.dialogs
* src/frontends/qt4/Makefile.am
* po/POTFILES.in: a few more translatable files.
* development/scons/scons_manifest.py: scons build system
* development/FORMAT: document format changes
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18243 a592a061-630c-0410-9148-cb99ea01b6c8
2007-05-09 19:11:42 +00:00
|
|
|
|
os << '{' << from_utf8(incfile) << '}';
|
2000-03-02 02:19:43 +00:00
|
|
|
|
} else {
|
2006-03-28 18:49:46 +00:00
|
|
|
|
runparams.exportdata->addExternalFile(tex_format, writefile,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
exportfile);
|
2004-06-01 13:39:33 +00:00
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
// \include don't want extension and demands that the
|
|
|
|
|
// file really have .tex
|
2006-04-08 22:31:11 +00:00
|
|
|
|
incfile = changeExtension(incfile, string());
|
2005-04-18 17:43:11 +00:00
|
|
|
|
incfile = latex_path(incfile);
|
2006-10-19 16:51:30 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
os << '\\' << from_ascii(params_.getCmdName()) << '{'
|
|
|
|
|
<< from_utf8(incfile) << '}';
|
2000-03-02 02:19:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetInclude::plaintext(Buffer const & buffer, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const &) const
|
2000-12-28 16:22:28 +00:00
|
|
|
|
{
|
Add support for listings package. Two listings command \lstinline, \lstinputlisting and an environment \lstlisting are supported, along with preamble \lstset. \lstinputlisting is implemented through Include dialog, and the other two are implemented with a new inset listings, along with its dialog.
* src/LyXAction.cpp: listing-insert action
* src/insets/Inset.h,cpp: LISTINGS_CODE
* src/insets/InsetInclude.cpp: handle \lstinputlisting
* src/insets/InsetListings.h,cpp: new listings inset
* src/insets/InsetListingsParams.h,cpp: parameters from listings package
* src/insets/InsetCommandParams.h,cpp: handle lstinputlisting option
* src/Bidi.cpp: handle LISTINGS_CODE
* src/frontends/qt4/ui/TextLayoutUi.ui: update UI
* src/frontends/qt4/ui/ListingsUi.ui: new dialog
* src/frontends/qt4/ui/IncludeUi.ui: update UI
* src/frontends/qt4/QInclude.h,cpp: add lstinputlisting
* src/frontends/qt4/QDocument.h,cpp: add textedit for preamble listings_params
* src/frontends/qt4/QListings.h,cpp: new listings inset
* src/frontends/qt4/Dialogs.cpp: new listings dialog
* src/frontends/controllers/ControlInclude.h,cpp: add lstinputlisting
* src/frontends/controllers/ControlListings.h,cpp: new listings inset
* src/LyXFunc.cpp: handle LISTING_CODE
* src/Paragraph.cpp: handle LISTING_CODE
* src/factory.cpp: new listings inset
* src/CutAndPaste.cpp: handle LISTINGS_CODE
* src/LaTeXFeatures.cpp: require listings
* src/Text3.cpp: Handle LISTINGS_CODE
* src/lfuns.h: add LFUN_LISTING_INSERT
* src/Buffer.cpp: change lyx file format to 269
* src/BufferParams.h,cpp: add listings_params to preamble
* lib/lyx2lyx/LyX.py: lyx2lyx
* lib/lyx2lyx/lyx_1_5.py: lyx2lyx
* lib/ui/stdmenus.inc: new menu item (no shortcut!)
* src/insets/Makefile.am: update autotools
* src/frontends/controllers/Makefile.am
* src/frontends/qt4/Makefile.dialogs
* src/frontends/qt4/Makefile.am
* po/POTFILES.in: a few more translatable files.
* development/scons/scons_manifest.py: scons build system
* development/FORMAT: document format changes
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18243 a592a061-630c-0410-9148-cb99ea01b6c8
2007-05-09 19:11:42 +00:00
|
|
|
|
if (isVerbatim(params_) || isListings(params_)) {
|
2007-02-20 19:14:55 +00:00
|
|
|
|
os << '[' << getScreenLabel(buffer) << '\n';
|
2006-10-11 19:40:50 +00:00
|
|
|
|
// FIXME: We don't know the encoding of the file
|
2007-02-20 19:14:55 +00:00
|
|
|
|
docstring const str =
|
|
|
|
|
from_utf8(getFileContents(includedFilename(buffer, params_)));
|
2006-09-10 09:28:00 +00:00
|
|
|
|
os << str;
|
2007-02-20 19:14:55 +00:00
|
|
|
|
os << "\n]";
|
|
|
|
|
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
|
|
|
|
|
} else {
|
2007-02-24 14:35:38 +00:00
|
|
|
|
docstring const str = '[' + getScreenLabel(buffer) + ']';
|
2007-02-20 19:14:55 +00:00
|
|
|
|
os << str;
|
|
|
|
|
return str.size();
|
2006-09-10 09:28:00 +00:00
|
|
|
|
}
|
2000-12-28 16:22:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 21:00:33 +00:00
|
|
|
|
int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2000-07-01 12:54:45 +00:00
|
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
|
string incfile = to_utf8(params_["filename"]);
|
2000-09-26 13:54:57 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
// Do nothing if no file name has been specified
|
2000-09-26 13:54:57 +00:00
|
|
|
|
if (incfile.empty())
|
2000-07-01 12:54:45 +00:00
|
|
|
|
return 0;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2006-12-27 10:56:11 +00:00
|
|
|
|
string const included_file = includedFilename(buffer, params_).absFilename();
|
2003-09-19 10:16:33 +00:00
|
|
|
|
|
2007-05-21 15:34:29 +00:00
|
|
|
|
//Check we're not trying to include ourselves.
|
|
|
|
|
//FIXME RECURSIVE INCLUDE
|
|
|
|
|
//This isn't sufficient, as the inclusion could be downstream.
|
|
|
|
|
//But it'll have to do for now.
|
|
|
|
|
if (buffer.fileName() == included_file) {
|
2007-05-28 22:27:45 +00:00
|
|
|
|
Alert::error(_("Recursive input"),
|
|
|
|
|
bformat(_("Attempted to include file %1$s in itself! "
|
|
|
|
|
"Ignoring inclusion."), from_utf8(incfile)));
|
2007-05-21 15:34:29 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-01 13:39:33 +00:00
|
|
|
|
// write it to a file (so far the complete file)
|
2006-04-08 22:31:11 +00:00
|
|
|
|
string const exportfile = changeExtension(incfile, ".sgml");
|
2006-11-26 21:30:39 +00:00
|
|
|
|
DocFileName writefile(changeExtension(included_file, ".sgml"));
|
2004-06-01 13:39:33 +00:00
|
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
|
if (loadIfNeeded(buffer, params_)) {
|
2006-10-11 17:24:46 +00:00
|
|
|
|
Buffer * tmp = theBufferList().getBuffer(included_file);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
string const mangled = writefile.mangledFilename();
|
2006-04-08 22:31:11 +00:00
|
|
|
|
writefile = makeAbsPath(mangled,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
buffer.getMasterBuffer()->temppath());
|
2004-06-01 13:39:33 +00:00
|
|
|
|
if (!runparams.nice)
|
|
|
|
|
incfile = mangled;
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::LATEX) << "incfile:" << incfile << endl;
|
|
|
|
|
LYXERR(Debug::LATEX) << "exportfile:" << exportfile << endl;
|
|
|
|
|
LYXERR(Debug::LATEX) << "writefile:" << writefile << endl;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2006-12-04 15:46:57 +00:00
|
|
|
|
tmp->makeDocBookFile(writefile, runparams, true);
|
2001-03-14 10:57:39 +00:00
|
|
|
|
}
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2004-06-01 13:39:33 +00:00
|
|
|
|
runparams.exportdata->addExternalFile("docbook", writefile,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
exportfile);
|
2004-06-01 13:39:33 +00:00
|
|
|
|
runparams.exportdata->addExternalFile("docbook-xml", writefile,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
exportfile);
|
2004-06-01 13:39:33 +00:00
|
|
|
|
|
Add support for listings package. Two listings command \lstinline, \lstinputlisting and an environment \lstlisting are supported, along with preamble \lstset. \lstinputlisting is implemented through Include dialog, and the other two are implemented with a new inset listings, along with its dialog.
* src/LyXAction.cpp: listing-insert action
* src/insets/Inset.h,cpp: LISTINGS_CODE
* src/insets/InsetInclude.cpp: handle \lstinputlisting
* src/insets/InsetListings.h,cpp: new listings inset
* src/insets/InsetListingsParams.h,cpp: parameters from listings package
* src/insets/InsetCommandParams.h,cpp: handle lstinputlisting option
* src/Bidi.cpp: handle LISTINGS_CODE
* src/frontends/qt4/ui/TextLayoutUi.ui: update UI
* src/frontends/qt4/ui/ListingsUi.ui: new dialog
* src/frontends/qt4/ui/IncludeUi.ui: update UI
* src/frontends/qt4/QInclude.h,cpp: add lstinputlisting
* src/frontends/qt4/QDocument.h,cpp: add textedit for preamble listings_params
* src/frontends/qt4/QListings.h,cpp: new listings inset
* src/frontends/qt4/Dialogs.cpp: new listings dialog
* src/frontends/controllers/ControlInclude.h,cpp: add lstinputlisting
* src/frontends/controllers/ControlListings.h,cpp: new listings inset
* src/LyXFunc.cpp: handle LISTING_CODE
* src/Paragraph.cpp: handle LISTING_CODE
* src/factory.cpp: new listings inset
* src/CutAndPaste.cpp: handle LISTINGS_CODE
* src/LaTeXFeatures.cpp: require listings
* src/Text3.cpp: Handle LISTINGS_CODE
* src/lfuns.h: add LFUN_LISTING_INSERT
* src/Buffer.cpp: change lyx file format to 269
* src/BufferParams.h,cpp: add listings_params to preamble
* lib/lyx2lyx/LyX.py: lyx2lyx
* lib/lyx2lyx/lyx_1_5.py: lyx2lyx
* lib/ui/stdmenus.inc: new menu item (no shortcut!)
* src/insets/Makefile.am: update autotools
* src/frontends/controllers/Makefile.am
* src/frontends/qt4/Makefile.dialogs
* src/frontends/qt4/Makefile.am
* po/POTFILES.in: a few more translatable files.
* development/scons/scons_manifest.py: scons build system
* development/FORMAT: document format changes
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18243 a592a061-630c-0410-9148-cb99ea01b6c8
2007-05-09 19:11:42 +00:00
|
|
|
|
if (isVerbatim(params_) || isListings(params_)) {
|
2002-01-16 12:04:16 +00:00
|
|
|
|
os << "<inlinegraphic fileref=\""
|
2006-10-21 19:40:29 +00:00
|
|
|
|
<< '&' << include_label << ';'
|
2002-01-16 12:54:52 +00:00
|
|
|
|
<< "\" format=\"linespecific\">";
|
2001-03-14 10:57:39 +00:00
|
|
|
|
} else
|
2007-05-28 22:27:45 +00:00
|
|
|
|
os << '&' << include_label << ';';
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetInclude::validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
|
string incfile(to_utf8(params_["filename"]));
|
2001-03-14 10:57:39 +00:00
|
|
|
|
string writefile;
|
|
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
|
Buffer const & buffer = features.buffer();
|
|
|
|
|
|
2006-12-27 10:56:11 +00:00
|
|
|
|
string const included_file = includedFilename(buffer, params_).absFilename();
|
2000-11-13 15:43:36 +00:00
|
|
|
|
|
2006-04-08 09:09:57 +00:00
|
|
|
|
if (isLyXFilename(included_file))
|
2006-04-08 22:31:11 +00:00
|
|
|
|
writefile = changeExtension(included_file, ".sgml");
|
2004-02-25 12:00:53 +00:00
|
|
|
|
else
|
2003-09-19 10:16:33 +00:00
|
|
|
|
writefile = included_file;
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
Add support for listings package. Two listings command \lstinline, \lstinputlisting and an environment \lstlisting are supported, along with preamble \lstset. \lstinputlisting is implemented through Include dialog, and the other two are implemented with a new inset listings, along with its dialog.
* src/LyXAction.cpp: listing-insert action
* src/insets/Inset.h,cpp: LISTINGS_CODE
* src/insets/InsetInclude.cpp: handle \lstinputlisting
* src/insets/InsetListings.h,cpp: new listings inset
* src/insets/InsetListingsParams.h,cpp: parameters from listings package
* src/insets/InsetCommandParams.h,cpp: handle lstinputlisting option
* src/Bidi.cpp: handle LISTINGS_CODE
* src/frontends/qt4/ui/TextLayoutUi.ui: update UI
* src/frontends/qt4/ui/ListingsUi.ui: new dialog
* src/frontends/qt4/ui/IncludeUi.ui: update UI
* src/frontends/qt4/QInclude.h,cpp: add lstinputlisting
* src/frontends/qt4/QDocument.h,cpp: add textedit for preamble listings_params
* src/frontends/qt4/QListings.h,cpp: new listings inset
* src/frontends/qt4/Dialogs.cpp: new listings dialog
* src/frontends/controllers/ControlInclude.h,cpp: add lstinputlisting
* src/frontends/controllers/ControlListings.h,cpp: new listings inset
* src/LyXFunc.cpp: handle LISTING_CODE
* src/Paragraph.cpp: handle LISTING_CODE
* src/factory.cpp: new listings inset
* src/CutAndPaste.cpp: handle LISTINGS_CODE
* src/LaTeXFeatures.cpp: require listings
* src/Text3.cpp: Handle LISTINGS_CODE
* src/lfuns.h: add LFUN_LISTING_INSERT
* src/Buffer.cpp: change lyx file format to 269
* src/BufferParams.h,cpp: add listings_params to preamble
* lib/lyx2lyx/LyX.py: lyx2lyx
* lib/lyx2lyx/lyx_1_5.py: lyx2lyx
* lib/ui/stdmenus.inc: new menu item (no shortcut!)
* src/insets/Makefile.am: update autotools
* src/frontends/controllers/Makefile.am
* src/frontends/qt4/Makefile.dialogs
* src/frontends/qt4/Makefile.am
* po/POTFILES.in: a few more translatable files.
* development/scons/scons_manifest.py: scons build system
* development/FORMAT: document format changes
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18243 a592a061-630c-0410-9148-cb99ea01b6c8
2007-05-09 19:11:42 +00:00
|
|
|
|
if (!features.runparams().nice && !isVerbatim(params_) && !isListings(params_)) {
|
2006-11-18 12:49:47 +00:00
|
|
|
|
incfile = DocFileName(writefile).mangledFilename();
|
2006-04-08 22:31:11 +00:00
|
|
|
|
writefile = makeAbsPath(incfile,
|
2006-12-27 10:56:11 +00:00
|
|
|
|
buffer.getMasterBuffer()->temppath()).absFilename();
|
2004-02-25 12:00:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.includeFile(include_label, writefile);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2003-09-18 17:22:36 +00:00
|
|
|
|
if (isVerbatim(params_))
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("verbatim");
|
Add support for listings package. Two listings command \lstinline, \lstinputlisting and an environment \lstlisting are supported, along with preamble \lstset. \lstinputlisting is implemented through Include dialog, and the other two are implemented with a new inset listings, along with its dialog.
* src/LyXAction.cpp: listing-insert action
* src/insets/Inset.h,cpp: LISTINGS_CODE
* src/insets/InsetInclude.cpp: handle \lstinputlisting
* src/insets/InsetListings.h,cpp: new listings inset
* src/insets/InsetListingsParams.h,cpp: parameters from listings package
* src/insets/InsetCommandParams.h,cpp: handle lstinputlisting option
* src/Bidi.cpp: handle LISTINGS_CODE
* src/frontends/qt4/ui/TextLayoutUi.ui: update UI
* src/frontends/qt4/ui/ListingsUi.ui: new dialog
* src/frontends/qt4/ui/IncludeUi.ui: update UI
* src/frontends/qt4/QInclude.h,cpp: add lstinputlisting
* src/frontends/qt4/QDocument.h,cpp: add textedit for preamble listings_params
* src/frontends/qt4/QListings.h,cpp: new listings inset
* src/frontends/qt4/Dialogs.cpp: new listings dialog
* src/frontends/controllers/ControlInclude.h,cpp: add lstinputlisting
* src/frontends/controllers/ControlListings.h,cpp: new listings inset
* src/LyXFunc.cpp: handle LISTING_CODE
* src/Paragraph.cpp: handle LISTING_CODE
* src/factory.cpp: new listings inset
* src/CutAndPaste.cpp: handle LISTINGS_CODE
* src/LaTeXFeatures.cpp: require listings
* src/Text3.cpp: Handle LISTINGS_CODE
* src/lfuns.h: add LFUN_LISTING_INSERT
* src/Buffer.cpp: change lyx file format to 269
* src/BufferParams.h,cpp: add listings_params to preamble
* lib/lyx2lyx/LyX.py: lyx2lyx
* lib/lyx2lyx/lyx_1_5.py: lyx2lyx
* lib/ui/stdmenus.inc: new menu item (no shortcut!)
* src/insets/Makefile.am: update autotools
* src/frontends/controllers/Makefile.am
* src/frontends/qt4/Makefile.dialogs
* src/frontends/qt4/Makefile.am
* po/POTFILES.in: a few more translatable files.
* development/scons/scons_manifest.py: scons build system
* development/FORMAT: document format changes
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18243 a592a061-630c-0410-9148-cb99ea01b6c8
2007-05-09 19:11:42 +00:00
|
|
|
|
else if (isListings(params_))
|
|
|
|
|
features.require("listings");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Here we must do the fun stuff...
|
|
|
|
|
// Load the file in the include if it needs
|
|
|
|
|
// to be loaded:
|
2003-09-19 10:16:33 +00:00
|
|
|
|
if (loadIfNeeded(buffer, params_)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// a file got loaded
|
2006-10-11 17:24:46 +00:00
|
|
|
|
Buffer * const tmp = theBufferList().getBuffer(included_file);
|
2007-05-21 15:34:29 +00:00
|
|
|
|
// make sure the buffer isn't us
|
|
|
|
|
// FIXME RECURSIVE INCLUDES
|
|
|
|
|
// This is not sufficient, as recursive includes could be
|
|
|
|
|
// more than a file away. But it will do for now.
|
|
|
|
|
if (tmp && tmp != & buffer) {
|
2004-04-08 10:09:09 +00:00
|
|
|
|
// We must temporarily change features.buffer,
|
|
|
|
|
// otherwise it would always be the master buffer,
|
|
|
|
|
// and nested includes would not work.
|
|
|
|
|
features.setBuffer(*tmp);
|
2001-03-23 17:09:34 +00:00
|
|
|
|
tmp->validate(features);
|
2004-04-08 10:09:09 +00:00
|
|
|
|
features.setBuffer(buffer);
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
|
void InsetInclude::getLabelList(Buffer const & buffer,
|
2006-10-12 10:50:45 +00:00
|
|
|
|
std::vector<docstring> & list) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-05-18 14:40:39 +00:00
|
|
|
|
if (isListings(params_)) {
|
|
|
|
|
InsetListingsParams params(params_.getOptions());
|
|
|
|
|
string label = params.getParamValue("label");
|
|
|
|
|
if (!label.empty())
|
|
|
|
|
list.push_back(from_utf8(label));
|
|
|
|
|
}
|
|
|
|
|
else if (loadIfNeeded(buffer, params_)) {
|
2006-12-27 10:56:11 +00:00
|
|
|
|
string const included_file = includedFilename(buffer, params_).absFilename();
|
2006-10-11 17:24:46 +00:00
|
|
|
|
Buffer * tmp = theBufferList().getBuffer(included_file);
|
2001-03-14 10:57:39 +00:00
|
|
|
|
tmp->setParentName("");
|
2003-06-16 11:49:38 +00:00
|
|
|
|
tmp->getLabelList(list);
|
2004-03-25 10:12:44 +00:00
|
|
|
|
tmp->setParentName(parentFilename(buffer));
|
2000-09-26 13:54:57 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-09-19 10:16:33 +00:00
|
|
|
|
void InsetInclude::fillWithBibKeys(Buffer const & buffer,
|
2007-08-20 16:30:02 +00:00
|
|
|
|
BiblioInfo & keys, InsetIterator const & /*di*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-09-19 10:16:33 +00:00
|
|
|
|
if (loadIfNeeded(buffer, params_)) {
|
2006-12-27 10:56:11 +00:00
|
|
|
|
string const included_file = includedFilename(buffer, params_).absFilename();
|
2006-10-11 17:24:46 +00:00
|
|
|
|
Buffer * tmp = theBufferList().getBuffer(included_file);
|
2007-08-16 01:59:20 +00:00
|
|
|
|
//FIXME This is kind of a dirty hack and should be made reasonable.
|
2001-03-14 10:57:39 +00:00
|
|
|
|
tmp->setParentName("");
|
2007-08-20 16:30:02 +00:00
|
|
|
|
keys.fillWithBibKeys(tmp);
|
2004-03-25 10:12:44 +00:00
|
|
|
|
tmp->setParentName(parentFilename(buffer));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
|
|
|
2006-04-15 11:46:17 +00:00
|
|
|
|
void InsetInclude::updateBibfilesCache(Buffer const & buffer)
|
|
|
|
|
{
|
2006-05-19 07:21:43 +00:00
|
|
|
|
Buffer * const tmp = getChildBuffer(buffer, params_);
|
|
|
|
|
if (tmp) {
|
2006-04-15 11:46:17 +00:00
|
|
|
|
tmp->setParentName("");
|
|
|
|
|
tmp->updateBibfilesCache();
|
|
|
|
|
tmp->setParentName(parentFilename(buffer));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-01 20:09:08 +00:00
|
|
|
|
std::vector<FileName> const &
|
2006-04-15 11:46:17 +00:00
|
|
|
|
InsetInclude::getBibfilesCache(Buffer const & buffer) const
|
|
|
|
|
{
|
2006-05-19 07:21:43 +00:00
|
|
|
|
Buffer * const tmp = getChildBuffer(buffer, params_);
|
|
|
|
|
if (tmp) {
|
2006-04-15 11:46:17 +00:00
|
|
|
|
tmp->setParentName("");
|
2006-12-01 20:09:08 +00:00
|
|
|
|
std::vector<FileName> const & cache = tmp->getBibfilesCache();
|
2006-04-15 11:46:17 +00:00
|
|
|
|
tmp->setParentName(parentFilename(buffer));
|
|
|
|
|
return cache;
|
|
|
|
|
}
|
2006-12-01 20:09:08 +00:00
|
|
|
|
static std::vector<FileName> const empty;
|
2006-04-15 11:46:17 +00:00
|
|
|
|
return empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-08-01 17:28:59 +00:00
|
|
|
|
{
|
2007-08-21 07:33:46 +00:00
|
|
|
|
BOOST_ASSERT(mi.base.bv);
|
2004-04-19 13:05:36 +00:00
|
|
|
|
|
|
|
|
|
bool use_preview = false;
|
2004-04-19 13:31:17 +00:00
|
|
|
|
if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
graphics::PreviewImage const * pimage =
|
2007-08-21 13:03:55 +00:00
|
|
|
|
preview_->getPreviewImage(mi.base.bv->buffer());
|
2004-04-19 13:05:36 +00:00
|
|
|
|
use_preview = pimage && pimage->image();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (use_preview) {
|
2003-10-10 21:24:06 +00:00
|
|
|
|
preview_->metrics(mi, dim);
|
2003-06-02 10:03:27 +00:00
|
|
|
|
} else {
|
2003-06-12 08:52:36 +00:00
|
|
|
|
if (!set_label_) {
|
|
|
|
|
set_label_ = true;
|
2007-08-21 13:03:55 +00:00
|
|
|
|
button_.update(getScreenLabel(mi.base.bv->buffer()),
|
2004-08-14 19:20:42 +00:00
|
|
|
|
true);
|
2003-06-12 08:52:36 +00:00
|
|
|
|
}
|
|
|
|
|
button_.metrics(mi, dim);
|
2003-06-02 10:03:27 +00:00
|
|
|
|
}
|
2004-08-14 19:20:42 +00:00
|
|
|
|
|
|
|
|
|
Box b(0, dim.wid, -dim.asc, dim.des);
|
2003-09-04 14:02:05 +00:00
|
|
|
|
button_.setBox(b);
|
|
|
|
|
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool const changed = dim_ != dim;
|
2003-06-02 10:03:27 +00:00
|
|
|
|
dim_ = dim;
|
2006-11-28 15:15:49 +00:00
|
|
|
|
return changed;
|
2002-08-01 17:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
|
void InsetInclude::draw(PainterInfo & pi, int x, int y) const
|
2002-08-01 17:28:59 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2003-12-12 10:20:17 +00:00
|
|
|
|
|
2007-08-21 07:33:46 +00:00
|
|
|
|
BOOST_ASSERT(pi.base.bv);
|
2004-04-19 13:05:36 +00:00
|
|
|
|
|
|
|
|
|
bool use_preview = false;
|
2004-08-14 19:20:42 +00:00
|
|
|
|
if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
graphics::PreviewImage const * pimage =
|
2007-08-21 13:03:55 +00:00
|
|
|
|
preview_->getPreviewImage(pi.base.bv->buffer());
|
2004-04-19 13:05:36 +00:00
|
|
|
|
use_preview = pimage && pimage->image();
|
2002-08-01 17:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-04-19 13:05:36 +00:00
|
|
|
|
if (use_preview)
|
2004-08-14 19:20:42 +00:00
|
|
|
|
preview_->draw(pi, x, y);
|
2004-04-19 13:05:36 +00:00
|
|
|
|
else
|
2004-08-14 19:20:42 +00:00
|
|
|
|
button_.draw(pi, x, y);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-05-18 14:32:29 +00:00
|
|
|
|
|
|
|
|
|
Inset::DisplayType InsetInclude::display() const
|
2004-10-05 10:11:42 +00:00
|
|
|
|
{
|
2007-05-18 14:32:29 +00:00
|
|
|
|
return type(params_) == INPUT ? Inline : AlignCenter;
|
2004-08-14 19:20:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// preview stuff
|
|
|
|
|
//
|
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
|
void InsetInclude::fileChanged() const
|
2002-08-01 17:28:59 +00:00
|
|
|
|
{
|
2003-10-14 21:30:23 +00:00
|
|
|
|
Buffer const * const buffer_ptr = LyX::cref().updateInset(this);
|
|
|
|
|
if (!buffer_ptr)
|
2003-10-10 21:08:55 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2003-10-14 21:30:23 +00:00
|
|
|
|
Buffer const & buffer = *buffer_ptr;
|
2003-10-10 21:08:55 +00:00
|
|
|
|
preview_->removePreview(buffer);
|
2003-10-22 22:26:47 +00:00
|
|
|
|
add_preview(*preview_.get(), *this, buffer);
|
|
|
|
|
preview_->startLoading(buffer);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer)
|
2002-08-01 17:28:59 +00:00
|
|
|
|
{
|
2006-12-27 10:56:11 +00:00
|
|
|
|
FileName const included_file = includedFilename(buffer, params);
|
2003-09-19 10:16:33 +00:00
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
|
return type(params) == INPUT && params.preview() &&
|
2006-12-27 10:56:11 +00:00
|
|
|
|
isFileReadable(included_file);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
docstring const latex_string(InsetInclude const & inset, Buffer const & buffer)
|
2002-08-01 17:28:59 +00:00
|
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
|
odocstringstream os;
|
2007-03-25 16:45:51 +00:00
|
|
|
|
// We don't need to set runparams.encoding since this will be done
|
|
|
|
|
// by latex() anyway.
|
2007-03-18 10:59:16 +00:00
|
|
|
|
OutputParams runparams(0);
|
2003-11-05 12:06:20 +00:00
|
|
|
|
runparams.flavor = OutputParams::LATEX;
|
2003-10-10 21:08:55 +00:00
|
|
|
|
inset.latex(buffer, os, runparams);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
|
return os.str();
|
2002-08-01 17:28:59 +00:00
|
|
|
|
}
|
2002-08-06 14:02:59 +00:00
|
|
|
|
|
|
|
|
|
|
2003-10-22 22:26:47 +00:00
|
|
|
|
void add_preview(RenderMonitoredPreview & renderer, InsetInclude const & inset,
|
|
|
|
|
Buffer const & buffer)
|
2002-08-06 14:02:59 +00:00
|
|
|
|
{
|
2003-10-10 21:08:55 +00:00
|
|
|
|
InsetCommandParams const & params = inset.params();
|
2004-08-14 19:20:42 +00:00
|
|
|
|
if (RenderPreview::status() != LyXRC::PREVIEW_OFF &&
|
2004-04-19 13:31:17 +00:00
|
|
|
|
preview_wanted(params, buffer)) {
|
2006-12-27 10:56:11 +00:00
|
|
|
|
renderer.setAbsFile(includedFilename(buffer, params));
|
2006-10-19 16:51:30 +00:00
|
|
|
|
docstring const snippet = latex_string(inset, buffer);
|
2003-10-22 22:26:47 +00:00
|
|
|
|
renderer.addPreview(snippet, buffer);
|
2003-10-10 21:08:55 +00:00
|
|
|
|
}
|
2002-08-06 14:02:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
2002-08-06 14:02:59 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
void InsetInclude::addPreview(graphics::PreviewLoader & ploader) const
|
2002-08-06 14:02:59 +00:00
|
|
|
|
{
|
2003-10-22 22:26:47 +00:00
|
|
|
|
Buffer const & buffer = ploader.buffer();
|
|
|
|
|
if (preview_wanted(params(), buffer)) {
|
2006-12-27 10:56:11 +00:00
|
|
|
|
preview_->setAbsFile(includedFilename(buffer, params()));
|
2006-10-19 16:51:30 +00:00
|
|
|
|
docstring const snippet = latex_string(*this, buffer);
|
2003-10-10 21:08:55 +00:00
|
|
|
|
preview_->addPreview(snippet, ploader);
|
2003-10-09 14:36:16 +00:00
|
|
|
|
}
|
2002-08-06 14:02:59 +00:00
|
|
|
|
}
|
2003-03-05 14:59:37 +00:00
|
|
|
|
|
|
|
|
|
|
2007-06-22 13:38:07 +00:00
|
|
|
|
void InsetInclude::addToToc(TocList & toclist, Buffer const & buffer, ParConstIterator const & pit) const
|
2006-11-13 16:53:49 +00:00
|
|
|
|
{
|
2007-06-05 17:24:11 +00:00
|
|
|
|
if (isListings(params_)) {
|
|
|
|
|
InsetListingsParams params(params_.getOptions());
|
|
|
|
|
string caption = params.getParamValue("caption");
|
|
|
|
|
if (!caption.empty()) {
|
|
|
|
|
Toc & toc = toclist["listing"];
|
|
|
|
|
docstring const str = convert<docstring>(toc.size() + 1)
|
2007-06-06 21:19:15 +00:00
|
|
|
|
+ ". " + from_utf8(caption);
|
2007-06-05 17:24:11 +00:00
|
|
|
|
// This inset does not have a valid ParConstIterator
|
|
|
|
|
// so it has to use the iterator of its parent paragraph
|
|
|
|
|
toc.push_back(TocItem(pit, 0, str));
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2006-11-13 16:53:49 +00:00
|
|
|
|
Buffer const * const childbuffer = getChildBuffer(buffer, params_);
|
|
|
|
|
if (!childbuffer)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
TocList const & childtoclist = childbuffer->tocBackend().tocs();
|
|
|
|
|
TocList::const_iterator it = childtoclist.begin();
|
|
|
|
|
TocList::const_iterator const end = childtoclist.end();
|
|
|
|
|
for(; it != end; ++it)
|
|
|
|
|
toclist[it->first].insert(toclist[it->first].end(),
|
|
|
|
|
it->second.begin(), it->second.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-12 21:43:58 +00:00
|
|
|
|
void InsetInclude::updateLabels(Buffer const & buffer,
|
2007-08-15 12:15:16 +00:00
|
|
|
|
ParIterator const &)
|
2006-11-13 16:53:49 +00:00
|
|
|
|
{
|
|
|
|
|
Buffer const * const childbuffer = getChildBuffer(buffer, params_);
|
2007-08-12 21:43:58 +00:00
|
|
|
|
if (childbuffer)
|
|
|
|
|
lyx::updateLabels(*childbuffer, true);
|
|
|
|
|
else if (isListings(params_)) {
|
|
|
|
|
InsetListingsParams const par = params_.getOptions();
|
|
|
|
|
if (par.getParamValue("caption").empty())
|
|
|
|
|
listings_label_.clear();
|
|
|
|
|
else {
|
|
|
|
|
Counters & counters = buffer.params().getTextClass().counters();
|
|
|
|
|
docstring const cnt = from_ascii("listing");
|
|
|
|
|
if (counters.hasCounter(cnt)) {
|
|
|
|
|
counters.step(cnt);
|
|
|
|
|
listings_label_ = buffer.B_("Program Listing ") + convert<docstring>(counters.value(cnt));
|
|
|
|
|
} else
|
|
|
|
|
listings_label_ = buffer.B_("Program Listing");
|
|
|
|
|
}
|
2007-05-24 14:10:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-30 20:46:42 +00:00
|
|
|
|
void InsetInclude::registerEmbeddedFiles(Buffer const & buffer,
|
|
|
|
|
EmbeddedFiles & files, ParConstIterator const & pit) const
|
|
|
|
|
{
|
|
|
|
|
// include and input are temprarily not considered.
|
|
|
|
|
if (isVerbatim(params_) || isListings(params_))
|
|
|
|
|
files.registerFile(includedFilename(buffer, params_).absFilename(),
|
2007-09-07 03:02:24 +00:00
|
|
|
|
false, pit);
|
2007-08-30 20:46:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
|
string const InsetIncludeMailer::name_("include");
|
|
|
|
|
|
2003-03-05 14:59:37 +00:00
|
|
|
|
InsetIncludeMailer::InsetIncludeMailer(InsetInclude & inset)
|
2003-03-07 14:08:10 +00:00
|
|
|
|
: inset_(inset)
|
2003-03-05 14:59:37 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-07-23 09:54:21 +00:00
|
|
|
|
string const InsetIncludeMailer::inset2string(Buffer const &) const
|
2003-03-05 14:59:37 +00:00
|
|
|
|
{
|
2003-03-07 14:08:10 +00:00
|
|
|
|
return params2string(inset_.params());
|
2003-03-05 14:59:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetIncludeMailer::string2params(string const & in,
|
2003-09-19 10:16:33 +00:00
|
|
|
|
InsetCommandParams & params)
|
2003-03-05 14:59:37 +00:00
|
|
|
|
{
|
Rework InsetCommandParams interface and file storage
* src/insets/insetcommandparams.[Ch]:
(operator[]): New, access a parameter
(clear): New, clear all parameters
(info_): New, stire info about this command
(cmdname): Rename to name_
(contents, options, sec_options): Replace with params_. Parameters
are now stored as docstring.
(findInfo): New factor for command info for all commands
(read, write): Use new syntax
(parameter set and get methods): reimplemenmt for new parameter storage
* src/insets/insetcommand.h
(getParam): New, get a parameter
(setParam): New, set a parameter
(parameter set and get methods): Adjust to InsetCommandParams changes
* src/insets/insetbibitem.[Ch]
(write): Remove, not needed anymore
(directWrite): ditto
* src/insets/insetbibitem.C
(InsetBibitem::read): Use InsetCommand::read
* src/insets/insetref.C
(InsetRef::latex): Use new InsetCommandParams interface
* src/mathed/InsetMathHull.C
(InsetMathHull::doDispatch): ditto
* src/text3.C
(LyXText::dispatch): ditto
* src/factory.C
(createInset): Create InsetCommandParams with command name
(readInset): ditto
(readInset): Remove error message for bibitem, since bibitem is
now a normal command inset
* src/buffer.C: Bump file format number
* src/frontends/controllers/ControlCommand.[Ch]
(ControlCommand): take an additional command name parameter
* src/text.C
(readParToken): Remove code for \bibitem
* lib/lyx2lyx/LyX.py: Bump latest file format number
* lib/lyx2lyx/lyx_1_5.py
(convert_bibitem, convert_commandparams): new, convert to new format
(revert_commandparams): new, convert to old format
* development/FORMAT: document new format
* many other files: Adjust to the changes above
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15357 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-17 21:07:16 +00:00
|
|
|
|
params.clear();
|
2003-04-24 20:02:49 +00:00
|
|
|
|
if (in.empty())
|
|
|
|
|
return;
|
2003-05-26 09:13:55 +00:00
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
|
istringstream data(in);
|
2007-04-26 11:30:54 +00:00
|
|
|
|
Lexer lex(0,0);
|
2003-03-07 14:08:10 +00:00
|
|
|
|
lex.setStream(data);
|
2003-03-05 14:59:37 +00:00
|
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
|
string name;
|
|
|
|
|
lex >> name;
|
|
|
|
|
if (!lex || name != name_)
|
|
|
|
|
return print_mailer_error("InsetIncludeMailer", in, 1, name_);
|
2003-03-05 14:59:37 +00:00
|
|
|
|
|
|
|
|
|
// This is part of the inset proper that is usually swallowed
|
2007-04-29 23:33:02 +00:00
|
|
|
|
// by Text::readInset
|
2003-12-11 15:23:15 +00:00
|
|
|
|
string id;
|
|
|
|
|
lex >> id;
|
|
|
|
|
if (!lex || id != "Include")
|
2005-08-02 22:31:56 +00:00
|
|
|
|
return print_mailer_error("InsetIncludeMailer", in, 2, "Include");
|
2003-03-05 14:59:37 +00:00
|
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
|
InsetInclude inset(params);
|
|
|
|
|
inset.read(lex);
|
|
|
|
|
params = inset.params();
|
2003-03-05 14:59:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const
|
2003-09-19 10:16:33 +00:00
|
|
|
|
InsetIncludeMailer::params2string(InsetCommandParams const & params)
|
2003-03-05 14:59:37 +00:00
|
|
|
|
{
|
|
|
|
|
InsetInclude inset(params);
|
|
|
|
|
ostringstream data;
|
2003-03-07 14:08:10 +00:00
|
|
|
|
data << name_ << ' ';
|
2003-08-28 07:41:31 +00:00
|
|
|
|
inset.write(data);
|
2003-03-05 14:59:37 +00:00
|
|
|
|
data << "\\end_inset\n";
|
2003-09-15 11:00:00 +00:00
|
|
|
|
return data.str();
|
2003-03-05 14:59:37 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|