From 4bcfc43c2958ef6dd083210ed25db4eb5a290a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 13 Feb 2004 07:30:59 +0000 Subject: [PATCH] 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 --- src/BufferView.C | 22 +- src/BufferView.h | 2 - src/BufferView_pimpl.C | 45 +-- src/ChangeLog | 1 + src/Spacing.C | 3 +- src/bufferview_funcs.C | 112 +------- src/bufferview_funcs.h | 12 +- src/cursor.C | 50 +++- src/cursor.h | 8 +- src/factory.C | 2 +- .../controllers/ControlCommandBuffer.C | 17 +- .../controllers/ControlSpellchecker.C | 19 +- src/insets/insetcollapsable.C | 7 +- src/insets/insettext.C | 6 +- src/lyx_cb.C | 4 +- src/lyxfind.C | 4 +- src/lyxfunc.C | 113 ++++---- src/lyxtext.h | 57 ++-- src/paper.h | 38 +-- src/text.C | 257 ++++++++++++------ src/text2.C | 144 +++++----- src/text3.C | 209 +++++++------- src/trans_mgr.C | 24 +- src/undo.C | 10 +- src/undo.h | 2 + 25 files changed, 566 insertions(+), 602 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 879849b777..53c9c3c310 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -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() { screen().hideCursor(); @@ -455,7 +435,7 @@ void BufferView::putSelectionAt(PosIterator const & cur, cursor().updatePos(); if (length) { - text->setSelectionRange(length); + text->setSelectionRange(cursor(), length); cursor().setSelection(); if (backwards) swap(cursor().cursor_, cursor().anchor_); diff --git a/src/BufferView.h b/src/BufferView.h index 711d9fdd4e..20583c982a 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -117,8 +117,6 @@ public: /// return the parent language of the given inset 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 void replaceSelectionWithString(std::string const & str); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 3e28a1cf23..290234247a 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -65,8 +65,6 @@ #include -using bv_funcs::currentState; - using lyx::pos_type; using lyx::support::AddPath; @@ -975,7 +973,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd) << " button[" << cmd.button() << ']' << endl; - LyXTextClass const & tclass = buffer_->params().getLyXTextClass(); LCursor & cur = bv_->cursor(); switch (cmd.action) { @@ -1015,7 +1012,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd) break; case LFUN_FONT_STATE: - owner_->getLyXFunc().setMessage(currentState(bv_)); + cur.message(cur.currentState()); break; case LFUN_INSERT_LABEL: { @@ -1049,31 +1046,13 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd) if (!label.empty()) bv_->gotoLabel(label); + break; } - break; case LFUN_PARAGRAPH_APPLY: setParagraphParams(*bv_, cmd.argument); 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: trackChanges(); break; @@ -1083,31 +1062,19 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd) break; case LFUN_ACCEPT_ALL_CHANGES: { - bv_->text()->setCursor(0, 0); + bv_->cursor().reset(); #warning FIXME changes while (lyx::find::findNextChange(bv_)) - bv_->getLyXText()->acceptChange(); + bv_->getLyXText()->acceptChange(bv_->cursor()); update(); break; } case LFUN_REJECT_ALL_CHANGES: { - bv_->text()->setCursor(0, 0); + bv_->cursor().reset(); #warning FIXME changes while (lyx::find::findNextChange(bv_)) - bv_->getLyXText()->rejectChange(); - update(); - break; - } - - case LFUN_ACCEPT_CHANGE: { - bv_->getLyXText()->acceptChange(); - update(); - break; - } - - case LFUN_REJECT_CHANGE: { - bv_->getLyXText()->rejectChange(); + bv_->getLyXText()->rejectChange(bv_->cursor()); update(); break; } diff --git a/src/ChangeLog b/src/ChangeLog index 89c583d39b..ede0327d78 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -5,6 +5,7 @@ * text.C: * text2.C: * text3.C: add LCursor & parameter to most cursor movement functions + remove usage of LyXText::cursorRow() and cursorPar() * cursor.[Ch]: add textRow() needed members diff --git a/src/Spacing.C b/src/Spacing.C index 0987e337bd..ec306a9d7b 100644 --- a/src/Spacing.C +++ b/src/Spacing.C @@ -11,9 +11,10 @@ #include -#include "support/std_sstream.h" #include "Spacing.h" +#include "support/std_sstream.h" + using std::ios; using std::istringstream; using std::ostream; diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 634ed5f9c4..0cbb5ae1b9 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -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 diff --git a/src/bufferview_funcs.h b/src/bufferview_funcs.h index d6bf1c7c26..2514ec737f 100644 --- a/src/bufferview_funcs.h +++ b/src/bufferview_funcs.h @@ -18,6 +18,7 @@ class BufferView; +class LCursor; class LyXFont; class LyXText; class PosIterator; @@ -45,17 +46,8 @@ enum DEPTH_CHANGE { 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 -bool changeDepthAllowed(BufferView *, LyXText *, DEPTH_CHANGE); - -/// Returns the current font and depth as a message. -std::string const currentState(BufferView *); -/// replace selection with insertion -void replaceSelection(LyXText * lt); - +bool changeDepthAllowed(LCursor & cur, LyXText * text, DEPTH_CHANGE); }; // namespace bv_funcs diff --git a/src/cursor.C b/src/cursor.C index 9dc8d6cba3..9c53dd5e0f 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -35,6 +35,8 @@ #include "mathed/math_support.h" #include "support/limited_stack.h" +#include "support/std_sstream.h" + #include "frontends/LyXView.h" #include @@ -255,7 +257,7 @@ void LCursor::getDim(int & asc, int & des) const asc = 10; des = 10; } else { - Row const & row = *text()->cursorRow(); + Row const & row = textRow(); asc = row.baseline(); 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) { cursor_[i].inset()->infoize(os); @@ -1031,7 +1033,7 @@ void LCursor::insert(InsetBase * inset) if (inMathed()) insert(MathAtom(inset)); else - text()->insertInset(inset); + text()->insertInset(*this, inset); } @@ -1829,8 +1831,7 @@ InsetBase * LCursor::nextInset() return 0; if (inMathed()) return nextAtom().nucleus(); - Paragraph & par = paragraph(); - return par.isInset(pos()) ? par.getInset(pos()) : 0; + return paragraph().isInset(pos()) ? paragraph().getInset(pos()) : 0; } @@ -1840,8 +1841,17 @@ InsetBase * LCursor::prevInset() return 0; if (inMathed()) return prevAtom().nucleus(); - Paragraph & par = paragraph(); - return par.isInset(pos() - 1) ? par.getInset(pos() - 1) : 0; + return paragraph().isInset(pos() - 1) ? paragraph().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? 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); +} + diff --git a/src/cursor.h b/src/cursor.h index 76b75f228a..4b90fae3e3 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -146,6 +146,8 @@ public: std::string selectionAsString(bool label) const; /// void paste(std::string const & data); + /// + std::string currentState(); // // access to the 'current' cursor slice @@ -189,6 +191,8 @@ public: InsetBase * nextInset(); /// the inset just in front of the cursor InsetBase * prevInset(); + /// the inset just in front of the cursor + InsetBase const * prevInset() const; // // math-specific part @@ -276,11 +280,13 @@ public: /// access to owning BufferView BufferView & bv() const; /// 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)? int currentMode(); /// reset cursor void reset(); + /// for spellchecking + void replaceWord(std::string const & replacestring); /// output friend std::ostream & operator<<(std::ostream & os, LCursor const & cur); diff --git a/src/factory.C b/src/factory.C index b0f443fdab..11340acb54 100644 --- a/src/factory.C +++ b/src/factory.C @@ -154,7 +154,7 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd) // Try and generate a valid index entry. InsetCommandParams icp("index"); string const contents = cmd.argument.empty() ? - bv->getLyXText()->getStringToIndex() : + bv->getLyXText()->getStringToIndex(bv->cursor()) : cmd.argument; icp.setContents(contents); diff --git a/src/frontends/controllers/ControlCommandBuffer.C b/src/frontends/controllers/ControlCommandBuffer.C index 7c84fe9f15..03055ddc65 100644 --- a/src/frontends/controllers/ControlCommandBuffer.C +++ b/src/frontends/controllers/ControlCommandBuffer.C @@ -13,17 +13,18 @@ #include #include "ControlCommandBuffer.h" -#include "bufferview_funcs.h" + +#include "BufferView.h" +#include "cursor.h" #include "lyxfunc.h" #include "LyXAction.h" #include "funcrequest.h" #include "frontends/LyXView.h" + #include "support/lyxalgo.h" #include "support/lstrings.h" -using bv_funcs::currentState; - using lyx::support::prefixIs; using std::back_inserter; @@ -66,9 +67,9 @@ string const ControlCommandBuffer::historyUp() string const ControlCommandBuffer::historyDown() { if (history_pos_ == history_.end()) - return ""; + return string(); if (history_pos_ + 1 == history_.end()) - return ""; + return string(); return *(++history_pos_); } @@ -76,7 +77,7 @@ string const ControlCommandBuffer::historyDown() 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(); } - // find maximal avaliable prefix + // find maximal available prefix string const tmp = comp[0]; - string test(prefix); + string test = prefix; if (tmp.length() > test.length()) test += tmp[test.length()]; while (test.length() < tmp.length()) { diff --git a/src/frontends/controllers/ControlSpellchecker.C b/src/frontends/controllers/ControlSpellchecker.C index 9aa770f043..4955ab8677 100644 --- a/src/frontends/controllers/ControlSpellchecker.C +++ b/src/frontends/controllers/ControlSpellchecker.C @@ -16,12 +16,11 @@ #include "buffer.h" #include "bufferparams.h" #include "BufferView.h" -#include "bufferview_funcs.h" +#include "cursor.h" #include "debug.h" #include "gettext.h" #include "language.h" #include "lyxrc.h" - #include "PosIterator.h" #include "paragraph.h" @@ -235,17 +234,17 @@ void ControlSpellchecker::check() lyxerr[Debug::GUI] << "Found word \"" << word_.word() << "\"" << endl; - if (!word_.word().empty()) { - int const size = word_.word().size(); - advance(cur, -size); - bufferview()->putSelectionAt(cur, size, false); - advance(cur, size); - } else { + if (word_.word().empty()) { showSummary(); endSession(); return; } + int const size = word_.word().size(); + advance(cur, -size); + bufferview()->putSelectionAt(cur, size, false); + advance(cur, size); + // set suggestions if (res != SpellBase::OK && res != SpellBase::IGNORE) { lyxerr[Debug::GUI] << "Found a word needing checking." << endl; @@ -292,7 +291,9 @@ void ControlSpellchecker::showSummary() void ControlSpellchecker::replace(string const & replacement) { - bufferview()->replaceWord(replacement); + bufferview()->cursor().replaceWord(replacement); + bufferview()->buffer()->markDirty(); + bufferview()->update(); // fix up the count --count_; check(); diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index a24d87c6ce..a2c6564b53 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -348,15 +348,14 @@ InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest const & cmd) return lfunMouseRelease(cur, cmd); case LFUN_INSET_TOGGLE: - if (inset.text_.toggleInset()) + if (inset.text_.toggleInset(cur)) return DispatchResult(true, true); if (status_ == Open) { setStatus(Inlined); return DispatchResult(true, true); - } else { - setStatus(Collapsed); - return DispatchResult(false, FINISHED_RIGHT); } + setStatus(Collapsed); + return DispatchResult(false, FINISHED_RIGHT); default: return inset.dispatch(cur, cmd); diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 85c22160ca..374736f4c2 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -52,8 +52,6 @@ #include -using bv_funcs::replaceSelection; - using lyx::pos_type; using lyx::graphics::PreviewLoader; @@ -279,7 +277,7 @@ void InsetText::sanitizeEmptyText(BufferView & bv) && bv.getParentLanguage(this) != text_.current_font.language()) { LyXFont font(LyXFont::ALL_IGNORE); 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) { LyXFont font(LyXFont::ALL_IGNORE); font.setLanguage(cur.bv().getParentLanguage(this)); - text_.setFont(font, false); + text_.setFont(cur, font, false); } //lyxerr << "InsetText::priv_dispatch (end)" << endl; diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 48ac377406..5838b29e14 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -361,9 +361,9 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph) if (bv->text() == bv->getLyXText()) bv->cursor().clearSelection(); if (asParagraph) - bv->getLyXText()->insertStringAsParagraphs(tmpstr); + bv->getLyXText()->insertStringAsParagraphs(bv->cursor(), tmpstr); else - bv->getLyXText()->insertStringAsLines(tmpstr); + bv->getLyXText()->insertStringAsLines(bv->cursor(), tmpstr); bv->update(); } diff --git a/src/lyxfind.C b/src/lyxfind.C index a4fe14d017..710de709ce 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -388,8 +388,8 @@ int replace(BufferView * bv, string const & searchstr, LyXText * text = bv->getLyXText(); - text->replaceSelectionWithString(replacestr); - text->setSelectionRange(replacestr.length()); + text->replaceSelectionWithString(bv->cursor(), replacestr); + text->setSelectionRange(bv->cursor(), replacestr.length()); bv->cursor().current() = fw ? bv->cursor().selEnd() : bv->cursor().selBegin(); bv->buffer()->markDirty(); find(bv, searchstr, cs, mw, fw); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 741375d6f1..87f37ff8c8 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -82,8 +82,6 @@ #include "support/std_sstream.h" #include "support/os.h" -using bv_funcs::changeDepth; -using bv_funcs::currentState; using bv_funcs::DEC_DEPTH; using bv_funcs::freefont2string; 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; Buffer * buf = owner->buffer(); LCursor & cur = view()->cursor(); - if (ev.action == LFUN_NOACTION) { + if (cmd.action == LFUN_NOACTION) { setStatusMessage(N_("Nothing to do")); flag.disabled(true); return flag; } - switch (ev.action) { + switch (cmd.action) { case LFUN_UNKNOWN_ACTION: #ifndef HAVE_LIBAIKSAURUS case LFUN_THESAURUS_ENTRY: @@ -278,7 +276,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const flag.disabled(true); break; default: - flag |= lyx_gui::getStatus(ev); + flag |= lyx_gui::getStatus(cmd); } if (flag.unknown()) { @@ -290,13 +288,13 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const setStatusMessage(N_("Command disabled")); // 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? if (buf) { // yes // Can we use a readonly buffer? if (buf->isReadonly() && - !lyxaction.funcHasFlag(ev.action, + !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)) { // no 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 // encode this in the function itself. bool disable = false; - switch (ev.action) { + switch (cmd.action) { case LFUN_EXPORT: - disable = ev.argument != "custom" - && !Exporter::IsExportable(*buf, ev.argument); + disable = cmd.argument != "custom" + && !Exporter::IsExportable(*buf, cmd.argument); break; case LFUN_UNDO: disable = buf->undostack().empty(); @@ -349,11 +347,11 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const break; case LFUN_DEPTH_MIN: - disable = !changeDepthAllowed(view(), view()->getLyXText(), DEC_DEPTH); + disable = !changeDepthAllowed(cur, view()->getLyXText(), DEC_DEPTH); break; case LFUN_DEPTH_PLUS: - disable = !changeDepthAllowed(view(), view()->getLyXText(), INC_DEPTH); + disable = !changeDepthAllowed(cur, view()->getLyXText(), INC_DEPTH); break; case LFUN_LAYOUT: @@ -377,15 +375,15 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const disable = true; break; } - if (ev.argument.empty()) { + if (cmd.argument.empty()) { flag.clear(); break; } - if (!contains("tcb", ev.argument[0])) { + if (!contains("tcb", cmd.argument[0])) { disable = true; break; } - flag.setOnOff(ev.argument[0] == align); + flag.setOnOff(cmd.argument[0] == align); } else { disable = true; @@ -394,15 +392,15 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const disable = true; break; } - if (ev.argument.empty()) { + if (cmd.argument.empty()) { flag.clear(); break; } - if (!contains("lcr", ev.argument[0])) { + if (!contains("lcr", cmd.argument[0])) { disable = true; break; } - flag.setOnOff(ev.argument[0] == align); + flag.setOnOff(cmd.argument[0] == align); disable = !mathcursor::halign(); break; @@ -413,7 +411,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const //ret.disabled(true); InsetTabular * tab = cur.innerInsetTabular(); if (tab) { - ret = tab->getStatus(ev.argument); + ret = tab->getStatus(cmd.argument); flag |= ret; disable = false; } else { @@ -422,7 +420,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const } else { static InsetTabular inset(*buf, 1, 1); disable = true; - FuncStatus ret = inset.getStatus(ev.argument); + FuncStatus ret = inset.getStatus(cmd.argument); if (ret.onoff(true) || ret.onoff(false)) flag.setOnOff(false); } @@ -447,7 +445,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const break; case LFUN_BOOKMARK_GOTO: disable = !view()-> - isSavedPosition(strToUnsignedInt(ev.argument)); + isSavedPosition(strToUnsignedInt(cmd.argument)); break; case LFUN_MERGE_CHANGES: @@ -474,25 +472,25 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const InsetOld::Code code = inset->lyxCode(); switch (code) { case InsetOld::TABULAR_CODE: - disable = ev.argument != "tabular"; + disable = cmd.argument != "tabular"; break; case InsetOld::ERT_CODE: - disable = ev.argument != "ert"; + disable = cmd.argument != "ert"; break; case InsetOld::FLOAT_CODE: - disable = ev.argument != "float"; + disable = cmd.argument != "float"; break; case InsetOld::WRAP_CODE: - disable = ev.argument != "wrap"; + disable = cmd.argument != "wrap"; break; case InsetOld::NOTE_CODE: - disable = ev.argument != "note"; + disable = cmd.argument != "note"; break; case InsetOld::BRANCH_CODE: - disable = ev.argument != "branch"; + disable = cmd.argument != "branch"; break; case InsetOld::BOX_CODE: - disable = ev.argument != "box"; + disable = cmd.argument != "box"; break; default: break; @@ -502,7 +500,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case LFUN_MATH_MUTATE: if (cur.inMathed()) - //flag.setOnOff(mathcursor::formula()->hullType() == ev.argument); + //flag.setOnOff(mathcursor::formula()->hullType() == cmd.argument); flag.setOnOff(false); else disable = true; @@ -519,7 +517,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const break; case LFUN_DIALOG_SHOW: { - string const name = ev.getArg(0); + string const name = cmd.getArg(0); if (!buf) { disable = !(name == "aboutlyx" || name == "file" || @@ -549,43 +547,43 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const // the functions which insert insets InsetOld::Code code = InsetOld::NO_CODE; - switch (ev.action) { + switch (cmd.action) { case LFUN_DIALOG_SHOW_NEW_INSET: - if (ev.argument == "bibitem") + if (cmd.argument == "bibitem") code = InsetOld::BIBITEM_CODE; - else if (ev.argument == "bibtex") + else if (cmd.argument == "bibtex") code = InsetOld::BIBTEX_CODE; - else if (ev.argument == "box") + else if (cmd.argument == "box") code = InsetOld::BOX_CODE; - else if (ev.argument == "branch") + else if (cmd.argument == "branch") code = InsetOld::BRANCH_CODE; - else if (ev.argument == "citation") + else if (cmd.argument == "citation") code = InsetOld::CITE_CODE; - else if (ev.argument == "ert") + else if (cmd.argument == "ert") code = InsetOld::ERT_CODE; - else if (ev.argument == "external") + else if (cmd.argument == "external") code = InsetOld::EXTERNAL_CODE; - else if (ev.argument == "float") + else if (cmd.argument == "float") code = InsetOld::FLOAT_CODE; - else if (ev.argument == "graphics") + else if (cmd.argument == "graphics") code = InsetOld::GRAPHICS_CODE; - else if (ev.argument == "include") + else if (cmd.argument == "include") code = InsetOld::INCLUDE_CODE; - else if (ev.argument == "index") + else if (cmd.argument == "index") code = InsetOld::INDEX_CODE; - else if (ev.argument == "label") + else if (cmd.argument == "label") code = InsetOld::LABEL_CODE; - else if (ev.argument == "note") + else if (cmd.argument == "note") code = InsetOld::NOTE_CODE; - else if (ev.argument == "ref") + else if (cmd.argument == "ref") code = InsetOld::REF_CODE; - else if (ev.argument == "toc") + else if (cmd.argument == "toc") code = InsetOld::TOC_CODE; - else if (ev.argument == "url") + else if (cmd.argument == "url") code = InsetOld::URL_CODE; - else if (ev.argument == "vspace") + else if (cmd.argument == "vspace") code = InsetOld::VSPACE_CODE; - else if (ev.argument == "wrap") + else if (cmd.argument == "wrap") code = InsetOld::WRAP_CODE; break; @@ -700,7 +698,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const flag.disabled(true); // A few general toggles - switch (ev.action) { + switch (cmd.action) { case LFUN_TOOLTIPS_TOGGLE: flag.setOnOff(owner->getDialogs().tooltipsEnabled()); break; @@ -715,7 +713,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case LFUN_SWITCHBUFFER: // toggle on the current buffer, but do not toggle off // the other ones (is that a good idea?) - if (ev.argument == buf->fileName()) + if (cmd.argument == buf->fileName()) flag.setOnOff(true); break; case LFUN_TRACK_CHANGES: @@ -729,7 +727,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const // the font related toggles if (cur.inTexted()) { LyXFont const & font = cur.text()->real_current_font; - switch (ev.action) { + switch (cmd.action) { case LFUN_EMPH: flag.setOnOff(font.emph() == LyXFont::ON); break; @@ -753,7 +751,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const } } else { string tc = mathcursor::getLastCode(); - switch (ev.action) { + switch (cmd.action) { case LFUN_BOLD: flag.setOnOff(tc == "mathbf"); break; @@ -783,10 +781,11 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const // this one is difficult to get right. As a half-baked // solution, we consider only the first action of the sequence - if (ev.action == LFUN_SEQUENCE) { + if (cmd.action == LFUN_SEQUENCE) { // argument contains ';'-terminated commands #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; @@ -1750,7 +1749,7 @@ string const LyXFunc::view_status_message() if (!view()->available()) return _("Welcome to LyX!"); - return currentState(view()); + return view()->cursor().currentState(); } diff --git a/src/lyxtext.h b/src/lyxtext.h index 4ae7bedd25..75d8714034 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -79,22 +79,19 @@ public: ParagraphList::iterator end, 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) - void changeDepth(bv_funcs::DEPTH_CHANGE type); + void changeDepth(LCursor & cur, bv_funcs::DEPTH_CHANGE type); /// 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 int getDepth() const; - /** set font over selection and make a total rebreak of those - paragraphs. - toggleall defaults to false. - */ - void setFont(LyXFont const &, bool toggleall = false); + /// Set font over selection paragraphs and rebreak. + void setFont(LCursor & cur, LyXFont const &, bool toggleall = false); /// rebreaks all paragaphs between the given pars. void redoParagraphs(ParagraphList::iterator begin, @@ -102,18 +99,18 @@ public: /// rebreaks the given par void redoParagraph(ParagraphList::iterator pit); /// 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 - void insertChar(char c); + void insertChar(LCursor & cur, char c); /// insert an inset at cursor position - void insertInset(InsetBase * inset); + void insertInset(LCursor & cur, InsetBase * inset); /// a full rebreak of the whole text void fullRebreak(); @@ -137,10 +134,10 @@ public: ParagraphList::iterator getPar(lyx::paroffset_type par) const; /// int parOffset(ParagraphList::iterator pit) const; - /// convenience + /// # FIXME: should not be used ParagraphList::iterator cursorPar() const; - /// - RowList::iterator cursorRow() const; + // Returns the current font and depth as a message. + std::string LyXText::currentState(LCursor & cur); /** returns an iterator pointing to the row near the specified * 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); /// 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 - void acceptChange(); + void acceptChange(LCursor & cur); /// reject selected change - void rejectChange(); + void rejectChange(LCursor & cur); /// returns true if par was empty and was removed bool setCursor(lyx::paroffset_type par, lyx::pos_type pos, @@ -224,7 +221,7 @@ public: /// void backspace(LCursor & cur); /// - bool selectWordWhenUnderCursor(lyx::word_location); + bool selectWordWhenUnderCursor(LCursor & cur, lyx::word_location); /// enum TextCase { /// @@ -235,16 +232,16 @@ public: text_uppercase = 2 }; /// Change the case of the word at cursor position. - void changeCase(TextCase action); + void changeCase(LCursor & cur, TextCase action); /// returns success - bool toggleInset(); + bool toggleInset(LCursor & cur); /// void cutSelection(bool doclear = true, bool realcut = true); /// 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 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 * characters to the right. No safety checks. */ - void setSelectionRange(lyx::pos_type length); - /** simple replacing. The font of the first selected character - is used - */ - void replaceSelectionWithString(std::string const & str); + void setSelectionRange(LCursor & cur, lyx::pos_type length); + /// simply replace using the font of the first selected character + void replaceSelectionWithString(LCursor & cur, std::string const & str); + /// replace selection helper + void replaceSelection(LCursor & cur); /// needed to insert the selection - void insertStringAsLines(std::string const & str); + void insertStringAsLines(LCursor & cur, std::string const & str); /// 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. bool gotoNextInset(std::vector const & codes, diff --git a/src/paper.h b/src/paper.h index 8cac625ea6..03a771d160 100644 --- a/src/paper.h +++ b/src/paper.h @@ -15,25 +15,25 @@ #ifndef PAPER_H #define PAPER_H - /// - enum PAPER_SIZE { - /// - PAPER_DEFAULT, - /// - PAPER_USLETTER, - /// - PAPER_LEGALPAPER, - /// - PAPER_EXECUTIVEPAPER, - /// - PAPER_A3PAPER, - /// - PAPER_A4PAPER, - /// - PAPER_A5PAPER, - /// - PAPER_B5PAPER - }; +/// +enum PAPER_SIZE { + /// + PAPER_DEFAULT, + /// + PAPER_USLETTER, + /// + PAPER_LEGALPAPER, + /// + PAPER_EXECUTIVEPAPER, + /// + PAPER_A3PAPER, + /// + PAPER_A4PAPER, + /// + PAPER_A5PAPER, + /// + PAPER_B5PAPER +}; /// enum PAPER_PACKAGES { diff --git a/src/text.C b/src/text.C index 9f67a17c3b..b58a24c8cb 100644 --- a/src/text.C +++ b/src/text.C @@ -18,6 +18,7 @@ #include "lyxtext.h" +#include "author.h" #include "buffer.h" #include "bufferparams.h" #include "BufferView.h" @@ -50,10 +51,13 @@ #include "support/lstrings.h" #include "support/textutils.h" +#include "support/tostr.h" +#include "support/std_sstream.h" using lyx::pos_type; using lyx::word_location; +using lyx::support::bformat; using lyx::support::contains; using lyx::support::lowercase; using lyx::support::uppercase; @@ -834,25 +838,26 @@ void LyXText::breakParagraph(LCursor & cur, char keep_layout) // convenience function -void LyXText::redoParagraph() +void LyXText::redoParagraph(LCursor & cur) { - bv()->cursor().clearSelection(); - redoParagraph(cursorPar()); - setCursorIntern(cursor().par(), cursor().pos()); + cur.clearSelection(); + redoParagraph(getPar(cur.par())); + setCursorIntern(cur.par(), cur.pos()); } // insert a character, moves all the following breaks in the // 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, - // disable the double-space checking + Paragraph & par = cur.paragraph(); + // try to remove this + ParagraphList::iterator pit = getPar(cur.par()); - bool const freeSpacing = cursorPar()->layout()->free_spacing || - cursorPar()->isFreeSpacing(); + bool const freeSpacing = par.layout()->free_spacing || + par.isFreeSpacing(); if (lyxrc.auto_number) { static string const number_operators = "+-/*"; @@ -862,36 +867,28 @@ void LyXText::insertChar(char c) if (current_font.number() == LyXFont::ON) { if (!IsDigit(c) && !contains(number_operators, c) && !(contains(number_seperators, c) && - cursor().pos() >= 1 && - cursor().pos() < cursorPar()->size() && - getFont(cursorPar(), cursor().pos()).number() == LyXFont::ON && - getFont(cursorPar(), cursor().pos() - 1).number() == LyXFont::ON) + cur.pos() != 0 && + cur.pos() != cur.lastpos() && + getFont(pit, cur.pos()).number() == LyXFont::ON && + getFont(pit, cur.pos() - 1).number() == LyXFont::ON) ) number(); // Set current_font.number to OFF } else if (IsDigit(c) && real_current_font.isVisibleRightToLeft()) { number(); // Set current_font.number to ON - if (cursor().pos() > 0) { - char const c = cursorPar()->getChar(cursor().pos() - 1); + if (cur.pos() != 0) { + char const c = par.getChar(cur.pos() - 1); if (contains(number_unary_operators, c) && - (cursor().pos() == 1 || - cursorPar()->isSeparator(cursor().pos() - 2) || - cursorPar()->isNewline(cursor().pos() - 2)) + (cur.pos() == 1 + || par.isSeparator(cur.pos() - 2) + || par.isNewline(cur.pos() - 2)) ) { - setCharFont( - cursorPar(), - cursor().pos() - 1, - current_font); - } else if (contains(number_seperators, c) && - cursor().pos() >= 2 && - getFont( - cursorPar(), - cursor().pos() - 2).number() == LyXFont::ON) { - setCharFont( - cursorPar(), - cursor().pos() - 1, - current_font); + setCharFont(pit, cur.pos() - 1, current_font); + } else if (contains(number_seperators, c) + && cur.pos() >= 2 + && getFont(pit, cur.pos() - 2).number() == LyXFont::ON) { + setCharFont(pit, cur.pos() - 1, current_font); } } } @@ -913,36 +910,41 @@ void LyXText::insertChar(char c) LyXFont realtmpfont = real_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 ((cursor().pos() > 0 - && cursorPar()->isLineSeparator(cursor().pos() - 1)) - || (cursor().pos() > 0 - && cursorPar()->isNewline(cursor().pos() - 1)) - || (cursor().pos() == 0)) { + if (cur.pos() == 0) { static bool sent_space_message = false; if (!sent_space_message) { - if (cursor().pos() == 0) - bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial.")); - else - bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial.")); + cur.message(_("You cannot insert a space at the " + "beginning of a paragraph. Please read the Tutorial.")); + sent_space_message = true; + 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; } - charInserted(); return; } } // Here case LyXText::InsertInset already inserted the character 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; real_current_font = realtmpfont; - redoParagraph(cursorPar()); - setCursor(cursor().par(), cursor().pos() + 1, false, cursor().boundary()); - + redoParagraph(cur); + setCursor(cur.par(), cur.pos() + 1, false, cur.boundary()); 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 to = cursor(); + CursorSlice from = cur.current(); + CursorSlice to = cur.current(); getWord(from, to, loc); - if (cursor() != from) + if (cur.current() != from) setCursor(from.par(), from.pos()); if (to == from) return; - bv()->cursor().resetAnchor(); + cur.resetAnchor(); setCursor(to.par(), to.pos()); - bv()->cursor().setSelection(); + cur.setSelection(); } // Select the word currently under the cursor when no // 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; - selectWord(loc); - return bv()->cursor().selection(); + selectWord(cur, loc); + return cur.selection(); } -void LyXText::acceptChange() +void LyXText::acceptChange(LCursor & cur) { - LCursor & cur = bv()->cursor(); - if (!cur.selection() && cursorPar()->size()) + if (!cur.selection() && cur.lastpos() != 0) return; - if (cur.selBegin().par() == cur.par()) { - CursorSlice const & startc = cur.selBegin(); - CursorSlice const & endc = cur.selEnd(); - recordUndo(cur, Undo::INSERT, cur.anchor().par()); + CursorSlice const & startc = cur.selBegin(); + CursorSlice const & endc = cur.selEnd(); + if (startc.par() == endc.par()) { + recordUndoSelection(cur, Undo::INSERT); getPar(startc)->acceptChange(startc.pos(), endc.pos()); finishUndo(); cur.clearSelection(); @@ -1163,16 +1164,15 @@ void LyXText::acceptChange() } -void LyXText::rejectChange() +void LyXText::rejectChange(LCursor & cur) { - LCursor & cur = bv()->cursor(); - if (!cur.selection() && cursorPar()->size()) + if (!cur.selection() && cur.lastpos() != 0) return; - if (cur.selBegin().par() == cur.selEnd().par()) { - CursorSlice const & startc = cur.selBegin(); - CursorSlice const & endc = cur.selEnd(); - recordUndo(cur, Undo::INSERT, cur.anchor().par()); + CursorSlice const & startc = cur.selBegin(); + CursorSlice const & endc = cur.selEnd(); + if (startc.par() == endc.par()) { + recordUndoSelection(cur, Undo::INSERT); getPar(startc)->rejectChange(startc.pos(), endc.pos()); finishUndo(); 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 to; @@ -1248,7 +1247,7 @@ void LyXText::changeCase(LyXText::TextCase action) setCursor(to.par(), to.pos() + 1); } - recordUndo(cur, Undo::ATOMIC, cur.anchor().par()); + recordUndoSelection(cur); pos_type pos = from.pos(); int par = from.par(); @@ -1298,23 +1297,21 @@ void LyXText::Delete(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) { // The cursor is at the beginning of a paragraph, so // the the backspace will collapse two paragraphs into // one. // 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; // we may paste some paragraphs // 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 // by moving the cursor one step // left and let the DeleteEmptyParagraphMechanism @@ -1323,7 +1320,7 @@ void LyXText::backspace(LCursor & cur) if (cur.par() != 0) { cursorLeft(cur, true); // the layout things can change the height of a row ! - redoParagraph(); + redoParagraph(cur); return; } } @@ -1331,7 +1328,7 @@ void LyXText::backspace(LCursor & cur) if (cur.par() != 0) 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 // not a good idea since it triggers the auto-delete // mechanism. So we do a cursorLeftIntern()-lite, @@ -1350,7 +1347,7 @@ void LyXText::backspace(LCursor & cur) Buffer & buf = *bv()->buffer(); BufferParams const & bufparams = buf.params(); LyXTextClass const & tclass = bufparams.getLyXTextClass(); - ParagraphList::iterator const cpit = cursorPar(); + ParagraphList::iterator const cpit = getPar(cur.par()); if (cpit != tmppit && (cpit->layout() == tmppit->layout() @@ -1381,7 +1378,7 @@ void LyXText::backspace(LCursor & cur) if (cur.pos() == cur.lastpos()) setCurrentFont(); - redoParagraph(); + redoParagraph(cur); 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 { return getPar(cur.par()); @@ -1861,3 +1852,89 @@ CursorSlice const & LyXText::cursor() const } 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(); +} diff --git a/src/text2.C b/src/text2.C index 7f7fc1d498..7837ee7831 100644 --- a/src/text2.C +++ b/src/text2.C @@ -279,7 +279,7 @@ LyXText::setLayout(ParagraphList::iterator start, // 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 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_CUT)); InsetBase * inset = new InsetEnvironment(params, layout); - insertInset(inset); + insertInset(cur, inset); //inset->edit(bv()); //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE)); return; } - ParagraphList::iterator start = - getPar(bv()->cursor().selBegin().par()); - ParagraphList::iterator end = - boost::next(getPar(bv()->cursor().selEnd().par())); + ParagraphList::iterator start = getPar(cur.selBegin().par()); + ParagraphList::iterator end = boost::next(getPar(cur.selEnd().par())); ParagraphList::iterator endpit = setLayout(start, end, layout); - redoParagraphs(start, endpit); updateCounters(); } @@ -311,16 +308,16 @@ void LyXText::setLayout(string const & layout) namespace { -void getSelectionSpan(LyXText & text, +void getSelectionSpan(LCursor & cur, LyXText & text, ParagraphList::iterator & beg, ParagraphList::iterator & end) { - if (!text.bv()->cursor().selection()) { - beg = text.cursorPar(); + if (!cur.selection()) { + beg = text.getPar(cur.par()); end = boost::next(beg); } else { - beg = text.getPar(text.bv()->cursor().selBegin()); - end = boost::next(text.getPar(text.bv()->cursor().selEnd())); + beg = text.getPar(cur.selBegin()); + 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; - getSelectionSpan(*this, beg, end); + getSelectionSpan(cur, *this, beg, end); int max_depth = 0; if (beg != paragraphs().begin()) 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; - getSelectionSpan(*this, beg, end); - - recUndo(parOffset(beg), parOffset(end) - 1); + getSelectionSpan(cur, *this, beg, end); + recordUndoSelection(cur); int max_depth = 0; 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 -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 (!cur.selection()) { // Determine basis font LyXFont layoutfont; - if (cursor().pos() < cursorPar()->beginOfBody()) - layoutfont = getLabelFont(cursorPar()); + ParagraphList::iterator pit = getPar(cur.par()); + if (cur.pos() < pit->beginOfBody()) + layoutfont = getLabelFont(pit); else - layoutfont = getLayoutFont(cursorPar()); + layoutfont = getLayoutFont(pit); // Update current font real_current_font.update(font, @@ -415,7 +411,7 @@ void LyXText::setFont(LyXFont const & font, bool toggleall) } // ok we have a selection. - recUndo(cur.selBegin().par(), cur.selEnd().par()); + recordUndoSelection(cur); freezeUndo(); 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 (font == LyXFont(LyXFont::ALL_IGNORE)) { // 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.")); return; } @@ -481,45 +477,44 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall) // Try implicit word selection // If there is a change in the language the implicit word selection // is disabled. - CursorSlice resetCursor = cursor(); + CursorSlice resetCursor = cur.current(); bool implicitSelection = font.language() == ignore_language && font.number() == LyXFont::IGNORE - && selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT); + && selectWordWhenUnderCursor(cur, lyx::WHOLE_WORD_STRICT); // Set font - setFont(font, toggleall); + setFont(cur, font, toggleall); // Implicit selections are cleared afterwards - //and cursor is set to the original position. + // and cursor is set to the original position. if (implicitSelection) { - bv()->cursor().clearSelection(); - cursor() = resetCursor; - bv()->cursor().resetAnchor(); + cur.clearSelection(); + cur.current() = resetCursor; + cur.resetAnchor(); } } -string LyXText::getStringToIndex() +string LyXText::getStringToIndex(LCursor & cur) { - LCursor & cur = bv()->cursor(); // Try implicit word selection // If there is a change in the language the implicit word selection // is disabled. - CursorSlice const reset_cursor = cursor(); + CursorSlice const reset_cursor = cur.current(); bool const implicitSelection = - selectWordWhenUnderCursor(lyx::PREVIOUS_WORD); + selectWordWhenUnderCursor(cur, lyx::PREVIOUS_WORD); string idxstring; if (!cur.selection()) - bv()->owner()->message(_("Nothing to index!")); + cur.message(_("Nothing to index!")); 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 idxstring = cur.selectionAsString(false); // Reset cursors to their original position. - cursor() = reset_cursor; + cur.current() = reset_cursor; cur.resetAnchor(); // 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())) - return; - - recUndo(cursor().par()); + recordUndo(cur); freezeUndo(); - cursorPar()->insertInset(cursor().pos(), inset); + cur.paragraph().insertInset(cur.pos(), inset); // Just to rebreak and refresh correctly. // 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 // the inset. After an undo LyX tries to call inset->edit(...) // and fails if the cursor is behind the inset and getInset // does not return the inset! if (isHighlyEditableInset(inset)) - cursorLeft(bv()->cursor(), true); - + cursorLeft(cur, true); unFreezeUndo(); } @@ -902,10 +893,10 @@ void LyXText::cutSelection(bool doclear, bool realcut) // and cur.selEnd() // make sure that the depth behind the selection are restored, too + recordUndoSelection(cur); ParagraphList::iterator begpit = getPar(cur.selBegin().par()); ParagraphList::iterator endpit = getPar(cur.selEnd().par()); ParagraphList::iterator undopit = undoSpan(endpit); - recUndo(cur.selBegin().par(), parOffset(undopit) - 1); int endpos = cur.selEnd().pos(); @@ -913,7 +904,7 @@ void LyXText::cutSelection(bool doclear, bool realcut) boost::tie(endpit, endpos) = realcut ? CutAndPaste::cutSelection(bufparams, paragraphs(), - begpit , endpit, + begpit, endpit, cur.selBegin().pos(), endpos, bufparams.textclass, doclear) @@ -930,8 +921,8 @@ void LyXText::cutSelection(bool doclear, bool realcut) // cutSelection can invalidate the cursor so we need to set // it anew. (Lgb) // we prefer the end for when tracking changes - cursor().pos(endpos); - cursor().par(parOffset(endpit)); + cur.pos() = endpos; + cur.par() = parOffset(endpit); // need a valid cursor. (Lgb) 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 if (!CutAndPaste::checkPastePossible()) return; - recUndo(cursor().par()); + recordUndo(cur); ParagraphList::iterator endpit; 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) return; - - LCursor & cur = bv()->cursor(); cur.resetAnchor(); while (length--) 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 -void LyXText::replaceSelectionWithString(string const & str) +void LyXText::replaceSelectionWithString(LCursor & cur, string const & str) { - LCursor & cur = bv()->cursor(); - recUndo(cur.par()); + recordUndo(cur); freezeUndo(); // Get font setting before we cut @@ -1042,34 +1029,32 @@ void LyXText::replaceSelectionWithString(string const & str) // 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 = cursorPar(); + ParagraphList::iterator pit = getPar(cur.par()); + ParagraphList::iterator endpit = boost::next(pit); pos_type pos = cursor().pos(); - ParagraphList::iterator endpit = boost::next(cursorPar()); - recordUndo(cur, Undo::ATOMIC); + recordUndo(cur); // only to be sure, should not be neccessary cur.clearSelection(); bv()->buffer()->insertStringAsLines(pit, pos, current_font, str); - redoParagraphs(cursorPar(), endpit); + redoParagraphs(getPar(cur.par()), endpit); cur.resetAnchor(); - setCursor(parOffset(pit), pos); + setCursor(cur.par(), pos); cur.setSelection(); } // turn double CR to single CR, others are converted into one // 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; - 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 (newline_inserted) { // we know that \r will be ignored by @@ -1085,7 +1070,7 @@ void LyXText::insertStringAsParagraphs(string const & str) newline_inserted = false; } } - insertStringAsLines(linestr); + insertStringAsLines(cur, linestr); } @@ -1197,6 +1182,7 @@ void LyXText::setCurrentFont() } } + // x is an absolute screen coord // returns the column near the specified x-coordinate of the row // 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) { - Row const & row = *cursorRow(); + Row const & row = cur.textRow(); int x = cur.x_target(); int y = cursorY(cur.current()) - row.baseline() - 1; 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? if (!isEditableInset(inset)) return false; - //bv()->owner()->message(inset->editMessage()); + cur.message(inset->editMessage()); // do we want to keep this?? (JMarc) if (!isHighlyEditableInset(inset)) - recUndo(cursor().par()); + recordUndo(cur); if (inset->isOpen()) inset->close(); diff --git a/src/text3.C b/src/text3.C index 6cb46638eb..7c99fc6775 100644 --- a/src/text3.C +++ b/src/text3.C @@ -57,9 +57,6 @@ #include - -using bv_funcs::replaceSelection; - using lyx::pos_type; using lyx::support::isStrUnsignedInt; @@ -88,28 +85,26 @@ namespace { bool toggleall = false; - void toggleAndShow(BufferView * bv, LyXText * text, + void toggleAndShow(LCursor & cur, LyXText * text, LyXFont const & font, bool toggleall = true) { - if (!bv->available()) + if (!cur.bv().available()) return; - text->toggleFree(font, toggleall); - bv->update(); + text->toggleFree(cur, font, toggleall); if (font.language() != ignore_language || font.number() != LyXFont::IGNORE) { - CursorSlice & cur = text->cursor(); - Paragraph & par = *text->cursorPar(); - text->bidi.computeTables(par, *bv->buffer(), - *par.getRow(cur.pos())); + Paragraph & par = cur.paragraph(); + text->bidi.computeTables(par, *cur.bv().buffer(), cur.textRow()); if (cur.boundary() != - text->bidi.isBoundary(*bv->buffer(), par, + text->bidi.isBoundary(*cur.bv().buffer(), par, cur.pos(), text->real_current_font)) text->setCursor(cur.par(), cur.pos(), false, !cur.boundary()); } + cur.bv().update(); } @@ -271,10 +266,10 @@ void LyXText::gotoInset(vector const & codes, bool same_content) cur.pos() = 0; if (!gotoNextInset(codes, contents)) { cursor() = tmp; - cur.bv().owner()->message(_("No more insets")); + cur.message(_("No more insets")); } } else { - cur.bv().owner()->message(_("No more insets")); + cur.message(_("No more insets")); } } cur.bv().update(); @@ -330,30 +325,31 @@ void LyXText::cursorNext(LCursor & cur) namespace { -void specialChar(LyXText * text, BufferView * bv, InsetSpecialChar::Kind kind) +void specialChar(LCursor & cur, LyXText * text, BufferView * bv, + InsetSpecialChar::Kind kind) { bv->update(); - replaceSelection(text); - text->insertInset(new InsetSpecialChar(kind)); + text->replaceSelection(cur); + cur.insert(new InsetSpecialChar(kind)); bv->update(); } -void doInsertInset(LyXText * text, BufferView * bv, FuncRequest const & cmd, - bool edit, bool pastesel) +void doInsertInset(LCursor & cur, LyXText * text, BufferView * bv, + FuncRequest const & cmd, bool edit, bool pastesel) { InsetBase * inset = createInset(bv, cmd); if (!inset) return; bool gotsel = false; - if (bv->cursor().selection()) { + if (cur.selection()) { bv->owner()->dispatch(FuncRequest(LFUN_CUT)); gotsel = true; } - text->insertInset(inset); + text->insertInset(cur, inset); if (edit) - inset->edit(bv->cursor(), true); + inset->edit(cur, true); if (gotsel && pastesel) bv->owner()->dispatch(FuncRequest(LFUN_PASTE)); } @@ -365,7 +361,7 @@ void LyXText::number() { LyXFont font(LyXFont::ALL_IGNORE); 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) { case LFUN_APPENDIX: { - ParagraphList::iterator pit = cursorPar(); - bool start = !pit->params().startOfAppendix(); + Paragraph & par = cur.paragraph(); + bool start = !par.params().startOfAppendix(); // ensure that we have only one start_of_appendix in this document ParagraphList::iterator tmp = paragraphs().begin(); @@ -401,12 +397,12 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) } } - recUndo(parOffset(pit)); - pit->params().startOfAppendix(start); + recordUndo(cur); + par.params().startOfAppendix(start); // we can set the refreshing parameters now updateCounters(); - redoParagraph(cursorPar()); + redoParagraph(cur); bv->update(); break; } @@ -560,7 +556,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) break; case LFUN_WORDSEL: { - selectWord(lyx::WHOLE_WORD); + selectWord(cur, lyx::WHOLE_WORD); finishChange(cur, true); break; } @@ -630,9 +626,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_BREAKLINE: { // Not allowed by LaTeX (labels or empty par) - if (cursor().pos() > cursorPar()->beginOfBody()) { - replaceSelection(this); - insertInset(new InsetNewline); + if (cur.pos() > cur.paragraph().beginOfBody()) { + replaceSelection(cur); + cur.insert(new InsetNewline); moveCursor(cur, false); } break; @@ -697,7 +693,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) break; case LFUN_BREAKPARAGRAPH: - replaceSelection(this); + replaceSelection(cur); breakParagraph(cur, 0); bv->update(); cur.resetAnchor(); @@ -706,7 +702,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) break; case LFUN_BREAKPARAGRAPHKEEPLAYOUT: - replaceSelection(this); + replaceSelection(cur); breakParagraph(cur, 1); bv->update(); cur.resetAnchor(); @@ -719,7 +715,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) // indentation and add a "defskip" at the top. // Otherwise, do the same as LFUN_BREAKPARAGRAPH. #warning look here - replaceSelection(this); + replaceSelection(cur); if (cur.pos() == 0) { ParagraphParameters & params = cur.paragraph().params(); setParagraph( @@ -772,7 +768,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) } if (cur_spacing != new_spacing || cur_value != new_value) { par.params().spacing(Spacing(new_spacing, new_value)); - redoParagraph(); + redoParagraph(cur); bv->update(); } break; @@ -791,7 +787,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_INSET_INSERT: { InsetBase * inset = createInset(bv, cmd); if (inset) - insertInset(inset); + insertInset(cur, inset); break; } @@ -802,69 +798,69 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_INSET_TOGGLE: cur.clearSelection(); - if (!toggleInset()) + if (!toggleInset(cur)) return DispatchResult(false); bv->update(); bv->switchKeyMap(); break; case LFUN_SPACE_INSERT: - if (cursorPar()->layout()->free_spacing) - insertChar(' '); + if (cur.paragraph().layout()->free_spacing) + insertChar(cur, ' '); else - doInsertInset(this, bv, cmd, false, false); + doInsertInset(cur, this, bv, cmd, false, false); moveCursor(cur, false); break; case LFUN_HYPHENATION: - specialChar(this, bv, InsetSpecialChar::HYPHENATION); + specialChar(cur, this, bv, InsetSpecialChar::HYPHENATION); break; case LFUN_LIGATURE_BREAK: - specialChar(this, bv, InsetSpecialChar::LIGATURE_BREAK); + specialChar(cur, this, bv, InsetSpecialChar::LIGATURE_BREAK); break; case LFUN_LDOTS: - specialChar(this, bv, InsetSpecialChar::LDOTS); + specialChar(cur, this, bv, InsetSpecialChar::LDOTS); break; case LFUN_END_OF_SENTENCE: - specialChar(this, bv, InsetSpecialChar::END_OF_SENTENCE); + specialChar(cur, this, bv, InsetSpecialChar::END_OF_SENTENCE); break; case LFUN_MENU_SEPARATOR: - specialChar(this, bv, InsetSpecialChar::MENU_SEPARATOR); + specialChar(cur, this, bv, InsetSpecialChar::MENU_SEPARATOR); break; case LFUN_UPCASE_WORD: - changeCase(LyXText::text_uppercase); + changeCase(cur, LyXText::text_uppercase); bv->update(); break; case LFUN_LOWCASE_WORD: - changeCase(LyXText::text_lowercase); + changeCase(cur, LyXText::text_lowercase); bv->update(); break; case LFUN_CAPITALIZE_WORD: - changeCase(LyXText::text_capitalization); + changeCase(cur, LyXText::text_capitalization); bv->update(); break; case LFUN_TRANSPOSE_CHARS: - recUndo(cursor().par()); - redoParagraph(); + recordUndo(cur); + redoParagraph(cur); bv->update(); break; case LFUN_PASTE: cur.message(_("Paste")); - replaceSelection(this); + replaceSelection(cur); #warning FIXME Check if the arg is in the domain of available selections. if (isStrUnsignedInt(cmd.argument)) - pasteSelection(strToUnsignedInt(cmd.argument)); + pasteSelection(cur, strToUnsignedInt(cmd.argument)); else - pasteSelection(0); + pasteSelection(cur, 0); cur.clearSelection(); // bug 393 bv->update(); bv->switchKeyMap(); @@ -928,7 +924,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) break; case LFUN_GETLAYOUT: - cur.message(cursorPar()->layout()->name()); + cur.message(cur.paragraph().layout()->name()); break; case LFUN_LAYOUT: { @@ -982,7 +978,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) if (change_layout) { current_layout = layout; - setLayout(layout); + setLayout(cur, layout); bv->owner()->setLayout(layout); bv->update(); bv->switchKeyMap(); @@ -995,9 +991,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) string const clip = bv->getClipboard(); if (!clip.empty()) { if (cmd.argument == "paragraph") - insertStringAsParagraphs(clip); + insertStringAsParagraphs(cur, clip); else - insertStringAsLines(clip); + insertStringAsLines(cur, clip); bv->update(); } break; @@ -1020,30 +1016,30 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) } case LFUN_QUOTE: { - replaceSelection(this); - ParagraphList::iterator pit = cursorPar(); - lyx::pos_type pos = cursor().pos(); + replaceSelection(cur); + Paragraph & par = cur.paragraph(); + lyx::pos_type pos = cur.pos(); char c; - if (!pos) + if (pos == 0) c = ' '; - else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace()) + else if (cur.prevInset() && cur.prevInset()->isSpace()) c = ' '; 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(); if (style->pass_thru || - pit->getFontSettings(bufparams,pos).language()->lang() == "hebrew") - insertInset(new InsetQuotes(c, bufparams)); + par.getFontSettings(bufparams, pos).language()->lang() == "hebrew") + cur.insert(new InsetQuotes(c, bufparams)); else bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\"")); break; } case LFUN_DATE_INSERT: { - replaceSelection(this); + replaceSelection(cur); time_t now_time_t = time(NULL); struct tm * now_tm = localtime(&now_time_t); setlocale(LC_TIME, ""); @@ -1057,7 +1053,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) ::strftime(datetmp, 32, arg.c_str(), now_tm); for (int i = 0; i < datetmp_len; i++) - insertChar(datetmp[i]); + insertChar(cur, datetmp[i]); cur.resetAnchor(); moveCursor(cur, false); @@ -1078,7 +1074,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_MOUSE_DOUBLE: if (cmd.button() == mouse_button::button1) { selection_possible = true; - selectWord(lyx::WHOLE_WORD_STRICT); + selectWord(cur, lyx::WHOLE_WORD_STRICT); bv->haveSelection(cur.selection()); } break; @@ -1095,14 +1091,14 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) "Dispatch: no selection possible\n"; break; } - RowList::iterator cursorrow = cursorRow(); + CursorSlice old = cur.current(); #warning setCursorFromCoordinates(cmd.x, cmd.y); // This is to allow jumping over large insets // 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()) cursorDown(cur, true); else if (cmd.y - bv->top_y() < 0) @@ -1280,12 +1276,12 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_ENVIRONMENT_INSERT: // Open the inset, and move the current selection // inside it. - doInsertInset(this, bv, cmd, true, true); + doInsertInset(cur, this, bv, cmd, true, true); break; case LFUN_INDEX_INSERT: // Just open the inset - doInsertInset(this, bv, cmd, true, false); + doInsertInset(cur, this, bv, cmd, true, false); break; case LFUN_INDEX_PRINT: @@ -1294,16 +1290,16 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_INSERT_LINE: case LFUN_INSERT_PAGEBREAK: // do nothing fancy - doInsertInset(this, bv, cmd, false, false); + doInsertInset(cur, this, bv, cmd, false, false); break; case LFUN_DEPTH_MIN: - bv_funcs::changeDepth(bv, this, bv_funcs::DEC_DEPTH); + changeDepth(cur, bv_funcs::DEC_DEPTH); bv->update(); break; case LFUN_DEPTH_PLUS: - bv_funcs::changeDepth(bv, this, bv_funcs::INC_DEPTH); + changeDepth(cur, bv_funcs::INC_DEPTH); bv->update(); break; @@ -1343,7 +1339,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_EMPH: { LyXFont font(LyXFont::ALL_IGNORE); font.setEmph(LyXFont::TOGGLE); - toggleAndShow(bv, this, font); + toggleAndShow(cur, this, font); bv->owner()->view_state_changed(); break; } @@ -1351,7 +1347,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_BOLD: { LyXFont font(LyXFont::ALL_IGNORE); font.setSeries(LyXFont::BOLD_SERIES); - toggleAndShow(bv, this, font); + toggleAndShow(cur, this, font); bv->owner()->view_state_changed(); break; } @@ -1359,7 +1355,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_NOUN: { LyXFont font(LyXFont::ALL_IGNORE); font.setNoun(LyXFont::TOGGLE); - toggleAndShow(bv, this, font); + toggleAndShow(cur, this, font); bv->owner()->view_state_changed(); break; } @@ -1367,7 +1363,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_CODE: { LyXFont font(LyXFont::ALL_IGNORE); font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good - toggleAndShow(bv, this, font); + toggleAndShow(cur, this, font); bv->owner()->view_state_changed(); break; } @@ -1375,7 +1371,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_SANS: { LyXFont font(LyXFont::ALL_IGNORE); font.setFamily(LyXFont::SANS_FAMILY); - toggleAndShow(bv, this, font); + toggleAndShow(cur, this, font); bv->owner()->view_state_changed(); break; } @@ -1383,14 +1379,14 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_ROMAN: { LyXFont font(LyXFont::ALL_IGNORE); font.setFamily(LyXFont::ROMAN_FAMILY); - toggleAndShow(bv, this, font); + toggleAndShow(cur, this, font); bv->owner()->view_state_changed(); break; } case LFUN_DEFAULT: { LyXFont font(LyXFont::ALL_INHERIT, ignore_language); - toggleAndShow(bv, this, font); + toggleAndShow(cur, this, font); bv->owner()->view_state_changed(); break; } @@ -1398,7 +1394,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_UNDERLINE: { LyXFont font(LyXFont::ALL_IGNORE); font.setUnderbar(LyXFont::TOGGLE); - toggleAndShow(bv, this, font); + toggleAndShow(cur, this, font); bv->owner()->view_state_changed(); break; } @@ -1406,7 +1402,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) case LFUN_FONT_SIZE: { LyXFont font(LyXFont::ALL_IGNORE); font.setLyXSize(cmd.argument); - toggleAndShow(bv, this, font); + toggleAndShow(cur, this, font); bv->owner()->view_state_changed(); break; } @@ -1417,16 +1413,16 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) break; LyXFont font(LyXFont::ALL_IGNORE); font.setLanguage(lang); - toggleAndShow(bv, this, font); + toggleAndShow(cur, this, font); bv->switchKeyMap(); bv->owner()->view_state_changed(); break; } case LFUN_FREEFONT_APPLY: - toggleAndShow(bv, this, freefont, toggleall); + toggleAndShow(cur, this, freefont, toggleall); bv->owner()->view_state_changed(); - bv->owner()->message(_("Character set")); + cur.message(_("Character set")); break; // 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)) { freefont = font; toggleall = toggle; - toggleAndShow(bv, this, freefont, toggleall); + toggleAndShow(cur, this, freefont, toggleall); bv->owner()->view_state_changed(); - bv->owner()->message(_("Character set")); + cur.message(_("Character set")); } break; } @@ -1535,9 +1531,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) breakParagraph(cur); } - setLayout(tclass.defaultLayoutName()); + setLayout(cur, tclass.defaultLayoutName()); setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0); - insertInset(new InsetFloatList(cmd.argument)); + cur.insert(new InsetFloatList(cmd.argument)); unFreezeUndo(); } else { lyxerr << "Non-existent float type: " @@ -1546,6 +1542,33 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) 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: return DispatchResult(false); } diff --git a/src/trans_mgr.C b/src/trans_mgr.C index 297d9db89d..ba9bb1e35f 100644 --- a/src/trans_mgr.C +++ b/src/trans_mgr.C @@ -12,11 +12,16 @@ #include #include "trans_mgr.h" -#include "trans.h" -#include "lyxtext.h" + +#include "BufferView.h" +#include "cursor.h" #include "debug.h" -#include "insets/insetlatexaccent.h" #include "lyxrc.h" +#include "lyxtext.h" +#include "trans.h" + +#include "insets/insetlatexaccent.h" + #include "support/lstrings.h" using lyx::support::split; @@ -260,11 +265,8 @@ void TransManager::TranslateAndInsert(char c, LyXText * text) void TransManager::insertVerbatim(string const & str, LyXText * text) { - string::size_type const l = str.length(); - - for (string::size_type i = 0; i < l; ++i) { - text->insertChar(str[i]); - } + for (string::size_type i = 0, n = str.size(); i < n; ++i) + text->insertChar(text->bv()->cursor(), str[i]); } @@ -282,15 +284,13 @@ void TransManager::insert(string const & str, LyXText * text) // Could not find an encoding InsetLatexAccent ins(str); if (ins.canDisplay()) { - text->insertInset( - new InsetLatexAccent(ins)); + text->bv()->cursor().insert(new InsetLatexAccent(ins)); } else { insertVerbatim(str, text); } return; } - string tmp; - tmp += static_cast(enc.second); + string const tmp(1, static_cast(enc.second)); insertVerbatim(tmp, text); } diff --git a/src/undo.C b/src/undo.C index 5c44ed5459..2f32fe663a 100644 --- a/src/undo.C +++ b/src/undo.C @@ -186,7 +186,9 @@ bool performUndoOrRedo(BufferView & bv, Undo const & undo) text->updateCounters(); // 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); 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) { recordUndo(kind, cur, cur.par(), from); diff --git a/src/undo.h b/src/undo.h index 07f177fe36..dfa93d440d 100644 --- a/src/undo.h +++ b/src/undo.h @@ -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 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 void recordUndoFullDocument(LCursor & cur);