1. rivo
  2. qt-creator-scheme-plugin

Commits

rivo  committed eefb411

qtcreator 3.0.1

  • Participants
  • Parent commits 1b2727f
  • Branches qtcreator-3

Comments (0)

Files changed (9)

File chicken.pluginspec.in

View file
  • Ignore whitespace
-<plugin name=\"chicken\" version=\"0.0.1\" compatVersion=\"0.0.1\">
+<plugin name=\"chicken\" version=\"0.0.2\" compatVersion=\"0.0.2\">
     <vendor>CHICKEN</vendor>
     <copyright>(C) CHICKEN</copyright>
     <license>Put your license text here</license>
-    <description>Put a short description of your plugin here</description>
-    <url>http://www.mycompany.com</url>
-    <dependencyList>
-        <dependency name=\"Core\" version=\"$$QTCREATOR_VERSION\"/>
-    </dependencyList>
+    <category>Scheme</category>
+    <description>Editor for CHICKEN Scheme</description>
+    <url>http://www.call-cc.org</url>
+    $$dependencyList
 </plugin>
-

File chicken.pro

View file
  • Ignore whitespace
 include(../../qtcreatorplugin.pri)
-include(chicken_dependencies.pri)
 
-TARGET = chicken
-TEMPLATE = lib
+DEFINES += \
+	CHICKEN_LIBRARY
 
-DEFINES += CHICKEN_LIBRARY
-
-# chicken files
-
-SOURCES += chickenplugin.cpp \
-    chickeneditor.cpp \
-    chickenindenter.cpp \
-    chickenhighlighter.cpp \
-    chickencompleter.cpp \
-    chickenassist.cpp
-
-HEADERS += chickenplugin.h \
+HEADERS += \
+	chickenplugin.h \
     chicken_global.h \
     chickenconstants.h \
     chickeneditor.h \
     chickencompleter.h \
     chickenassist.h
 
-OTHER_FILES += chicken.mimetypes.xml
+SOURCES += \
+	chickenplugin.cpp \
+    chickeneditor.cpp \
+    chickenindenter.cpp \
+    chickenhighlighter.cpp \
+    chickencompleter.cpp \
+    chickenassist.cpp
+
 RESOURCES += chickeneditor.qrc

File chicken_dependencies.pri

View file
  • Ignore whitespace
-include(../../plugins/coreplugin/coreplugin.pri)
-include(../../plugins/projectexplorer/projectexplorer.pri)
-include(../../plugins/texteditor/texteditor.pri)
-include(../../plugins/cpptools/cpptools.pri)
+QTC_PLUGIN_NAME = chicken
+QTC_LIB_DEPENDS += \
+    utils \
+    cplusplus
+QTC_PLUGIN_DEPENDS += \
+    coreplugin \
+    texteditor \
+    cpptools

File chickeneditor.cpp

View file
  • Ignore whitespace
     setMarksVisible(true);
     setIndenter(new ChickenIndenter());
     setAutoCompleter(new ChickenCompleter());
-    new ChickenHighlighter(baseTextDocument().data());
+    baseTextDocument()->setSyntaxHighlighter(new ChickenHighlighter);
 }
 
 ChickenTextEditorWidget::~ChickenTextEditorWidget()
      */
     Q_UNUSED(resolveTarget);
 
+    QString id;
     int start = tc.position();
     int end = start;
     while (start > 0)
     {
-        const QChar c = editor()->characterAt(start - 1);
+        const QChar c = document()->characterAt(start - 1);
         if (!(ChickenHighlighter::isIdentifier(c) || c.isDigit()))
         {
             break;
         }
+        id.prepend(c);
         start--;
     }
     for (;;)
     {
-        const QChar c = editor()->characterAt(end);
+        const QChar c = document()->characterAt(end);
         if (!(ChickenHighlighter::isIdentifier(c) || c.isDigit()))
         {
             break;
         }
+        id.append(c);
         end++;
     }
