Restore old bookmark behaviors (stop using bookmark queue)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17628 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2007-03-29 03:41:55 +00:00
parent ce899a9fa1
commit 6fc7d47a5f
10 changed files with 107 additions and 43 deletions

View File

@ -132,12 +132,24 @@
\bind "M-~S-n e" "error-next" \bind "M-~S-n e" "error-next"
\bind "M-~S-n n" "note-next" \bind "M-~S-n n" "note-next"
\bind "M-~S-n r" "label-goto" \bind "M-~S-n r" "label-goto"
\bind "M-~S-n b s" "bookmark-save 1" \bind "M-~S-n S-B 1" "bookmark-save 1"
\bind "M-~S-n S-B 2" "bookmark-save 2"
\bind "M-~S-n S-B 3" "bookmark-save 3"
\bind "M-~S-n S-B 4" "bookmark-save 4"
\bind "M-~S-n S-B 5" "bookmark-save 5"
\bind "M-~S-n S-B 6" "bookmark-save 6"
\bind "M-~S-n S-B 7" "bookmark-save 7"
\bind "M-~S-n S-B 8" "bookmark-save 8"
\bind "M-~S-n S-B 9" "bookmark-save 9"
\bind "M-~S-n b 1" "bookmark-goto 1" \bind "M-~S-n b 1" "bookmark-goto 1"
\bind "M-~S-n b 2" "bookmark-goto 2" \bind "M-~S-n b 2" "bookmark-goto 2"
\bind "M-~S-n b 3" "bookmark-goto 3" \bind "M-~S-n b 3" "bookmark-goto 3"
\bind "M-~S-n b 4" "bookmark-goto 4" \bind "M-~S-n b 4" "bookmark-goto 4"
\bind "M-~S-n b 5" "bookmark-goto 5" \bind "M-~S-n b 5" "bookmark-goto 5"
\bind "M-~S-n b 6" "bookmark-goto 6"
\bind "M-~S-n b 7" "bookmark-goto 7"
\bind "M-~S-n b 8" "bookmark-goto 8"
\bind "M-~S-n b 9" "bookmark-goto 9"
\bind "M-~S-h i" "help-open Intro" \bind "M-~S-h i" "help-open Intro"
\bind "M-~S-h t" "help-open Tutorial" \bind "M-~S-h t" "help-open Tutorial"

View File

@ -168,7 +168,19 @@
\bind "C-~S-3" "bookmark-goto 3" \bind "C-~S-3" "bookmark-goto 3"
\bind "C-~S-4" "bookmark-goto 4" \bind "C-~S-4" "bookmark-goto 4"
\bind "C-~S-5" "bookmark-goto 5" \bind "C-~S-5" "bookmark-goto 5"
\bind "C-~S-6" "bookmark-goto 6"
\bind "C-~S-7" "bookmark-goto 7"
\bind "C-~S-8" "bookmark-goto 8"
\bind "C-~S-9" "bookmark-goto 9"
\bind "C-M-~S-1" "bookmark-save 1" \bind "C-M-~S-1" "bookmark-save 1"
\bind "C-M-~S-2" "bookmark-save 2"
\bind "C-M-~S-3" "bookmark-save 3"
\bind "C-M-~S-4" "bookmark-save 4"
\bind "C-M-~S-5" "bookmark-save 5"
\bind "C-M-~S-6" "bookmark-save 6"
\bind "C-M-~S-7" "bookmark-save 7"
\bind "C-M-~S-8" "bookmark-save 8"
\bind "C-M-~S-9" "bookmark-save 9"
# #

View File

