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
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);
48 searchField.text = "";
52 searchField.focus = false;
57 onShownChanged: if (shown) resetSearch()
70 contentHeight: headerContainer.height
73 contentY: searchField.activeFocus || searchField.text != "" ? searchContainer.y : headerContainer.y
75 Behavior on contentY { NumberAnimation { duration: 200; easing.type: Easing.OutQuad } }
77 // FIXME this could potentially be simplified to avoid all the containers
82 height: childrenRect.height
94 leftMargin: units.gu(2)
96 verticalCenter: parent.verticalCenter
99 color: Theme.palette.selected.backgroundText
101 font.family: "Ubuntu"
102 font.weight: Font.Light
104 elide: Text.ElideRight
112 objectName: "searchContainer"
114 visible: searchEntryEnabled
115 property bool popoverShouldOpen: false
116 property bool popoverShouldClose: false
118 property bool narrowMode: parent.width < label.contentWidth + units.gu(50)
120 property bool active: searchField.text != "" || searchField.activeFocus
121 property var popover: null
123 anchors.right: textContainer.right
124 height: header.height
127 if (active && narrowMode) "narrowActive"
128 else if (!active && narrowMode) "narrowInactive"
129 else if (active && !narrowMode) "active"
130 else if (!active && !narrowMode) "inactive"
133 if (state == "active" || state == "narrowActive") {
134 popoverShouldOpen = true;
135 popoverShouldClose = false;
137 popoverShouldOpen = false;
138 popoverShouldClose = true;
142 function openPopover() {
143 if (searchHistory.count > 0) {
144 searchContainer.popover = PopupUtils.open(popoverComponent, searchField,
146 "pointerTarget": pointerPositioner,
147 "contentWidth": searchField.width,
148 "edgeMargins": units.gu(1)
152 popoverShouldOpen = false;
153 popoverShouldClose = false;
156 function closePopover() {
157 if (searchContainer.popover) {
158 PopupUtils.close(searchContainer.popover);
159 searchContainer.popover = null;
161 popoverShouldOpen = false;
162 popoverShouldClose = false;
165 onActiveFocusChanged: if (!activeFocus) { searchHistory.addQuery(searchField.text) }
171 anchors.margins: units.gu(1)
173 hasClearButton: false
175 primaryItem: AbstractButton {
176 enabled: searchField.text != "" && !searchIndicator.running
178 if (searchField.text != "") {
179 searchHistory.addQuery(searchField.text)
180 searchField.text = ""
183 height: parent.height
188 objectName: "searchIndicator"
191 verticalCenter: parent.verticalCenter
193 leftMargin: units.gu(0.5)
201 objectName: "primaryImage"
203 verticalCenter: parent.verticalCenter
205 leftMargin: units.gu(0.5)
213 id: pointerPositioner
214 anchors.left: parent.right
215 anchors.leftMargin: units.gu(0.5)
216 anchors.top: parent.bottom
221 if (text != "") searchContainer.closePopover()
222 else if (text == "" && activeFocus) searchContainer.openPopover()
225 onActiveFocusChanged: {
226 if (!activeFocus) searchContainer.closePopover()
232 when: scope && scope.searchInProgress
233 PropertyChanges { target: searchIndicator; running: true; opacity: 1 }
234 PropertyChanges { target: primaryImage; opacity: 0 }
238 when: !scope || !scope.searchInProgress
239 PropertyChanges { target: searchIndicator; opacity: 0 }
240 PropertyChanges { target: primaryImage; opacity: 1 }
248 SequentialAnimation {
249 NumberAnimation { target: primaryImage; property: "opacity"; duration: UbuntuAnimation.FastDuration; easing.type: Easing.Linear }
250 NumberAnimation { target: searchIndicator; property: "opacity"; duration: UbuntuAnimation.FastDuration; easing.type: Easing.Linear }
259 AnchorChanges { target: textContainer; anchors.top: headerContainer.top }
260 AnchorChanges { target: searchContainer; anchors.left: undefined; anchors.top: textContainer.top }
264 PropertyChanges { target: searchField; highlighted: true }
265 AnchorChanges { target: textContainer; anchors.top: searchContainer.bottom }
266 AnchorChanges { target: searchContainer; anchors.left: headerContainer.left; anchors.top: headerContainer.top }
271 PropertyChanges { target: searchContainer; width: units.gu(40) }
272 PropertyChanges { target: primaryImage; source: searchField.text ? "../Dash/graphics/icon_clear.png" : "../Dash/graphics/icon_search_active.png" }
273 PropertyChanges { target: searchField; highlighted: true }
278 PropertyChanges { target: searchContainer; width: units.gu(25) }
279 PropertyChanges { target: primaryImage; source: "../Dash/graphics/icon_search_inactive.png" }
280 PropertyChanges { target: searchField; highlighted: false }
285 PropertyChanges { target: header; contentY: 0 }
286 PropertyChanges { target: primaryImage; source: searchField.text ? "../Dash/graphics/icon_clear.png" : "../Dash/graphics/icon_search_active.png" }
289 name: "narrowInactive"
291 PropertyChanges { target: header; contentY: header.height }
292 PropertyChanges { target: primaryImage; source: searchField.text ? "../Dash/graphics/icon_clear.png" : "../Dash/graphics/icon_search_active.png" }
299 SequentialAnimation {
301 NumberAnimation { targets: [searchContainer, searchField]; property: "width"; duration: 200; easing.type: Easing.InOutQuad }
302 PropertyAction { target: primaryImage; property: "source" }
303 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
305 ScriptAction { script: if (searchContainer.popoverShouldOpen) { searchContainer.openPopover(); } }
310 ScriptAction { script: if (searchContainer.popoverShouldClose) { searchContainer.closePopover(); } }
311 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.InOutQuad }
312 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
316 SequentialAnimation {
318 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.OutQuad }
319 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
321 ScriptAction { script: if (searchContainer.popoverShouldOpen) { searchContainer.openPopover(); } }
326 ScriptAction { script: if (searchContainer.popoverShouldClose) { searchContainer.closePopover(); } }
327 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.OutQuad }
328 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
337 // FIXME: this should go into the first item below, but enable: false
338 // prevents mouse events propagation
347 onClicked: searchContainer.closePopover()
350 anchors.centerIn: parent
353 source: "../Dash/graphics/icon_listview_clear.png"
364 ListItem.Standard { enabled: false; text: i18n.tr("Recent searches") }
370 delegate: ListItem.Standard {
371 showDivider: index < recentSearches.count - 1
374 searchHistory.addQuery(text)
375 searchField.text = text
384 enabled: searchField.activeFocus
392 height: searchContainer.popover ? parent.height + searchContainer.popover.contentHeight + units.gu(2) : parent.height
394 onPressed: searchField.focus = false
406 bottom: parent.bottom
409 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