Commit 2a130e1c authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Improve convergent logic

parent aca8e26b
......@@ -51,8 +51,6 @@ DiscoverPage {
title: category ? category.name : ""
onSearchChanged: {
if (search.length === 0)
Navigation.openHome()
appsModel.sortOrder = Qt.AscendingOrder
}
signal clearSearch()
......
......@@ -19,6 +19,7 @@
***************************************************************************/
import QtQuick 2.1
import QtQuick.Layouts 1.1
Loader
{
......@@ -28,5 +29,6 @@ Loader
property Component componentFalse
property bool condition
Layout.minimumHeight: item && item.Layout ? item.Layout.minimumHeight : 0
sourceComponent: condition ? componentTrue : componentFalse
}
......@@ -56,59 +56,28 @@ Kirigami.GlobalDrawer {
id: toploader
condition: drawer.wideScreen
Layout.fillWidth: true
componentTrue: TextField {
componentFalse: Item {
Layout.minimumHeight: 1
Keys.forwardTo: [window.pageStack]
}
componentTrue: SearchField {
id: searchField
visible: drawer.wideScreen
enabled: window.leftPage && (window.leftPage.searchFor != null || window.leftPage.hasOwnProperty("search"))
Keys.forwardTo: [window.pageStack]
Component.onCompleted: {
searchField.forceActiveFocus()
}
Shortcut {
sequence: "Ctrl+F"
onActivated: {
searchField.forceActiveFocus()
searchField.selectAll()
}
}
placeholderText: (!enabled || !window.leftPage || window.leftPage.title.length === 0) ? i18n("Search...") : i18n("Search in '%1'...", window.leftPage.title)
onTextChanged: {
if(window.stack.depth > 0)
searchTimer.running = true
drawer.currentSearchText = text
}
Connections {
ignoreUnknownSignals: true
target: window.leftPage
onClearSearch: {
searchField.text = ""
}
}
page: window.leftPage
Connections {
target: window
onCurrentTopLevelChanged: {
if (window.currentTopLevel.length > 0)
searchField.text = ""
}
}
onCurrentSearchTextChanged: {
if (currentSearchText.length === 0)
Navigation.openHome()
Timer {
id: searchTimer
running: false
repeat: false
interval: 200
onTriggered: {
var curr = window.leftPage;
if (!curr.hasOwnProperty("search")) {
Navigation.clearStack()
Navigation.openApplicationList( { search: parent.text })
} else
curr.search = parent.text;
var curr = window.leftPage;
if (!curr.hasOwnProperty("search")) {
Navigation.clearStack()
Navigation.openApplicationList( { search: currentSearchText })
} else {
curr.search = currentSearchText;
}
}
}
......
/***************************************************************************
* Copyright © 2017 Aleix Pol Gonzalez <aleixpol@blue-systems.com> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License or (at your option) version 3 or any later version *
* accepted by the membership of KDE e.V. (or its successor approved *
* by the membership of KDE e.V.), which shall act as a proxy *
* defined in Section 14 of version 3 of the license. *
* *
* 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, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
import QtQuick 2.5
import QtQuick.Controls 2.1
TextField
{
property QtObject page
property string currentSearchText
placeholderText: (!enabled || !page || page.title.length === 0) ? i18n("Search...") : i18n("Search in '%1'...", window.leftPage.title)
Shortcut {
sequence: "Ctrl+F"
onActivated: {
searchField.forceActiveFocus()
searchField.selectAll()
}
}
onTextChanged: {
if (applicationWindow().stack.depth > 0)
searchTimer.running = true
}
Component.onCompleted: forceActiveFocus()
Connections {
ignoreUnknownSignals: true
target: page
onClearSearch: {
searchField.text = ""
}
}
Connections {
target: applicationWindow()
onCurrentTopLevelChanged: {
if (applicationWindow().currentTopLevel.length > 0)
searchField.text = ""
}
}
Timer {
id: searchTimer
running: false
repeat: false
interval: 200
onTriggered: {
currentSearchText = parent.text
}
}
}
......@@ -18,14 +18,34 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
import QtQuick.Controls 1.1
import org.kde.discover 2.0
import QtQuick 2.5
ApplicationsListPage {
id: page
id: searchPage
listHeaderExtra: TextField {
signal shown()
Timer {
interval: 0
running: true
onTriggered: {
searchPage.shown()
}
}
listHeaderExtra: SearchField {
id: searchField
focus: true
onTextChanged: page.search = text
Connections {
ignoreUnknownSignals: true
target: searchPage
onShown: {
searchField.forceActiveFocus()
}
}
onCurrentSearchTextChanged: {
searchPage.search = currentSearchText
}
}
}
......@@ -17,9 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import QtQuick 2.1
import org.kde.kirigami 2.0
import "navigation.js" as Navigation
Action {
property string component
......
......@@ -32,6 +32,7 @@
<file>qml/DiscoverDrawer.qml</file>
<file>qml/ActionListItem.qml</file>
<file>qml/LoadingPage.qml</file>
<file>qml/SearchField.qml</file>
<file>qml/navigation.js</file>
</qresource>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment