Ticket #10410: 0001-Added-a-simple-window-to-display-console-messages-fi.patch
File 0001-Added-a-simple-window-to-display-console-messages-fi.patch, 8.8 KB (added by , 10 years ago) |
---|
-
src/apps/webpositive/BrowserApp.cpp
From d819d52f7c0d4755a9b64281952069052acc336a Mon Sep 17 00:00:00 2001 From: Zhuowei Zhang <zhuoweizhang@yahoo.com> Date: Sun, 16 Mar 2014 20:46:57 -0400 Subject: [PATCH] Added a simple window to display console messages (fixes #10410) --- src/apps/webpositive/BrowserApp.cpp | 20 ++++++- src/apps/webpositive/BrowserApp.h | 2 + src/apps/webpositive/BrowserWindow.cpp | 7 +++ src/apps/webpositive/BrowserWindow.h | 3 +- src/apps/webpositive/ConsoleWindow.cpp | 100 +++++++++++++++++++++++++++++++++ src/apps/webpositive/ConsoleWindow.h | 31 ++++++++++ src/apps/webpositive/Jamfile | 1 + 7 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 src/apps/webpositive/ConsoleWindow.cpp create mode 100644 src/apps/webpositive/ConsoleWindow.h diff --git a/src/apps/webpositive/BrowserApp.cpp b/src/apps/webpositive/BrowserApp.cpp index ba6f50b..bd419ea 100644
a b 48 48 #include "DownloadWindow.h" 49 49 #include "SettingsMessage.h" 50 50 #include "SettingsWindow.h" 51 #include "ConsoleWindow.h" 51 52 #include "NetworkCookieJar.h" 52 53 #include "WebKitInfo.h" 53 54 #include "WebPage.h" 54 55 #include "WebSettings.h" 55 56 #include "WebView.h" 57 #include "WebViewConstants.h" 56 58 57 59 58 60 #undef B_TRANSLATION_CONTEXT … … BrowserApp::BrowserApp() 76 78 fCookies(NULL), 77 79 fContext(NULL), 78 80 fDownloadWindow(NULL), 79 fSettingsWindow(NULL) 81 fSettingsWindow(NULL), 82 fConsoleWindow(NULL) 80 83 { 81 84 #if ENABLE_NATIVE_COOKIES 82 85 BString cookieStorePath = kApplicationName; … … BrowserApp::ReadyToRun() 181 184 defaultDownloadWindowFrame); 182 185 BRect settingsWindowFrame = fSettings->GetValue("settings window frame", 183 186 BRect()); 187 BRect consoleWindowFrame = fSettings->GetValue("console window frame", 188 BRect(50, 50, 400, 300)); 184 189 bool showDownloads = fSettings->GetValue("show downloads", false); 185 190 186 191 fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads, … … BrowserApp::ReadyToRun() 201 206 fSettingsWindow = new SettingsWindow(settingsWindowFrame, fSettings); 202 207 203 208 BWebPage::SetDownloadListener(BMessenger(fDownloadWindow)); 209 210 fConsoleWindow = new ConsoleWindow(consoleWindowFrame); 204 211 205 212 fInitialized = true; 206 213 … … BrowserApp::MessageReceived(BMessage* message) 265 272 case SHOW_SETTINGS_WINDOW: 266 273 _ShowWindow(message, fSettingsWindow); 267 274 break; 275 case SHOW_CONSOLE_WINDOW: 276 _ShowWindow(message, fConsoleWindow); 277 break; 278 case ADD_CONSOLE_MESSAGE: 279 fConsoleWindow->PostMessage(message); 280 break; 268 281 269 282 default: 270 283 BApplication::MessageReceived(message); … … BrowserApp::QuitRequested() 340 353 fSettings->SetValue("settings window frame", fSettingsWindow->Frame()); 341 354 fSettingsWindow->Unlock(); 342 355 } 356 357 if (fConsoleWindow->Lock()) { 358 fSettings->SetValue("console window frame", fConsoleWindow->Frame()); 359 fConsoleWindow->Unlock(); 360 } 343 361 344 362 BMessage cookieArchive; 345 363 BNetworkCookieJar& cookieJar = fContext->GetCookieJar(); -
src/apps/webpositive/BrowserApp.h
diff --git a/src/apps/webpositive/BrowserApp.h b/src/apps/webpositive/BrowserApp.h index 937cd05..baf4fb1 100644
a b class DownloadWindow; 40 40 class BrowserWindow; 41 41 class SettingsMessage; 42 42 class SettingsWindow; 43 class ConsoleWindow; 43 44 44 45 45 46 class BrowserApp : public BApplication { … … private: 81 82 82 83 DownloadWindow* fDownloadWindow; 83 84 SettingsWindow* fSettingsWindow; 85 ConsoleWindow* fConsoleWindow; 84 86 }; 85 87 86 88 -
src/apps/webpositive/BrowserWindow.cpp
diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index 71bd484..7993691 100644
a b BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings, 397 397 new BMessage(SHOW_DOWNLOAD_WINDOW), 'D')); 398 398 menu->AddItem(new BMenuItem(B_TRANSLATE("Settings"), 399 399 new BMessage(SHOW_SETTINGS_WINDOW))); 400 menu->AddItem(new BMenuItem(B_TRANSLATE("Script console"), 401 new BMessage(SHOW_CONSOLE_WINDOW))); 400 402 BMenuItem* aboutItem = new BMenuItem(B_TRANSLATE("About"), 401 403 new BMessage(B_ABOUT_REQUESTED)); 402 404 menu->AddItem(aboutItem); … … BrowserWindow::MessageReceived(BMessage* message) 1006 1008 1007 1009 case SHOW_DOWNLOAD_WINDOW: 1008 1010 case SHOW_SETTINGS_WINDOW: 1011 case SHOW_CONSOLE_WINDOW: 1009 1012 message->AddUInt32("workspaces", Workspaces()); 1010 1013 be_app->PostMessage(message); 1011 1014 break; … … BrowserWindow::MessageReceived(BMessage* message) 1087 1090 } 1088 1091 break; 1089 1092 } 1093 case ADD_CONSOLE_MESSAGE: 1094 be_app->PostMessage(message); 1095 BWebWindow::MessageReceived(message); 1096 break; 1090 1097 1091 1098 default: 1092 1099 BWebWindow::MessageReceived(message); -
src/apps/webpositive/BrowserWindow.h
diff --git a/src/apps/webpositive/BrowserWindow.h b/src/apps/webpositive/BrowserWindow.h index e9840b4..8b2093a 100644
a b enum { 80 80 WINDOW_OPENED = 'wndo', 81 81 WINDOW_CLOSED = 'wndc', 82 82 SHOW_DOWNLOAD_WINDOW = 'sdwd', 83 SHOW_SETTINGS_WINDOW = 'sswd' 83 SHOW_SETTINGS_WINDOW = 'sswd', 84 SHOW_CONSOLE_WINDOW = 'scwd' 84 85 }; 85 86 86 87 #define INTEGRATE_MENU_INTO_TAB_BAR 0 -
new file src/apps/webpositive/ConsoleWindow.cpp
diff --git a/src/apps/webpositive/ConsoleWindow.cpp b/src/apps/webpositive/ConsoleWindow.cpp new file mode 100644 index 0000000..19d01fa
- + 1 /* 2 * Copyright 2014 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Zhuowei Zhang 7 */ 8 #include "ConsoleWindow.h" 9 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> 20 21 #include "BrowserWindow.h" 22 #include "BrowserApp.h" 23 #include "WebViewConstants.h" 24 25 26 #undef B_TRANSLATION_CONTEXT 27 #define B_TRANSLATION_CONTEXT "Console Window" 28 29 30 enum { 31 EVAL_CONSOLE_WINDOW_COMMAND = 'ecwc', 32 CLEAR_CONSOLE_MESSAGES = 'ccms' 33 }; 34 35 36 ConsoleWindow::ConsoleWindow(BRect frame) 37 : 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) 41 { 42 SetLayout(new BGroupLayout(B_VERTICAL, 0.0)); 43 44 fMessagesListView = new BListView("Console messages"); 45 fClearMessagesButton = new BButton(B_TRANSLATE("Clear"), 46 new BMessage(CLEAR_CONSOLE_MESSAGES)); 47 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) 55 ) 56 .SetInsets(5, 5, 5, 5) 57 ); 58 if (!frame.IsValid()) 59 CenterOnScreen(); 60 } 61 62 63 void 64 ConsoleWindow::MessageReceived(BMessage* message) 65 { 66 switch (message->what) { 67 case ADD_CONSOLE_MESSAGE: 68 { 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:%li:%li: %s\n", source.String(), lineNumber, 75 columnNumber, text.String()); 76 fMessagesListView->AddItem(new BStringItem(finalText.String())); 77 break; 78 } 79 case CLEAR_CONSOLE_MESSAGES: 80 { 81 int count = fMessagesListView->CountItems(); 82 for (int i = count - 1; i >= 0; i--) { 83 delete fMessagesListView->RemoveItem(i); 84 } 85 break; 86 } 87 default: 88 BWindow::MessageReceived(message); 89 break; 90 } 91 } 92 93 94 bool 95 ConsoleWindow::QuitRequested() 96 { 97 if (!IsHidden()) 98 Hide(); 99 return false; 100 } -
new file src/apps/webpositive/ConsoleWindow.h
diff --git a/src/apps/webpositive/ConsoleWindow.h b/src/apps/webpositive/ConsoleWindow.h new file mode 100644 index 0000000..66d62a8
- + 1 /* 2 * Copyright 2014 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Zhuowei Zhang 7 */ 8 #ifndef CONSOLE_WINDOW_H 9 #define CONSOLE_WINDOW_H 10 11 12 #include <String.h> 13 #include <Window.h> 14 15 16 class BListView; 17 class BButton; 18 19 20 class ConsoleWindow : public BWindow { 21 public: 22 ConsoleWindow(BRect frame); 23 virtual void MessageReceived(BMessage* message); 24 virtual bool QuitRequested(); 25 private: 26 BListView* fMessagesListView; 27 BButton* fClearMessagesButton; 28 }; 29 30 31 #endif // CONSOLE_WINDOW_H -
src/apps/webpositive/Jamfile
diff --git a/src/apps/webpositive/Jamfile b/src/apps/webpositive/Jamfile index ea555ff..d6986be 100644
a b local sources = 37 37 SettingsKeys.cpp 38 38 SettingsWindow.cpp 39 39 URLInputGroup.cpp 40 ConsoleWindow.cpp 40 41 ; 41 42 42 43 # We build WebPositive only for one architecture -- the first architecture for