on xenial help sign in
Refactor the Drawer for easier testing
c1712dfDalton Durst
qml/Launcher/Drawer.qml+71
@@ -31,12 +31,82 @@ FocusScope {
31 readonly property bool moving: appList && appList.moving
31 readonly property bool moving: appList && appList.moving
32 readonly property Item searchTextField: searchField
32 readonly property Item searchTextField: searchField
33 readonly property real delegateWidth: units.gu(10)
33 readonly property real delegateWidth: units.gu(10)
34+ visible: x > -width
35+ property var fullyOpen: x === 0
36+ property var fullyClosed: x === -width
34
37
35 signal applicationSelected(string appId)
38 signal applicationSelected(string appId)
36
39
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
37 property bool draggingHorizontally: false
49 property bool draggingHorizontally: false
38 property int dragDistance: 0
50 property int dragDistance: 0
39
51
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+
40 function focusInput() {
110 function focusInput() {
41 searchField.selectAll();
111 searchField.selectAll();
42 searchField.focus = true;
112 searchField.focus = true;
@@ -96,6 +166,7 @@ FocusScope {
96
166
97 MouseArea {
167 MouseArea {
98 id: drawerHandle
168 id: drawerHandle
169+ objectName: "drawerHandle"
99 anchors {
170 anchors {
100 right: parent.right
171 right: parent.right
101 top: parent.top
172 top: parent.top
qml/Launcher/Launcher.qml+5−52
@@ -352,34 +352,10 @@ FocusScope {
352 topMargin: root.inverted ? root.topPanelHeight : 0
352 topMargin: root.inverted ? root.topPanelHeight : 0
353 bottom: parent.bottom
353 bottom: parent.bottom
354 right: parent.left
354 right: parent.left
355− onRightMarginChanged: {
356− if (fullyOpen && hadFocus) {
357− // See drawer.onDraggingHorizontallyChanged below
358− drawer.searchTextField.focus = hadFocus;
359− drawer.searchTextField.select(oldSelectionStart, oldSelectionEnd);
360− } else if (fullyClosed) {
361− drawer.searchTextField.text = "";
362− }
363− resetOldFocus();
364− }
365 }
355 }
366 width: Math.min(root.width, units.gu(81))
356 width: Math.min(root.width, units.gu(81))
367 panelWidth: panel.width
357 panelWidth: panel.width
368− visible: x > -width
369− property var fullyOpen: x === 0
370− property var fullyClosed: x === -width
371−
372− property var hadFocus: false
373− property var oldSelectionStart: null
374− property var oldSelectionEnd: null
375−
376− Behavior on anchors.rightMargin {
377− enabled: !dragArea.dragging && !launcherDragArea.drag.active && panel.animate && !drawer.draggingHorizontally
358+ allowSlidingAnimation: !dragArea.dragging && !launcherDragArea.drag.active && panel.animate
378− NumberAnimation {
379− duration: 300
380− easing.type: Easing.OutCubic
381− }
382− }
383
359
384 onApplicationSelected: {
360 onApplicationSelected: {
385 root.hide();
361 root.hide();
@@ -387,35 +363,12 @@ FocusScope {
387 root.focus = false;
363 root.focus = false;
388 }
364 }
389
365
390− function resetOldFocus() {
366+ onHide: {
391− hadFocus = false;
392− oldSelectionStart = null;
393− oldSelectionEnd = null;
394− }
395−
396− Keys.onEscapePressed: {
397− root.hide()
367+ root.hide();
398 }
368 }
399
369
400− onDragDistanceChanged: {
370+ onOpen: {
401− anchors.rightMargin = Math.max(-drawer.width, anchors.rightMargin + dragDistance);
402− }
403− onDraggingHorizontallyChanged: {
404− if (draggingHorizontally) {
405− // Remove (and put back using anchors.onRightMarginChanged) the
406− // focus for the searchfield in order to hide the copy/paste
407− // popover when we move the drawer
408− hadFocus = drawer.searchTextField.focus;
409− oldSelectionStart = drawer.searchTextField.selectionStart;
410− oldSelectionEnd = drawer.searchTextField.selectionEnd;
411− drawer.searchTextField.focus = false;
412− } else {
413− if (drawer.x < -units.gu(10)) {
414− root.hide();
415− } else {
416− root.toggleDrawer(false, true);
371+ root.toggleDrawer(false, true);
417− }
418− }
419 }
372 }
420 }
373 }
421
374