Commit 2f5413cc authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

Fix tab order

parent 572d014f
......@@ -30,3 +30,20 @@ function setTabOrder(lst) {
}
}
}
/**
* Return a list of all children of item (including item itself) which have the
* boolean property "tabMe" set to true
*/
function findTabMeChildren(item) {
var lst = new Array();
if (item.tabMe === true) {
lst.push(item);
} else {
for (var idx = 0; idx < item.children.length; ++idx) {
var childLst = findTabMeChildren(item.children[idx]);
lst = lst.concat(childLst);
};
}
return lst;
}
......@@ -28,6 +28,8 @@ FocusScope {
signal indexClicked(int index)
property bool tabMe: gridView.count > 0
//FIXME: figure out sizing properly..
property int resultItemHeight: 128
property int resultItemWidth: 128
......@@ -131,7 +133,7 @@ FocusScope {
focus: true
/*
// Debug help
// Focus debug help
LogText {
anchors.right: parent.right
anchors.bottom: parent.bottom
......
......@@ -25,7 +25,7 @@ import org.kde.plasma.components 0.1 as PlasmaComponents
import "KeyboardUtils.js" as KeyboardUtils
FocusScope {
Item {
id: main
property variant favoriteModels
......@@ -35,6 +35,7 @@ FocusScope {
property string searchCriteria
signal resultTriggered
signal updateTabOrderRequested
// Internal
property variant browseModels: []
......@@ -101,6 +102,9 @@ FocusScope {
}
}
}
onItemAdded: updateTabOrderRequested()
onItemRemoved: updateTabOrderRequested()
}
}
......@@ -208,12 +212,12 @@ FocusScope {
page.destroy();
}
page = pageComponent.createObject(main);
var views = models.map(function(model) {
models.forEach(function(model) {
var component = "modelForRow" in model ? multiResultsViewComponent : resultsViewComponent;
return component.createObject(page.viewContainer, {"model": model, "favoriteModels": favoriteModels});
component.createObject(page.viewContainer, {"model": model, "favoriteModels": favoriteModels});
});
KeyboardUtils.setTabOrder(views);
updateTabOrderRequested();
}
function reset() {
......
......@@ -24,6 +24,8 @@ import org.kde.plasma.core 0.1 as PlasmaCore
import org.kde.plasma.components 0.1 as PlasmaComponents
import org.kde.qtextracomponents 0.1 as QtExtra
import "KeyboardUtils.js" as KeyboardUtils
Item {
id: main
signal closeRequested
......@@ -55,9 +57,15 @@ Item {
Component {
id: tabContent
TabContent {
id: tabContentMain
// FIXME: If SAL is a containment mode, onResultTriggered should
// call reset() instead of emitting closeRequested()
onResultTriggered: closeRequested()
onUpdateTabOrderRequested: {
if (currentTabContent == tabContentMain) {
updateTabOrder();
}
}
}
}
......@@ -84,22 +92,12 @@ Item {
// This should not be "var tab": we set the "tab" property of the TabButton
tab = tabContent.createObject(tabGroup, {"sources": model.sources, "favoriteModels": favoriteModels});
var lst = tabContentList;
if (lst.length == 0) {
tab.forceActiveFocus();
}
lst.push(tab);
tabContentList = lst;
}
}
}
Connections {
target: tabGroup
onCurrentTabChanged: {
tabGroup.currentTab.forceActiveFocus();
}
}
/**
* Use duck-typing to determine if an item is a tab and not a Repeater
* or something else.
......@@ -209,7 +207,6 @@ Item {
bottom: filterTabBar.bottom
}
focus: true
width: parent.width / 4
visible: currentTabContent.searchable
......@@ -239,6 +236,20 @@ Item {
elementId: "horizontal-line"
}
Connections {
target: main
onCurrentTabContentChanged: {
updateTabOrder();
var firstView = searchField.KeyNavigation.tab;
if (firstView) {
firstView.forceActiveFocus();
}
}
}
Component.onCompleted: {
updateTabOrder();
}
// Code
function reset() {
......@@ -249,6 +260,15 @@ Item {
searchField.text = "";
}
function updateTabOrder() {
if (currentTabContent) {
var lst = KeyboardUtils.findTabMeChildren(currentTabContent);
lst.unshift(searchField);
lst.push(searchField);
KeyboardUtils.setTabOrder(lst);
}
}
Keys.onPressed: {
var lst = [
[Qt.ControlModifier, Qt.Key_PageUp, filterTabBar.goToPreviousTab],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment