Improve the auto-signature insertion algorithm

* Append the signature only after the e-mail Reader thread will finish
  it's work. This prevent from inserting the signature in wrong place;
* Added extra lines between original e-mail quote and the signature for
  more comfortable editing of replies.
* This fix was made during GCI2011;
* This fixes #4590.

Signed-off-by: Siarzhuk Zharski <zharik@gmx.li>
This commit is contained in:
Aleksas Pantechovskis 2012-01-15 20:48:06 +01:00 committed by Siarzhuk Zharski
parent db3aecc840
commit 7df4b41328
3 changed files with 37 additions and 20 deletions

View File

@ -702,6 +702,13 @@ TContentView::MessageReceived(BMessage *msg)
case M_SIGNATURE:
{
if (fTextView->IsReaderThreadRunning()) {
// Do not add the signature until the reader thread
// is finished. Resubmit the message for later processing
Window()->PostMessage(msg);
break;
}
entry_ref ref;
msg->FindRef("ref", &ref);
@ -727,21 +734,23 @@ TContentView::MessageReceived(BMessage *msg)
const char *text = fTextView->Text();
int32 length = fTextView->TextLength();
if (length && text[length - 1] != '\n') {
fTextView->Select(length, length);
// reserve some empty lines before the signature
const char* newLines = "\n\n\n\n";
if (length && text[length - 1] == '\n')
newLines++;
char newLine = '\n';
fTextView->Insert(&newLine, 1);
length++;
}
fTextView->Select(length, length);
fTextView->Insert(newLines, strlen(newLines));
length += strlen(newLines);
// append the signature
fTextView->Select(length, length);
fTextView->Insert(signature, bytesRead);
fTextView->Select(length, length + bytesRead);
fTextView->ScrollToSelection();
fTextView->Select(start, finish);
// set the editing cursor position
fTextView->Select(length - 2 , length - 2);
fTextView->ScrollToSelection();
free (signature);
} else {
@ -2086,6 +2095,20 @@ TTextView::StopLoad()
}
bool
TTextView::IsReaderThreadRunning()
{
if (fThread == 0)
return false;
thread_info info;
for (int i = 5; i > 0; i--, usleep(100000))
if (get_thread_info(fThread, &info) != B_OK)
return false;
return true;
}
void
TTextView::AddAsContent(BEmailMessage *mail, bool wrap, uint32 charset, mail_encoding encoding)
{

View File

@ -168,6 +168,7 @@ class TTextView : public BTextView {
void Open(hyper_text*);
status_t Save(BMessage *, bool makeNewFile = true);
void StopLoad();
bool IsReaderThreadRunning();
void AddAsContent(BEmailMessage *mail, bool wrap, uint32 charset, mail_encoding encoding);
void CheckSpelling(int32 start, int32 end,
int32 flags = S_CLEAR_ERRORS | S_SHOW_ERRORS);

View File

@ -534,22 +534,15 @@ TMailWindow::TMailWindow(BRect rect, const char* title, TMailApp* app,
// If we find the named query, add it to the text.
BEntry entry;
if (query.GetNextEntry(&entry) == B_NO_ERROR) {
off_t size;
BFile file;
file.SetTo(&entry, O_RDWR);
if (file.InitCheck() == B_NO_ERROR) {
file.GetSize(&size);
char *str = (char *)malloc(size);
size = file.Read(str, size);
entry_ref ref;
entry.GetRef(&ref);
fContentView->fTextView->Insert(str, size);
fContentView->fTextView->GoToLine(0);
fContentView->fTextView->ScrollToSelection();
fStartingText = (char *)malloc(size
= strlen(fContentView->fTextView->Text()) + 1);
if (fStartingText != NULL)
strcpy(fStartingText, fContentView->fTextView->Text());
BMessage msg(M_SIGNATURE);
msg.AddRef("ref", &ref);
PostMessage(&msg);
}
} else {
char tempString [2048];