2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetNote.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.
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
* \author Angus Leeming
|
2003-08-01 15:36:47 +00:00
|
|
|
* \author Martin Vermeer
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-07-20 09:57:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetNote.h"
|
2003-09-04 01:01:13 +00:00
|
|
|
|
2007-05-01 08:26:40 +00:00
|
|
|
#include "Buffer.h"
|
2007-08-12 21:43:58 +00:00
|
|
|
#include "BufferParams.h"
|
2001-07-20 09:57:23 +00:00
|
|
|
#include "BufferView.h"
|
2007-08-13 12:13:17 +00:00
|
|
|
#include "BufferParams.h"
|
2007-08-12 21:43:58 +00:00
|
|
|
#include "Counters.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.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"
|
2008-06-18 18:16:50 +00:00
|
|
|
#include "InsetIterator.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2010-02-13 16:22:39 +00:00
|
|
|
#include "LyXRC.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "OutputParams.h"
|
2008-02-11 13:06:01 +00:00
|
|
|
#include "ParIterator.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
#include "TextClass.h"
|
2008-02-11 13:06:01 +00:00
|
|
|
#include "TocBackend.h"
|
2003-09-04 01:01:13 +00:00
|
|
|
|
2008-02-14 07:30:33 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "support/docstream.h"
|
2008-06-18 18:16:50 +00:00
|
|
|
#include "support/gettext.h"
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
#include "support/Translator.h"
|
2001-07-20 09:57:23 +00:00
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
#include "frontends/Application.h"
|
|
|
|
|
2007-08-12 08:57:17 +00:00
|
|
|
#include <algorithm>
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
2006-09-09 18:52:00 +00:00
|
|
|
|
2003-12-10 17:28:14 +00:00
|
|
|
namespace {
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
typedef Translator<string, InsetNoteParams::Type> NoteTranslator;
|
2006-12-22 09:23:10 +00:00
|
|
|
typedef Translator<docstring, InsetNoteParams::Type> NoteTranslatorLoc;
|
2003-12-10 17:28:14 +00:00
|
|
|
|
2006-09-09 15:27:44 +00:00
|
|
|
NoteTranslator const init_notetranslator()
|
|
|
|
{
|
2003-12-10 17:28:14 +00:00
|
|
|
NoteTranslator translator("Note", InsetNoteParams::Note);
|
|
|
|
translator.addPair("Comment", InsetNoteParams::Comment);
|
|
|
|
translator.addPair("Greyedout", InsetNoteParams::Greyedout);
|
|
|
|
return translator;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-09 15:27:44 +00:00
|
|
|
NoteTranslator const & notetranslator()
|
|
|
|
{
|
2003-12-10 17:28:14 +00:00
|
|
|
static NoteTranslator translator = init_notetranslator();
|
|
|
|
return translator;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // anon
|
|
|
|
|
|
|
|
|
|
|
|
InsetNoteParams::InsetNoteParams()
|
|
|
|
: type(Note)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNoteParams::write(ostream & os) const
|
|
|
|
{
|
|
|
|
string const label = notetranslator().find(type);
|
|
|
|
os << "Note " << label << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
void InsetNoteParams::read(Lexer & lex)
|
2003-12-10 17:28:14 +00:00
|
|
|
{
|
|
|
|
string label;
|
|
|
|
lex >> label;
|
2007-03-26 13:43:49 +00:00
|
|
|
if (lex)
|
2003-12-10 17:28:14 +00:00
|
|
|
type = notetranslator().find(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-05 00:21:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2009-01-19 23:59:57 +00:00
|
|
|
// InsetNote
|
2008-03-05 00:21:05 +00:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetNote::InsetNote(Buffer * buf, string const & label)
|
2008-03-04 22:28:18 +00:00
|
|
|
: InsetCollapsable(buf)
|
2001-07-23 09:11:14 +00:00
|
|
|
{
|
2003-12-10 17:28:14 +00:00
|
|
|
params_.type = notetranslator().find(label);
|
2001-07-23 09:11:14 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 10:13:19 +00:00
|
|
|
|
2003-09-22 07:39:46 +00:00
|
|
|
InsetNote::~InsetNote()
|
2003-07-08 14:19:25 +00:00
|
|
|
{
|
2008-03-27 22:26:24 +00:00
|
|
|
hideDialogs("note", this);
|
2003-07-08 14:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-13 12:13:17 +00:00
|
|
|
docstring InsetNote::name() const
|
|
|
|
{
|
2008-02-14 07:30:33 +00:00
|
|
|
return from_ascii("Note:" + notetranslator().find(params_.type));
|
2007-08-13 12:13:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-18 20:00:19 +00:00
|
|
|
Inset::DisplayType InsetNote::display() const
|
|
|
|
{
|
2007-12-04 09:25:50 +00:00
|
|
|
return Inline;
|
2007-05-18 20:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetNote::write(ostream & os) const
|
2001-07-20 09:57:23 +00:00
|
|
|
{
|
2003-07-08 14:19:25 +00:00
|
|
|
params_.write(os);
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetCollapsable::write(os);
|
2001-07-20 09:57:23 +00:00
|
|
|
}
|
2003-07-08 14:19:25 +00:00
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetNote::read(Lexer & lex)
|
2003-07-08 14:19:25 +00:00
|
|
|
{
|
2003-12-10 17:28:14 +00:00
|
|
|
params_.read(lex);
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetCollapsable::read(lex);
|
2003-07-08 14:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-15 23:52:05 +00:00
|
|
|
bool InsetNote::showInsetDialog(BufferView * bv) const
|
|
|
|
{
|
2008-03-27 22:26:24 +00:00
|
|
|
bv->showDialog("note", params2string(params()),
|
|
|
|
const_cast<InsetNote *>(this));
|
2003-07-15 23:52:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
2003-07-08 14:19:25 +00:00
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetNote::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2003-07-08 14:19:25 +00:00
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2003-08-05 08:07:07 +00:00
|
|
|
|
2004-02-16 11:58:51 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
2010-11-29 09:47:46 +00:00
|
|
|
cur.recordUndoInset(ATOMIC_UNDO, this);
|
2008-03-27 22:26:24 +00:00
|
|
|
string2params(to_utf8(cmd.argument()), params_);
|
2009-08-25 00:04:47 +00:00
|
|
|
setButtonLabel();
|
2010-07-09 14:37:00 +00:00
|
|
|
// what we really want here is a TOC update, but that means
|
|
|
|
// a full buffer update
|
|
|
|
cur.forceBufferUpdate();
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-08-05 08:07:07 +00:00
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2008-03-27 22:26:24 +00:00
|
|
|
cur.bv().updateDialog("note", params2string(params()));
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2008-03-27 22:26:24 +00:00
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-07-08 14:19:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetNote::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2005-04-22 08:57:22 +00:00
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2005-04-22 08:57:22 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY:
|
2008-03-24 13:33:48 +00:00
|
|
|
// disallow comment and greyed out in commands
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(!cur.paragraph().layout().isCommand() ||
|
2008-03-24 13:33:48 +00:00
|
|
|
cmd.getArg(2) == "Note");
|
|
|
|
if (cmd.getArg(0) == "note") {
|
|
|
|
InsetNoteParams params;
|
2008-03-27 22:26:24 +00:00
|
|
|
string2params(to_utf8(cmd.argument()), params);
|
2008-03-24 13:33:48 +00:00
|
|
|
flag.setOnOff(params_.type == params.type);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
2005-04-22 08:57:22 +00:00
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(true);
|
2005-04-22 08:57:22 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-24 13:33:48 +00:00
|
|
|
|
2011-01-12 22:23:27 +00:00
|
|
|
void InsetNote::addToToc(DocIterator const & cpit) const
|
2008-02-11 13:06:01 +00:00
|
|
|
{
|
2008-05-13 08:23:44 +00:00
|
|
|
DocIterator pit = cpit;
|
2011-01-12 22:23:27 +00:00
|
|
|
pit.push_back(CursorSlice(const_cast<InsetNote &>(*this)));
|
2008-02-11 13:06:01 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
Toc & toc = buffer().tocBackend().toc("note");
|
2010-12-14 23:50:50 +00:00
|
|
|
InsetLayout const & il = getLayout();
|
2010-12-20 21:55:09 +00:00
|
|
|
docstring str = translateIfPossible(il.labelstring()) + from_ascii(": ");
|
|
|
|
text().forToc(str, TOC_ENTRY_LENGTH);
|
2010-12-22 01:29:17 +00:00
|
|
|
toc.push_back(TocItem(pit, 0, str, toolTipText(docstring(), 3, 60)));
|
2008-06-03 11:33:13 +00:00
|
|
|
// Proceed with the rest of the inset.
|
|
|
|
InsetCollapsable::addToToc(cpit);
|
2008-02-11 13:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
bool InsetNote::isMacroScope() const
|
2007-12-21 20:42:46 +00:00
|
|
|
{
|
|
|
|
// LyX note has no latex output
|
|
|
|
if (params_.type == InsetNoteParams::Note)
|
|
|
|
return true;
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
return InsetCollapsable::isMacroScope();
|
2007-12-21 20:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
int InsetNote::latex(otexstream & os, OutputParams const & runparams_in) const
|
2003-07-08 14:19:25 +00:00
|
|
|
{
|
2003-12-10 17:28:14 +00:00
|
|
|
if (params_.type == InsetNoteParams::Note)
|
|
|
|
return 0;
|
|
|
|
|
2006-01-09 21:00:24 +00:00
|
|
|
OutputParams runparams(runparams_in);
|
|
|
|
if (params_.type == InsetNoteParams::Comment) {
|
|
|
|
runparams.inComment = true;
|
|
|
|
// Ignore files that are exported inside a comment
|
|
|
|
runparams.exportdata.reset(new ExportData);
|
2007-08-20 04:58:29 +00:00
|
|
|
}
|
2003-12-10 17:28:14 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
odocstringstream ss;
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
otexstream ots(ss);
|
|
|
|
ots.canBreakLine(os.canBreakLine());
|
|
|
|
InsetCollapsable::latex(ots, runparams);
|
|
|
|
docstring const str = ss.str();
|
|
|
|
os << str;
|
|
|
|
|
2006-08-15 15:12:26 +00:00
|
|
|
// the space after the comment in 'a[comment] b' will be eaten by the
|
|
|
|
// comment environment since the space before b is ignored with the
|
|
|
|
// following latex output:
|
|
|
|
//
|
|
|
|
// a%
|
|
|
|
// \begin{comment}
|
|
|
|
// comment
|
|
|
|
// \end{comment}
|
|
|
|
// b
|
|
|
|
//
|
|
|
|
// Adding {} before ' b' fixes this.
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
// The {} will be automatically added, but only if needed, by
|
|
|
|
// telling otexstream to protect an immediately following space.
|
|
|
|
os.protectSpace(ots.protectSpace());
|
2003-12-10 17:28:14 +00:00
|
|
|
|
2007-03-18 10:59:16 +00:00
|
|
|
runparams_in.encoding = runparams.encoding;
|
2003-12-10 17:28:14 +00:00
|
|
|
// Return how many newlines we issued.
|
2007-12-12 19:28:07 +00:00
|
|
|
return int(count(str.begin(), str.end(), '\n'));
|
2003-07-08 14:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetNote::plaintext(odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
OutputParams const & runparams_in) const
|
2003-07-08 14:19:25 +00:00
|
|
|
{
|
2003-12-10 17:28:14 +00:00
|
|
|
if (params_.type == InsetNoteParams::Note)
|
|
|
|
return 0;
|
2003-07-27 13:02:26 +00:00
|
|
|
|
2006-01-09 21:00:24 +00:00
|
|
|
OutputParams runparams(runparams_in);
|
|
|
|
if (params_.type == InsetNoteParams::Comment) {
|
|
|
|
runparams.inComment = true;
|
|
|
|
// Ignore files that are exported inside a comment
|
|
|
|
runparams.exportdata.reset(new ExportData);
|
|
|
|
}
|
2008-02-27 20:43:16 +00:00
|
|
|
os << '[' << buffer().B_("note") << ":\n";
|
|
|
|
InsetText::plaintext(os, runparams);
|
2007-02-15 22:59:06 +00:00
|
|
|
os << "\n]";
|
2003-07-27 13:02:26 +00:00
|
|
|
|
2007-02-20 17:52:41 +00:00
|
|
|
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
|
2003-07-08 14:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetNote::docbook(odocstream & os, OutputParams const & runparams_in) const
|
2003-07-08 14:19:25 +00:00
|
|
|
{
|
2003-12-10 17:28:14 +00:00
|
|
|
if (params_.type == InsetNoteParams::Note)
|
|
|
|
return 0;
|
|
|
|
|
2006-01-09 21:00:24 +00:00
|
|
|
OutputParams runparams(runparams_in);
|
|
|
|
if (params_.type == InsetNoteParams::Comment) {
|
2007-02-15 22:59:06 +00:00
|
|
|
os << "<remark>\n";
|
2006-01-09 21:00:24 +00:00
|
|
|
runparams.inComment = true;
|
|
|
|
// Ignore files that are exported inside a comment
|
|
|
|
runparams.exportdata.reset(new ExportData);
|
|
|
|
}
|
2007-02-15 22:59:06 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int const n = InsetText::docbook(os, runparams);
|
2007-02-15 22:59:06 +00:00
|
|
|
|
|
|
|
if (params_.type == InsetNoteParams::Comment)
|
|
|
|
os << "\n</remark>\n";
|
2003-12-10 17:28:14 +00:00
|
|
|
|
|
|
|
// Return how many newlines we issued.
|
2007-02-15 22:59:06 +00:00
|
|
|
//return int(count(str.begin(), str.end(), '\n'));
|
2007-05-28 22:27:45 +00:00
|
|
|
return n + 1 + 2;
|
2003-07-08 14:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-25 21:58:18 +00:00
|
|
|
docstring InsetNote::xhtml(XHTMLStream & xs, OutputParams const & rp) const
|
2009-06-05 19:58:23 +00:00
|
|
|
{
|
|
|
|
if (params_.type == InsetNoteParams::Note)
|
2009-06-12 17:23:17 +00:00
|
|
|
return docstring();
|
2009-06-05 19:58:23 +00:00
|
|
|
|
2009-11-25 21:58:18 +00:00
|
|
|
return InsetCollapsable::xhtml(xs, rp);
|
2009-06-05 19:58:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
void InsetNote::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
2008-12-12 15:38:52 +00:00
|
|
|
switch (params_.type) {
|
|
|
|
case InsetNoteParams::Comment:
|
2003-07-08 14:19:25 +00:00
|
|
|
features.require("verbatim");
|
2008-12-12 15:38:52 +00:00
|
|
|
break;
|
|
|
|
case InsetNoteParams::Greyedout:
|
2003-07-08 14:19:25 +00:00
|
|
|
features.require("color");
|
2003-07-29 12:20:04 +00:00
|
|
|
features.require("lyxgreyedout");
|
2008-12-12 15:38:52 +00:00
|
|
|
InsetCollapsable::validate(features);
|
|
|
|
break;
|
|
|
|
case InsetNoteParams::Note:
|
|
|
|
break;
|
2003-07-29 12:20:04 +00:00
|
|
|
}
|
2003-07-08 14:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-29 21:27:25 +00:00
|
|
|
docstring InsetNote::contextMenuName() const
|
2008-03-24 13:33:48 +00:00
|
|
|
{
|
|
|
|
return from_ascii("context-note");
|
|
|
|
}
|
|
|
|
|
2010-02-13 16:22:39 +00:00
|
|
|
bool InsetNote::allowSpellCheck() const
|
|
|
|
{
|
|
|
|
return (params_.type == InsetNoteParams::Greyedout || lyxrc.spellcheck_notes);
|
|
|
|
}
|
|
|
|
|
2003-07-08 14:19:25 +00:00
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
string InsetNote::params2string(InsetNoteParams const & params)
|
2003-07-08 14:19:25 +00:00
|
|
|
{
|
|
|
|
ostringstream data;
|
2008-03-27 22:26:24 +00:00
|
|
|
data << "note" << ' ';
|
2003-07-08 14:19:25 +00:00
|
|
|
params.write(data);
|
2003-09-15 11:00:00 +00:00
|
|
|
return data.str();
|
2003-07-08 14:19:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
void InsetNote::string2params(string const & in, InsetNoteParams & params)
|
2003-07-08 14:19:25 +00:00
|
|
|
{
|
|
|
|
params = InsetNoteParams();
|
|
|
|
|
|
|
|
if (in.empty())
|
|
|
|
return;
|
|
|
|
|
2003-09-15 11:00:00 +00:00
|
|
|
istringstream data(in);
|
2008-04-02 23:06:22 +00:00
|
|
|
Lexer lex;
|
2003-07-08 14:19:25 +00:00
|
|
|
lex.setStream(data);
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.setContext("InsetNote::string2params");
|
2009-02-19 04:18:31 +00:00
|
|
|
lex >> "note";
|
|
|
|
// There are cases, such as when we are called via getStatus() from
|
|
|
|
// Dialog::canApply(), where we are just called with "note" rather
|
|
|
|
// than a full "note Note TYPE".
|
|
|
|
if (!lex.isOK())
|
|
|
|
return;
|
|
|
|
lex >> "Note";
|
2003-12-10 17:28:14 +00:00
|
|
|
|
|
|
|
params.read(lex);
|
2003-07-08 14:19:25 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2008-11-17 11:46:07 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|