Commit bab8c94f authored by Roberto Raggi's avatar Roberto Raggi

Show the quickfixes in the context menu.

parent a579f2f2
......@@ -31,6 +31,7 @@
#include "cppeditorconstants.h"
#include "cppplugin.h"
#include "cpphighlighter.h"
#include "cppquickfix.h"
#include <cpptools/cpptoolsplugin.h>
#include <AST.h>
......@@ -81,6 +82,7 @@
#include <QtCore/QTimer>
#include <QtCore/QStack>
#include <QtCore/QSettings>
#include <QtCore/QSignalMapper>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QHeaderView>
......@@ -1675,6 +1677,13 @@ bool CPPEditor::event(QEvent *e)
return BaseTextEditor::event(e);
}
void CPPEditor::performQuickFix(int index)
{
CPPQuickFixCollector *quickFixCollector = CppPlugin::instance()->quickFixCollector();
QuickFixOperationPtr op = m_quickFixes.at(index);
quickFixCollector->perform(op);
}
void CPPEditor::contextMenuEvent(QContextMenuEvent *e)
{
// ### enable
......@@ -1686,12 +1695,35 @@ void CPPEditor::contextMenuEvent(QContextMenuEvent *e)
Core::ActionContainer *mcontext = am->actionContainer(CppEditor::Constants::M_CONTEXT);
QMenu *contextMenu = mcontext->menu();
CPPQuickFixCollector *quickFixCollector = CppPlugin::instance()->quickFixCollector();
QSignalMapper mapper;
connect(&mapper, SIGNAL(mapped(int)), this, SLOT(performQuickFix(int)));
if (! isOutdated()) {
if (quickFixCollector->startCompletion(editableInterface()) != -1) {
m_quickFixes = quickFixCollector->quickFixes();
for (int index = 0; index < m_quickFixes.size(); ++index) {
QuickFixOperationPtr op = m_quickFixes.at(index);
QAction *action = menu->addAction(op->description());
mapper.setMapping(action, index);
connect(action, SIGNAL(triggered()), &mapper, SLOT(map()));
}
if (! m_quickFixes.isEmpty())
menu->addSeparator();
}
}
foreach (QAction *action, contextMenu->actions())
menu->addAction(action);
appendStandardContextMenuActions(menu);
menu->exec(e->globalPos());
quickFixCollector->cleanup();
m_quickFixes.clear();
delete menu;
}
......
......@@ -31,6 +31,7 @@
#define CPPEDITOR_H
#include "cppeditorenums.h"
#include "cppquickfix.h"
#include <cplusplus/CppDocument.h>
#include <texteditor/basetexteditor.h>
......@@ -235,6 +236,8 @@ private Q_SLOTS:
void semanticRehighlight();
void updateSemanticInfo(const SemanticInfo &semanticInfo);
void performQuickFix(int index);
private:
bool showWarningMessage() const;
void setShowWarningMessage(bool showWarningMessage);
......@@ -292,6 +295,7 @@ private:
SemanticHighlighter *m_semanticHighlighter;
SemanticInfo m_lastSemanticInfo;
QList<QuickFixOperationPtr> m_quickFixes;
bool m_initialized;
};
......
......@@ -40,6 +40,7 @@ const char * const CPPEDITOR_KIND = QT_TRANSLATE_NOOP("OpenWith::Editors", "C++
const char * const SWITCH_DECLARATION_DEFINITION = "CppEditor.SwitchDeclarationDefinition";
const char * const RENAME_SYMBOL_UNDER_CURSOR = "CppEditor.RenameSymbolUnderCursor";
const char * const FIND_USAGES = "CppEditor.FindUsages";
const char * const REFACTOR_MENU = "CppEditor.RefactorMenu";
const char * const SEPARATOR = "CppEditor.Separator";
const char * const SEPARATOR2 = "CppEditor.Separator2";
const char * const FIND_REFERENCES = "CppEditor.FindReferences";
......
......@@ -137,6 +137,7 @@ CppPlugin::CppPlugin() :
{
m_instance = this;
m_quickFixCollector = 0;
m_quickFixTimer = new QTimer(this);
m_quickFixTimer->setInterval(20);
m_quickFixTimer->setSingleShot(true);
......@@ -184,6 +185,9 @@ bool CppPlugin::sortedMethodOverview() const
return m_sortedMethodOverview;
}
CPPQuickFixCollector *CppPlugin::quickFixCollector() const
{ return m_quickFixCollector; }
bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
{
Core::ICore *core = Core::ICore::instance();
......@@ -193,7 +197,9 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
addAutoReleasedObject(new CppEditorFactory(this));
addAutoReleasedObject(new CppHoverHandler);
addAutoReleasedObject(new CPPQuickFixCollector);
m_quickFixCollector = new CPPQuickFixCollector;
addAutoReleasedObject(m_quickFixCollector);
CppFileWizard::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
......
......@@ -46,6 +46,7 @@ namespace CppEditor {
namespace Internal {
class CPPEditor;
class CPPQuickFixCollector;
class CppPlugin : public ExtensionSystem::IPlugin
{
......@@ -66,6 +67,8 @@ public:
bool sortedMethodOverview() const;
CPPQuickFixCollector *quickFixCollector() const;
signals:
void methodOverviewSortingChanged(bool sort);
......@@ -95,6 +98,8 @@ private:
QAction *m_findUsagesAction;
QAction *m_updateCodeModelAction;
CPPQuickFixCollector *m_quickFixCollector;
QTimer *m_quickFixTimer;
QPointer<TextEditor::ITextEditable> m_currentTextEditable;
};
......
......@@ -858,11 +858,16 @@ void CPPQuickFixCollector::complete(const TextEditor::CompletionItem &item)
if (index < _quickFixes.size()) {
QuickFixOperationPtr quickFix = _quickFixes.at(index);
quickFix->setTextCursor(_editor->textCursor());
quickFix->apply();
perform(quickFix);
}
}
void CPPQuickFixCollector::perform(QuickFixOperationPtr op)
{
op->setTextCursor(_editor->textCursor());
op->apply();
}
void CPPQuickFixCollector::cleanup()
{
_quickFixes.clear();
......
......@@ -126,6 +126,8 @@ public:
CPPQuickFixCollector();
virtual ~CPPQuickFixCollector();
QList<QuickFixOperationPtr> quickFixes() const { return _quickFixes; }
virtual bool supportsEditor(TextEditor::ITextEditable *editor);
virtual bool triggersCompletion(TextEditor::ITextEditable *editor);
virtual int startCompletion(TextEditor::ITextEditable *editor);
......@@ -133,6 +135,9 @@ public:
virtual void complete(const TextEditor::CompletionItem &item);
virtual void cleanup();
public Q_SLOTS:
void perform(QuickFixOperationPtr op);
private:
CppTools::CppModelManagerInterface *_modelManager;
CPPEditor *_editor;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment