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 <zharik@gmx.li>
This commit is contained in:
parent
f35fa32b3a
commit
cd8bd6fa3f
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -86,6 +86,7 @@ enum MENUS {
|
||||
M_CLOSE_SAVED,
|
||||
M_CLOSE_CUSTOM,
|
||||
M_STATUS,
|
||||
M_READ_POS,
|
||||
|
||||
// edit
|
||||
M_SELECT,
|
||||
|
Loading…
Reference in New Issue
Block a user