diff options
-rw-r--r-- | main.cc | 30 | ||||
-rw-r--r-- | src/command/commands.js | 10 |
2 files changed, 38 insertions, 2 deletions
@@ -1,12 +1,36 @@ +#include <QDir> +#include <QQmlContext> #include <QApplication> #include <QQmlApplicationEngine> +class WorkingDirectory : public QObject { + Q_OBJECT + + public: + Q_INVOKABLE bool cd(const QString& path) const { + QDir current(QDir::current()); + + const bool result = current.cd(path); + + QDir::setCurrent(current.absolutePath()); + + return result; + } + + Q_INVOKABLE QString current() const { + return QDir::current().absolutePath(); + } +}; + int main(int argc, char *argv[]) { - QApplication application(argc, argv); + WorkingDirectory directory; + QApplication application(argc, argv); + QQmlApplicationEngine engine(QUrl(QStringLiteral("qrc:/main.qml"))); + application.setOrganizationName("akr"); application.setApplicationName("MetaTerm"); - QQmlApplicationEngine engine(QUrl(QStringLiteral("qrc:/main.qml"))); + engine.rootContext()->setContextProperty("workingDirectory", &directory); QObject::connect( static_cast<QObject*>(&engine), @@ -17,3 +41,5 @@ int main(int argc, char *argv[]) { return application.exec(); } + +#include "main.moc" diff --git a/src/command/commands.js b/src/command/commands.js index 732eb5b..2ec1bb6 100644 --- a/src/command/commands.js +++ b/src/command/commands.js @@ -114,3 +114,13 @@ function prev() { function q() { Qt.quit(); } + +function cd(output, path) { + if ( path.length > 0 ) { + if ( !workingDirectory.cd(path) ) { + output.error('\"' + path + '\" doesn\'t exist.'); + } + } else { + output.log(workingDirectory.current()); + } +} |