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:
parent
db3aecc840
commit
7df4b41328
|
@ -702,6 +702,13 @@ TContentView::MessageReceived(BMessage *msg)
|
||||||
|
|
||||||
case M_SIGNATURE:
|
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;
|
entry_ref ref;
|
||||||
msg->FindRef("ref", &ref);
|
msg->FindRef("ref", &ref);
|
||||||
|
|
||||||
|
@ -727,21 +734,23 @@ TContentView::MessageReceived(BMessage *msg)
|
||||||
const char *text = fTextView->Text();
|
const char *text = fTextView->Text();
|
||||||
int32 length = fTextView->TextLength();
|
int32 length = fTextView->TextLength();
|
||||||
|
|
||||||
if (length && text[length - 1] != '\n') {
|
// reserve some empty lines before the signature
|
||||||
|
const char* newLines = "\n\n\n\n";
|
||||||
|
if (length && text[length - 1] == '\n')
|
||||||
|
newLines++;
|
||||||
|
|
||||||
fTextView->Select(length, length);
|
fTextView->Select(length, length);
|
||||||
|
fTextView->Insert(newLines, strlen(newLines));
|
||||||
|
length += strlen(newLines);
|
||||||
|
|
||||||
char newLine = '\n';
|
// append the signature
|
||||||
fTextView->Insert(&newLine, 1);
|
|
||||||
|
|
||||||
length++;
|
|
||||||
}
|
|
||||||
|
|
||||||
fTextView->Select(length, length);
|
fTextView->Select(length, length);
|
||||||
fTextView->Insert(signature, bytesRead);
|
fTextView->Insert(signature, bytesRead);
|
||||||
fTextView->Select(length, length + bytesRead);
|
fTextView->Select(length, length + bytesRead);
|
||||||
fTextView->ScrollToSelection();
|
fTextView->ScrollToSelection();
|
||||||
|
|
||||||
fTextView->Select(start, finish);
|
// set the editing cursor position
|
||||||
|
fTextView->Select(length - 2 , length - 2);
|
||||||
fTextView->ScrollToSelection();
|
fTextView->ScrollToSelection();
|
||||||
free (signature);
|
free (signature);
|
||||||
} else {
|
} 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
|
void
|
||||||
TTextView::AddAsContent(BEmailMessage *mail, bool wrap, uint32 charset, mail_encoding encoding)
|
TTextView::AddAsContent(BEmailMessage *mail, bool wrap, uint32 charset, mail_encoding encoding)
|
||||||
{
|
{
|
||||||
|
|
|
@ -168,6 +168,7 @@ class TTextView : public BTextView {
|
||||||
void Open(hyper_text*);
|
void Open(hyper_text*);
|
||||||
status_t Save(BMessage *, bool makeNewFile = true);
|
status_t Save(BMessage *, bool makeNewFile = true);
|
||||||
void StopLoad();
|
void StopLoad();
|
||||||
|
bool IsReaderThreadRunning();
|
||||||
void AddAsContent(BEmailMessage *mail, bool wrap, uint32 charset, mail_encoding encoding);
|
void AddAsContent(BEmailMessage *mail, bool wrap, uint32 charset, mail_encoding encoding);
|
||||||
void CheckSpelling(int32 start, int32 end,
|
void CheckSpelling(int32 start, int32 end,
|
||||||
int32 flags = S_CLEAR_ERRORS | S_SHOW_ERRORS);
|
int32 flags = S_CLEAR_ERRORS | S_SHOW_ERRORS);
|
||||||
|
|
|
@ -534,22 +534,15 @@ TMailWindow::TMailWindow(BRect rect, const char* title, TMailApp* app,
|
||||||
// If we find the named query, add it to the text.
|
// If we find the named query, add it to the text.
|
||||||
BEntry entry;
|
BEntry entry;
|
||||||
if (query.GetNextEntry(&entry) == B_NO_ERROR) {
|
if (query.GetNextEntry(&entry) == B_NO_ERROR) {
|
||||||
off_t size;
|
|
||||||
BFile file;
|
BFile file;
|
||||||
file.SetTo(&entry, O_RDWR);
|
file.SetTo(&entry, O_RDWR);
|
||||||
if (file.InitCheck() == B_NO_ERROR) {
|
if (file.InitCheck() == B_NO_ERROR) {
|
||||||
file.GetSize(&size);
|
entry_ref ref;
|
||||||
char *str = (char *)malloc(size);
|
entry.GetRef(&ref);
|
||||||
size = file.Read(str, size);
|
|
||||||
|
|
||||||
fContentView->fTextView->Insert(str, size);
|
BMessage msg(M_SIGNATURE);
|
||||||
fContentView->fTextView->GoToLine(0);
|
msg.AddRef("ref", &ref);
|
||||||
fContentView->fTextView->ScrollToSelection();
|
PostMessage(&msg);
|
||||||
|
|
||||||
fStartingText = (char *)malloc(size
|
|
||||||
= strlen(fContentView->fTextView->Text()) + 1);
|
|
||||||
if (fStartingText != NULL)
|
|
||||||
strcpy(fStartingText, fContentView->fTextView->Text());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char tempString [2048];
|
char tempString [2048];
|
||||||
|
|
Loading…
Reference in New Issue