on xenial help sign in
Restore focus to where it was when our ShellDialogs get unloaded

UITK Dialogs want to have this feature but it seems to be broken, so i'm fixing it here first (since we use dialogs in a kind of special way) I'll try to fix UITK next

commita87fdb37170c15a1d83327d8def290d1fe8aa6bd authorAlbert Astals Cid <albert.astals@canonical.com> dateThu 5 Jan 2017, 10:38 (10 years ago) parent712a613
2 files changed+43
qml/Components/Dialogs.qml+18 tests/qmltests/tst_OrientedShell.qml+25
qml/Components/Dialogs.qml+18
@@ -149,6 +149,24 @@ MouseArea {
149149 objectName: "dialogLoader"
150150 anchors.fill: parent
151151 active: false
152+ onActiveChanged: {
153+ if (!active) {
154+ previousSourceComponent = undefined;
155+ if (previousFocusedComponent) {
156+ previousFocusedComponent.forceActiveFocus(Qt.OtherFocusReason);
157+ previousFocusedComponent = undefined;
158+ }
159+ }
160+ }
161+ onSourceComponentChanged: {
162+ if (previousSourceComponent !== sourceComponent) {
163+ previousSourceComponent = sourceComponent;
164+ previousFocusedComponent = window.activeFocusItem;
165+ }
166+ }
167+
168+ property var previousSourceComponent: undefined
169+ property var previousFocusedComponent: undefined
152170 }
153171
154172 Component {
tests/qmltests/tst_OrientedShell.qml+25
@@ -1596,5 +1596,30 @@ Rectangle {
15961596
15971597 tryCompare(dialogLoader, "item", null);
15981598 }
1599+
1600+ function test_focusOnShutdownDialogClose() {
1601+ loadShell("manta");
1602+ usageModeSelector.selectWindowed();
1603+
1604+ var surfaceId = topLevelSurfaceList.nextId;
1605+ var app = ApplicationManager.startApplication("twitter-webapp");
1606+ waitUntilAppWindowIsFullyLoaded(surfaceId);
1607+
1608+ var primaryAppWindow = findAppWindowForSurfaceId(surfaceId);
1609+ var surface = app.surfaceList.get(0);
1610+ var surfaceItem = findSurfaceItem(primaryAppWindow, surface);
1611+
1612+ compare(window.activeFocusItem, surfaceItem);
1613+
1614+ testCase.showPowerDialog();
1615+
1616+ var dialogLoader = findChild(orientedShell, "dialogLoader");
1617+ tryCompareFunction(function() { return dialogLoader.item !== null }, true);
1618+
1619+ keyClick(Qt.Key_Escape);
1620+
1621+ tryCompare(dialogLoader, "item", null);
1622+ compare(window.activeFocusItem, surfaceItem);
1623+ }
15991624 }
16001625}