diff --git a/plugins/filetemplates/CMakeLists.txt b/plugins/filetemplates/CMakeLists.txt --- a/plugins/filetemplates/CMakeLists.txt +++ b/plugins/filetemplates/CMakeLists.txt @@ -4,6 +4,7 @@ templatepreviewtoolview.cpp filetemplatesplugin.cpp + ipagefocus.cpp classidentifierpage.cpp classmemberspage.cpp defaultcreateclasshelper.cpp @@ -64,6 +65,7 @@ main.cpp templatepreview.cpp + ipagefocus.cpp classidentifierpage.cpp classmemberspage.cpp defaultcreateclasshelper.cpp diff --git a/plugins/filetemplates/classidentifierpage.h b/plugins/filetemplates/classidentifierpage.h --- a/plugins/filetemplates/classidentifierpage.h +++ b/plugins/filetemplates/classidentifierpage.h @@ -21,10 +21,15 @@ #include +#include "ipagefocus.h" + +namespace KDevelop +{ + /** * Assistant dialog page for setting the identifier and inheritances of a new class */ -class ClassIdentifierPage : public QWidget +class ClassIdentifierPage : public QWidget, public IPageFocus { Q_OBJECT Q_PROPERTY(QStringList inheritance READ inheritanceList) @@ -54,6 +59,8 @@ */ void setInheritanceList(const QStringList& list); + void setFocusToFirstEditWidget() override; + Q_SIGNALS: void inheritanceChanged(); /** @@ -71,4 +78,6 @@ struct ClassIdentifierPagePrivate* const d; }; +} + #endif // KDEVPLATFORM_PLUGIN_CLASSIDENTIFIERPAGE_H diff --git a/plugins/filetemplates/classidentifierpage.cpp b/plugins/filetemplates/classidentifierpage.cpp --- a/plugins/filetemplates/classidentifierpage.cpp +++ b/plugins/filetemplates/classidentifierpage.cpp @@ -22,7 +22,9 @@ #include "ui_newclass.h" -struct ClassIdentifierPagePrivate +using namespace KDevelop; + +struct KDevelop::ClassIdentifierPagePrivate { ClassIdentifierPagePrivate() : classid(nullptr) @@ -74,3 +76,8 @@ { d->classid->keditlistwidget->setItems(list); } + +void ClassIdentifierPage::setFocusToFirstEditWidget() +{ + d->classid->identifierLineEdit->setFocus(); +} diff --git a/plugins/filetemplates/classmemberspage.h b/plugins/filetemplates/classmemberspage.h --- a/plugins/filetemplates/classmemberspage.h +++ b/plugins/filetemplates/classmemberspage.h @@ -24,11 +24,16 @@ #include +#include "ipagefocus.h" + +namespace KDevelop +{ + /** * Assistant dialog page for declaring data members of a new class * */ -class ClassMembersPage : public QWidget +class ClassMembersPage : public QWidget, public IPageFocus { Q_OBJECT Q_PROPERTY(KDevelop::VariableDescriptionList members READ members WRITE setMembers) @@ -46,8 +51,12 @@ */ void setMembers(const KDevelop::VariableDescriptionList& members); + void setFocusToFirstEditWidget() override; + private: class ClassMembersPagePrivate* const d; }; +} + #endif // KDEVPLATFORM_PLUGIN_CLASSMEMBERSPAGE_H diff --git a/plugins/filetemplates/classmemberspage.cpp b/plugins/filetemplates/classmemberspage.cpp --- a/plugins/filetemplates/classmemberspage.cpp +++ b/plugins/filetemplates/classmemberspage.cpp @@ -28,7 +28,7 @@ using namespace KDevelop; -class ClassMembersPagePrivate +class KDevelop::ClassMembersPagePrivate { public: KEditListWidget* editListWidget; @@ -107,3 +107,8 @@ } return list; } + +void ClassMembersPage::setFocusToFirstEditWidget() +{ + d->editListWidget->lineEdit()->setFocus(); +} diff --git a/plugins/filetemplates/ipagefocus.h b/plugins/filetemplates/ipagefocus.h new file mode 100644 --- /dev/null +++ b/plugins/filetemplates/ipagefocus.h @@ -0,0 +1,39 @@ +/* This file is part of KDevelop + Copyright 2017 Friedrich W. H. Kossebau + + 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. +*/ + +#ifndef KDEVPLATFORM_PLUGIN_IPAGEFOCUS_H +#define KDEVPLATFORM_PLUGIN_IPAGEFOCUS_H + +namespace KDevelop +{ + +class IPageFocus +{ +public: + virtual ~IPageFocus(); + + /** + * Set the keyboard input focus to the first edit widget. + */ + virtual void setFocusToFirstEditWidget() = 0; +}; + +} + +#endif diff --git a/plugins/filetemplates/ipagefocus.cpp b/plugins/filetemplates/ipagefocus.cpp new file mode 100644 --- /dev/null +++ b/plugins/filetemplates/ipagefocus.cpp @@ -0,0 +1,28 @@ +/* This file is part of KDevelop + Copyright 2017 Friedrich W. H. Kossebau + + 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 "ipagefocus.h" + +namespace KDevelop +{ + +IPageFocus::~IPageFocus() = default; + +} + diff --git a/plugins/filetemplates/licensepage.h b/plugins/filetemplates/licensepage.h --- a/plugins/filetemplates/licensepage.h +++ b/plugins/filetemplates/licensepage.h @@ -21,16 +21,16 @@ #include - +#include "ipagefocus.h" namespace KDevelop { /** * Assistant dialog page for choosing the license of new source files * * @todo Add the name of the Author at the top of the license */ -class LicensePage : public QWidget +class LicensePage : public QWidget, public IPageFocus { Q_OBJECT @@ -44,6 +44,8 @@ */ QString license() const; + void setFocusToFirstEditWidget() override; + private: // data struct LicensePagePrivate* const d; diff --git a/plugins/filetemplates/licensepage.cpp b/plugins/filetemplates/licensepage.cpp --- a/plugins/filetemplates/licensepage.cpp +++ b/plugins/filetemplates/licensepage.cpp @@ -270,6 +270,11 @@ return licenseText; } +void LicensePage::setFocusToFirstEditWidget() +{ + d->license->licenseComboBox->setFocus(); +} + } Q_DECLARE_TYPEINFO(KDevelop::LicensePagePrivate::LicenseInfo, Q_MOVABLE_TYPE); diff --git a/plugins/filetemplates/outputpage.h b/plugins/filetemplates/outputpage.h --- a/plugins/filetemplates/outputpage.h +++ b/plugins/filetemplates/outputpage.h @@ -23,6 +23,8 @@ #include #include +#include "ipagefocus.h" + namespace KDevelop { class TemplateRenderer; @@ -32,7 +34,7 @@ /** * Assistant page for setting the output location of generated source code */ -class OutputPage : public QWidget +class OutputPage : public QWidget, public IPageFocus { Q_OBJECT @@ -69,6 +71,8 @@ */ QHash filePositions() const; + void setFocusToFirstEditWidget() override; + Q_SIGNALS: /** * @copydoc ClassIdentifierPage::isValid diff --git a/plugins/filetemplates/outputpage.cpp b/plugins/filetemplates/outputpage.cpp --- a/plugins/filetemplates/outputpage.cpp +++ b/plugins/filetemplates/outputpage.cpp @@ -265,6 +265,11 @@ return positions; } +void OutputPage::setFocusToFirstEditWidget() +{ + d->output->lowerFilenameCheckBox->setFocus(); +} + } #include "moc_outputpage.cpp" diff --git a/plugins/filetemplates/overridespage.h b/plugins/filetemplates/overridespage.h --- a/plugins/filetemplates/overridespage.h +++ b/plugins/filetemplates/overridespage.h @@ -22,6 +22,7 @@ #include #include "language/duchain/declaration.h" +#include "ipagefocus.h" class QTreeWidget; class QTreeWidgetItem; @@ -31,7 +32,7 @@ /** * Assistant page for choosing class functions, overridden from base classes. */ -class OverridesPage : public QWidget +class OverridesPage : public QWidget, public IPageFocus { Q_OBJECT @@ -79,6 +80,8 @@ QWidget* extraFunctionsContainer() const; + void setFocusToFirstEditWidget() override; + public Q_SLOTS: /** * Selects all functions for overriding diff --git a/plugins/filetemplates/overridespage.cpp b/plugins/filetemplates/overridespage.cpp --- a/plugins/filetemplates/overridespage.cpp +++ b/plugins/filetemplates/overridespage.cpp @@ -264,3 +264,8 @@ overrideTree()->expandAll(); overrideTree()->header()->resizeSections(QHeaderView::ResizeToContents); } + +void OverridesPage::setFocusToFirstEditWidget() +{ + d->overrides->overridesTree->setFocus(); +} diff --git a/plugins/filetemplates/templateclassassistant.cpp b/plugins/filetemplates/templateclassassistant.cpp --- a/plugins/filetemplates/templateclassassistant.cpp +++ b/plugins/filetemplates/templateclassassistant.cpp @@ -505,6 +505,10 @@ { d->outputPageWidget->loadFileTemplate(d->fileTemplate, d->baseUrl, d->renderer); } + + if (auto* pageFocus = dynamic_cast(currentPage()->widget())) { + pageFocus->setFocusToFirstEditWidget(); + } } void TemplateClassAssistant::back() diff --git a/plugins/filetemplates/templateoptionspage.h b/plugins/filetemplates/templateoptionspage.h --- a/plugins/filetemplates/templateoptionspage.h +++ b/plugins/filetemplates/templateoptionspage.h @@ -23,6 +23,7 @@ #include #include +#include "ipagefocus.h" namespace KDevelop @@ -42,7 +43,7 @@ * * @sa SourceFileTemplate::customOptions() **/ -class TemplateOptionsPage : public QWidget +class TemplateOptionsPage : public QWidget, public IPageFocus { Q_OBJECT Q_PROPERTY(QVariantHash templateOptions READ templateOptions) @@ -75,6 +76,8 @@ **/ QVariantHash templateOptions() const; + void setFocusToFirstEditWidget() override; + private: class TemplateOptionsPagePrivate* const d; }; diff --git a/plugins/filetemplates/templateoptionspage.cpp b/plugins/filetemplates/templateoptionspage.cpp --- a/plugins/filetemplates/templateoptionspage.cpp +++ b/plugins/filetemplates/templateoptionspage.cpp @@ -43,12 +43,15 @@ QList entries; QHash controls; QHash typeProperties; + QWidget *firstEditWidget; }; TemplateOptionsPage::TemplateOptionsPage(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f) , d(new TemplateOptionsPagePrivate) { + d->firstEditWidget = nullptr; + d->typeProperties.insert(QStringLiteral("String"), "text"); d->typeProperties.insert(QStringLiteral("Int"), "value"); d->typeProperties.insert(QStringLiteral("Bool"), "checked"); @@ -62,6 +65,8 @@ void TemplateOptionsPage::load(const SourceFileTemplate& fileTemplate, TemplateRenderer* renderer) { d->entries.clear(); + d->controls.clear(); + d->firstEditWidget = nullptr; QLayout* layout = new QVBoxLayout(); QHash > options = fileTemplate.customOptions(renderer); @@ -114,6 +119,9 @@ QLabel* label = new QLabel(entryLabelText, box); formLayout->addRow(label, control); d->controls.insert(entry.name, control); + if (d->firstEditWidget == nullptr) { + d->firstEditWidget = control; + } } } @@ -139,3 +147,10 @@ return values; } + +void TemplateOptionsPage::setFocusToFirstEditWidget() +{ + if (d->firstEditWidget) { + d->firstEditWidget->setFocus(); + } +} diff --git a/plugins/filetemplates/testcasespage.h b/plugins/filetemplates/testcasespage.h --- a/plugins/filetemplates/testcasespage.h +++ b/plugins/filetemplates/testcasespage.h @@ -23,7 +23,7 @@ #include - +#include "ipagefocus.h" class KEditListWidget; @@ -34,7 +34,7 @@ * Assistant page for specifying the list of test cases * */ -class TestCasesPage : public QWidget +class TestCasesPage : public QWidget, public IPageFocus { Q_OBJECT Q_PROPERTY(QStringList testCases READ testCases WRITE setTestCases) @@ -57,6 +57,8 @@ */ void setTestCases(const QStringList& testCases); + void setFocusToFirstEditWidget() override; + Q_SIGNALS: void isValid(bool valid); diff --git a/plugins/filetemplates/testcasespage.cpp b/plugins/filetemplates/testcasespage.cpp --- a/plugins/filetemplates/testcasespage.cpp +++ b/plugins/filetemplates/testcasespage.cpp @@ -69,6 +69,11 @@ return d->ui->keditlistwidget->items(); } +void TestCasesPage::setFocusToFirstEditWidget() +{ + d->ui->identifierLineEdit->setFocus(); +} + void TestCasesPage::identifierChanged(const QString& identifier) { emit isValid(!identifier.isEmpty());