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 Approved by: Andrea Cimitan, Unity8 CI Bot

commit7b99df23b10db8e2ff2afc398e7e8cb89f233652 authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 24 Jan 2017, 07:38 (10 years ago) parent3f99e4cf47d0f3
2 files changed+54
qml/Components/Dialogs.qml+19 tests/qmltests/tst_OrientedShell.qml+35
qml/Components/Dialogs.qml+19
@@ -149,6 +149,25 @@ MouseArea {
149149 objectName: "dialogLoader"
150150 anchors.fill: parent
151151 active: false
152+ onActiveChanged: {
153+ if (!active) {
154+ if (previousFocusedItem) {
155+ previousFocusedItem.forceActiveFocus(Qt.OtherFocusReason);
156+ previousFocusedItem = undefined;
157+ }
158+ previousSourceComponent = undefined;
159+ sourceComponent = undefined;
160+ }
161+ }
162+ onSourceComponentChanged: {
163+ if (previousSourceComponent !== sourceComponent) {
164+ previousSourceComponent = sourceComponent;
165+ previousFocusedItem = window.activeFocusItem;
166+ }
167+ }
168+
169+ property var previousSourceComponent: undefined
170+ property var previousFocusedItem: undefined
152171 }
153172
154173 Component {
tests/qmltests/tst_OrientedShell.qml+35
@@ -1603,5 +1603,40 @@ Rectangle {
16031603
16041604 tryCompare(dialogLoader, "item", null);
16051605 }
1606+
1607+ function test_focusOnShutdownDialogClose() {
1608+ loadShell("manta");
1609+ usageModeSelector.selectWindowed();
1610+
1611+ var surfaceId = topLevelSurfaceList.nextId;
1612+ var app = ApplicationManager.startApplication("twitter-webapp");
1613+ waitUntilAppWindowIsFullyLoaded(surfaceId);
1614+
1615+ var primaryAppWindow = findAppWindowForSurfaceId(surfaceId);
1616+ var surface = app.surfaceList.get(0);
1617+ var surfaceItem = findSurfaceItem(primaryAppWindow, surface);
1618+
1619+ compare(window.activeFocusItem, surfaceItem);
1620+
1621+ testCase.showPowerDialog();
1622+
1623+ var dialogLoader = findChild(orientedShell, "dialogLoader");
1624+ tryCompareFunction(function() { return dialogLoader.item !== null }, true);
1625+
1626+ keyClick(Qt.Key_Escape);
1627+
1628+ tryCompare(dialogLoader, "item", null);
1629+ compare(window.activeFocusItem, surfaceItem);
1630+
1631+ // Do it twice, our previous solution failed the second time ^_^
1632+ testCase.showPowerDialog();
1633+
1634+ tryCompareFunction(function() { return dialogLoader.item !== null }, true);
1635+
1636+ keyClick(Qt.Key_Escape);
1637+
1638+ tryCompare(dialogLoader, "item", null);
1639+ compare(window.activeFocusItem, surfaceItem);
1640+ }
16061641 }
16071642}