@ -157,7 +157,19 @@
\bind "C-~S-3" "bookmark-goto 3" \bind "C-~S-3" "bookmark-goto 3"
\bind "C-~S-4" "bookmark-goto 4" \bind "C-~S-4" "bookmark-goto 4"
\bind "C-~S-5" "bookmark-goto 5" \bind "C-~S-5" "bookmark-goto 5"
\bind "C-~S-6" "bookmark-goto 6"
\bind "C-~S-7" "bookmark-goto 7"
\bind "C-~S-8" "bookmark-goto 8"
\bind "C-~S-9" "bookmark-goto 9"
\bind "C-M-~S-1" "bookmark-save 1" \bind "C-M-~S-1" "bookmark-save 1"
\bind "C-M-~S-2" "bookmark-save 2"
\bind "C-M-~S-3" "bookmark-save 3"
\bind "C-M-~S-4" "bookmark-save 4"
\bind "C-M-~S-5" "bookmark-save 5"
\bind "C-M-~S-6" "bookmark-save 6"
\bind "C-M-~S-7" "bookmark-save 7"
\bind "C-M-~S-8" "bookmark-save 8"
\bind "C-M-~S-9" "bookmark-save 9"
# The below are xemacs bindings # The below are xemacs bindings
#\bind "Home" "line-begin" #\bind "Home" "line-begin"

View File

@ -156,7 +156,19 @@
\bind "C-~S-3" "bookmark-goto 3" \bind "C-~S-3" "bookmark-goto 3"
\bind "C-~S-4" "bookmark-goto 4" \bind "C-~S-4" "bookmark-goto 4"
\bind "C-~S-5" "bookmark-goto 5" \bind "C-~S-5" "bookmark-goto 5"
\bind "C-~S-6" "bookmark-goto 6"
\bind "C-~S-7" "bookmark-goto 7"
\bind "C-~S-8" "bookmark-goto 8"
\bind "C-~S-9" "bookmark-goto 9"
\bind "C-M-~S-1" "bookmark-save 1" \bind "C-M-~S-1" "bookmark-save 1"
\bind "C-M-~S-2" "bookmark-save 2"
\bind "C-M-~S-3" "bookmark-save 3"
\bind "C-M-~S-4" "bookmark-save 4"
\bind "C-M-~S-5" "bookmark-save 5"
\bind "C-M-~S-6" "bookmark-save 6"
\bind "C-M-~S-7" "bookmark-save 7"
\bind "C-M-~S-8" "bookmark-save 8"
\bind "C-M-~S-9" "bookmark-save 9"
# #

View File

@ -172,7 +172,21 @@
\bind "C-~S-3" "bookmark-goto 3" \bind "C-~S-3" "bookmark-goto 3"
\bind "C-~S-4" "bookmark-goto 4" \bind "C-~S-4" "bookmark-goto 4"
\bind "C-~S-5" "bookmark-goto 5" \bind "C-~S-5" "bookmark-goto 5"
\bind "C-~S-6" "bookmark-goto 6"
\bind "C-~S-7" "bookmark-goto 7"
\bind "C-~S-8" "bookmark-goto 8"
\bind "C-~S-9" "bookmark-goto 9"
\bind "C-M-~S-1" "bookmark-save 1" \bind "C-M-~S-1" "bookmark-save 1"
\bind "C-M-~S-2" "bookmark-save 2"
\bind "C-M-~S-3" "bookmark-save 3"
\bind "C-M-~S-4" "bookmark-save 4"
\bind "C-M-~S-5" "bookmark-save 5"
\bind "C-M-~S-6" "bookmark-save 6"
\bind "C-M-~S-7" "bookmark-save 7"
\bind "C-M-~S-8" "bookmark-save 8"
\bind "C-M-~S-9" "bookmark-save 9"
# #
# Motion + select group # Motion + select group

View File

@ -436,7 +436,11 @@ Menuset
End End
Menu "navigate_bookmarks" Menu "navigate_bookmarks"
Item "Save Bookmark|S" "bookmark-save 1" Item "Save Bookmark 1|S" "bookmark-save 1"
Item "Save Bookmark 2" "bookmark-save 2"
Item "Save Bookmark 3" "bookmark-save 3"
Item "Save Bookmark 4" "bookmark-save 4"
Item "Save Bookmark 5" "bookmark-save 5"
Item "Clear Bookmarks|C" "bookmark-clear" Item "Clear Bookmarks|C" "bookmark-clear"
Separator Separator
Bookmarks Bookmarks

