forked from qt-creator/qt-creator
PythonEditor: Support file operations
Change-Id: I0fc5a3e1795fe56c753e300ed1c1ca7514964401 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
a31655cde7
commit
d585b85550
@@ -113,6 +113,10 @@ public:
|
||||
|
||||
bool showInSimpleTree() const override;
|
||||
QString addFileFilter() const override;
|
||||
bool supportsAction(ProjectAction action, const Node *node) const override;
|
||||
bool addFiles(const QStringList &filePaths, QStringList *) override;
|
||||
bool removeFiles(const QStringList &filePaths, QStringList *) override;
|
||||
bool deleteFiles(const QStringList &) override;
|
||||
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
||||
|
||||
private:
|
||||
@@ -388,7 +392,7 @@ bool PythonProject::removeFiles(const QStringList &filePaths)
|
||||
bool PythonProject::setFiles(const QStringList &filePaths)
|
||||
{
|
||||
QStringList newList;
|
||||
QDir baseDir(projectFilePath().toString());
|
||||
QDir baseDir(projectDirectory().toString());
|
||||
foreach (const QString &filePath, filePaths)
|
||||
newList.append(baseDir.relativeFilePath(filePath));
|
||||
|
||||
@@ -403,7 +407,7 @@ bool PythonProject::renameFile(const QString &filePath, const QString &newFilePa
|
||||
if (i != m_rawListEntries.end()) {
|
||||
int index = newList.indexOf(i.value());
|
||||
if (index != -1) {
|
||||
QDir baseDir(projectFilePath().toString());
|
||||
QDir baseDir(projectDirectory().toString());
|
||||
newList.replace(index, baseDir.relativeFilePath(newFilePath));
|
||||
}
|
||||
}
|
||||
@@ -576,6 +580,37 @@ QString PythonProjectNode::addFileFilter() const
|
||||
return QLatin1String("*.py");
|
||||
}
|
||||
|
||||
bool PythonProjectNode::supportsAction(ProjectAction action, const Node *node) const
|
||||
{
|
||||
switch (node->nodeType()) {
|
||||
case NodeType::File:
|
||||
return action == ProjectAction::Rename
|
||||
|| action == ProjectAction::RemoveFile;
|
||||
case NodeType::Folder:
|
||||
case NodeType::Project:
|
||||
return action == ProjectAction::AddNewFile
|
||||
|| action == ProjectAction::RemoveFile
|
||||
|| action == ProjectAction::AddExistingFile;
|
||||
default:
|
||||
return ProjectNode::supportsAction(action, node);
|
||||
}
|
||||
}
|
||||
|
||||
bool PythonProjectNode::addFiles(const QStringList &filePaths, QStringList *)
|
||||
{
|
||||
return m_project->addFiles(filePaths);
|
||||
}
|
||||
|
||||
bool PythonProjectNode::removeFiles(const QStringList &filePaths, QStringList *)
|
||||
{
|
||||
return m_project->removeFiles(filePaths);
|
||||
}
|
||||
|
||||
bool PythonProjectNode::deleteFiles(const QStringList &)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PythonProjectNode::renameFile(const QString &filePath, const QString &newFilePath)
|
||||
{
|
||||
return m_project->renameFile(filePath, newFilePath);
|
||||
|
||||
Reference in New Issue
Block a user