Add new folder dialog and terminal opening

This commit is contained in:
cutefishd 2021-03-31 10:40:38 +08:00
parent 5618819563
commit bb142016b8
8 changed files with 186 additions and 36 deletions

View file

@ -27,6 +27,7 @@ add_executable(cutefish-filemanager
model/positioner.cpp model/positioner.cpp
dialogs/propertiesdialog.cpp dialogs/propertiesdialog.cpp
dialogs/createfolderdialog.cpp
widgets/rubberband.cpp widgets/rubberband.cpp
widgets/itemviewadapter.cpp widgets/itemviewadapter.cpp

View file

@ -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();
}

View file

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

View file

@ -2,6 +2,7 @@
#include "dirlister.h" #include "dirlister.h"
#include "../dialogs/propertiesdialog.h" #include "../dialogs/propertiesdialog.h"
#include "../dialogs/createfolderdialog.h"
// Qt // Qt
#include <QDir> #include <QDir>
@ -36,6 +37,7 @@
#include <KFileItemListProperties> #include <KFileItemListProperties>
#include <KDesktopFile> #include <KDesktopFile>
#include <KRun> #include <KRun>
#include <KToolInvocation>
FolderModel::FolderModel(QObject *parent) FolderModel::FolderModel(QObject *parent)
: QSortFilterProxyModel(parent) : QSortFilterProxyModel(parent)
@ -596,6 +598,13 @@ void FolderModel::unpinSelection()
m_pinnedSelection = QItemSelection(); m_pinnedSelection = QItemSelection();
} }
void FolderModel::newFolder()
{
CreateFolderDialog *dlg = new CreateFolderDialog;
dlg->setPath(rootItem().url().toString());
dlg->show();
}
void FolderModel::rename(int row, const QString &name) void FolderModel::rename(int row, const QString &name)
{ {
if (row < 0) if (row < 0)
@ -852,7 +861,17 @@ void FolderModel::openPropertiesDialog()
void FolderModel::openInTerminal() void FolderModel::openInTerminal()
{ {
qDebug() << "TODO"; QString url;
if (m_selectionModel->hasSelection()) {
KFileItem item = itemForIndex(m_selectionModel->selectedIndexes().first());
if (item.isDir()) {
url = item.url().toLocalFile();
}
} else {
url = rootItem().url().toLocalFile();
}
KToolInvocation::invokeTerminal(QString(), url);
} }
void FolderModel::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) void FolderModel::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
@ -986,6 +1005,7 @@ void FolderModel::createActions()
connect(paste, &QAction::triggered, this, &FolderModel::paste); connect(paste, &QAction::triggered, this, &FolderModel::paste);
QAction *newFolder = new QAction(tr("New Folder"), this); QAction *newFolder = new QAction(tr("New Folder"), this);
connect(newFolder, &QAction::triggered, this, &FolderModel::newFolder);
QAction *trash = new QAction(tr("Move To Trash"), this); QAction *trash = new QAction(tr("Move To Trash"), this);
connect(trash, &QAction::triggered, this, &FolderModel::moveSelectedToTrash); connect(trash, &QAction::triggered, this, &FolderModel::moveSelectedToTrash);

View file

@ -128,6 +128,7 @@ public:
Q_INVOKABLE void pinSelection(); Q_INVOKABLE void pinSelection();
Q_INVOKABLE void unpinSelection(); Q_INVOKABLE void unpinSelection();
Q_INVOKABLE void newFolder();
Q_INVOKABLE void rename(int row, const QString &name); Q_INVOKABLE void rename(int row, const QString &name);
Q_INVOKABLE void copy(); Q_INVOKABLE void copy();
Q_INVOKABLE void paste(); Q_INVOKABLE void paste();

View file

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

View file

@ -129,10 +129,6 @@ Item {
onCountChanged: { onCountChanged: {
_fileTips.visible = count === 0 _fileTips.visible = count === 0
} }
// Component.onCompleted: {
// folderModel.requestRename.connect(rename)
// }
} }
} }

View file

