Warning, /plasma/discover/discover/qml/SearchField.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *   SPDX-FileCopyrightText: 2017 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
0003  *   SPDX-FileCopyrightText: 2019 Carl Schwan <carl@carlschwan.eu>
0004  *
0005  *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006  */
0007 
0008 import QtQuick 2.5
0009 import QtQuick.Controls 2.1
0010 import org.kde.kirigami 2.14 as Kirigami
0011 
0012 Kirigami.SearchField
0013 {
0014     id: searchField
0015 
0016     // Search operations are network-intensive, so we can't have search-as-you-type.
0017     // This means we should turn off auto-accept entirely, rather than having it on
0018     // with a delay. The result just isn't good. See Bug 445142.
0019     autoAccept: false
0020 
0021     property QtObject page
0022     property string currentSearchText
0023 
0024     placeholderText: (!enabled || !page || page.hasOwnProperty("isHome") || window.leftPage.name.length === 0) ? i18n("Search…") : i18n("Search in '%1'…", window.leftPage.name)
0025 
0026     onAccepted: {
0027         searchField.text = searchField.text.replace(/\n/g, ' ');
0028         currentSearchText = searchField.text
0029     }
0030 
0031     function clearText() {
0032         searchField.text = ""
0033         searchField.accepted()
0034     }
0035 
0036     Connections {
0037         ignoreUnknownSignals: true
0038         target: page
0039         function onClearSearch() {
0040             clearText()
0041         }
0042     }
0043 
0044     Connections {
0045         target: applicationWindow()
0046         function onCurrentTopLevelChanged() {
0047             if (applicationWindow().currentTopLevel.length > 0)
0048                 clearText()
0049         }
0050     }
0051 }