2013-01-14 23:11:10 +04:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-01-14 23:11:10 +04:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2013-01-14 23:11:10 +04:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2013-01-14 23:11:10 +04:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "pythoneditorplugin.h"
|
2014-08-20 15:05:32 +02:00
|
|
|
#include "pythoneditor.h"
|
2013-01-14 23:11:10 +04:00
|
|
|
#include "pythoneditorconstants.h"
|
2016-08-03 00:07:44 +02:00
|
|
|
#include "pythonhighlighter.h"
|
2013-01-14 23:11:10 +04:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
2015-06-09 15:19:54 +02:00
|
|
|
#include <coreplugin/documentmanager.h>
|
2013-01-14 23:11:10 +04:00
|
|
|
#include <coreplugin/fileiconprovider.h>
|
|
|
|
|
#include <coreplugin/id.h>
|
2019-03-01 10:26:59 +01:00
|
|
|
#include <coreplugin/messagemanager.h>
|
2013-01-14 23:11:10 +04:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2015-06-09 15:19:54 +02:00
|
|
|
|
2018-03-06 15:28:06 +01:00
|
|
|
#include <projectexplorer/buildtargetinfo.h>
|
2015-06-09 15:19:54 +02:00
|
|
|
#include <projectexplorer/kitmanager.h>
|
|
|
|
|
#include <projectexplorer/localenvironmentaspect.h>
|
2019-03-13 08:06:08 +01:00
|
|
|
#include <projectexplorer/runcontrol.h>
|
2015-06-09 15:19:54 +02:00
|
|
|
#include <projectexplorer/runconfiguration.h>
|
|
|
|
|
#include <projectexplorer/runconfigurationaspects.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
2017-03-03 18:16:34 +01:00
|
|
|
#include <projectexplorer/projectmanager.h>
|
|
|
|
|
#include <projectexplorer/projectnodes.h>
|
2015-06-09 15:19:54 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2018-03-29 15:29:17 +02:00
|
|
|
#include <projectexplorer/task.h>
|
|
|
|
|
#include <projectexplorer/taskhub.h>
|
2015-06-09 15:19:54 +02:00
|
|
|
|
2013-01-14 23:11:10 +04:00
|
|
|
#include <texteditor/texteditorconstants.h>
|
2015-06-09 15:19:54 +02:00
|
|
|
|
2016-09-30 23:13:45 +02:00
|
|
|
#include <utils/algorithm.h>
|
2018-03-29 15:29:17 +02:00
|
|
|
#include <utils/outputformatter.h>
|
2015-06-09 15:19:54 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2016-08-03 17:55:54 +02:00
|
|
|
#include <utils/utilsicons.h>
|
2013-01-14 23:11:10 +04:00
|
|
|
|
2018-03-06 15:28:06 +01:00
|
|
|
#include <QDir>
|
2017-03-09 23:02:32 +01:00
|
|
|
#include <QRegExp>
|
2018-03-29 15:29:17 +02:00
|
|
|
#include <QRegularExpression>
|
|
|
|
|
#include <QRegularExpressionMatch>
|
|
|
|
|
#include <QTextCursor>
|
2019-01-16 13:04:51 +01:00
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QJsonObject>
|
2019-03-01 10:26:59 +01:00
|
|
|
#include <QJsonParseError>
|
2019-01-16 13:04:51 +01:00
|
|
|
#include <QJsonValue>
|
|
|
|
|
#include <QJsonArray>
|
2013-01-14 23:11:10 +04:00
|
|
|
|
2015-06-09 15:19:54 +02:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace ProjectExplorer;
|
2013-01-14 23:11:10 +04:00
|
|
|
using namespace PythonEditor::Constants;
|
2015-06-09 15:19:54 +02:00
|
|
|
using namespace Utils;
|
2013-01-14 23:11:10 +04:00
|
|
|
|
|
|
|
|
namespace PythonEditor {
|
2013-08-23 13:41:17 +02:00
|
|
|
namespace Internal {
|
2013-01-14 23:11:10 +04:00
|
|
|
|
2015-06-09 15:19:54 +02:00
|
|
|
const char PythonMimeType[] = "text/x-python-project"; // ### FIXME
|
|
|
|
|
const char PythonProjectId[] = "PythonProject";
|
2018-03-29 15:29:17 +02:00
|
|
|
const char PythonErrorTaskCategory[] = "Task.Category.Python";
|
2015-06-09 15:19:54 +02:00
|
|
|
|
|
|
|
|
class PythonProject : public Project
|
|
|
|
|
{
|
2017-11-17 08:24:47 +01:00
|
|
|
Q_OBJECT
|
2015-06-09 15:19:54 +02:00
|
|
|
public:
|
2017-03-03 18:16:34 +01:00
|
|
|
explicit PythonProject(const Utils::FileName &filename);
|
2015-06-09 15:19:54 +02:00
|
|
|
|
|
|
|
|
bool addFiles(const QStringList &filePaths);
|
|
|
|
|
bool removeFiles(const QStringList &filePaths);
|
|
|
|
|
bool setFiles(const QStringList &filePaths);
|
|
|
|
|
bool renameFile(const QString &filePath, const QString &newFilePath);
|
2018-03-06 15:28:06 +01:00
|
|
|
void refresh(Target *target = nullptr);
|
2015-06-09 15:19:54 +02:00
|
|
|
|
2018-03-09 13:30:13 +01:00
|
|
|
bool needsConfiguration() const final { return false; }
|
2018-04-19 13:30:15 +02:00
|
|
|
bool needsBuildConfigurations() const final { return false; }
|
2018-03-09 13:30:13 +01:00
|
|
|
|
2019-03-13 18:22:45 +01:00
|
|
|
bool writePyProjectFile(const QString &fileName, QString &content,
|
|
|
|
|
const QStringList &rawList, QString *errorMessage);
|
|
|
|
|
|
2015-06-09 15:19:54 +02:00
|
|
|
private:
|
2015-07-23 11:23:52 +02:00
|
|
|
RestoreResult fromMap(const QVariantMap &map, QString *errorMessage) override;
|
2018-03-09 12:23:00 +01:00
|
|
|
bool setupTarget(Target *t) override
|
2018-03-06 15:28:06 +01:00
|
|
|
{
|
|
|
|
|
refresh(t);
|
|
|
|
|
return Project::setupTarget(t);
|
|
|
|
|
}
|
2015-07-23 11:23:52 +02:00
|
|
|
|
2015-06-09 15:19:54 +02:00
|
|
|
bool saveRawFileList(const QStringList &rawFileList);
|
|
|
|
|
bool saveRawList(const QStringList &rawList, const QString &fileName);
|
|
|
|
|
void parseProject();
|
|
|
|
|
QStringList processEntries(const QStringList &paths,
|
2018-11-23 23:23:01 +01:00
|
|
|
QHash<QString, QString> *map = nullptr) const;
|
2015-06-09 15:19:54 +02:00
|
|
|
|
|
|
|
|
QStringList m_rawFileList;
|
|
|
|
|
QStringList m_files;
|
|
|
|
|
QHash<QString, QString> m_rawListEntries;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PythonProjectNode : public ProjectNode
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-10-29 17:12:36 +01:00
|
|
|
PythonProjectNode(PythonProject *project);
|
2015-06-09 15:19:54 +02:00
|
|
|
|
2018-09-28 17:30:58 +03:00
|
|
|
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;
|
2015-07-23 11:23:52 +02:00
|
|
|
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
2015-06-09 15:19:54 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
PythonProject *m_project;
|
|
|
|
|
};
|
|
|
|
|
|
2018-04-06 09:54:14 +02:00
|
|
|
static QTextCharFormat linkFormat(const QTextCharFormat &inputFormat, const QString &href)
|
|
|
|
|
{
|
|
|
|
|
QTextCharFormat result = inputFormat;
|
|
|
|
|
result.setForeground(creatorTheme()->color(Theme::TextColorLink));
|
|
|
|
|
result.setUnderlineStyle(QTextCharFormat::SingleUnderline);
|
|
|
|
|
result.setAnchor(true);
|
|
|
|
|
result.setAnchorHref(href);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PythonOutputFormatter : public OutputFormatter
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-04-06 09:21:44 +02:00
|
|
|
PythonOutputFormatter(Project *)
|
2018-04-06 09:54:14 +02:00
|
|
|
// Note that moc dislikes raw string literals.
|
|
|
|
|
: filePattern("^(\\s*)(File \"([^\"]+)\", line (\\d+), .*$)")
|
|
|
|
|
{
|
|
|
|
|
TaskHub::clearTasks(PythonErrorTaskCategory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void appendMessage(const QString &text, OutputFormat format) final
|
|
|
|
|
{
|
|
|
|
|
const bool isTrace = (format == StdErrFormat
|
|
|
|
|
|| format == StdErrFormatSameLine)
|
|
|
|
|
&& (text.startsWith("Traceback (most recent call last):")
|
|
|
|
|
|| text.startsWith("\nTraceback (most recent call last):"));
|
|
|
|
|
|
|
|
|
|
if (!isTrace) {
|
|
|
|
|
OutputFormatter::appendMessage(text, format);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QTextCharFormat frm = charFormat(format);
|
|
|
|
|
const Core::Id id(PythonErrorTaskCategory);
|
|
|
|
|
QVector<Task> tasks;
|
|
|
|
|
const QStringList lines = text.split('\n');
|
|
|
|
|
unsigned taskId = unsigned(lines.size());
|
|
|
|
|
|
|
|
|
|
for (const QString &line : lines) {
|
|
|
|
|
const QRegularExpressionMatch match = filePattern.match(line);
|
|
|
|
|
if (match.hasMatch()) {
|
|
|
|
|
QTextCursor tc = plainTextEdit()->textCursor();
|
|
|
|
|
tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
|
|
|
|
|
tc.insertText('\n' + match.captured(1));
|
|
|
|
|
tc.insertText(match.captured(2), linkFormat(frm, match.captured(2)));
|
|
|
|
|
|
|
|
|
|
const auto fileName = FileName::fromString(match.captured(3));
|
|
|
|
|
const int lineNumber = match.capturedRef(4).toInt();
|
|
|
|
|
Task task(Task::Warning,
|
|
|
|
|
QString(), fileName, lineNumber, id);
|
|
|
|
|
task.taskId = --taskId;
|
|
|
|
|
tasks.append(task);
|
|
|
|
|
} else {
|
|
|
|
|
if (!tasks.isEmpty()) {
|
|
|
|
|
Task &task = tasks.back();
|
|
|
|
|
if (!task.description.isEmpty())
|
|
|
|
|
task.description += ' ';
|
|
|
|
|
task.description += line.trimmed();
|
|
|
|
|
}
|
|
|
|
|
OutputFormatter::appendMessage('\n' + line, format);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!tasks.isEmpty()) {
|
|
|
|
|
tasks.back().type = Task::Error;
|
|
|
|
|
for (auto rit = tasks.crbegin(), rend = tasks.crend(); rit != rend; ++rit)
|
|
|
|
|
TaskHub::addTask(*rit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handleLink(const QString &href) final
|
|
|
|
|
{
|
|
|
|
|
const QRegularExpressionMatch match = filePattern.match(href);
|
|
|
|
|
if (!match.hasMatch())
|
|
|
|
|
return;
|
|
|
|
|
const QString fileName = match.captured(3);
|
|
|
|
|
const int lineNumber = match.capturedRef(4).toInt();
|
|
|
|
|
Core::EditorManager::openEditorAt(fileName, lineNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QRegularExpression filePattern;
|
|
|
|
|
};
|
|
|
|
|
|
2018-04-26 17:04:52 +02:00
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class InterpreterAspect : public BaseStringAspect
|
2015-06-09 15:19:54 +02:00
|
|
|
{
|
2018-04-26 17:04:52 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
2015-06-09 15:19:54 +02:00
|
|
|
public:
|
2018-09-12 10:43:10 +02:00
|
|
|
InterpreterAspect() = default;
|
2018-04-26 17:04:52 +02:00
|
|
|
};
|
2015-06-09 15:19:54 +02:00
|
|
|
|
2018-04-26 17:04:52 +02:00
|
|
|
class MainScriptAspect : public BaseStringAspect
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2018-09-12 10:43:10 +02:00
|
|
|
MainScriptAspect() = default;
|
2015-06-09 15:19:54 +02:00
|
|
|
};
|
|
|
|
|
|
2016-10-05 17:59:59 +02:00
|
|
|
class PythonRunConfiguration : public RunConfiguration
|
2015-06-09 15:19:54 +02:00
|
|
|
{
|
2015-07-23 14:31:43 +03:00
|
|
|
Q_OBJECT
|
2015-07-23 11:23:52 +02:00
|
|
|
|
|
|
|
|
Q_PROPERTY(bool supportsDebugger READ supportsDebugger)
|
|
|
|
|
Q_PROPERTY(QString interpreter READ interpreter)
|
|
|
|
|
Q_PROPERTY(QString mainScript READ mainScript)
|
|
|
|
|
Q_PROPERTY(QString arguments READ arguments)
|
|
|
|
|
|
2015-06-09 15:19:54 +02:00
|
|
|
public:
|
2018-04-25 10:26:08 +02:00
|
|
|
PythonRunConfiguration(Target *target, Core::Id id);
|
2015-06-09 15:19:54 +02:00
|
|
|
|
2018-04-26 17:04:52 +02:00
|
|
|
private:
|
|
|
|
|
void doAdditionalSetup(const RunConfigurationCreationInfo &) final { updateTargetInformation(); }
|
|
|
|
|
Runnable runnable() const final;
|
2015-06-09 15:19:54 +02:00
|
|
|
|
2015-07-23 11:23:52 +02:00
|
|
|
bool supportsDebugger() const { return true; }
|
2018-09-07 13:29:45 +02:00
|
|
|
QString mainScript() const { return aspect<MainScriptAspect>()->value(); }
|
|
|
|
|
QString arguments() const { return aspect<ArgumentsAspect>()->arguments(macroExpander()); }
|
|
|
|
|
QString interpreter() const { return aspect<InterpreterAspect>()->value(); }
|
2015-06-09 15:19:54 +02:00
|
|
|
|
2018-04-26 17:04:52 +02:00
|
|
|
void updateTargetInformation();
|
2015-06-09 15:19:54 +02:00
|
|
|
};
|
|
|
|
|
|
2018-04-25 10:26:08 +02:00
|
|
|
PythonRunConfiguration::PythonRunConfiguration(Target *target, Core::Id id)
|
|
|
|
|
: RunConfiguration(target, id)
|
2015-06-09 15:19:54 +02:00
|
|
|
{
|
2018-04-26 17:04:52 +02:00
|
|
|
const Environment sysEnv = Environment::systemEnvironment();
|
|
|
|
|
const QString exec = sysEnv.searchInPath("python").toString();
|
|
|
|
|
|
2018-09-04 10:36:44 +02:00
|
|
|
auto interpreterAspect = addAspect<InterpreterAspect>();
|
2018-04-26 17:04:52 +02:00
|
|
|
interpreterAspect->setSettingsKey("PythonEditor.RunConfiguation.Interpreter");
|
|
|
|
|
interpreterAspect->setLabelText(tr("Interpreter:"));
|
|
|
|
|
interpreterAspect->setDisplayStyle(BaseStringAspect::PathChooserDisplay);
|
2018-05-09 13:53:41 +02:00
|
|
|
interpreterAspect->setHistoryCompleter("PythonEditor.Interpreter.History");
|
2018-04-26 17:04:52 +02:00
|
|
|
interpreterAspect->setValue(exec.isEmpty() ? "python" : exec);
|
|
|
|
|
|
2018-09-04 10:36:44 +02:00
|
|
|
auto scriptAspect = addAspect<MainScriptAspect>();
|
2018-04-26 17:04:52 +02:00
|
|
|
scriptAspect->setSettingsKey("PythonEditor.RunConfiguation.Script");
|
|
|
|
|
scriptAspect->setLabelText(tr("Script:"));
|
|
|
|
|
scriptAspect->setDisplayStyle(BaseStringAspect::LabelDisplay);
|
|
|
|
|
|
2019-03-07 10:10:22 +01:00
|
|
|
addAspect<LocalEnvironmentAspect>(target);
|
2018-09-04 10:36:44 +02:00
|
|
|
addAspect<ArgumentsAspect>();
|
|
|
|
|
addAspect<TerminalAspect>();
|
2015-06-09 15:19:54 +02:00
|
|
|
|
2018-04-26 17:04:52 +02:00
|
|
|
setOutputFormatter<PythonOutputFormatter>();
|
2015-06-09 15:19:54 +02:00
|
|
|
|
2018-04-26 17:04:52 +02:00
|
|
|
connect(target, &Target::applicationTargetsChanged,
|
|
|
|
|
this, &PythonRunConfiguration::updateTargetInformation);
|
|
|
|
|
connect(target->project(), &Project::parsingFinished,
|
|
|
|
|
this, &PythonRunConfiguration::updateTargetInformation);
|
2018-03-06 16:48:51 +01:00
|
|
|
}
|
|
|
|
|
|
2018-04-26 17:04:52 +02:00
|
|
|
void PythonRunConfiguration::updateTargetInformation()
|
2015-06-09 15:19:54 +02:00
|
|
|
{
|
2018-04-30 09:42:55 +02:00
|
|
|
const BuildTargetInfo bti = buildTargetInfo();
|
2018-04-26 17:04:52 +02:00
|
|
|
const QString script = bti.targetFilePath.toString();
|
|
|
|
|
setDefaultDisplayName(tr("Run %1").arg(script));
|
2018-09-07 13:29:45 +02:00
|
|
|
aspect<MainScriptAspect>()->setValue(script);
|
2015-06-09 15:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
2017-03-10 09:05:52 +01:00
|
|
|
Runnable PythonRunConfiguration::runnable() const
|
|
|
|
|
{
|
2018-05-16 15:42:03 +02:00
|
|
|
Runnable r;
|
2018-04-26 17:04:52 +02:00
|
|
|
QtcProcess::addArg(&r.commandLineArguments, mainScript());
|
2018-09-12 10:09:41 +02:00
|
|
|
QtcProcess::addArgs(&r.commandLineArguments,
|
2018-09-07 13:29:45 +02:00
|
|
|
aspect<ArgumentsAspect>()->arguments(macroExpander()));
|
|
|
|
|
r.executable = aspect<InterpreterAspect>()->value();
|
|
|
|
|
r.environment = aspect<EnvironmentAspect>()->environment();
|
2017-03-10 09:05:52 +01:00
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-06 17:14:43 +01:00
|
|
|
class PythonRunConfigurationFactory : public RunConfigurationFactory
|
2015-06-09 15:19:54 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
PythonRunConfigurationFactory()
|
|
|
|
|
{
|
2018-04-25 10:26:08 +02:00
|
|
|
registerRunConfiguration<PythonRunConfiguration>("PythonEditor.RunConfiguration.");
|
2017-12-08 14:50:57 +01:00
|
|
|
addSupportedProjectType(PythonProjectId);
|
2015-06-09 15:19:54 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-03-29 11:25:01 +02:00
|
|
|
PythonProject::PythonProject(const FileName &fileName) :
|
|
|
|
|
Project(Constants::C_PY_MIMETYPE, fileName, [this]() { refresh(); })
|
2015-06-09 15:19:54 +02:00
|
|
|
{
|
|
|
|
|
setId(PythonProjectId);
|
2017-01-30 14:59:10 +01:00
|
|
|
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
2017-04-07 14:35:49 +02:00
|
|
|
setDisplayName(fileName.toFileInfo().completeBaseName());
|
2015-06-09 15:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-28 17:55:46 +03:00
|
|
|
static QStringList readLines(const Utils::FileName &projectFile)
|
2015-06-09 15:19:54 +02:00
|
|
|
{
|
2018-09-28 17:55:46 +03:00
|
|
|
const QString projectFileName = projectFile.fileName();
|
|
|
|
|
QSet<QString> visited = { projectFileName };
|
|
|
|
|
QStringList lines = { projectFileName };
|
2015-06-09 15:19:54 +02:00
|
|
|
|
2018-09-28 17:55:46 +03:00
|
|
|
QFile file(projectFile.toString());
|
2015-06-09 15:19:54 +02:00
|
|
|
if (file.open(QFile::ReadOnly)) {
|
|
|
|
|
QTextStream stream(&file);
|
|
|
|
|
|
2019-03-14 08:11:31 +01:00
|
|
|
while (true) {
|
2019-03-28 09:29:30 +01:00
|
|
|
const QString line = stream.readLine();
|
2015-06-09 15:19:54 +02:00
|
|
|
if (line.isNull())
|
|
|
|
|
break;
|
2018-09-28 17:55:46 +03:00
|
|
|
if (visited.contains(line))
|
|
|
|
|
continue;
|
2015-06-09 15:19:54 +02:00
|
|
|
lines.append(line);
|
2018-09-28 17:55:46 +03:00
|
|
|
visited.insert(line);
|
2015-06-09 15:19:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lines;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-01 10:26:59 +01:00
|
|
|
static QStringList readLinesJson(const Utils::FileName &projectFile,
|
|
|
|
|
QString *errorMessage)
|
2019-01-16 13:04:51 +01:00
|
|
|
{
|
|
|
|
|
const QString projectFileName = projectFile.fileName();
|
|
|
|
|
QStringList lines = { projectFileName };
|
|
|
|
|
|
|
|
|
|
QFile file(projectFile.toString());
|
2019-03-01 10:26:59 +01:00
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
|
*errorMessage = PythonProject::tr("Unable to open \"%1\" for reading: %2")
|
|
|
|
|
.arg(projectFile.toUserOutput(), file.errorString());
|
2019-01-16 13:04:51 +01:00
|
|
|
return lines;
|
2019-03-01 10:26:59 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-16 13:04:51 +01:00
|
|
|
const QByteArray content = file.readAll();
|
|
|
|
|
|
|
|
|
|
// This assumes te project file is formed with only one field called
|
|
|
|
|
// 'files' that has a list associated of the files to include in the project.
|
2019-03-01 10:26:59 +01:00
|
|
|
if (content.isEmpty()) {
|
2019-03-11 14:54:31 +01:00
|
|
|
*errorMessage = PythonProject::tr("Unable to read \"%1\": The file is empty.")
|
2019-03-01 10:26:59 +01:00
|
|
|
.arg(projectFile.toUserOutput());
|
|
|
|
|
return lines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QJsonParseError error;
|
|
|
|
|
const QJsonDocument doc = QJsonDocument::fromJson(content, &error);
|
|
|
|
|
if (doc.isNull()) {
|
|
|
|
|
const int line = content.left(error.offset).count('\n') + 1;
|
2019-03-11 14:54:31 +01:00
|
|
|
*errorMessage = PythonProject::tr("Unable to parse \"%1\":%2: %3")
|
2019-03-01 10:26:59 +01:00
|
|
|
.arg(projectFile.toUserOutput()).arg(line)
|
|
|
|
|
.arg(error.errorString());
|
|
|
|
|
return lines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QJsonObject obj = doc.object();
|
|
|
|
|
if (obj.contains("files")) {
|
2019-03-27 19:19:25 +01:00
|
|
|
const QJsonValue files = obj.value("files");
|
|
|
|
|
const QJsonArray files_array = files.toArray();
|
2019-03-01 10:26:59 +01:00
|
|
|
QSet<QString> visited;
|
|
|
|
|
for (const auto &file : files_array)
|
|
|
|
|
visited.insert(file.toString());
|
|
|
|
|
|
|
|
|
|
lines.append(visited.toList());
|
2019-01-16 13:04:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lines;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-09 15:19:54 +02:00
|
|
|
bool PythonProject::saveRawFileList(const QStringList &rawFileList)
|
|
|
|
|
{
|
2019-03-28 09:29:30 +01:00
|
|
|
const bool result = saveRawList(rawFileList, projectFilePath().toString());
|
2015-06-09 15:19:54 +02:00
|
|
|
// refresh(PythonProject::Files);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PythonProject::saveRawList(const QStringList &rawList, const QString &fileName)
|
|
|
|
|
{
|
2016-07-18 10:04:42 +02:00
|
|
|
FileChangeBlocker changeGuarg(fileName);
|
2019-03-13 18:22:45 +01:00
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
|
|
// New project file
|
|
|
|
|
if (fileName.endsWith(".pyproject")) {
|
|
|
|
|
FileSaver saver(fileName, QIODevice::ReadOnly | QIODevice::Text);
|
|
|
|
|
if (!saver.hasError()) {
|
|
|
|
|
QString content = QTextStream(saver.file()).readAll();
|
|
|
|
|
if (saver.finalize(ICore::mainWindow())) {
|
|
|
|
|
QString errorMessage;
|
|
|
|
|
result = writePyProjectFile(fileName, content, rawList, &errorMessage);
|
|
|
|
|
if (!errorMessage.isEmpty())
|
|
|
|
|
Core::MessageManager::write(errorMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else { // Old project file
|
|
|
|
|
FileSaver saver(fileName, QIODevice::WriteOnly | QIODevice::Text);
|
|
|
|
|
if (!saver.hasError()) {
|
|
|
|
|
QTextStream stream(saver.file());
|
|
|
|
|
for (const QString &filePath : rawList)
|
|
|
|
|
stream << filePath << '\n';
|
|
|
|
|
saver.setResult(&stream);
|
|
|
|
|
result = saver.finalize(ICore::mainWindow());
|
|
|
|
|
}
|
2015-06-09 15:19:54 +02:00
|
|
|
}
|
2019-03-13 18:22:45 +01:00
|
|
|
|
2015-06-09 15:19:54 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-13 18:22:45 +01:00
|
|
|
bool PythonProject::writePyProjectFile(const QString &fileName, QString &content,
|
|
|
|
|
const QStringList &rawList, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
QFile file(fileName);
|
|
|
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
|
|
|
*errorMessage = PythonProject::tr("Unable to open \"%1\" for reading: %2")
|
|
|
|
|
.arg(fileName, file.errorString());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build list of files with the current rawList for the JSON file
|
|
|
|
|
QString files("[");
|
|
|
|
|
for (const QString &f : rawList)
|
|
|
|
|
if (!f.endsWith(".pyproject"))
|
|
|
|
|
files += QString("\"%1\",").arg(f);
|
|
|
|
|
files = files.left(files.lastIndexOf(',')); // Removing leading comma
|
|
|
|
|
files += ']';
|
|
|
|
|
|
|
|
|
|
// Removing everything inside square parenthesis
|
|
|
|
|
// to replace it with the new list of files for the JSON file.
|
|
|
|
|
QRegularExpression pattern(R"(\[.*\])");
|
|
|
|
|
content.replace(pattern, files);
|
|
|
|
|
file.write(content.toUtf8());
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-09 15:19:54 +02:00
|
|
|
bool PythonProject::addFiles(const QStringList &filePaths)
|
|
|
|
|
{
|
|
|
|
|
QStringList newList = m_rawFileList;
|
|
|
|
|
|
2019-03-28 09:29:30 +01:00
|
|
|
const QDir baseDir(projectDirectory().toString());
|
2019-03-14 08:11:31 +01:00
|
|
|
for (const QString &filePath : filePaths)
|
2015-06-09 15:19:54 +02:00
|
|
|
newList.append(baseDir.relativeFilePath(filePath));
|
|
|
|
|
|
2019-03-13 18:22:45 +01:00
|
|
|
return saveRawFileList(newList);
|
2015-06-09 15:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PythonProject::removeFiles(const QStringList &filePaths)
|
|
|
|
|
{
|
|
|
|
|
QStringList newList = m_rawFileList;
|
|
|
|
|
|
2019-03-14 08:11:31 +01:00
|
|
|
for (const QString &filePath : filePaths) {
|
2019-03-28 09:29:30 +01:00
|
|
|
const QHash<QString, QString>::iterator i = m_rawListEntries.find(filePath);
|
2015-06-09 15:19:54 +02:00
|
|
|
if (i != m_rawListEntries.end())
|
|
|
|
|
newList.removeOne(i.value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return saveRawFileList(newList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PythonProject::setFiles(const QStringList &filePaths)
|
|
|
|
|
{
|
|
|
|
|
QStringList newList;
|
2019-03-28 09:29:30 +01:00
|
|
|
const QDir baseDir(projectDirectory().toString());
|
2019-03-14 08:11:31 +01:00
|
|
|
for (const QString &filePath : filePaths)
|
2015-06-09 15:19:54 +02:00
|
|
|
newList.append(baseDir.relativeFilePath(filePath));
|
|
|
|
|
|
|
|
|
|
return saveRawFileList(newList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PythonProject::renameFile(const QString &filePath, const QString &newFilePath)
|
|
|
|
|
{
|
|
|
|
|
QStringList newList = m_rawFileList;
|
|
|
|
|
|
2019-03-28 09:29:30 +01:00
|
|
|
const QHash<QString, QString>::iterator i = m_rawListEntries.find(filePath);
|
2015-06-09 15:19:54 +02:00
|
|
|
if (i != m_rawListEntries.end()) {
|
2019-03-28 09:29:30 +01:00
|
|
|
const int index = newList.indexOf(i.value());
|
2015-06-09 15:19:54 +02:00
|
|
|
if (index != -1) {
|
2019-03-28 09:29:30 +01:00
|
|
|
const QDir baseDir(projectDirectory().toString());
|
2015-06-09 15:19:54 +02:00
|
|
|
newList.replace(index, baseDir.relativeFilePath(newFilePath));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return saveRawFileList(newList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PythonProject::parseProject()
|
|
|
|
|
{
|
|
|
|
|
m_rawListEntries.clear();
|
2019-01-16 13:04:51 +01:00
|
|
|
const Utils::FileName filePath = projectFilePath();
|
|
|
|
|
// The PySide project file is JSON based
|
2019-03-01 10:26:59 +01:00
|
|
|
if (filePath.endsWith(".pyproject")) {
|
|
|
|
|
QString errorMessage;
|
|
|
|
|
m_rawFileList = readLinesJson(filePath, &errorMessage);
|
|
|
|
|
if (!errorMessage.isEmpty())
|
|
|
|
|
Core::MessageManager::write(errorMessage);
|
|
|
|
|
}
|
2019-01-16 13:04:51 +01:00
|
|
|
// To keep compatibility with PyQt we keep the compatibility with plain
|
|
|
|
|
// text files as project files.
|
|
|
|
|
else if (filePath.endsWith(".pyqtc"))
|
|
|
|
|
m_rawFileList = readLines(filePath);
|
|
|
|
|
|
2015-06-09 15:19:54 +02:00
|
|
|
m_files = processEntries(m_rawFileList, &m_rawListEntries);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Provides displayName relative to project node
|
|
|
|
|
*/
|
2016-10-05 17:59:59 +02:00
|
|
|
class PythonFileNode : public FileNode
|
2015-06-09 15:19:54 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2017-10-18 14:10:10 +02:00
|
|
|
PythonFileNode(const Utils::FileName &filePath, const QString &nodeDisplayName,
|
|
|
|
|
FileType fileType = FileType::Source)
|
2019-02-25 12:08:58 +01:00
|
|
|
: FileNode(filePath, fileType)
|
2015-06-09 15:19:54 +02:00
|
|
|
, m_displayName(nodeDisplayName)
|
|
|
|
|
{}
|
|
|
|
|
|
2015-10-29 16:59:27 +01:00
|
|
|
QString displayName() const override { return m_displayName; }
|
2015-06-09 15:19:54 +02:00
|
|
|
private:
|
|
|
|
|
QString m_displayName;
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-06 15:28:06 +01:00
|
|
|
void PythonProject::refresh(Target *target)
|
2015-06-09 15:19:54 +02:00
|
|
|
{
|
2017-07-13 10:51:15 +02:00
|
|
|
emitParsingStarted();
|
2015-06-09 15:19:54 +02:00
|
|
|
parseProject();
|
|
|
|
|
|
2019-03-28 09:29:30 +01:00
|
|
|
const QDir baseDir(projectDirectory().toString());
|
2018-03-06 15:28:06 +01:00
|
|
|
BuildTargetInfoList appTargets;
|
2018-04-26 14:41:46 +02:00
|
|
|
auto newRoot = std::make_unique<PythonProjectNode>(this);
|
2019-03-27 19:19:25 +01:00
|
|
|
for (const QString &f : qAsConst(m_files)) {
|
2017-03-10 17:30:40 +01:00
|
|
|
const QString displayName = baseDir.relativeFilePath(f);
|
2019-03-28 09:29:30 +01:00
|
|
|
const FileType fileType = f.endsWith(".pyproject") || f.endsWith(".pyqtc") ? FileType::Project
|
|
|
|
|
: FileType::Source;
|
2018-04-26 15:07:56 +02:00
|
|
|
newRoot->addNestedNode(std::make_unique<PythonFileNode>(FileName::fromString(f),
|
|
|
|
|
displayName, fileType));
|
2018-03-06 15:28:06 +01:00
|
|
|
if (fileType == FileType::Source) {
|
|
|
|
|
BuildTargetInfo bti;
|
2018-04-09 12:33:10 +02:00
|
|
|
bti.buildKey = f;
|
2018-03-06 15:28:06 +01:00
|
|
|
bti.targetFilePath = FileName::fromString(f);
|
|
|
|
|
bti.projectFilePath = projectFilePath();
|
|
|
|
|
appTargets.list.append(bti);
|
|
|
|
|
}
|
2017-03-10 17:30:40 +01:00
|
|
|
}
|
2018-04-26 14:41:46 +02:00
|
|
|
setRootProjectNode(std::move(newRoot));
|
2016-10-20 13:18:54 +02:00
|
|
|
|
2018-03-06 15:28:06 +01:00
|
|
|
if (!target)
|
|
|
|
|
target = activeTarget();
|
|
|
|
|
if (target)
|
|
|
|
|
target->setApplicationTargets(appTargets);
|
|
|
|
|
|
2017-07-13 10:51:15 +02:00
|
|
|
emitParsingFinished(true);
|
2015-06-09 15:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Expands environment variables in the given \a string when they are written
|
|
|
|
|
* like $$(VARIABLE).
|
|
|
|
|
*/
|
|
|
|
|
static void expandEnvironmentVariables(const QProcessEnvironment &env, QString &string)
|
|
|
|
|
{
|
|
|
|
|
static QRegExp candidate(QLatin1String("\\$\\$\\((.+)\\)"));
|
|
|
|
|
|
|
|
|
|
int index = candidate.indexIn(string);
|
|
|
|
|
while (index != -1) {
|
|
|
|
|
const QString value = env.value(candidate.cap(1));
|
|
|
|
|
|
|
|
|
|
string.replace(index, candidate.matchedLength(), value);
|
|
|
|
|
index += value.length();
|
|
|
|
|
|
|
|
|
|
index = candidate.indexIn(string, index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Expands environment variables and converts the path from relative to the
|
|
|
|
|
* project to an absolute path.
|
|
|
|
|
*
|
|
|
|
|
* The \a map variable is an optional argument that will map the returned
|
|
|
|
|
* absolute paths back to their original \a entries.
|
|
|
|
|
*/
|
|
|
|
|
QStringList PythonProject::processEntries(const QStringList &paths,
|
|
|
|
|
QHash<QString, QString> *map) const
|
|
|
|
|
{
|
|
|
|
|
const QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
2016-01-08 12:12:27 +01:00
|
|
|
const QDir projectDir(projectDirectory().toString());
|
2015-06-09 15:19:54 +02:00
|
|
|
|
|
|
|
|
QFileInfo fileInfo;
|
|
|
|
|
QStringList absolutePaths;
|
2019-03-14 08:11:31 +01:00
|
|
|
for (const QString &path : paths) {
|
2015-06-09 15:19:54 +02:00
|
|
|
QString trimmedPath = path.trimmed();
|
|
|
|
|
if (trimmedPath.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
expandEnvironmentVariables(env, trimmedPath);
|
|
|
|
|
|
|
|
|
|
trimmedPath = FileName::fromUserInput(trimmedPath).toString();
|
|
|
|
|
|
|
|
|
|
fileInfo.setFile(projectDir, trimmedPath);
|
|
|
|
|
if (fileInfo.exists()) {
|
|
|
|
|
const QString absPath = fileInfo.absoluteFilePath();
|
|
|
|
|
absolutePaths.append(absPath);
|
|
|
|
|
if (map)
|
|
|
|
|
map->insert(absPath, trimmedPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
absolutePaths.removeDuplicates();
|
|
|
|
|
return absolutePaths;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-23 11:23:52 +02:00
|
|
|
Project::RestoreResult PythonProject::fromMap(const QVariantMap &map, QString *errorMessage)
|
2015-06-09 15:19:54 +02:00
|
|
|
{
|
2015-07-23 11:23:52 +02:00
|
|
|
Project::RestoreResult res = Project::fromMap(map, errorMessage);
|
|
|
|
|
if (res == RestoreResult::Ok) {
|
2017-10-18 12:58:59 +02:00
|
|
|
refresh();
|
|
|
|
|
|
2015-07-23 11:23:52 +02:00
|
|
|
Kit *defaultKit = KitManager::defaultKit();
|
|
|
|
|
if (!activeTarget() && defaultKit)
|
2015-11-16 17:10:55 +01:00
|
|
|
addTarget(createTarget(defaultKit));
|
2015-06-09 15:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-23 11:23:52 +02:00
|
|
|
return res;
|
2015-06-09 15:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
2015-10-29 17:12:36 +01:00
|
|
|
PythonProjectNode::PythonProjectNode(PythonProject *project)
|
2016-09-30 23:13:45 +02:00
|
|
|
: ProjectNode(project->projectDirectory())
|
2015-06-09 15:19:54 +02:00
|
|
|
, m_project(project)
|
|
|
|
|
{
|
2015-10-29 17:12:36 +01:00
|
|
|
setDisplayName(project->projectFilePath().toFileInfo().completeBaseName());
|
2019-02-28 16:45:00 +01:00
|
|
|
setAddFileFilter("*.py");
|
2015-06-09 15:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QHash<QString, QStringList> sortFilesIntoPaths(const QString &base, const QSet<QString> &files)
|
|
|
|
|
{
|
|
|
|
|
QHash<QString, QStringList> filesInPath;
|
|
|
|
|
const QDir baseDir(base);
|
|
|
|
|
|
2019-03-14 08:11:31 +01:00
|
|
|
for (const QString &absoluteFileName : files) {
|
2019-03-28 09:29:30 +01:00
|
|
|
const QFileInfo fileInfo(absoluteFileName);
|
|
|
|
|
const FileName absoluteFilePath = FileName::fromString(fileInfo.path());
|
2015-06-09 15:19:54 +02:00
|
|
|
QString relativeFilePath;
|
|
|
|
|
|
|
|
|
|
if (absoluteFilePath.isChildOf(baseDir)) {
|
|
|
|
|
relativeFilePath = absoluteFilePath.relativeChildPath(FileName::fromString(base)).toString();
|
|
|
|
|
} else {
|
|
|
|
|
// 'file' is not part of the project.
|
|
|
|
|
relativeFilePath = baseDir.relativeFilePath(absoluteFilePath.toString());
|
2016-08-03 00:07:44 +02:00
|
|
|
if (relativeFilePath.endsWith('/'))
|
2015-06-09 15:19:54 +02:00
|
|
|
relativeFilePath.chop(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filesInPath[relativeFilePath].append(absoluteFileName);
|
|
|
|
|
}
|
|
|
|
|
return filesInPath;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-28 17:30:58 +03:00
|
|
|
bool PythonProjectNode::supportsAction(ProjectAction action, const Node *node) const
|
|
|
|
|
{
|
2019-02-28 17:19:18 +01:00
|
|
|
if (node->asFileNode()) {
|
2018-09-28 17:30:58 +03:00
|
|
|
return action == ProjectAction::Rename
|
|
|
|
|
|| action == ProjectAction::RemoveFile;
|
2019-02-26 17:44:56 +01:00
|
|
|
}
|
|
|
|
|
if (node->isFolderNodeType() || node->isProjectNodeType()) {
|
2018-09-28 17:30:58 +03:00
|
|
|
return action == ProjectAction::AddNewFile
|
|
|
|
|
|| action == ProjectAction::RemoveFile
|
|
|
|
|
|| action == ProjectAction::AddExistingFile;
|
|
|
|
|
}
|
2019-02-26 17:44:56 +01:00
|
|
|
return ProjectNode::supportsAction(action, node);
|
2018-09-28 17:30:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-09 15:19:54 +02:00
|
|
|
bool PythonProjectNode::renameFile(const QString &filePath, const QString &newFilePath)
|
|
|
|
|
{
|
|
|
|
|
return m_project->renameFile(filePath, newFilePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// PythonEditorPlugin
|
|
|
|
|
//
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2018-02-06 12:46:02 +01:00
|
|
|
class PythonEditorPluginPrivate
|
2013-01-14 23:11:10 +04:00
|
|
|
{
|
2018-02-06 12:46:02 +01:00
|
|
|
public:
|
|
|
|
|
PythonEditorFactory editorFactory;
|
|
|
|
|
PythonRunConfigurationFactory runConfigFactory;
|
2019-03-25 15:31:43 +01:00
|
|
|
SimpleRunWorkerFactory<SimpleTargetRunner, PythonRunConfiguration> runWorkerFactory;
|
2018-02-06 12:46:02 +01:00
|
|
|
};
|
|
|
|
|
|
2013-01-14 23:11:10 +04:00
|
|
|
PythonEditorPlugin::~PythonEditorPlugin()
|
|
|
|
|
{
|
2018-04-26 17:42:07 +02:00
|
|
|
delete d;
|
2013-01-14 23:11:10 +04:00
|
|
|
}
|
|
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
bool PythonEditorPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
2013-01-14 23:11:10 +04:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(arguments)
|
2015-02-04 09:32:46 +01:00
|
|
|
Q_UNUSED(errorMessage)
|
2013-01-14 23:11:10 +04:00
|
|
|
|
2018-04-26 17:42:07 +02:00
|
|
|
d = new PythonEditorPluginPrivate;
|
2017-03-03 18:16:34 +01:00
|
|
|
|
2018-02-06 12:46:02 +01:00
|
|
|
ProjectManager::registerProjectType<PythonProject>(PythonMimeType);
|
2017-06-19 13:27:59 +02:00
|
|
|
|
2016-11-07 18:42:19 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PythonEditorPlugin::extensionsInitialized()
|
|
|
|
|
{
|
2013-01-14 23:11:10 +04:00
|
|
|
// Add MIME overlay icons (these icons displayed at Project dock panel)
|
2019-03-13 18:22:45 +01:00
|
|
|
QString imageFile = creatorTheme()->imageFile(Theme::IconOverlayPro,
|
|
|
|
|
ProjectExplorer::Constants::FILEOVERLAY_PY);
|
|
|
|
|
FileIconProvider::registerIconOverlayForSuffix(imageFile, "py");
|
2018-03-29 15:29:17 +02:00
|
|
|
|
2018-04-06 09:54:14 +02:00
|
|
|
TaskHub::addCategory(PythonErrorTaskCategory, "Python", true);
|
2013-01-14 23:11:10 +04:00
|
|
|
}
|
|
|
|
|
|
2013-08-23 13:41:17 +02:00
|
|
|
} // namespace Internal
|
2013-01-14 23:11:10 +04:00
|
|
|
} // namespace PythonEditor
|
2015-07-23 14:31:43 +03:00
|
|
|
|
|
|
|
|
#include "pythoneditorplugin.moc"
|