Add new folder dialog and terminal opening
This commit is contained in:
parent
5618819563
commit
bb142016b8
8 changed files with 186 additions and 36 deletions
|
@ -27,6 +27,7 @@ add_executable(cutefish-filemanager
|
|||
model/positioner.cpp
|
||||
|
||||
dialogs/propertiesdialog.cpp
|
||||
dialogs/createfolderdialog.cpp
|
||||
widgets/rubberband.cpp
|
||||
widgets/itemviewadapter.cpp
|
||||
|
||||
|
|
33
dialogs/createfolderdialog.cpp
Normal file
33
dialogs/createfolderdialog.cpp
Normal 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();
|
||||
}
|
22
dialogs/createfolderdialog.h
Normal file
22
dialogs/createfolderdialog.h
Normal 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
|
|
@ -2,6 +2,7 @@
|
|||
#include "dirlister.h"
|
||||
|
||||
#include "../dialogs/propertiesdialog.h"
|
||||
#include "../dialogs/createfolderdialog.h"
|
||||
|
||||
// Qt
|
||||
#include <QDir>
|
||||
|
@ -36,6 +37,7 @@
|
|||
#include <KFileItemListProperties>
|
||||
#include <KDesktopFile>
|
||||
#include <KRun>
|
||||
#include <KToolInvocation>
|
||||
|
||||
FolderModel::FolderModel(QObject *parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
|
@ -596,6 +598,13 @@ void FolderModel::unpinSelection()
|
|||
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)
|
||||
{
|
||||
if (row < 0)
|
||||
|
@ -852,7 +861,17 @@ void FolderModel::openPropertiesDialog()
|
|||
|
||||
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)
|
||||
|
@ -986,6 +1005,7 @@ void FolderModel::createActions()
|
|||
connect(paste, &QAction::triggered, this, &FolderModel::paste);
|
||||
|
||||
QAction *newFolder = new QAction(tr("New Folder"), this);
|
||||
connect(newFolder, &QAction::triggered, this, &FolderModel::newFolder);
|
||||
|
||||
QAction *trash = new QAction(tr("Move To Trash"), this);
|
||||
connect(trash, &QAction::triggered, this, &FolderModel::moveSelectedToTrash);
|
||||
|
|
|
@ -128,6 +128,7 @@ public:
|
|||
Q_INVOKABLE void pinSelection();
|
||||
Q_INVOKABLE void unpinSelection();
|
||||
|
||||
Q_INVOKABLE void newFolder();
|
||||
Q_INVOKABLE void rename(int row, const QString &name);
|
||||
Q_INVOKABLE void copy();
|
||||
Q_INVOKABLE void paste();
|
||||
|
|
|
@ -1,12 +1,66 @@
|
|||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Window 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import MeuiKit 1.0 as Meui
|
||||
|
||||
Dialog {
|
||||
Window {
|
||||
id: control
|
||||
modal: true
|
||||
|
||||
x: (parent.width - control.width) / 2
|
||||
y: (parent.height - control.height) / 2
|
||||
title: qsTr("New Folder")
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,10 +129,6 @@ Item {
|
|||
onCountChanged: {
|
||||
_fileTips.visible = count === 0
|
||||
}
|
||||
|
||||
// Component.onCompleted: {
|
||||
// folderModel.requestRename.connect(rename)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<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>
|
||||
<name>DesktopView</name>
|
||||
<message>
|
||||
<location filename="../desktop/desktopview.cpp" line="37"/>
|
||||
<location filename="../desktop/desktopview.cpp" line="38"/>
|
||||
<source>Desktop</source>
|
||||
<translation>桌面</translation>
|
||||
</message>
|
||||
|
@ -12,82 +35,82 @@
|
|||
<context>
|
||||
<name>FolderModel</name>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="407"/>
|
||||
<location filename="../model/foldermodel.cpp" line="415"/>
|
||||
<source>%1 selected</source>
|
||||
<translation>选中了 %1 项</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="411"/>
|
||||
<location filename="../model/foldermodel.cpp" line="419"/>
|
||||
<source>%1 item</source>
|
||||
<translation>%1 项</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="415"/>
|
||||
<location filename="../model/foldermodel.cpp" line="423"/>
|
||||
<source>%1 items</source>
|
||||
<translation>%1 项</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="746"/>
|
||||
<location filename="../model/foldermodel.cpp" line="791"/>
|
||||
<source>Select All</source>
|
||||
<translation>全选</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="924"/>
|
||||
<location filename="../model/foldermodel.cpp" line="984"/>
|
||||
<source>Open</source>
|
||||
<translation>打开</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="927"/>
|
||||
<location filename="../model/foldermodel.cpp" line="987"/>
|
||||
<source>Cut</source>
|
||||
<translation>剪切</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="930"/>
|
||||
<location filename="../model/foldermodel.cpp" line="990"/>
|
||||
<source>Copy</source>
|
||||
<translation>复制</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="933"/>
|
||||
<location filename="../model/foldermodel.cpp" line="993"/>
|
||||
<source>Paste</source>
|
||||
<translation>粘贴</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="936"/>
|
||||
<location filename="../model/foldermodel.cpp" line="996"/>
|
||||
<source>New Folder</source>
|
||||
<translation>新建文件夹</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="938"/>
|
||||
<location filename="../model/foldermodel.cpp" line="999"/>
|
||||
<source>Move To Trash</source>
|
||||
<translation>移动到回收站</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="941"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1002"/>
|
||||
<source>Empty Trash</source>
|
||||
<translation>清空回收站</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="944"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1005"/>
|
||||
<source>Delete</source>
|
||||
<translation>删除</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="947"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1008"/>
|
||||
<source>Rename</source>
|
||||
<translation>重命名</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="950"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1011"/>
|
||||
<source>Open in Terminal</source>
|
||||
<translation>在终端中打开</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="953"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1014"/>
|
||||
<source>Set as Wallpaper</source>
|
||||
<translation>设置为壁纸</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="956"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1017"/>
|
||||
<source>Properties</source>
|
||||
<translation>属性</translation>
|
||||
</message>
|
||||
|
@ -95,12 +118,12 @@
|
|||
<context>
|
||||
<name>FolderPage</name>
|
||||
<message>
|
||||
<location filename="../qml/FolderPage.qml" line="32"/>
|
||||
<location filename="../qml/FolderPage.qml" line="34"/>
|
||||
<source>No files</source>
|
||||
<translation>无文件</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/FolderPage.qml" line="97"/>
|
||||
<location filename="../qml/FolderPage.qml" line="108"/>
|
||||
<source>Empty Trash</source>
|
||||
<translation>清空回收站</translation>
|
||||
</message>
|
||||
|
@ -108,42 +131,42 @@
|
|||
<context>
|
||||
<name>PlacesModel</name>
|
||||
<message>
|
||||
<location filename="../model/placesmodel.cpp" line="38"/>
|
||||
<location filename="../model/placesmodel.cpp" line="39"/>
|
||||
<source>Home</source>
|
||||
<translation>主文件夹</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/placesmodel.cpp" line="45"/>
|
||||
<location filename="../model/placesmodel.cpp" line="46"/>
|
||||
<source>Desktop</source>
|
||||
<translation>桌面</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/placesmodel.cpp" line="52"/>
|
||||
<location filename="../model/placesmodel.cpp" line="53"/>
|
||||
<source>Documents</source>
|
||||
<translation>文档</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/placesmodel.cpp" line="59"/>
|
||||
<location filename="../model/placesmodel.cpp" line="60"/>
|
||||
<source>Downloads</source>
|
||||
<translation>下载</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/placesmodel.cpp" line="66"/>
|
||||
<location filename="../model/placesmodel.cpp" line="67"/>
|
||||
<source>Music</source>
|
||||
<translation>音乐</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/placesmodel.cpp" line="73"/>
|
||||
<location filename="../model/placesmodel.cpp" line="74"/>
|
||||
<source>Pictures</source>
|
||||
<translation>图片</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/placesmodel.cpp" line="80"/>
|
||||
<location filename="../model/placesmodel.cpp" line="81"/>
|
||||
<source>Videos</source>
|
||||
<translation>视频</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/placesmodel.cpp" line="85"/>
|
||||
<location filename="../model/placesmodel.cpp" line="86"/>
|
||||
<source>Trash</source>
|
||||
<translation>回收站</translation>
|
||||
</message>
|
||||
|
|
Loading…
Reference in a new issue