forked from Shinonome/dots-hyprland
wallpaper selector: back/forward navigation
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import QtQuick
|
||||
import Qt.labs.folderlistmodel
|
||||
|
||||
FolderListModel {
|
||||
id: root
|
||||
property list<url> folderHistory: []
|
||||
property int currentFolderHistoryIndex: -1
|
||||
property bool historyNavigationLock: false
|
||||
|
||||
function lockNextNavigation() {
|
||||
historyNavigationLock = true;
|
||||
}
|
||||
|
||||
function pushToHistory(path) {
|
||||
if (folderHistory[currentFolderHistoryIndex] === path)
|
||||
return;
|
||||
folderHistory = folderHistory.slice(0, currentFolderHistoryIndex + 1);
|
||||
folderHistory.push(path);
|
||||
currentFolderHistoryIndex = folderHistory.length - 1;
|
||||
}
|
||||
|
||||
function navigateUp() {
|
||||
root.folder = root.parentFolder;
|
||||
}
|
||||
|
||||
function navigateBack() {
|
||||
if (currentFolderHistoryIndex === 0)
|
||||
return;
|
||||
currentFolderHistoryIndex--;
|
||||
lockNextNavigation();
|
||||
root.folder = folderHistory[currentFolderHistoryIndex];
|
||||
}
|
||||
|
||||
function navigateForward() {
|
||||
if (currentFolderHistoryIndex >= folderHistory.length - 1) return;
|
||||
currentFolderHistoryIndex++;
|
||||
lockNextNavigation();
|
||||
root.folder = folderHistory[currentFolderHistoryIndex];
|
||||
}
|
||||
|
||||
onFolderChanged: {
|
||||
if (historyNavigationLock) {
|
||||
historyNavigationLock = false;
|
||||
return;
|
||||
}
|
||||
pushToHistory(folder);
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
root.folderHistory = [root.folder]
|
||||
root.currentFolderHistoryIndex = 0
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import Qt5Compat.GraphicalEffects
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
Item {
|
||||
MouseArea {
|
||||
id: root
|
||||
property int columns: 4
|
||||
property real previewCellAspectRatio: 4 / 3
|
||||
@@ -40,6 +40,15 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
acceptedButtons: Qt.BackButton | Qt.ForwardButton
|
||||
onPressed: event => {
|
||||
if (event.button === Qt.BackButton) {
|
||||
Wallpapers.navigateBack();
|
||||
} else if (event.button === Qt.ForwardButton) {
|
||||
Wallpapers.navigateForward();
|
||||
}
|
||||
}
|
||||
|
||||
Keys.onPressed: event => {
|
||||
if (event.key === Qt.Key_Escape) {
|
||||
GlobalStates.wallpaperSelectorOpen = false;
|
||||
@@ -47,7 +56,13 @@ Item {
|
||||
} else if ((event.modifiers & Qt.ControlModifier) && event.key === Qt.Key_V) { // Intercept Ctrl+V to handle "paste to go to" in pickers
|
||||
root.handleFilePasting(event);
|
||||
} else if (event.modifiers & Qt.AltModifier && event.key === Qt.Key_Up) {
|
||||
Wallpapers.setDirectory(FileUtils.parentDirectory(Wallpapers.directory));
|
||||
Wallpapers.navigateUp();
|
||||
event.accepted = true;
|
||||
} else if (event.modifiers & Qt.AltModifier && event.key === Qt.Key_Left) {
|
||||
Wallpapers.navigateBack();
|
||||
event.accepted = true;
|
||||
} else if (event.modifiers & Qt.AltModifier && event.key === Qt.Key_Right) {
|
||||
Wallpapers.navigateForward();
|
||||
event.accepted = true;
|
||||
} else if (event.key === Qt.Key_Left) {
|
||||
grid.moveSelection(-1);
|
||||
@@ -160,7 +175,7 @@ Item {
|
||||
}
|
||||
onClicked: Wallpapers.setDirectory(quickDirButton.modelData.path)
|
||||
enabled: modelData.icon.length > 0
|
||||
toggled: Wallpapers.directory === FileUtils.trimFileProtocol(modelData.path)
|
||||
toggled: Wallpapers.directory === Qt.resolvedUrl(modelData.path)
|
||||
colBackgroundToggled: Appearance.colors.colSecondaryContainer
|
||||
colBackgroundToggledHover: Appearance.colors.colSecondaryContainerHover
|
||||
colRippleToggled: Appearance.colors.colSecondaryContainerActive
|
||||
|
||||
Reference in New Issue
Block a user