diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2009-11-18 15:06:26 +0100 |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2009-11-18 15:15:00 +0100 |
commit | 8fd0777ab05537c37679d9a7f3b399cc8c1ae0ea (patch) | |
tree | d26783c3a653e7b5a2b094f5588be6706efdaa1a /src/plugins | |
parent | 8e16ea717a28b9ae80d9947405461ac665cfd1fc (diff) | |
download | qt-creator-8fd0777ab05537c37679d9a7f3b399cc8c1ae0ea.tar.gz |
Ensure the document is updated before invoking a quickfix.
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/cppeditor/cppeditor.cpp | 8 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppeditor.h | 1 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppplugin.cpp | 41 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppplugin.h | 6 | ||||
-rw-r--r-- | src/plugins/qmleditor/qmleditorplugin.cpp | 4 | ||||
-rw-r--r-- | src/plugins/qtscripteditor/qtscripteditorplugin.cpp | 4 | ||||
-rw-r--r-- | src/plugins/texteditor/basetexteditor.h | 4 | ||||
-rw-r--r-- | src/plugins/texteditor/completionsupport.h | 4 |
8 files changed, 60 insertions, 12 deletions
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 4bba1e21a5..696600b8ec 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -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; diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h index 9518e27a21..bc00864224 100644 --- a/src/plugins/cppeditor/cppeditor.h +++ b/src/plugins/cppeditor/cppeditor.h @@ -185,6 +185,7 @@ public: void indentInsertedText(const QTextCursor &tc); + bool isOutdated() const; SemanticInfo semanticInfo() const; public Q_SLOTS: diff --git a/src/plugins/cppeditor/cppplugin.cpp b/src/plugins/cppeditor/cppplugin.cpp index 36883d5450..b93408df19 100644 --- a/src/plugins/cppeditor/cppplugin.cpp +++ b/src/plugins/cppeditor/cppplugin.cpp @@ -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) { diff --git a/src/plugins/cppeditor/cppplugin.h b/src/plugins/cppeditor/cppplugin.h index 25687c300e..7e8ea29b67 100644 --- a/src/plugins/cppeditor/cppplugin.h +++ b/src/plugins/cppeditor/cppplugin.h @@ -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 diff --git a/src/plugins/qmleditor/qmleditorplugin.cpp b/src/plugins/qmleditor/qmleditorplugin.cpp index 078e88a719..f7c629bc8b 100644 --- a/src/plugins/qmleditor/qmleditorplugin.cpp +++ b/src/plugins/qmleditor/qmleditorplugin.cpp @@ -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) diff --git a/src/plugins/qtscripteditor/qtscripteditorplugin.cpp b/src/plugins/qtscripteditor/qtscripteditorplugin.cpp index 266d2d4820..2d328db2d6 100644 --- a/src/plugins/qtscripteditor/qtscripteditorplugin.cpp +++ b/src/plugins/qtscripteditor/qtscripteditorplugin.cpp @@ -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() diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index fbd1e977e7..87cf828f45 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -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); diff --git a/src/plugins/texteditor/completionsupport.h b/src/plugins/texteditor/completionsupport.h index 78e00ad8e5..4b531413e1 100644 --- a/src/plugins/texteditor/completionsupport.h +++ b/src/plugins/texteditor/completionsupport.h @@ -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); |