diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp
index cc34e97..8d0a28a 100644
--- a/model/foldermodel.cpp
+++ b/model/foldermodel.cpp
@@ -914,6 +914,33 @@ void FolderModel::newFolder()
job->start();
}
+void FolderModel::newTextFile()
+{
+ QString rootPath = rootItem().url().toString();
+ QString baseName = tr("New Text");
+ QString newName = baseName;
+
+ int i = 0;
+ while (true) {
+ if (QFile::exists(rootItem().url().toLocalFile() + "/" + newName)) {
+ ++i;
+ newName = QString("%1%2").arg(baseName).arg(QString::number(i));
+ } else {
+ break;
+ }
+ }
+
+ m_newDocumentUrl = QUrl(rootItem().url().toString() + "/" + newName);
+
+ QFile srcFile(":/templates/TextFile.txt");
+
+ if (!srcFile.open(QIODevice::ReadOnly)) {
+ return;
+ }
+
+ srcFile.copy(m_newDocumentUrl.toLocalFile());
+}
+
void FolderModel::rename(int row, const QString &name)
{
if (row < 0)
@@ -1229,7 +1256,11 @@ void FolderModel::openContextMenu(QQuickItem *visualParent, Qt::KeyboardModifier
QAction *selectAll = new QAction(tr("Select All"), this);
connect(selectAll, &QAction::triggered, this, &FolderModel::selectAll);
+ QMenu *newMenu = new QMenu(tr("New Documents"));
+ newMenu->addAction(m_actionCollection.action("newTextFile"));
+
menu->addAction(m_actionCollection.action("newFolder"));
+ menu->addMenu(newMenu);
menu->addSeparator();
menu->addAction(m_actionCollection.action("paste"));
menu->addAction(selectAll);
@@ -1675,6 +1706,11 @@ void FolderModel::createActions()
QAction *newFolder = new QAction(tr("New Folder"), this);
connect(newFolder, &QAction::triggered, this, &FolderModel::newFolder);
+ QMenu *newDocuments = new QMenu(tr("New Documents"));
+ QAction *newTextFile = new QAction(tr("New Text"), this);
+ connect(newTextFile, &QAction::triggered, this, &FolderModel::newTextFile);
+ newDocuments->addAction(newTextFile);
+
QAction *trash = new QAction(tr("Move To Trash"), this);
connect(trash, &QAction::triggered, this, &FolderModel::moveSelectedToTrash);
@@ -1716,6 +1752,7 @@ void FolderModel::createActions()
m_actionCollection.addAction(QStringLiteral("copy"), copy);
m_actionCollection.addAction(QStringLiteral("paste"), paste);
m_actionCollection.addAction(QStringLiteral("newFolder"), newFolder);
+ m_actionCollection.addAction(QStringLiteral("newTextFile"), newTextFile);
m_actionCollection.addAction(QStringLiteral("trash"), trash);
m_actionCollection.addAction(QStringLiteral("emptyTrash"), emptyTrash);
m_actionCollection.addAction(QStringLiteral("del"), del);
@@ -1792,6 +1829,11 @@ void FolderModel::updateActions()
newFolder->setEnabled(rootItem().isWritable());
}
+ if (QAction *newTextFile = m_actionCollection.action(QStringLiteral("newTextFile"))) {
+ newTextFile->setVisible(!isTrash);
+ newTextFile->setEnabled(rootItem().isWritable());
+ }
+
if (QAction *paste = m_actionCollection.action(QStringLiteral("paste"))) {
bool enable = false;
diff --git a/model/foldermodel.h b/model/foldermodel.h
index ce1811c..6920ec8 100644
--- a/model/foldermodel.h
+++ b/model/foldermodel.h
@@ -188,6 +188,7 @@ public:
Q_INVOKABLE void unpinSelection();
Q_INVOKABLE void newFolder();
+ Q_INVOKABLE void newTextFile();
Q_INVOKABLE void rename(int row, const QString &name);
Q_INVOKABLE void copy();
Q_INVOKABLE void paste();
diff --git a/qml.qrc b/qml.qrc
index 1c76bec..66f91a2 100644
--- a/qml.qrc
+++ b/qml.qrc
@@ -72,5 +72,6 @@
images/drive-harddisk.svg
images/drive-optical.svg
images/drive-removable-media-usb.svg
+ templates/TextFile.txt
diff --git a/templates/TextFile.txt b/templates/TextFile.txt
new file mode 100644
index 0000000..8d1c8b6
--- /dev/null
+++ b/templates/TextFile.txt
@@ -0,0 +1 @@
+
diff --git a/translations/en_US.ts b/translations/en_US.ts
index 1353d83..1299640 100644
--- a/translations/en_US.ts
+++ b/translations/en_US.ts
@@ -142,98 +142,110 @@
The file or folder %1 does not exist.
-
+
Select All
-
+
File Manager
-
+
Open
-
+
Open with
-
+
Cut
-
+
Copy
-
+
Paste
-
+
New Folder
-
+
+
+
+
+
+
+
+
+
+
+
+
+
Move To Trash
-
+
Empty Trash
-
+
Delete
-
+
Rename
-
+
Open in Terminal
-
+
Set as Wallpaper
-
+
Properties
-
+
Change background
-
+
Restore
-
+
Show hidden files
-
+
diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts
index 5a52b3a..21abaaa 100644
--- a/translations/zh_CN.ts
+++ b/translations/zh_CN.ts
@@ -142,98 +142,110 @@
文件或文件夹 %1 不存在
-
+
全选
-
+
文件管理器
-
+
打开
-
+
打开方式
-
+
剪切
-
+
复制
-
+
粘贴
-
+
新建文件夹
-
+
+
+
+ 新建文本
+
+
+
+
+
+ 新建文档
+
+
+
移动到回收站
-
+
清空回收站
-
+
删除
-
+
重命名
-
+
在终端中打开
-
+
设置为壁纸
-
+
属性
-
+
更改桌面背景
-
+
恢复
-
+
显示隐藏文件
-
+
在新窗口中打开
@@ -454,10 +466,6 @@
PropertiesDialog
-
-
- 属性
-
@@ -503,10 +511,6 @@
确定
-
-
- %1 项
-
SideBar