From 140bbfd29c19b8a17750387e0b2e45470bcbfcbf Mon Sep 17 00:00:00 2001 From: cutefishd Date: Wed, 31 Mar 2021 12:45:51 +0800 Subject: [PATCH] Handle url --- main.cpp | 11 +++++++++++ qml/Desktop/main.qml | 36 +++++++++++++++++++++++++++++++----- qml/FolderPage.qml | 5 ++++- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index 3b6b587..6ef8847 100644 --- a/main.cpp +++ b/main.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -66,9 +67,12 @@ int main(int argc, char *argv[]) parser.setApplicationDescription(QStringLiteral("File Manager")); parser.addHelpOption(); + parser.addPositionalArgument("files", "Files", "[FILE1, FILE2,...]"); + QCommandLineOption desktopOption(QStringList() << "d" << "desktop" << "Desktop Mode"); parser.addOption(desktopOption); parser.process(app); + parser.addHelpOption(); if (parser.isSet(desktopOption)) { DesktopView view; @@ -84,6 +88,13 @@ int main(int argc, char *argv[]) if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); + + // Handle urls + if (!parser.positionalArguments().isEmpty()) { + QStringList arguments = parser.positionalArguments(); + engine.rootContext()->setContextProperty("arg", arguments.first()); + } + engine.load(url); engine.addImageProvider("thumbnailer", new Thumbnailer()); diff --git a/qml/Desktop/main.qml b/qml/Desktop/main.qml index e08aff8..783c5e1 100644 --- a/qml/Desktop/main.qml +++ b/qml/Desktop/main.qml @@ -60,17 +60,20 @@ Item { } } + FolderModel { + id: folderModel + url: desktopPath() + isDesktop: true + } + FolderGridView { + id: _folderView anchors.fill: parent isDesktopView: true iconSize: globalSettings.desktopIconSize - model: FolderModel { - id: folderModel - url: desktopPath() - isDesktop: true - } + model: folderModel leftMargin: desktopView.screenAvailableRect ? desktopView.screenAvailableRect.x : 0 topMargin: desktopView.screenAvailableRect ? desktopView.screenAvailableRect.y : 0 @@ -82,6 +85,29 @@ Item { delegate: FolderGridItem {} } + Connections { + target: _folderView + + function onKeyPress(event) { + if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) + folderModel.openSelected() + else if (event.key === Qt.Key_C && event.modifiers & Qt.ControlModifier) + folderModel.copy() + else if (event.key === Qt.Key_X && event.modifiers & Qt.ControlModifier) + folderModel.cut() + else if (event.key === Qt.Key_V && event.modifiers & Qt.ControlModifier) + folderModel.paste() + else if (event.key === Qt.Key_F2) + folderModel.requestRename() + else if (event.key === Qt.Key_L && event.modifiers & Qt.ControlModifier) + folderPage.requestPathEditor() + else if (event.key === Qt.Key_A && event.modifiers & Qt.ControlModifier) + folderModel.selectAll() + else if (event.key === Qt.Key_Backspace) + folderModel.up() + } + } + Component { id: rubberBandObject diff --git a/qml/FolderPage.qml b/qml/FolderPage.qml index 48482bd..dca7f8f 100644 --- a/qml/FolderPage.qml +++ b/qml/FolderPage.qml @@ -41,7 +41,10 @@ Item { viewAdapter: viewAdapter Component.onCompleted: { - folderModel.url = folderModel.homePath() + if (arg) + folderModel.url = arg + else + folderModel.url = folderModel.homePath() } }