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