IU stuff + shuffling things from BV::dispatch to LyXText::dispatch

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8427 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2004-02-13 07:30:59 +00:00
parent df974a3904
commit 4bcfc43c29
25 changed files with 566 additions and 602 deletions

View File

@ -324,26 +324,6 @@ void BufferView::gotoLabel(string const & label)
} }
void BufferView::replaceWord(string const & replacestring)
{
if (!available())
return;
LyXText * t = getLyXText();
t->replaceSelectionWithString(replacestring);
t->setSelectionRange(replacestring.length());
// Go back so that replacement string is also spellchecked
for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
t->cursorLeft(cursor(), this);
// FIXME: should be done through LFUN
buffer()->markDirty();
update();
}
void BufferView::hideCursor() void BufferView::hideCursor()
{ {
screen().hideCursor(); screen().hideCursor();
@ -455,7 +435,7 @@ void BufferView::putSelectionAt(PosIterator const & cur,
cursor().updatePos(); cursor().updatePos();
if (length) { if (length) {
text->setSelectionRange(length); text->setSelectionRange(cursor(), length);
cursor().setSelection(); cursor().setSelection();
if (backwards) if (backwards)
swap(cursor().cursor_, cursor().anchor_); swap(cursor().cursor_, cursor().anchor_);

View File

@ -117,8 +117,6 @@ public:
/// return the parent language of the given inset /// return the parent language of the given inset
Language const * getParentLanguage(InsetOld * inset) const; Language const * getParentLanguage(InsetOld * inset) const;
/// replace the currently selected word
void replaceWord(std::string const & replacestring);
/// simple replacing. Use the font of the first selected character /// simple replacing. Use the font of the first selected character
void replaceSelectionWithString(std::string const & str); void replaceSelectionWithString(std::string const & str);

View File

@ -65,8 +65,6 @@
#include <boost/bind.hpp> #include <boost/bind.hpp>
using bv_funcs::currentState;
using lyx::pos_type; using lyx::pos_type;
using lyx::support::AddPath; using lyx::support::AddPath;
@ -975,7 +973,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
<< " button[" << cmd.button() << ']' << " button[" << cmd.button() << ']'
<< endl; << endl;
LyXTextClass const & tclass = buffer_->params().getLyXTextClass();
LCursor & cur = bv_->cursor(); LCursor & cur = bv_->cursor();
switch (cmd.action) { switch (cmd.action) {
@ -1015,7 +1012,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
break; break;
case LFUN_FONT_STATE: case LFUN_FONT_STATE:
owner_->getLyXFunc().setMessage(currentState(bv_)); cur.message(cur.currentState());
break; break;
case LFUN_INSERT_LABEL: { case LFUN_INSERT_LABEL: {
@ -1049,31 +1046,13 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
if (!label.empty()) if (!label.empty())
bv_->gotoLabel(label); bv_->gotoLabel(label);
break;
} }
break;
case LFUN_PARAGRAPH_APPLY: case LFUN_PARAGRAPH_APPLY:
setParagraphParams(*bv_, cmd.argument); setParagraphParams(*bv_, cmd.argument);
break; break;
case LFUN_THESAURUS_ENTRY: {
string arg = cmd.argument;
if (arg.empty()) {
arg = cur.selectionAsString(false);
// FIXME
if (arg.size() > 100 || arg.empty()) {
// Get word or selection
bv_->getLyXText()->selectWordWhenUnderCursor(lyx::WHOLE_WORD);
arg = cur.selectionAsString(false);
// FIXME: where is getLyXText()->unselect(bv_) ?
}
}
bv_->owner()->getDialogs().show("thesaurus", arg);
break;
}
case LFUN_TRACK_CHANGES: case LFUN_TRACK_CHANGES:
trackChanges(); trackChanges();
break; break;
@ -1083,31 +1062,19 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
break; break;
case LFUN_ACCEPT_ALL_CHANGES: { case LFUN_ACCEPT_ALL_CHANGES: {
bv_->text()->setCursor(0, 0); bv_->cursor().reset();
#warning FIXME changes #warning FIXME changes
while (lyx::find::findNextChange(bv_)) while (lyx::find::findNextChange(bv_))
bv_->getLyXText()->acceptChange(); bv_->getLyXText()->acceptChange(bv_->cursor());
update(); update();
break; break;
} }
case LFUN_REJECT_ALL_CHANGES: { case LFUN_REJECT_ALL_CHANGES: {
bv_->text()->setCursor(0, 0); bv_->cursor().reset();
#warning FIXME changes #warning FIXME changes
while (lyx::find::findNextChange(bv_)) while (lyx::find::findNextChange(bv_))
bv_->getLyXText()->rejectChange(); bv_->getLyXText()->rejectChange(bv_->cursor());
update();
break;
}
case LFUN_ACCEPT_CHANGE: {
bv_->getLyXText()->acceptChange();
update();
break;
}
case LFUN_REJECT_CHANGE: {
bv_->getLyXText()->rejectChange();
update(); update();
break; break;
} }

View File

@ -5,6 +5,7 @@
* text.C: * text.C:
* text2.C: * text2.C:
* text3.C: add LCursor & parameter to most cursor movement functions * text3.C: add LCursor & parameter to most cursor movement functions
remove usage of LyXText::cursorRow() and cursorPar()
* cursor.[Ch]: add textRow() needed members * cursor.[Ch]: add textRow() needed members

View File

@ -11,9 +11,10 @@
#include <config.h> #include <config.h>
#include "support/std_sstream.h"
#include "Spacing.h" #include "Spacing.h"
#include "support/std_sstream.h"
using std::ios; using std::ios;
using std::istringstream; using std::istringstream;
using std::ostream; using std::ostream;

View File

@ -145,118 +145,10 @@ bool string2font(string const & data, LyXFont & font, bool & toggle)
} }
bool changeDepthAllowed(BufferView * bv, LyXText * text, DEPTH_CHANGE type) bool changeDepthAllowed(LCursor & cur, LyXText * text, DEPTH_CHANGE type)
{ {
return bv->available() && text && text->changeDepthAllowed(type); return cur.bv().available() && text && text->changeDepthAllowed(cur, type);
} }
void changeDepth(BufferView * bv, LyXText * text, DEPTH_CHANGE type)
{
if (bv->available() && text)
text->changeDepth(type);
}
// Returns the current font and depth as a message.
string const currentState(BufferView * bv)
{
ostringstream state;
if (!bv->available())
return string();
if (bv->cursor().inMathed()) {
bv->cursor().info(state);
return state.str();
}
LyXText * text = bv->getLyXText();
Buffer * buffer = bv->buffer();
CursorSlice const & c = text->cursor();
bool const show_change = buffer->params().tracking_changes
&& text->cursor().pos() != text->cursorPar()->size()
&& text->cursorPar()->lookupChange(c.pos()) != Change::UNCHANGED;
if (show_change) {
Change change = text->cursorPar()->lookupChangeFull(c.pos());
Author const & a = bv->buffer()->params().authors().get(change.author);
state << _("Change: ") << a.name();
if (!a.email().empty())
state << " (" << a.email() << ")";
if (change.changetime)
state << _(" at ") << ctime(&change.changetime);
state << " : ";
}
// I think we should only show changes from the default
// font. (Asger)
LyXFont font = text->real_current_font;
font.reduce(buffer->params().getLyXTextClass().defaultfont());
// avoid _(...) re-entrance problem
string const s = font.stateText(&buffer->params());
state << bformat(_("Font: %1$s"), s);
// state << bformat(_("Font: %1$s"), font.stateText(&buffer->params));
// The paragraph depth
int depth = text->getDepth();
if (depth > 0)
state << bformat(_(", Depth: %1$s"), tostr(depth));
// The paragraph spacing, but only if different from
// buffer spacing.
if (!text->cursorPar()->params().spacing().isDefault()) {
Spacing::Space cur_space =
text->cursorPar()->params().spacing().getSpace();
state << _(", Spacing: ");
switch (cur_space) {
case Spacing::Single:
state << _("Single");
break;
case Spacing::Onehalf:
state << _("OneHalf");
break;
case Spacing::Double:
state << _("Double");
break;
case Spacing::Other:
state << _("Other (")
<< text->cursorPar()->params().spacing().getValue()
<< ')';
break;
case Spacing::Default:
// should never happen, do nothing
break;
}
}
#ifdef DEVEL_VERSION
ParagraphList::iterator pit = text->cursorPar();
state << _(", Paragraph: ") << pit->id();
state << _(", Position: ") << text->cursor().pos();
RowList::iterator rit = pit->getRow(text->cursor().pos());
state << bformat(_(", Row b:%1$d e:%2$d"), rit->pos(), rit->endpos());
state << _(", Inset: ");
InsetOld * inset = pit->inInset();
if (inset)
state << inset << " owner: " << inset->owner();
else
state << -1;
#endif
return state.str();
}
// deletes a selection during an insertion
void replaceSelection(LyXText * text)
{
if (text->bv()->cursor().selection()) {
text->cutSelection(true, false);
text->bv()->update();
}
}
} // namespace bv_funcs } // namespace bv_funcs

View File

@ -18,6 +18,7 @@
class BufferView; class BufferView;
class LCursor;
class LyXFont; class LyXFont;
class LyXText; class LyXText;
class PosIterator; class PosIterator;
@ -45,17 +46,8 @@ enum DEPTH_CHANGE {
DEC_DEPTH DEC_DEPTH
}; };
/// Increase or decrease the nesting depth of the selected paragraph(s)
void changeDepth(BufferView *, LyXText *, DEPTH_CHANGE);
/// Returns whether something would be changed by changeDepth /// Returns whether something would be changed by changeDepth
bool changeDepthAllowed(BufferView *, LyXText *, DEPTH_CHANGE); bool changeDepthAllowed(LCursor & cur, LyXText * text, DEPTH_CHANGE);
/// Returns the current font and depth as a message.
std::string const currentState(BufferView *);
/// replace selection with insertion
void replaceSelection(LyXText * lt);
}; // namespace bv_funcs }; // namespace bv_funcs

View File

@ -35,6 +35,8 @@
#include "mathed/math_support.h" #include "mathed/math_support.h"
#include "support/limited_stack.h" #include "support/limited_stack.h"
#include "support/std_sstream.h"
#include "frontends/LyXView.h" #include "frontends/LyXView.h"
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -255,7 +257,7 @@ void LCursor::getDim(int & asc, int & des) const
asc = 10; asc = 10;
des = 10; des = 10;
} else { } else {
Row const & row = *text()->cursorRow(); Row const & row = textRow();
asc = row.baseline(); asc = row.baseline();
des = row.height() - asc; des = row.height() - asc;
} }
@ -568,7 +570,7 @@ MathArray & LCursor::cell()
} }
void LCursor::info(std::ostream & os) void LCursor::info(std::ostream & os) const
{ {
for (int i = 1, n = depth(); i < n; ++i) { for (int i = 1, n = depth(); i < n; ++i) {
cursor_[i].inset()->infoize(os); cursor_[i].inset()->infoize(os);
@ -1031,7 +1033,7 @@ void LCursor::insert(InsetBase * inset)
if (inMathed()) if (inMathed())
insert(MathAtom(inset)); insert(MathAtom(inset));
else else
text()->insertInset(inset); text()->insertInset(*this, inset);
} }
@ -1829,8 +1831,7 @@ InsetBase * LCursor::nextInset()
return 0; return 0;
if (inMathed()) if (inMathed())
return nextAtom().nucleus(); return nextAtom().nucleus();
Paragraph & par = paragraph(); return paragraph().isInset(pos()) ? paragraph().getInset(pos()) : 0;
return par.isInset(pos()) ? par.getInset(pos()) : 0;
} }
@ -1840,8 +1841,17 @@ InsetBase * LCursor::prevInset()
return 0; return 0;
if (inMathed()) if (inMathed())
return prevAtom().nucleus(); return prevAtom().nucleus();
Paragraph & par = paragraph(); return paragraph().isInset(pos() - 1) ? paragraph().getInset(pos() - 1) : 0;
return par.isInset(pos() - 1) ? par.getInset(pos() - 1) : 0; }
InsetBase const * LCursor::prevInset() const
{
if (pos() == 0)
return 0;
if (inMathed())
return prevAtom().nucleus();
return paragraph().isInset(pos() - 1) ? paragraph().getInset(pos() - 1) : 0;
} }
@ -1892,3 +1902,29 @@ string LCursor::selectionAsString(bool label) const
#warning an mathed? #warning an mathed?
return string(); return string();
} }
string LCursor::currentState()
{
if (inMathed()) {
std::ostringstream os;
info(os);
return os.str();
}
return text()->currentState(*this);
}
// only used by the spellchecker
void LCursor::replaceWord(string const & replacestring)
{
LyXText * t = text();
t->replaceSelectionWithString(*this, replacestring);
t->setSelectionRange(*this, replacestring.length());
// Go back so that replacement string is also spellchecked
for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
t->cursorLeft(*this, true);
}

