btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / webpositive / ConsoleWindow.cpp
blob5e69b4d0bcdc6852e125a48fcebd16d8334d5fd4
1 /*
2 * Copyright 2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Zhuowei Zhang
7 */
8 #include "ConsoleWindow.h"
10 #include <Catalog.h>
11 #include <Message.h>
12 #include <Button.h>
13 #include <GroupLayout.h>
14 #include <GroupLayoutBuilder.h>
15 #include <LayoutBuilder.h>
16 #include <SeparatorView.h>
17 #include <TextControl.h>
18 #include <ListView.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"
30 enum {
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)
58 if (!frame.IsValid())
59 CenterOnScreen();
63 void
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");
73 BString finalText;
74 finalText.SetToFormat("%s:%" B_PRIi32 ":%" B_PRIi32 ": %s\n",
75 source.String(), lineNumber, columnNumber, text.String());
76 fMessagesListView->AddItem(new BStringItem(finalText.String()));
77 break;
79 case CLEAR_CONSOLE_MESSAGES:
81 int count = fMessagesListView->CountItems();
82 for (int i = count - 1; i >= 0; i--) {
83 delete fMessagesListView->RemoveItem(i);
85 break;
87 default:
88 BWindow::MessageReceived(message);
89 break;
94 bool
95 ConsoleWindow::QuitRequested()
97 if (!IsHidden())
98 Hide();
99 return false;