Patch by Bryce Groff: add line number display to StyledEdit. Fixes ticket #2623. It does however expose an interesting curiosity in BTextView - CurrentLine() does not count a line until it's actually had some text put into it (i.e. simply hitting enter at the last line of the doc does not increment the number that CurrentLine() returns. Is this an oversight or does R5 behave this way also?
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29782 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
973032b8d7
commit
8e26769c8b
@ -75,5 +75,8 @@ const uint32 OPEN_AS_ENCODING = 'FPoe';
|
||||
const uint32 SAVE_AS_ENCODING = 'FPse';
|
||||
const uint32 SAVE_THEN_QUIT = 'FPsq';
|
||||
|
||||
// Update Line Info
|
||||
const uint32 UPDATE_LINE = 'UPln';
|
||||
|
||||
#endif // CONSTANTS_H
|
||||
|
||||
|
@ -49,8 +49,8 @@ void
|
||||
StyledEditView::Select(int32 start, int32 finish)
|
||||
{
|
||||
fMessenger->SendMessage(start == finish ? DISABLE_ITEMS : ENABLE_ITEMS);
|
||||
|
||||
BTextView::Select(start, finish);
|
||||
fMessenger->SendMessage(UPDATE_LINE);
|
||||
BTextView::Select(start, finish);
|
||||
}
|
||||
|
||||
|
||||
@ -169,6 +169,7 @@ StyledEditView::DeleteText(int32 start, int32 finish)
|
||||
fMessenger-> SendMessage(TEXT_CHANGED);
|
||||
|
||||
BTextView::DeleteText(start, finish);
|
||||
fMessenger->SendMessage(UPDATE_LINE);
|
||||
}
|
||||
|
||||
|
||||
@ -179,7 +180,8 @@ StyledEditView::InsertText(const char *text, int32 length, int32 offset,
|
||||
if (!fSuppressChanges)
|
||||
fMessenger->SendMessage(TEXT_CHANGED);
|
||||
|
||||
BTextView::InsertText(text, length, offset, runs);
|
||||
BTextView::InsertText(text, length, offset, runs);
|
||||
fMessenger->SendMessage(UPDATE_LINE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,13 +31,14 @@
|
||||
#include <Rect.h>
|
||||
#include <Roster.h>
|
||||
#include <ScrollView.h>
|
||||
#include <StringView.h>
|
||||
#include <TextControl.h>
|
||||
#include <TextView.h>
|
||||
#include <TranslationUtils.h>
|
||||
|
||||
|
||||
using namespace BPrivate;
|
||||
|
||||
const float kLineViewWidth = 30.0;
|
||||
|
||||
StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding)
|
||||
: BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
|
||||
@ -118,9 +119,17 @@ StyledEditWindow::InitWindow(uint32 encoding)
|
||||
true, true, B_PLAIN_BORDER);
|
||||
AddChild(fScrollView);
|
||||
fTextView->MakeFocus(true);
|
||||
|
||||
|
||||
BScrollBar* HScrollBar = fScrollView->ScrollBar(B_HORIZONTAL);
|
||||
HScrollBar->MoveBy(kLineViewWidth + 1, 0);
|
||||
HScrollBar->ResizeBy((-1 * kLineViewWidth) - 1, 0);
|
||||
|
||||
fStringView = new BStringView(BRect(0,0,kLineViewWidth,B_H_SCROLL_BAR_HEIGHT), "stringview", "1", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
|
||||
fStringView->SetAlignment(B_ALIGN_CENTER);
|
||||
fScrollView->AddChild(fStringView);
|
||||
fStringView->MoveTo(0.0, HScrollBar->Frame().top);
|
||||
|
||||
// Add "File"-menu:
|
||||
|
||||
BMenu* menu = new BMenu("File");
|
||||
fMenuBar->AddItem(menu);
|
||||
|
||||
@ -533,6 +542,11 @@ StyledEditWindow::MessageReceived(BMessage *message)
|
||||
fCopyItem->SetEnabled(false);
|
||||
fClearItem->SetEnabled(false);
|
||||
break;
|
||||
case UPDATE_LINE:
|
||||
char buf[20];
|
||||
sprintf(buf, "%ld", fTextView->CurrentLine() + 1);
|
||||
fStringView->SetText(buf);
|
||||
break;
|
||||
case TEXT_CHANGED:
|
||||
if (fUndoFlag) {
|
||||
if (fUndoCleans) {
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include <String.h>
|
||||
#include <Message.h>
|
||||
|
||||
|
||||
struct entry_ref;
|
||||
|
||||
class BMenu;
|
||||
@ -24,6 +23,7 @@ class BMenuBar;
|
||||
class BMenuItem;
|
||||
class BFilePanel;
|
||||
class BScrollView;
|
||||
class BStringView;
|
||||
class StyledEditView;
|
||||
|
||||
|
||||
@ -116,6 +116,7 @@ class StyledEditWindow : public BWindow {
|
||||
|
||||
StyledEditView *fTextView;
|
||||
BScrollView *fScrollView;
|
||||
BStringView *fStringView;
|
||||
|
||||
BFilePanel *fSavePanel;
|
||||
BMenu *fSavePanelEncodingMenu;
|
||||
|
Loading…
Reference in New Issue
Block a user