From cd8bd6fa3fd3871812cc3e4027e15ca11e1adeaa Mon Sep 17 00:00:00 2001 From: Aleksas Pantechovskis Date: Thu, 12 Jan 2012 22:00:46 +0000 Subject: [PATCH] Preserve/Restore e-mail reading position * Introduce the "MAIL:read_pos" attribute of e-mail file node to store the latest scroll position of the mail text view; * Fixes #4302 (Mail should store and restore scroll offset); * This feature was implemented during completing GCI2011 task. Signed-off-by: Siarzhuk Zharski --- src/apps/mail/Content.cpp | 3 +++ src/apps/mail/MailWindow.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/apps/mail/MailWindow.h | 1 + src/apps/mail/Messages.h | 1 + 4 files changed, 41 insertions(+) diff --git a/src/apps/mail/Content.cpp b/src/apps/mail/Content.cpp index d8e45c02e4..b0c90c6027 100644 --- a/src/apps/mail/Content.cpp +++ b/src/apps/mail/Content.cpp @@ -2622,6 +2622,9 @@ TTextView::Reader::Run(void *_this) } done: + // restore the reading position if available + view->Window()->PostMessage(M_READ_POS); + reader->Unlock(); delete reader; diff --git a/src/apps/mail/MailWindow.cpp b/src/apps/mail/MailWindow.cpp index e204cb8ece..1822886c1a 100644 --- a/src/apps/mail/MailWindow.cpp +++ b/src/apps/mail/MailWindow.cpp @@ -794,6 +794,31 @@ TMailWindow::SetTrackerSelectionToCurrent() } +void +TMailWindow::PreserveReadingPos(bool save) +{ + BScrollBar *scroll = fContentView->fTextView->ScrollBar(B_VERTICAL); + if (scroll == NULL || fRef == NULL) + return; + + BNode node(fRef); + float pos = scroll->Value(); + + const char* name = "MAIL:read_pos"; + if (save) { + node.WriteAttr(name, B_FLOAT_TYPE, 0, &pos, sizeof(pos)); + syslog(0, "save: %f", pos); + return; + } + + if (node.ReadAttr(name, B_FLOAT_TYPE, 0, &pos, sizeof(pos)) == sizeof(pos)) { + Lock(); + scroll->SetValue(pos); + Unlock(); + } +} + + void TMailWindow::MarkMessageRead(entry_ref* message, read_flags flag) { @@ -810,6 +835,9 @@ TMailWindow::MarkMessageRead(entry_ref* message, read_flags flag) // don't wait for the server write the attribute directly write_read_attr(node, flag); + // preserve the read position in the node attribute + PreserveReadingPos(true); + BMailDaemon::MarkAsRead(account, *message, flag); } @@ -1337,6 +1365,10 @@ TMailWindow::MessageReceived(BMessage *msg) break; } + case M_READ_POS: + PreserveReadingPos(false); + break; + case M_PRINT_SETUP: PrintSetup(); break; @@ -2848,6 +2880,10 @@ TMailWindow::OpenMessage(const entry_ref *ref, uint32 characterSetForDecoding) } AddEnclosure(&msg); } + + // restore the reading position if available + PostMessage(M_READ_POS); + PostMessage(RESET_BUTTONS); fIncoming = false; fDraft = true; diff --git a/src/apps/mail/MailWindow.h b/src/apps/mail/MailWindow.h index 00f91e1ce2..d2a2c903a3 100644 --- a/src/apps/mail/MailWindow.h +++ b/src/apps/mail/MailWindow.h @@ -108,6 +108,7 @@ class TMailWindow : public BWindow { void SaveTrackerPosition(entry_ref*); void SetOriginatingWindow(BWindow* window); + void PreserveReadingPos(bool save); void MarkMessageRead(entry_ref* message, read_flags flag); void SetTrackerSelectionToCurrent(); diff --git a/src/apps/mail/Messages.h b/src/apps/mail/Messages.h index 1f304f03a4..a98b06adcc 100644 --- a/src/apps/mail/Messages.h +++ b/src/apps/mail/Messages.h @@ -86,6 +86,7 @@ enum MENUS { M_CLOSE_SAVED, M_CLOSE_CUSTOM, M_STATUS, + M_READ_POS, // edit M_SELECT,