@@ -64,9 +64,12 @@ Item {
67− function closePopup() {
67+ function closePopup(keepFocus) {
68 if (headerContainer.popover != null) {
68 if (headerContainer.popover != null) {
69+ headerContainer.popover.unfocusOnDestruction = !keepFocus;
69 PopupUtils.close(headerContainer.popover);
70 PopupUtils.close(headerContainer.popover);
71+ } else if (!keepFocus) {
@@ -74,11 +77,8 @@ Item {
74 if (searchHistory) {
77 if (searchHistory) {
75 searchHistory.addQuery(searchTextField.text);
78 searchHistory.addQuery(searchTextField.text);
80 searchTextField.text = "";
80 searchTextField.text = "";
81− closePopup();
81+ closePopup(keepFocus);
84 function unfocus() {
84 function unfocus() {
@@ -119,11 +119,10 @@ Item {
119 anchors { fill: parent; margins: units.gu(1); bottomMargin: units.gu(3) + bottomContainer.height }
119 anchors { fill: parent; margins: units.gu(1); bottomMargin: units.gu(3) + bottomContainer.height }
120 visible: headerContainer.showSearch
120 visible: headerContainer.showSearch
121 onPressed: {
121 onPressed: {
122− closePopup();
122+ closePopup(/* keepFocus */false);
123 if (!searchTextField.text) {
123 if (!searchTextField.text) {
124 headerContainer.showSearch = false;
124 headerContainer.showSearch = false;
126− searchTextField.focus = false;
127 mouse.accepted = false;
126 mouse.accepted = false;
@@ -228,7 +227,7 @@ Item {
229 onTextChanged: {
228 onTextChanged: {
230 if (text != "") {
229 if (text != "") {
231− closePopup();
230+ closePopup(/* keepFocus */true);
@@ -310,8 +309,13 @@ Item {
310 id: popover
309 id: popover
311 autoClose: false
310 autoClose: false
312+ property bool unfocusOnDestruction: false
313 Component.onDestruction: {
314 Component.onDestruction: {
314 headerContainer.popover = null;
315 headerContainer.popover = null;
316+ if (unfocusOnDestruction) {
@@ -332,8 +336,7 @@ Item {
332 onClicked: {
336 onClicked: {
333 searchHistory.addQuery(text);
337 searchHistory.addQuery(text);
334 searchTextField.text = text;
338 searchTextField.text = text;
335− closePopup();
339+ closePopup(/* keepFocus */false);