Commit 04b9d761 authored by Sergey Shambir's avatar Sergey Shambir Committed by hjk

Added PythonEditor plugin

Contains lexical highlighter, indenter and file wizard.
Icon loaded from theme, if possible.
Class wizard will be added later since it needs to extend libUtils.

Change-Id: If723867c01e9be83371424e406d116805c88c2b0
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent e5b304c8
......@@ -60,6 +60,7 @@ Project {
"src/plugins/perforce/perforce.qbs",
"src/plugins/projectexplorer/projectexplorer.qbs",
"src/plugins/qbsprojectmanager/qbsprojectmanager.qbs",
"src/plugins/pythoneditor/pythoneditor.qbs",
// "src/plugins/qmldesigner/qmldesigner.qbs",
"src/plugins/qmljseditor/qmljseditor.qbs",
"src/plugins/qmljstools/qmljstools.qbs",
......
......@@ -32,6 +32,7 @@ SUBDIRS = plugin_coreplugin \
plugin_genericprojectmanager \
plugin_qmljseditor \
plugin_glsleditor \
plugin_pythoneditor \
plugin_mercurial \
plugin_bazaar \
plugin_classview \
......@@ -350,3 +351,8 @@ plugin_clearcase.subdir = clearcase
plugin_clearcase.depends = plugin_vcsbase
plugin_clearcase.depends += plugin_projectexplorer
plugin_clearcase.depends += plugin_coreplugin
plugin_pythoneditor.subdir = pythoneditor
plugin_pythoneditor.depends = plugin_coreplugin
plugin_pythoneditor.depends += plugin_cpptools
plugin_pythoneditor.depends += plugin_texteditor
<plugin name=\"PythonEditor\" version=\"$$QTCREATOR_VERSION\" compatVersion=\"$$QTCREATOR_VERSION\">
<vendor>Digia Plc</vendor>
<copyright>(C) 2013 Digia Plc</copyright>
<license>
Commercial Usage
Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Digia.
GNU Lesser General Public License Usage
Alternatively, this plugin may be used under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. Please review the following information to ensure the GNU Lesser General Public License version 2.1 requirements will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
</license>
<category>Python</category>
<description>Editor and file creation wizards for Python. Example plugin for QtCreator API demonstration.</description>
<url>http://www.qt-project.org</url>
<dependencyList>
<dependency name=\"Core\" version=\"$$QTCREATOR_VERSION\"/>
<dependency name=\"TextEditor\" version=\"$$QTCREATOR_VERSION\"/>
<dependency name=\"CppTools\" version=\"$$QTCREATOR_VERSION\"/>
</dependencyList>
</plugin>
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
/**
\class PyEditor::Editor implements interface Core::IEditor
This editor makes possible to edit Python source files
*/
#include "pythoneditorconstants.h"
#include "pythoneditorplugin.h"
#include "pythoneditorwidget.h"
#include "pythoneditor.h"
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/texteditorsettings.h>
#include <QFileInfo>
namespace PythonEditor {
PythonEditor::PythonEditor(EditorWidget *editorWidget)
:BaseTextEditor(editorWidget)
{
setContext(Core::Context(Constants::C_PYTHONEDITOR_ID,
TextEditor::Constants::C_TEXTEDITOR));
}
PythonEditor::~PythonEditor()
{
}
Core::IEditor *PythonEditor::duplicate(QWidget *parent)
{
EditorWidget *widget = new EditorWidget(parent);
widget->duplicateFrom(editorWidget());
PythonEditorPlugin::initializeEditor(widget);
return widget->editor();
}
/**
* @returns Unique editor class identifier, that is Constants::C_PYTHONEDITOR_ID
*/
Core::Id PythonEditor::id() const
{
return Core::Id(Constants::C_PYTHONEDITOR_ID);
}
Core::Id PythonEditor::preferredModeType() const
{
return Core::Id();
}
bool PythonEditor::open(QString *errorString,
const QString &fileName,
const QString &realFileName)
{
Core::MimeType mimeType;
Core::MimeDatabase *mimeDB = Core::ICore::instance()->mimeDatabase();
mimeType = mimeDB->findByFile(QFileInfo(fileName));
editorWidget()->setMimeType(mimeType.type());
bool status = TextEditor::BaseTextEditor::open(errorString,
fileName,
realFileName);
return status;
}
} // namespace PythonEditor
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef PYTHONEDITOR_EDITOR_H
#define PYTHONEDITOR_EDITOR_H
#include "pythoneditor_global.h"
#include <texteditor/basetexteditor.h>
namespace PythonEditor {
class EditorWidget;
class PYEDITOR_EXPORT PythonEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
explicit PythonEditor(EditorWidget *editorWidget);
virtual ~PythonEditor();
bool duplicateSupported() const { return true; }
Core::IEditor *duplicate(QWidget *parent);
Core::Id id() const;
bool isTemporary() const { return false; }
Core::Id preferredModeType() const;
/**
Opens file for editing, actual work performed by base class
*/
bool open(QString *errorString,
const QString &fileName,
const QString &realFileName);
};
} // namespace PythonEditor
#endif // PYTHONEDITOR_EDITOR_H
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="text/x-python">
<sub-class-of type="text/plain"/>
<comment>Python Source File</comment>
<glob pattern="*.py"/>
<glob pattern="*.pyw"/>
<glob pattern="*.wsgi"/>
</mime-type>
</mime-info>
TEMPLATE = lib
TARGET = PythonEditor
include(../../qtcreatorplugin.pri)
# dependencies
include(../../plugins/coreplugin/coreplugin.pri)
include(../../plugins/texteditor/texteditor.pri)
include(../../plugins/cpptools/cpptools.pri)
DEFINES += \
PYEDITOR_LIBRARY
OTHER_FILES += PythonEditor.pluginspec.in \
pythoneditor.mimetypes.xml
RESOURCES += \
pythoneditorplugin.qrc
HEADERS += \
pythoneditor_global.h \
pythoneditorplugin.h \
pythoneditorfactory.h \
pythoneditor.h \
pythoneditorwidget.h \
pythoneditorconstants.h \
wizard/pythonfilewizard.h \
tools/pythonhighlighter.h \
tools/pythonindenter.h \
tools/lexical/pythonformattoken.h \
tools/lexical/pythonscanner.h \
tools/lexical/sourcecodestream.h
SOURCES += \
pythoneditorplugin.cpp \
pythoneditorfactory.cpp \
pythoneditor.cpp \
pythoneditorwidget.cpp \
wizard/pythonfilewizard.cpp \
tools/pythonhighlighter.cpp \
tools/pythonindenter.cpp \
tools/lexical/pythonscanner.cpp
import qbs.base 1.0
import "../QtcPlugin.qbs" as QtcPlugin
QtcPlugin {
name: "PythonEditor"
Depends { name: "Core" }
Depends { name: "TextEditor" }
Depends { name: "CppTools" }
Depends { name: "cpp" }
cpp.defines: base.concat(["PYEDITOR_LIBRARY", "QT_CREATOR"])
files: [
"pythoneditor.cpp",
"pythoneditor.h",
"pythoneditor.mimetypes.xml",
"pythoneditor_global.h",
"pythoneditorconstants.h",
"pythoneditorfactory.cpp",
"pythoneditorfactory.h",
"pythoneditorfeatures.h",
"pythoneditorplugin.cpp",
"pythoneditorplugin.h",
"pythoneditorplugin.qrc",
"pythoneditorwidget.cpp",
"pythoneditorwidget.h",
"tools/lexical/sourcecodestream.h",
"tools/lexical/pythonscanner.h",
"tools/lexical/pythonformattoken.h",
"tools/lexical/pythonscanner.cpp",
"tools/pythonhighlighter.h",
"tools/pythonindenter.cpp",
"tools/pythonhighlighter.cpp",
"tools/pythonindenter.h",
"wizard/pythonfilewizard.h",
"wizard/pythonfilewizard.cpp",
]
}
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef PYTHONEDITOR_GLOBAL_H
#define PYTHONEDITOR_GLOBAL_H
#include <QtGlobal>
#if defined(PYEDITOR_LIBRARY)
# define PYEDITOR_EXPORT Q_DECL_EXPORT
#else
# define PYEDITOR_EXPORT Q_DECL_IMPORT
#endif
#endif // PYTHONEDITOR_GLOBAL_H
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef PYTHONEDITOR_CONSTANTS_H
#define PYTHONEDITOR_CONSTANTS_H
#include <QtGlobal>
namespace PythonEditor {
namespace Constants {
const char C_PYTHONEDITOR_ID[] = "PythonEditor.PythonEditor";
const char C_EDITOR_DISPLAY_NAME[] =
QT_TRANSLATE_NOOP("OpenWith::Editors", "Python Editor");
/*******************************************************************************
* File creation wizard
******************************************************************************/
const char C_PY_WIZARD_CATEGORY[] = "U.Python";
const char C_PY_EXTENSION[] = ".py";
const char C_PY_DISPLAY_CATEGORY[] = "Python";
// source
const char C_PY_SOURCE_WIZARD_ID[] = "P.PySource";
const char C_PY_SOURCE_CONTENT[] =
"#!/usr/bin/env python\n"
"# -*- coding: utf-8 -*-\n"
"\n";
const char EN_PY_SOURCE_DISPLAY_NAME[] = "Python source file";
const char EN_PY_SOURCE_DESCRIPTION[] =
"Creates an empty python script with utf-8 charset";
// class
const char C_PY_CLASS_WIZARD_ID[] = "P.PyClass";
const char EN_PY_CLASS_DISPLAY_NAME[] = "Python class";
const char EN_PY_CLASS_DESCRIPTION[] =
"Creates new Python class";
// For future: boost binding
const char C_PY_CPPMODULE_WIZARD_ID[] = "F.PyCppModule";
const char EN_PY_CPPMODULE_DISPLAY_NAME[] = "C++ module for Python";
const char EN_PY_CPPMODULE_DESCRIPTION[] =
"Creates C++/boost file with bindings for python";
/*******************************************************************************
* MIME type
******************************************************************************/
const char C_PY_MIMETYPE[] = "text/x-python";
const char RC_PY_MIME_XML[] = ":/pythoneditor/pythoneditor.mimetypes.xml";
const char C_PY_MIME_ICON[] = "text-x-python";
} // namespace Constants
} // namespace PythonEditor
#endif // PYTHONEDITOR_CONSTANTS_H
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "pythoneditorconstants.h"
#include "pythoneditorwidget.h"
#include "pythoneditorplugin.h"
#include "pythoneditorfactory.h"
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <texteditor/texteditorsettings.h>
#include <QDebug>
namespace PythonEditor {
EditorFactory::EditorFactory(QObject *parent)
: Core::IEditorFactory(parent)
{
m_mimeTypes << QLatin1String(Constants::C_PY_MIMETYPE);
}
Core::Id EditorFactory::id() const
{
return Constants::C_PYTHONEDITOR_ID;
}
QString EditorFactory::displayName() const
{
return tr(Constants::C_EDITOR_DISPLAY_NAME);
}
Core::IDocument *EditorFactory::open(const QString &fileName)
{
Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
if (!iface) {
qWarning() << "CEditorFactory::open: openEditor failed for " << fileName;
return 0;
}
return iface->document();
}
Core::IEditor *EditorFactory::createEditor(QWidget *parent)
{
EditorWidget *widget = new EditorWidget(parent);
PythonEditorPlugin::initializeEditor(widget);
return widget->editor();
}
QStringList EditorFactory::mimeTypes() const
{
return m_mimeTypes;
}
} // namespace PythonEditor
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef PYTHONEDITOR_EDITORFACTORY_H
#define PYTHONEDITOR_EDITORFACTORY_H
#include "pythoneditor_global.h"
#include <coreplugin/editormanager/ieditorfactory.h>
#include <QStringList>
namespace PythonEditor {
class PYEDITOR_EXPORT EditorFactory : public Core::IEditorFactory
{
Q_OBJECT
public:
EditorFactory(QObject *parent);
/**
Returns MIME types handled by editor
*/
QStringList mimeTypes() const;
/**
Unique editor class identifier, see Constants::C_PYEDITOR_ID
*/
Core::Id id() const;
QString displayName() const;
/**
Opens file in new editor
*/
Core::IDocument *open(const QString &fileName);
/**
Creates and initializes new editor widget
*/
Core::IEditor *createEditor(QWidget *parent);
private:
QStringList m_mimeTypes;
};
} // namespace PythonEditor
#endif // PYTHONEDITOR_EDITORFACTORY_H
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "pythoneditorplugin.h"
#include "pythoneditorconstants.h"
#include "wizard/pythonfilewizard.h"
#include "pythoneditorwidget.h"
#include "pythoneditorfactory.h"
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/fileiconprovider.h>
#include <coreplugin/id.h>
#include <coreplugin/editormanager/editormanager.h>
#include <extensionsystem/pluginmanager.h>