Toggle Console Widget and clear output (#2213)

* Add shortcuts to toggle Console and clear its output
* Update the docs

Co-authored-by: Kārlis Seņko <karlis3p70l1ij@gmail.com>
This commit is contained in:
Itay Cohen 2020-05-25 12:19:05 +03:00 committed by GitHub
parent b1e79ec6a6
commit bfec29f825
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 7 deletions

View File

@ -30,6 +30,10 @@ Widget shortcuts
+-----------+---------+
| Shift+E | Exports |
+-----------+---------+
| Ctrl+` | Console |
+-----------+---------+
| : | Console |
+-----------+---------+
Disassembly view shortcuts
--------------------------

View File

@ -14,6 +14,7 @@
#include "ui_ConsoleWidget.h"
#include "common/Helpers.h"
#include "common/SvgIconEngine.h"
#include "WidgetShortcuts.h"
#ifdef Q_OS_WIN
#include <io.h>
@ -59,8 +60,24 @@ ConsoleWidget::ConsoleWidget(MainWindow *main) :
QTextDocument *console_docu = ui->outputTextEdit->document();
console_docu->setDocumentMargin(10);
QAction *actionClear = new QAction(tr("Clear Output"), ui->outputTextEdit);
connect(actionClear, SIGNAL(triggered(bool)), ui->outputTextEdit, SLOT(clear()));
// Ctrl+` and ';' to toggle console widget
QAction *toggleConsole = toggleViewAction();
QList<QKeySequence> toggleShortcuts;
toggleShortcuts << widgetShortcuts["ConsoleWidget"] << widgetShortcuts["ConsoleWidgetAlternative"];
toggleConsole->setShortcuts(toggleShortcuts);
connect(toggleConsole, &QAction::triggered, this, [this, toggleConsole](){
if (toggleConsole->isChecked()) {
widgetToFocusOnRaise()->setFocus();
}
});
QAction *actionClear = new QAction(tr("Clear Output"), this);
connect(actionClear, &QAction::triggered, ui->outputTextEdit, &QPlainTextEdit::clear);
addAction(actionClear);
// Ctrl+l to clear the output
actionClear->setShortcut(Qt::CTRL + Qt::Key_L);
actionClear->setShortcutContext(Qt::WidgetWithChildrenShortcut);
actions.append(actionClear);
actionWrapLines = new QAction(tr("Wrap Lines"), ui->outputTextEdit);
@ -157,6 +174,11 @@ bool ConsoleWidget::eventFilter(QObject *obj, QEvent *event)
return false;
}
QWidget *ConsoleWidget::widgetToFocusOnRaise()
{
return ui->r2InputLineEdit;
}
void ConsoleWidget::setupFont()
{
ui->outputTextEdit->setFont(Config()->getFont());

View File

@ -39,7 +39,8 @@ public:
}
protected:
bool eventFilter(QObject *obj, QEvent *event);
bool eventFilter(QObject *obj, QEvent *event) override;
QWidget* widgetToFocusOnRaise() override;
public slots:
void focusInputLineEdit();

View File

@ -2,10 +2,12 @@
#define WIDGETSHORTCUTS_H
static const QHash<QString, QKeySequence> widgetShortcuts = {
{ "StringsWidget", Qt::SHIFT + Qt::Key_F12 },
{ "GraphWidget", Qt::SHIFT + Qt::Key_G },
{ "ImportsWidget", Qt::SHIFT + Qt::Key_I },
{ "ExportsWidget", Qt::SHIFT + Qt::Key_E }
{ "StringsWidget", Qt::SHIFT + Qt::Key_F12 },
{ "GraphWidget", Qt::SHIFT + Qt::Key_G },
{ "ImportsWidget", Qt::SHIFT + Qt::Key_I },
{ "ExportsWidget", Qt::SHIFT + Qt::Key_E },
{ "ConsoleWidget", Qt::CTRL + Qt::Key_QuoteLeft },
{ "ConsoleWidgetAlternative", Qt::Key_Colon }
};
#endif