From d585b85550797f1d6bb384b51c376ce871394255 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Fri, 28 Sep 2018 17:30:58 +0300 Subject: PythonEditor: Support file operations Change-Id: I0fc5a3e1795fe56c753e300ed1c1ca7514964401 Reviewed-by: hjk --- src/plugins/pythoneditor/pythoneditorplugin.cpp | 39 +++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'src/plugins/pythoneditor/pythoneditorplugin.cpp') diff --git a/src/plugins/pythoneditor/pythoneditorplugin.cpp b/src/plugins/pythoneditor/pythoneditorplugin.cpp index 1441ba0ee4..b17f1990a4 100644 --- a/src/plugins/pythoneditor/pythoneditorplugin.cpp +++ b/src/plugins/pythoneditor/pythoneditorplugin.cpp @@ -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); -- cgit v1.2.1