feat: add new documents option

This commit is contained in:
kateleet 2021-12-27 01:32:21 +08:00
parent b1a1061922
commit d733c9d55c
6 changed files with 107 additions and 46 deletions

View file

@ -914,6 +914,33 @@ void FolderModel::newFolder()
job->start(); 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) void FolderModel::rename(int row, const QString &name)
{ {
if (row < 0) if (row < 0)
@ -1229,7 +1256,11 @@ void FolderModel::openContextMenu(QQuickItem *visualParent, Qt::KeyboardModifier
QAction *selectAll = new QAction(tr("Select All"), this); QAction *selectAll = new QAction(tr("Select All"), this);
connect(selectAll, &QAction::triggered, this, &FolderModel::selectAll); 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->addAction(m_actionCollection.action("newFolder"));
menu->addMenu(newMenu);
menu->addSeparator(); menu->addSeparator();
menu->addAction(m_actionCollection.action("paste")); menu->addAction(m_actionCollection.action("paste"));
menu->addAction(selectAll); menu->addAction(selectAll);
@ -1675,6 +1706,11 @@ void FolderModel::createActions()
QAction *newFolder = new QAction(tr("New Folder"), this); QAction *newFolder = new QAction(tr("New Folder"), this);
connect(newFolder, &QAction::triggered, this, &FolderModel::newFolder); 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); QAction *trash = new QAction(tr("Move To Trash"), this);
connect(trash, &QAction::triggered, this, &FolderModel::moveSelectedToTrash); connect(trash, &QAction::triggered, this, &FolderModel::moveSelectedToTrash);
@ -1716,6 +1752,7 @@ void FolderModel::createActions()
m_actionCollection.addAction(QStringLiteral("copy"), copy); m_actionCollection.addAction(QStringLiteral("copy"), copy);
m_actionCollection.addAction(QStringLiteral("paste"), paste); m_actionCollection.addAction(QStringLiteral("paste"), paste);
m_actionCollection.addAction(QStringLiteral("newFolder"), newFolder); m_actionCollection.addAction(QStringLiteral("newFolder"), newFolder);
m_actionCollection.addAction(QStringLiteral("newTextFile"), newTextFile);
m_actionCollection.addAction(QStringLiteral("trash"), trash); m_actionCollection.addAction(QStringLiteral("trash"), trash);
m_actionCollection.addAction(QStringLiteral("emptyTrash"), emptyTrash); m_actionCollection.addAction(QStringLiteral("emptyTrash"), emptyTrash);
m_actionCollection.addAction(QStringLiteral("del"), del); m_actionCollection.addAction(QStringLiteral("del"), del);
@ -1792,6 +1829,11 @@ void FolderModel::updateActions()
newFolder->setEnabled(rootItem().isWritable()); 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"))) { if (QAction *paste = m_actionCollection.action(QStringLiteral("paste"))) {
bool enable = false; bool enable = false;

View file

@ -188,6 +188,7 @@ public:
Q_INVOKABLE void unpinSelection(); Q_INVOKABLE void unpinSelection();
Q_INVOKABLE void newFolder(); Q_INVOKABLE void newFolder();
Q_INVOKABLE void newTextFile();
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

@ -72,5 +72,6 @@
<file>images/drive-harddisk.svg</file> <file>images/drive-harddisk.svg</file>
<file>images/drive-optical.svg</file> <file>images/drive-optical.svg</file>
<file>images/drive-removable-media-usb.svg</file> <file>images/drive-removable-media-usb.svg</file>
<file>templates/TextFile.txt</file>
</qresource> </qresource>
</RCC> </RCC>

1
templates/TextFile.txt Normal file
View file

@ -0,0 +1 @@

View file

@ -142,98 +142,110 @@
<translation>The file or folder %1 does not exist.</translation> <translation>The file or folder %1 does not exist.</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1229"/> <location filename="../model/foldermodel.cpp" line="1256"/>
<source>Select All</source> <source>Select All</source>
<translation>Select All</translation> <translation>Select All</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1342"/> <location filename="../model/foldermodel.cpp" line="1373"/>
<source>File Manager</source> <source>File Manager</source>
<translation>File Manager</translation> <translation>File Manager</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1660"/> <location filename="../model/foldermodel.cpp" line="1691"/>
<source>Open</source> <source>Open</source>
<translation>Open</translation> <translation>Open</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1663"/> <location filename="../model/foldermodel.cpp" line="1694"/>
<source>Open with</source> <source>Open with</source>
<translation>Open with</translation> <translation>Open with</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1666"/> <location filename="../model/foldermodel.cpp" line="1697"/>
<source>Cut</source> <source>Cut</source>
<translation>Cut</translation> <translation>Cut</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1669"/> <location filename="../model/foldermodel.cpp" line="1700"/>
<source>Copy</source> <source>Copy</source>
<translation>Copy</translation> <translation>Copy</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1672"/> <location filename="../model/foldermodel.cpp" line="1703"/>
<source>Paste</source> <source>Paste</source>
<translation>Paste</translation> <translation>Paste</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="898"/> <location filename="../model/foldermodel.cpp" line="898"/>
<location filename="../model/foldermodel.cpp" line="1675"/> <location filename="../model/foldermodel.cpp" line="1706"/>
<source>New Folder</source> <source>New Folder</source>
<translation>New Folder</translation> <translation>New Folder</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1678"/> <location filename="../model/foldermodel.cpp" line="920"/>
<location filename="../model/foldermodel.cpp" line="1710"/>
<source>New Text</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1259"/>
<location filename="../model/foldermodel.cpp" line="1709"/>
<source>New Documents</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1714"/>
<source>Move To Trash</source> <source>Move To Trash</source>
<translation>Move To Trash</translation> <translation>Move To Trash</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1681"/> <location filename="../model/foldermodel.cpp" line="1717"/>
<source>Empty Trash</source> <source>Empty Trash</source>
<translation>Empty Trash</translation> <translation>Empty Trash</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1684"/> <location filename="../model/foldermodel.cpp" line="1720"/>
<source>Delete</source> <source>Delete</source>
<translation>Delete</translation> <translation>Delete</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1687"/> <location filename="../model/foldermodel.cpp" line="1723"/>
<source>Rename</source> <source>Rename</source>
<translation>Rename</translation> <translation>Rename</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1690"/> <location filename="../model/foldermodel.cpp" line="1726"/>
<source>Open in Terminal</source> <source>Open in Terminal</source>
<translation>Open in Terminal</translation> <translation>Open in Terminal</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1693"/> <location filename="../model/foldermodel.cpp" line="1729"/>
<source>Set as Wallpaper</source> <source>Set as Wallpaper</source>
<translation>Set as Wallpaper</translation> <translation>Set as Wallpaper</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1696"/> <location filename="../model/foldermodel.cpp" line="1732"/>
<source>Properties</source> <source>Properties</source>
<translation>Properties</translation> <translation>Properties</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1699"/> <location filename="../model/foldermodel.cpp" line="1735"/>
<source>Change background</source> <source>Change background</source>
<translation>Change background</translation> <translation>Change background</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1702"/> <location filename="../model/foldermodel.cpp" line="1738"/>
<source>Restore</source> <source>Restore</source>
<translation>Restore</translation> <translation>Restore</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1705"/> <location filename="../model/foldermodel.cpp" line="1741"/>
<source>Show hidden files</source> <source>Show hidden files</source>
<translation>Show hidden files</translation> <translation>Show hidden files</translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1710"/> <location filename="../model/foldermodel.cpp" line="1746"/>
<source>Open in new window</source> <source>Open in new window</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>

View file

@ -142,98 +142,110 @@
<translation> %1 </translation> <translation> %1 </translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1229"/> <location filename="../model/foldermodel.cpp" line="1256"/>
<source>Select All</source> <source>Select All</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1342"/> <location filename="../model/foldermodel.cpp" line="1373"/>
<source>File Manager</source> <source>File Manager</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1660"/> <location filename="../model/foldermodel.cpp" line="1691"/>
<source>Open</source> <source>Open</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1663"/> <location filename="../model/foldermodel.cpp" line="1694"/>
<source>Open with</source> <source>Open with</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1666"/> <location filename="../model/foldermodel.cpp" line="1697"/>
<source>Cut</source> <source>Cut</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1669"/> <location filename="../model/foldermodel.cpp" line="1700"/>
<source>Copy</source> <source>Copy</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1672"/> <location filename="../model/foldermodel.cpp" line="1703"/>
<source>Paste</source> <source>Paste</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="898"/> <location filename="../model/foldermodel.cpp" line="898"/>
<location filename="../model/foldermodel.cpp" line="1675"/> <location filename="../model/foldermodel.cpp" line="1706"/>
<source>New Folder</source> <source>New Folder</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1678"/> <location filename="../model/foldermodel.cpp" line="920"/>
<location filename="../model/foldermodel.cpp" line="1710"/>
<source>New Text</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1259"/>
<location filename="../model/foldermodel.cpp" line="1709"/>
<source>New Documents</source>
<translation></translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1714"/>
<source>Move To Trash</source> <source>Move To Trash</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1681"/> <location filename="../model/foldermodel.cpp" line="1717"/>
<source>Empty Trash</source> <source>Empty Trash</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1684"/> <location filename="../model/foldermodel.cpp" line="1720"/>
<source>Delete</source> <source>Delete</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1687"/> <location filename="../model/foldermodel.cpp" line="1723"/>
<source>Rename</source> <source>Rename</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1690"/> <location filename="../model/foldermodel.cpp" line="1726"/>
<source>Open in Terminal</source> <source>Open in Terminal</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1693"/> <location filename="../model/foldermodel.cpp" line="1729"/>
<source>Set as Wallpaper</source> <source>Set as Wallpaper</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1696"/> <location filename="../model/foldermodel.cpp" line="1732"/>
<source>Properties</source> <source>Properties</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1699"/> <location filename="../model/foldermodel.cpp" line="1735"/>
<source>Change background</source> <source>Change background</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1702"/> <location filename="../model/foldermodel.cpp" line="1738"/>
<source>Restore</source> <source>Restore</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1705"/> <location filename="../model/foldermodel.cpp" line="1741"/>
<source>Show hidden files</source> <source>Show hidden files</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../model/foldermodel.cpp" line="1710"/> <location filename="../model/foldermodel.cpp" line="1746"/>
<source>Open in new window</source> <source>Open in new window</source>
<translation></translation> <translation></translation>
</message> </message>
@ -454,10 +466,6 @@
</context> </context>
<context> <context>
<name>PropertiesDialog</name> <name>PropertiesDialog</name>
<message>
<source>Properties</source>
<translation type="vanished"></translation>
</message>
<message> <message>
<location filename="../qml/Dialogs/PropertiesDialog.qml" line="100"/> <location filename="../qml/Dialogs/PropertiesDialog.qml" line="100"/>
<source>Type:</source> <source>Type:</source>
@ -503,10 +511,6 @@
<source>OK</source> <source>OK</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>%1 files</source>
<translation type="vanished">%1 </translation>
</message>
</context> </context>
<context> <context>
<name>SideBar</name> <name>SideBar</name>