@ -1,10 +1,33 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS> <!DOCTYPE TS>
<TS version="2.1" language="zh_CN"> <TS version="2.1" language="zh_CN">
<context>
<name>CreateFolderDialog</name>
<message>
<location filename="../qml/Dialogs/CreateFolderDialog.qml" line="10"/>
<source>New Folder</source>
<translation></translation>
</message>
<message>
<location filename="../qml/Dialogs/CreateFolderDialog.qml" line="36"/>
<source>Name</source>
<translation></translation>
</message>
<message>
<location filename="../qml/Dialogs/CreateFolderDialog.qml" line="48"/>
<source>Cancel</source>
<translation></translation>
</message>
<message>
<location filename="../qml/Dialogs/CreateFolderDialog.qml" line="54"/>
<source>OK</source>
<translation></translation>
</message>
</context>
<context> <context>
<name>DesktopView</name> <name>DesktopView</name>
<message> <message>
<location filename="../desktop/desktopview.cpp" line="37"/> <location filename="../desktop/desktopview.cpp" line="38"/>
<source>Desktop</source> <source>Desktop</source>
<translation></translation> <translation></translation>
</message> </message>
@ -12,82 +35,82 @@
<context> <context>
<name>FolderModel</name> <name>FolderModel</name>
<message> <message>
<location filename="../model/foldermodel.cpp" line="407"/> <location filename="../model/foldermodel.cpp" line="415"/>
<source>%1 selected</source> <source>%1 selected</source>
<translation> %1 </translation> <translation> %1 </translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="411"/> <location filename="../model/foldermodel.cpp" line="419"/>
<source>%1 item</source> <source>%1 item</source>
<translation>%1 </translation> <translation>%1 </translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="415"/> <location filename="../model/foldermodel.cpp" line="423"/>
<source>%1 items</source> <source>%1 items</source>
<translation>%1 </translation> <translation>%1 </translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="746"/> <location filename="../model/foldermodel.cpp" line="791"/>
<source>Select All</source> <source>Select All</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="924"/> <location filename="../model/foldermodel.cpp" line="984"/>
<source>Open</source> <source>Open</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="927"/> <location filename="../model/foldermodel.cpp" line="987"/>
<source>Cut</source> <source>Cut</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="930"/> <location filename="../model/foldermodel.cpp" line="990"/>
<source>Copy</source> <source>Copy</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="933"/> <location filename="../model/foldermodel.cpp" line="993"/>
<source>Paste</source> <source>Paste</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="936"/> <location filename="../model/foldermodel.cpp" line="996"/>
<source>New Folder</source> <source>New Folder</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="938"/> <location filename="../model/foldermodel.cpp" line="999"/>
<source>Move To Trash</source> <source>Move To Trash</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="941"/> <location filename="../model/foldermodel.cpp" line="1002"/>
<source>Empty Trash</source> <source>Empty Trash</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="944"/> <location filename="../model/foldermodel.cpp" line="1005"/>
<source>Delete</source> <source>Delete</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="947"/> <location filename="../model/foldermodel.cpp" line="1008"/>
<source>Rename</source> <source>Rename</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="950"/> <location filename="../model/foldermodel.cpp" line="1011"/>
<source>Open in Terminal</source> <source>Open in Terminal</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="953"/> <location filename="../model/foldermodel.cpp" line="1014"/>
<source>Set as Wallpaper</source> <source>Set as Wallpaper</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="956"/> <location filename="../model/foldermodel.cpp" line="1017"/>
<source>Properties</source> <source>Properties</source>
<translation></translation> <translation></translation>
</message> </message>
@ -95,12 +118,12 @@
<context> <context>
<name>FolderPage</name> <name>FolderPage</name>
<message> <message>
<location filename="../qml/FolderPage.qml" line="32"/> <location filename="../qml/FolderPage.qml" line="34"/>
<source>No files</source> <source>No files</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../qml/FolderPage.qml" line="97"/> <location filename="../qml/FolderPage.qml" line="108"/>
<source>Empty Trash</source> <source>Empty Trash</source>
<translation></translation> <translation></translation>
</message> </message>
@ -108,42 +131,42 @@
<context> <context>
<name>PlacesModel</name> <name>PlacesModel</name>
<message> <message>
<location filename="../model/placesmodel.cpp" line="38"/> <location filename="../model/placesmodel.cpp" line="39"/>
<source>Home</source> <source>Home</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/placesmodel.cpp" line="45"/> <location filename="../model/placesmodel.cpp" line="46"/>
<source>Desktop</source> <source>Desktop</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/placesmodel.cpp" line="52"/> <location filename="../model/placesmodel.cpp" line="53"/>
<source>Documents</source> <source>Documents</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/placesmodel.cpp" line="59"/> <location filename="../model/placesmodel.cpp" line="60"/>
<source>Downloads</source> <source>Downloads</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/placesmodel.cpp" line="66"/> <location filename="../model/placesmodel.cpp" line="67"/>
<source>Music</source> <source>Music</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/placesmodel.cpp" line="73"/> <location filename="../model/placesmodel.cpp" line="74"/>
<source>Pictures</source> <source>Pictures</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/placesmodel.cpp" line="80"/> <location filename="../model/placesmodel.cpp" line="81"/>
<source>Videos</source> <source>Videos</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/placesmodel.cpp" line="85"/> <location filename="../model/placesmodel.cpp" line="86"/>
<source>Trash</source> <source>Trash</source>
<translation></translation> <translation></translation>
</message> </message>