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 1.1
19import Ubuntu.Components.Themes.Ambiance 1.1
20import Ubuntu.Components.Popups 1.0
21import Ubuntu.Components.ListItems 1.0
22import "SearchHistoryModel"
26 objectName: "pageHeader"
27 implicitHeight: headerContainer.height + bottomContainer.height + (showSignatureLine ? units.gu(2) : 0)
29 property bool showBackButton: false
32 property bool searchEntryEnabled: false
33 property ListModel searchHistory: SearchHistoryModel
34 property alias searchQuery: searchTextField.text
35 property bool searchInProgress: false
36 property alias showSignatureLine: bottomBorder.visible
38 property alias bottomItem: bottomContainer.children
40 // TODO We should use foreground for the icons
41 // of the toolbar but unfortunately Action does not have
42 // the keyColor property as Icon does :-/
43 property var scopeStyle: null
47 onScopeStyleChanged: refreshLogo()
49 function triggerSearch() {
50 if (searchEntryEnabled) {
51 headerContainer.showSearch = true;
52 searchTextField.forceActiveFocus();
56 function resetSearch(keepFocus) {
58 searchHistory.addQuery(searchTextField.text);
63 searchTextField.text = "";
68 searchTextField.focus = false;
69 if (!searchTextField.text) {
70 headerContainer.showSearch = false;
74 function openSearchHistory() {
75 if (openSearchAnimation.running) {
76 openSearchAnimation.openSearchHistory = true;
77 } else if (root.searchHistory.count > 0 && headerContainer.popover == null) {
78 headerContainer.popover = PopupUtils.open(popoverComponent, searchTextField,
80 "contentWidth": searchTextField.width,
81 "edgeMargins": units.gu(1)
87 function closeSearchHistory() {
88 if (headerContainer.popover != null) {
89 PopupUtils.close(headerContainer.popover);
93 function refreshLogo() {
94 if (scopeStyle ? scopeStyle.headerLogo != "" : false) {
95 header.contents = imageComponent.createObject();
96 } else if (header.contents) {
97 header.contents.destroy();
98 header.contents = null;
103 target: root.scopeStyle
104 onHeaderLogoChanged: root.refreshLogo()
108 anchors { fill: parent; margins: units.gu(1); bottomMargin: units.gu(3) + bottomContainer.height }
109 visible: headerContainer.showSearch
111 closeSearchHistory();
112 if (!searchTextField.text) {
113 headerContainer.showSearch = false;
115 searchTextField.focus = false;
116 mouse.accepted = false;
122 objectName: "headerContainer"
124 anchors { left: parent.left; top: parent.top; right: parent.right }
125 height: units.gu(6.5)
126 contentHeight: headersColumn.height
128 contentY: showSearch ? 0 : height
130 property bool showSearch: false
131 property var popover: null
134 objectName: "headerBackground"
135 style: scopeStyle.headerBackground
138 Behavior on contentY {
139 UbuntuNumberAnimation {
140 id: openSearchAnimation
141 property bool openSearchHistory: false
144 if (!running && openSearchAnimation.openSearchHistory) {
145 openSearchAnimation.openSearchHistory = false;
146 root.openSearchHistory();
154 anchors { left: parent.left; right: parent.right }
158 anchors { left: parent.left; right: parent.right }
159 height: headerContainer.height
160 contentHeight: height
162 // Required to keep PageHeadStyle noise down as it expects the Page's properties around.
163 property var styledItem: searchHeader
164 property string title
165 property var config: PageHeadConfiguration {
170 headerContainer.showSearch = false;
174 property var contents: TextField {
176 objectName: "searchTextField"
177 hasClearButton: false
180 leftMargin: units.gu(1)
181 topMargin: units.gu(1)
182 bottomMargin: units.gu(1)
183 rightMargin: root.width > units.gu(60) ? root.width - units.gu(40) : units.gu(1)
186 secondaryItem: AbstractButton {
187 height: searchTextField.height
189 enabled: searchTextField.text.length > 0
192 objectName: "clearIcon"
194 anchors.margins: units.gu(.75)
195 source: "image://theme/clear"
196 opacity: searchTextField.text.length > 0 && !searchActivityIndicator.running
198 Behavior on opacity {
199 UbuntuNumberAnimation { duration: UbuntuAnimation.FastDuration }
204 id: searchActivityIndicator
205 objectName: "searchIndicator"
207 anchors.margins: units.gu(.75)
208 running: root.searchInProgress
209 opacity: running ? 1 : 0
210 Behavior on opacity {
211 UbuntuNumberAnimation { duration: UbuntuAnimation.FastDuration }
216 root.resetSearch(true);
217 root.openSearchHistory();
221 onActiveFocusChanged: {
223 root.openSearchHistory();
231 objectName: "innerPageHeader"
232 anchors { left: parent.left; right: parent.right }
233 height: headerContainer.height
234 contentHeight: height
236 textColor: root.scopeStyle ? root.scopeStyle.headerForeground : "grey"
237 property var styledItem: header
238 property string title: root.title
239 property var config: PageHeadConfiguration {
242 visible: root.showBackButton
252 visible: root.searchEntryEnabled
254 headerContainer.showSearch = true;
255 searchTextField.forceActiveFocus();
261 property var contents: null
262 Component.onCompleted: root.refreshLogo()
268 anchors { fill: parent; topMargin: units.gu(1); bottomMargin: units.gu(1) }
271 objectName: "titleImage"
273 source: root.scopeStyle ? root.scopeStyle.headerLogo : ""
274 fillMode: Image.PreserveAspectFit
275 horizontalAlignment: Image.AlignLeft
276 sourceSize.height: height
290 Component.onDestruction: {
291 headerContainer.popover = null;
306 showDivider: index < recentSearches.count - 1
309 searchHistory.addQuery(text);
310 searchTextField.text = text;
311 PopupUtils.close(popover);
322 top: headerContainer.bottom
325 bottom: bottomContainer.top
328 source: "graphics/PageHeaderBaseDivider.sci"
337 bottom: parent.bottom
339 height: childrenRect.height
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