-    const QString name = editor()->textAt(start,end - start);
-    SymbolRef r = ChickenPlugin::instance()->getLocation(name);
+    SymbolRef r = ChickenPlugin::instance()->getLocation(id);
     return r.file.isEmpty() ? Link() : Link(r.file, r.line);
 }
 /*!
 
 bool ChickenEditorEditable::open(QString *errorString, const QString &fileName, const QString &realFileName)
 {
-    editorWidget()->setMimeType(Core::ICore::mimeDatabase()->findByFile(QFileInfo(fileName)).type());
+    editorWidget()->setMimeType(Core::MimeDatabase::findByFile(QFileInfo(fileName)).type());
     bool b = TextEditor::BaseTextEditor::open(errorString, fileName, realFileName);
     return b;
 }
-
-Core::Id ChickenEditorEditable::preferredModeType() const
-{
-    return Core::Id();
-}

File chickeneditor.h

View file
  • Ignore whitespace
     Core::Id id() const;
     bool isTemporary() const { return false; }
     bool open(QString *errorString, const QString &fileName, const QString &realFileName);
-    Core::Id preferredModeType() const;
 };
 
 

File chickenhighlighter.cpp

View file
  • Ignore whitespace
 
 #define STATE_STRING 1
 
-ChickenHighlighter::ChickenHighlighter(TextEditor::BaseTextDocument *parent)
-    : TextEditor::SyntaxHighlighter(parent)
+ChickenHighlighter::ChickenHighlighter(QTextDocument *document)
+    : TextEditor::SyntaxHighlighter(document)
 {
 }
 
 void ChickenHighlighter::highlightLine(const QString &text, int position, int length,
                                        const QTextCharFormat &format)
 {
-    //qDebug() << "highlightLine:" << text;
+    Q_UNUSED(text);
+    Q_UNUSED(format);
     setFormat(position,length,Qt::blue);
 }
 

File chickenhighlighter.h

View file
  • Ignore whitespace
 
 public:
 
-    explicit ChickenHighlighter(TextEditor::BaseTextDocument *parent);
+    explicit ChickenHighlighter(QTextDocument *document = 0);
     virtual ~ChickenHighlighter();
 
     static const QSet<QString> &keywords();

File chickenplugin.cpp

View file
  • Ignore whitespace
 #include <QMenu>
 
 #include <QtPlugin>
+#include <QSet>
+#include <QDebug>
 
 using namespace chicken::Internal;
 
 static ChickenPlugin* s_pluginInstance;
 
 ChickenPlugin::ChickenPlugin()
-    : m_factory(NULL)
 {
     s_pluginInstance = this;
 }
 
 ChickenPlugin::~ChickenPlugin()
 {
-    removeObject(m_factory);
 }
 
-bool ChickenPlugin::initialize(const QStringList &arguments, QString *errorString)
+bool ChickenPlugin::initialize(const QStringList &arguments, QString *errorMessage)
 {
-    Q_UNUSED(arguments)
-    Q_UNUSED(errorString)
+    Q_UNUSED(arguments);
 
-    m_factory = new ChickenEditorFactory(this);
-    addObject(m_factory);
+    if (!Core::MimeDatabase::addMimeTypes(QLatin1String(":/chickeneditor/chicken.mimetypes.xml"), errorMessage))
+        return false;
+
+    addAutoReleasedObject(new ChickenEditorFactory(this));
+    addAutoReleasedObject(new ChickenHighlighterFactory);
     addAutoReleasedObject(new ChickenCompletionAssistProvider);
 
-    if (!Core::ICore::mimeDatabase()->addMimeTypes(
-                QLatin1String(":/chickeneditor/chicken.mimetypes.xml"), errorString))
-        return false;
-
     m_actionHandler = new TextEditor::TextEditorActionHandler(
                 Constants::CHICKEN_EDITOR_ID,
                 TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor);
+    m_actionHandler->initializeActions();
 
     Core::Command *cmd = 0;
 
     connect(buildIndex, SIGNAL(triggered()), this, SLOT(buildSymbolIndex()));
     menu->addAction(cmd);
 
+ 
+
+    errorMessage->clear();
     return true;
 }
 
 
 void ChickenPlugin::buildSymbolIndex()
 {
-    ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
-    const QList<ProjectExplorer::Project *> &projects = pe->session()->projects();
+    const QList<ProjectExplorer::Project *> &projects =
+            ProjectExplorer::SessionManager::projects();
     m_symbols.clear();
     foreach(ProjectExplorer::Project *p, projects) {
         foreach (const QString &name, p->files(ProjectExplorer::Project::AllFiles)) {
     return SymbolRef();
 }
 
-ChickenEditorFactory::ChickenEditorFactory(QObject *parent)
-    : Core::IEditorFactory(parent)
+ChickenEditorFactory::ChickenEditorFactory(ChickenPlugin *owner)
+    : Core::IEditorFactory(owner)
 {
+    setId(Constants::CHICKEN_EDITOR_ID);
+    setDisplayName(QLatin1String("Chicken"));
+    addMimeType(Constants::SCM_MIMETYPE);
 }
-QStringList ChickenEditorFactory::mimeTypes() const
-{
-    return QStringList() << QLatin1String(chicken::Constants::SCM_MIMETYPE);
-}
-Core::Id ChickenEditorFactory::id() const
-{
-    return Core::Id(chicken::Constants::CHICKEN_EDITOR_ID);
-}
-QString ChickenEditorFactory::displayName() const
-{
-    return QLatin1String("CHICKEN Scheme Editor");
-}
+
 Core::IEditor *ChickenEditorFactory::createEditor(QWidget *parent)
 {
     ChickenTextEditorWidget *w = new ChickenTextEditorWidget(parent);
     return w->editor();
 }
 
+ChickenHighlighterFactory::ChickenHighlighterFactory()
+{
+    setId(Constants::CHICKEN_EDITOR_ID);
+    addMimeType(Constants::SCM_MIMETYPE);
+}
+
+TextEditor::SyntaxHighlighter *ChickenHighlighterFactory::createHighlighter() const
+{
+   return new ChickenHighlighter;
+}
+
 Q_EXPORT_PLUGIN2(chicken, ChickenPlugin)

File chickenplugin.h

View file
  • Ignore whitespace
 
 #include <extensionsystem/iplugin.h>
 #include <coreplugin/editormanager/ieditorfactory.h>
+#include <texteditor/ihighlighterfactory.h>
 #include <texteditor/texteditoractionhandler.h>
 #include <QPair>
+#include <QMap>
 
 namespace chicken {
 namespace Internal {
 
+class ChickenPlugin;
 class ChickenTextEditorWidget;
+
 class ChickenEditorFactory : public Core::IEditorFactory
 {
     Q_OBJECT
 public:
-    ChickenEditorFactory(QObject *parent);
-    QStringList mimeTypes() const;
-    Core::Id id() const;
-    QString displayName() const;
+    ChickenEditorFactory(ChickenPlugin *owner);
     Core::IEditor *createEditor(QWidget *parent);
 };
 
+class ChickenHighlighterFactory : public TextEditor::IHighlighterFactory
+{
+    Q_OBJECT
+public:
+    ChickenHighlighterFactory();
+    virtual TextEditor::SyntaxHighlighter *createHighlighter() const;
+};
+
 struct SymbolRef {
     enum Type {
         Constant,   // define-constant
     ChickenPlugin();
     ~ChickenPlugin();
 
-    bool initialize(const QStringList &arguments, QString *errorString);
+    static ChickenPlugin* instance();
+
+    bool initialize(const QStringList &arguments, QString *errorMessage);
     void extensionsInitialized();
     ShutdownFlag aboutToShutdown();
     void initializeEditor(ChickenTextEditorWidget *editor);
     void addSymbol(const QString &name, SymbolRef symref);
     QSet<SymbolHint> suggestions(const QString &name);
     SymbolRef getLocation(const QString& name);
-
-    static ChickenPlugin* instance();
     
 private slots:
     void buildSymbolIndex();
     void indexLine(const QString &file, int line, const QString &text);
 
 private:
-    ChickenEditorFactory* m_factory;
     TextEditor::TextEditorActionHandler *m_actionHandler;
     QMap<QString,SymbolRef> m_symbols;
 };