Added a simple window to display console messages (fixes #10410)
Signed-off-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
449d68282f
commit
8512f7b056
@@ -48,11 +48,13 @@
|
|||||||
#include "DownloadWindow.h"
|
#include "DownloadWindow.h"
|
||||||
#include "SettingsMessage.h"
|
#include "SettingsMessage.h"
|
||||||
#include "SettingsWindow.h"
|
#include "SettingsWindow.h"
|
||||||
|
#include "ConsoleWindow.h"
|
||||||
#include "NetworkCookieJar.h"
|
#include "NetworkCookieJar.h"
|
||||||
#include "WebKitInfo.h"
|
#include "WebKitInfo.h"
|
||||||
#include "WebPage.h"
|
#include "WebPage.h"
|
||||||
#include "WebSettings.h"
|
#include "WebSettings.h"
|
||||||
#include "WebView.h"
|
#include "WebView.h"
|
||||||
|
#include "WebViewConstants.h"
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
#undef B_TRANSLATION_CONTEXT
|
||||||
@@ -76,7 +78,8 @@ BrowserApp::BrowserApp()
|
|||||||
fCookies(NULL),
|
fCookies(NULL),
|
||||||
fContext(NULL),
|
fContext(NULL),
|
||||||
fDownloadWindow(NULL),
|
fDownloadWindow(NULL),
|
||||||
fSettingsWindow(NULL)
|
fSettingsWindow(NULL),
|
||||||
|
fConsoleWindow(NULL)
|
||||||
{
|
{
|
||||||
#if ENABLE_NATIVE_COOKIES
|
#if ENABLE_NATIVE_COOKIES
|
||||||
BString cookieStorePath = kApplicationName;
|
BString cookieStorePath = kApplicationName;
|
||||||
@@ -181,6 +184,8 @@ BrowserApp::ReadyToRun()
|
|||||||
defaultDownloadWindowFrame);
|
defaultDownloadWindowFrame);
|
||||||
BRect settingsWindowFrame = fSettings->GetValue("settings window frame",
|
BRect settingsWindowFrame = fSettings->GetValue("settings window frame",
|
||||||
BRect());
|
BRect());
|
||||||
|
BRect consoleWindowFrame = fSettings->GetValue("console window frame",
|
||||||
|
BRect(50, 50, 400, 300));
|
||||||
bool showDownloads = fSettings->GetValue("show downloads", false);
|
bool showDownloads = fSettings->GetValue("show downloads", false);
|
||||||
|
|
||||||
fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads,
|
fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads,
|
||||||
@@ -202,6 +207,8 @@ BrowserApp::ReadyToRun()
|
|||||||
|
|
||||||
BWebPage::SetDownloadListener(BMessenger(fDownloadWindow));
|
BWebPage::SetDownloadListener(BMessenger(fDownloadWindow));
|
||||||
|
|
||||||
|
fConsoleWindow = new ConsoleWindow(consoleWindowFrame);
|
||||||
|
|
||||||
fInitialized = true;
|
fInitialized = true;
|
||||||
|
|
||||||
int32 pagesCreated = 0;
|
int32 pagesCreated = 0;
|
||||||
@@ -265,6 +272,12 @@ BrowserApp::MessageReceived(BMessage* message)
|
|||||||
case SHOW_SETTINGS_WINDOW:
|
case SHOW_SETTINGS_WINDOW:
|
||||||
_ShowWindow(message, fSettingsWindow);
|
_ShowWindow(message, fSettingsWindow);
|
||||||
break;
|
break;
|
||||||
|
case SHOW_CONSOLE_WINDOW:
|
||||||
|
_ShowWindow(message, fConsoleWindow);
|
||||||
|
break;
|
||||||
|
case ADD_CONSOLE_MESSAGE:
|
||||||
|
fConsoleWindow->PostMessage(message);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BApplication::MessageReceived(message);
|
BApplication::MessageReceived(message);
|
||||||
@@ -341,6 +354,11 @@ BrowserApp::QuitRequested()
|
|||||||
fSettingsWindow->Unlock();
|
fSettingsWindow->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fConsoleWindow->Lock()) {
|
||||||
|
fSettings->SetValue("console window frame", fConsoleWindow->Frame());
|
||||||
|
fConsoleWindow->Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
BMessage cookieArchive;
|
BMessage cookieArchive;
|
||||||
BNetworkCookieJar& cookieJar = fContext->GetCookieJar();
|
BNetworkCookieJar& cookieJar = fContext->GetCookieJar();
|
||||||
if (cookieJar.Archive(&cookieArchive) == B_OK)
|
if (cookieJar.Archive(&cookieArchive) == B_OK)
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ class DownloadWindow;
|
|||||||
class BrowserWindow;
|
class BrowserWindow;
|
||||||
class SettingsMessage;
|
class SettingsMessage;
|
||||||
class SettingsWindow;
|
class SettingsWindow;
|
||||||
|
class ConsoleWindow;
|
||||||
|
|
||||||
|
|
||||||
class BrowserApp : public BApplication {
|
class BrowserApp : public BApplication {
|
||||||
@@ -81,6 +82,7 @@ private:
|
|||||||
|
|
||||||
DownloadWindow* fDownloadWindow;
|
DownloadWindow* fDownloadWindow;
|
||||||
SettingsWindow* fSettingsWindow;
|
SettingsWindow* fSettingsWindow;
|
||||||
|
ConsoleWindow* fConsoleWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -397,6 +397,8 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
|
|||||||
new BMessage(SHOW_DOWNLOAD_WINDOW), 'D'));
|
new BMessage(SHOW_DOWNLOAD_WINDOW), 'D'));
|
||||||
menu->AddItem(new BMenuItem(B_TRANSLATE("Settings"),
|
menu->AddItem(new BMenuItem(B_TRANSLATE("Settings"),
|
||||||
new BMessage(SHOW_SETTINGS_WINDOW)));
|
new BMessage(SHOW_SETTINGS_WINDOW)));
|
||||||
|
menu->AddItem(new BMenuItem(B_TRANSLATE("Script console"),
|
||||||
|
new BMessage(SHOW_CONSOLE_WINDOW)));
|
||||||
BMenuItem* aboutItem = new BMenuItem(B_TRANSLATE("About"),
|
BMenuItem* aboutItem = new BMenuItem(B_TRANSLATE("About"),
|
||||||
new BMessage(B_ABOUT_REQUESTED));
|
new BMessage(B_ABOUT_REQUESTED));
|
||||||
menu->AddItem(aboutItem);
|
menu->AddItem(aboutItem);
|
||||||
@@ -1006,6 +1008,7 @@ BrowserWindow::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
case SHOW_DOWNLOAD_WINDOW:
|
case SHOW_DOWNLOAD_WINDOW:
|
||||||
case SHOW_SETTINGS_WINDOW:
|
case SHOW_SETTINGS_WINDOW:
|
||||||
|
case SHOW_CONSOLE_WINDOW:
|
||||||
message->AddUInt32("workspaces", Workspaces());
|
message->AddUInt32("workspaces", Workspaces());
|
||||||
be_app->PostMessage(message);
|
be_app->PostMessage(message);
|
||||||
break;
|
break;
|
||||||
@@ -1087,6 +1090,10 @@ BrowserWindow::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ADD_CONSOLE_MESSAGE:
|
||||||
|
be_app->PostMessage(message);
|
||||||
|
BWebWindow::MessageReceived(message);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWebWindow::MessageReceived(message);
|
BWebWindow::MessageReceived(message);
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ enum {
|
|||||||
WINDOW_OPENED = 'wndo',
|
WINDOW_OPENED = 'wndo',
|
||||||
WINDOW_CLOSED = 'wndc',
|
WINDOW_CLOSED = 'wndc',
|
||||||
SHOW_DOWNLOAD_WINDOW = 'sdwd',
|
SHOW_DOWNLOAD_WINDOW = 'sdwd',
|
||||||
SHOW_SETTINGS_WINDOW = 'sswd'
|
SHOW_SETTINGS_WINDOW = 'sswd',
|
||||||
|
SHOW_CONSOLE_WINDOW = 'scwd'
|
||||||
};
|
};
|
||||||
|
|
||||||
#define INTEGRATE_MENU_INTO_TAB_BAR 0
|
#define INTEGRATE_MENU_INTO_TAB_BAR 0
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Zhuowei Zhang
|
||||||
|
*/
|
||||||
|
#include "ConsoleWindow.h"
|
||||||
|
|
||||||
|
#include <Catalog.h>
|
||||||
|
#include <Message.h>
|
||||||
|
#include <Button.h>
|
||||||
|
#include <GroupLayout.h>
|
||||||
|
#include <GroupLayoutBuilder.h>
|
||||||
|
#include <LayoutBuilder.h>
|
||||||
|
#include <SeparatorView.h>
|
||||||
|
#include <TextControl.h>
|
||||||
|
#include <ListView.h>
|
||||||
|
#include <ScrollView.h>
|
||||||
|
|
||||||
|
#include "BrowserWindow.h"
|
||||||
|
#include "BrowserApp.h"
|
||||||
|
#include "WebViewConstants.h"
|
||||||
|
|
||||||
|
|
||||||
|
#undef B_TRANSLATION_CONTEXT
|
||||||
|
#define B_TRANSLATION_CONTEXT "Console Window"
|
||||||
|
|
||||||
|
|
||||||
|
enum {
|
||||||
|
EVAL_CONSOLE_WINDOW_COMMAND = 'ecwc',
|
||||||
|
CLEAR_CONSOLE_MESSAGES = 'ccms'
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
ConsoleWindow::ConsoleWindow(BRect frame)
|
||||||
|
:
|
||||||
|
BWindow(frame, B_TRANSLATE("Script console"), B_TITLED_WINDOW,
|
||||||
|
B_NORMAL_WINDOW_FEEL, B_AUTO_UPDATE_SIZE_LIMITS
|
||||||
|
| B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
|
||||||
|
{
|
||||||
|
SetLayout(new BGroupLayout(B_VERTICAL, 0.0));
|
||||||
|
|
||||||
|
fMessagesListView = new BListView("Console messages");
|
||||||
|
fClearMessagesButton = new BButton(B_TRANSLATE("Clear"),
|
||||||
|
new BMessage(CLEAR_CONSOLE_MESSAGES));
|
||||||
|
|
||||||
|
AddChild(BGroupLayoutBuilder(B_VERTICAL, 0.0)
|
||||||
|
.Add(new BScrollView("Console messages scroll",
|
||||||
|
fMessagesListView, 0, true, true))
|
||||||
|
.Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER))
|
||||||
|
.Add(BGroupLayoutBuilder(B_HORIZONTAL, B_USE_SMALL_SPACING)
|
||||||
|
.Add(fClearMessagesButton)
|
||||||
|
.SetInsets(0, 5, 0, 5)
|
||||||
|
)
|
||||||
|
.SetInsets(5, 5, 5, 5)
|
||||||
|
);
|
||||||
|
if (!frame.IsValid())
|
||||||
|
CenterOnScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ConsoleWindow::MessageReceived(BMessage* message)
|
||||||
|
{
|
||||||
|
switch (message->what) {
|
||||||
|
case ADD_CONSOLE_MESSAGE:
|
||||||
|
{
|
||||||
|
BString source = message->FindString("source");
|
||||||
|
int32 lineNumber = message->FindInt32("line");
|
||||||
|
int32 columnNumber = message->FindInt32("column");
|
||||||
|
BString text = message->FindString("string");
|
||||||
|
BString finalText;
|
||||||
|
finalText.SetToFormat("%s:%li:%li: %s\n", source.String(), lineNumber,
|
||||||
|
columnNumber, text.String());
|
||||||
|
fMessagesListView->AddItem(new BStringItem(finalText.String()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CLEAR_CONSOLE_MESSAGES:
|
||||||
|
{
|
||||||
|
int count = fMessagesListView->CountItems();
|
||||||
|
for (int i = count - 1; i >= 0; i--) {
|
||||||
|
delete fMessagesListView->RemoveItem(i);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
BWindow::MessageReceived(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ConsoleWindow::QuitRequested()
|
||||||
|
{
|
||||||
|
if (!IsHidden())
|
||||||
|
Hide();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Zhuowei Zhang
|
||||||
|
*/
|
||||||
|
#ifndef CONSOLE_WINDOW_H
|
||||||
|
#define CONSOLE_WINDOW_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
|
|
||||||
|
class BListView;
|
||||||
|
class BButton;
|
||||||
|
|
||||||
|
|
||||||
|
class ConsoleWindow : public BWindow {
|
||||||
|
public:
|
||||||
|
ConsoleWindow(BRect frame);
|
||||||
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
virtual bool QuitRequested();
|
||||||
|
private:
|
||||||
|
BListView* fMessagesListView;
|
||||||
|
BButton* fClearMessagesButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // CONSOLE_WINDOW_H
|
||||||
@@ -37,6 +37,7 @@ local sources =
|
|||||||
SettingsKeys.cpp
|
SettingsKeys.cpp
|
||||||
SettingsWindow.cpp
|
SettingsWindow.cpp
|
||||||
URLInputGroup.cpp
|
URLInputGroup.cpp
|
||||||
|
ConsoleWindow.cpp
|
||||||
;
|
;
|
||||||
|
|
||||||
# We build WebPositive only for one architecture -- the first architecture for
|
# We build WebPositive only for one architecture -- the first architecture for
|
||||||
|
|||||||
Reference in New Issue
Block a user