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;
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
116 property bool narrowMode: parent.width < label.contentWidth + units.gu(50)
118 property bool active: searchField.text != "" || searchField.activeFocus
119 property var popover: null
121 anchors.right: textContainer.right
122 height: header.height
125 if (active && narrowMode) "narrowActive"
126 else if (!active && narrowMode) "narrowInactive"
127 else if (active && !narrowMode) "active"
128 else if (!active && !narrowMode) "inactive"
130 function openPopover() {
131 if (searchHistory.count > 0) {
132 searchContainer.popover = PopupUtils.open(popoverComponent, searchField,
134 "pointerTarget": pointerPositioner,
135 "contentWidth": searchField.width,
136 "edgeMargins": units.gu(1)
142 function closePopover() {
143 if (searchContainer.popover) PopupUtils.close(searchContainer.popover)
146 onActiveFocusChanged: if (!activeFocus) { searchHistory.addQuery(searchField.text) }
152 anchors.margins: units.gu(1)
154 hasClearButton: false
156 primaryItem: AbstractButton {
157 enabled: searchField.text != "" && !searchIndicator.running
159 if (searchField.text != "") {
160 searchHistory.addQuery(searchField.text)
161 searchField.text = ""
164 height: parent.height
169 objectName: "searchIndicator"
172 verticalCenter: parent.verticalCenter
174 leftMargin: units.gu(0.5)
182 objectName: "primaryImage"
184 verticalCenter: parent.verticalCenter
186 leftMargin: units.gu(0.5)
194 id: pointerPositioner
195 anchors.left: parent.right
196 anchors.leftMargin: units.gu(0.5)
197 anchors.top: parent.bottom
202 if (text != "") searchContainer.closePopover()
203 else if (text == "" && activeFocus) searchContainer.openPopover()
206 onActiveFocusChanged: {
207 if (!activeFocus) searchContainer.closePopover()
213 when: scope && scope.searchInProgress
214 PropertyChanges { target: searchIndicator; running: true; opacity: 1 }
215 PropertyChanges { target: primaryImage; opacity: 0 }
219 when: !scope || !scope.searchInProgress
220 PropertyChanges { target: searchIndicator; opacity: 0 }
221 PropertyChanges { target: primaryImage; opacity: 1 }
229 SequentialAnimation {
230 NumberAnimation { target: primaryImage; property: "opacity"; duration: UbuntuAnimation.FastDuration; easing.type: Easing.Linear }
231 NumberAnimation { target: searchIndicator; property: "opacity"; duration: UbuntuAnimation.FastDuration; easing.type: Easing.Linear }
240 AnchorChanges { target: textContainer; anchors.top: headerContainer.top }
241 AnchorChanges { target: searchContainer; anchors.left: undefined; anchors.top: textContainer.top }
245 PropertyChanges { target: searchField; highlighted: true }
246 AnchorChanges { target: textContainer; anchors.top: searchContainer.bottom }
247 AnchorChanges { target: searchContainer; anchors.left: headerContainer.left; anchors.top: headerContainer.top }
252 PropertyChanges { target: searchContainer; width: units.gu(40) }
253 PropertyChanges { target: primaryImage; source: searchField.text ? "../Dash/graphics/icon_clear.png" : "../Dash/graphics/icon_search_active.png" }
254 PropertyChanges { target: searchField; highlighted: true }
259 PropertyChanges { target: searchContainer; width: units.gu(25) }
260 PropertyChanges { target: primaryImage; source: "../Dash/graphics/icon_search_inactive.png" }
261 PropertyChanges { target: searchField; highlighted: false }
266 PropertyChanges { target: header; contentY: 0 }
267 PropertyChanges { target: primaryImage; source: searchField.text ? "../Dash/graphics/icon_clear.png" : "../Dash/graphics/icon_search_active.png" }
270 name: "narrowInactive"
272 PropertyChanges { target: header; contentY: header.height }
273 PropertyChanges { target: primaryImage; source: searchField.text ? "../Dash/graphics/icon_clear.png" : "../Dash/graphics/icon_search_active.png" }
280 SequentialAnimation {
282 NumberAnimation { targets: [searchContainer, searchField]; property: "width"; duration: 200; easing.type: Easing.InOutQuad }
283 PropertyAction { target: primaryImage; property: "source" }
284 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
286 ScriptAction { script: searchContainer.openPopover() }
291 ScriptAction { script: searchContainer.closePopover() }
292 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.InOutQuad }
293 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
297 SequentialAnimation {
299 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.OutQuad }
300 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
302 ScriptAction { script: searchContainer.openPopover() }
307 ScriptAction { script: searchContainer.closePopover() }
308 NumberAnimation { targets: [searchContainer, searchField] ; property: "width"; duration: 200; easing.type: Easing.OutQuad }
309 AnchorAnimation { targets: [searchContainer, textContainer]; duration: 200; easing.type: Easing.InOutQuad }
318 // FIXME: this should go into the first item below, but enable: false
319 // prevents mouse events propagation
328 onClicked: searchContainer.closePopover()
331 anchors.centerIn: parent
334 source: "../Dash/graphics/icon_listview_clear.png"
345 ListItem.Standard { enabled: false; text: i18n.tr("Recent searches") }
351 delegate: ListItem.Standard {
352 showDivider: index < recentSearches.count - 1
355 searchHistory.addQuery(text)
356 searchField.text = text
365 enabled: searchField.activeFocus
373 height: searchContainer.popover ? parent.height + searchContainer.popover.contentHeight + units.gu(2) : parent.height
375 onPressed: searchField.focus = false
387 bottom: parent.bottom
390 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