Add new folder dialog and terminal opening
parent
5618819563
commit
bb142016b8
@ -0,0 +1,33 @@
|
|||||||
|
#include "createfolderdialog.h"
|
||||||
|
#include <QQmlApplicationEngine>
|
||||||
|
#include <QQuickView>
|
||||||
|
#include <QQmlContext>
|
||||||
|
|
||||||
|
#include <KIO/MkdirJob>
|
||||||
|
|
||||||
|
CreateFolderDialog::CreateFolderDialog(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateFolderDialog::setPath(const QString &path)
|
||||||
|
{
|
||||||
|
m_path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateFolderDialog::show()
|
||||||
|
{
|
||||||
|
QQmlApplicationEngine *engine = new QQmlApplicationEngine;
|
||||||
|
engine->rootContext()->setContextProperty("main", this);
|
||||||
|
engine->load(QUrl("qrc:/qml/Dialogs/CreateFolderDialog.qml"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateFolderDialog::newFolder(const QString &folderName)
|
||||||
|
{
|
||||||
|
if (m_path.isEmpty() || folderName.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto job = KIO::mkdir(QUrl(m_path + "/" + folderName));
|
||||||
|
job->start();
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef CREATEFOLDERDIALOG_H
|
||||||
|
#define CREATEFOLDERDIALOG_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class CreateFolderDialog : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit CreateFolderDialog(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
void setPath(const QString &path);
|
||||||
|
void show();
|
||||||
|
|
||||||
|
Q_INVOKABLE void newFolder(const QString &folderName);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_path;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CREATEFOLDERDIALOG_H
|
||||||
@ -1,12 +1,66 @@
|
|||||||
import QtQuick 2.12
|
import QtQuick 2.12
|
||||||
import QtQuick.Controls 2.12
|
import QtQuick.Controls 2.12
|
||||||
|
import QtQuick.Window 2.12
|
||||||
import QtQuick.Layouts 1.12
|
import QtQuick.Layouts 1.12
|
||||||
import MeuiKit 1.0 as Meui
|
import MeuiKit 1.0 as Meui
|
||||||
|
|
||||||
Dialog {
|
Window {
|
||||||
id: control
|
id: control
|
||||||
modal: true
|
|
||||||
|
|
||||||
x: (parent.width - control.width) / 2
|
title: qsTr("New Folder")
|
||||||
y: (parent.height - control.height) / 2
|
flags: Qt.Dialog
|
||||||
|
visible: true
|
||||||
|
|
||||||
|
width: 400 + Meui.Units.largeSpacing * 2
|
||||||
|
height: _mainLayout.implicitHeight + Meui.Units.largeSpacing * 4
|
||||||
|
|
||||||
|
minimumWidth: width
|
||||||
|
minimumHeight: height
|
||||||
|
maximumWidth: width
|
||||||
|
maximumHeight: height
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
anchors.fill: parent
|
||||||
|
color: Meui.Theme.backgroundColor
|
||||||
|
}
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
id: _mainLayout
|
||||||
|
anchors.fill: parent
|
||||||
|
anchors.leftMargin: Meui.Units.largeSpacing
|
||||||
|
anchors.rightMargin: Meui.Units.largeSpacing
|
||||||
|
spacing: 0
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
Label {
|
||||||
|
text: qsTr("Name")
|
||||||
|
}
|
||||||
|
|
||||||
|
TextField {
|
||||||
|
id: _textField
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Keys.onEscapePressed: control.close()
|
||||||
|
focus: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
Button {
|
||||||
|
text: qsTr("Cancel")
|
||||||
|
Layout.fillWidth: true
|
||||||
|
onClicked: control.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
text: qsTr("OK")
|
||||||
|
Layout.fillWidth: true
|
||||||
|
onClicked: {
|
||||||
|
main.newFolder(_textField.text)
|
||||||
|
control.close()
|
||||||
|
}
|
||||||
|
enabled: _textField.text
|
||||||
|
flat: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue