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

Commits

rivo  committed 12a6a71

fixed build for qt4.8
fixed follow symbol under cursor

  • Participants
  • Parent commits 37ef2c6
  • Branches default

Comments (0)

Files changed (8)

File chicken.pro

View file
  • Ignore whitespace
+include(../../qtcreatorplugin.pri)
+include(chicken_dependencies.pri)
+
 TARGET = chicken
 TEMPLATE = lib
 
     chickenassist.cpp
 
 HEADERS += chickenplugin.h \
-        chicken_global.h \
-        chickenconstants.h \
+    chicken_global.h \
+    chickenconstants.h \
     chickeneditor.h \
     chickenindenter.h \
     chickenhighlighter.h \
     chickencompleter.h \
     chickenassist.h
 
-# Qt Creator linking
-
-## set the QTC_SOURCE environment variable to override the setting here
-QTCREATOR_SOURCES = $$(QTC_SOURCE)
-isEmpty(QTCREATOR_SOURCES):QTCREATOR_SOURCES=C:/hg/qt-creator-2.7.1-src
-
-## set the QTC_BUILD environment variable to override the setting here
-IDE_BUILD_TREE = $$(QTC_BUILD)
-isEmpty(IDE_BUILD_TREE):IDE_BUILD_TREE=C:/hg/build-qtcreator-Desktop_Qt_5_0_2_MinGW_32bit-Debug
-
-## uncomment to build plugin into user config directory
-## <localappdata>/plugins/<ideversion>
-##    where <localappdata> is e.g.
-##    "%LOCALAPPDATA%\QtProject\qtcreator" on Windows Vista and later
-##    "$XDG_DATA_HOME/data/QtProject/qtcreator" or "~/.local/share/data/QtProject/qtcreator" on Linux
-##    "~/Library/Application Support/QtProject/Qt Creator" on Mac
-# USE_USER_DESTDIR = yes
-
-PROVIDER = CHICKEN
-
-include($$QTCREATOR_SOURCES/src/qtcreatorplugin.pri)
-include($$QTCREATOR_SOURCES/src/plugins/coreplugin/coreplugin.pri)
-include($$QTCREATOR_SOURCES/src/plugins/texteditor/texteditor.pri)
-include($$QTCREATOR_SOURCES/src/plugins/cpptools/cpptools.pri)
-include($$QTCREATOR_SOURCES/src/plugins/projectexplorer/projectexplorer.pri)
-
-LIBS += -L$$IDE_PLUGIN_PATH/QtProject
-
 OTHER_FILES += chicken.mimetypes.xml
 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)

File chickenassist.cpp

View file
  • Ignore whitespace
     int start;
     int end;
     const QString word = wordUnderCursor(interface, start, end);
