forked from qt-creator/qt-creator
Code model: Update on changes from the versioning system.
Add state logic to CppCodeModelManagerInterface, making it aware whether an indexer is running, protect the update methods from another invocation while running. Add changed signals to IVersionControl and VCSManager and wire them to the update methods. Add a menu action for manually updating. Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com> Reviewed-by: con <qtc-committer@nokia.com>
This commit is contained in:
@@ -43,7 +43,7 @@
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
#include <cpptools/cppmodelmanagerinterface.h>
|
||||
#include <texteditor/completionsupport.h>
|
||||
#include <texteditor/fontsettings.h>
|
||||
#include <texteditor/storagesettings.h>
|
||||
@@ -112,7 +112,11 @@ CppPlugin *CppPlugin::m_instance = 0;
|
||||
|
||||
CppPlugin::CppPlugin() :
|
||||
m_actionHandler(0),
|
||||
m_sortedMethodOverview(false)
|
||||
m_sortedMethodOverview(false),
|
||||
m_renameSymbolUnderCursorAction(0),
|
||||
m_findUsagesAction(0),
|
||||
m_updateCodeModelAction(0)
|
||||
|
||||
{
|
||||
m_instance = this;
|
||||
}
|
||||
@@ -158,6 +162,17 @@ bool CppPlugin::sortedMethodOverview() const
|
||||
return m_sortedMethodOverview;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
|
||||
{
|
||||
Core::ICore *core = Core::ICore::instance();
|
||||
@@ -192,6 +207,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
|
||||
Core::ActionContainer *contextMenu= am->createMenu(CppEditor::Constants::M_CONTEXT);
|
||||
|
||||
Core::Command *cmd;
|
||||
Core::ActionContainer *cppToolsMenu = am->actionContainer(QLatin1String(CppTools::Constants::M_TOOLS_CPP));
|
||||
|
||||
QAction *jumpToDefinition = new QAction(tr("Follow Symbol under Cursor"), this);
|
||||
cmd = am->registerAction(jumpToDefinition,
|
||||
@@ -200,7 +216,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
|
||||
connect(jumpToDefinition, SIGNAL(triggered()),
|
||||
this, SLOT(jumpToDefinition()));
|
||||
contextMenu->addAction(cmd);
|
||||
am->actionContainer(CppTools::Constants::M_TOOLS_CPP)->addAction(cmd);
|
||||
cppToolsMenu->addAction(cmd);
|
||||
|
||||
QAction *switchDeclarationDefinition = new QAction(tr("Switch between Method Declaration/Definition"), this);
|
||||
cmd = am->registerAction(switchDeclarationDefinition,
|
||||
@@ -209,14 +225,14 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
|
||||
connect(switchDeclarationDefinition, SIGNAL(triggered()),
|
||||
this, SLOT(switchDeclarationDefinition()));
|
||||
contextMenu->addAction(cmd);
|
||||
am->actionContainer(CppTools::Constants::M_TOOLS_CPP)->addAction(cmd);
|
||||
cppToolsMenu->addAction(cmd);
|
||||
|
||||
m_findUsagesAction = new QAction(tr("Find Usages"), this);
|
||||
cmd = am->registerAction(m_findUsagesAction, Constants::FIND_USAGES, context);
|
||||
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+U")));
|
||||
connect(m_findUsagesAction, SIGNAL(triggered()), this, SLOT(findUsages()));
|
||||
contextMenu->addAction(cmd);
|
||||
am->actionContainer(CppTools::Constants::M_TOOLS_CPP)->addAction(cmd);
|
||||
cppToolsMenu->addAction(cmd);
|
||||
|
||||
m_renameSymbolUnderCursorAction = new QAction(tr("Rename Symbol under Cursor"), this);
|
||||
cmd = am->registerAction(m_renameSymbolUnderCursorAction,
|
||||
@@ -224,7 +240,17 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
|
||||
cmd->setDefaultKeySequence(QKeySequence("CTRL+SHIFT+R"));
|
||||
connect(m_renameSymbolUnderCursorAction, SIGNAL(triggered()), this, SLOT(renameSymbolUnderCursor()));
|
||||
contextMenu->addAction(cmd);
|
||||
am->actionContainer(CppTools::Constants::M_TOOLS_CPP)->addAction(cmd);
|
||||
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);
|
||||
|
||||
m_actionHandler = new TextEditor::TextEditorActionHandler(CppEditor::Constants::C_CPPEDITOR,
|
||||
TextEditor::TextEditorActionHandler::Format
|
||||
@@ -233,10 +259,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
|
||||
|
||||
m_actionHandler->initializeActions();
|
||||
|
||||
QAction *separator = new QAction(this);
|
||||
separator->setSeparator(true);
|
||||
cmd = am->registerAction(separator, CppEditor::Constants::SEPARATOR, context);
|
||||
contextMenu->addAction(cmd);
|
||||
contextMenu->addAction(createSeparator(am, this, context, CppEditor::Constants::SEPARATOR));
|
||||
|
||||
cmd = am->command(TextEditor::Constants::AUTO_INDENT_SELECTION);
|
||||
contextMenu->addAction(cmd);
|
||||
@@ -244,10 +267,8 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
|
||||
cmd = am->command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
||||
contextMenu->addAction(cmd);
|
||||
|
||||
connect(core->progressManager(), SIGNAL(taskStarted(QString)),
|
||||
this, SLOT(onTaskStarted(QString)));
|
||||
connect(core->progressManager(), SIGNAL(allTasksFinished(QString)),
|
||||
this, SLOT(onAllTasksFinished(QString)));
|
||||
connect(cppModelManager, SIGNAL(indexingStarted()), this, SLOT(onCppModelIndexingStarted()));
|
||||
connect(cppModelManager, SIGNAL(indexingFinished()), this, SLOT(onCppModelIndexingFinished()));
|
||||
readSettings();
|
||||
return true;
|
||||
}
|
||||
@@ -303,20 +324,18 @@ void CppPlugin::findUsages()
|
||||
editor->findUsages();
|
||||
}
|
||||
|
||||
void CppPlugin::onTaskStarted(const QString &type)
|
||||
void CppPlugin::onCppModelIndexingStarted()
|
||||
{
|
||||
if (type == CppTools::Constants::TASK_INDEX) {
|
||||
m_renameSymbolUnderCursorAction->setEnabled(false);
|
||||
m_findUsagesAction->setEnabled(false);
|
||||
}
|
||||
m_renameSymbolUnderCursorAction->setEnabled(false);
|
||||
m_findUsagesAction->setEnabled(false);
|
||||
m_updateCodeModelAction->setEnabled(false);
|
||||
}
|
||||
|
||||
void CppPlugin::onAllTasksFinished(const QString &type)
|
||||
void CppPlugin::onCppModelIndexingFinished()
|
||||
{
|
||||
if (type == CppTools::Constants::TASK_INDEX) {
|
||||
m_renameSymbolUnderCursorAction->setEnabled(true);
|
||||
m_findUsagesAction->setEnabled(true);
|
||||
}
|
||||
m_renameSymbolUnderCursorAction->setEnabled(true);
|
||||
m_findUsagesAction->setEnabled(true);
|
||||
m_updateCodeModelAction->setEnabled(true);
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN(CppPlugin)
|
||||
|
||||
Reference in New Issue
Block a user