View File

@ -146,6 +146,8 @@ public:
std::string selectionAsString(bool label) const; std::string selectionAsString(bool label) const;
/// ///
void paste(std::string const & data); void paste(std::string const & data);
///
std::string currentState();
// //
// access to the 'current' cursor slice // access to the 'current' cursor slice
@ -189,6 +191,8 @@ public:
InsetBase * nextInset(); InsetBase * nextInset();
/// the inset just in front of the cursor /// the inset just in front of the cursor
InsetBase * prevInset(); InsetBase * prevInset();
/// the inset just in front of the cursor
InsetBase const * prevInset() const;
// //
// math-specific part // math-specific part
@ -276,11 +280,13 @@ public:
/// access to owning BufferView /// access to owning BufferView
BufferView & bv() const; BufferView & bv() const;
/// get some interesting description of current position /// get some interesting description of current position
void info(std::ostream & os); void info(std::ostream & os) const;
/// are we in math mode (2), text mode (1) or unsure (0)? /// are we in math mode (2), text mode (1) or unsure (0)?
int currentMode(); int currentMode();
/// reset cursor /// reset cursor
void reset(); void reset();
/// for spellchecking
void replaceWord(std::string const & replacestring);
/// output /// output
friend std::ostream & operator<<(std::ostream & os, LCursor const & cur); friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);

View File

@ -154,7 +154,7 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd)
// Try and generate a valid index entry. // Try and generate a valid index entry.
InsetCommandParams icp("index"); InsetCommandParams icp("index");
string const contents = cmd.argument.empty() ? string const contents = cmd.argument.empty() ?
bv->getLyXText()->getStringToIndex() : bv->getLyXText()->getStringToIndex(bv->cursor()) :
cmd.argument; cmd.argument;
icp.setContents(contents); icp.setContents(contents);

View File

@ -13,17 +13,18 @@
#include <config.h> #include <config.h>
#include "ControlCommandBuffer.h" #include "ControlCommandBuffer.h"
#include "bufferview_funcs.h"
#include "BufferView.h"
#include "cursor.h"
#include "lyxfunc.h" #include "lyxfunc.h"
#include "LyXAction.h" #include "LyXAction.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "frontends/LyXView.h" #include "frontends/LyXView.h"
#include "support/lyxalgo.h" #include "support/lyxalgo.h"
#include "support/lstrings.h" #include "support/lstrings.h"
using bv_funcs::currentState;
using lyx::support::prefixIs; using lyx::support::prefixIs;
using std::back_inserter; using std::back_inserter;
@ -66,9 +67,9 @@ string const ControlCommandBuffer::historyUp()
string const ControlCommandBuffer::historyDown() string const ControlCommandBuffer::historyDown()
{ {
if (history_pos_ == history_.end()) if (history_pos_ == history_.end())
return ""; return string();
if (history_pos_ + 1 == history_.end()) if (history_pos_ + 1 == history_.end())
return ""; return string();
return *(++history_pos_); return *(++history_pos_);
} }
@ -76,7 +77,7 @@ string const ControlCommandBuffer::historyDown()
string const ControlCommandBuffer::getCurrentState() const string const ControlCommandBuffer::getCurrentState() const
{ {
return currentState(lv_.view().get()); return lv_.view()->cursor().currentState();
} }
@ -98,9 +99,9 @@ ControlCommandBuffer::completions(string const & prefix, string & new_prefix)
return vector<string>(); return vector<string>();
} }
// find maximal avaliable prefix // find maximal available prefix
string const tmp = comp[0]; string const tmp = comp[0];
string test(prefix); string test = prefix;
if (tmp.length() > test.length()) if (tmp.length() > test.length())
test += tmp[test.length()]; test += tmp[test.length()];
while (test.length() < tmp.length()) { while (test.length() < tmp.length()) {

View File

@ -16,12 +16,11 @@
#include "buffer.h" #include "buffer.h"
#include "bufferparams.h" #include "bufferparams.h"
#include "BufferView.h" #include "BufferView.h"
#include "bufferview_funcs.h" #include "cursor.h"
#include "debug.h" #include "debug.h"
#include "gettext.h" #include "gettext.h"
#include "language.h" #include "language.h"
#include "lyxrc.h" #include "lyxrc.h"
#include "PosIterator.h" #include "PosIterator.h"
#include "paragraph.h" #include "paragraph.h"
@ -235,17 +234,17 @@ void ControlSpellchecker::check()
lyxerr[Debug::GUI] << "Found word \"" << word_.word() << "\"" << endl; lyxerr[Debug::GUI] << "Found word \"" << word_.word() << "\"" << endl;
if (!word_.word().empty()) { if (word_.word().empty()) {
int const size = word_.word().size();
advance(cur, -size);
bufferview()->putSelectionAt(cur, size, false);
advance(cur, size);
} else {
showSummary(); showSummary();
endSession(); endSession();
return; return;
} }
int const size = word_.word().size();
advance(cur, -size);
bufferview()->putSelectionAt(cur, size, false);
advance(cur, size);
// set suggestions // set suggestions
if (res != SpellBase::OK && res != SpellBase::IGNORE) { if (res != SpellBase::OK && res != SpellBase::IGNORE) {
lyxerr[Debug::GUI] << "Found a word needing checking." << endl; lyxerr[Debug::GUI] << "Found a word needing checking." << endl;
@ -292,7 +291,9 @@ void ControlSpellchecker::showSummary()
void ControlSpellchecker::replace(string const & replacement) void ControlSpellchecker::replace(string const & replacement)
{ {
bufferview()->replaceWord(replacement); bufferview()->cursor().replaceWord(replacement);
bufferview()->buffer()->markDirty();
bufferview()->update();
// fix up the count // fix up the count
--count_; --count_;
check(); check();

View File

@ -348,15 +348,14 @@ InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
return lfunMouseRelease(cur, cmd); return lfunMouseRelease(cur, cmd);
case LFUN_INSET_TOGGLE: case LFUN_INSET_TOGGLE:
if (inset.text_.toggleInset()) if (inset.text_.toggleInset(cur))
return DispatchResult(true, true); return DispatchResult(true, true);
if (status_ == Open) { if (status_ == Open) {
setStatus(Inlined); setStatus(Inlined);
return DispatchResult(true, true); return DispatchResult(true, true);
} else {
setStatus(Collapsed);
return DispatchResult(false, FINISHED_RIGHT);
} }
setStatus(Collapsed);
return DispatchResult(false, FINISHED_RIGHT);
default: default:
return inset.dispatch(cur, cmd); return inset.dispatch(cur, cmd);

View File

@ -52,8 +52,6 @@
#include <boost/bind.hpp> #include <boost/bind.hpp>
using bv_funcs::replaceSelection;
using lyx::pos_type; using lyx::pos_type;
using lyx::graphics::PreviewLoader; using lyx::graphics::PreviewLoader;
@ -279,7 +277,7 @@ void InsetText::sanitizeEmptyText(BufferView & bv)
&& bv.getParentLanguage(this) != text_.current_font.language()) { && bv.getParentLanguage(this) != text_.current_font.language()) {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setLanguage(bv.getParentLanguage(this)); font.setLanguage(bv.getParentLanguage(this));
text_.setFont(font, false); text_.setFont(bv.cursor(), font, false);
} }
} }
@ -329,7 +327,7 @@ DispatchResult InsetText::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
paragraphs().size() == 1) { paragraphs().size() == 1) {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setLanguage(cur.bv().getParentLanguage(this)); font.setLanguage(cur.bv().getParentLanguage(this));
text_.setFont(font, false); text_.setFont(cur, font, false);
} }
//lyxerr << "InsetText::priv_dispatch (end)" << endl; //lyxerr << "InsetText::priv_dispatch (end)" << endl;

View File

@ -361,9 +361,9 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
if (bv->text() == bv->getLyXText()) if (bv->text() == bv->getLyXText())
bv->cursor().clearSelection(); bv->cursor().clearSelection();
if (asParagraph) if (asParagraph)
bv->getLyXText()->insertStringAsParagraphs(tmpstr); bv->getLyXText()->insertStringAsParagraphs(bv->cursor(), tmpstr);
else else
bv->getLyXText()->insertStringAsLines(tmpstr); bv->getLyXText()->insertStringAsLines(bv->cursor(), tmpstr);
bv->update(); bv->update();
} }

View File

