on xenial help sign in
fix the launching of the searched item by pressing enter
commit6824477fc5ed6fe6d5c7bfd82db4741c73563e42 authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 28 Nov 2016, 11:17 (10 years ago) parentc7fb112
6 files changed+62−13
plugins/Utils/CMakeLists.txt+1 plugins/Utils/appdrawerproxymodel.cpp+23 plugins/Utils/appdrawerproxymodel.h+2 qml/Launcher/Drawer.qml+3−13 qml/Launcher/DrawerListView.qml+31 tests/mocks/Utils/CMakeLists.txt+2
plugins/Utils/CMakeLists.txt+1
@@ -17,6 +17,7 @@ set(QMLPLUGIN_SRC
1717 applicationsfiltermodel.cpp
1818 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/AppDrawerModelInterface.h
1919 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
20+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
2021 appdrawerproxymodel.cpp
2122 constants.cpp
2223 WindowInputMonitor.cpp
plugins/Utils/appdrawerproxymodel.cpp+23
@@ -16,6 +16,8 @@
1616
1717#include "appdrawerproxymodel.h"
1818
19+#include <unity/shell/launcher/LauncherItemInterface.h>
20+
1921#include <QDebug>
2022
2123AppDrawerProxyModel::AppDrawerProxyModel(QObject *parent):
@@ -167,3 +169,24 @@ bool AppDrawerProxyModel::filterAcceptsRow(int source_row, const QModelIndex &so
167169 }
168170 return true;
169171}
172+
173+QString AppDrawerProxyModel::appId(int index) const
174+{
175+ qDebug() << "get called:" << index << this << m_source->staticMetaObject.className() << m_source;
176+ if (index >= 0 && index < rowCount()) {
177+ QModelIndex sourceIndex = mapToSource(this->index(index, 0));
178+
179+ AppDrawerModelInterface* adm = dynamic_cast<AppDrawerModelInterface*>(m_source);
180+ qDebug() << "tried casting to ADMI:" << adm;
181+ if (adm) {
182+ return adm->data(sourceIndex, AppDrawerModelInterface::RoleAppId).toString();
183+ }
184+
185+ AppDrawerProxyModel* adpm = qobject_cast<AppDrawerProxyModel*>(m_source);
186+ if (adpm) {
187+ return adpm->appId(sourceIndex.row());
188+ }
189+ }
190+ qDebug() << "could nto cast source model";
191+ return nullptr;
192+}
plugins/Utils/appdrawerproxymodel.h+2
@@ -65,6 +65,8 @@ public:
6565 QVariant data(const QModelIndex &index, int role) const override;
6666 QHash<int, QByteArray> roleNames() const override;
6767
68+ Q_INVOKABLE QString appId(int index) const;
69+
6870protected:
6971 bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
7072
qml/Launcher/Drawer.qml+3−13
@@ -81,7 +81,7 @@ FocusScope {
8181 focus: true
8282 onAccepted: {
8383 if (searchField.displayText != "" && listLoader.item && listLoader.item.currentItem) {
84− root.applicationSelected(listLoader.item.currentItem.appId);
84+ root.applicationSelected(listLoader.item.getFirstAppId());
8585 }
8686 }
8787 }
@@ -166,12 +166,7 @@ FocusScope {
166166
167167 Component {
168168 id: mostUsedComponent
169− ListView {
170− anchors.fill: parent
171− topMargin: units.gu(1)
172− bottomMargin: units.gu(1)
173− spacing: units.gu(1)
174− clip: true
169+ DrawerListView {
175170
176171 header: MoreAppsHeader {
177172 width: parent.width
@@ -213,12 +208,7 @@ FocusScope {
213208
214209 Component {
215210 id: aToZComponent
216− ListView {
217− anchors.fill: parent
218− topMargin: units.gu(1)
219− bottomMargin: units.gu(1)
220− spacing: units.gu(1)
221− clip: true
211+ DrawerListView {
222212
223213 header: MoreAppsHeader {
224214 width: parent.width
qml/Launcher/DrawerListView.qmlnew file+31
@@ -0,0 +1,31 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.4
18+import Ubuntu.Components 1.3
19+
20+ListView {
21+ id: root
22+ anchors.fill: parent
23+ topMargin: units.gu(1)
24+ bottomMargin: units.gu(1)
25+ spacing: units.gu(1)
26+ clip: true
27+
28+ function getFirstAppId() {
29+ return model.appId(0);
30+ }
31+}
tests/mocks/Utils/CMakeLists.txt+2
@@ -31,6 +31,8 @@ set(QMLPLUGIN_SRC
3131 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceListInterface.h
3232 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/Mir.h
3333 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/AppDrawerModelInterface.h
34+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
35+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
3436 constants.cpp
3537 plugin.cpp
3638 windowstatestorage.cpp