Commit 8fd0777a authored by Roberto Raggi's avatar Roberto Raggi

Ensure the document is updated before invoking a quickfix.

parent 8e16ea71
......@@ -1308,6 +1308,14 @@ Symbol *CPPEditor::findDefinition(Symbol *symbol)
return 0;
}
bool CPPEditor::isOutdated() const
{
if (m_lastSemanticInfo.revision != document()->revision())
return true;
return false;
}
SemanticInfo CPPEditor::semanticInfo() const
{
return m_lastSemanticInfo;
......
......@@ -185,6 +185,7 @@ public:
void indentInsertedText(const QTextCursor &tc);
bool isOutdated() const;
SemanticInfo semanticInfo() const;
public Q_SLOTS:
......
......@@ -57,10 +57,14 @@
#include <QtCore/QFileInfo>
#include <QtCore/QSettings>
#include <QtCore/QTimer>
#include <QtGui/QMenu>
using namespace CppEditor::Internal;
enum { QUICKFIX_INTERVAL = 20 };
//////////////////////////// CppEditorFactory /////////////////////////////
CppEditorFactory::CppEditorFactory(CppPlugin *owner) :
......@@ -132,6 +136,11 @@ CppPlugin::CppPlugin() :
{
m_instance = this;
m_quickFixTimer = new QTimer(this);
m_quickFixTimer->setInterval(20);
m_quickFixTimer->setSingleShot(true);
connect(m_quickFixTimer, SIGNAL(timeout()), this, SLOT(quickFixNow()));
}
CppPlugin::~CppPlugin()
......@@ -152,12 +161,12 @@ void CppPlugin::initializeEditor(CPPEditor *editor)
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
// auto completion
connect(editor, SIGNAL(requestAutoCompletion(ITextEditable*, bool)),
TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(ITextEditable*, bool)));
connect(editor, SIGNAL(requestAutoCompletion(TextEditor::ITextEditable*, bool)),
TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(TextEditor::ITextEditable*, bool)));
// quick fix
connect(editor, SIGNAL(requestQuickFix(ITextEditable*)),
TextEditor::Internal::CompletionSupport::instance(), SLOT(quickFix(ITextEditable*)));
connect(editor, SIGNAL(requestQuickFix(TextEditor::ITextEditable*)),
this, SLOT(quickFix(TextEditor::ITextEditable*)));
// method combo box sorting
connect(this, SIGNAL(methodOverviewSortingChanged(bool)),
......@@ -329,6 +338,30 @@ void CppPlugin::findUsages()
editor->findUsages();
}
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);
}
}
}
void CppPlugin::onTaskStarted(const QString &type)
{
if (type == CppTools::Constants::TASK_INDEX) {
......
......@@ -39,6 +39,7 @@
namespace TextEditor {
class TextEditorActionHandler;
class ITextEditable;
} // namespace TextEditor
namespace CppEditor {
......@@ -78,6 +79,8 @@ private slots:
void onTaskStarted(const QString &type);
void onAllTasksFinished(const QString &type);
void findUsages();
void quickFix(TextEditor::ITextEditable *editable);
void quickFixNow();
private:
Core::IEditor *createEditor(QWidget *parent);
......@@ -91,6 +94,9 @@ private:
QAction *m_renameSymbolUnderCursorAction;
QAction *m_findUsagesAction;
QAction *m_updateCodeModelAction;
QTimer *m_quickFixTimer;
QPointer<TextEditor::ITextEditable> m_currentTextEditable;
};
class CppEditorFactory : public Core::IEditorFactory
......
......@@ -174,8 +174,8 @@ void QmlEditorPlugin::initializeEditor(QmlEditor::Internal::ScriptEditor *editor
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
// auto completion
connect(editor, SIGNAL(requestAutoCompletion(ITextEditable*, bool)),
TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(ITextEditable*, bool)));
connect(editor, SIGNAL(requestAutoCompletion(TextEditor::ITextEditable*, bool)),
TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(TextEditor::ITextEditable*, bool)));
}
Q_EXPORT_PLUGIN(QmlEditorPlugin)
......@@ -140,8 +140,8 @@ void QtScriptEditorPlugin::initializeEditor(QtScriptEditor::Internal::ScriptEdit
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
// auto completion
connect(editor, SIGNAL(requestAutoCompletion(ITextEditable*, bool)),
TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(ITextEditable*, bool)));
connect(editor, SIGNAL(requestAutoCompletion(TextEditor::ITextEditable*, bool)),
TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(TextEditor::ITextEditable*, bool)));
}
void QtScriptEditorPlugin::registerActions()
......
......@@ -573,8 +573,8 @@ protected slots:
signals:
void requestFontSize(int pointSize);
void requestBlockUpdate(const QTextBlock &);
void requestAutoCompletion(ITextEditable *editor, bool forced);
void requestQuickFix(ITextEditable *editor);
void requestAutoCompletion(TextEditor::ITextEditable *editor, bool forced);
void requestQuickFix(TextEditor::ITextEditable *editor);
private:
void indentOrUnindent(bool doIndent);
......
......@@ -56,8 +56,8 @@ public:
static CompletionSupport *instance();
public slots:
void autoComplete(ITextEditable *editor, bool forced);
void quickFix(ITextEditable *editor);
void autoComplete(TextEditor::ITextEditable *editor, bool forced);
void quickFix(TextEditor::ITextEditable *editor);
private slots:
void performCompletion(const TextEditor::CompletionItem &item);
......
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