@@ -31,12 +31,82 @@ FocusScope {
3131 readonly property bool moving: appList && appList.moving
3232 readonly property Item searchTextField: searchField
3333 readonly property real delegateWidth: units.gu(10)
34+ visible: x > -width
35+ property var fullyOpen: x === 0
36+ property var fullyClosed: x === -width
3437
3538 signal applicationSelected(string appId)
3639
40+ // Request that the Drawer is opened fully, if it was partially closed then
41+ // brought back
42+ signal open();
43+
44+ // Request that the Drawer (and maybe its parent) is hidden, normally if
45+ // the Drawer has been dragged away.
46+ signal hide();
47+
48+ property bool allowSlidingAnimation: false
3749 property bool draggingHorizontally: false
3850 property int dragDistance: 0
3951
52+ property var hadFocus: false
53+ property var oldSelectionStart: null
54+ property var oldSelectionEnd: null
55+
56+ anchors {
57+ onRightMarginChanged: {
58+ if (fullyOpen && hadFocus) {
59+ // See onDraggingHorizontallyChanged below
60+ searchField.focus = hadFocus;
61+ searchField.select(oldSelectionStart, oldSelectionEnd);
62+ return;
63+ } else if (fullyClosed || fullyOpen) {
64+ searchField.text = "";
65+ resetOldFocus();
66+ }
67+ }
68+ }
69+
70+ Behavior on anchors.rightMargin {
71+ enabled: allowSlidingAnimation && !draggingHorizontally
72+ NumberAnimation {
73+ duration: 300
74+ easing.type: Easing.OutCubic
75+ }
76+ }
77+
78+ onDraggingHorizontallyChanged: {
79+ if (draggingHorizontally) {
80+ // Remove (and put back using anchors.onRightMarginChanged) the
81+ // focus for the searchfield in order to hide the copy/paste
82+ // popover when we move the drawer
83+ hadFocus = searchField.focus;
84+ oldSelectionStart = searchField.selectionStart;
85+ oldSelectionEnd = searchField.selectionEnd;
86+ searchField.focus = false;
87+ } else {
88+ if (x < -units.gu(10)) {
89+ hide();
90+ } else {
91+ requestOpen();
92+ }
93+ }
94+ }
95+
96+ Keys.onEscapePressed: {
97+ root.hide()
98+ }
99+
100+ onDragDistanceChanged: {
101+ anchors.rightMargin = Math.max(-drawer.width, anchors.rightMargin + dragDistance);
102+ }
103+
104+ function resetOldFocus() {
105+ hadFocus = false;
106+ oldSelectionStart = null;
107+ oldSelectionEnd = null;
108+ }
109+
40110 function focusInput() {
41111 searchField.selectAll();
42112 searchField.focus = true;
@@ -96,6 +166,7 @@ FocusScope {
96166
97167 MouseArea {
98168 id: drawerHandle
169+ objectName: "drawerHandle"
99170 anchors {
100171 right: parent.right
101172 top: parent.top