forked from quickshell/quickshell
feat: add support for getting and setting workdir
This commit is contained in:
parent
b5f50cd68f
commit
bbe64f42f3
8 changed files with 109 additions and 2 deletions
|
@ -2,7 +2,9 @@
|
|||
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qcoreapplication.h>
|
||||
#include <qdir.h>
|
||||
#include <qguiapplication.h>
|
||||
#include <qjsengine.h>
|
||||
#include <qlogging.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmlcontext.h>
|
||||
|
@ -83,3 +85,29 @@ QVariant QuickshellGlobal::env(const QString& variable) { // NOLINT
|
|||
|
||||
return qEnvironmentVariable(vstr.data());
|
||||
}
|
||||
|
||||
QString QuickshellGlobal::workingDirectory() const { // NOLINT
|
||||
return QDir::current().absolutePath();
|
||||
}
|
||||
|
||||
void QuickshellGlobal::setWorkingDirectory(const QString& workingDirectory) { // NOLINT
|
||||
QDir::setCurrent(workingDirectory);
|
||||
emit this->workingDirectoryChanged();
|
||||
}
|
||||
|
||||
static QuickshellGlobal* g_instance = nullptr; // NOLINT
|
||||
|
||||
QuickshellGlobal* QuickshellGlobal::create(QQmlEngine* /*unused*/, QJSEngine* /*unused*/) {
|
||||
return QuickshellGlobal::instance();
|
||||
}
|
||||
|
||||
QuickshellGlobal* QuickshellGlobal::instance() {
|
||||
if (g_instance == nullptr) g_instance = new QuickshellGlobal();
|
||||
QJSEngine::setObjectOwnership(g_instance, QJSEngine::CppOwnership);
|
||||
return g_instance;
|
||||
}
|
||||
|
||||
void QuickshellGlobal::deleteInstance() {
|
||||
delete g_instance;
|
||||
g_instance = nullptr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue