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 <QCommandLineParser>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QTranslator>
#include <QLocale>
@ -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());

View file

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

View file

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