From 46b37aa369f0f0d7bd541454885d57989d0ca4e3 Mon Sep 17 00:00:00 2001 From: Dekel Tsur Date: Mon, 15 Jan 2001 18:54:31 +0000 Subject: [PATCH] Replace gotoNote/gotoError by gotoInset git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1338 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 6 ------ src/BufferView.h | 7 ++++--- src/BufferView2.C | 32 ++++++++++++++++++++++++-------- src/BufferView_pimpl.C | 32 -------------------------------- src/BufferView_pimpl.h | 2 -- src/ChangeLog | 8 ++++++++ src/LyXAction.C | 1 + src/commandtags.h | 1 + src/insets/inseterror.h | 2 +- src/insets/lyxinset.h | 4 +++- src/lyxfunc.C | 13 +++++++++++-- src/lyxtext.h | 9 ++++----- src/text2.C | 35 ++++++++++------------------------- 13 files changed, 67 insertions(+), 85 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index c2bd11863f..5d33f7d764 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -135,12 +135,6 @@ int BufferView::resizeCurrentBuffer() } -void BufferView::gotoError() -{ - pimpl_->gotoError(); -} - - #if 0 void BufferView::enterView() { diff --git a/src/BufferView.h b/src/BufferView.h index b9ca44b8b5..9c791e8894 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -79,7 +79,10 @@ public: /// int resizeCurrentBuffer(); /// - void gotoError(); + void gotoInset(std::vector const & codes, + bool same_content); + /// + void gotoInset(Inset::Code codes, bool same_content); /// void cursorPrevious(LyXText *); /// @@ -137,8 +140,6 @@ public: /// void insertCorrectQuote(); /// - void gotoNote(); - /// bool gotoLabel(string const & label); /// void paste(); diff --git a/src/BufferView2.C b/src/BufferView2.C index 5381ebdfab..734d7c1fbd 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -616,28 +616,38 @@ void BufferView::paste() } -void BufferView::gotoNote() +void BufferView::gotoInset(std::vector const & codes, + bool same_content) { if (!available()) return; hideCursor(); beforeChange(); update(BufferView::SELECT|BufferView::FITCUR); - LyXCursor tmp; - - if (!text->GotoNextNote(this)) { + + string contents; + if (same_content && + text->cursor.par()->GetChar(text->cursor.pos()) == LyXParagraph::META_INSET) { + Inset const * inset = text->cursor.par()->GetInset(text->cursor.pos()); + if (find(codes.begin(), codes.end(), inset->LyxCode()) + != codes.end()) + contents = + static_cast(inset)->getContents(); + } + + if (!text->GotoNextInset(this, codes, contents)) { if (text->cursor.pos() || text->cursor.par() != text->FirstParagraph()) { - tmp = text->cursor; + LyXCursor tmp = text->cursor; text->cursor.par(text->FirstParagraph()); text->cursor.pos(0); - if (!text->GotoNextNote(this)) { + if (!text->GotoNextInset(this, codes, contents)) { text->cursor = tmp; - owner()->getMiniBuffer()->Set(_("No more notes")); + owner()->getMiniBuffer()->Set(_("No more insets")); LyXBell(); } } else { - owner()->getMiniBuffer()->Set(_("No more notes")); + owner()->getMiniBuffer()->Set(_("No more insets")); LyXBell(); } } @@ -646,6 +656,12 @@ void BufferView::gotoNote() } +void BufferView::gotoInset(Inset::Code code, bool same_content) +{ + gotoInset(vector(1, code), same_content); +} + + void BufferView::insertCorrectQuote() { char c; diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index fac6aa8d9d..bd23465081 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -318,38 +318,6 @@ int BufferView::Pimpl::resizeCurrentBuffer() } -void BufferView::Pimpl::gotoError() -{ - if (!screen_) - return; - - screen_->HideCursor(); - bv_->beforeChange(); - update(BufferView::SELECT|BufferView::FITCUR); - LyXCursor tmp; - - if (!bv_->text->GotoNextError(bv_)) { - if (bv_->text->cursor.pos() - || bv_->text->cursor.par() != bv_->text->FirstParagraph()) { - tmp = bv_->text->cursor; - bv_->text->cursor.par(bv_->text->FirstParagraph()); - bv_->text->cursor.pos(0); - if (!bv_->text->GotoNextError(bv_)) { - bv_->text->cursor = tmp; - owner_->getMiniBuffer() - ->Set(_("No more errors")); - LyXBell(); - } - } else { - owner_->getMiniBuffer()->Set(_("No more errors")); - LyXBell(); - } - } - update(BufferView::SELECT|BufferView::FITCUR); - bv_->text->sel_cursor = bv_->text->cursor; -} - - void BufferView::Pimpl::updateScreen() { // Regenerate the screen. diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 7eaef53b6d..70a767788e 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -45,8 +45,6 @@ struct BufferView::Pimpl : public Object { void update(); // void update(BufferView::UpdateCodes); - /// - void gotoError(); /// Update pixmap of screen void updateScreen(); /// diff --git a/src/ChangeLog b/src/ChangeLog index 4e8c6a39ac..c4c65d1e6c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,13 @@ 2001-01-15 Dekel Tsur + * BufferView2.C (gotoInset): New method. Replaces gotoNote() and + gotoError(). + + * text2.C (GotoNextInset): New method. Replaces GotoNextError() + and GotoNextNote(). + + * src/LyXAction.C: Added reference-next. + * text.C (InsertChar): Use contains instead of strchr. * lyx_cb.C (MenuInsertLabel): Enable default value code. diff --git a/src/LyXAction.C b/src/LyXAction.C index 31e60716b4..18d1a1cb5e 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -359,6 +359,7 @@ void LyXAction::init() { LFUN_REF_GOTO, "reference-goto", "", ReadOnly }, { LFUN_REF_INSERT, "reference-insert", N_("Insert cross reference"), ReadOnly }, + { LFUN_REFERENCE_GOTO, "reference-next", "", ReadOnly }, { LFUN_NEXT, "screen-down", "", ReadOnly }, { LFUN_NEXTSEL, "screen-down-select", "", ReadOnly }, { LFUN_SCREEN_FONT_UPDATE, "screen-font-update", diff --git a/src/commandtags.h b/src/commandtags.h index adffe4c210..8b01de9182 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -273,6 +273,7 @@ enum kb_action { LFUN_SCREEN_FONT_UPDATE, // ARRae 20000813 LFUN_DIALOG_TABULAR_INSERT, // 250 // Jug 20000825 (old table-insert) LFUN_GOTO_PARAGRAPH, // Dekel 20000826 + LFUN_REFERENCE_GOTO, // Dekel 20010114 LFUN_LASTACTION /* this marks the end of the table */ }; diff --git a/src/insets/inseterror.h b/src/insets/inseterror.h index 5ed89186b3..a333d543a5 100644 --- a/src/insets/inseterror.h +++ b/src/insets/inseterror.h @@ -67,7 +67,7 @@ public: /// Inset * Clone(Buffer const &) const { return new InsetError(contents); } /// - Inset::Code LyxCode() const { return Inset::NO_CODE; } + Inset::Code LyxCode() const { return Inset::ERROR_CODE; } /// We don't want "begin" and "end inset" in lyx-file bool DirectWrite() const { return true; }; /// diff --git a/src/insets/lyxinset.h b/src/insets/lyxinset.h index 146741299b..bbe02c7e49 100644 --- a/src/insets/lyxinset.h +++ b/src/insets/lyxinset.h @@ -105,7 +105,9 @@ public: /// CAPTION_CODE, /// - MATHMACRO_CODE + MATHMACRO_CODE, + /// + ERROR_CODE, }; /// diff --git a/src/lyxfunc.C b/src/lyxfunc.C index c0af8bd4cf..0d97f80e20 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -976,7 +976,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_GOTOERROR: - owner->view()->gotoError(); + owner->view()->gotoInset(Inset::ERROR_CODE, false); break; case LFUN_REMOVEERRORS: @@ -987,9 +987,18 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_GOTONOTE: - owner->view()->gotoNote(); + owner->view()->gotoInset(Inset::IGNORE_CODE, false); break; + case LFUN_REFERENCE_GOTO: + { + vector tmp; + tmp.push_back(Inset::LABEL_CODE); + tmp.push_back(Inset::REF_CODE); + owner->view()->gotoInset(tmp, true); + break; + } + #ifndef NEW_INSETS case LFUN_OPENSTUFF: owner->view()->openStuff(); diff --git a/src/lyxtext.h b/src/lyxtext.h index 7a7d551ced..8c9369a6bb 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -427,11 +427,10 @@ public: /// needed to insert the selection void InsertStringB(BufferView *, string const & str); - /// usefull when texing from within LyX - bool GotoNextError(BufferView *) const; - - /// just another feature :) - bool GotoNextNote(BufferView *) const; + /// Find next inset of some specified type. + bool GotoNextInset(BufferView *, std::vector const & codes, + string const & contents = string()) const; + /// /* for the greater insets */ diff --git a/src/text2.C b/src/text2.C index 2c7e52f73d..a52ac6678d 100644 --- a/src/text2.C +++ b/src/text2.C @@ -2602,9 +2602,12 @@ void LyXText::InsertStringB(BufferView * bview, string const & s) } -bool LyXText::GotoNextError(BufferView * bview) const +bool LyXText::GotoNextInset(BufferView * bview, + std::vector const & codes, + string const & contents) const { LyXCursor res = cursor; + Inset * inset; do { if (res.pos() < res.par()->Last() - 1) { res.pos(res.pos() + 1); @@ -2615,31 +2618,13 @@ bool LyXText::GotoNextError(BufferView * bview) const } while (res.par() && !(res.par()->GetChar(res.pos()) == LyXParagraph::META_INSET - && res.par()->GetInset(res.pos())->AutoDelete())); - - if (res.par()) { - SetCursor(bview, res.par(), res.pos()); - return true; - } - return false; -} - + && (inset = res.par()->GetInset(res.pos())) != 0 + && find(codes.begin(), codes.end(), inset->LyxCode()) + != codes.end() + && (contents.empty() || + static_cast(res.par()->GetInset(res.pos()))->getContents() + == contents))); -bool LyXText::GotoNextNote(BufferView * bview) const -{ - LyXCursor res = cursor; - do { - if (res.pos() < res.par()->Last() - 1) { - res.pos(res.pos() + 1); - } else { - res.par(res.par()->Next()); - res.pos(0); - } - - } while (res.par() && - !(res.par()->GetChar(res.pos()) == LyXParagraph::META_INSET - && res.par()->GetInset(res.pos())->LyxCode() == Inset::IGNORE_CODE)); - if (res.par()) { SetCursor(bview, res.par(), res.pos()); return true; -- 2.39.2