2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file 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 Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cppplugin.h"
|
2008-12-16 12:22:08 +01:00
|
|
|
#include "cppclasswizard.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cppeditor.h"
|
|
|
|
|
#include "cppeditorconstants.h"
|
|
|
|
|
#include "cppeditorenums.h"
|
|
|
|
|
#include "cppfilewizard.h"
|
2008-12-16 12:22:08 +01:00
|
|
|
#include "cpphoverhandler.h"
|
2009-11-13 16:14:26 +01:00
|
|
|
#include "cppquickfix.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-20 15:31:33 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/mimedatabase.h>
|
|
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
|
|
|
|
#include <coreplugin/fileiconprovider.h>
|
2009-01-13 13:39:31 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2009-01-14 13:17:53 +01:00
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2009-11-10 18:02:42 +01:00
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <texteditor/completionsupport.h>
|
|
|
|
|
#include <texteditor/fontsettings.h>
|
|
|
|
|
#include <texteditor/storagesettings.h>
|
2009-03-17 17:38:16 +01:00
|
|
|
#include <texteditor/texteditoractionhandler.h>
|
2009-03-17 18:17:51 +01:00
|
|
|
#include <texteditor/texteditorplugin.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <texteditor/texteditorsettings.h>
|
2009-07-22 15:32:52 +02:00
|
|
|
#include <texteditor/texteditorconstants.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <cpptools/cpptoolsconstants.h>
|
2009-11-11 14:32:54 +01:00
|
|
|
#include <cpptools/cppmodelmanagerinterface.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
#include <QtCore/QSettings>
|
2009-11-18 15:06:26 +01:00
|
|
|
#include <QtCore/QTimer>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QMenu>
|
|
|
|
|
|
|
|
|
|
using namespace CppEditor::Internal;
|
|
|
|
|
|
2009-11-18 15:06:26 +01:00
|
|
|
enum { QUICKFIX_INTERVAL = 20 };
|
|
|
|
|
|
2009-03-17 17:43:51 +01:00
|
|
|
//////////////////////////// CppEditorFactory /////////////////////////////
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-03-17 17:43:51 +01:00
|
|
|
CppEditorFactory::CppEditorFactory(CppPlugin *owner) :
|
2008-12-02 12:01:29 +01:00
|
|
|
m_owner(owner)
|
|
|
|
|
{
|
|
|
|
|
m_mimeTypes << QLatin1String(CppEditor::Constants::C_SOURCE_MIMETYPE)
|
2009-07-15 11:20:24 +02:00
|
|
|
<< QLatin1String(CppEditor::Constants::C_HEADER_MIMETYPE)
|
|
|
|
|
<< QLatin1String(CppEditor::Constants::CPP_SOURCE_MIMETYPE)
|
|
|
|
|
<< QLatin1String(CppEditor::Constants::CPP_HEADER_MIMETYPE);
|
|
|
|
|
|
2010-01-28 15:47:45 +01:00
|
|
|
#if !defined(Q_WS_MAC) && !defined(Q_WS_WIN)
|
2009-07-15 11:20:24 +02:00
|
|
|
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
|
|
|
|
|
Core::MimeDatabase *mimeDatabase = Core::ICore::instance()->mimeDatabase();
|
|
|
|
|
iconProvider->registerIconOverlayForMimeType(QIcon(":/cppeditor/images/qt_cpp.png"),
|
|
|
|
|
mimeDatabase->findByType(QLatin1String(CppEditor::Constants::CPP_SOURCE_MIMETYPE)));
|
|
|
|
|
iconProvider->registerIconOverlayForMimeType(QIcon(":/cppeditor/images/qt_c.png"),
|
|
|
|
|
mimeDatabase->findByType(QLatin1String(CppEditor::Constants::C_SOURCE_MIMETYPE)));
|
|
|
|
|
iconProvider->registerIconOverlayForMimeType(QIcon(":/cppeditor/images/qt_h.png"),
|
|
|
|
|
mimeDatabase->findByType(QLatin1String(CppEditor::Constants::CPP_HEADER_MIMETYPE)));
|
2009-07-14 16:37:26 +02:00
|
|
|
#endif
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString CppEditorFactory::id() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-01-28 15:47:45 +01:00
|
|
|
return QLatin1String(CppEditor::Constants::CPPEDITOR_ID);
|
2010-01-07 18:17:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CppEditorFactory::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return tr(CppEditor::Constants::CPPEDITOR_DISPLAY_NAME);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-17 17:43:51 +01:00
|
|
|
Core::IFile *CppEditorFactory::open(const QString &fileName)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-01-07 18:17:24 +01:00
|
|
|
Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
|
2008-12-02 12:01:29 +01:00
|
|
|
return iface ? iface->file() : 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-17 17:43:51 +01:00
|
|
|
Core::IEditor *CppEditorFactory::createEditor(QWidget *parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
CPPEditor *editor = new CPPEditor(parent);
|
|
|
|
|
editor->setRevisionsVisible(true);
|
|
|
|
|
m_owner->initializeEditor(editor);
|
|
|
|
|
return editor->editableInterface();
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-17 17:43:51 +01:00
|
|
|
QStringList CppEditorFactory::mimeTypes() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_mimeTypes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////// CppPlugin //////////////////////////////////
|
|
|
|
|
|
2009-11-11 14:32:54 +01:00
|
|
|
static inline
|
|
|
|
|
Core::Command *createSeparator(Core::ActionManager *am,
|
|
|
|
|
QObject *parent,
|
|
|
|
|
const QList<int> &context,
|
|
|
|
|
const char *id)
|
|
|
|
|
{
|
|
|
|
|
QAction *separator = new QAction(parent);
|
|
|
|
|
separator->setSeparator(true);
|
|
|
|
|
return am->registerAction(separator, QLatin1String(id), context);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
CppPlugin *CppPlugin::m_instance = 0;
|
|
|
|
|
|
|
|
|
|
CppPlugin::CppPlugin() :
|
|
|
|
|
m_actionHandler(0),
|
2009-11-11 14:32:54 +01:00
|
|
|
m_sortedMethodOverview(false),
|
|
|
|
|
m_renameSymbolUnderCursorAction(0),
|
|
|
|
|
m_findUsagesAction(0),
|
|
|
|
|
m_updateCodeModelAction(0)
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_instance = this;
|
2009-11-18 15:06:26 +01:00
|
|
|
|
2009-11-23 16:55:04 +01:00
|
|
|
m_quickFixCollector = 0;
|
2009-11-18 15:06:26 +01:00
|
|
|
m_quickFixTimer = new QTimer(this);
|
|
|
|
|
m_quickFixTimer->setInterval(20);
|
|
|
|
|
m_quickFixTimer->setSingleShot(true);
|
|
|
|
|
connect(m_quickFixTimer, SIGNAL(timeout()), this, SLOT(quickFixNow()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CppPlugin::~CppPlugin()
|
|
|
|
|
{
|
|
|
|
|
delete m_actionHandler;
|
|
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CppPlugin *CppPlugin::instance()
|
|
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppPlugin::initializeEditor(CPPEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
m_actionHandler->setupActions(editor);
|
|
|
|
|
|
2009-03-17 18:17:51 +01:00
|
|
|
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// auto completion
|
2009-11-18 15:06:26 +01:00
|
|
|
connect(editor, SIGNAL(requestAutoCompletion(TextEditor::ITextEditable*, bool)),
|
|
|
|
|
TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(TextEditor::ITextEditable*, bool)));
|
2009-06-09 13:52:27 +02:00
|
|
|
|
|
|
|
|
// quick fix
|
2009-11-18 15:06:26 +01:00
|
|
|
connect(editor, SIGNAL(requestQuickFix(TextEditor::ITextEditable*)),
|
|
|
|
|
this, SLOT(quickFix(TextEditor::ITextEditable*)));
|
2009-06-09 13:52:27 +02:00
|
|
|
|
2009-04-27 17:22:49 +02:00
|
|
|
// method combo box sorting
|
|
|
|
|
connect(this, SIGNAL(methodOverviewSortingChanged(bool)),
|
|
|
|
|
editor, SLOT(setSortedMethodOverview(bool)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppPlugin::setSortedMethodOverview(bool sorted)
|
|
|
|
|
{
|
|
|
|
|
m_sortedMethodOverview = sorted;
|
|
|
|
|
emit methodOverviewSortingChanged(sorted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CppPlugin::sortedMethodOverview() const
|
|
|
|
|
{
|
|
|
|
|
return m_sortedMethodOverview;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-23 16:55:04 +01:00
|
|
|
CPPQuickFixCollector *CppPlugin::quickFixCollector() const
|
|
|
|
|
{ return m_quickFixCollector; }
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
|
|
|
|
|
{
|
2009-01-20 11:52:04 +01:00
|
|
|
Core::ICore *core = Core::ICore::instance();
|
2009-07-15 11:20:24 +02:00
|
|
|
|
2009-01-20 11:52:04 +01:00
|
|
|
if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/cppeditor/CppEditor.mimetypes.xml"), errorMessage))
|
2008-12-02 12:01:29 +01:00
|
|
|
return false;
|
|
|
|
|
|
2009-07-15 11:20:24 +02:00
|
|
|
addAutoReleasedObject(new CppEditorFactory(this));
|
2008-12-16 12:22:08 +01:00
|
|
|
addAutoReleasedObject(new CppHoverHandler);
|
2009-11-23 16:55:04 +01:00
|
|
|
|
|
|
|
|
m_quickFixCollector = new CPPQuickFixCollector;
|
|
|
|
|
addAutoReleasedObject(m_quickFixCollector);
|
2008-12-16 12:22:08 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
CppFileWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
|
|
|
|
|
|
2010-01-13 18:44:15 +01:00
|
|
|
wizardParameters.setCategory(QLatin1String("O.C++"));
|
2010-01-07 18:17:24 +01:00
|
|
|
wizardParameters.setDisplayCategory(tr("C++"));
|
|
|
|
|
wizardParameters.setDisplayName(tr("C++ Class"));
|
2009-11-27 10:33:24 +01:00
|
|
|
wizardParameters.setId(QLatin1String("A.Class"));
|
|
|
|
|
wizardParameters.setKind(Core::IWizard::ClassWizard);
|
|
|
|
|
wizardParameters.setDescription(tr("Creates a header and a source file for a new class."));
|
|
|
|
|
addAutoReleasedObject(new CppClassWizard(wizardParameters, core));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-27 10:33:24 +01:00
|
|
|
wizardParameters.setKind(Core::IWizard::FileWizard);
|
2009-05-25 13:45:00 +02:00
|
|
|
wizardParameters.setDescription(tr("Creates a C++ source file."));
|
2010-01-07 18:17:24 +01:00
|
|
|
wizardParameters.setDisplayName(tr("C++ Source File"));
|
2009-11-27 10:33:24 +01:00
|
|
|
wizardParameters.setId(QLatin1String("B.Source"));
|
2009-01-20 11:52:04 +01:00
|
|
|
addAutoReleasedObject(new CppFileWizard(wizardParameters, Source, core));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-27 10:33:24 +01:00
|
|
|
wizardParameters.setDescription(tr("Creates a C++ header file."));
|
2010-01-07 18:17:24 +01:00
|
|
|
wizardParameters.setDisplayName(tr("C++ Header File"));
|
2009-11-27 10:33:24 +01:00
|
|
|
wizardParameters.setId(QLatin1String("C.Header"));
|
|
|
|
|
addAutoReleasedObject(new CppFileWizard(wizardParameters, Header, core));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QList<int> context;
|
2010-01-11 16:52:38 +01:00
|
|
|
context << core->uniqueIDManager()->uniqueIdentifier(CppEditor::Constants::C_CPPEDITOR);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-20 11:52:04 +01:00
|
|
|
Core::ActionManager *am = core->actionManager();
|
2009-09-24 14:50:22 +02:00
|
|
|
Core::ActionContainer *contextMenu= am->createMenu(CppEditor::Constants::M_CONTEXT);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-14 13:17:53 +01:00
|
|
|
Core::Command *cmd;
|
2009-11-11 14:32:54 +01:00
|
|
|
Core::ActionContainer *cppToolsMenu = am->actionContainer(QLatin1String(CppTools::Constants::M_TOOLS_CPP));
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-25 10:58:40 +01:00
|
|
|
QAction *jumpToDefinition = new QAction(tr("Follow Symbol Under Cursor"), this);
|
2008-12-02 12:01:29 +01:00
|
|
|
cmd = am->registerAction(jumpToDefinition,
|
|
|
|
|
Constants::JUMP_TO_DEFINITION, context);
|
|
|
|
|
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F2));
|
|
|
|
|
connect(jumpToDefinition, SIGNAL(triggered()),
|
|
|
|
|
this, SLOT(jumpToDefinition()));
|
2009-09-24 14:50:22 +02:00
|
|
|
contextMenu->addAction(cmd);
|
2009-11-11 14:32:54 +01:00
|
|
|
cppToolsMenu->addAction(cmd);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-25 10:58:40 +01:00
|
|
|
QAction *switchDeclarationDefinition = new QAction(tr("Switch Between Method Declaration/Definition"), this);
|
2008-12-02 12:01:29 +01:00
|
|
|
cmd = am->registerAction(switchDeclarationDefinition,
|
|
|
|
|
Constants::SWITCH_DECLARATION_DEFINITION, context);
|
|
|
|
|
cmd->setDefaultKeySequence(QKeySequence("Shift+F2"));
|
|
|
|
|
connect(switchDeclarationDefinition, SIGNAL(triggered()),
|
|
|
|
|
this, SLOT(switchDeclarationDefinition()));
|
2009-09-24 14:50:22 +02:00
|
|
|
contextMenu->addAction(cmd);
|
2009-11-11 14:32:54 +01:00
|
|
|
cppToolsMenu->addAction(cmd);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-04 16:07:42 +01:00
|
|
|
m_findUsagesAction = new QAction(tr("Find Usages"), this);
|
|
|
|
|
cmd = am->registerAction(m_findUsagesAction, Constants::FIND_USAGES, context);
|
2009-10-07 11:11:48 +02:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+U")));
|
2009-11-04 16:07:42 +01:00
|
|
|
connect(m_findUsagesAction, SIGNAL(triggered()), this, SLOT(findUsages()));
|
2009-10-05 15:17:25 +02:00
|
|
|
contextMenu->addAction(cmd);
|
2009-11-11 14:32:54 +01:00
|
|
|
cppToolsMenu->addAction(cmd);
|
2009-10-05 15:17:25 +02:00
|
|
|
|
2009-11-25 10:58:40 +01:00
|
|
|
m_renameSymbolUnderCursorAction = new QAction(tr("Rename Symbol Under Cursor"), this);
|
2009-11-04 16:07:42 +01:00
|
|
|
cmd = am->registerAction(m_renameSymbolUnderCursorAction,
|
2009-08-04 13:44:54 +02:00
|
|
|
Constants::RENAME_SYMBOL_UNDER_CURSOR, context);
|
|
|
|
|
cmd->setDefaultKeySequence(QKeySequence("CTRL+SHIFT+R"));
|
2009-11-04 16:07:42 +01:00
|
|
|
connect(m_renameSymbolUnderCursorAction, SIGNAL(triggered()), this, SLOT(renameSymbolUnderCursor()));
|
2009-09-24 14:50:22 +02:00
|
|
|
contextMenu->addAction(cmd);
|
2009-11-11 14:32:54 +01:00
|
|
|
cppToolsMenu->addAction(cmd);
|
|
|
|
|
|
|
|
|
|
// Update context in global context
|
|
|
|
|
QList<int> globalContext;
|
|
|
|
|
globalContext.append(Core::Constants::C_GLOBAL_ID);
|
|
|
|
|
cppToolsMenu->addAction(createSeparator(am, this, globalContext, CppEditor::Constants::SEPARATOR2));
|
|
|
|
|
m_updateCodeModelAction = new QAction(tr("Update code model"), this);
|
|
|
|
|
cmd = am->registerAction(m_updateCodeModelAction, QLatin1String(Constants::UPDATE_CODEMODEL), globalContext);
|
|
|
|
|
CppTools::CppModelManagerInterface *cppModelManager = CppTools::CppModelManagerInterface::instance();
|
|
|
|
|
connect(m_updateCodeModelAction, SIGNAL(triggered()), cppModelManager, SLOT(updateModifiedSourceFiles()));
|
|
|
|
|
cppToolsMenu->addAction(cmd);
|
2009-08-04 13:44:54 +02:00
|
|
|
|
2010-01-11 16:52:38 +01:00
|
|
|
m_actionHandler = new TextEditor::TextEditorActionHandler(CppEditor::Constants::C_CPPEDITOR,
|
2008-12-02 12:01:29 +01:00
|
|
|
TextEditor::TextEditorActionHandler::Format
|
|
|
|
|
| TextEditor::TextEditorActionHandler::UnCommentSelection
|
|
|
|
|
| TextEditor::TextEditorActionHandler::UnCollapseAll);
|
|
|
|
|
|
2009-07-22 15:32:52 +02:00
|
|
|
m_actionHandler->initializeActions();
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2009-11-11 14:32:54 +01:00
|
|
|
contextMenu->addAction(createSeparator(am, this, context, CppEditor::Constants::SEPARATOR));
|
2009-07-22 15:32:52 +02:00
|
|
|
|
|
|
|
|
cmd = am->command(TextEditor::Constants::AUTO_INDENT_SELECTION);
|
2009-09-24 14:50:22 +02:00
|
|
|
contextMenu->addAction(cmd);
|
2009-07-22 15:32:52 +02:00
|
|
|
|
|
|
|
|
cmd = am->command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
2009-09-24 14:50:22 +02:00
|
|
|
contextMenu->addAction(cmd);
|
2009-07-22 15:32:52 +02:00
|
|
|
|
2009-11-10 18:02:42 +01:00
|
|
|
connect(core->progressManager(), SIGNAL(taskStarted(QString)),
|
|
|
|
|
this, SLOT(onTaskStarted(QString)));
|
|
|
|
|
connect(core->progressManager(), SIGNAL(allTasksFinished(QString)),
|
|
|
|
|
this, SLOT(onAllTasksFinished(QString)));
|
2009-04-27 17:22:49 +02:00
|
|
|
readSettings();
|
2008-12-02 12:01:29 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-27 17:22:49 +02:00
|
|
|
void CppPlugin::readSettings()
|
|
|
|
|
{
|
|
|
|
|
m_sortedMethodOverview = Core::ICore::instance()->settings()->value("CppTools/SortedMethodOverview", false).toBool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppPlugin::writeSettings()
|
|
|
|
|
{
|
|
|
|
|
Core::ICore::instance()->settings()->setValue("CppTools/SortedMethodOverview", m_sortedMethodOverview);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void CppPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-27 17:22:49 +02:00
|
|
|
void CppPlugin::shutdown()
|
|
|
|
|
{
|
|
|
|
|
writeSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void CppPlugin::switchDeclarationDefinition()
|
|
|
|
|
{
|
2009-01-21 15:52:34 +01:00
|
|
|
Core::EditorManager *em = Core::EditorManager::instance();
|
|
|
|
|
CPPEditor *editor = qobject_cast<CPPEditor*>(em->currentEditor()->widget());
|
|
|
|
|
if (editor)
|
2008-12-02 12:01:29 +01:00
|
|
|
editor->switchDeclarationDefinition();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppPlugin::jumpToDefinition()
|
|
|
|
|
{
|
2009-01-21 15:52:34 +01:00
|
|
|
Core::EditorManager *em = Core::EditorManager::instance();
|
|
|
|
|
CPPEditor *editor = qobject_cast<CPPEditor*>(em->currentEditor()->widget());
|
|
|
|
|
if (editor)
|
2008-12-02 12:01:29 +01:00
|
|
|
editor->jumpToDefinition();
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-04 13:44:54 +02:00
|
|
|
void CppPlugin::renameSymbolUnderCursor()
|
|
|
|
|
{
|
|
|
|
|
Core::EditorManager *em = Core::EditorManager::instance();
|
|
|
|
|
CPPEditor *editor = qobject_cast<CPPEditor*>(em->currentEditor()->widget());
|
|
|
|
|
if (editor)
|
|
|
|
|
editor->renameSymbolUnderCursor();
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-05 15:17:25 +02:00
|
|
|
void CppPlugin::findUsages()
|
|
|
|
|
{
|
|
|
|
|
Core::EditorManager *em = Core::EditorManager::instance();
|
|
|
|
|
CPPEditor *editor = qobject_cast<CPPEditor*>(em->currentEditor()->widget());
|
|
|
|
|
if (editor)
|
|
|
|
|
editor->findUsages();
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-18 15:06:26 +01:00
|
|
|
void CppPlugin::quickFix(TextEditor::ITextEditable *editable)
|
|
|
|
|
{
|
|
|
|
|
m_currentTextEditable = editable;
|
|
|
|
|
quickFixNow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppPlugin::quickFixNow()
|
|
|
|
|
{
|
|
|
|
|
if (! m_currentTextEditable)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Core::EditorManager *em = Core::EditorManager::instance();
|
|
|
|
|
CPPEditor *currentEditor = qobject_cast<CPPEditor*>(em->currentEditor()->widget());
|
|
|
|
|
|
|
|
|
|
if (CPPEditor *editor = qobject_cast<CPPEditor*>(m_currentTextEditable->widget())) {
|
|
|
|
|
if (currentEditor == editor) {
|
|
|
|
|
if (editor->isOutdated())
|
|
|
|
|
m_quickFixTimer->start(QUICKFIX_INTERVAL);
|
|
|
|
|
else
|
|
|
|
|
TextEditor::Internal::CompletionSupport::instance()->quickFix(m_currentTextEditable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-10 18:02:42 +01:00
|
|
|
void CppPlugin::onTaskStarted(const QString &type)
|
2009-11-04 16:07:42 +01:00
|
|
|
{
|
2009-11-10 18:02:42 +01:00
|
|
|
if (type == CppTools::Constants::TASK_INDEX) {
|
|
|
|
|
m_renameSymbolUnderCursorAction->setEnabled(false);
|
|
|
|
|
m_findUsagesAction->setEnabled(false);
|
2009-11-11 14:32:54 +01:00
|
|
|
m_updateCodeModelAction->setEnabled(false);
|
2009-11-10 18:02:42 +01:00
|
|
|
}
|
2009-11-04 16:07:42 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-10 18:02:42 +01:00
|
|
|
void CppPlugin::onAllTasksFinished(const QString &type)
|
2009-11-04 16:07:42 +01:00
|
|
|
{
|
2009-11-10 18:02:42 +01:00
|
|
|
if (type == CppTools::Constants::TASK_INDEX) {
|
|
|
|
|
m_renameSymbolUnderCursorAction->setEnabled(true);
|
|
|
|
|
m_findUsagesAction->setEnabled(true);
|
2009-11-11 14:32:54 +01:00
|
|
|
m_updateCodeModelAction->setEnabled(true);
|
2009-11-10 18:02:42 +01:00
|
|
|
}
|
2009-11-04 16:07:42 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
Q_EXPORT_PLUGIN(CppPlugin)
|