Handle url

This commit is contained in:
cutefishd 2021-03-31 12:45:51 +08:00
parent bb142016b8
commit 140bbfd29c
3 changed files with 46 additions and 6 deletions

View file

@ -20,6 +20,7 @@
#include <QApplication> #include <QApplication>
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QTranslator> #include <QTranslator>
#include <QLocale> #include <QLocale>
@ -66,9 +67,12 @@ int main(int argc, char *argv[])
parser.setApplicationDescription(QStringLiteral("File Manager")); parser.setApplicationDescription(QStringLiteral("File Manager"));
parser.addHelpOption(); parser.addHelpOption();
parser.addPositionalArgument("files", "Files", "[FILE1, FILE2,...]");
QCommandLineOption desktopOption(QStringList() << "d" << "desktop" << "Desktop Mode"); QCommandLineOption desktopOption(QStringList() << "d" << "desktop" << "Desktop Mode");
parser.addOption(desktopOption); parser.addOption(desktopOption);
parser.process(app); parser.process(app);
parser.addHelpOption();
if (parser.isSet(desktopOption)) { if (parser.isSet(desktopOption)) {
DesktopView view; DesktopView view;
@ -84,6 +88,13 @@ int main(int argc, char *argv[])
if (!obj && url == objUrl) if (!obj && url == objUrl)
QCoreApplication::exit(-1); QCoreApplication::exit(-1);
}, Qt::QueuedConnection); }, Qt::QueuedConnection);
// Handle urls
if (!parser.positionalArguments().isEmpty()) {
QStringList arguments = parser.positionalArguments();
engine.rootContext()->setContextProperty("arg", arguments.first());
}
engine.load(url); engine.load(url);
engine.addImageProvider("thumbnailer", new Thumbnailer()); engine.addImageProvider("thumbnailer", new Thumbnailer());

View file

@ -60,17 +60,20 @@ Item {
} }
} }
FolderModel {
id: folderModel
url: desktopPath()
isDesktop: true
}
FolderGridView { FolderGridView {
id: _folderView
anchors.fill: parent anchors.fill: parent
isDesktopView: true isDesktopView: true
iconSize: globalSettings.desktopIconSize iconSize: globalSettings.desktopIconSize
model: FolderModel { model: folderModel
id: folderModel
url: desktopPath()
isDesktop: true
}
leftMargin: desktopView.screenAvailableRect ? desktopView.screenAvailableRect.x : 0 leftMargin: desktopView.screenAvailableRect ? desktopView.screenAvailableRect.x : 0
topMargin: desktopView.screenAvailableRect ? desktopView.screenAvailableRect.y : 0 topMargin: desktopView.screenAvailableRect ? desktopView.screenAvailableRect.y : 0
@ -82,6 +85,29 @@ Item {
delegate: FolderGridItem {} 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 { Component {
id: rubberBandObject id: rubberBandObject

View file

@ -41,6 +41,9 @@ Item {
viewAdapter: viewAdapter viewAdapter: viewAdapter
Component.onCompleted: { Component.onCompleted: {
if (arg)
folderModel.url = arg
else
folderModel.url = folderModel.homePath() folderModel.url = folderModel.homePath()
} }
} }