wallpaper selector: back/forward navigation

This commit is contained in:
end-4 2025-09-12 08:09:12 +02:00
parent fcdc17dd93
commit 9c8d71ca4d
3 changed files with 87 additions and 8 deletions

View file

@ -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
}
}

View file

@ -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

View file

@ -1,4 +1,5 @@
import qs.modules.common
import qs.modules.common.models
import qs.modules.common.functions
import QtQuick
import Qt.labs.folderlistmodel
@ -16,8 +17,9 @@ Singleton {
property string thumbgenScriptPath: `${FileUtils.trimFileProtocol(Directories.scriptPath)}/thumbnails/thumbgen.py`
property string generateThumbnailsMagicScriptPath: `${FileUtils.trimFileProtocol(Directories.scriptPath)}/thumbnails/generate-thumbnails-magick.sh`
property string directory: FileUtils.trimFileProtocol(`${Directories.pictures}/Wallpapers`)
property alias directory: folderModel.folder
readonly property string effectiveDirectory: FileUtils.trimFileProtocol(folderModel.folder.toString())
property url defaultFolder: Qt.resolvedUrl(`${Directories.pictures}/Wallpapers`)
property alias folderModel: folderModel // Expose for direct binding when needed
property string searchQuery: ""
readonly property list<string> extensions: [ // TODO: add videos
@ -88,11 +90,11 @@ Singleton {
}
stdout: StdioCollector {
onStreamFinished: {
root.directory = Qt.resolvedUrl(validateDirProc.nicePath)
const result = text.trim()
if (result === "dir") {
root.directory = validateDirProc.nicePath
} else if (result === "file") {
root.directory = FileUtils.parentDirectory(validateDirProc.nicePath)
root.directory = Qt.resolvedUrl(FileUtils.parentDirectory(validateDirProc.nicePath))
} else {
// Ignore
}
@ -102,11 +104,20 @@ Singleton {
function setDirectory(path) {
validateDirProc.setDirectoryIfValid(path)
}
function navigateUp() {
folderModel.navigateUp()
}
function navigateBack() {
folderModel.navigateBack()
}
function navigateForward() {
folderModel.navigateForward()
}
// Folder model
FolderListModel {
FolderListModelWithHistory {
id: folderModel
folder: Qt.resolvedUrl(root.directory)
folder: Qt.resolvedUrl(root.defaultFolder)
caseSensitive: false
nameFilters: root.extensions.map(ext => `*${searchQuery.split(" ").filter(s => s.length > 0).map(s => `*${s}*`)}*.${ext}`)
showDirs: true