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 zhuowei, 6 years ago)

Adds a simple console window

  • 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  
    4848#include "DownloadWindow.h"
    4949#include "SettingsMessage.h"
    5050#include "SettingsWindow.h"
     51#include "ConsoleWindow.h"
    5152#include "NetworkCookieJar.h"
    5253#include "WebKitInfo.h"
    5354#include "WebPage.h"
    5455#include "WebSettings.h"
    5556#include "WebView.h"
     57#include "WebViewConstants.h"
    5658
    5759
    5860#undef B_TRANSLATION_CONTEXT
    BrowserApp::BrowserApp()  
    7678    fCookies(NULL),
    7779    fContext(NULL),
    7880    fDownloadWindow(NULL),
    79     fSettingsWindow(NULL)
     81    fSettingsWindow(NULL),
     82    fConsoleWindow(NULL)
    8083{
    8184#if ENABLE_NATIVE_COOKIES
    8285    BString cookieStorePath = kApplicationName;
    BrowserApp::ReadyToRun()  
    181184        defaultDownloadWindowFrame);
    182185    BRect settingsWindowFrame = fSettings->GetValue("settings window frame",
    183186        BRect());
     187    BRect consoleWindowFrame = fSettings->GetValue("console window frame",
     188        BRect(50, 50, 400, 300));
    184189    bool showDownloads = fSettings->GetValue("show downloads", false);
    185190
    186191    fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads,
    BrowserApp::ReadyToRun()  
    201206    fSettingsWindow = new SettingsWindow(settingsWindowFrame, fSettings);
    202207
    203208    BWebPage::SetDownloadListener(BMessenger(fDownloadWindow));
     209   
     210    fConsoleWindow = new ConsoleWindow(consoleWindowFrame);
    204211
    205212    fInitialized = true;
    206213
    BrowserApp::MessageReceived(BMessage* message)  
    265272    case SHOW_SETTINGS_WINDOW:
    266273        _ShowWindow(message, fSettingsWindow);
    267274        break;
     275    case SHOW_CONSOLE_WINDOW:
     276        _ShowWindow(message, fConsoleWindow);
     277        break;
     278    case ADD_CONSOLE_MESSAGE:
     279        fConsoleWindow->PostMessage(message);
     280        break;
    268281
    269282    default:
    270283        BApplication::MessageReceived(message);
    BrowserApp::QuitRequested()  
    340353        fSettings->SetValue("settings window frame", fSettingsWindow->Frame());
    341354        fSettingsWindow->Unlock();
    342355    }
     356   
     357    if (fConsoleWindow->Lock()) {
     358        fSettings->SetValue("console window frame", fConsoleWindow->Frame());
     359        fConsoleWindow->Unlock();
     360    }
    343361
    344362    BMessage cookieArchive;
    345363    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;  
    4040class BrowserWindow;
    4141class SettingsMessage;
    4242class SettingsWindow;
     43class ConsoleWindow;
    4344
    4445
    4546class BrowserApp : public BApplication {
    private:  
    8182
    8283            DownloadWindow*     fDownloadWindow;
    8384            SettingsWindow*     fSettingsWindow;
     85            ConsoleWindow*      fConsoleWindow;
    8486};
    8587
    8688
  • 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,  
    397397        new BMessage(SHOW_DOWNLOAD_WINDOW), 'D'));
    398398    menu->AddItem(new BMenuItem(B_TRANSLATE("Settings"),
    399399        new BMessage(SHOW_SETTINGS_WINDOW)));
     400    menu->AddItem(new BMenuItem(B_TRANSLATE("Script console"),
     401        new BMessage(SHOW_CONSOLE_WINDOW)));   
    400402    BMenuItem* aboutItem = new BMenuItem(B_TRANSLATE("About"),
    401403        new BMessage(B_ABOUT_REQUESTED));
    402404    menu->AddItem(aboutItem);
    BrowserWindow::MessageReceived(BMessage* message)  
    10061008
    10071009        case SHOW_DOWNLOAD_WINDOW:
    10081010        case SHOW_SETTINGS_WINDOW:
     1011        case SHOW_CONSOLE_WINDOW:
    10091012            message->AddUInt32("workspaces", Workspaces());
    10101013            be_app->PostMessage(message);
    10111014            break;
    BrowserWindow::MessageReceived(BMessage* message)  
    10871090            }
    10881091            break;
    10891092        }
     1093        case ADD_CONSOLE_MESSAGE:
     1094            be_app->PostMessage(message);
     1095            BWebWindow::MessageReceived(message);
     1096            break;
    10901097
    10911098        default:
    10921099            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 {  
    8080    WINDOW_OPENED                   = 'wndo',
    8181    WINDOW_CLOSED                   = 'wndc',
    8282    SHOW_DOWNLOAD_WINDOW            = 'sdwd',
    83     SHOW_SETTINGS_WINDOW            = 'sswd'
     83    SHOW_SETTINGS_WINDOW            = 'sswd',
     84    SHOW_CONSOLE_WINDOW             = 'scwd'
    8485};
    8586
    8687#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
     30enum {
     31    EVAL_CONSOLE_WINDOW_COMMAND = 'ecwc',
     32    CLEAR_CONSOLE_MESSAGES = 'ccms'
     33};
     34
     35
     36ConsoleWindow::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
     63void
     64ConsoleWindow::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
     94bool
     95ConsoleWindow::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
     16class BListView;
     17class BButton;
     18
     19
     20class ConsoleWindow : public BWindow {
     21public:
     22                                ConsoleWindow(BRect frame);
     23    virtual void                MessageReceived(BMessage* message);
     24    virtual bool                QuitRequested();
     25private:
     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 =  
    3737    SettingsKeys.cpp
    3838    SettingsWindow.cpp
    3939    URLInputGroup.cpp
     40    ConsoleWindow.cpp
    4041;
    4142
    4243# We build WebPositive only for one architecture -- the first architecture for