2 * Copyright 2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
8 #include "ConsoleWindow.h"
13 #include <GroupLayout.h>
14 #include <GroupLayoutBuilder.h>
15 #include <LayoutBuilder.h>
16 #include <SeparatorView.h>
17 #include <TextControl.h>
19 #include <ScrollView.h>
21 #include "BrowserWindow.h"
22 #include "BrowserApp.h"
23 #include "WebViewConstants.h"
26 #undef B_TRANSLATION_CONTEXT
27 #define B_TRANSLATION_CONTEXT "Console Window"
31 EVAL_CONSOLE_WINDOW_COMMAND
= 'ecwc',
32 CLEAR_CONSOLE_MESSAGES
= 'ccms'
36 ConsoleWindow::ConsoleWindow(BRect frame
)
38 BWindow(frame
, B_TRANSLATE("Script console"), B_TITLED_WINDOW
,
39 B_NORMAL_WINDOW_FEEL
, B_AUTO_UPDATE_SIZE_LIMITS
40 | B_ASYNCHRONOUS_CONTROLS
| B_NOT_ZOOMABLE
)
42 SetLayout(new BGroupLayout(B_VERTICAL
, 0.0));
44 fMessagesListView
= new BListView("Console messages");
45 fClearMessagesButton
= new BButton(B_TRANSLATE("Clear"),
46 new BMessage(CLEAR_CONSOLE_MESSAGES
));
48 AddChild(BGroupLayoutBuilder(B_VERTICAL
, 0.0)
49 .Add(new BScrollView("Console messages scroll",
50 fMessagesListView
, 0, true, true))
51 .Add(new BSeparatorView(B_HORIZONTAL
, B_PLAIN_BORDER
))
52 .Add(BGroupLayoutBuilder(B_HORIZONTAL
, B_USE_SMALL_SPACING
)
53 .Add(fClearMessagesButton
)
54 .SetInsets(0, 5, 0, 5)
56 .SetInsets(5, 5, 5, 5)
64 ConsoleWindow::MessageReceived(BMessage
* message
)
66 switch (message
->what
) {
67 case ADD_CONSOLE_MESSAGE
:
69 BString source
= message
->FindString("source");
70 int32 lineNumber
= message
->FindInt32("line");
71 int32 columnNumber
= message
->FindInt32("column");
72 BString text
= message
->FindString("string");
74 finalText
.SetToFormat("%s:%" B_PRIi32
":%" B_PRIi32
": %s\n",
75 source
.String(), lineNumber
, columnNumber
, text
.String());
76 fMessagesListView
->AddItem(new BStringItem(finalText
.String()));
79 case CLEAR_CONSOLE_MESSAGES
:
81 int count
= fMessagesListView
->CountItems();
82 for (int i
= count
- 1; i
>= 0; i
--) {
83 delete fMessagesListView
->RemoveItem(i
);
88 BWindow::MessageReceived(message
);
95 ConsoleWindow::QuitRequested()