mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-10 11:26:27 +02:00
intial commit #21369 Working on clear method of console
This commit is contained in:
parent
e79fd9c5cb
commit
904e25c9e3
14 changed files with 154 additions and 121 deletions
|
@ -75,6 +75,12 @@ Windows.Window {
|
|||
}
|
||||
}
|
||||
|
||||
function fromConsole() {
|
||||
if (root.dynamicContent && root.dynamicContent.fromConsole) {
|
||||
root.dynamicContent.fromConsole();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle message traffic from our loaded QML to the script that launched us
|
||||
signal sendToScript(var message);
|
||||
onDynamicContentChanged: {
|
||||
|
|
|
@ -5514,6 +5514,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
|||
connect(scriptEngine, &ScriptEngine::errorMessage, DependencyManager::get<ScriptEngines>().data(), &ScriptEngines::onErrorMessage);
|
||||
connect(scriptEngine, &ScriptEngine::warningMessage, DependencyManager::get<ScriptEngines>().data(), &ScriptEngines::onWarningMessage);
|
||||
connect(scriptEngine, &ScriptEngine::infoMessage, DependencyManager::get<ScriptEngines>().data(), &ScriptEngines::onInfoMessage);
|
||||
connect(scriptEngine, &ScriptEngine::clearDebugWindow, DependencyManager::get<ScriptEngines>().data(), &ScriptEngines::OnClearConsole);
|
||||
}
|
||||
|
||||
bool Application::canAcceptURL(const QString& urlString) const {
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "Application.h"
|
||||
#include "JSConsole.h"
|
||||
#include "ScriptHighlighting.h"
|
||||
//#include "D:\Dhruvesh\Project\Hifi\github\hifi\libraries\script-engine\src\ScriptEngineLogging.h"
|
||||
|
||||
const int NO_CURRENT_HISTORY_COMMAND = -1;
|
||||
const int MAX_HISTORY_SIZE = 64;
|
||||
|
@ -85,7 +84,6 @@ void JSConsole::setScriptEngine(ScriptEngine* scriptEngine) {
|
|||
disconnect(_scriptEngine, &ScriptEngine::infoMessage, this, &JSConsole::handleInfo);
|
||||
disconnect(_scriptEngine, &ScriptEngine::warningMessage, this, &JSConsole::handleWarning);
|
||||
disconnect(_scriptEngine, &ScriptEngine::errorMessage, this, &JSConsole::handleError);
|
||||
disconnect(_scriptEngine, &ScriptEngine::clearDebugWindow, this, &JSConsole::clear);
|
||||
if (_ownScriptEngine) {
|
||||
_scriptEngine->deleteLater();
|
||||
}
|
||||
|
@ -99,7 +97,6 @@ void JSConsole::setScriptEngine(ScriptEngine* scriptEngine) {
|
|||
connect(_scriptEngine, &ScriptEngine::infoMessage, this, &JSConsole::handleInfo);
|
||||
connect(_scriptEngine, &ScriptEngine::warningMessage, this, &JSConsole::handleWarning);
|
||||
connect(_scriptEngine, &ScriptEngine::errorMessage, this, &JSConsole::handleError);
|
||||
connect(_scriptEngine, &ScriptEngine::clearDebugWindow, this, &JSConsole::clear);
|
||||
}
|
||||
|
||||
void JSConsole::executeCommand(const QString& command) {
|
||||
|
@ -147,7 +144,6 @@ void JSConsole::commandFinished() {
|
|||
void JSConsole::handleError(const QString& message, const QString& scriptName) {
|
||||
Q_UNUSED(scriptName);
|
||||
appendMessage(GUTTER_ERROR, "<span style='" + RESULT_ERROR_STYLE + "'>" + message.toHtmlEscaped() + "</span>");
|
||||
|
||||
}
|
||||
|
||||
void JSConsole::handlePrint(const QString& message, const QString& scriptName) {
|
||||
|
@ -184,7 +180,8 @@ bool JSConsole::eventFilter(QObject* sender, QEvent* event) {
|
|||
// If the shift key is being used then treat it as a regular return/enter. If this isn't done,
|
||||
// a new QTextBlock isn't created.
|
||||
keyEvent->setModifiers(keyEvent->modifiers() & ~Qt::ShiftModifier);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
QString command = _ui->promptTextEdit->toPlainText().trimmed();
|
||||
|
||||
if (!command.isEmpty()) {
|
||||
|
@ -196,7 +193,8 @@ bool JSConsole::eventFilter(QObject* sender, QEvent* event) {
|
|||
|
||||
return true;
|
||||
}
|
||||
} else if (key == Qt::Key_Down) {
|
||||
}
|
||||
else if (key == Qt::Key_Down) {
|
||||
// Go to the next command in history if the cursor is at the last line of the current command.
|
||||
int blockNumber = _ui->promptTextEdit->textCursor().blockNumber();
|
||||
int blockCount = _ui->promptTextEdit->document()->blockCount();
|
||||
|
@ -204,7 +202,8 @@ bool JSConsole::eventFilter(QObject* sender, QEvent* event) {
|
|||
setToNextCommandInHistory();
|
||||
return true;
|
||||
}
|
||||
} else if (key == Qt::Key_Up) {
|
||||
}
|
||||
else if (key == Qt::Key_Up) {
|
||||
// Go to the previous command in history if the cursor is at the first line of the current command.
|
||||
int blockNumber = _ui->promptTextEdit->textCursor().blockNumber();
|
||||
if (blockNumber == 0) {
|
||||
|
@ -222,7 +221,8 @@ void JSConsole::setToNextCommandInHistory() {
|
|||
_currentCommandInHistory--;
|
||||
if (_currentCommandInHistory == NO_CURRENT_HISTORY_COMMAND) {
|
||||
setAndSelectCommand(_rootCommand);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
setAndSelectCommand(_commandHistory[_currentCommandInHistory]);
|
||||
}
|
||||
}
|
||||
|
@ -295,14 +295,11 @@ void JSConsole::appendMessage(const QString& gutter, const QString& message) {
|
|||
}
|
||||
|
||||
void JSConsole::clear() {
|
||||
/* qCDebug(scriptengine) << "=============================";
|
||||
qCDebug(scriptengine) << "Clear fUNCTION";*/
|
||||
QLayoutItem* item;
|
||||
while ((item = _ui->logArea->layout()->takeAt(0)) != NULL) {
|
||||
// qCDebug(scriptengine) << "While loop called";
|
||||
delete item->widget();
|
||||
delete item;
|
||||
}
|
||||
// _ui->logArea->updateGeometry();
|
||||
// scrollToBottom();
|
||||
_ui->logArea->updateGeometry();
|
||||
scrollToBottom();
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ public:
|
|||
~JSConsole();
|
||||
|
||||
void setScriptEngine(ScriptEngine* scriptEngine = NULL);
|
||||
void clear();
|
||||
|
||||
public slots:
|
||||
void executeCommand(const QString& command);
|
||||
|
@ -51,7 +52,6 @@ protected slots:
|
|||
void handleWarning(const QString& message, const QString& scriptName);
|
||||
void handleError(const QString& message, const QString& scriptName);
|
||||
void commandFinished();
|
||||
void clear();
|
||||
|
||||
private:
|
||||
void appendMessage(const QString& gutter, const QString& message);
|
||||
|
|
|
@ -32,5 +32,4 @@ TestingDialog::TestingDialog(QWidget* parent) :
|
|||
void TestingDialog::onTestingFinished(const QString& scriptPath) {
|
||||
_engine = nullptr;
|
||||
_console->setScriptEngine(nullptr);
|
||||
|
||||
}
|
||||
|
|
|
@ -563,7 +563,8 @@ QObject* OffscreenQmlSurface::finishQmlLoad(std::function<void(QQmlContext*, QOb
|
|||
QString webChannelStr = QTextStream(&webChannelFile).readAll();
|
||||
QString createGlobalEventBridgeStr = QTextStream(&createGlobalEventBridgeFile).readAll();
|
||||
javaScriptToInject = webChannelStr + createGlobalEventBridgeStr;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
qCWarning(glLogging) << "Unable to find qwebchannel.js or createGlobalEventBridge.js";
|
||||
}
|
||||
|
||||
|
@ -648,7 +649,8 @@ QPointF OffscreenQmlSurface::mapWindowToUi(const QPointF& sourcePosition, QObjec
|
|||
vec2 sourceSize;
|
||||
if (dynamic_cast<QWidget*>(sourceObject)) {
|
||||
sourceSize = toGlm(((QWidget*)sourceObject)->size());
|
||||
} else if (dynamic_cast<QWindow*>(sourceObject)) {
|
||||
}
|
||||
else if (dynamic_cast<QWindow*>(sourceObject)) {
|
||||
sourceSize = toGlm(((QWindow*)sourceObject)->size());
|
||||
}
|
||||
vec2 offscreenPosition = toGlm(sourcePosition);
|
||||
|
@ -892,16 +894,20 @@ void OffscreenQmlSurface::synthesizeKeyPress(QString key) {
|
|||
if (equals(utf8Key, SHIFT_ARROW) || equals(utf8Key, NUMERIC_SHIFT_ARROW) ||
|
||||
equals(utf8Key, (uint8_t*)PUNCTUATION_STRING) || equals(utf8Key, (uint8_t*)ALPHABET_STRING)) {
|
||||
return; // ignore
|
||||
} else if (equals(utf8Key, BACKSPACE_SYMBOL)) {
|
||||
}
|
||||
else if (equals(utf8Key, BACKSPACE_SYMBOL)) {
|
||||
scanCode = Qt::Key_Backspace;
|
||||
keyString = "\x08";
|
||||
} else if (equals(utf8Key, RETURN_SYMBOL)) {
|
||||
}
|
||||
else if (equals(utf8Key, RETURN_SYMBOL)) {
|
||||
scanCode = Qt::Key_Return;
|
||||
keyString = "\x0d";
|
||||
} else if (equals(utf8Key, LEFT_ARROW)) {
|
||||
}
|
||||
else if (equals(utf8Key, LEFT_ARROW)) {
|
||||
scanCode = Qt::Key_Left;
|
||||
keyString = "";
|
||||
} else if (equals(utf8Key, RIGHT_ARROW)) {
|
||||
}
|
||||
else if (equals(utf8Key, RIGHT_ARROW)) {
|
||||
scanCode = Qt::Key_Right;
|
||||
keyString = "";
|
||||
}
|
||||
|
@ -941,7 +947,8 @@ void OffscreenQmlSurface::setKeyboardRaised(QObject* object, bool raised, bool n
|
|||
void OffscreenQmlSurface::emitScriptEvent(const QVariant& message) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "emitScriptEvent", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
emit scriptEventReceived(message);
|
||||
}
|
||||
}
|
||||
|
@ -949,7 +956,8 @@ void OffscreenQmlSurface::emitScriptEvent(const QVariant& message) {
|
|||
void OffscreenQmlSurface::emitWebEvent(const QVariant& message) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "emitWebEvent", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// Special case to handle raising and lowering the virtual keyboard.
|
||||
const QString RAISE_KEYBOARD = "_RAISE_KEYBOARD";
|
||||
const QString RAISE_KEYBOARD_NUMERIC = "_RAISE_KEYBOARD_NUMERIC";
|
||||
|
@ -957,9 +965,11 @@ void OffscreenQmlSurface::emitWebEvent(const QVariant& message) {
|
|||
QString messageString = message.type() == QVariant::String ? message.toString() : "";
|
||||
if (messageString.left(RAISE_KEYBOARD.length()) == RAISE_KEYBOARD) {
|
||||
setKeyboardRaised(_currentFocusItem, true, messageString == RAISE_KEYBOARD_NUMERIC);
|
||||
} else if (messageString == LOWER_KEYBOARD) {
|
||||
}
|
||||
else if (messageString == LOWER_KEYBOARD) {
|
||||
setKeyboardRaised(_currentFocusItem, false);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
emit webEventReceived(message);
|
||||
}
|
||||
}
|
||||
|
@ -968,7 +978,8 @@ void OffscreenQmlSurface::emitWebEvent(const QVariant& message) {
|
|||
void OffscreenQmlSurface::sendToQml(const QVariant& message) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "emitQmlEvent", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
||||
} else if (_rootItem) {
|
||||
}
|
||||
else if (_rootItem) {
|
||||
// call fromScript method on qml root
|
||||
QMetaObject::invokeMethod(_rootItem, "fromScript", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
||||
}
|
||||
|
|
|
@ -485,10 +485,11 @@ void ScriptEngine::scriptPrintedMessage(const QString& message) {
|
|||
qCDebug(scriptengine) << message;
|
||||
emit printedMessage(message, getFilename());
|
||||
}
|
||||
|
||||
void ScriptEngine::clearConsole() {
|
||||
qCDebug(scriptengine) << "Clearing debug window";
|
||||
emit clearDebugWindow();
|
||||
}
|
||||
|
||||
// Even though we never pass AnimVariantMap directly to and from javascript, the queued invokeMethod of
|
||||
// callAnimationStateHandler requires that the type be registered.
|
||||
// These two are meaningful, if we ever do want to use them...
|
||||
|
|
|
@ -54,6 +54,10 @@ void ScriptEngines::onInfoMessage(const QString& message, const QString& scriptN
|
|||
emit infoMessage(message, scriptName);
|
||||
}
|
||||
|
||||
void ScriptEngines::OnClearConsole() {
|
||||
emit clearDebugWindow();
|
||||
}
|
||||
|
||||
void ScriptEngines::onErrorLoadingScript(const QString& url) {
|
||||
emit errorLoadingScript(url);
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ signals:
|
|||
void warningMessage(const QString& message, const QString& engineName);
|
||||
void infoMessage(const QString& message, const QString& engineName);
|
||||
void errorLoadingScript(const QString& url);
|
||||
void clearDebugWindow();
|
||||
|
||||
public slots:
|
||||
void onPrintedMessage(const QString& message, const QString& scriptName);
|
||||
|
@ -86,6 +87,7 @@ public slots:
|
|||
void onWarningMessage(const QString& message, const QString& scriptName);
|
||||
void onInfoMessage(const QString& message, const QString& scriptName);
|
||||
void onErrorLoadingScript(const QString& url);
|
||||
void OnClearConsole();
|
||||
|
||||
protected slots:
|
||||
void onScriptFinished(const QString& fileNameString, ScriptEngine* engine);
|
||||
|
|
|
@ -153,6 +153,9 @@ void QmlWindowClass::sendToQml(const QVariant& message) {
|
|||
QMetaObject::invokeMethod(asQuickItem(), "fromScript", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
||||
}
|
||||
|
||||
void QmlWindowClass::clearConsole() {
|
||||
QMetaObject::invokeMethod(asQuickItem(), "fromConsole", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void QmlWindowClass::emitScriptEvent(const QVariant& scriptMessage) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
|
|
|
@ -53,6 +53,7 @@ public slots:
|
|||
|
||||
// Scripts can use this to send a message to the QML object
|
||||
void sendToQml(const QVariant& message);
|
||||
void clearConsole();
|
||||
|
||||
// QmlWindow content may include WebView requiring EventBridge.
|
||||
void emitScriptEvent(const QVariant& scriptMessage);
|
||||
|
|
|
@ -49,4 +49,8 @@ ScriptDiscoveryService.infoMessage.connect(function(message, scriptFileName) {
|
|||
sendToLogWindow("INFO", message, scriptFileName);
|
||||
});
|
||||
|
||||
ScriptDiscoveryService.clearDebugWindow.connect(function () {
|
||||
window.clearConsole();
|
||||
});
|
||||
|
||||
}()); // END LOCAL_SCOPE
|
|
@ -40,6 +40,10 @@ Rectangle {
|
|||
}
|
||||
textArea.append(message);
|
||||
}
|
||||
|
||||
function fromConsole(){
|
||||
textArea.remove(0,textArea.length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue