mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-31 08:37:26 +00:00
Disable Up/Down in Console during Completion (#1554)
This commit is contained in:
parent
c0f4f458ed
commit
7e8eb9c393
@ -23,7 +23,10 @@ ConsoleWidget::ConsoleWidget(MainWindow *main, QAction *action) :
|
|||||||
ui(new Ui::ConsoleWidget),
|
ui(new Ui::ConsoleWidget),
|
||||||
debugOutputEnabled(true),
|
debugOutputEnabled(true),
|
||||||
maxHistoryEntries(100),
|
maxHistoryEntries(100),
|
||||||
lastHistoryPosition(invalidHistoryPos)
|
lastHistoryPosition(invalidHistoryPos),
|
||||||
|
completer(nullptr),
|
||||||
|
historyUpShortcut(nullptr),
|
||||||
|
historyDownShortcut(nullptr)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@ -55,7 +58,7 @@ ConsoleWidget::ConsoleWidget(MainWindow *main, QAction *action) :
|
|||||||
completer->setFilterMode(Qt::MatchStartsWith);
|
completer->setFilterMode(Qt::MatchStartsWith);
|
||||||
ui->inputLineEdit->setCompleter(completer);
|
ui->inputLineEdit->setCompleter(completer);
|
||||||
|
|
||||||
connect(ui->inputLineEdit, &QLineEdit::textChanged, this, &ConsoleWidget::updateCompletion);
|
connect(ui->inputLineEdit, &QLineEdit::textEdited, this, &ConsoleWidget::updateCompletion);
|
||||||
updateCompletion();
|
updateCompletion();
|
||||||
|
|
||||||
// Set console output context menu
|
// Set console output context menu
|
||||||
@ -69,15 +72,17 @@ ConsoleWidget::ConsoleWidget(MainWindow *main, QAction *action) :
|
|||||||
clear_shortcut->setContext(Qt::WidgetShortcut);
|
clear_shortcut->setContext(Qt::WidgetShortcut);
|
||||||
|
|
||||||
// Up and down arrows show history
|
// Up and down arrows show history
|
||||||
QShortcut *historyOnUp = new QShortcut(QKeySequence(Qt::Key_Up), ui->inputLineEdit);
|
historyUpShortcut = new QShortcut(QKeySequence(Qt::Key_Up), ui->inputLineEdit);
|
||||||
connect(historyOnUp, SIGNAL(activated()), this, SLOT(historyPrev()));
|
connect(historyUpShortcut, SIGNAL(activated()), this, SLOT(historyPrev()));
|
||||||
historyOnUp->setContext(Qt::WidgetShortcut);
|
historyUpShortcut->setContext(Qt::WidgetShortcut);
|
||||||
|
|
||||||
QShortcut *historyOnDown = new QShortcut(QKeySequence(Qt::Key_Down), ui->inputLineEdit);
|
historyDownShortcut = new QShortcut(QKeySequence(Qt::Key_Down), ui->inputLineEdit);
|
||||||
connect(historyOnDown, SIGNAL(activated()), this, SLOT(historyNext()));
|
connect(historyDownShortcut, SIGNAL(activated()), this, SLOT(historyNext()));
|
||||||
historyOnDown->setContext(Qt::WidgetShortcut);
|
historyDownShortcut->setContext(Qt::WidgetShortcut);
|
||||||
|
|
||||||
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(setupFont()));
|
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(setupFont()));
|
||||||
|
|
||||||
|
completer->popup()->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsoleWidget::~ConsoleWidget()
|
ConsoleWidget::~ConsoleWidget()
|
||||||
@ -85,6 +90,22 @@ ConsoleWidget::~ConsoleWidget()
|
|||||||
delete completer;
|
delete completer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ConsoleWidget::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
{
|
||||||
|
if(completer && obj == completer->popup() &&
|
||||||
|
// disable up/down shortcuts if completer is shown
|
||||||
|
(event->type() == QEvent::Type::Show || event->type() == QEvent::Type::Hide)) {
|
||||||
|
bool enabled = !completer->popup()->isVisible();
|
||||||
|
if (historyUpShortcut) {
|
||||||
|
historyUpShortcut->setEnabled(enabled);
|
||||||
|
}
|
||||||
|
if (historyDownShortcut) {
|
||||||
|
historyDownShortcut->setEnabled(enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void ConsoleWidget::setupFont()
|
void ConsoleWidget::setupFont()
|
||||||
{
|
{
|
||||||
ui->outputTextEdit->setFont(Config()->getFont());
|
ui->outputTextEdit->setFont(Config()->getFont());
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class QCompleter;
|
class QCompleter;
|
||||||
|
class QShortcut;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ConsoleWidget;
|
class ConsoleWidget;
|
||||||
@ -34,6 +35,9 @@ public:
|
|||||||
maxHistoryEntries = max;
|
maxHistoryEntries = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void focusInputLineEdit();
|
void focusInputLineEdit();
|
||||||
|
|
||||||
@ -75,6 +79,8 @@ private:
|
|||||||
QStringList history;
|
QStringList history;
|
||||||
QStringListModel completionModel;
|
QStringListModel completionModel;
|
||||||
QCompleter *completer;
|
QCompleter *completer;
|
||||||
|
QShortcut *historyUpShortcut;
|
||||||
|
QShortcut *historyDownShortcut;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONSOLEWIDGET_H
|
#endif // CONSOLEWIDGET_H
|
||||||
|
Loading…
Reference in New Issue
Block a user