2 * Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
18import Ubuntu.Components 0.1
19import Ubuntu.Components.Popups 0.1
20import Ubuntu.Components.ListItems 0.1 as ListItem
25 property bool searchEntryEnabled: false
26 property alias searchQuery: searchField.text
27 property ListModel searchHistory
29 property alias childItem: itemContainer.children
32 implicitHeight: units.gu(8.5)
34 function triggerSearch() {
35 if (searchEntryEnabled) searchField.forceActiveFocus()
38 function resetSearch() {
39 if (!searchHistory) return;
41 searchHistory.addQuery(searchField.text);
43 searchField.text = "";
47 searchField.focus = false;
52 onShownChanged: if (shown) resetSearch()
65 contentHeight: headerContainer.height
68 contentY: searchField.activeFocus || searchField.text != "" ? searchContainer.y : headerContainer.y
70 Behavior on contentY { NumberAnimation { duration: 200; easing.type: Easing.OutQuad } }
72 // FIXME this could potentially be simplified to avoid all the containers
77 height: childrenRect.height
82 width: searchContainer.narrowMode ? header.width : header.width - searchContainer.width
88 objectName: "searchContainer"
90 visible: searchEntryEnabled
91 property bool popoverShouldOpen: false
92 property bool popoverShouldClose: false
94 property bool narrowMode: parent.width < units.gu(60)
96 property bool active: searchField.text != "" || searchField.activeFocus
97 property var popover: null
99 anchors.right: headerContainer.right
100 height: header.height
103 if (active && narrowMode) "narrowActive"
104 else if (!active && narrowMode) "narrowInactive"
105 else if (active && !narrowMode) "active"
106 else if (!active && !narrowMode) "inactive"
109 if (state == "active" || state == "narrowActive") {
110 popoverShouldOpen = true;
111 popoverShouldClose = false;
113 popoverShouldOpen = false;
114 popoverShouldClose = true;
118 function openPopover() {
119 if (searchHistory.count > 0) {
120 searchContainer.popover = PopupUtils.open(popoverComponent, searchField,
122 "pointerTarget": pointerPositioner,
123 "contentWidth": searchField.width,
124 "edgeMargins": units.gu(1)
128 popoverShouldOpen = false;
129 popoverShouldClose = false;
132 function closePopover() {
133 if (searchContainer.popover) {
134 PopupUtils.close(searchContainer.popover);
135 searchContainer.popover = null;
137 popoverShouldOpen = false;
138 popoverShouldClose = false;
141 onActiveFocusChanged: if (!activeFocus) { searchHistory.addQuery(searchField.text) }
147 anchors.margins: units.gu(1)
149 hasClearButton: false
151 primaryItem: AbstractButton {
152 enabled: searchField.text != "" && !searchIndicator.running
154 if (searchField.text != "") {
155 searchHistory.addQuery(searchField.text)
156 searchField.text = ""
159 height: parent.height
164 objectName: "searchIndicator"
167 verticalCenter: parent.verticalCenter
169 leftMargin: units.gu(0.5)
177 objectName: "primaryImage"
179 verticalCenter: parent.verticalCenter
181 leftMargin: units.gu(0.5)
189 id: pointerPositioner
190 anchors.left: parent.right
191 anchors.leftMargin: units.gu(0.5)
192 anchors.top: parent.bottom
197 if (text != "") searchContainer.closePopover()
198 else if (text == "" && activeFocus) searchContainer.openPopover()
201 onActiveFocusChanged: {
202 if (!activeFocus) searchContainer.closePopover()
208 when: scope && scope.searchInProgress
209 PropertyChanges { target: searchIndicator; running: true; opacity: 1 }
210 PropertyChanges { target: primaryImage; opacity: 0 }
214 when: !scope || !scope.searchInProgress
215 PropertyChanges { target: searchIndicator; opacity: 0 }
216 PropertyChanges { target: primaryImage; opacity: 1 }
224 SequentialAnimation {
225 NumberAnimation { target: primaryImage; property: "opacity"; duration: UbuntuAnimation.FastDuration; easing.type: Easing.Linear }
226 NumberAnimation { target: searchIndicator; property: "opacity"; duration: UbuntuAnimation.FastDuration; easing.type: Easing.Linear }
235 AnchorChanges { target: itemContainer; anchors.top: headerContainer.top }
236 AnchorChanges { target: searchContainer; anchors.left: undefined; anchors.top: itemContainer.top }
240 PropertyChanges { target: searchField; highlighted: true }
241 AnchorChanges { target: itemContainer; anchors.top: searchContainer.bottom }
242 AnchorChanges { target: searchContainer; anchors.left: headerContainer.left; anchors.top: headerContainer.top }
247 PropertyChanges { target: searchContainer; width: units.gu(40) }
248 PropertyChanges { target: primaryImage; source: searchField.text ? "../Dash/graphics/icon_clear.png" : "../Dash/graphics/icon_search_active.png" }
249 PropertyChanges { target: searchField; highlighted: true }
254 PropertyChanges { target: searchContainer; width: units.gu(25) }
255 PropertyChanges { target: primaryImage; source: "../Dash/graphics/icon_search_inactive.png" }
256 PropertyChanges { target: searchField; highlighted: false }
261 PropertyChanges { target: header; contentY: 0 }
262 PropertyChanges { target: primaryImage; source: searchField.text ? "../Dash/graphics/icon_clear.png" : "../Dash/graphics/icon_search_active.png" }
265 name: "narrowInactive"
267 PropertyChanges { target: header; contentY: header.height }
268 PropertyChanges { target: primaryImage; source: searchField.text ? "../Dash/graphics/icon_clear.png" : "../Dash/graphics/icon_search_active.png" }
275 SequentialAnimation {
277 NumberAnimation { targets: [searchContainer, searchField]; property: "width"; duration: 200; easing.type: Easing.InOutQuad }
278 PropertyAction { target: primaryImage; property: "source" }
279 AnchorAnimation { targets: [searchContainer, itemContainer]; duration: 200; easing.type: Easing.InOutQuad }
281 ScriptAction { script: if (searchContainer.popoverShouldOpen) { searchContainer.openPopover(); } }
286 ScriptAction { script: if (searchContainer.popoverShouldClose) { searchContainer.closePopover(); } }
287 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.InOutQuad }
288 AnchorAnimation { targets: [searchContainer, itemContainer]; duration: 200; easing.type: Easing.InOutQuad }
292 SequentialAnimation {
294 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.OutQuad }
295 AnchorAnimation { targets: [searchContainer, itemContainer]; duration: 200; easing.type: Easing.InOutQuad }
297 ScriptAction { script: if (searchContainer.popoverShouldOpen) { searchContainer.openPopover(); } }
302 ScriptAction { script: if (searchContainer.popoverShouldClose) { searchContainer.closePopover(); } }
303 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.OutQuad }
304 AnchorAnimation { targets: [searchContainer, itemContainer]; duration: 200; easing.type: Easing.InOutQuad }
313 // FIXME: this should go into the first item below, but enable: false
314 // prevents mouse events propagation
323 onClicked: searchContainer.closePopover()
326 anchors.centerIn: parent
329 source: "../Dash/graphics/icon_listview_clear.png"
340 ListItem.Standard { enabled: false; text: i18n.tr("Recent searches") }
346 delegate: ListItem.Standard {
347 showDivider: index < recentSearches.count - 1
350 searchHistory.addQuery(text)
351 searchField.text = text
360 enabled: searchField.activeFocus
368 height: searchContainer.popover ? parent.height + searchContainer.popover.contentHeight + units.gu(2) : parent.height
370 onPressed: searchField.focus = false
382 bottom: parent.bottom
385 source: "graphics/PageHeaderBaseDivider.sci"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list