diff --git a/plugins/filetemplates/classidentifierpage.cpp b/plugins/filetemplates/classidentifierpage.cpp index ff11ede3c..07a25dceb 100644 --- a/plugins/filetemplates/classidentifierpage.cpp +++ b/plugins/filetemplates/classidentifierpage.cpp @@ -1,74 +1,83 @@ /* This file is part of KDevelop Copyright 2008 Hamish Rodda This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "classidentifierpage.h" #include "language/duchain/identifier.h" #include #include "ui_newclass.h" struct ClassIdentifierPagePrivate { ClassIdentifierPagePrivate() : classid(nullptr) { } Ui::NewClassDialog* classid; }; ClassIdentifierPage::ClassIdentifierPage(QWidget* parent) : QWidget(parent) , d(new ClassIdentifierPagePrivate()) { d->classid = new Ui::NewClassDialog; d->classid->setupUi(this); d->classid->keditlistwidget->lineEdit()->setPlaceholderText(i18n("Inheritance type and base class name")); d->classid->inheritanceLabel->setBuddy(d->classid->keditlistwidget->lineEdit()); connect(d->classid->identifierLineEdit, &QLineEdit::textChanged, this, &ClassIdentifierPage::checkIdentifier); + // ensure keyboard focus is returned to edit line + // Patch pending for KEditListWidget: https://phabricator.kde.org/D4392 + connect(d->classid->keditlistwidget, &KEditListWidget::added, + d->classid->keditlistwidget->lineEdit(), + static_cast(&QWidget::setFocus)); + connect(d->classid->keditlistwidget, &KEditListWidget::removed, + d->classid->keditlistwidget->lineEdit(), + static_cast(&QWidget::setFocus)); + emit isValid(false); } ClassIdentifierPage::~ClassIdentifierPage() { delete d->classid; delete d; } QString ClassIdentifierPage::identifier() const { return d->classid->identifierLineEdit->text(); } void ClassIdentifierPage::checkIdentifier() { emit isValid(!identifier().isEmpty()); } QStringList ClassIdentifierPage::inheritanceList() const { return d->classid->keditlistwidget->items(); } void ClassIdentifierPage::setInheritanceList (const QStringList& list) { d->classid->keditlistwidget->setItems(list); } diff --git a/plugins/filetemplates/classmemberspage.cpp b/plugins/filetemplates/classmemberspage.cpp index ac8600ade..93bb948e8 100644 --- a/plugins/filetemplates/classmemberspage.cpp +++ b/plugins/filetemplates/classmemberspage.cpp @@ -1,109 +1,119 @@ /* This file is part of KDevelop Copyright 2012 Miha Čančula This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "classmemberspage.h" #include "debug.h" #include #include #include #include using namespace KDevelop; class ClassMembersPagePrivate { public: KEditListWidget* editListWidget; }; ClassMembersPage::ClassMembersPage(QWidget* parent) : QWidget(parent) , d(new ClassMembersPagePrivate) { d->editListWidget = new KEditListWidget(this); d->editListWidget->lineEdit()->setPlaceholderText(i18n("Variable type and identifier")); QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(d->editListWidget); + + // ensure keyboard focus is returned to edit line + // Patch pending for KEditListWidget: https://phabricator.kde.org/D4392 + connect(d->editListWidget, &KEditListWidget::added, + d->editListWidget->lineEdit(), + static_cast(&QWidget::setFocus)); + connect(d->editListWidget, &KEditListWidget::removed, + d->editListWidget->lineEdit(), + static_cast(&QWidget::setFocus)); + setLayout(layout); } ClassMembersPage::~ClassMembersPage() { delete d; } void ClassMembersPage::setMembers(const VariableDescriptionList& members) { QStringList memberItems; foreach (const VariableDescription& variable, members) { QStringList items; if (!variable.access.isEmpty()) { items << variable.access; } if (!variable.type.isEmpty()) { items << variable.type; } items << variable.name; memberItems << items.join(QLatin1Char(' ')); } d->editListWidget->setItems(memberItems); } VariableDescriptionList ClassMembersPage::members() const { VariableDescriptionList list; foreach (const QString& item, d->editListWidget->items()) { VariableDescription var; QStringList parts = item.split(' '); switch (parts.size()) { case 1: var.name = parts[0]; break; case 2: var.type = parts[0]; var.name = parts[1]; break; case 3: var.access = parts[0]; var.type = parts[1]; var.name = parts[2]; break; default: qCDebug(PLUGIN_FILETEMPLATES) << "Malformed class member" << item; break; } if (!var.name.isEmpty()) { list << var; } } return list; } diff --git a/plugins/filetemplates/testcasespage.cpp b/plugins/filetemplates/testcasespage.cpp index fb4580121..3fdb3b48c 100644 --- a/plugins/filetemplates/testcasespage.cpp +++ b/plugins/filetemplates/testcasespage.cpp @@ -1,73 +1,82 @@ /* * This file is part of KDevelop * Copyright 2012 Miha Čančula * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testcasespage.h" #include "ui_testcases.h" #include #include #include using namespace KDevelop; class KDevelop::TestCasesPagePrivate { public: Ui::TestCasesPage* ui; }; TestCasesPage::TestCasesPage(QWidget* parent, Qt::WindowFlags f) : QWidget (parent, f) , d(new TestCasesPagePrivate) { d->ui = new Ui::TestCasesPage(); d->ui->setupUi(this); d->ui->testCasesLabel->setBuddy(d->ui->keditlistwidget->lineEdit()); - + + // ensure keyboard focus is returned to edit line + // Patch pending for KEditListWidget: https://phabricator.kde.org/D4392 + connect(d->ui->keditlistwidget, &KEditListWidget::added, + d->ui->keditlistwidget->lineEdit(), + static_cast(&QWidget::setFocus)); + connect(d->ui->keditlistwidget, &KEditListWidget::removed, + d->ui->keditlistwidget->lineEdit(), + static_cast(&QWidget::setFocus)); + connect(d->ui->identifierLineEdit, &QLineEdit::textChanged, this, &TestCasesPage::identifierChanged); } TestCasesPage::~TestCasesPage() { delete d->ui; delete d; } QString TestCasesPage::name() const { return d->ui->identifierLineEdit->text(); } void TestCasesPage::setTestCases(const QStringList& testCases) { d->ui->keditlistwidget->setItems(testCases); } QStringList TestCasesPage::testCases() const { return d->ui->keditlistwidget->items(); } void TestCasesPage::identifierChanged(const QString& identifier) { emit isValid(!identifier.isEmpty()); }