Tommaso patch, part 5, lots of thing to cleanup still but I'll do that afterwards.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27521 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-11-16 00:12:21 +00:00
parent a287184d72
commit 4209cbc631
12 changed files with 91 additions and 27 deletions

View File

@ -375,6 +375,12 @@ string const Buffer::temppath() const
} }
TexRow & Buffer::texrow()
{
return d->texrow;
}
TexRow const & Buffer::texrow() const TexRow const & Buffer::texrow() const
{ {
return d->texrow; return d->texrow;

View File

@ -348,6 +348,7 @@ public:
/// Used when typesetting to place errorboxes. /// Used when typesetting to place errorboxes.
TexRow const & texrow() const; TexRow const & texrow() const;
TexRow & texrow();
/// ///
ParIterator par_iterator_begin(); ParIterator par_iterator_begin();

View File

@ -878,6 +878,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
case LFUN_NOTE_NEXT: case LFUN_NOTE_NEXT:
case LFUN_REFERENCE_NEXT: case LFUN_REFERENCE_NEXT:
case LFUN_WORD_FIND: case LFUN_WORD_FIND:
case LFUN_WORD_FINDADV:
case LFUN_WORD_REPLACE: case LFUN_WORD_REPLACE:
case LFUN_MARK_OFF: case LFUN_MARK_OFF:
case LFUN_MARK_ON: case LFUN_MARK_ON:
@ -891,6 +892,11 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
flag.setEnabled(true); flag.setEnabled(true);
break; break;
// @todo Test if current WorkArea is the search WorkArea
case LFUN_REGEXP_MODE:
flag.setEnabled(! this->cursor().inRegexped());
break;
case LFUN_NEXT_INSET_TOGGLE: case LFUN_NEXT_INSET_TOGGLE:
case LFUN_NEXT_INSET_MODIFY: { case LFUN_NEXT_INSET_MODIFY: {
// this is the real function we want to invoke // this is the real function we want to invoke
@ -1232,6 +1238,10 @@ bool BufferView::dispatch(FuncRequest const & cmd)
break; break;
} }
case LFUN_WORD_FINDADV:
findAdv(this, cmd);
break;
case LFUN_MARK_OFF: case LFUN_MARK_OFF:
cur.clearSelection(); cur.clearSelection();
cur.resetAnchor(); cur.resetAnchor();

View File

@ -20,6 +20,7 @@
#include "mathed/MathData.h" #include "mathed/MathData.h"
#include "mathed/InsetMath.h" #include "mathed/InsetMath.h"
#include "mathed/InsetMathHull.h"
#include "insets/InsetTabular.h" #include "insets/InsetTabular.h"
@ -60,6 +61,13 @@ DocIterator doc_iterator_end(Inset & inset)
} }
bool DocIterator::inRegexped() const
{
InsetMathHull * i = dynamic_cast<InsetMathHull *>(inset().asInsetMath());
return i && i->getType() == hullRegexp;
}
LyXErr & operator<<(LyXErr & os, DocIterator const & it) LyXErr & operator<<(LyXErr & os, DocIterator const & it)
{ {
os.stream() << it; os.stream() << it;

View File

@ -124,6 +124,8 @@ public:
/// are we in texted?. /// are we in texted?.
bool inTexted() const bool inTexted() const
{ return !empty() && !inset().inMathed(); } { return !empty() && !inset().inMathed(); }
/// are we in regexp-mode ?
bool inRegexped() const;
// //
// math-specific part // math-specific part

View File

@ -568,6 +568,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
case LFUN_WORD_FIND_FORWARD: case LFUN_WORD_FIND_FORWARD:
case LFUN_WORD_FIND_BACKWARD: case LFUN_WORD_FIND_BACKWARD:
case LFUN_WORD_FINDADV:
case LFUN_COMMAND_PREFIX: case LFUN_COMMAND_PREFIX:
case LFUN_COMMAND_EXECUTE: case LFUN_COMMAND_EXECUTE:
case LFUN_CANCEL: case LFUN_CANCEL:

View File

@ -1909,7 +1909,8 @@ int Paragraph::Private::endTeXParParams(BufferParams const & bparams,
bool Paragraph::latex(BufferParams const & bparams, bool Paragraph::latex(BufferParams const & bparams,
Font const & outerfont, Font const & outerfont,
odocstream & os, TexRow & texrow, odocstream & os, TexRow & texrow,
OutputParams const & runparams) const OutputParams const & runparams,
int start_pos, int end_pos) const
{ {
LYXERR(Debug::LATEX, "Paragraph::latex... " << this); LYXERR(Debug::LATEX, "Paragraph::latex... " << this);
@ -2083,7 +2084,7 @@ bool Paragraph::latex(BufferParams const & bparams,
os << fontchange; os << fontchange;
} }
if (c == ' ') { if (c == ' ' && i >= start_pos && i < end_pos) {
// FIXME: integrate this case in latexSpecialChar // FIXME: integrate this case in latexSpecialChar
// Do not print the separation of the optional argument // Do not print the separation of the optional argument
// if style.pass_thru is false. This works because // if style.pass_thru is false. This works because
@ -2111,12 +2112,14 @@ bool Paragraph::latex(BufferParams const & bparams,
// Two major modes: LaTeX or plain // Two major modes: LaTeX or plain
// Handle here those cases common to both modes // Handle here those cases common to both modes
// and then split to handle the two modes separately. // and then split to handle the two modes separately.
if (c == META_INSET) if (c == META_INSET) {
if (i >= start_pos && i < end_pos)
d->latexInset(bparams, os, d->latexInset(bparams, os,
texrow, rp, running_font, texrow, rp, running_font,
basefont, outerfont, open_font, basefont, outerfont, open_font,
runningChange, style, i, column); runningChange, style, i, column);
else { } else {
if (i >= start_pos && i < end_pos) {
try { try {
d->latexSpecialChar(os, rp, running_font, runningChange, d->latexSpecialChar(os, rp, running_font, runningChange,
style, i, column); style, i, column);
@ -2134,6 +2137,7 @@ bool Paragraph::latex(BufferParams const & bparams,
} }
} }
} }
}
// Set the encoding to that returned from latexSpecialChar (see // Set the encoding to that returned from latexSpecialChar (see
// comment for encoding member in OutputParams.h) // comment for encoding member in OutputParams.h)

View File

@ -132,7 +132,8 @@ public:
/// ///
bool latex(BufferParams const &, Font const & outerfont, odocstream &, bool latex(BufferParams const &, Font const & outerfont, odocstream &,
TexRow & texrow, OutputParams const &) const; TexRow & texrow, OutputParams const &,
int start_pos = -1, int end_pos = -1) const;
/// Can we drop the standard paragraph wrapper? /// Can we drop the standard paragraph wrapper?
bool emptyTag() const; bool emptyTag() const;

View File

@ -48,6 +48,9 @@
#include "frontends/Clipboard.h" #include "frontends/Clipboard.h"
#include "frontends/Selection.h" #include "frontends/Selection.h"
#include "frontends/Application.h"
#include "frontends/LyXView.h"
#include "frontends/WorkArea.h"
#include "insets/InsetCollapsable.h" #include "insets/InsetCollapsable.h"
#include "insets/InsetCommand.h" #include "insets/InsetCommand.h"
@ -84,6 +87,8 @@ using cap::pasteFromStack;
using cap::pasteClipboardText; using cap::pasteClipboardText;
using cap::pasteClipboardGraphics; using cap::pasteClipboardGraphics;
using cap::replaceSelection; using cap::replaceSelection;
using cap::grabAndEraseSelection;
using cap::selClearOrDel;
// globals... // globals...
static Font freefont(ignore_font, ignore_language); static Font freefont(ignore_font, ignore_language);
@ -187,6 +192,26 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
} }
void regexpDispatch(Cursor & cur, FuncRequest const & cmd)
{
BOOST_ASSERT(cmd.action == LFUN_REGEXP_MODE);
if (cur.inRegexped()) {
cur.message(_("Already in regexp mode"));
return;
}
cur.recordUndo();
docstring const save_selection = grabAndEraseSelection(cur);
selClearOrDel(cur);
// replaceSelection(cur);
cur.insert(new InsetMathHull(hullRegexp));
cur.nextInset()->edit(cur, true);
cur.niceInsert(save_selection);
cur.message(_("Regexp editor mode"));
}
static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind) static void specialChar(Cursor & cur, InsetSpecialChar::Kind kind)
{ {
cur.recordUndo(); cur.recordUndo();
@ -1487,6 +1512,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
mathDispatch(cur, cmd, true); mathDispatch(cur, cmd, true);
break; break;
case LFUN_REGEXP_MODE:
regexpDispatch(cur, cmd);
break;
case LFUN_MATH_MODE: case LFUN_MATH_MODE:
if (cmd.argument() == "on") if (cmd.argument() == "on")
// don't pass "on" as argument // don't pass "on" as argument

View File

@ -735,8 +735,10 @@ docstring latexifyFromCursor(Buffer const & buf, DocIterator const & cur, int le
// ParagraphList::const_iterator pit_end = pit; // ParagraphList::const_iterator pit_end = pit;
// ++pit_end; // ++pit_end;
// lyx::latexParagraphs(buf, cur.innerText()->paragraphs(), ods, texrow, runparams, string(), pit, pit_end); // lyx::latexParagraphs(buf, cur.innerText()->paragraphs(), ods, texrow, runparams, string(), pit, pit_end);
pos_type const endpos = (len == -1 || cur.pos() + len > int(pit->size()))
? pit->size() : cur.pos() + len;
TeXOnePar(buf, *cur.innerText(), pit, ods, texrow, runparams, string(), TeXOnePar(buf, *cur.innerText(), pit, ods, texrow, runparams, string(),
cur.pos(), ( len == -1 || cur.pos() + len > int(pit->size()) ) ? -1 : cur.pos() + len); cur.pos(), endpos);
LYXERR(Debug::DEBUG, "Latexified text: '" << lyx::to_utf8(ods.str()) << "'"); LYXERR(Debug::DEBUG, "Latexified text: '" << lyx::to_utf8(ods.str()) << "'");
} else if (cur.inMathed()) { } else if (cur.inMathed()) {
// Retrieve the math environment type, and add '$' or '$[' or others (\begin{equation}) accordingly // Retrieve the math environment type, and add '$' or '$[' or others (\begin{equation}) accordingly

View File

@ -61,14 +61,6 @@ TeXEnvironment(Buffer const & buf,
odocstream & os, TexRow & texrow, odocstream & os, TexRow & texrow,
OutputParams const & runparams); OutputParams const & runparams);
ParagraphList::const_iterator
TeXOnePar(Buffer const & buf,
Text const & text,
ParagraphList::const_iterator pit,
odocstream & os, TexRow & texrow,
OutputParams const & runparams,
string const & everypar = string());
ParagraphList::const_iterator ParagraphList::const_iterator
TeXDeeper(Buffer const & buf, TeXDeeper(Buffer const & buf,
@ -277,16 +269,14 @@ int latexOptArgInsets(Paragraph const & par, odocstream & os,
return lines; return lines;
} }
// FIXME: this should be anonymous
namespace { ParagraphList::const_iterator TeXOnePar(Buffer const & buf,
ParagraphList::const_iterator
TeXOnePar(Buffer const & buf,
Text const & text, Text const & text,
ParagraphList::const_iterator const pit, ParagraphList::const_iterator const pit,
odocstream & os, TexRow & texrow, odocstream & os, TexRow & texrow,
OutputParams const & runparams_in, OutputParams const & runparams_in,
string const & everypar) string const & everypar,
int start_pos, int end_pos)
{ {
LYXERR(Debug::LATEX, "TeXOnePar... " << &*pit << " '" LYXERR(Debug::LATEX, "TeXOnePar... " << &*pit << " '"
<< everypar << "'"); << everypar << "'");
@ -312,7 +302,7 @@ TeXOnePar(Buffer const & buf,
} }
/*bool need_par = */ pit->latex(bparams, outerfont, /*bool need_par = */ pit->latex(bparams, outerfont,
os, texrow, runparams); os, texrow, runparams, start_pos, end_pos);
return nextpit; return nextpit;
} }
@ -543,7 +533,7 @@ TeXOnePar(Buffer const & buf,
// FIXME UNICODE // FIXME UNICODE
os << from_utf8(everypar); os << from_utf8(everypar);
bool need_par = pit->latex(bparams, outerfont, bool need_par = pit->latex(bparams, outerfont,
os, texrow, runparams); os, texrow, runparams, start_pos, end_pos);
// Make sure that \\par is done with the font of the last // Make sure that \\par is done with the font of the last
// character if this has another size as the default. // character if this has another size as the default.
@ -747,8 +737,6 @@ TeXOnePar(Buffer const & buf,
return nextpit; return nextpit;
} }
} // anon namespace
// LaTeX all paragraphs // LaTeX all paragraphs
void latexParagraphs(Buffer const & buf, void latexParagraphs(Buffer const & buf,

View File

@ -15,6 +15,9 @@
#include <utility> #include <utility>
#include "support/docstream.h" #include "support/docstream.h"
#include "Paragraph.h"
#include "ParIterator.h"
#include "ParagraphList.h"
namespace lyx { namespace lyx {
@ -53,6 +56,15 @@ std::pair<bool, int> switchEncoding(odocstream & os,
OutputParams const &, Encoding const & newEnc, OutputParams const &, Encoding const & newEnc,
bool force = false); bool force = false);
/// FIXME: this should not be visible.
ParagraphList::const_iterator TeXOnePar(Buffer const & buf,
Text const & text,
ParagraphList::const_iterator pit,
odocstream & os, TexRow & texrow,
OutputParams const & runparams,
std::string const & everypar = std::string(),
int start_pos = -1, int end_pos = -1);
} // namespace lyx } // namespace lyx
#endif #endif