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

View file

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

View file

@ -72,5 +72,6 @@
<file>images/drive-harddisk.svg</file>
<file>images/drive-optical.svg</file>
<file>images/drive-removable-media-usb.svg</file>
<file>templates/TextFile.txt</file>
</qresource>
</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>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1229"/>
<location filename="../model/foldermodel.cpp" line="1256"/>
<source>Select All</source>
<translation>Select All</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1342"/>
<location filename="../model/foldermodel.cpp" line="1373"/>
<source>File Manager</source>
<translation>File Manager</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1660"/>
<location filename="../model/foldermodel.cpp" line="1691"/>
<source>Open</source>
<translation>Open</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1663"/>
<location filename="../model/foldermodel.cpp" line="1694"/>
<source>Open with</source>
<translation>Open with</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1666"/>
<location filename="../model/foldermodel.cpp" line="1697"/>
<source>Cut</source>
<translation>Cut</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1669"/>
<location filename="../model/foldermodel.cpp" line="1700"/>
<source>Copy</source>
<translation>Copy</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1672"/>
<location filename="../model/foldermodel.cpp" line="1703"/>
<source>Paste</source>
<translation>Paste</translation>
</message>
<message>
<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>
<translation>New Folder</translation>
</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>
<translation>Move To Trash</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1681"/>
<location filename="../model/foldermodel.cpp" line="1717"/>
<source>Empty Trash</source>
<translation>Empty Trash</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1684"/>
<location filename="../model/foldermodel.cpp" line="1720"/>
<source>Delete</source>
<translation>Delete</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1687"/>
<location filename="../model/foldermodel.cpp" line="1723"/>
<source>Rename</source>
<translation>Rename</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1690"/>
<location filename="../model/foldermodel.cpp" line="1726"/>
<source>Open in Terminal</source>
<translation>Open in Terminal</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1693"/>
<location filename="../model/foldermodel.cpp" line="1729"/>
<source>Set as Wallpaper</source>
<translation>Set as Wallpaper</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1696"/>
<location filename="../model/foldermodel.cpp" line="1732"/>
<source>Properties</source>
<translation>Properties</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1699"/>
<location filename="../model/foldermodel.cpp" line="1735"/>
<source>Change background</source>
<translation>Change background</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1702"/>
<location filename="../model/foldermodel.cpp" line="1738"/>
<source>Restore</source>
<translation>Restore</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1705"/>
<location filename="../model/foldermodel.cpp" line="1741"/>
<source>Show hidden files</source>
<translation>Show hidden files</translation>
</message>
<message>
<location filename="../model/foldermodel.cpp" line="1710"/>
<location filename="../model/foldermodel.cpp" line="1746"/>
<source>Open in new window</source>
<translation type="unfinished"></translation>
</message>

View file

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