diff options
| author | con <[email protected]> | 2008-12-02 12:01:29 +0100 |
|---|---|---|
| committer | con <[email protected]> | 2008-12-02 12:01:29 +0100 |
| commit | 05c35356abc31549c5db6eba31fb608c0365c2a0 (patch) | |
| tree | be044530104267afaff13f8943889cb97f8c8bad /src/plugins/qtscripteditor | |
Initial import
Diffstat (limited to 'src/plugins/qtscripteditor')
| -rw-r--r-- | src/plugins/qtscripteditor/QtScriptEditor.mimetypes.xml | 41 | ||||
| -rw-r--r-- | src/plugins/qtscripteditor/QtScriptEditor.pluginspec | 11 | ||||
| -rw-r--r-- | src/plugins/qtscripteditor/qtscripteditor.cpp | 172 | ||||
| -rw-r--r-- | src/plugins/qtscripteditor/qtscripteditor.h | 99 | ||||
| -rw-r--r-- | src/plugins/qtscripteditor/qtscripteditor.pro | 22 | ||||
| -rw-r--r-- | src/plugins/qtscripteditor/qtscripteditor.qrc | 5 | ||||
| -rw-r--r-- | src/plugins/qtscripteditor/qtscripteditoractionhandler.cpp | 110 | ||||
| -rw-r--r-- | src/plugins/qtscripteditor/qtscripteditoractionhandler.h | 62 | ||||
| -rw-r--r-- | src/plugins/qtscripteditor/qtscripteditorconstants.h | 46 | ||||
| -rw-r--r-- | src/plugins/qtscripteditor/qtscripteditorfactory.cpp | 89 | ||||
| -rw-r--r-- | src/plugins/qtscripteditor/qtscripteditorfactory.h | 84 | ||||
| -rw-r--r-- | src/plugins/qtscripteditor/qtscripteditorplugin.cpp | 145 | ||||
| -rw-r--r-- | src/plugins/qtscripteditor/qtscripteditorplugin.h | 84 | ||||
| -rw-r--r-- | src/plugins/qtscripteditor/qtscripthighlighter.cpp | 110 | ||||
| -rw-r--r-- | src/plugins/qtscripteditor/qtscripthighlighter.h | 67 |
15 files changed, 1147 insertions, 0 deletions
diff --git a/src/plugins/qtscripteditor/QtScriptEditor.mimetypes.xml b/src/plugins/qtscripteditor/QtScriptEditor.mimetypes.xml new file mode 100644 index 00000000000..45f6c0b00b8 --- /dev/null +++ b/src/plugins/qtscripteditor/QtScriptEditor.mimetypes.xml @@ -0,0 +1,41 @@ +<?xml version="1.0"?> +<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'> + <mime-type type="application/javascript"> + <alias type="application/x-javascript"/> + <alias type="text/javascript"/> + <sub-class-of type="text/plain"/> + <comment>Qt Script file</comment> + <comment xml:lang="bg">Програма на JavaScript</comment> + <comment xml:lang="ca">programa JavaScript</comment> + <comment xml:lang="cs">Program v JavaScriptu</comment> + <comment xml:lang="da">JavaScript-program</comment> + <comment xml:lang="de">JavaScript-Programm</comment> + <comment xml:lang="el">πρόγραμμα JavaScript</comment> + <comment xml:lang="eo">JavaScript-programo</comment> + <comment xml:lang="es">programa en JavaScript</comment> + <comment xml:lang="eu">JavaScript programa</comment> + <comment xml:lang="fi">JavaScript-ohjelma</comment> + <comment xml:lang="fr">programme JavaScript</comment> + <comment xml:lang="hu">JavaScript-program</comment> + <comment xml:lang="it">Programma JavaScript</comment> + <comment xml:lang="ja">JavaScript プログラム</comment> + <comment xml:lang="ko">자바스크립트 프로그램</comment> + <comment xml:lang="lt">JavaScript programa</comment> + <comment xml:lang="ms">Program JavaScript</comment> + <comment xml:lang="nb">JavaScript-program</comment> + <comment xml:lang="nl">JavaScript-programma</comment> + <comment xml:lang="nn">JavaScript-program</comment> + <comment xml:lang="pl">Pogram JavaScript</comment> + <comment xml:lang="pt">programa JavaScript</comment> + <comment xml:lang="pt_BR">Programa JavaScript</comment> + <comment xml:lang="ru">программа JavaScript</comment> + <comment xml:lang="sq">program JavaScript</comment> + <comment xml:lang="sr">Јаваскрипт програм</comment> + <comment xml:lang="sv">JavaScript-program</comment> + <comment xml:lang="uk">Програма на мові JavaScript</comment> + <comment xml:lang="vi">Chương trình JavaScript</comment> + <comment xml:lang="zh_CN">JavaScript 程序</comment> + <comment xml:lang="zh_TW">JavaScript 程式</comment> + <glob pattern="*.js"/> + </mime-type> +</mime-info> diff --git a/src/plugins/qtscripteditor/QtScriptEditor.pluginspec b/src/plugins/qtscripteditor/QtScriptEditor.pluginspec new file mode 100644 index 00000000000..3e70cf5568e --- /dev/null +++ b/src/plugins/qtscripteditor/QtScriptEditor.pluginspec @@ -0,0 +1,11 @@ +<plugin name="QtScriptEditor" version="0.9.1" compatVersion="0.9.1"> + <vendor>Nokia Corporation</vendor> + <copyright>(C) 2008 Nokia Corporation</copyright> + <license>Nokia Technology Preview License Agreement</license> + <description>Editor for QtScript.</description> + <url>http://www.trolltech.com/</url> + <dependencyList> + <dependency name="Core" version="0.9.1"/> + <dependency name="TextEditor" version="0.9.1"/> + </dependencyList> +</plugin> diff --git a/src/plugins/qtscripteditor/qtscripteditor.cpp b/src/plugins/qtscripteditor/qtscripteditor.cpp new file mode 100644 index 00000000000..d72fc1f6314 --- /dev/null +++ b/src/plugins/qtscripteditor/qtscripteditor.cpp @@ -0,0 +1,172 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "qtscripteditor.h" +#include "qtscripteditorconstants.h" +#include "qtscripthighlighter.h" +#include "qtscripteditorplugin.h" + +#include <indenter.h> + +#include <coreplugin/icore.h> +#include <coreplugin/actionmanager/actionmanagerinterface.h> +#include <texteditor/basetextdocument.h> +#include <texteditor/fontsettings.h> +#include <texteditor/textblockiterator.h> +#include <texteditor/texteditorconstants.h> + +#include <QtGui/QMenu> + +namespace QtScriptEditor { +namespace Internal { + +ScriptEditorEditable::ScriptEditorEditable(ScriptEditor *editor, const QList<int>& context) + : BaseTextEditorEditable(editor), m_context(context) +{ + +} + +ScriptEditor::ScriptEditor(const Context &context, + Core::ICore *core, + TextEditor::TextEditorActionHandler *ah, + QWidget *parent) : + TextEditor::BaseTextEditor(parent), + m_context(context), + m_core(core), + m_ah(ah) +{ + setParenthesesMatchingEnabled(true); + setMarksVisible(true); + setCodeFoldingVisible(true); + setMimeType(QtScriptEditor::Constants::C_QTSCRIPTEDITOR_MIMETYPE); + + baseTextDocument()->setSyntaxHighlighter(new QtScriptHighlighter); +} + +ScriptEditor::~ScriptEditor() +{ +} + +Core::IEditor *ScriptEditorEditable::duplicate(QWidget *parent) +{ + return qobject_cast<ScriptEditor*>(editor())->duplicate(parent)->editableInterface(); +} + +ScriptEditor *ScriptEditor::duplicate(QWidget *parent) +{ + ScriptEditor *editor = new ScriptEditor(m_context, m_core, m_ah, parent); + editor->duplicateFrom(this); + QtScriptEditorPlugin::initializeEditor(editor); + return editor; +} + +const char *ScriptEditorEditable::kind() const +{ + return QtScriptEditor::Constants::C_QTSCRIPTEDITOR; +} + +ScriptEditor::Context ScriptEditorEditable::context() const +{ + return m_context; +} + +void ScriptEditor::setFontSettings(const TextEditor::FontSettings &fs) +{ + TextEditor::BaseTextEditor::setFontSettings(fs); + QtScriptHighlighter *highlighter = qobject_cast<QtScriptHighlighter*>(baseTextDocument()->syntaxHighlighter()); + if (!highlighter) + return; + + static QVector<QString> categories; + if (categories.isEmpty()) { + categories << QLatin1String(TextEditor::Constants::C_NUMBER) + << QLatin1String(TextEditor::Constants::C_STRING) + << QLatin1String(TextEditor::Constants::C_TYPE) + << QLatin1String(TextEditor::Constants::C_KEYWORD) + << QLatin1String(TextEditor::Constants::C_PREPROCESSOR) + << QLatin1String(TextEditor::Constants::C_LABEL) + << QLatin1String(TextEditor::Constants::C_COMMENT); + } + + highlighter->setFormats(fs.toTextCharFormats(categories)); + highlighter->rehighlight(); +} + +bool ScriptEditor::isElectricCharacter(const QChar &ch) const +{ + if (ch == QLatin1Char('{') || ch == QLatin1Char('}')) + return true; + return false; +} + + // Indent a code line based on previous +template <class Iterator> +static void indentScriptBlock(const TextEditor::TabSettings &ts, + const QTextBlock &block, + const Iterator &programBegin, + const Iterator &programEnd, + QChar typedChar) +{ + typedef typename SharedTools::Indenter<Iterator> Indenter ; + Indenter &indenter = Indenter::instance(); + indenter.setIndentSize(ts.m_tabSize); + const TextEditor::TextBlockIterator current(block); + const int indent = indenter.indentForBottomLine(current, programBegin, + programEnd, typedChar); + ts.indentLine(block, indent); +} + +void ScriptEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar) +{ + const TextEditor::TextBlockIterator begin(doc->begin()); + const TextEditor::TextBlockIterator end(block.next()); + indentScriptBlock(tabSettings(), block, begin, end, typedChar); +} + +void ScriptEditor::contextMenuEvent(QContextMenuEvent *e) +{ + QMenu *menu = createStandardContextMenu(); + + if (Core::IActionContainer *mcontext = m_core->actionManager()->actionContainer(QtScriptEditor::Constants::M_CONTEXT)) { + QMenu *contextMenu = mcontext->menu(); + foreach(QAction *action, contextMenu->actions()) { + menu->addAction(action); + } + } + + menu->exec(e->globalPos()); + delete menu; + +} + +} // namespace Internal +} // namespace QtScriptEditor diff --git a/src/plugins/qtscripteditor/qtscripteditor.h b/src/plugins/qtscripteditor/qtscripteditor.h new file mode 100644 index 00000000000..f005da2af72 --- /dev/null +++ b/src/plugins/qtscripteditor/qtscripteditor.h @@ -0,0 +1,99 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef QTSCRIPTDITORW_H +#define QTSCRIPTDITORW_H + +#include <texteditor/basetexteditor.h> + +namespace Core { + class ICore; +} + +namespace QtScriptEditor { +namespace Internal { + +class QtScriptHighlighter; + +class ScriptEditor; + +class ScriptEditorEditable : public TextEditor::BaseTextEditorEditable +{ +public: + ScriptEditorEditable(ScriptEditor *, const QList<int>&); + QList<int> context() const; + + bool duplicateSupported() const { return true; } + Core::IEditor *duplicate(QWidget *parent); + const char *kind() const; + QToolBar *toolBar() { return 0; } + +private: + QList<int> m_context; +}; + + +class ScriptEditor : public TextEditor::BaseTextEditor +{ + Q_OBJECT + +public: + typedef QList<int> Context; + + ScriptEditor(const Context &context, + Core::ICore *core, + TextEditor::TextEditorActionHandler *ah, + QWidget *parent = 0); + ~ScriptEditor(); + + ScriptEditor *duplicate(QWidget *parent); + +public slots: + virtual void setFontSettings(const TextEditor::FontSettings &); + +protected: + void contextMenuEvent(QContextMenuEvent *e); + TextEditor::BaseTextEditorEditable *createEditableInterface() { return new ScriptEditorEditable(this, m_context); } + +private: + virtual bool isElectricCharacter(const QChar &ch) const; + virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar); + + const Context m_context; + Core::ICore *m_core; + TextEditor::TextEditorActionHandler *m_ah; +}; + +} // namespace Internal +} // namespace QtScriptEditor + +#endif // QTSCRIPTDITORW_H diff --git a/src/plugins/qtscripteditor/qtscripteditor.pro b/src/plugins/qtscripteditor/qtscripteditor.pro new file mode 100644 index 00000000000..1e93663ec4e --- /dev/null +++ b/src/plugins/qtscripteditor/qtscripteditor.pro @@ -0,0 +1,22 @@ +TEMPLATE = lib +TARGET = QtScriptEditor +QT += script + +include(../../qworkbenchplugin.pri) +include(../../plugins/texteditor/texteditor.pri) +include(../../../shared/qscripthighlighter/qscripthighlighter.pri) +include(../../../shared/indenter/indenter.pri) +include(../../plugins/coreplugin/coreplugin.pri) + +HEADERS += qtscripteditor.h \ +qtscripteditorfactory.h \ +qtscripteditorplugin.h \ +qtscripthighlighter.h \ +qtscripteditoractionhandler.h + +SOURCES += qtscripteditor.cpp \ +qtscripteditorfactory.cpp \ +qtscripteditorplugin.cpp \ +qtscripthighlighter.cpp \ +qtscripteditoractionhandler.cpp +RESOURCES += qtscripteditor.qrc diff --git a/src/plugins/qtscripteditor/qtscripteditor.qrc b/src/plugins/qtscripteditor/qtscripteditor.qrc new file mode 100644 index 00000000000..1e987b5a4a2 --- /dev/null +++ b/src/plugins/qtscripteditor/qtscripteditor.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/qtscripteditor" > + <file>QtScriptEditor.mimetypes.xml</file> + </qresource> +</RCC> diff --git a/src/plugins/qtscripteditor/qtscripteditoractionhandler.cpp b/src/plugins/qtscripteditor/qtscripteditoractionhandler.cpp new file mode 100644 index 00000000000..9fd78777c14 --- /dev/null +++ b/src/plugins/qtscripteditor/qtscripteditoractionhandler.cpp @@ -0,0 +1,110 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "qtscripteditoractionhandler.h" +#include "qtscripteditorconstants.h" +#include "qtscripteditor.h" + +#include <coreplugin/actionmanager/actionmanagerinterface.h> +#include <coreplugin/scriptmanager/scriptmanagerinterface.h> + +#include <QtGui/QAction> +#include <QtGui/QMessageBox> +#include <QtGui/QMainWindow> +#include <QtCore/QDebug> + +static QAction *actionFromId(Core::ICore *core, const QString &id) +{ + Core::ICommand *cmd = core->actionManager()->command(id); + if (!cmd) + return 0; + return cmd->action(); +} + +namespace QtScriptEditor { +namespace Internal { + +QtScriptEditorActionHandler::QtScriptEditorActionHandler(Core::ICore *core) : + TextEditor::TextEditorActionHandler(core, + QLatin1String(QtScriptEditor::Constants::C_QTSCRIPTEDITOR), + Format), + m_runAction(0) +{ +} + +void QtScriptEditorActionHandler::createActions() +{ + TextEditor::TextEditorActionHandler::createActions(); + m_runAction = actionFromId(core(), QLatin1String(QtScriptEditor::Constants::RUN)); + connect(m_runAction, SIGNAL(triggered()), this, SLOT(run())); +} + + +void QtScriptEditorActionHandler::updateActions(UpdateMode um) +{ + TextEditor::TextEditorActionHandler::updateActions(um); + if (m_runAction) + m_runAction->setEnabled(um != NoEditor); +} + +void QtScriptEditorActionHandler::run() +{ + typedef Core::ScriptManagerInterface::Stack Stack; + if (!currentEditor()) + return; + + const QString script = currentEditor()->toPlainText(); + + // run + Stack errorStack; + QString errorMessage; + if (core()->scriptManager()->runScript(script, &errorMessage, &errorStack)) + return; + + // try to find a suitable error line in the stack + // ignoring 0 and other files (todo: open other files?) + int errorLineNumber = 0; + if (const int numFrames = errorStack.size()) { + for (int f = 0; f < numFrames; f++) { + if (errorStack[f].lineNumber && errorStack[f].fileName.isEmpty()) { + errorLineNumber = errorStack[f].lineNumber; + break; + } + } + } + if (errorLineNumber) + currentEditor()->gotoLine(errorLineNumber); + QMessageBox::critical(core()->mainWindow(), tr("Qt Script Error"), errorMessage); +} + +} // namespace Internal +} // namespace QtScriptEditor diff --git a/src/plugins/qtscripteditor/qtscripteditoractionhandler.h b/src/plugins/qtscripteditor/qtscripteditoractionhandler.h new file mode 100644 index 00000000000..65073540d8e --- /dev/null +++ b/src/plugins/qtscripteditor/qtscripteditoractionhandler.h @@ -0,0 +1,62 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef QTSCRIPTDITORACTIONHANDLER_H +#define QTSCRIPTDITORACTIONHANDLER_H + +#include <texteditor/texteditoractionhandler.h> + +namespace QtScriptEditor { +namespace Internal { + +class QtScriptEditorActionHandler : public TextEditor::TextEditorActionHandler +{ + Q_OBJECT + +public: + QtScriptEditorActionHandler(Core::ICore *core); + +private: + virtual void createActions(); + virtual void updateActions(UpdateMode um); + +private slots: + void run(); + +private: + QAction *m_runAction; +}; + +} // namespace Internal +} // namespace QtScriptEditor + +#endif // QTSCRIPTDITORACTIONHANDLER_H diff --git a/src/plugins/qtscripteditor/qtscripteditorconstants.h b/src/plugins/qtscripteditor/qtscripteditorconstants.h new file mode 100644 index 00000000000..c26384cf46f --- /dev/null +++ b/src/plugins/qtscripteditor/qtscripteditorconstants.h @@ -0,0 +1,46 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef QTSCRIPTEDITOR_CONSTANTS_H +#define QTSCRIPTEDITOR_CONSTANTS_H + +namespace QtScriptEditor { +namespace Constants { +const char * const M_CONTEXT = "Qt Script Editor.ContextMenu"; +const char * const RUN = "Qt Script Editor.Run"; +const char * const RUN_SEP = "Qt Script Editor.Run.Separator"; +const char * const C_QTSCRIPTEDITOR = "Qt Script Editor"; +const char * const C_QTSCRIPTEDITOR_MIMETYPE = "application/javascript"; +} +} + +#endif //QTSCRIPTEDITOR_CONSTANTS_H diff --git a/src/plugins/qtscripteditor/qtscripteditorfactory.cpp b/src/plugins/qtscripteditor/qtscripteditorfactory.cpp new file mode 100644 index 00000000000..bf5c12dcfeb --- /dev/null +++ b/src/plugins/qtscripteditor/qtscripteditorfactory.cpp @@ -0,0 +1,89 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "qtscripteditorfactory.h" +#include "qtscripteditor.h" +#include "qtscripteditoractionhandler.h" +#include "qtscripteditorconstants.h" +#include "qtscripteditorplugin.h" + +#include <coreplugin/editormanager/editormanager.h> + +#include <QtCore/QFileInfo> +#include <QtCore/qdebug.h> + +using namespace QtScriptEditor::Internal; +using namespace QtScriptEditor::Constants; + +QtScriptEditorFactory::QtScriptEditorFactory(Core::ICore *core, + const Context &context, + QObject *parent) : + Core::IEditorFactory(parent), + m_kind(QLatin1String(C_QTSCRIPTEDITOR)), + m_mimeTypes(QLatin1String(QtScriptEditor::Constants::C_QTSCRIPTEDITOR_MIMETYPE)), + m_context(context), + m_core(core), + m_actionHandler(new QtScriptEditorActionHandler(core)) +{ +} + +QtScriptEditorFactory::~QtScriptEditorFactory() +{ + delete m_actionHandler; +} + +QString QtScriptEditorFactory::kind() const +{ + return m_kind; +} + +Core::IFile *QtScriptEditorFactory::open(const QString &fileName) +{ + Core::IEditor *iface = m_core->editorManager()->openEditor(fileName, kind()); + if (!iface) { + qWarning() << "QtScriptEditorFactory::open: openEditor failed for " << fileName; + return 0; + } + return iface->file(); +} + +Core::IEditor *QtScriptEditorFactory::createEditor(QWidget *parent) +{ + ScriptEditor *rc = new ScriptEditor(m_context, m_core, m_actionHandler, parent); + QtScriptEditorPlugin::initializeEditor(rc); + return rc->editableInterface(); +} + +QStringList QtScriptEditorFactory::mimeTypes() const +{ + return m_mimeTypes; +} diff --git a/src/plugins/qtscripteditor/qtscripteditorfactory.h b/src/plugins/qtscripteditor/qtscripteditorfactory.h new file mode 100644 index 00000000000..600277d2c0a --- /dev/null +++ b/src/plugins/qtscripteditor/qtscripteditorfactory.h @@ -0,0 +1,84 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef RQTSCRIPTEDITORFACTORY_H +#define RQTSCRIPTEDITORFACTORY_H + +#include <extensionsystem/ExtensionSystemInterfaces> +#include <coreplugin/editormanager/ieditorfactory.h> + +#include <QtCore/QStringList> + +namespace Core { +class ICore; +} + +namespace TextEditor { +class TextEditorActionHandler; +} + +namespace QtScriptEditor { +namespace Internal { + +class QtScriptEditorActionHandler; + +class QtScriptEditorFactory : public Core::IEditorFactory +{ + Q_OBJECT + +public: + typedef QList<int> Context; + + QtScriptEditorFactory(Core::ICore *core, + const Context &context, + QObject *parent); + ~QtScriptEditorFactory(); + + virtual QStringList mimeTypes() const; + //EditorFactory + QString kind() const; + Core::IFile *open(const QString &fileName); + Core::IEditor *createEditor(QWidget *parent); + +private: + const QString m_kind; + const QStringList m_mimeTypes; + const Context m_context; + + Core::ICore *m_core; + TextEditor::TextEditorActionHandler *m_actionHandler; +}; + +} // namespace Internal +} // namespace QtScriptEditor + +#endif // RQTSCRIPTEDITORFACTORY_H diff --git a/src/plugins/qtscripteditor/qtscripteditorplugin.cpp b/src/plugins/qtscripteditor/qtscripteditorplugin.cpp new file mode 100644 index 00000000000..7216a77f350 --- /dev/null +++ b/src/plugins/qtscripteditor/qtscripteditorplugin.cpp @@ -0,0 +1,145 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "qtscripteditorplugin.h" +#include "qtscripteditorconstants.h" +#include "qtscripteditorfactory.h" +#include "qtscripteditor.h" +#include "qscripthighlighter.h" + +#include <coreplugin/icore.h> +#include <coreplugin/coreconstants.h> +#include <coreplugin/mimedatabase.h> +#include <coreplugin/uniqueidmanager.h> +#include <coreplugin/actionmanager/actionmanagerinterface.h> +#include <texteditor/fontsettings.h> +#include <texteditor/storagesettings.h> +#include <texteditor/texteditorconstants.h> +#include <texteditor/texteditorsettings.h> +#include <texteditor/textfilewizard.h> + +#include <QtCore/qplugin.h> +#include <QtCore/QDebug> +#include <QtGui/QAction> + +using namespace QtScriptEditor::Internal; +using namespace QtScriptEditor::Constants; + +QtScriptEditorPlugin *QtScriptEditorPlugin::m_instance = 0; + +QtScriptEditorPlugin::QtScriptEditorPlugin() : + m_wizard(0), + m_editor(0) +{ + m_instance = this; +} + +QtScriptEditorPlugin::~QtScriptEditorPlugin() +{ + removeObject(m_editor); + removeObject(m_wizard); + m_instance = 0; +} + +bool QtScriptEditorPlugin::initialize(const QStringList & /*arguments*/, QString *error_message) +{ + typedef SharedTools::QScriptHighlighter QScriptHighlighter; + + Core::ICore *core = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>(); + if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/qtscripteditor/QtScriptEditor.mimetypes.xml"), error_message)) + return false; + m_scriptcontext << core->uniqueIDManager()->uniqueIdentifier(QtScriptEditor::Constants::C_QTSCRIPTEDITOR); + m_context = m_scriptcontext; + m_context << core->uniqueIDManager()->uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR); + + registerActions(core); + + m_editor = new QtScriptEditorFactory(core, m_context, this); + addObject(m_editor); + + Core::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard); + wizardParameters.setDescription(tr("Qt Script file")); + wizardParameters.setName(tr("Qt Script file")); + wizardParameters.setCategory(QLatin1String("Qt")); + wizardParameters.setTrCategory(tr("Qt")); + m_wizard = new TextEditor::TextFileWizard(QLatin1String(QtScriptEditor::Constants::C_QTSCRIPTEDITOR_MIMETYPE), + QLatin1String(QtScriptEditor::Constants::C_QTSCRIPTEDITOR), + QLatin1String("qtscript$"), + wizardParameters, core, this); + addObject(m_wizard); + + error_message->clear(); + return true; +} + +void QtScriptEditorPlugin::extensionsInitialized() +{ +} + +void QtScriptEditorPlugin::initializeEditor(QtScriptEditor::Internal::ScriptEditor *editor) +{ + Q_ASSERT(m_instance); + + TextEditor::TextEditorSettings *settings = TextEditor::TextEditorSettings::instance(); + connect(settings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)), + editor, SLOT(setFontSettings(TextEditor::FontSettings))); + connect(settings, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)), + editor, SLOT(setTabSettings(TextEditor::TabSettings))); + connect(settings, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)), + editor, SLOT(setStorageSettings(TextEditor::StorageSettings))); + connect(settings, SIGNAL(displaySettingsChanged(TextEditor::DisplaySettings)), + editor, SLOT(setDisplaySettings(TextEditor::DisplaySettings))); + + // tab settings rely on font settings + editor->setFontSettings(settings->fontSettings()); + editor->setTabSettings(settings->tabSettings()); + editor->setStorageSettings(settings->storageSettings()); + editor->setDisplaySettings(settings->displaySettings()); +} + +void QtScriptEditorPlugin::registerActions(Core::ICore *core) +{ + Core::ActionManagerInterface *am = core->actionManager(); + Core::IActionContainer *mcontext = am->createMenu(QtScriptEditor::Constants::M_CONTEXT); + + QAction *action = new QAction(this); + action->setSeparator(true); + Core::ICommand *cmd = am->registerAction(action, QtScriptEditor::Constants::RUN_SEP, m_scriptcontext); + mcontext->addAction(cmd, Core::Constants::G_DEFAULT_THREE); + + action = new QAction(tr("Run"), this); + cmd = am->registerAction(action, QtScriptEditor::Constants::RUN, m_scriptcontext); + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+R"))); + mcontext->addAction(cmd, Core::Constants::G_DEFAULT_THREE); +} + +Q_EXPORT_PLUGIN(QtScriptEditorPlugin) diff --git a/src/plugins/qtscripteditor/qtscripteditorplugin.h b/src/plugins/qtscripteditor/qtscripteditorplugin.h new file mode 100644 index 00000000000..449f8263f15 --- /dev/null +++ b/src/plugins/qtscripteditor/qtscripteditorplugin.h @@ -0,0 +1,84 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef QTSCRIPTEDITORPLUGIN_H +#define QTSCRIPTEDITORPLUGIN_H + +#include <extensionsystem/iplugin.h> + +namespace Core { +class ICore; +} + +namespace TextEditor { +class FontSettingsPage; +class TextFileWizard; +} + +namespace QtScriptEditor { +namespace Internal { + +class QtScriptWizard; +class QtScriptEditorFactory; +class ScriptEditor; + +class QtScriptEditorPlugin : public ExtensionSystem::IPlugin +{ + Q_OBJECT + +public: + QtScriptEditorPlugin(); + virtual ~QtScriptEditorPlugin(); + + //Plugin + bool initialize(const QStringList &arguments, QString *error_message = 0); + void extensionsInitialized(); + + static void initializeEditor(ScriptEditor *editor); + +private: + void registerActions(Core::ICore *core); + + static QtScriptEditorPlugin *m_instance; + + typedef QList<int> Context; + Context m_context; + Context m_scriptcontext; + + TextEditor::TextFileWizard *m_wizard; + QtScriptEditorFactory *m_editor; +}; + +} // namespace Internal +} // namespace QtScriptEditor + +#endif // QTSCRIPTEDITORPLUGIN_H diff --git a/src/plugins/qtscripteditor/qtscripthighlighter.cpp b/src/plugins/qtscripteditor/qtscripthighlighter.cpp new file mode 100644 index 00000000000..16d8f114728 --- /dev/null +++ b/src/plugins/qtscripteditor/qtscripthighlighter.cpp @@ -0,0 +1,110 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "qtscripthighlighter.h" + +namespace QtScriptEditor { +namespace Internal { + +QtScriptHighlighter::QtScriptHighlighter(QTextDocument *parent) : + SharedTools::QScriptHighlighter(parent) +{ + m_currentBlockParentheses.reserve(20); + m_braceDepth = 0; +} + +int QtScriptHighlighter::onBlockStart() +{ + m_currentBlockParentheses.clear(); + m_braceDepth = 0; + + int state = 0; + int previousState = previousBlockState(); + if (previousState != -1) { + state = previousState & 0xff; + m_braceDepth = previousState >> 8; + } + + return state; +} + +void QtScriptHighlighter::onOpeningParenthesis(QChar parenthesis, int pos) +{ + if (parenthesis == QLatin1Char('{')) + ++m_braceDepth; + m_currentBlockParentheses.push_back(Parenthesis(Parenthesis::Opened, parenthesis, pos)); +} + +void QtScriptHighlighter::onClosingParenthesis(QChar parenthesis, int pos) +{ + if (parenthesis == QLatin1Char('}')) + --m_braceDepth; + m_currentBlockParentheses.push_back(Parenthesis(Parenthesis::Closed, parenthesis, pos)); +} + +void QtScriptHighlighter::onBlockEnd(int state, int firstNonSpace) +{ + typedef TextEditor::TextBlockUserData TextEditorBlockData; + + setCurrentBlockState((m_braceDepth << 8) | state); + + // Set block data parentheses. Force creation of block data unless empty + TextEditorBlockData *blockData = 0; + + if (QTextBlockUserData *userData = currentBlockUserData()) + blockData = static_cast<TextEditorBlockData *>(userData); + + if (!blockData && !m_currentBlockParentheses.empty()) { + blockData = new TextEditorBlockData; + setCurrentBlockUserData(blockData); + } + if (blockData) { + blockData->setParentheses(m_currentBlockParentheses); + blockData->setClosingCollapseMode(TextEditor::TextBlockUserData::NoClosingCollapse); + blockData->setCollapseMode(TextEditor::TextBlockUserData::NoCollapse); + } + if (!m_currentBlockParentheses.isEmpty()) { + Q_ASSERT(blockData); + int collapse = Parenthesis::collapseAtPos(m_currentBlockParentheses); + if (collapse >= 0) { + if (collapse == firstNonSpace) + blockData->setCollapseMode(TextEditor::TextBlockUserData::CollapseThis); + else + blockData->setCollapseMode(TextEditor::TextBlockUserData::CollapseAfter); + } + if (Parenthesis::hasClosingCollapse(m_currentBlockParentheses)) + blockData->setClosingCollapseMode(TextEditor::TextBlockUserData::NoClosingCollapse); + } +} + +} // namespace Internal +} // namespace QtScriptEditor diff --git a/src/plugins/qtscripteditor/qtscripthighlighter.h b/src/plugins/qtscripteditor/qtscripthighlighter.h new file mode 100644 index 00000000000..2e9f23d144d --- /dev/null +++ b/src/plugins/qtscripteditor/qtscripthighlighter.h @@ -0,0 +1,67 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef QTSCRIPTSYNTAXHIGHLIGHTER_H +#define QTSCRIPTSYNTAXHIGHLIGHTER_H + +#include "qscripthighlighter.h" +#include <texteditor/basetexteditor.h> + +namespace QtScriptEditor { +namespace Internal { + +// Highlighter for Scripts that stores +// the parentheses encountered in the block data +// for parentheses matching to work. + +class QtScriptHighlighter : public SharedTools::QScriptHighlighter +{ + Q_OBJECT +public: + QtScriptHighlighter(QTextDocument *parent = 0); + +private: + virtual int onBlockStart(); + virtual void onOpeningParenthesis(QChar parenthesis, int pos); + virtual void onClosingParenthesis(QChar parenthesis, int pos); + virtual void onBlockEnd(int state, int firstNonSpace); + + typedef TextEditor::Parenthesis Parenthesis; + typedef TextEditor::Parentheses Parentheses; + Parentheses m_currentBlockParentheses; + int m_braceDepth; +}; + +} // namespace Internal +} // namespace QtScriptEditor + +#endif // QTSCRIPTSYNTAXHIGHLIGHTER_H |
