Handle be:line and °K in RefsReceived, store it in file attributes
This work was done during GCI2012 Fixes #4794 Signed-off-by: Siarzhuk Zharski <zharik@gmx.li>
This commit is contained in:
parent
ec8f666514
commit
46f1daff68
@ -81,6 +81,7 @@ const uint32 SAVE_THEN_QUIT = 'FPsq';
|
|||||||
// Update StatusView
|
// Update StatusView
|
||||||
const uint32 UPDATE_STATUS = 'UPSt';
|
const uint32 UPDATE_STATUS = 'UPSt';
|
||||||
const uint32 UNLOCK_FILE = 'UNLk';
|
const uint32 UNLOCK_FILE = 'UNLk';
|
||||||
|
const uint32 UPDATE_LINE_SEL = 'UPls';
|
||||||
|
|
||||||
#endif // CONSTANTS_H
|
#endif // CONSTANTS_H
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ StyledEditApp::OpenDocument()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
StyledEditApp::OpenDocument(entry_ref* ref)
|
StyledEditApp::OpenDocument(entry_ref* ref, BMessage* message)
|
||||||
{
|
{
|
||||||
// traverse eventual symlink
|
// traverse eventual symlink
|
||||||
BEntry entry(ref, true);
|
BEntry entry(ref, true);
|
||||||
@ -217,13 +217,19 @@ StyledEditApp::OpenDocument(entry_ref* ref)
|
|||||||
if (document->Lock()) {
|
if (document->Lock()) {
|
||||||
document->Activate();
|
document->Activate();
|
||||||
document->Unlock();
|
document->Unlock();
|
||||||
|
if (message != NULL)
|
||||||
|
document->PostMessage(message);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cascade();
|
cascade();
|
||||||
new StyledEditWindow(gWindowRect, ref, fOpenAsEncoding);
|
document = new StyledEditWindow(gWindowRect, ref, fOpenAsEncoding);
|
||||||
|
|
||||||
|
if (message != NULL)
|
||||||
|
document->PostMessage(message);
|
||||||
|
|
||||||
fWindowCount++;
|
fWindowCount++;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@ -248,8 +254,31 @@ StyledEditApp::RefsReceived(BMessage* message)
|
|||||||
int32 index = 0;
|
int32 index = 0;
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
|
|
||||||
while (message->FindRef("refs", index++, &ref) == B_OK) {
|
while (message->FindRef("refs", index, &ref) == B_OK) {
|
||||||
OpenDocument(&ref);
|
int32 line;
|
||||||
|
if (message->FindInt32("be:line", index, &line) != B_OK)
|
||||||
|
line = -1;
|
||||||
|
int32 start, length;
|
||||||
|
if (message->FindInt32("be:selection_length", index, &length) != B_OK
|
||||||
|
|| message->FindInt32("be:selection_offset", index, &start) != B_OK)
|
||||||
|
{
|
||||||
|
start = -1;
|
||||||
|
length = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
BMessage* selMessage = NULL;
|
||||||
|
if (line >= 0 || (start >= 0 && length >= 0)) {
|
||||||
|
selMessage = new BMessage(UPDATE_LINE_SEL);
|
||||||
|
if (line >= 0)
|
||||||
|
selMessage->AddInt32("be:line", line);
|
||||||
|
if (start >= 0) {
|
||||||
|
selMessage->AddInt32("be:selection_offset", start);
|
||||||
|
selMessage->AddInt32("be:selection_length", max_c(0, length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenDocument(&ref, selMessage);
|
||||||
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,7 +338,7 @@ StyledEditApp::ReadyToRun()
|
|||||||
int32
|
int32
|
||||||
StyledEditApp::NumberOfWindows()
|
StyledEditApp::NumberOfWindows()
|
||||||
{
|
{
|
||||||
return fWindowCount;
|
return fWindowCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,8 @@ public:
|
|||||||
|
|
||||||
int32 NumberOfWindows();
|
int32 NumberOfWindows();
|
||||||
void OpenDocument();
|
void OpenDocument();
|
||||||
status_t OpenDocument(entry_ref* ref);
|
status_t OpenDocument(entry_ref* ref,
|
||||||
|
BMessage* message = NULL);
|
||||||
void CloseDocument();
|
void CloseDocument();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -535,6 +535,24 @@ StyledEditWindow::MessageReceived(BMessage* message)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case UPDATE_LINE_SEL:
|
||||||
|
{
|
||||||
|
int32 line;
|
||||||
|
if (message->FindInt32("be:line", &line) == B_OK) {
|
||||||
|
fTextView->GoToLine(line);
|
||||||
|
fTextView->ScrollToSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 start, length;
|
||||||
|
if (message->FindInt32("be:selection_offset", &start) == B_OK) {
|
||||||
|
if (message->FindInt32("be:selection_length", &length) != B_OK)
|
||||||
|
length = 0;
|
||||||
|
|
||||||
|
fTextView->Select(start, start + length);
|
||||||
|
fTextView->ScrollToOffset(start);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
@ -867,7 +885,6 @@ StyledEditWindow::OpenFile(entry_ref* ref)
|
|||||||
|
|
||||||
fReloadItem->SetEnabled(fSaveMessage != NULL);
|
fReloadItem->SetEnabled(fSaveMessage != NULL);
|
||||||
fEncodingItem->SetEnabled(fSaveMessage != NULL);
|
fEncodingItem->SetEnabled(fSaveMessage != NULL);
|
||||||
fTextView->Select(0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1318,6 +1335,33 @@ StyledEditWindow::_LoadAttrs()
|
|||||||
MoveTo(newFrame.left, newFrame.top);
|
MoveTo(newFrame.left, newFrame.top);
|
||||||
ResizeTo(newFrame.Width(), newFrame.Height());
|
ResizeTo(newFrame.Width(), newFrame.Height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// info about position of caret may live in the file attributes
|
||||||
|
int32 line = 0;
|
||||||
|
int32 lineMax = fTextView->CountLines();
|
||||||
|
if (documentNode.ReadAttr("be:line",
|
||||||
|
B_INT32_TYPE, 0, &line, sizeof(line)) == sizeof(line))
|
||||||
|
line = min_c(max_c(0, line), lineMax);
|
||||||
|
else
|
||||||
|
line = 0;
|
||||||
|
|
||||||
|
int32 start = 0, length = 0, finish = 0;
|
||||||
|
int32 offsetMax = fTextView->OffsetAt(lineMax);
|
||||||
|
if (documentNode.ReadAttr("be:selection_offset",
|
||||||
|
B_INT32_TYPE, 0, &start, sizeof(start)) == sizeof(start)
|
||||||
|
&& documentNode.ReadAttr("be:selection_length",
|
||||||
|
B_INT32_TYPE, 0, &length, sizeof(length)) == sizeof(length))
|
||||||
|
{
|
||||||
|
finish = start + length;
|
||||||
|
start = min_c(max_c(0, start), offsetMax);
|
||||||
|
finish = min_c(max_c(0, finish), offsetMax);
|
||||||
|
} else {
|
||||||
|
start = fTextView->OffsetAt(line);
|
||||||
|
finish = start;
|
||||||
|
}
|
||||||
|
|
||||||
|
fTextView->Select(start, finish);
|
||||||
|
fTextView->ScrollToOffset(start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1345,6 +1389,18 @@ StyledEditWindow::_SaveAttrs()
|
|||||||
|
|
||||||
documentNode.WriteAttr(kInfoAttributeName, B_RECT_TYPE, 0, &frame,
|
documentNode.WriteAttr(kInfoAttributeName, B_RECT_TYPE, 0, &frame,
|
||||||
sizeof(BRect));
|
sizeof(BRect));
|
||||||
|
|
||||||
|
// preserve current line and selection too
|
||||||
|
int32 line = fTextView->CurrentLine();
|
||||||
|
documentNode.WriteAttr("be:line", B_INT32_TYPE, 0, &line, sizeof(line));
|
||||||
|
|
||||||
|
int32 start, end;
|
||||||
|
fTextView->GetSelection(&start, &end);
|
||||||
|
int32 length = end - start;
|
||||||
|
documentNode.WriteAttr("be:selection_offset",
|
||||||
|
B_INT32_TYPE, 0, &start, sizeof(start));
|
||||||
|
documentNode.WriteAttr("be:selection_length",
|
||||||
|
B_INT32_TYPE, 0, &length, sizeof(length));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user