From 1ecfd5f42531d0dde9473407966278b79faa8dc9 Mon Sep 17 00:00:00 2001 From: Dekel Tsur Date: Sun, 28 Jan 2001 18:31:36 +0000 Subject: [PATCH] Bookmarks. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1410 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 12 +++++------ src/BufferView.h | 6 +++--- src/BufferView_pimpl.C | 38 +++++++++++++++++++++++----------- src/BufferView_pimpl.h | 24 +++++++++++++++------ src/ChangeLog | 9 ++++++++ src/LyXAction.C | 3 ++- src/commandtags.h | 4 +++- src/frontends/gnome/FormRef.C | 2 +- src/frontends/kde/FormRef.C | 5 +++-- src/frontends/xforms/FormRef.C | 11 ++++++---- src/lyxfunc.C | 26 +++++++++++++---------- 11 files changed, 93 insertions(+), 47 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 5d33f7d764..1db0214573 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -217,21 +217,21 @@ void BufferView::beforeChange() } -void BufferView::savePosition() +void BufferView::savePosition(unsigned int i) { - pimpl_->savePosition(); + pimpl_->savePosition(i); } -void BufferView::restorePosition() +void BufferView::restorePosition(unsigned int i) { - pimpl_->restorePosition(); + pimpl_->restorePosition(i); } -bool BufferView::NoSavedPositions() +bool BufferView::isSavedPosition(unsigned int i) { - return pimpl_->NoSavedPositions(); + return pimpl_->isSavedPosition(i); } diff --git a/src/BufferView.h b/src/BufferView.h index 9c791e8894..6bf6350d14 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -94,11 +94,11 @@ public: /// void beforeChange(); /// - void savePosition(); + void savePosition(unsigned int i); /// - void restorePosition(); + void restorePosition(unsigned int i); /// - bool NoSavedPositions(); + bool isSavedPosition(unsigned int i); /** This holds the mapping between buffer paragraphs and screen rows. This should be private...but not yet. (Lgb) */ diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index bd23465081..a257021565 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -35,6 +35,7 @@ using std::pair; using std::endl; using std::vector; using std::make_pair; +using std::min; /* the selection possible is needed, that only motion events are * used, where the bottom press event was on the drawing area too */ @@ -47,6 +48,7 @@ extern "C" void TimerCB(FL_OBJECT *, long); extern void sigchldhandler(pid_t pid, int * status); extern int bibitemMaxWidth(BufferView *, LyXFont const &); +const unsigned int saved_positions_num = 20; static inline void waitForX() @@ -110,6 +112,7 @@ BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o, cursor_timeout.start(); workarea_->setFocus(); using_xterm_cursor = false; + saved_positions.resize(saved_positions_num); } @@ -1171,20 +1174,23 @@ void BufferView::Pimpl::beforeChange() } -void BufferView::Pimpl::savePosition() +void BufferView::Pimpl::savePosition(unsigned int i) { - backstack.push(buffer_->fileName(), - bv_->text->cursor.x(), - bv_->text->cursor.y()); + if (i >= saved_positions_num) + return; + saved_positions[i] = Position(buffer_->fileName(), + bv_->text->cursor.par()->id(), + bv_->text->cursor.pos()); } -void BufferView::Pimpl::restorePosition() +void BufferView::Pimpl::restorePosition(unsigned int i) { - if (backstack.empty()) return; - - int x, y; - string fname = backstack.pop(&x, &y); + if (i >= saved_positions_num) + return; + + + string fname = saved_positions[i].filename; beforeChange(); @@ -1195,14 +1201,22 @@ void BufferView::Pimpl::restorePosition() if (b != 0 ) buffer(b); } - bv_->text->SetCursorFromCoordinates(bv_, x, y); + LyXParagraph * par = bv_->text->GetParFromID(saved_positions[i].par_id); + if (!par) + return; + + bv_->text->SetCursor(bv_, par, + min(par->Last(), saved_positions[i].par_pos)); update(BufferView::SELECT|BufferView::FITCUR); } -bool BufferView::Pimpl::NoSavedPositions() +bool BufferView::Pimpl::isSavedPosition(unsigned int i) { - return backstack.empty(); + if (i >= saved_positions_num) + return false; + + return !saved_positions[i].filename.empty(); } diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 70a767788e..7472a32a36 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -5,7 +5,6 @@ #include "BufferView.h" #include "UpdateInset.h" -#include "BackStack.h" #include "Timeout.h" #ifdef __GNUG__ @@ -87,11 +86,11 @@ struct BufferView::Pimpl : public Object { /// void beforeChange(); /// - void savePosition(); + void savePosition(unsigned int i); /// - void restorePosition(); + void restorePosition(unsigned int i); /// - bool NoSavedPositions(); + bool isSavedPosition(unsigned int i); /// void setState(); /// @@ -133,8 +132,6 @@ struct BufferView::Pimpl : public Object { /// Timeout cursor_timeout; /// - BackStack backstack; - /// int last_click_x; /// int last_click_y; @@ -149,5 +146,20 @@ struct BufferView::Pimpl : public Object { private: /// bool using_xterm_cursor; + + struct Position { + /// Filename + string filename; + /// Cursor paragraph Id + int par_id; + /// Cursor position + int par_pos; + /// + Position() : par_id(0), par_pos(0) {} + /// + Position(string const & f, int id, int pos) + : filename(f), par_id(id), par_pos(pos) {} + }; + vector saved_positions; }; #endif diff --git a/src/ChangeLog b/src/ChangeLog index c7d00ee16f..952f7e7004 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2001-01-27 Dekel Tsur + + * BufferView_pimpl.C (savePosition, restorePosition): Use a vector of + saved positions instrad of a stack. Furthermore, a position is + stored using paragraph id/paragraph position. + + * commandtags.h: Add LFUN_BOOKMARK_SAVE and LFUN_BOOKMARK_GOTO. + Remove LFUN_REF_BACK. + 2001-01-27 Dekel Tsur * converter.C (dvipdfm_options): New method. diff --git a/src/LyXAction.C b/src/LyXAction.C index 5f5478f8c3..84617186b7 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -105,6 +105,8 @@ void LyXAction::init() { LFUN_INSERT_BIBTEX, "bibtex-insert", N_("Insert bibtex"), Noop }, { LFUN_BIBTEX_STYLE, "bibtex-style", "", Noop }, + { LFUN_BOOKMARK_GOTO, "bookmark-goto", "", ReadOnly }, + { LFUN_BOOKMARK_SAVE, "bookmark-save", "", ReadOnly }, { LFUN_BREAKLINE, "break-line", "", Noop }, { LFUN_BREAKPARAGRAPH, "break-paragraph", "", Noop }, { LFUN_BREAKPARAGRAPHKEEPLAYOUT, "break-paragraph-keep-layout", @@ -355,7 +357,6 @@ void LyXAction::init() { LFUN_RECONFIGURE, "reconfigure", N_("Reconfigure"), NoBuffer }, { LFUN_REDO, "redo", N_("Redo"), Noop }, - { LFUN_REF_BACK, "reference-back", "", ReadOnly }, { LFUN_REF_GOTO, "reference-goto", "", ReadOnly }, { LFUN_REF_INSERT, "reference-insert", N_("Insert cross reference"), ReadOnly }, diff --git a/src/commandtags.h b/src/commandtags.h index 8b01de9182..1bbc5a385e 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -222,7 +222,7 @@ enum kb_action { LFUN_EXPORT, // Lgb 97-07-29 LFUN_INSERTFOOTNOTE, // Bernhard 97-08-07 LFUN_REF_GOTO, // 200 // Ale 970806 - LFUN_REF_BACK, // Ale 970806 + //LFUN_REF_BACK, // Ale 970806 LFUN_PARENTINSERT, // Ale 970813 LFUN_REMOVEERRORS, // Asger 970906 LFUN_LDOTS, // Asger 970929 @@ -274,6 +274,8 @@ enum kb_action { LFUN_DIALOG_TABULAR_INSERT, // 250 // Jug 20000825 (old table-insert) LFUN_GOTO_PARAGRAPH, // Dekel 20000826 LFUN_REFERENCE_GOTO, // Dekel 20010114 + LFUN_BOOKMARK_SAVE, // Dekel 20010127 + LFUN_BOOKMARK_GOTO, // Dekel 20010127 LFUN_LASTACTION /* this marks the end of the table */ }; diff --git a/src/frontends/gnome/FormRef.C b/src/frontends/gnome/FormRef.C index dc2fa4b01b..d6c460d352 100644 --- a/src/frontends/gnome/FormRef.C +++ b/src/frontends/gnome/FormRef.C @@ -364,7 +364,7 @@ void FormRef::gotoRef() } case GOBACK: { - lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK); + lv_->getLyXFunc()->Dispatch(LFUN_BOOKMARK_GOTO, "0"); gototype_ = GOREF; b_goto->set_text(GOTO_REF_LABEL); diff --git a/src/frontends/kde/FormRef.C b/src/frontends/kde/FormRef.C index cd53a7303b..89d4e6432b 100644 --- a/src/frontends/kde/FormRef.C +++ b/src/frontends/kde/FormRef.C @@ -108,7 +108,7 @@ void FormRef::goto_ref() QToolTip::add(dialog_->buttonGoto,_("Jump back to original position")); break; case GOTOBACK: - lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK); + lv_->getLyXFunc()->Dispatch(LFUN_BOOKMARK_GOTO, "0"); gotowhere=GOTOREF; dialog_->buttonGoto->setText(_("&Goto reference")); QToolTip::remove(dialog_->buttonGoto); @@ -121,7 +121,7 @@ void FormRef::updateRefs() { // list will be re-done, should go back if necessary if (gotowhere==GOTOBACK) { - lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK); + lv_->getLyXFunc()->Dispatch(LFUN_BOOKMARK_GOTO, "0"); gotowhere = GOTOREF; dialog_->buttonGoto->setText(_("&Goto reference")); QToolTip::remove(dialog_->buttonGoto); @@ -176,6 +176,7 @@ void FormRef::update(bool switched) if (inset_) dialog_->type->setCurrentItem(InsetRef::getType(params.getCmdName())); + lv_->getLyXFunc()->Dispatch(LFUN_BOOKMARK_SAVE, "0"); dialog_->buttonGoto->setText(_("&Goto reference")); QToolTip::remove(dialog_->buttonGoto); QToolTip::add(dialog_->buttonGoto,_("Jump to selected reference")); diff --git a/src/frontends/xforms/FormRef.C b/src/frontends/xforms/FormRef.C index 702a0a0e7c..4cb2bcf60e 100644 --- a/src/frontends/xforms/FormRef.C +++ b/src/frontends/xforms/FormRef.C @@ -102,6 +102,8 @@ void FormRef::update() InsetRef::getType(params.getCmdName()) + 1); } + lv_->getLyXFunc()->Dispatch(LFUN_BOOKMARK_SAVE, "0"); + toggle = GOBACK; fl_set_object_label(dialog_->button_go, _("Goto reference")); @@ -157,9 +159,10 @@ void FormRef::updateBrowser(vector const & akeys) const string ref = fl_get_input(dialog_->ref); vector::const_iterator cit = find(keys.begin(), keys.end(), ref); - if (cit == keys.end()) + if (cit == keys.end()) { cit = keys.begin(); - if (ref.empty()) + fl_set_input(dialog_->ref, (*cit).c_str()); + } else if (ref.empty()) fl_set_input(dialog_->ref, (*cit).c_str()); int const i = static_cast(cit - keys.begin()); @@ -218,7 +221,7 @@ bool FormRef::input(FL_OBJECT *, long data) case GOBACK: { - lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK); + lv_->getLyXFunc()->Dispatch(LFUN_BOOKMARK_GOTO, "0"); fl_set_object_label(dialog_->button_go, _("Goto reference")); } @@ -242,7 +245,7 @@ bool FormRef::input(FL_OBJECT *, long data) } toggle = GOBACK; - lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK); + lv_->getLyXFunc()->Dispatch(LFUN_BOOKMARK_GOTO, "0"); fl_set_object_label(dialog_->button_go, _("Goto reference")); fl_activate_object(dialog_->type); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index d9f7e28269..40f53c1eac 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -446,9 +446,9 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const case LFUN_VC_HISTORY: disable = !buf->lyxvc.inUse(); break; - case LFUN_REF_BACK: - disable = owner->view()->NoSavedPositions(); - break; + case LFUN_BOOKMARK_GOTO: + disable = !owner->view()-> + isSavedPosition(strToUnsignedInt(argument)); default: break; } @@ -1423,11 +1423,13 @@ string const LyXFunc::Dispatch(int ac, } break; - case LFUN_REF_BACK: - { - owner->view()->restorePosition(); - } - break; + case LFUN_BOOKMARK_SAVE: + owner->view()->savePosition(strToUnsignedInt(argument)); + break; + + case LFUN_BOOKMARK_GOTO: + owner->view()->restorePosition(strToUnsignedInt(argument)); + break; case LFUN_REF_GOTO: { @@ -1435,12 +1437,14 @@ string const LyXFunc::Dispatch(int ac, if (label.empty()) { InsetRef * inset = static_cast(getInsetByCode(Inset::REF_CODE)); - if (inset) + if (inset) { label = inset->getContents(); + owner->view()->savePosition(0); + } } if (!label.empty()) { - owner->view()->savePosition(); + //owner->view()->savePosition(0); if (!owner->view()->gotoLabel(label)) WriteAlert(_("Error"), _("Couldn't find this label"), @@ -2765,7 +2769,7 @@ string const LyXFunc::Dispatch(int ac, OnlyPath(owner->buffer()->fileName())); setMessage(N_("Opening child document ") + MakeDisplayPath(filename) + "..."); - owner->view()->savePosition(); + owner->view()->savePosition(0); if (bufferlist.exists(filename)) owner->view()->buffer(bufferlist.getBuffer(filename)); else -- 2.39.2