forked from qt-creator/qt-creator
QmlJS: Fix focus handling in QML/JS console
We want the line editor to be focused by default when the console is opened either by mouse or by keyboard interaction. Change-Id: Ic366d1ac5f1306c0739c334584568402969895f3 Task-number: QTCREATORBUG-14931 Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
@@ -195,12 +195,17 @@ bool QmlConsolePane::canFocus() const
|
|||||||
|
|
||||||
bool QmlConsolePane::hasFocus() const
|
bool QmlConsolePane::hasFocus() const
|
||||||
{
|
{
|
||||||
return m_consoleWidget->window()->focusWidget() == m_consoleWidget;
|
for (QWidget *widget = m_consoleWidget->window()->focusWidget(); widget != 0;
|
||||||
|
widget = widget->parentWidget()) {
|
||||||
|
if (widget == m_consoleWidget)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlConsolePane::setFocus()
|
void QmlConsolePane::setFocus()
|
||||||
{
|
{
|
||||||
m_consoleWidget->setFocus();
|
m_consoleView->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmlConsolePane::canNext() const
|
bool QmlConsolePane::canNext() const
|
||||||
|
|||||||
@@ -164,9 +164,6 @@ void QmlConsoleView::mousePressEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
if (!handled)
|
if (!handled)
|
||||||
Utils::TreeView::mousePressEvent(event);
|
Utils::TreeView::mousePressEvent(event);
|
||||||
} else {
|
|
||||||
selectionModel()->setCurrentIndex(model()->index(model()->rowCount() - 1, 0),
|
|
||||||
QItemSelectionModel::ClearAndSelect);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,6 +213,13 @@ void QmlConsoleView::contextMenuEvent(QContextMenuEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlConsoleView::focusInEvent(QFocusEvent *event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(event);
|
||||||
|
selectionModel()->setCurrentIndex(model()->index(model()->rowCount() - 1, 0),
|
||||||
|
QItemSelectionModel::ClearAndSelect);
|
||||||
|
}
|
||||||
|
|
||||||
void QmlConsoleView::onRowActivated(const QModelIndex &index)
|
void QmlConsoleView::onRowActivated(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ protected:
|
|||||||
void drawBranches(QPainter *painter, const QRect &rect,
|
void drawBranches(QPainter *painter, const QRect &rect,
|
||||||
const QModelIndex &index) const;
|
const QModelIndex &index) const;
|
||||||
void contextMenuEvent(QContextMenuEvent *event);
|
void contextMenuEvent(QContextMenuEvent *event);
|
||||||
|
void focusInEvent(QFocusEvent *event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onRowActivated(const QModelIndex &index);
|
void onRowActivated(const QModelIndex &index);
|
||||||
|
|||||||
Reference in New Issue
Block a user