-    qDebug() << "complete: " << word << " start:" << start << " end:" << end;
+    //qDebug() << "complete: " << word << " start:" << start << " end:" << end;
     foreach(const SymbolHint &sym, ChickenPlugin::instance()->suggestions(word))
     {
         TextEditor::BasicProposalItem* i = new TextEditor::BasicProposalItem();

File chickenassist.h

View file
  • Ignore whitespace
 #include <texteditor/codeassist/iassistprocessor.h>
 #include <texteditor/codeassist/defaultassistinterface.h>
 #include <texteditor/codeassist/ifunctionhintproposalmodel.h>
+#include <QIcon>
 
 namespace chicken {
 namespace Internal {

File chickeneditor.cpp

View file
  • Ignore whitespace
 #include <coreplugin/id.h>
 #include <coreplugin/mimedatabase.h>
 
+#include <QDebug>
+
 using namespace chicken::Internal;
 
 
         TextEditor::AssistKind assistKind,
         TextEditor::AssistReason reason) const
 {
-//    if (kind == TextEditor::Completion)
-//        return new GLSLCompletionAssistInterface();
     return BaseTextEditorWidget::createAssistInterface(assistKind, reason);
 }
 
 void ChickenTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
 {
     TextEditor::BaseTextEditorWidget::setFontSettings(fs);
-    //ChickenHighlighter *highlighter = qobject_cast<ChickenHighlighter*>(baseTextDocument()->syntaxHighlighter());
-    //if (!highlighter) return;
-    //highlighter->setFormats(fs.toTextCharFormats(categories));
-    //highlighter->rehighlight();
 }
 
+TextEditor::BaseTextEditorWidget::Link ChickenTextEditorWidget::findLinkAt(const QTextCursor &tc, bool resolveTarget)
+{
+    /*!
+       Reimplement this function to enable code navigation.
+
+       \a resolveTarget is set to true when the target of the link is relevant
+       (it isn't until the link is used).
+     */
+    int start = tc.position();
+    int end = start;
+    while (start > 0)
+    {
+        const QChar c = editor()->characterAt(start - 1);
+        if (!(ChickenHighlighter::isIdentifier(c) || c.isDigit()))
+        {
+            break;
+        }
+        start--;
+    }
+    for (;;)
+    {
+        const QChar c = editor()->characterAt(end);
+        if (!(ChickenHighlighter::isIdentifier(c) || c.isDigit()))
+        {
+            break;
+        }
+        end++;
+    }
+    const QString name = editor()->textAt(start,end - start);
+    SymbolRef r = ChickenPlugin::instance()->getLocation(name);
+    return r.file.isEmpty() ? Link() : Link(r.file, r.line);
+}
+/*!
+bool ChickenTextEditorWidget::openLink(const TextEditor::BaseTextEditorWidget::Link &link, bool inNextSplit)
+{
+       Reimplement this function if you want to customize the way a link is
+       opened. Returns whether the link was opened successfully.
+    return isNextSplit;
+}
+*/
+
 TextEditor::BaseTextEditor *ChickenTextEditorWidget::createEditor()
 {
     ChickenEditorEditable *editable = new ChickenEditorEditable(this);
     return editable;
 }
 
-/////
-/// \brief ChickenEditorEditable::ChickenEditorEditable
-///
 ChickenEditorEditable::ChickenEditorEditable(ChickenTextEditorWidget *editor)
     : BaseTextEditor(editor)
 {

File chickenindenter.cpp

View file
  • Ignore whitespace
     for (int i = 0; i < str.length(); ++i)
     {
         const QChar c = str.at(i);
-        if (c == QChar::Tabulation)
+        if (c == QChar::fromLatin1('\t'))
         {
             count += tabs.m_tabSize;
             continue;
 void ChickenIndenter::indent(QTextDocument *doc, const QTextCursor &cursor, const QChar &typedChar,
                              const TextEditor::TabSettings &tabSettings)
 {
-    qDebug() << "tab_size:" << tabSettings.m_tabSize << " indent_size:" << tabSettings.m_indentSize;
+    //qDebug() << "tab_size:" << tabSettings.m_tabSize << " indent_size:" << tabSettings.m_indentSize;
     if (cursor.hasSelection()) {
-        qDebug() << " selection: " << cursor.block().text();
+        //qDebug() << " selection: " << cursor.block().text();
     } else {
         int lb = 0;
         int rb = 0;

File chickenplugin.cpp

View file
  • Ignore whitespace
 
     m_actionHandler = new TextEditor::TextEditorActionHandler(
                 Constants::CHICKEN_EDITOR_ID,
-                TextEditor::TextEditorActionHandler::None);
-    
-    Core::Context context(Core::Constants::C_GLOBAL);
-    QAction *action = new QAction(tr("chicken action"), this);
-    Core::Command *cmd = Core::ActionManager::registerAction(action, Constants::ACTION_ID, context);
-    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Meta+A")));
-    connect(action, SIGNAL(triggered()), this, SLOT(triggerAction()));
-    
+                TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor);
+
+    Core::Command *cmd = 0;
+
+    Core::Context context(Constants::CHICKEN_EDITOR_ID);
     Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::MENU_ID);
-    menu->menu()->setTitle(tr("chicken"));
-    menu->addAction(cmd);
+    menu->menu()->setTitle(tr("Chicken"));
     Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu);
 
-    QAction *gotoDefinition = new QAction(tr("Go To Definition"), this);
-    cmd = Core::ActionManager::registerAction(
-                gotoDefinition, Constants::GOTO_DEFINITION, context, true);
-    cmd->setDefaultKeySequence(QKeySequence(tr("F2")));
-    connect(gotoDefinition, SIGNAL(triggered()), this, SLOT(gotoDefinition()));
-    menu->addAction(cmd);
-
     QAction *buildIndex = new QAction(tr("Build Index"), this);
     cmd = Core::ActionManager::registerAction(
                 buildIndex, Constants::BUILD_INDEX, context, true);
-    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+F2")));
+    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F2")));
     connect(buildIndex, SIGNAL(triggered()), this, SLOT(buildSymbolIndex()));
     menu->addAction(cmd);
 
     return s_pluginInstance;
 }
 
-void ChickenPlugin::triggerAction()
+SymbolRef ChickenPlugin::getLocation(const QString& name)
 {
-    QMessageBox::information(Core::ICore::mainWindow(),
-                             tr("Action triggered"),
-                             tr("This is an action from chicken."));
-}
+    if (!name.isEmpty() && m_symbols.contains(name))
+        return m_symbols.value(name);
 
-static QString wordUnderCursor(TextEditor::ITextEditor *editor)
-{
-    int start = editor->position();
-    int end = start;
-    while (start > 0)
-    {
-        const QChar c = editor->characterAt(start - 1);
-        if (!(ChickenHighlighter::isIdentifier(c) || c.isDigit()))
-        {
-            break;
-        }
-        start--;
-    }
-    for (;;)
-    {
-        const QChar c = editor->characterAt(end);
-        if (!(ChickenHighlighter::isIdentifier(c) || c.isDigit()))
-        {
-            break;
-        }
-        end++;
-    }
-    return editor->textAt(start,end - start);
-}
-
-void ChickenPlugin::gotoDefinition()
-{
-    Core::IEditor *currEditor = Core::EditorManager::currentEditor();
-    TextEditor::ITextEditor *editor = qobject_cast<TextEditor::ITextEditor *>(currEditor);
-
-    const QString name = wordUnderCursor(editor);
-
-    if (!name.isEmpty() && m_symbols.contains(name)) {
-        const SymbolRef &sym = m_symbols.value(name);
-        TextEditor::BaseTextEditorWidget::openEditorAt(sym.file,sym.line);
-    }
+    return SymbolRef();
 }
 
 ChickenEditorFactory::ChickenEditorFactory(QObject *parent)

File chickenplugin.h

View file
  • Ignore whitespace
 
     void addSymbol(const QString &name, SymbolRef symref);
     QSet<SymbolHint> suggestions(const QString &name);
+    SymbolRef getLocation(const QString& name);
 
     static ChickenPlugin* instance();
     
 private slots:
-    void triggerAction();
-    void gotoDefinition();
     void buildSymbolIndex();
 
 private: