Warning, /plasma/plasma-desktop/desktoppackage/contents/activitymanager/ActivityList.qml is written in an unsupported language. File is not indexed.
0001 /* vim:set foldmethod=marker:
0002
0003 SPDX-FileCopyrightText: 2014 Ivan Cukic <ivan.cukic(at)kde.org>
0004
0005 SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007
0008 import QtQuick 2.2
0009 import org.kde.kirigami 2.20 as Kirigami
0010 import org.kde.activities 0.1 as Activities
0011
0012 import org.kde.plasma.activityswitcher as ActivitySwitcher
0013
0014 Flickable {
0015 id: root
0016
0017 // contentWidth: content.width
0018 contentHeight: content.height
0019
0020 property var model: ActivitySwitcher.Backend.runningActivitiesModel()
0021 property string filterString: ""
0022 property bool showSwitcherOnly: false
0023
0024 property int itemsWidth: 0
0025
0026 property int selectedIndex: -1
0027
0028 function _selectRelativeToCurrent(distance)
0029 {
0030 var startingWithSelected = selectedIndex;
0031
0032 do {
0033 selectedIndex += distance;
0034
0035 if (selectedIndex >= activitiesList.count) {
0036 selectedIndex = 0;
0037 }
0038
0039 if (selectedIndex < 0) {
0040 selectedIndex = activitiesList.count - 1;
0041 }
0042
0043 // Searching for the first item that is visible, or back to the one
0044 // that we started with
0045 } while (!activitiesList.itemAt(selectedIndex).visible
0046 && startingWithSelected !== selectedIndex);
0047
0048 _updateSelectedItem();
0049
0050 }
0051
0052 function selectNext()
0053 {
0054 _selectRelativeToCurrent(1);
0055 }
0056
0057 function selectPrevious()
0058 {
0059 _selectRelativeToCurrent(-1);
0060 }
0061
0062 function _updateSelectedItem()
0063 {
0064 for (var i = 0; i < activitiesList.count; i++) {
0065 activitiesList.itemAt(i).selected = (i === selectedIndex);
0066 }
0067 }
0068
0069 function openSelected()
0070 {
0071 var selectedItem = null;
0072
0073 if (selectedIndex >= 0 && selectedIndex < activitiesList.count) {
0074 selectedItem = activitiesList.itemAt(selectedIndex);
0075
0076 } else if (root.filterString != "") {
0077 // If we have only one item shown, activate it. It doesn't matter
0078 // that it is not really selected
0079
0080 for (var i = 0; i < activitiesList.count; i++) {
0081 var item = activitiesList.itemAt(i);
0082
0083 if (item.visible) {
0084 selectedItem = item;
0085 break;
0086 }
0087 }
0088 }
0089
0090 if (selectedItem !== null) {
0091 ActivitySwitcher.Backend.setCurrentActivity(selectedItem.activityId);
0092 }
0093 }
0094
0095 Column {
0096 id: content
0097
0098 // width: root.width - (root.width % 10)
0099 width: root.itemsWidth
0100 spacing: Kirigami.Units.smallSpacing * 2
0101
0102 // Running activities
0103
0104 Repeater {
0105 id: activitiesList
0106
0107 model: ActivitySwitcher.Backend.runningActivitiesModel()
0108
0109 ActivityItem {
0110
0111 width: content.width
0112
0113 visible : (root.filterString == "") ||
0114 (title.toLowerCase().indexOf(root.filterString) != -1)
0115
0116 activityId : model.id
0117 title : model.name
0118 icon : model.iconSource
0119 background : model.background
0120 current : model.isCurrent
0121 hasWindows : model.hasWindows
0122 innerPadding : 2 * Kirigami.Units.smallSpacing
0123 stoppable : activitiesList.count > 1
0124
0125 onClicked : {
0126 ActivitySwitcher.Backend.setCurrentActivity(model.id);
0127 }
0128 }
0129 }
0130
0131 // Stopped activities
0132
0133 Item {
0134 // spacer
0135 width : parent.width
0136 height : Kirigami.Units.gridUnit
0137 }
0138
0139 Kirigami.Heading {
0140 id: stoppedActivitiesHeading
0141
0142 text: i18nd("plasma_shell_org.kde.plasma.desktop", "Stopped activities:")
0143 textFormat: Text.PlainText
0144 level: 3
0145 visible: !root.showSwitcherOnly && stoppedActivitiesList.count > 0
0146 }
0147
0148 Repeater {
0149 id: stoppedActivitiesList
0150
0151 model: root.showSwitcherOnly ? null : ActivitySwitcher.Backend.stoppedActivitiesModel()
0152
0153 delegate: StoppedActivityItem {
0154 id: stoppedActivityItem
0155
0156 width: parent.width
0157
0158 visible : (root.filterString == "") ||
0159 (title.toLowerCase().indexOf(root.filterString) != -1)
0160
0161 activityId : model.id
0162 title : model.name
0163 icon : model.iconSource
0164 innerPadding : 2 * Kirigami.Units.smallSpacing
0165
0166 onClicked: {
0167 ActivitySwitcher.Backend.setCurrentActivity(model.id)
0168 }
0169 }
0170 }
0171
0172 Item {
0173 // spacer
0174 width : parent.width
0175 height : Kirigami.Units.gridUnit * 2
0176
0177 visible: stoppedActivitiesHeading.visible
0178 }
0179
0180 add: Transition {
0181 NumberAnimation {
0182 properties: "x"
0183 from: -100
0184 duration: Kirigami.Units.shortDuration
0185 }
0186 }
0187
0188 move: Transition {
0189 NumberAnimation {
0190 id: animation
0191 properties: "y"
0192 duration: Kirigami.Units.longDuration
0193 }
0194 }
0195 }
0196 }
0197