View File

@ -551,16 +551,16 @@ Change const BufferView::getCurrentChange() const
} }
void BufferView::saveBookmark(bool persistent) void BufferView::saveBookmark(unsigned int idx)
{ {
LyX::ref().session().bookmarks().save( LyX::ref().session().bookmarks().save(
FileName(buffer_->fileName()), FileName(buffer_->fileName()),
cursor_.pit(), cursor_.pit(),
cursor_.paragraph().id(), cursor_.paragraph().id(),
cursor_.pos(), cursor_.pos(),
persistent idx
); );
if (persistent) if (idx)
// emit message signal. // emit message signal.
message(_("Save bookmark")); message(_("Save bookmark"));
} }
@ -786,7 +786,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
if (inset) { if (inset) {
label = inset->getParam("reference"); label = inset->getParam("reference");
// persistent=false: use temp_bookmark // persistent=false: use temp_bookmark
saveBookmark(false); saveBookmark(0);
} }
} }

View File

@ -113,8 +113,8 @@ public:
ScrollbarParameters const & scrollbarParameters() const; ScrollbarParameters const & scrollbarParameters() const;
/// Save the current position as bookmark. /// Save the current position as bookmark.
/// if persistent=false, save to temp_bookmark /// if idx == 0, save to temp_bookmark
void saveBookmark(bool persistent); void saveBookmark(unsigned int idx);
/// goto a specified position, try par_id first, and then par_pit /// goto a specified position, try par_id first, and then par_pit
/// return the par_pit and par_id of the new paragraph /// return the par_pit and par_id of the new paragraph
boost::tuple<pit_type, int> moveToPosition( boost::tuple<pit_type, int> moveToPosition(

View File

@ -231,6 +231,14 @@ LastFilePosSection::FilePos LastFilePosSection::load(FileName const & fname) con
} }
void BookmarksSection::clear()
{
// keep bookmark[0], the temporary one
bookmarks.resize(1);
bookmarks.resize(max_bookmarks + 1);
}
void BookmarksSection::read(istream & is) void BookmarksSection::read(istream & is)
{ {
string tmp; string tmp;
@ -244,11 +252,14 @@ void BookmarksSection::read(istream & is)
try { try {
// read bookmarks // read bookmarks
// pit, pos, file\n // idx, pit, pos, file\n
unsigned int idx;
pit_type pit; pit_type pit;
pos_type pos; pos_type pos;
string fname; string fname;
istringstream itmp(tmp); istringstream itmp(tmp);
itmp >> idx;
itmp.ignore(2); // ignore ", "
itmp >> pit; itmp >> pit;
itmp.ignore(2); // ignore ", " itmp.ignore(2); // ignore ", "
itmp >> pos; itmp >> pos;
@ -260,8 +271,8 @@ void BookmarksSection::read(istream & is)
// only load valid bookmarks // only load valid bookmarks
if (fs::exists(file.toFilesystemEncoding()) && if (fs::exists(file.toFilesystemEncoding()) &&
!fs::is_directory(file.toFilesystemEncoding()) && !fs::is_directory(file.toFilesystemEncoding()) &&
bookmarks.size() < max_bookmarks) idx <= max_bookmarks)
bookmarks.push_back(Bookmark(file, pit, 0, pos)); bookmarks[idx] = Bookmark(file, pit, 0, pos);
else else
lyxerr[Debug::INIT] << "LyX: Warning: Ignore bookmark of file: " << fname << endl; lyxerr[Debug::INIT] << "LyX: Warning: Ignore bookmark of file: " << fname << endl;
} catch (...) { } catch (...) {
@ -274,41 +285,33 @@ void BookmarksSection::read(istream & is)
void BookmarksSection::write(ostream & os) const void BookmarksSection::write(ostream & os) const
{ {
os << '\n' << sec_bookmarks << '\n'; os << '\n' << sec_bookmarks << '\n';
for (size_t i = 0; i < bookmarks.size(); ++i) { for (size_t i = 1; i <= max_bookmarks; ++i) {
os << bookmarks[i].par_pit << ", " if (isValid(i))
<< bookmarks[i].par_pos << ", " os << i << ", "
<< bookmarks[i].filename << '\n'; << bookmarks[i].par_pit << ", "
<< bookmarks[i].par_pos << ", "
<< bookmarks[i].filename << '\n';
} }
} }
void BookmarksSection::save(FileName const & fname, pit_type par_pit, int par_id, pos_type par_pos, bool persistent) void BookmarksSection::save(FileName const & fname, pit_type par_pit, int par_id, pos_type par_pos, unsigned int idx)
{ {
if (persistent) { // silently ignore bookmarks when idx is out of range
bookmarks.push_back(Bookmark(fname, par_pit, par_id, par_pos)); if (idx <= max_bookmarks)
if (bookmarks.size() > max_bookmarks) bookmarks[idx] = Bookmark(fname, par_pit, par_id, par_pos);
bookmarks.pop_back();
}
else
temp_bookmark = Bookmark(fname, par_pit, par_id, par_pos);
} }
bool BookmarksSection::isValid(unsigned int i) const bool BookmarksSection::isValid(unsigned int i) const
{ {
if (i == 0) return i <= max_bookmarks && !bookmarks[i].filename.empty();
return !temp_bookmark.filename.empty();
else
return i <= bookmarks.size() && !bookmarks[i-1].filename.empty();
} }
BookmarksSection::Bookmark const & BookmarksSection::bookmark(unsigned int i) const BookmarksSection::Bookmark const & BookmarksSection::bookmark(unsigned int i) const
{ {
if (i == 0) return bookmarks[i];
return temp_bookmark;
else
return bookmarks[i-1];
} }

View File

@ -199,28 +199,27 @@ public:
}; };
/// ///
typedef std::deque<Bookmark> BookmarkList; typedef std::vector<Bookmark> BookmarkList;
public: public:
/// constructor, set max_bookmarks /// constructor, set max_bookmarks
/// allow 20 regular bookmarks /// allow 9 regular bookmarks, bookmark 0 is temporary
BookmarksSection() : bookmarks(0), max_bookmarks(20) {} BookmarksSection() : bookmarks(10), max_bookmarks(9) {}
/// Save the current position as bookmark /// Save the current position as bookmark
/// if save==false, save to temp_bookmark void save(support::FileName const & fname, pit_type pit, int par_id, pos_type par_pos, unsigned int idx);
void save(support::FileName const & fname, pit_type pit, int par_id, pos_type par_pos, bool persistent);
/// return bookmark, return temp_bookmark if i==0 /// return bookmark 0-9, bookmark 0 is the temporary bookmark
Bookmark const & bookmark(unsigned int i) const; Bookmark const & bookmark(unsigned int i) const;
/// does the given bookmark have a saved position ? /// does the given bookmark have a saved position ?
bool isValid(unsigned int i) const; bool isValid(unsigned int i) const;
/// ///
unsigned int size() const { return bookmarks.size(); } unsigned int size() const { return max_bookmarks; }
/// clear all bookmarks /// clear all bookmarks
void clear() { bookmarks.clear(); } void clear();
/// ///
void read(std::istream & is); void read(std::istream & is);
@ -234,10 +233,6 @@ public:
BookmarkList & load() { return bookmarks; } BookmarkList & load() { return bookmarks; }
private: private:
/// temp bookmark (previously saved_positions[0]), this is really ugly
/// c.f. ./frontends/controllers/ControlRef.C
/// FIXME: a separate LFUN may be a better solution
Bookmark temp_bookmark;
/// a list of bookmarks /// a list of bookmarks
BookmarkList bookmarks; BookmarkList bookmarks;