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
26 The text that is shown inside the Page Header
27 \qmlproperty string text
29 property alias text: label.text
31 property bool searchEntryEnabled: false
32 property alias searchQuery: searchField.text
33 property ListModel searchHistory: SearchHistoryModel {}
37 implicitHeight: units.gu(8.5)
39 function triggerSearch() {
40 if (searchEntryEnabled) searchField.forceActiveFocus()
43 function resetSearch() {
44 if (!searchHistory) return;
46 searchHistory.addQuery(searchField.text);
47 searchField.text = "";
48 searchField.focus = false;
53 onShownChanged: if (shown) resetSearch()
66 contentHeight: headerContainer.height
69 contentY: searchField.activeFocus || searchField.text != "" ? searchContainer.y : headerContainer.y
71 Behavior on contentY { NumberAnimation { duration: 200; easing.type: Easing.OutQuad } }
73 // FIXME this could potentially be simplified to avoid all the containers
78 height: childrenRect.height
90 leftMargin: units.gu(2)
92 verticalCenter: parent.verticalCenter
95 color: Theme.palette.selected.backgroundText
98 font.weight: Font.Light
100 elide: Text.ElideRight
108 objectName: "searchContainer"
110 visible: searchEntryEnabled
112 property bool narrowMode: parent.width < label.contentWidth + units.gu(50)
114 property bool active: searchField.text != "" || searchField.activeFocus
115 property var popover: null
117 anchors.right: textContainer.right
118 height: header.height
121 if (active && narrowMode) "narrowActive"
122 else if (!active && narrowMode) "narrowInactive"
123 else if (active && !narrowMode) "active"
124 else if (!active && !narrowMode) "inactive"
126 function openPopover() {
127 if (searchHistory.count > 0) {
128 searchContainer.popover = PopupUtils.open(popoverComponent, searchField,
130 "pointerTarget": pointerPositioner,
131 "contentWidth": searchField.width,
132 "edgeMargins": units.gu(1)
138 function closePopover() {
139 if (searchContainer.popover) PopupUtils.close(searchContainer.popover)
142 onActiveFocusChanged: if (!activeFocus) { searchHistory.addQuery(searchField.text) }
148 anchors.margins: units.gu(1)
150 hasClearButton: false
152 primaryItem: AbstractButton {
153 enabled: searchField.text != "" && !searchIndicator.running
155 if (searchField.text != "") {
156 searchHistory.addQuery(searchField.text)
157 searchField.text = ""
160 height: parent.height
165 objectName: "searchIndicator"
168 verticalCenter: parent.verticalCenter
170 leftMargin: units.gu(0.5)
178 objectName: "primaryImage"
180 verticalCenter: parent.verticalCenter
182 leftMargin: units.gu(0.5)
190 id: pointerPositioner
191 anchors.left: parent.right
192 anchors.leftMargin: units.gu(0.5)
193 anchors.top: parent.bottom
198 if (text != "") searchContainer.closePopover()
199 else if (text == "" && activeFocus) searchContainer.openPopover()
202 onActiveFocusChanged: {
203 if (!activeFocus) searchContainer.closePopover()
209 when: scope.searchInProgress && searchField.text !== ""
210 PropertyChanges { target: searchIndicator; running: true; opacity: 1 }
211 PropertyChanges { target: primaryImage; opacity: 0 }
215 when: !scope.searchInProgress || searchField.text === ""
216 PropertyChanges { target: searchIndicator; opacity: 0 }
217 PropertyChanges { target: primaryImage; opacity: 1 }
225 SequentialAnimation {
226 NumberAnimation { target: primaryImage; property: "opacity"; duration: UbuntuAnimation.FastDuration; easing.type: Easing.Linear }
227 NumberAnimation { target: searchIndicator; property: "opacity"; duration: UbuntuAnimation.FastDuration; easing.type: Easing.Linear }
236 AnchorChanges { target: textContainer; anchors.top: headerContainer.top }
237 AnchorChanges { target: searchContainer; anchors.left: undefined; anchors.top: textContainer.top }
241 PropertyChanges { target: searchField; highlighted: true }
242 AnchorChanges { target: textContainer; anchors.top: searchContainer.bottom }
243 AnchorChanges { target: searchContainer; anchors.left: headerContainer.left; anchors.top: headerContainer.top }
248 PropertyChanges { target: searchContainer; width: units.gu(40) }
249 PropertyChanges { target: primaryImage; source: searchField.text ? "../Dash/graphics/icon_clear.png" : "../Dash/graphics/icon_search_active.png" }
250 PropertyChanges { target: searchField; highlighted: true }
255 PropertyChanges { target: searchContainer; width: units.gu(25) }
256 PropertyChanges { target: primaryImage; source: "../Dash/graphics/icon_search_inactive.png" }
257 PropertyChanges { target: searchField; highlighted: false }
262 PropertyChanges { target: header; contentY: 0 }
263 PropertyChanges { target: primaryImage; source: searchField.text ? "../Dash/graphics/icon_clear.png" : "../Dash/graphics/icon_search_active.png" }
266 name: "narrowInactive"
268 PropertyChanges { target: header; contentY: header.height }
269 PropertyChanges { target: primaryImage; source: searchField.text ? "../Dash/graphics/icon_clear.png" : "../Dash/graphics/icon_search_active.png" }
276 SequentialAnimation {
278 NumberAnimation { targets: [searchContainer, searchField]; property: "width"; duration: 200; easing.type: Easing.InOutQuad }
279 PropertyAction { target: primaryImage; property: "source" }
280 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
282 ScriptAction { script: searchContainer.openPopover() }
287 ScriptAction { script: searchContainer.closePopover() }
288 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.InOutQuad }
289 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
293 SequentialAnimation {
295 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.OutQuad }
296 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
298 ScriptAction { script: searchContainer.openPopover() }
303 ScriptAction { script: searchContainer.closePopover() }
304 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.OutQuad }
305 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
314 // FIXME: this should go into the first item below, but enable: false
315 // prevents mouse events propagation
324 onClicked: searchContainer.closePopover()
327 anchors.centerIn: parent
330 source: "../Dash/graphics/icon_listview_clear.png"
341 ListItem.Standard { enabled: false; text: i18n.tr("Recent searches") }
347 delegate: ListItem.Standard {
348 showDivider: index < recentSearches.count - 1
351 searchHistory.addQuery(text)
352 searchField.text = text
361 enabled: searchField.activeFocus
369 height: searchContainer.popover ? parent.height + searchContainer.popover.contentHeight + units.gu(2) : parent.height
371 onPressed: searchField.focus = false
383 bottom: parent.bottom
386 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