~nick-dedekind/unity8/indicator.submenu-reinit

« back to all changes in this revision

Viewing changes to plugins/Unity/Indicators/qml/IndicatorPage.qml

  • Committer: Nick Dedekind
  • Date: 2013-09-26 11:00:25 UTC
  • Revision ID: nicholas.dedekind@gmail.com-20130926110025-1ygxdv5wmvgkmcok
Fixed menu selection on initial add.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
        // Only allow flicking if the content doesn't fit on the page
61
61
        interactive: contentHeight > height
62
62
 
63
 
        currentIndex: -1
 
63
        property int selectedIndex: -1
 
64
        property bool blockCurrentIndexChange: false
 
65
        // for count = 0
 
66
        onCountChanged: {
 
67
            if (count == 0 && selectedIndex != -1) {
 
68
                selectedIndex = -1;
 
69
            }
 
70
        }
 
71
        // for highlight following
 
72
        onSelectedIndexChanged: {
 
73
            if (currentIndex != selectedIndex) {
 
74
                var blocked = blockCurrentIndexChange;
 
75
                blockCurrentIndexChange = true;
 
76
 
 
77
                currentIndex = selectedIndex;
 
78
 
 
79
                blockCurrentIndexChange = blocked;
 
80
            }
 
81
        }
 
82
        // for item addition/removal
 
83
        onCurrentIndexChanged: {
 
84
            if (!blockCurrentIndexChange) {
 
85
                if (selectedIndex != -1 && selectedIndex != currentIndex) {
 
86
                    selectedIndex = currentIndex;
 
87
                }
 
88
            }
 
89
        }
 
90
 
64
91
        delegate: Item {
65
92
            id: menuDelegate
66
93
 
90
117
                    }
91
118
 
92
119
                    if (item.hasOwnProperty("menuSelected")) {
93
 
                        item.menuSelected = Qt.binding(function() { return mainMenu.currentIndex == index; });
94
 
                        item.selectMenu.connect(function() { mainMenu.currentIndex = index; });
95
 
                        item.deselectMenu.connect(function() { mainMenu.currentIndex = -1; });
 
120
                        item.menuSelected = Qt.binding(function() { return mainMenu.selectedIndex == index; });
 
121
                        item.selectMenu.connect(function() { mainMenu.selectedIndex = index; });
 
122
                        item.deselectMenu.connect(function() { mainMenu.selectedIndex = -1; });
96
123
                    }
97
124
                    if (item.hasOwnProperty("menu")) {
98
125
                        item.menu = Qt.binding(function() { return model; });
149
176
 
150
177
    function reset()
151
178
    {
152
 
        mainMenu.currentIndex = -1;
 
179
        mainMenu.selectedIndex = -1;
153
180
        mainMenu.positionViewAtBeginning();
154
181
    }
155
182
}