/* vim:set foldmethod=marker:SPDX-FileCopyrightText: 2014 Ivan Cukic <ivan.cukic(at)kde.org>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuickimport org.kde.kirigami as Kirigamiimport org.kde.plasma.activityswitcher as ActivitySwitcherFlickable {id: root// contentWidth: content.widthcontentHeight: content.heightproperty var model: ActivitySwitcher.Backend.runningActivitiesModel()property string filterString: ""property bool showSwitcherOnly: falseproperty int itemsWidth: 0property int selectedIndex: -1function _selectRelativeToCurrent(distance){var startingWithSelected = selectedIndex;var visited = 0;do {selectedIndex += distance;visited++;if (selectedIndex >= activitiesList.count) {selectedIndex = 0;}if (selectedIndex < 0) {selectedIndex = activitiesList.count - 1;}if (visited >= activitiesList.count) {// we've visited all activities but could not find a visible// one, so stop searching and select the one we started withselectedIndex = startingWithSelected;break;}// Searching for the first item that is visible} while (!activitiesList.itemAt(selectedIndex).visible);_updateSelectedItem();}function selectNext(){_selectRelativeToCurrent(1);}function selectPrevious(){_selectRelativeToCurrent(-1);}function _updateSelectedItem(){for (var i = 0; i < activitiesList.count; i++) {activitiesList.itemAt(i).selected = (i === selectedIndex);}}function openSelected(){var selectedItem = null;if (selectedIndex >= 0 && selectedIndex < activitiesList.count) {selectedItem = activitiesList.itemAt(selectedIndex) as ActivityItem;} else if (root.filterString != "") {// If we have only one item shown, activate it. It doesn't matter// that it is not really selectedfor (var i = 0; i < activitiesList.count; i++) {var item = activitiesList.itemAt(i) as ActivityItem;if (item.visible) {selectedItem = item;break;}}}if (selectedItem !== null) {ActivitySwitcher.Backend.setCurrentActivity(selectedItem.activityId);}}Column {id: content// width: root.width - (root.width % 10)width: root.itemsWidthspacing: Kirigami.Units.smallSpacing * 2Repeater {id: activitiesListmodel: ActivitySwitcher.Backend.runningActivitiesModel()ActivityItem {width: content.widthvisible : (root.filterString == "") ||(title.toLowerCase().indexOf(root.filterString) != -1)activityId : model.idtitle : model.nameicon : model.iconSourcebackground : model.backgroundcurrent : model.isCurrenthasWindows : model.hasWindowsinnerPadding : 2 * Kirigami.Units.smallSpacingonClicked : {ActivitySwitcher.Backend.setCurrentActivity(model.id);}}}add: Transition {NumberAnimation {properties: "x"from: -100duration: Kirigami.Units.shortDuration}}move: Transition {NumberAnimation {id: animationproperties: "y"duration: Kirigami.Units.longDuration}}}}