Web+ console: Show count of repeated lines
In order not to fill up the console with identical strings, show a count of the repeated lines instead. When the console is cleared, make sure the repeating line is inserted by resetting the fPreviousText. Plus a minor style fix. Change-Id: I408a24e59a04c9e51d4ede3f272f7ca23a19b432 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6206 Tested-by: Automation <[email protected]> Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2021 Haiku, Inc. All rights reserved.
|
* Copyright 2014-2023 Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <GroupLayoutBuilder.h>
|
#include <GroupLayoutBuilder.h>
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <SeparatorView.h>
|
#include <SeparatorView.h>
|
||||||
|
#include <StringFormat.h>
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
#include <ListView.h>
|
#include <ListView.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
@@ -39,7 +40,9 @@ ConsoleWindow::ConsoleWindow(BRect frame)
|
|||||||
:
|
:
|
||||||
BWindow(frame, B_TRANSLATE("Script console"), B_TITLED_WINDOW,
|
BWindow(frame, B_TRANSLATE("Script console"), B_TITLED_WINDOW,
|
||||||
B_NORMAL_WINDOW_FEEL, B_AUTO_UPDATE_SIZE_LIMITS
|
B_NORMAL_WINDOW_FEEL, B_AUTO_UPDATE_SIZE_LIMITS
|
||||||
| B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
|
| B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE),
|
||||||
|
fPreviousText(""),
|
||||||
|
fRepeatCounter(0)
|
||||||
{
|
{
|
||||||
SetLayout(new BGroupLayout(B_VERTICAL, 0.0));
|
SetLayout(new BGroupLayout(B_VERTICAL, 0.0));
|
||||||
|
|
||||||
@@ -81,15 +84,34 @@ ConsoleWindow::MessageReceived(BMessage* message)
|
|||||||
BString finalText;
|
BString finalText;
|
||||||
finalText.SetToFormat("%s:%" B_PRIi32 ":%" B_PRIi32 ": %s\n",
|
finalText.SetToFormat("%s:%" B_PRIi32 ":%" B_PRIi32 ": %s\n",
|
||||||
source.String(), lineNumber, columnNumber, text.String());
|
source.String(), lineNumber, columnNumber, text.String());
|
||||||
|
|
||||||
|
if (finalText == fPreviousText) {
|
||||||
|
finalText = "";
|
||||||
|
static BStringFormat format(B_TRANSLATE("{0, plural,"
|
||||||
|
"one{Last line repeated # time.}"
|
||||||
|
"other{Last line repeated # times.}}"));
|
||||||
|
format.Format(finalText, ++fRepeatCounter);
|
||||||
|
// preserve the repeated line
|
||||||
|
if (fRepeatCounter > 1) {
|
||||||
|
int32 index = fMessagesListView->CountItems() - 1;
|
||||||
|
BStringItem* item = (BStringItem*)fMessagesListView->ItemAt(index);
|
||||||
|
item->SetText(finalText.String());
|
||||||
|
fMessagesListView->InvalidateItem(index);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fPreviousText = finalText;
|
||||||
|
fRepeatCounter = 0;
|
||||||
|
}
|
||||||
fMessagesListView->AddItem(new BStringItem(finalText.String()));
|
fMessagesListView->AddItem(new BStringItem(finalText.String()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CLEAR_CONSOLE_MESSAGES:
|
case CLEAR_CONSOLE_MESSAGES:
|
||||||
{
|
{
|
||||||
|
fPreviousText = "";
|
||||||
int count = fMessagesListView->CountItems();
|
int count = fMessagesListView->CountItems();
|
||||||
for (int i = count - 1; i >= 0; i--) {
|
for (int i = count - 1; i >= 0; i--)
|
||||||
delete fMessagesListView->RemoveItem(i);
|
delete fMessagesListView->RemoveItem(i);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case B_COPY:
|
case B_COPY:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2021 Haiku, Inc. All rights reserved.
|
* Copyright 2014-2023 Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -31,6 +31,8 @@ private:
|
|||||||
BListView* fMessagesListView;
|
BListView* fMessagesListView;
|
||||||
BButton* fClearMessagesButton;
|
BButton* fClearMessagesButton;
|
||||||
BButton* fCopyMessagesButton;
|
BButton* fCopyMessagesButton;
|
||||||
|
BString fPreviousText;
|
||||||
|
int32 fRepeatCounter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user