@ -388,8 +388,8 @@ int replace(BufferView * bv, string const & searchstr,
LyXText * text = bv->getLyXText(); LyXText * text = bv->getLyXText();
text->replaceSelectionWithString(replacestr); text->replaceSelectionWithString(bv->cursor(), replacestr);
text->setSelectionRange(replacestr.length()); text->setSelectionRange(bv->cursor(), replacestr.length());
bv->cursor().current() = fw ? bv->cursor().selEnd() : bv->cursor().selBegin(); bv->cursor().current() = fw ? bv->cursor().selEnd() : bv->cursor().selBegin();
bv->buffer()->markDirty(); bv->buffer()->markDirty();
find(bv, searchstr, cs, mw, fw); find(bv, searchstr, cs, mw, fw);

View File

@ -82,8 +82,6 @@
#include "support/std_sstream.h" #include "support/std_sstream.h"
#include "support/os.h" #include "support/os.h"
using bv_funcs::changeDepth;
using bv_funcs::currentState;
using bv_funcs::DEC_DEPTH; using bv_funcs::DEC_DEPTH;
using bv_funcs::freefont2string; using bv_funcs::freefont2string;
using bv_funcs::INC_DEPTH; using bv_funcs::INC_DEPTH;
@ -257,19 +255,19 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
} }
FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
{ {
FuncStatus flag; FuncStatus flag;
Buffer * buf = owner->buffer(); Buffer * buf = owner->buffer();
LCursor & cur = view()->cursor(); LCursor & cur = view()->cursor();
if (ev.action == LFUN_NOACTION) { if (cmd.action == LFUN_NOACTION) {
setStatusMessage(N_("Nothing to do")); setStatusMessage(N_("Nothing to do"));
flag.disabled(true); flag.disabled(true);
return flag; return flag;
} }
switch (ev.action) { switch (cmd.action) {
case LFUN_UNKNOWN_ACTION: case LFUN_UNKNOWN_ACTION:
#ifndef HAVE_LIBAIKSAURUS #ifndef HAVE_LIBAIKSAURUS
case LFUN_THESAURUS_ENTRY: case LFUN_THESAURUS_ENTRY:
@ -278,7 +276,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
flag.disabled(true); flag.disabled(true);
break; break;
default: default:
flag |= lyx_gui::getStatus(ev); flag |= lyx_gui::getStatus(cmd);
} }
if (flag.unknown()) { if (flag.unknown()) {
@ -290,13 +288,13 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
setStatusMessage(N_("Command disabled")); setStatusMessage(N_("Command disabled"));
// Check whether we need a buffer // Check whether we need a buffer
if (!lyxaction.funcHasFlag(ev.action, LyXAction::NoBuffer)) { if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
// Yes we need a buffer, do we have one? // Yes we need a buffer, do we have one?
if (buf) { if (buf) {
// yes // yes
// Can we use a readonly buffer? // Can we use a readonly buffer?
if (buf->isReadonly() && if (buf->isReadonly() &&
!lyxaction.funcHasFlag(ev.action, !lyxaction.funcHasFlag(cmd.action,
LyXAction::ReadOnly)) { LyXAction::ReadOnly)) {
// no // no
setStatusMessage(N_("Document is read-only")); setStatusMessage(N_("Document is read-only"));
@ -317,10 +315,10 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
// I would really like to avoid having this switch and rather try to // I would really like to avoid having this switch and rather try to
// encode this in the function itself. // encode this in the function itself.
bool disable = false; bool disable = false;
switch (ev.action) { switch (cmd.action) {
case LFUN_EXPORT: case LFUN_EXPORT:
disable = ev.argument != "custom" disable = cmd.argument != "custom"
&& !Exporter::IsExportable(*buf, ev.argument); && !Exporter::IsExportable(*buf, cmd.argument);
break; break;
case LFUN_UNDO: case LFUN_UNDO:
disable = buf->undostack().empty(); disable = buf->undostack().empty();
@ -349,11 +347,11 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
break; break;
case LFUN_DEPTH_MIN: case LFUN_DEPTH_MIN:
disable = !changeDepthAllowed(view(), view()->getLyXText(), DEC_DEPTH); disable = !changeDepthAllowed(cur, view()->getLyXText(), DEC_DEPTH);
break; break;
case LFUN_DEPTH_PLUS: case LFUN_DEPTH_PLUS:
disable = !changeDepthAllowed(view(), view()->getLyXText(), INC_DEPTH); disable = !changeDepthAllowed(cur, view()->getLyXText(), INC_DEPTH);
break; break;
case LFUN_LAYOUT: case LFUN_LAYOUT:
@ -377,15 +375,15 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
disable = true; disable = true;
break; break;
} }
if (ev.argument.empty()) { if (cmd.argument.empty()) {
flag.clear(); flag.clear();
break; break;
} }
if (!contains("tcb", ev.argument[0])) { if (!contains("tcb", cmd.argument[0])) {
disable = true; disable = true;
break; break;
} }
flag.setOnOff(ev.argument[0] == align); flag.setOnOff(cmd.argument[0] == align);
} else { } else {
disable = true; disable = true;
@ -394,15 +392,15 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
disable = true; disable = true;
break; break;
} }
if (ev.argument.empty()) { if (cmd.argument.empty()) {
flag.clear(); flag.clear();
break; break;
} }
if (!contains("lcr", ev.argument[0])) { if (!contains("lcr", cmd.argument[0])) {
disable = true; disable = true;
break; break;
} }
flag.setOnOff(ev.argument[0] == align); flag.setOnOff(cmd.argument[0] == align);
disable = !mathcursor::halign(); disable = !mathcursor::halign();
break; break;
@ -413,7 +411,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
//ret.disabled(true); //ret.disabled(true);
InsetTabular * tab = cur.innerInsetTabular(); InsetTabular * tab = cur.innerInsetTabular();
if (tab) { if (tab) {
ret = tab->getStatus(ev.argument); ret = tab->getStatus(cmd.argument);
flag |= ret; flag |= ret;
disable = false; disable = false;
} else { } else {
@ -422,7 +420,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
} else { } else {
static InsetTabular inset(*buf, 1, 1); static InsetTabular inset(*buf, 1, 1);
disable = true; disable = true;
FuncStatus ret = inset.getStatus(ev.argument); FuncStatus ret = inset.getStatus(cmd.argument);
if (ret.onoff(true) || ret.onoff(false)) if (ret.onoff(true) || ret.onoff(false))
flag.setOnOff(false); flag.setOnOff(false);
} }
@ -447,7 +445,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
break; break;
case LFUN_BOOKMARK_GOTO: case LFUN_BOOKMARK_GOTO:
disable = !view()-> disable = !view()->
isSavedPosition(strToUnsignedInt(ev.argument)); isSavedPosition(strToUnsignedInt(cmd.argument));
break; break;
case LFUN_MERGE_CHANGES: case LFUN_MERGE_CHANGES:
@ -474,25 +472,25 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
InsetOld::Code code = inset->lyxCode(); InsetOld::Code code = inset->lyxCode();
switch (code) { switch (code) {
case InsetOld::TABULAR_CODE: case InsetOld::TABULAR_CODE:
disable = ev.argument != "tabular"; disable = cmd.argument != "tabular";
break; break;
case InsetOld::ERT_CODE: case InsetOld::ERT_CODE:
disable = ev.argument != "ert"; disable = cmd.argument != "ert";
break; break;
case InsetOld::FLOAT_CODE: case InsetOld::FLOAT_CODE:
disable = ev.argument != "float"; disable = cmd.argument != "float";
break; break;
case InsetOld::WRAP_CODE: case InsetOld::WRAP_CODE:
disable = ev.argument != "wrap"; disable = cmd.argument != "wrap";
break; break;
case InsetOld::NOTE_CODE: case InsetOld::NOTE_CODE:
disable = ev.argument != "note"; disable = cmd.argument != "note";
break; break;
case InsetOld::BRANCH_CODE: case InsetOld::BRANCH_CODE:
disable = ev.argument != "branch"; disable = cmd.argument != "branch";
break; break;
case InsetOld::BOX_CODE: case InsetOld::BOX_CODE:
disable = ev.argument != "box"; disable = cmd.argument != "box";
break; break;
default: default:
break; break;
@ -502,7 +500,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
case LFUN_MATH_MUTATE: case LFUN_MATH_MUTATE:
if (cur.inMathed()) if (cur.inMathed())
//flag.setOnOff(mathcursor::formula()->hullType() == ev.argument); //flag.setOnOff(mathcursor::formula()->hullType() == cmd.argument);
flag.setOnOff(false); flag.setOnOff(false);
else else
disable = true; disable = true;
@ -519,7 +517,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
break; break;
case LFUN_DIALOG_SHOW: { case LFUN_DIALOG_SHOW: {
string const name = ev.getArg(0); string const name = cmd.getArg(0);
if (!buf) { if (!buf) {
disable = !(name == "aboutlyx" || disable = !(name == "aboutlyx" ||
name == "file" || name == "file" ||
@ -549,43 +547,43 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
// the functions which insert insets // the functions which insert insets
InsetOld::Code code = InsetOld::NO_CODE; InsetOld::Code code = InsetOld::NO_CODE;
switch (ev.action) { switch (cmd.action) {
case LFUN_DIALOG_SHOW_NEW_INSET: case LFUN_DIALOG_SHOW_NEW_INSET:
if (ev.argument == "bibitem") if (cmd.argument == "bibitem")
code = InsetOld::BIBITEM_CODE; code = InsetOld::BIBITEM_CODE;
else if (ev.argument == "bibtex") else if (cmd.argument == "bibtex")
code = InsetOld::BIBTEX_CODE; code = InsetOld::BIBTEX_CODE;
else if (ev.argument == "box") else if (cmd.argument == "box")
code = InsetOld::BOX_CODE; code = InsetOld::BOX_CODE;
else if (ev.argument == "branch") else if (cmd.argument == "branch")
code = InsetOld::BRANCH_CODE; code = InsetOld::BRANCH_CODE;
else if (ev.argument == "citation") else if (cmd.argument == "citation")
code = InsetOld::CITE_CODE; code = InsetOld::CITE_CODE;
else if (ev.argument == "ert") else if (cmd.argument == "ert")
code = InsetOld::ERT_CODE; code = InsetOld::ERT_CODE;
else if (ev.argument == "external") else if (cmd.argument == "external")
code = InsetOld::EXTERNAL_CODE; code = InsetOld::EXTERNAL_CODE;
else if (ev.argument == "float") else if (cmd.argument == "float")
code = InsetOld::FLOAT_CODE; code = InsetOld::FLOAT_CODE;
else if (ev.argument == "graphics") else if (cmd.argument == "graphics")
code = InsetOld::GRAPHICS_CODE; code = InsetOld::GRAPHICS_CODE;
else if (ev.argument == "include") else if (cmd.argument == "include")
code = InsetOld::INCLUDE_CODE; code = InsetOld::INCLUDE_CODE;
else if (ev.argument == "index") else if (cmd.argument == "index")
code = InsetOld::INDEX_CODE; code = InsetOld::INDEX_CODE;
else if (ev.argument == "label") else if (cmd.argument == "label")
code = InsetOld::LABEL_CODE; code = InsetOld::LABEL_CODE;
else if (ev.argument == "note") else if (cmd.argument == "note")
code = InsetOld::NOTE_CODE; code = InsetOld::NOTE_CODE;
else if (ev.argument == "ref") else if (cmd.argument == "ref")
code = InsetOld::REF_CODE; code = InsetOld::REF_CODE;
else if (ev.argument == "toc") else if (cmd.argument == "toc")
code = InsetOld::TOC_CODE; code = InsetOld::TOC_CODE;
else if (ev.argument == "url") else if (cmd.argument == "url")
code = InsetOld::URL_CODE; code = InsetOld::URL_CODE;
else if (ev.argument == "vspace") else if (cmd.argument == "vspace")
code = InsetOld::VSPACE_CODE; code = InsetOld::VSPACE_CODE;
else if (ev.argument == "wrap") else if (cmd.argument == "wrap")
code = InsetOld::WRAP_CODE; code = InsetOld::WRAP_CODE;
break; break;
@ -700,7 +698,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
flag.disabled(true); flag.disabled(true);
// A few general toggles // A few general toggles
switch (ev.action) { switch (cmd.action) {
case LFUN_TOOLTIPS_TOGGLE: case LFUN_TOOLTIPS_TOGGLE:
flag.setOnOff(owner->getDialogs().tooltipsEnabled()); flag.setOnOff(owner->getDialogs().tooltipsEnabled());
break; break;
@ -715,7 +713,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
case LFUN_SWITCHBUFFER: case LFUN_SWITCHBUFFER:
// toggle on the current buffer, but do not toggle off // toggle on the current buffer, but do not toggle off
// the other ones (is that a good idea?) // the other ones (is that a good idea?)
if (ev.argument == buf->fileName()) if (cmd.argument == buf->fileName())
flag.setOnOff(true); flag.setOnOff(true);
break; break;
case LFUN_TRACK_CHANGES: case LFUN_TRACK_CHANGES:
@ -729,7 +727,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
// the font related toggles // the font related toggles
if (cur.inTexted()) { if (cur.inTexted()) {
LyXFont const & font = cur.text()->real_current_font; LyXFont const & font = cur.text()->real_current_font;
switch (ev.action) { switch (cmd.action) {
case LFUN_EMPH: case LFUN_EMPH:
flag.setOnOff(font.emph() == LyXFont::ON); flag.setOnOff(font.emph() == LyXFont::ON);
break; break;
@ -753,7 +751,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
} }
} else { } else {
string tc = mathcursor::getLastCode(); string tc = mathcursor::getLastCode();
switch (ev.action) { switch (cmd.action) {
case LFUN_BOLD: case LFUN_BOLD:
flag.setOnOff(tc == "mathbf"); flag.setOnOff(tc == "mathbf");
break; break;
@ -783,10 +781,11 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
// this one is difficult to get right. As a half-baked // this one is difficult to get right. As a half-baked
// solution, we consider only the first action of the sequence // solution, we consider only the first action of the sequence
if (ev.action == LFUN_SEQUENCE) { if (cmd.action == LFUN_SEQUENCE) {
// argument contains ';'-terminated commands // argument contains ';'-terminated commands
#warning LyXAction arguments not handled here. #warning LyXAction arguments not handled here.
flag = getStatus(FuncRequest(lyxaction.lookupFunc(token(ev.argument, ';', 0)))); flag = getStatus(FuncRequest(
lyxaction.lookupFunc(token(cmd.argument, ';', 0))));
} }
return flag; return flag;
@ -1750,7 +1749,7 @@ string const LyXFunc::view_status_message()
if (!view()->available()) if (!view()->available())
return _("Welcome to LyX!"); return _("Welcome to LyX!");
return currentState(view()); return view()->cursor().currentState();
} }

View File

@ -79,22 +79,19 @@ public:
ParagraphList::iterator end, ParagraphList::iterator end,
std::string const & layout); std::string const & layout);
/// ///
void setLayout(std::string const & layout); void setLayout(LCursor & cur, std::string const & layout);
/// Increase or decrease the nesting depth of the selected paragraph(s) /// Increase or decrease the nesting depth of the selected paragraph(s)
void changeDepth(bv_funcs::DEPTH_CHANGE type); void changeDepth(LCursor & cur, bv_funcs::DEPTH_CHANGE type);
/// Returns whether something would be changed by changeDepth /// Returns whether something would be changed by changeDepth
bool changeDepthAllowed(bv_funcs::DEPTH_CHANGE type); bool changeDepthAllowed(LCursor & cur, bv_funcs::DEPTH_CHANGE type);
/// get the depth at current cursor position /// get the depth at current cursor position
int getDepth() const; int getDepth() const;
/** set font over selection and make a total rebreak of those /// Set font over selection paragraphs and rebreak.
paragraphs. void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
toggleall defaults to false.
*/
void setFont(LyXFont const &, bool toggleall = false);
/// rebreaks all paragaphs between the given pars. /// rebreaks all paragaphs between the given pars.
void redoParagraphs(ParagraphList::iterator begin, void redoParagraphs(ParagraphList::iterator begin,
@ -102,18 +99,18 @@ public:
/// rebreaks the given par /// rebreaks the given par
void redoParagraph(ParagraphList::iterator pit); void redoParagraph(ParagraphList::iterator pit);
/// rebreaks the cursor par /// rebreaks the cursor par
void redoParagraph(); void redoParagraph(LCursor & cur);
/// ///
void toggleFree(LyXFont const &, bool toggleall = false); void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
/// ///
std::string getStringToIndex(); std::string getStringToIndex(LCursor & cur);
/// insert a character at cursor position /// insert a character at cursor position
void insertChar(char c); void insertChar(LCursor & cur, char c);
/// insert an inset at cursor position /// insert an inset at cursor position
void insertInset(InsetBase * inset); void insertInset(LCursor & cur, InsetBase * inset);
/// a full rebreak of the whole text /// a full rebreak of the whole text
void fullRebreak(); void fullRebreak();
@ -137,10 +134,10 @@ public:
ParagraphList::iterator getPar(lyx::paroffset_type par) const; ParagraphList::iterator getPar(lyx::paroffset_type par) const;
/// ///
int parOffset(ParagraphList::iterator pit) const; int parOffset(ParagraphList::iterator pit) const;
/// convenience /// # FIXME: should not be used
ParagraphList::iterator cursorPar() const; ParagraphList::iterator cursorPar() const;
/// // Returns the current font and depth as a message.
RowList::iterator cursorRow() const; std::string LyXText::currentState(LCursor & cur);
/** returns an iterator pointing to the row near the specified /** returns an iterator pointing to the row near the specified
* y-coordinate (relative to the whole text). y is set to the * y-coordinate (relative to the whole text). y is set to the
@ -162,12 +159,12 @@ public:
*/ */
void getWord(CursorSlice & from, CursorSlice & to, lyx::word_location const); void getWord(CursorSlice & from, CursorSlice & to, lyx::word_location const);
/// just selects the word the cursor is in /// just selects the word the cursor is in
void selectWord(lyx::word_location loc); void selectWord(LCursor & cur, lyx::word_location loc);
/// accept selected change /// accept selected change
void acceptChange(); void acceptChange(LCursor & cur);
/// reject selected change /// reject selected change
void rejectChange(); void rejectChange(LCursor & cur);
/// returns true if par was empty and was removed /// returns true if par was empty and was removed
bool setCursor(lyx::paroffset_type par, lyx::pos_type pos, bool setCursor(lyx::paroffset_type par, lyx::pos_type pos,
@ -224,7 +221,7 @@ public:
/// ///
void backspace(LCursor & cur); void backspace(LCursor & cur);
/// ///
bool selectWordWhenUnderCursor(lyx::word_location); bool selectWordWhenUnderCursor(LCursor & cur, lyx::word_location);
/// ///
enum TextCase { enum TextCase {
/// ///
@ -235,16 +232,16 @@ public:
text_uppercase = 2 text_uppercase = 2
}; };
/// Change the case of the word at cursor position. /// Change the case of the word at cursor position.
void changeCase(TextCase action); void changeCase(LCursor & cur, TextCase action);
/// returns success /// returns success
bool toggleInset(); bool toggleInset(LCursor & cur);
/// ///
void cutSelection(bool doclear = true, bool realcut = true); void cutSelection(bool doclear = true, bool realcut = true);
/// ///
void copySelection(); void copySelection();
/// ///
void pasteSelection(size_t sel_index = 0); void pasteSelection(LCursor & cur, size_t sel_index = 0);
/** the DTP switches for paragraphs. LyX will store the top settings /** the DTP switches for paragraphs. LyX will store the top settings
always in the first physical paragraph, the bottom settings in the always in the first physical paragraph, the bottom settings in the
@ -263,16 +260,16 @@ public:
* Sets the selection from the current cursor position to length * Sets the selection from the current cursor position to length
* characters to the right. No safety checks. * characters to the right. No safety checks.
*/ */
void setSelectionRange(lyx::pos_type length); void setSelectionRange(LCursor & cur, lyx::pos_type length);
/** simple replacing. The font of the first selected character /// simply replace using the font of the first selected character
is used void replaceSelectionWithString(LCursor & cur, std::string const & str);
*/ /// replace selection helper
void replaceSelectionWithString(std::string const & str); void replaceSelection(LCursor & cur);
/// needed to insert the selection /// needed to insert the selection
void insertStringAsLines(std::string const & str); void insertStringAsLines(LCursor & cur, std::string const & str);
/// needed to insert the selection /// needed to insert the selection
void insertStringAsParagraphs(std::string const & str); void insertStringAsParagraphs(LCursor & cur, std::string const & str);
/// Find next inset of some specified type. /// Find next inset of some specified type.
bool gotoNextInset(std::vector<InsetOld_code> const & codes, bool gotoNextInset(std::vector<InsetOld_code> const & codes,

View File

@ -15,25 +15,25 @@
#ifndef PAPER_H #ifndef PAPER_H
#define PAPER_H #define PAPER_H
/// ///
enum PAPER_SIZE { enum PAPER_SIZE {
/// ///
PAPER_DEFAULT, PAPER_DEFAULT,
/// ///
PAPER_USLETTER, PAPER_USLETTER,
/// ///
PAPER_LEGALPAPER, PAPER_LEGALPAPER,
/// ///
PAPER_EXECUTIVEPAPER, PAPER_EXECUTIVEPAPER,
/// ///
PAPER_A3PAPER, PAPER_A3PAPER,
/// ///
PAPER_A4PAPER, PAPER_A4PAPER,
/// ///
PAPER_A5PAPER, PAPER_A5PAPER,
/// ///
PAPER_B5PAPER PAPER_B5PAPER
}; };
/// ///
enum PAPER_PACKAGES { enum PAPER_PACKAGES {

View File

@ -18,6 +18,7 @@
#include "lyxtext.h" #include "lyxtext.h"
#include "author.h"
#include "buffer.h" #include "buffer.h"
#include "bufferparams.h" #include "bufferparams.h"
#include "BufferView.h" #include "BufferView.h"
@ -50,10 +51,13 @@
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/textutils.h" #include "support/textutils.h"
#include "support/tostr.h"
#include "support/std_sstream.h"
using lyx::pos_type; using lyx::pos_type;
using lyx::word_location; using lyx::word_location;
using lyx::support::bformat;
using lyx::support::contains; using lyx::support::contains;
using lyx::support::lowercase; using lyx::support::lowercase;
using lyx::support::uppercase; using lyx::support::uppercase;
@ -834,25 +838,26 @@ void LyXText::breakParagraph(LCursor & cur, char keep_layout)
// convenience function // convenience function
void LyXText::redoParagraph() void LyXText::redoParagraph(LCursor & cur)
{ {
bv()->cursor().clearSelection(); cur.clearSelection();
redoParagraph(cursorPar()); redoParagraph(getPar(cur.par()));
setCursorIntern(cursor().par(), cursor().pos()); setCursorIntern(cur.par(), cur.pos());
} }
// insert a character, moves all the following breaks in the // insert a character, moves all the following breaks in the
// same Paragraph one to the right and make a rebreak // same Paragraph one to the right and make a rebreak
void LyXText::insertChar(char c) void LyXText::insertChar(LCursor & cur, char c)
{ {
recordUndo(bv()->cursor(), Undo::INSERT); recordUndo(cur, Undo::INSERT);
// When the free-spacing option is set for the current layout, Paragraph & par = cur.paragraph();
// disable the double-space checking // try to remove this
ParagraphList::iterator pit = getPar(cur.par());
bool const freeSpacing = cursorPar()->layout()->free_spacing || bool const freeSpacing = par.layout()->free_spacing ||
cursorPar()->isFreeSpacing(); par.isFreeSpacing();
if (lyxrc.auto_number) { if (lyxrc.auto_number) {
static string const number_operators = "+-/*"; static string const number_operators = "+-/*";
@ -862,36 +867,28 @@ void LyXText::insertChar(char c)
if (current_font.number() == LyXFont::ON) { if (current_font.number() == LyXFont::ON) {
if (!IsDigit(c) && !contains(number_operators, c) && if (!IsDigit(c) && !contains(number_operators, c) &&
!(contains(number_seperators, c) && !(contains(number_seperators, c) &&
cursor().pos() >= 1 && cur.pos() != 0 &&
cursor().pos() < cursorPar()->size() && cur.pos() != cur.lastpos() &&
getFont(cursorPar(), cursor().pos()).number() == LyXFont::ON && getFont(pit, cur.pos()).number() == LyXFont::ON &&
getFont(cursorPar(), cursor().pos() - 1).number() == LyXFont::ON) getFont(pit, cur.pos() - 1).number() == LyXFont::ON)
) )
number(); // Set current_font.number to OFF number(); // Set current_font.number to OFF
} else if (IsDigit(c) && } else if (IsDigit(c) &&
real_current_font.isVisibleRightToLeft()) { real_current_font.isVisibleRightToLeft()) {
number(); // Set current_font.number to ON number(); // Set current_font.number to ON
if (cursor().pos() > 0) { if (cur.pos() != 0) {
char const c = cursorPar()->getChar(cursor().pos() - 1); char const c = par.getChar(cur.pos() - 1);
if (contains(number_unary_operators, c) && if (contains(number_unary_operators, c) &&
(cursor().pos() == 1 || (cur.pos() == 1
cursorPar()->isSeparator(cursor().pos() - 2) || || par.isSeparator(cur.pos() - 2)
cursorPar()->isNewline(cursor().pos() - 2)) || par.isNewline(cur.pos() - 2))
) { ) {
setCharFont( setCharFont(pit, cur.pos() - 1, current_font);
cursorPar(), } else if (contains(number_seperators, c)
cursor().pos() - 1, && cur.pos() >= 2
current_font); && getFont(pit, cur.pos() - 2).number() == LyXFont::ON) {
} else if (contains(number_seperators, c) && setCharFont(pit, cur.pos() - 1, current_font);
cursor().pos() >= 2 &&
getFont(
cursorPar(),
cursor().pos() - 2).number() == LyXFont::ON) {
setCharFont(
cursorPar(),
cursor().pos() - 1,
current_font);
} }
} }
} }
@ -913,36 +910,41 @@ void LyXText::insertChar(char c)
LyXFont realtmpfont = real_current_font; LyXFont realtmpfont = real_current_font;
LyXFont rawtmpfont = current_font; LyXFont rawtmpfont = current_font;
// When the free-spacing option is set for the current layout,
// disable the double-space checking
if (!freeSpacing && IsLineSeparatorChar(c)) { if (!freeSpacing && IsLineSeparatorChar(c)) {
if ((cursor().pos() > 0 if (cur.pos() == 0) {
&& cursorPar()->isLineSeparator(cursor().pos() - 1))
|| (cursor().pos() > 0
&& cursorPar()->isNewline(cursor().pos() - 1))
|| (cursor().pos() == 0)) {
static bool sent_space_message = false; static bool sent_space_message = false;
if (!sent_space_message) { if (!sent_space_message) {
if (cursor().pos() == 0) cur.message(_("You cannot insert a space at the "
bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial.")); "beginning of a paragraph. Please read the Tutorial."));
else sent_space_message = true;
bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial.")); return;
}
}
BOOST_ASSERT(cur.pos() > 0);
if (par.isLineSeparator(cur.pos() - 1)
|| par.isNewline(cur.pos() - 1)) {
static bool sent_space_message = false;
if (!sent_space_message) {
cur.message(_("You cannot type two spaces this way. "
"Please read the Tutorial."));
sent_space_message = true; sent_space_message = true;
} }
charInserted();
return; return;
} }
} }
// Here case LyXText::InsertInset already inserted the character // Here case LyXText::InsertInset already inserted the character
if (c != Paragraph::META_INSET) if (c != Paragraph::META_INSET)
cursorPar()->insertChar(cursor().pos(), c); par.insertChar(cur.pos(), c);
setCharFont(cursorPar(), cursor().pos(), rawtmpfont); setCharFont(pit, cur.pos(), rawtmpfont);
current_font = rawtmpfont; current_font = rawtmpfont;
real_current_font = realtmpfont; real_current_font = realtmpfont;
redoParagraph(cursorPar()); redoParagraph(cur);
setCursor(cursor().par(), cursor().pos() + 1, false, cursor().boundary()); setCursor(cur.par(), cur.pos() + 1, false, cur.boundary());
charInserted(); charInserted();
} }
@ -1117,42 +1119,41 @@ void LyXText::cursorLeftOneWord(LCursor & cur)
} }
void LyXText::selectWord(word_location loc) void LyXText::selectWord(LCursor & cur, word_location loc)
{ {
CursorSlice from = cursor(); CursorSlice from = cur.current();
CursorSlice to = cursor(); CursorSlice to = cur.current();
getWord(from, to, loc); getWord(from, to, loc);
if (cursor() != from) if (cur.current() != from)
setCursor(from.par(), from.pos()); setCursor(from.par(), from.pos());
if (to == from) if (to == from)
return; return;
bv()->cursor().resetAnchor(); cur.resetAnchor();
setCursor(to.par(), to.pos()); setCursor(to.par(), to.pos());
bv()->cursor().setSelection(); cur.setSelection();
} }
// Select the word currently under the cursor when no // Select the word currently under the cursor when no
// selection is currently set // selection is currently set
bool LyXText::selectWordWhenUnderCursor(word_location loc) bool LyXText::selectWordWhenUnderCursor(LCursor & cur, word_location loc)
{ {
if (bv()->cursor().selection()) if (cur.selection())
return false; return false;
selectWord(loc); selectWord(cur, loc);
return bv()->cursor().selection(); return cur.selection();
} }
void LyXText::acceptChange() void LyXText::acceptChange(LCursor & cur)
{ {
LCursor & cur = bv()->cursor(); if (!cur.selection() && cur.lastpos() != 0)
if (!cur.selection() && cursorPar()->size())
return; return;
if (cur.selBegin().par() == cur.par()) { CursorSlice const & startc = cur.selBegin();
CursorSlice const & startc = cur.selBegin(); CursorSlice const & endc = cur.selEnd();
CursorSlice const & endc = cur.selEnd(); if (startc.par() == endc.par()) {
recordUndo(cur, Undo::INSERT, cur.anchor().par()); recordUndoSelection(cur, Undo::INSERT);
getPar(startc)->acceptChange(startc.pos(), endc.pos()); getPar(startc)->acceptChange(startc.pos(), endc.pos());
finishUndo(); finishUndo();
cur.clearSelection(); cur.clearSelection();
@ -1163,16 +1164,15 @@ void LyXText::acceptChange()
} }
void LyXText::rejectChange() void LyXText::rejectChange(LCursor & cur)
{ {
LCursor & cur = bv()->cursor(); if (!cur.selection() && cur.lastpos() != 0)
if (!cur.selection() && cursorPar()->size())
return; return;
if (cur.selBegin().par() == cur.selEnd().par()) { CursorSlice const & startc = cur.selBegin();
CursorSlice const & startc = cur.selBegin(); CursorSlice const & endc = cur.selEnd();
CursorSlice const & endc = cur.selEnd(); if (startc.par() == endc.par()) {
recordUndo(cur, Undo::INSERT, cur.anchor().par()); recordUndoSelection(cur, Undo::INSERT);
getPar(startc)->rejectChange(startc.pos(), endc.pos()); getPar(startc)->rejectChange(startc.pos(), endc.pos());
finishUndo(); finishUndo();
cur.clearSelection(); cur.clearSelection();
@ -1233,9 +1233,8 @@ void LyXText::deleteLineForward(LCursor & cur)
} }
void LyXText::changeCase(LyXText::TextCase action) void LyXText::changeCase(LCursor & cur, LyXText::TextCase action)
{ {
LCursor & cur = bv()->cursor();
CursorSlice from; CursorSlice from;
CursorSlice to; CursorSlice to;
@ -1248,7 +1247,7 @@ void LyXText::changeCase(LyXText::TextCase action)
setCursor(to.par(), to.pos() + 1); setCursor(to.par(), to.pos() + 1);
} }
recordUndo(cur, Undo::ATOMIC, cur.anchor().par()); recordUndoSelection(cur);
pos_type pos = from.pos(); pos_type pos = from.pos();
int par = from.par(); int par = from.par();
@ -1298,23 +1297,21 @@ void LyXText::Delete(LCursor & cur)
void LyXText::backspace(LCursor & cur) void LyXText::backspace(LCursor & cur)
{ {
// Get the font that is used to calculate the baselineskip
ParagraphList::iterator pit = cursorPar();
pos_type lastpos = pit->size();
if (cur.pos() == 0) { if (cur.pos() == 0) {
// The cursor is at the beginning of a paragraph, so // The cursor is at the beginning of a paragraph, so
// the the backspace will collapse two paragraphs into // the the backspace will collapse two paragraphs into
// one. // one.
// but it's not allowed unless it's new // but it's not allowed unless it's new
if (pit->isChangeEdited(0, pit->size())) Paragraph & par = cur.paragraph();
if (par.isChangeEdited(0, par.size()))
return; return;
// we may paste some paragraphs // we may paste some paragraphs
// is it an empty paragraph? // is it an empty paragraph?
if (lastpos == 0 || (lastpos == 1 && pit->isSeparator(0))) { pos_type lastpos = cur.lastpos();
if (lastpos == 0 || (lastpos == 1 && par.isSeparator(0))) {
// This is an empty paragraph and we delete it just // This is an empty paragraph and we delete it just
// by moving the cursor one step // by moving the cursor one step
// left and let the DeleteEmptyParagraphMechanism // left and let the DeleteEmptyParagraphMechanism
@ -1323,7 +1320,7 @@ void LyXText::backspace(LCursor & cur)
if (cur.par() != 0) { if (cur.par() != 0) {
cursorLeft(cur, true); cursorLeft(cur, true);
// the layout things can change the height of a row ! // the layout things can change the height of a row !
redoParagraph(); redoParagraph(cur);
return; return;
} }
} }
@ -1331,7 +1328,7 @@ void LyXText::backspace(LCursor & cur)
if (cur.par() != 0) if (cur.par() != 0)
recordUndo(cur, Undo::DELETE, cur.par() - 1); recordUndo(cur, Undo::DELETE, cur.par() - 1);
ParagraphList::iterator tmppit = cursorPar(); ParagraphList::iterator tmppit = getPar(cur.par());
// We used to do cursorLeftIntern() here, but it is // We used to do cursorLeftIntern() here, but it is
// not a good idea since it triggers the auto-delete // not a good idea since it triggers the auto-delete
// mechanism. So we do a cursorLeftIntern()-lite, // mechanism. So we do a cursorLeftIntern()-lite,
@ -1350,7 +1347,7 @@ void LyXText::backspace(LCursor & cur)
Buffer & buf = *bv()->buffer(); Buffer & buf = *bv()->buffer();
BufferParams const & bufparams = buf.params(); BufferParams const & bufparams = buf.params();
LyXTextClass const & tclass = bufparams.getLyXTextClass(); LyXTextClass const & tclass = bufparams.getLyXTextClass();
ParagraphList::iterator const cpit = cursorPar(); ParagraphList::iterator const cpit = getPar(cur.par());
if (cpit != tmppit if (cpit != tmppit
&& (cpit->layout() == tmppit->layout() && (cpit->layout() == tmppit->layout()
@ -1381,7 +1378,7 @@ void LyXText::backspace(LCursor & cur)
if (cur.pos() == cur.lastpos()) if (cur.pos() == cur.lastpos())
setCurrentFont(); setCurrentFont();
redoParagraph(); redoParagraph(cur);
setCursor(cur.par(), cur.pos(), false, cur.boundary()); setCursor(cur.par(), cur.pos(), false, cur.boundary());
} }
@ -1394,12 +1391,6 @@ ParagraphList::iterator LyXText::cursorPar() const
} }
RowList::iterator LyXText::cursorRow() const
{
return cursorPar()->getRow(cursor().pos());
}
ParagraphList::iterator LyXText::getPar(CursorSlice const & cur) const ParagraphList::iterator LyXText::getPar(CursorSlice const & cur) const
{ {
return getPar(cur.par()); return getPar(cur.par());
@ -1861,3 +1852,89 @@ CursorSlice const & LyXText::cursor() const
} }
return bv()->cursor().current(); return bv()->cursor().current();
} }
void LyXText::replaceSelection(LCursor & cur)
{
if (cur.selection()) {
cutSelection(true, false);
bv()->update();
}
}
// Returns the current font and depth as a message.
string LyXText::currentState(LCursor & cur)
{
Buffer * buffer = bv()->buffer();
Paragraph const & par = cur.paragraph();
std::ostringstream os;
bool const show_change = buffer->params().tracking_changes
&& cur.pos() != cur.lastpos()
&& par.lookupChange(cur.pos()) != Change::UNCHANGED;
if (show_change) {
Change change = par.lookupChangeFull(cur.pos());
Author const & a = buffer->params().authors().get(change.author);
os << _("Change: ") << a.name();
if (!a.email().empty())
os << " (" << a.email() << ")";
if (change.changetime)
os << _(" at ") << ctime(&change.changetime);
os << " : ";
}
// I think we should only show changes from the default
// font. (Asger)
LyXFont font = real_current_font;
font.reduce(buffer->params().getLyXTextClass().defaultfont());
// avoid _(...) re-entrance problem
string const s = font.stateText(&buffer->params());
os << bformat(_("Font: %1$s"), s);
// os << bformat(_("Font: %1$s"), font.stateText(&buffer->params));
// The paragraph depth
int depth = getDepth();
if (depth > 0)
os << bformat(_(", Depth: %1$s"), tostr(depth));
// The paragraph spacing, but only if different from
// buffer spacing.
Spacing const & spacing = par.params().spacing();
if (!spacing.isDefault()) {
os << _(", Spacing: ");
switch (spacing.getSpace()) {
case Spacing::Single:
os << _("Single");
break;
case Spacing::Onehalf:
os << _("OneHalf");
break;
case Spacing::Double:
os << _("Double");
break;
case Spacing::Other:
os << _("Other (") << spacing.getValue() << ')';
break;
case Spacing::Default:
// should never happen, do nothing
break;
}
}
#ifdef DEVEL_VERSION
os << _(", Paragraph: ") << par.id();
os << _(", Position: ") << cur.pos();
Row & row = cur.textRow();
os << bformat(_(", Row b:%1$d e:%2$d"), row.pos(), row.endpos());
os << _(", Inset: ");
InsetOld * inset = par.inInset();
if (inset)
os << inset << " owner: " << inset->owner();
else
os << -1;
#endif
return os.str();
}

View File

@ -279,7 +279,7 @@ LyXText::setLayout(ParagraphList::iterator start,
// set layout over selection and make a total rebreak of those paragraphs // set layout over selection and make a total rebreak of those paragraphs
void LyXText::setLayout(string const & layout) void LyXText::setLayout(LCursor & cur, string const & layout)
{ {
// special handling of new environment insets // special handling of new environment insets
BufferParams const & params = bv()->buffer()->params(); BufferParams const & params = bv()->buffer()->params();
@ -291,18 +291,15 @@ void LyXText::setLayout(string const & layout)
bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL)); bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
bv()->owner()->dispatch(FuncRequest(LFUN_CUT)); bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
InsetBase * inset = new InsetEnvironment(params, layout); InsetBase * inset = new InsetEnvironment(params, layout);
insertInset(inset); insertInset(cur, inset);
//inset->edit(bv()); //inset->edit(bv());
//bv()->owner()->dispatch(FuncRequest(LFUN_PASTE)); //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
return; return;
} }
ParagraphList::iterator start = ParagraphList::iterator start = getPar(cur.selBegin().par());
getPar(bv()->cursor().selBegin().par()); ParagraphList::iterator end = boost::next(getPar(cur.selEnd().par()));
ParagraphList::iterator end =
boost::next(getPar(bv()->cursor().selEnd().par()));
ParagraphList::iterator endpit = setLayout(start, end, layout); ParagraphList::iterator endpit = setLayout(start, end, layout);
redoParagraphs(start, endpit); redoParagraphs(start, endpit);
updateCounters(); updateCounters();
} }
@ -311,16 +308,16 @@ void LyXText::setLayout(string const & layout)
namespace { namespace {
void getSelectionSpan(LyXText & text, void getSelectionSpan(LCursor & cur, LyXText & text,
ParagraphList::iterator & beg, ParagraphList::iterator & beg,
ParagraphList::iterator & end) ParagraphList::iterator & end)
{ {
if (!text.bv()->cursor().selection()) { if (!cur.selection()) {
beg = text.cursorPar(); beg = text.getPar(cur.par());
end = boost::next(beg); end = boost::next(beg);
} else { } else {
beg = text.getPar(text.bv()->cursor().selBegin()); beg = text.getPar(cur.selBegin());
end = boost::next(text.getPar(text.bv()->cursor().selEnd())); end = boost::next(text.getPar(cur.selEnd()));
} }
} }
@ -343,10 +340,10 @@ bool changeDepthAllowed(bv_funcs::DEPTH_CHANGE type,
} }
bool LyXText::changeDepthAllowed(bv_funcs::DEPTH_CHANGE type) bool LyXText::changeDepthAllowed(LCursor & cur, bv_funcs::DEPTH_CHANGE type)
{ {
ParagraphList::iterator beg, end; ParagraphList::iterator beg, end;
getSelectionSpan(*this, beg, end); getSelectionSpan(cur, *this, beg, end);
int max_depth = 0; int max_depth = 0;
if (beg != paragraphs().begin()) if (beg != paragraphs().begin())
max_depth = boost::prior(beg)->getMaxDepthAfter(); max_depth = boost::prior(beg)->getMaxDepthAfter();
@ -360,12 +357,11 @@ bool LyXText::changeDepthAllowed(bv_funcs::DEPTH_CHANGE type)
} }
void LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type) void LyXText::changeDepth(LCursor & cur, bv_funcs::DEPTH_CHANGE type)
{ {
ParagraphList::iterator beg, end; ParagraphList::iterator beg, end;
getSelectionSpan(*this, beg, end); getSelectionSpan(cur, *this, beg, end);
recordUndoSelection(cur);
recUndo(parOffset(beg), parOffset(end) - 1);
int max_depth = 0; int max_depth = 0;
if (beg != paragraphs().begin()) if (beg != paragraphs().begin())
@ -388,17 +384,17 @@ void LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type)
// set font over selection and make a total rebreak of those paragraphs // set font over selection and make a total rebreak of those paragraphs
void LyXText::setFont(LyXFont const & font, bool toggleall) void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall)
{ {
LCursor & cur = bv()->cursor();
// if there is no selection just set the current_font // if there is no selection just set the current_font
if (!cur.selection()) { if (!cur.selection()) {
// Determine basis font // Determine basis font
LyXFont layoutfont; LyXFont layoutfont;
if (cursor().pos() < cursorPar()->beginOfBody()) ParagraphList::iterator pit = getPar(cur.par());
layoutfont = getLabelFont(cursorPar()); if (cur.pos() < pit->beginOfBody())
layoutfont = getLabelFont(pit);
else else
layoutfont = getLayoutFont(cursorPar()); layoutfont = getLayoutFont(pit);
// Update current font // Update current font
real_current_font.update(font, real_current_font.update(font,
@ -415,7 +411,7 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
} }
// ok we have a selection. // ok we have a selection.
recUndo(cur.selBegin().par(), cur.selEnd().par()); recordUndoSelection(cur);
freezeUndo(); freezeUndo();
ParagraphList::iterator beg = getPar(cur.selBegin().par()); ParagraphList::iterator beg = getPar(cur.selBegin().par());
@ -468,12 +464,12 @@ void LyXText::cursorBottom(LCursor & cur)
} }
void LyXText::toggleFree(LyXFont const & font, bool toggleall) void LyXText::toggleFree(LCursor & cur, LyXFont const & font, bool toggleall)
{ {
// If the mask is completely neutral, tell user // If the mask is completely neutral, tell user
if (font == LyXFont(LyXFont::ALL_IGNORE)) { if (font == LyXFont(LyXFont::ALL_IGNORE)) {
// Could only happen with user style // Could only happen with user style
bv()->owner()->message(_("No font change defined. " cur.message(_("No font change defined. "
"Use Character under the Layout menu to define font change.")); "Use Character under the Layout menu to define font change."));
return; return;
} }
@ -481,45 +477,44 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall)
// Try implicit word selection // Try implicit word selection
// If there is a change in the language the implicit word selection // If there is a change in the language the implicit word selection
// is disabled. // is disabled.
CursorSlice resetCursor = cursor(); CursorSlice resetCursor = cur.current();
bool implicitSelection = bool implicitSelection =
font.language() == ignore_language font.language() == ignore_language
&& font.number() == LyXFont::IGNORE && font.number() == LyXFont::IGNORE
&& selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT); && selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD_STRICT);
// Set font // Set font
setFont(font, toggleall); setFont(cur, font, toggleall);
// Implicit selections are cleared afterwards // Implicit selections are cleared afterwards
//and cursor is set to the original position. // and cursor is set to the original position.
if (implicitSelection) { if (implicitSelection) {
bv()->cursor().clearSelection(); cur.clearSelection();
cursor() = resetCursor; cur.current() = resetCursor;
bv()->cursor().resetAnchor(); cur.resetAnchor();
} }
} }
string LyXText::getStringToIndex() string LyXText::getStringToIndex(LCursor & cur)
{ {
LCursor & cur = bv()->cursor();
// Try implicit word selection // Try implicit word selection
// If there is a change in the language the implicit word selection // If there is a change in the language the implicit word selection
// is disabled. // is disabled.
CursorSlice const reset_cursor = cursor(); CursorSlice const reset_cursor = cur.current();
bool const implicitSelection = bool const implicitSelection =
selectWordWhenUnderCursor(lyx::PREVIOUS_WORD); selectWordWhenUnderCursor(cur, lyx::PREVIOUS_WORD);
string idxstring; string idxstring;
if (!cur.selection()) if (!cur.selection())
bv()->owner()->message(_("Nothing to index!")); cur.message(_("Nothing to index!"));
else if (cur.selBegin().par() != cur.selEnd().par()) else if (cur.selBegin().par() != cur.selEnd().par())
bv()->owner()->message(_("Cannot index more than one paragraph!")); cur.message(_("Cannot index more than one paragraph!"));
else else
idxstring = cur.selectionAsString(false); idxstring = cur.selectionAsString(false);
// Reset cursors to their original position. // Reset cursors to their original position.
cursor() = reset_cursor; cur.current() = reset_cursor;
cur.resetAnchor(); cur.resetAnchor();
// Clear the implicit selection. // Clear the implicit selection.
@ -859,24 +854,20 @@ void LyXText::updateCounters()
} }
void LyXText::insertInset(InsetBase * inset) void LyXText::insertInset(LCursor & cur, InsetBase * inset)
{ {
if (!cursorPar()->insetAllowed(inset->lyxCode())) recordUndo(cur);
return;
recUndo(cursor().par());
freezeUndo(); freezeUndo();
cursorPar()->insertInset(cursor().pos(), inset); cur.paragraph().insertInset(cur.pos(), inset);
// Just to rebreak and refresh correctly. // Just to rebreak and refresh correctly.
// The character will not be inserted a second time // The character will not be inserted a second time
insertChar(Paragraph::META_INSET); insertChar(cur, Paragraph::META_INSET);
// If we enter a highly editable inset the cursor should be before // If we enter a highly editable inset the cursor should be before
// the inset. After an undo LyX tries to call inset->edit(...) // the inset. After an undo LyX tries to call inset->edit(...)
// and fails if the cursor is behind the inset and getInset // and fails if the cursor is behind the inset and getInset
// does not return the inset! // does not return the inset!
if (isHighlyEditableInset(inset)) if (isHighlyEditableInset(inset))
cursorLeft(bv()->cursor(), true); cursorLeft(cur, true);
unFreezeUndo(); unFreezeUndo();
} }
@ -902,10 +893,10 @@ void LyXText::cutSelection(bool doclear, bool realcut)
// and cur.selEnd() // and cur.selEnd()
// make sure that the depth behind the selection are restored, too // make sure that the depth behind the selection are restored, too
recordUndoSelection(cur);
ParagraphList::iterator begpit = getPar(cur.selBegin().par()); ParagraphList::iterator begpit = getPar(cur.selBegin().par());
ParagraphList::iterator endpit = getPar(cur.selEnd().par()); ParagraphList::iterator endpit = getPar(cur.selEnd().par());
ParagraphList::iterator undopit = undoSpan(endpit); ParagraphList::iterator undopit = undoSpan(endpit);
recUndo(cur.selBegin().par(), parOffset(undopit) - 1);
int endpos = cur.selEnd().pos(); int endpos = cur.selEnd().pos();
@ -913,7 +904,7 @@ void LyXText::cutSelection(bool doclear, bool realcut)
boost::tie(endpit, endpos) = realcut ? boost::tie(endpit, endpos) = realcut ?
CutAndPaste::cutSelection(bufparams, CutAndPaste::cutSelection(bufparams,
paragraphs(), paragraphs(),
begpit , endpit, begpit, endpit,
cur.selBegin().pos(), endpos, cur.selBegin().pos(), endpos,
bufparams.textclass, bufparams.textclass,
doclear) doclear)
@ -930,8 +921,8 @@ void LyXText::cutSelection(bool doclear, bool realcut)
// cutSelection can invalidate the cursor so we need to set // cutSelection can invalidate the cursor so we need to set
// it anew. (Lgb) // it anew. (Lgb)
// we prefer the end for when tracking changes // we prefer the end for when tracking changes
cursor().pos(endpos); cur.pos() = endpos;
cursor().par(parOffset(endpit)); cur.par() = parOffset(endpit);
// need a valid cursor. (Lgb) // need a valid cursor. (Lgb)
cur.clearSelection(); cur.clearSelection();
@ -967,14 +958,13 @@ void LyXText::copySelection()
} }
void LyXText::pasteSelection(size_t sel_index) void LyXText::pasteSelection(LCursor & cur, size_t sel_index)
{ {
LCursor & cur = bv()->cursor();
// this does not make sense, if there is nothing to paste // this does not make sense, if there is nothing to paste
if (!CutAndPaste::checkPastePossible()) if (!CutAndPaste::checkPastePossible())
return; return;
recUndo(cursor().par()); recordUndo(cur);
ParagraphList::iterator endpit; ParagraphList::iterator endpit;
PitPosPair ppp; PitPosPair ppp;
@ -1000,12 +990,10 @@ void LyXText::pasteSelection(size_t sel_index)
} }
void LyXText::setSelectionRange(lyx::pos_type length) void LyXText::setSelectionRange(LCursor & cur, lyx::pos_type length)
{ {
if (!length) if (!length)
return; return;
LCursor & cur = bv()->cursor();
cur.resetAnchor(); cur.resetAnchor();
while (length--) while (length--)
cursorRight(cur, true); cursorRight(cur, true);
@ -1014,10 +1002,9 @@ void LyXText::setSelectionRange(lyx::pos_type length)
// simple replacing. The font of the first selected character is used // simple replacing. The font of the first selected character is used
void LyXText::replaceSelectionWithString(string const & str) void LyXText::replaceSelectionWithString(LCursor & cur, string const & str)
{ {
LCursor & cur = bv()->cursor(); recordUndo(cur);
recUndo(cur.par());
freezeUndo(); freezeUndo();
// Get font setting before we cut // Get font setting before we cut
@ -1042,34 +1029,32 @@ void LyXText::replaceSelectionWithString(string const & str)
// needed to insert the selection // needed to insert the selection
void LyXText::insertStringAsLines(string const & str) void LyXText::insertStringAsLines(LCursor & cur, string const & str)
{ {
LCursor & cur = bv()->cursor(); ParagraphList::iterator pit = getPar(cur.par());
ParagraphList::iterator pit = cursorPar(); ParagraphList::iterator endpit = boost::next(pit);
pos_type pos = cursor().pos(); pos_type pos = cursor().pos();
ParagraphList::iterator endpit = boost::next(cursorPar()); recordUndo(cur);
recordUndo(cur, Undo::ATOMIC);
// only to be sure, should not be neccessary // only to be sure, should not be neccessary
cur.clearSelection(); cur.clearSelection();
bv()->buffer()->insertStringAsLines(pit, pos, current_font, str); bv()->buffer()->insertStringAsLines(pit, pos, current_font, str);
redoParagraphs(cursorPar(), endpit); redoParagraphs(getPar(cur.par()), endpit);
cur.resetAnchor(); cur.resetAnchor();
setCursor(parOffset(pit), pos); setCursor(cur.par(), pos);
cur.setSelection(); cur.setSelection();
} }
// turn double CR to single CR, others are converted into one // turn double CR to single CR, others are converted into one
// blank. Then insertStringAsLines is called // blank. Then insertStringAsLines is called
void LyXText::insertStringAsParagraphs(string const & str) void LyXText::insertStringAsParagraphs(LCursor & cur, string const & str)
{ {
string linestr(str); string linestr = str;
bool newline_inserted = false; bool newline_inserted = false;
string::size_type const siz = linestr.length();
for (string::size_type i = 0; i < siz; ++i) { for (string::size_type i = 0, siz = linestr.size(); i < siz; ++i) {
if (linestr[i] == '\n') { if (linestr[i] == '\n') {
if (newline_inserted) { if (newline_inserted) {
// we know that \r will be ignored by // we know that \r will be ignored by
@ -1085,7 +1070,7 @@ void LyXText::insertStringAsParagraphs(string const & str)
newline_inserted = false; newline_inserted = false;
} }
} }
insertStringAsLines(linestr); insertStringAsLines(cur, linestr);
} }
@ -1197,6 +1182,7 @@ void LyXText::setCurrentFont()
} }
} }
// x is an absolute screen coord // x is an absolute screen coord
// returns the column near the specified x-coordinate of the row // returns the column near the specified x-coordinate of the row
// x is set to the real beginning of this column // x is set to the real beginning of this column
@ -1479,7 +1465,7 @@ bool LyXText::cursorRight(LCursor & cur, bool internal)
void LyXText::cursorUp(LCursor & cur, bool selecting) void LyXText::cursorUp(LCursor & cur, bool selecting)
{ {
Row const & row = *cursorRow(); Row const & row = cur.textRow();
int x = cur.x_target(); int x = cur.x_target();
int y = cursorY(cur.current()) - row.baseline() - 1; int y = cursorY(cur.current()) - row.baseline() - 1;
setCursorFromCoordinates(x, y); setCursorFromCoordinates(x, y);
@ -1702,17 +1688,17 @@ bool LyXText::isInInset() const
} }
bool LyXText::toggleInset() bool LyXText::toggleInset(LCursor & cur)
{ {
InsetBase * inset = bv()->cursor().nextInset(); InsetBase * inset = cur.nextInset();
// is there an editable inset at cursor position? // is there an editable inset at cursor position?
if (!isEditableInset(inset)) if (!isEditableInset(inset))
return false; return false;
//bv()->owner()->message(inset->editMessage()); cur.message(inset->editMessage());
// do we want to keep this?? (JMarc) // do we want to keep this?? (JMarc)
if (!isHighlyEditableInset(inset)) if (!isHighlyEditableInset(inset))
recUndo(cursor().par()); recordUndo(cur);
if (inset->isOpen()) if (inset->isOpen())
inset->close(); inset->close();

View File

@ -57,9 +57,6 @@
#include <clocale> #include <clocale>
using bv_funcs::replaceSelection;
using lyx::pos_type; using lyx::pos_type;
using lyx::support::isStrUnsignedInt; using lyx::support::isStrUnsignedInt;
@ -88,28 +85,26 @@ namespace {
bool toggleall = false; bool toggleall = false;
void toggleAndShow(BufferView * bv, LyXText * text, void toggleAndShow(LCursor & cur, LyXText * text,
LyXFont const & font, bool toggleall = true) LyXFont const & font, bool toggleall = true)
{ {
if (!bv->available()) if (!cur.bv().available())
return; return;
text->toggleFree(font, toggleall); text->toggleFree(cur, font, toggleall);
bv->update();
if (font.language() != ignore_language || if (font.language() != ignore_language ||
font.number() != LyXFont::IGNORE) { font.number() != LyXFont::IGNORE) {
CursorSlice & cur = text->cursor(); Paragraph & par = cur.paragraph();
Paragraph & par = *text->cursorPar(); text->bidi.computeTables(par, *cur.bv().buffer(), cur.textRow());
text->bidi.computeTables(par, *bv->buffer(),
*par.getRow(cur.pos()));
if (cur.boundary() != if (cur.boundary() !=
text->bidi.isBoundary(*bv->buffer(), par, text->bidi.isBoundary(*cur.bv().buffer(), par,
cur.pos(), cur.pos(),
text->real_current_font)) text->real_current_font))
text->setCursor(cur.par(), cur.pos(), text->setCursor(cur.par(), cur.pos(),
false, !cur.boundary()); false, !cur.boundary());
} }
cur.bv().update();
} }
@ -271,10 +266,10 @@ void LyXText::gotoInset(vector<InsetOld_code> const & codes, bool same_content)
cur.pos() = 0; cur.pos() = 0;
if (!gotoNextInset(codes, contents)) { if (!gotoNextInset(codes, contents)) {
cursor() = tmp; cursor() = tmp;
cur.bv().owner()->message(_("No more insets")); cur.message(_("No more insets"));
} }
} else { } else {
cur.bv().owner()->message(_("No more insets")); cur.message(_("No more insets"));
} }
} }
cur.bv().update(); cur.bv().update();
@ -330,30 +325,31 @@ void LyXText::cursorNext(LCursor & cur)
namespace { namespace {
void specialChar(LyXText * text, BufferView * bv, InsetSpecialChar::Kind kind) void specialChar(LCursor & cur, LyXText * text, BufferView * bv,
InsetSpecialChar::Kind kind)
{ {
bv->update(); bv->update();
replaceSelection(text); text->replaceSelection(cur);
text->insertInset(new InsetSpecialChar(kind)); cur.insert(new InsetSpecialChar(kind));
bv->update(); bv->update();
} }
void doInsertInset(LyXText * text, BufferView * bv, FuncRequest const & cmd, void doInsertInset(LCursor & cur, LyXText * text, BufferView * bv,
bool edit, bool pastesel) FuncRequest const & cmd, bool edit, bool pastesel)
{ {
InsetBase * inset = createInset(bv, cmd); InsetBase * inset = createInset(bv, cmd);
if (!inset) if (!inset)
return; return;
bool gotsel = false; bool gotsel = false;
if (bv->cursor().selection()) { if (cur.selection()) {
bv->owner()->dispatch(FuncRequest(LFUN_CUT)); bv->owner()->dispatch(FuncRequest(LFUN_CUT));
gotsel = true; gotsel = true;
} }
text->insertInset(inset); text->insertInset(cur, inset);
if (edit) if (edit)
inset->edit(bv->cursor(), true); inset->edit(cur, true);
if (gotsel && pastesel) if (gotsel && pastesel)
bv->owner()->dispatch(FuncRequest(LFUN_PASTE)); bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
} }
@ -365,7 +361,7 @@ void LyXText::number()
{ {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setNumber(LyXFont::TOGGLE); font.setNumber(LyXFont::TOGGLE);
toggleAndShow(bv(), this, font); toggleAndShow(bv()->cursor(), this, font);
} }
@ -385,8 +381,8 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
switch (cmd.action) { switch (cmd.action) {
case LFUN_APPENDIX: { case LFUN_APPENDIX: {
ParagraphList::iterator pit = cursorPar(); Paragraph & par = cur.paragraph();
bool start = !pit->params().startOfAppendix(); bool start = !par.params().startOfAppendix();
// ensure that we have only one start_of_appendix in this document // ensure that we have only one start_of_appendix in this document
ParagraphList::iterator tmp = paragraphs().begin(); ParagraphList::iterator tmp = paragraphs().begin();
@ -401,12 +397,12 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
} }
} }
recUndo(parOffset(pit)); recordUndo(cur);
pit->params().startOfAppendix(start); par.params().startOfAppendix(start);
// we can set the refreshing parameters now // we can set the refreshing parameters now
updateCounters(); updateCounters();
redoParagraph(cursorPar()); redoParagraph(cur);
bv->update(); bv->update();
break; break;
} }
@ -560,7 +556,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
break; break;
case LFUN_WORDSEL: { case LFUN_WORDSEL: {
selectWord(lyx::WHOLE_WORD); selectWord(cur, lyx::WHOLE_WORD);
finishChange(cur, true); finishChange(cur, true);
break; break;
} }
@ -630,9 +626,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_BREAKLINE: { case LFUN_BREAKLINE: {
// Not allowed by LaTeX (labels or empty par) // Not allowed by LaTeX (labels or empty par)
if (cursor().pos() > cursorPar()->beginOfBody()) { if (cur.pos() > cur.paragraph().beginOfBody()) {
replaceSelection(this); replaceSelection(cur);
insertInset(new InsetNewline); cur.insert(new InsetNewline);
moveCursor(cur, false); moveCursor(cur, false);
} }
break; break;
@ -697,7 +693,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
break; break;
case LFUN_BREAKPARAGRAPH: case LFUN_BREAKPARAGRAPH:
replaceSelection(this); replaceSelection(cur);
breakParagraph(cur, 0); breakParagraph(cur, 0);
bv->update(); bv->update();
cur.resetAnchor(); cur.resetAnchor();
@ -706,7 +702,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
break; break;
case LFUN_BREAKPARAGRAPHKEEPLAYOUT: case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
replaceSelection(this); replaceSelection(cur);
breakParagraph(cur, 1); breakParagraph(cur, 1);
bv->update(); bv->update();
cur.resetAnchor(); cur.resetAnchor();
@ -719,7 +715,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
// indentation and add a "defskip" at the top. // indentation and add a "defskip" at the top.
// Otherwise, do the same as LFUN_BREAKPARAGRAPH. // Otherwise, do the same as LFUN_BREAKPARAGRAPH.
#warning look here #warning look here
replaceSelection(this); replaceSelection(cur);
if (cur.pos() == 0) { if (cur.pos() == 0) {
ParagraphParameters & params = cur.paragraph().params(); ParagraphParameters & params = cur.paragraph().params();
setParagraph( setParagraph(
@ -772,7 +768,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
} }
if (cur_spacing != new_spacing || cur_value != new_value) { if (cur_spacing != new_spacing || cur_value != new_value) {
par.params().spacing(Spacing(new_spacing, new_value)); par.params().spacing(Spacing(new_spacing, new_value));
redoParagraph(); redoParagraph(cur);
bv->update(); bv->update();
} }
break; break;
@ -791,7 +787,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_INSET_INSERT: { case LFUN_INSET_INSERT: {
InsetBase * inset = createInset(bv, cmd); InsetBase * inset = createInset(bv, cmd);
if (inset) if (inset)
insertInset(inset); insertInset(cur, inset);
break; break;
} }
@ -802,69 +798,69 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_INSET_TOGGLE: case LFUN_INSET_TOGGLE:
cur.clearSelection(); cur.clearSelection();
if (!toggleInset()) if (!toggleInset(cur))
return DispatchResult(false); return DispatchResult(false);
bv->update(); bv->update();
bv->switchKeyMap(); bv->switchKeyMap();
break; break;
case LFUN_SPACE_INSERT: case LFUN_SPACE_INSERT:
if (cursorPar()->layout()->free_spacing) if (cur.paragraph().layout()->free_spacing)
insertChar(' '); insertChar(cur, ' ');
else else
doInsertInset(this, bv, cmd, false, false); doInsertInset(cur, this, bv, cmd, false, false);
moveCursor(cur, false); moveCursor(cur, false);
break; break;
case LFUN_HYPHENATION: case LFUN_HYPHENATION:
specialChar(this, bv, InsetSpecialChar::HYPHENATION); specialChar(cur, this, bv, InsetSpecialChar::HYPHENATION);
break; break;
case LFUN_LIGATURE_BREAK: case LFUN_LIGATURE_BREAK:
specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK); specialChar(cur, this, bv, InsetSpecialChar::LIGATURE_BREAK);
break; break;
case LFUN_LDOTS: case LFUN_LDOTS:
specialChar(this, bv, InsetSpecialChar::LDOTS); specialChar(cur, this, bv, InsetSpecialChar::LDOTS);
break; break;
case LFUN_END_OF_SENTENCE: case LFUN_END_OF_SENTENCE:
specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE); specialChar(cur, this, bv, InsetSpecialChar::END_OF_SENTENCE);
break; break;
case LFUN_MENU_SEPARATOR: case LFUN_MENU_SEPARATOR:
specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR); specialChar(cur, this, bv, InsetSpecialChar::MENU_SEPARATOR);
break; break;
case LFUN_UPCASE_WORD: case LFUN_UPCASE_WORD:
changeCase(LyXText::text_uppercase); changeCase(cur, LyXText::text_uppercase);
bv->update(); bv->update();
break; break;
case LFUN_LOWCASE_WORD: case LFUN_LOWCASE_WORD:
changeCase(LyXText::text_lowercase); changeCase(cur, LyXText::text_lowercase);
bv->update(); bv->update();
break; break;
case LFUN_CAPITALIZE_WORD: case LFUN_CAPITALIZE_WORD:
changeCase(LyXText::text_capitalization); changeCase(cur, LyXText::text_capitalization);
bv->update(); bv->update();
break; break;
case LFUN_TRANSPOSE_CHARS: case LFUN_TRANSPOSE_CHARS:
recUndo(cursor().par()); recordUndo(cur);
redoParagraph(); redoParagraph(cur);
bv->update(); bv->update();
break; break;
case LFUN_PASTE: case LFUN_PASTE:
cur.message(_("Paste")); cur.message(_("Paste"));
replaceSelection(this); replaceSelection(cur);
#warning FIXME Check if the arg is in the domain of available selections. #warning FIXME Check if the arg is in the domain of available selections.
if (isStrUnsignedInt(cmd.argument)) if (isStrUnsignedInt(cmd.argument))
pasteSelection(strToUnsignedInt(cmd.argument)); pasteSelection(cur, strToUnsignedInt(cmd.argument));
else else
pasteSelection(0); pasteSelection(cur, 0);
cur.clearSelection(); // bug 393 cur.clearSelection(); // bug 393
bv->update(); bv->update();
bv->switchKeyMap(); bv->switchKeyMap();
@ -928,7 +924,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
break; break;
case LFUN_GETLAYOUT: case LFUN_GETLAYOUT:
cur.message(cursorPar()->layout()->name()); cur.message(cur.paragraph().layout()->name());
break; break;
case LFUN_LAYOUT: { case LFUN_LAYOUT: {
@ -982,7 +978,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
if (change_layout) { if (change_layout) {
current_layout = layout; current_layout = layout;
setLayout(layout); setLayout(cur, layout);
bv->owner()->setLayout(layout); bv->owner()->setLayout(layout);
bv->update(); bv->update();
bv->switchKeyMap(); bv->switchKeyMap();
@ -995,9 +991,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
string const clip = bv->getClipboard(); string const clip = bv->getClipboard();
if (!clip.empty()) { if (!clip.empty()) {
if (cmd.argument == "paragraph") if (cmd.argument == "paragraph")
insertStringAsParagraphs(clip); insertStringAsParagraphs(cur, clip);
else else
insertStringAsLines(clip); insertStringAsLines(cur, clip);
bv->update(); bv->update();
} }
break; break;
@ -1020,30 +1016,30 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
} }
case LFUN_QUOTE: { case LFUN_QUOTE: {
replaceSelection(this); replaceSelection(cur);
ParagraphList::iterator pit = cursorPar(); Paragraph & par = cur.paragraph();
lyx::pos_type pos = cursor().pos(); lyx::pos_type pos = cur.pos();
char c; char c;
if (!pos) if (pos == 0)
c = ' '; c = ' ';
else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace()) else if (cur.prevInset() && cur.prevInset()->isSpace())
c = ' '; c = ' ';
else else
c = pit->getChar(pos - 1); c = par.getChar(pos - 1);
LyXLayout_ptr const & style = pit->layout(); LyXLayout_ptr const & style = par.layout();
BufferParams const & bufparams = bv->buffer()->params(); BufferParams const & bufparams = bv->buffer()->params();
if (style->pass_thru || if (style->pass_thru ||
pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew") par.getFontSettings(bufparams, pos).language()->lang() == "hebrew")
insertInset(new InsetQuotes(c, bufparams)); cur.insert(new InsetQuotes(c, bufparams));
else else
bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\"")); bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
break; break;
} }
case LFUN_DATE_INSERT: { case LFUN_DATE_INSERT: {
replaceSelection(this); replaceSelection(cur);
time_t now_time_t = time(NULL); time_t now_time_t = time(NULL);
struct tm * now_tm = localtime(&now_time_t); struct tm * now_tm = localtime(&now_time_t);
setlocale(LC_TIME, ""); setlocale(LC_TIME, "");
@ -1057,7 +1053,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
::strftime(datetmp, 32, arg.c_str(), now_tm); ::strftime(datetmp, 32, arg.c_str(), now_tm);
for (int i = 0; i < datetmp_len; i++) for (int i = 0; i < datetmp_len; i++)
insertChar(datetmp[i]); insertChar(cur, datetmp[i]);
cur.resetAnchor(); cur.resetAnchor();
moveCursor(cur, false); moveCursor(cur, false);
@ -1078,7 +1074,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_MOUSE_DOUBLE: case LFUN_MOUSE_DOUBLE:
if (cmd.button() == mouse_button::button1) { if (cmd.button() == mouse_button::button1) {
selection_possible = true; selection_possible = true;
selectWord(lyx::WHOLE_WORD_STRICT); selectWord(cur, lyx::WHOLE_WORD_STRICT);
bv->haveSelection(cur.selection()); bv->haveSelection(cur.selection());
} }
break; break;
@ -1095,14 +1091,14 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
"Dispatch: no selection possible\n"; "Dispatch: no selection possible\n";
break; break;
} }
RowList::iterator cursorrow = cursorRow(); CursorSlice old = cur.current();
#warning #warning
setCursorFromCoordinates(cmd.x, cmd.y); setCursorFromCoordinates(cmd.x, cmd.y);
// This is to allow jumping over large insets // This is to allow jumping over large insets
// FIXME: shouldn't be top-text-specific // FIXME: shouldn't be top-text-specific
if (cursorrow == cursorRow() && !in_inset_) { if (!in_inset_ && cur.current() == old) {
if (cmd.y - bv->top_y() >= bv->workHeight()) if (cmd.y - bv->top_y() >= bv->workHeight())
cursorDown(cur, true); cursorDown(cur, true);
else if (cmd.y - bv->top_y() < 0) else if (cmd.y - bv->top_y() < 0)
@ -1280,12 +1276,12 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_ENVIRONMENT_INSERT: case LFUN_ENVIRONMENT_INSERT:
// Open the inset, and move the current selection // Open the inset, and move the current selection
// inside it. // inside it.
doInsertInset(this, bv, cmd, true, true); doInsertInset(cur, this, bv, cmd, true, true);
break; break;
case LFUN_INDEX_INSERT: case LFUN_INDEX_INSERT:
// Just open the inset // Just open the inset
doInsertInset(this, bv, cmd, true, false); doInsertInset(cur, this, bv, cmd, true, false);
break; break;
case LFUN_INDEX_PRINT: case LFUN_INDEX_PRINT:
@ -1294,16 +1290,16 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_INSERT_LINE: case LFUN_INSERT_LINE:
case LFUN_INSERT_PAGEBREAK: case LFUN_INSERT_PAGEBREAK:
// do nothing fancy // do nothing fancy
doInsertInset(this, bv, cmd, false, false); doInsertInset(cur, this, bv, cmd, false, false);
break; break;
case LFUN_DEPTH_MIN: case LFUN_DEPTH_MIN:
bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH); changeDepth(cur, bv_funcs::DEC_DEPTH);
bv->update(); bv->update();
break; break;
case LFUN_DEPTH_PLUS: case LFUN_DEPTH_PLUS:
bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH); changeDepth(cur, bv_funcs::INC_DEPTH);
bv->update(); bv->update();
break; break;
@ -1343,7 +1339,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_EMPH: { case LFUN_EMPH: {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setEmph(LyXFont::TOGGLE); font.setEmph(LyXFont::TOGGLE);
toggleAndShow(bv, this, font); toggleAndShow(cur, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
} }
@ -1351,7 +1347,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_BOLD: { case LFUN_BOLD: {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setSeries(LyXFont::BOLD_SERIES); font.setSeries(LyXFont::BOLD_SERIES);
toggleAndShow(bv, this, font); toggleAndShow(cur, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
} }
@ -1359,7 +1355,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_NOUN: { case LFUN_NOUN: {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setNoun(LyXFont::TOGGLE); font.setNoun(LyXFont::TOGGLE);
toggleAndShow(bv, this, font); toggleAndShow(cur, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
} }
@ -1367,7 +1363,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_CODE: { case LFUN_CODE: {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
toggleAndShow(bv, this, font); toggleAndShow(cur, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
} }
@ -1375,7 +1371,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_SANS: { case LFUN_SANS: {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setFamily(LyXFont::SANS_FAMILY); font.setFamily(LyXFont::SANS_FAMILY);
toggleAndShow(bv, this, font); toggleAndShow(cur, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
} }
@ -1383,14 +1379,14 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_ROMAN: { case LFUN_ROMAN: {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setFamily(LyXFont::ROMAN_FAMILY); font.setFamily(LyXFont::ROMAN_FAMILY);
toggleAndShow(bv, this, font); toggleAndShow(cur, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
} }
case LFUN_DEFAULT: { case LFUN_DEFAULT: {
LyXFont font(LyXFont::ALL_INHERIT, ignore_language); LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
toggleAndShow(bv, this, font); toggleAndShow(cur, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
} }
@ -1398,7 +1394,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_UNDERLINE: { case LFUN_UNDERLINE: {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setUnderbar(LyXFont::TOGGLE); font.setUnderbar(LyXFont::TOGGLE);
toggleAndShow(bv, this, font); toggleAndShow(cur, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
} }
@ -1406,7 +1402,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_FONT_SIZE: { case LFUN_FONT_SIZE: {
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setLyXSize(cmd.argument); font.setLyXSize(cmd.argument);
toggleAndShow(bv, this, font); toggleAndShow(cur, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
} }
@ -1417,16 +1413,16 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
break; break;
LyXFont font(LyXFont::ALL_IGNORE); LyXFont font(LyXFont::ALL_IGNORE);
font.setLanguage(lang); font.setLanguage(lang);
toggleAndShow(bv, this, font); toggleAndShow(cur, this, font);
bv->switchKeyMap(); bv->switchKeyMap();
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
} }
case LFUN_FREEFONT_APPLY: case LFUN_FREEFONT_APPLY:
toggleAndShow(bv, this, freefont, toggleall); toggleAndShow(cur, this, freefont, toggleall);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
bv->owner()->message(_("Character set")); cur.message(_("Character set"));
break; break;
// Set the freefont using the contents of \param data dispatched from // Set the freefont using the contents of \param data dispatched from
@ -1437,9 +1433,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
if (bv_funcs::string2font(cmd.argument, font, toggle)) { if (bv_funcs::string2font(cmd.argument, font, toggle)) {
freefont = font; freefont = font;
toggleall = toggle; toggleall = toggle;
toggleAndShow(bv, this, freefont, toggleall); toggleAndShow(cur, this, freefont, toggleall);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
bv->owner()->message(_("Character set")); cur.message(_("Character set"));
} }
break; break;
} }
@ -1535,9 +1531,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
breakParagraph(cur); breakParagraph(cur);
} }
setLayout(tclass.defaultLayoutName()); setLayout(cur, tclass.defaultLayoutName());
setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0); setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
insertInset(new InsetFloatList(cmd.argument)); cur.insert(new InsetFloatList(cmd.argument));
unFreezeUndo(); unFreezeUndo();
} else { } else {
lyxerr << "Non-existent float type: " lyxerr << "Non-existent float type: "
@ -1546,6 +1542,33 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
break; break;
} }
case LFUN_ACCEPT_CHANGE: {
acceptChange(cur);
bv->update();
break;
}
case LFUN_REJECT_CHANGE: {
rejectChange(cur);
bv->update();
break;
}
case LFUN_THESAURUS_ENTRY: {
string arg = cmd.argument;
if (arg.empty()) {
arg = cur.selectionAsString(false);
// FIXME
if (arg.size() > 100 || arg.empty()) {
// Get word or selection
selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD);
arg = cur.selectionAsString(false);
}
}
bv->owner()->getDialogs().show("thesaurus", arg);
break;
}
default: default:
return DispatchResult(false); return DispatchResult(false);
} }

View File

@ -12,11 +12,16 @@
#include <config.h> #include <config.h>
#include "trans_mgr.h" #include "trans_mgr.h"
#include "trans.h"
#include "lyxtext.h" #include "BufferView.h"
#include "cursor.h"
#include "debug.h" #include "debug.h"
#include "insets/insetlatexaccent.h"
#include "lyxrc.h" #include "lyxrc.h"
#include "lyxtext.h"
#include "trans.h"
#include "insets/insetlatexaccent.h"
#include "support/lstrings.h" #include "support/lstrings.h"
using lyx::support::split; using lyx::support::split;
@ -260,11 +265,8 @@ void TransManager::TranslateAndInsert(char c, LyXText * text)
void TransManager::insertVerbatim(string const & str, LyXText * text) void TransManager::insertVerbatim(string const & str, LyXText * text)
{ {
string::size_type const l = str.length(); for (string::size_type i = 0, n = str.size(); i < n; ++i)
text->insertChar(text->bv()->cursor(), str[i]);
for (string::size_type i = 0; i < l; ++i) {
text->insertChar(str[i]);
}
} }
@ -282,15 +284,13 @@ void TransManager::insert(string const & str, LyXText * text)
// Could not find an encoding // Could not find an encoding
InsetLatexAccent ins(str); InsetLatexAccent ins(str);
if (ins.canDisplay()) { if (ins.canDisplay()) {
text->insertInset( text->bv()->cursor().insert(new InsetLatexAccent(ins));
new InsetLatexAccent(ins));
} else { } else {
insertVerbatim(str, text); insertVerbatim(str, text);
} }
return; return;
} }
string tmp; string const tmp(1, static_cast<char>(enc.second));
tmp += static_cast<char>(enc.second);
insertVerbatim(tmp, text); insertVerbatim(tmp, text);
} }

View File

@ -186,7 +186,9 @@ bool performUndoOrRedo(BufferView & bv, Undo const & undo)
text->updateCounters(); text->updateCounters();
// rebreak the entire lyxtext // rebreak the entire lyxtext
buf.text().fullRebreak(); #warning needed?
text->redoParagraphs(buf.paragraphs().begin(), buf.paragraphs().end());
bv.cursor().resetAnchor();
ParIterator pit2 = num2pit(buf, undo.text); ParIterator pit2 = num2pit(buf, undo.text);
advance(pit2, undo.cursor_par); advance(pit2, undo.cursor_par);
@ -290,6 +292,12 @@ void recordUndo(LCursor & cur, Undo::undo_kind kind)
} }
void recordUndoSelection(LCursor & cur, Undo::undo_kind kind)
{
recordUndo(kind, cur, cur.selBegin().par(), cur.selEnd().par());
}
void recordUndo(LCursor & cur, Undo::undo_kind kind, paroffset_type from) void recordUndo(LCursor & cur, Undo::undo_kind kind, paroffset_type from)
{ {
recordUndo(kind, cur, cur.par(), from); recordUndo(kind, cur, cur.par(), from);

View File

@ -102,6 +102,8 @@ void recordUndo(LCursor & cur, Undo::undo_kind kind, lyx::paroffset_type from);
/// convienience: prepare undo for the single paragraph containing the cursor /// convienience: prepare undo for the single paragraph containing the cursor
void recordUndo(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC); void recordUndo(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
/// convienience: prepare undo for the selected paragraphs
void recordUndoSelection(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);
/// convienience: prepare undo for the single paragraph containing the cursor /// convienience: prepare undo for the single paragraph containing the cursor
void recordUndoFullDocument(LCursor & cur); void recordUndoFullDocument(LCursor & cur);