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 <[email protected]>
This commit is contained in:
committed by
Siarzhuk Zharski
parent
f35fa32b3a
commit
cd8bd6fa3f
@@ -2622,6 +2622,9 @@ TTextView::Reader::Run(void *_this)
|
|||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
// restore the reading position if available
|
||||||
|
view->Window()->PostMessage(M_READ_POS);
|
||||||
|
|
||||||
reader->Unlock();
|
reader->Unlock();
|
||||||
|
|
||||||
delete reader;
|
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
|
void
|
||||||
TMailWindow::MarkMessageRead(entry_ref* message, read_flags flag)
|
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
|
// don't wait for the server write the attribute directly
|
||||||
write_read_attr(node, flag);
|
write_read_attr(node, flag);
|
||||||
|
|
||||||
|
// preserve the read position in the node attribute
|
||||||
|
PreserveReadingPos(true);
|
||||||
|
|
||||||
BMailDaemon::MarkAsRead(account, *message, flag);
|
BMailDaemon::MarkAsRead(account, *message, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1337,6 +1365,10 @@ TMailWindow::MessageReceived(BMessage *msg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case M_READ_POS:
|
||||||
|
PreserveReadingPos(false);
|
||||||
|
break;
|
||||||
|
|
||||||
case M_PRINT_SETUP:
|
case M_PRINT_SETUP:
|
||||||
PrintSetup();
|
PrintSetup();
|
||||||
break;
|
break;
|
||||||
@@ -2848,6 +2880,10 @@ TMailWindow::OpenMessage(const entry_ref *ref, uint32 characterSetForDecoding)
|
|||||||
}
|
}
|
||||||
AddEnclosure(&msg);
|
AddEnclosure(&msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// restore the reading position if available
|
||||||
|
PostMessage(M_READ_POS);
|
||||||
|
|
||||||
PostMessage(RESET_BUTTONS);
|
PostMessage(RESET_BUTTONS);
|
||||||
fIncoming = false;
|
fIncoming = false;
|
||||||
fDraft = true;
|
fDraft = true;
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ class TMailWindow : public BWindow {
|
|||||||
void SaveTrackerPosition(entry_ref*);
|
void SaveTrackerPosition(entry_ref*);
|
||||||
void SetOriginatingWindow(BWindow* window);
|
void SetOriginatingWindow(BWindow* window);
|
||||||
|
|
||||||
|
void PreserveReadingPos(bool save);
|
||||||
void MarkMessageRead(entry_ref* message,
|
void MarkMessageRead(entry_ref* message,
|
||||||
read_flags flag);
|
read_flags flag);
|
||||||
void SetTrackerSelectionToCurrent();
|
void SetTrackerSelectionToCurrent();
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ enum MENUS {
|
|||||||
M_CLOSE_SAVED,
|
M_CLOSE_SAVED,
|
||||||
M_CLOSE_CUSTOM,
|
M_CLOSE_CUSTOM,
|
||||||
M_STATUS,
|
M_STATUS,
|
||||||
|
M_READ_POS,
|
||||||
|
|
||||||
// edit
|
// edit
|
||||||
M_SELECT,
|
M_SELECT,
|
||||||
|
|||||||
Reference in New Issue
Block a user