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
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
|
|
||||||
Item {
|
MouseArea {
|
||||||
id: root
|
id: root
|
||||||
property int columns: 4
|
property int columns: 4
|
||||||
property real previewCellAspectRatio: 4 / 3
|
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 => {
|
Keys.onPressed: event => {
|
||||||
if (event.key === Qt.Key_Escape) {
|
if (event.key === Qt.Key_Escape) {
|
||||||
GlobalStates.wallpaperSelectorOpen = false;
|
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
|
} 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);
|
root.handleFilePasting(event);
|
||||||
} else if (event.modifiers & Qt.AltModifier && event.key === Qt.Key_Up) {
|
} 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;
|
event.accepted = true;
|
||||||
} else if (event.key === Qt.Key_Left) {
|
} else if (event.key === Qt.Key_Left) {
|
||||||
grid.moveSelection(-1);
|
grid.moveSelection(-1);
|
||||||
@@ -160,7 +175,7 @@ Item {
|
|||||||
}
|
}
|
||||||
onClicked: Wallpapers.setDirectory(quickDirButton.modelData.path)
|
onClicked: Wallpapers.setDirectory(quickDirButton.modelData.path)
|
||||||
enabled: modelData.icon.length > 0
|
enabled: modelData.icon.length > 0
|
||||||
toggled: Wallpapers.directory === FileUtils.trimFileProtocol(modelData.path)
|
toggled: Wallpapers.directory === Qt.resolvedUrl(modelData.path)
|
||||||
colBackgroundToggled: Appearance.colors.colSecondaryContainer
|
colBackgroundToggled: Appearance.colors.colSecondaryContainer
|
||||||
colBackgroundToggledHover: Appearance.colors.colSecondaryContainerHover
|
colBackgroundToggledHover: Appearance.colors.colSecondaryContainerHover
|
||||||
colRippleToggled: Appearance.colors.colSecondaryContainerActive
|
colRippleToggled: Appearance.colors.colSecondaryContainerActive
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import qs.modules.common
|
import qs.modules.common
|
||||||
|
import qs.modules.common.models
|
||||||
import qs.modules.common.functions
|
import qs.modules.common.functions
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import Qt.labs.folderlistmodel
|
import Qt.labs.folderlistmodel
|
||||||
@@ -16,8 +17,9 @@ Singleton {
|
|||||||
|
|
||||||
property string thumbgenScriptPath: `${FileUtils.trimFileProtocol(Directories.scriptPath)}/thumbnails/thumbgen.py`
|
property string thumbgenScriptPath: `${FileUtils.trimFileProtocol(Directories.scriptPath)}/thumbnails/thumbgen.py`
|
||||||
property string generateThumbnailsMagicScriptPath: `${FileUtils.trimFileProtocol(Directories.scriptPath)}/thumbnails/generate-thumbnails-magick.sh`
|
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())
|
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 alias folderModel: folderModel // Expose for direct binding when needed
|
||||||
property string searchQuery: ""
|
property string searchQuery: ""
|
||||||
readonly property list<string> extensions: [ // TODO: add videos
|
readonly property list<string> extensions: [ // TODO: add videos
|
||||||
@@ -88,11 +90,11 @@ Singleton {
|
|||||||
}
|
}
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
|
root.directory = Qt.resolvedUrl(validateDirProc.nicePath)
|
||||||
const result = text.trim()
|
const result = text.trim()
|
||||||
if (result === "dir") {
|
if (result === "dir") {
|
||||||
root.directory = validateDirProc.nicePath
|
|
||||||
} else if (result === "file") {
|
} else if (result === "file") {
|
||||||
root.directory = FileUtils.parentDirectory(validateDirProc.nicePath)
|
root.directory = Qt.resolvedUrl(FileUtils.parentDirectory(validateDirProc.nicePath))
|
||||||
} else {
|
} else {
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
@@ -102,11 +104,20 @@ Singleton {
|
|||||||
function setDirectory(path) {
|
function setDirectory(path) {
|
||||||
validateDirProc.setDirectoryIfValid(path)
|
validateDirProc.setDirectoryIfValid(path)
|
||||||
}
|
}
|
||||||
|
function navigateUp() {
|
||||||
|
folderModel.navigateUp()
|
||||||
|
}
|
||||||
|
function navigateBack() {
|
||||||
|
folderModel.navigateBack()
|
||||||
|
}
|
||||||
|
function navigateForward() {
|
||||||
|
folderModel.navigateForward()
|
||||||
|
}
|
||||||
|
|
||||||
// Folder model
|
// Folder model
|
||||||
FolderListModel {
|
FolderListModelWithHistory {
|
||||||
id: folderModel
|
id: folderModel
|
||||||
folder: Qt.resolvedUrl(root.directory)
|
folder: Qt.resolvedUrl(root.defaultFolder)
|
||||||
caseSensitive: false
|
caseSensitive: false
|
||||||
nameFilters: root.extensions.map(ext => `*${searchQuery.split(" ").filter(s => s.length > 0).map(s => `*${s}*`)}*.${ext}`)
|
nameFilters: root.extensions.map(ext => `*${searchQuery.split(" ").filter(s => s.length > 0).map(s => `*${s}*`)}*.${ext}`)
|
||||||
showDirs: true
|
showDirs: true
|
||||||
|
|||||||
Reference in New Issue
Block a user