forked from qt-creator/qt-creator
committed by
Thorbjørn Lindeijer
parent
b6ca8da0bd
commit
f3c2bbaabe
@@ -239,6 +239,9 @@ void Document::startSkippingBlocks(unsigned start)
|
|||||||
|
|
||||||
void Document::stopSkippingBlocks(unsigned stop)
|
void Document::stopSkippingBlocks(unsigned stop)
|
||||||
{
|
{
|
||||||
|
if (_skippedBlocks.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
unsigned start = _skippedBlocks.back().begin();
|
unsigned start = _skippedBlocks.back().begin();
|
||||||
if (start > stop)
|
if (start > stop)
|
||||||
_skippedBlocks.removeLast(); // Ignore this block, it's invalid.
|
_skippedBlocks.removeLast(); // Ignore this block, it's invalid.
|
||||||
|
@@ -69,6 +69,7 @@
|
|||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QMutexLocker>
|
#include <QtCore/QMutexLocker>
|
||||||
#include <QtCore/QTime>
|
#include <QtCore/QTime>
|
||||||
|
#include <QtCore/QTimer>
|
||||||
|
|
||||||
using namespace CppTools;
|
using namespace CppTools;
|
||||||
using namespace CppTools::Internal;
|
using namespace CppTools::Internal;
|
||||||
@@ -447,6 +448,12 @@ CppModelManager::CppModelManager(QObject *parent)
|
|||||||
ProjectExplorer::SessionManager *session = m_projectExplorer->session();
|
ProjectExplorer::SessionManager *session = m_projectExplorer->session();
|
||||||
QTC_ASSERT(session, return);
|
QTC_ASSERT(session, return);
|
||||||
|
|
||||||
|
m_updateEditorSelectionsTimer = new QTimer(this);
|
||||||
|
m_updateEditorSelectionsTimer->setInterval(500);
|
||||||
|
m_updateEditorSelectionsTimer->setSingleShot(true);
|
||||||
|
connect(m_updateEditorSelectionsTimer, SIGNAL(timeout()),
|
||||||
|
this, SLOT(updateEditorSelections()));
|
||||||
|
|
||||||
connect(session, SIGNAL(projectAdded(ProjectExplorer::Project*)),
|
connect(session, SIGNAL(projectAdded(ProjectExplorer::Project*)),
|
||||||
this, SLOT(onProjectAdded(ProjectExplorer::Project*)));
|
this, SLOT(onProjectAdded(ProjectExplorer::Project*)));
|
||||||
|
|
||||||
@@ -710,8 +717,8 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
|
|||||||
continue;
|
continue;
|
||||||
else if (lines.contains(m.line()))
|
else if (lines.contains(m.line()))
|
||||||
continue;
|
continue;
|
||||||
else if (lines.size() == MAX_SELECTION_COUNT)
|
//else if (lines.size() == MAX_SELECTION_COUNT)
|
||||||
break; // we're done.
|
//break; // we're done.
|
||||||
|
|
||||||
lines.insert(m.line());
|
lines.insert(m.line());
|
||||||
|
|
||||||
@@ -733,12 +740,42 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
|
|||||||
sel.cursor = c;
|
sel.cursor = c;
|
||||||
selections.append(sel);
|
selections.append(sel);
|
||||||
}
|
}
|
||||||
ed->setExtraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection, selections);
|
|
||||||
|
QList<Editor> todo;
|
||||||
|
foreach (Editor e, todo) {
|
||||||
|
if (e.widget != ed)
|
||||||
|
todo.append(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Editor e;
|
||||||
|
e.widget = ed;
|
||||||
|
e.selections = selections;
|
||||||
|
todo.append(e);
|
||||||
|
m_todo = todo;
|
||||||
|
postEditorUpdate();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CppModelManager::postEditorUpdate()
|
||||||
|
{
|
||||||
|
m_updateEditorSelectionsTimer->start(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CppModelManager::updateEditorSelections()
|
||||||
|
{
|
||||||
|
foreach (Editor ed, m_todo) {
|
||||||
|
if (! ed.widget)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ed.widget->setExtraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection,
|
||||||
|
ed.selections);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_todo.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void CppModelManager::onProjectAdded(ProjectExplorer::Project *)
|
void CppModelManager::onProjectAdded(ProjectExplorer::Project *)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
|
@@ -41,6 +41,8 @@
|
|||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QFutureInterface>
|
#include <QFutureInterface>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QTextEdit>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
class ICore;
|
class ICore;
|
||||||
@@ -49,6 +51,7 @@ class IEditor;
|
|||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
class ITextEditor;
|
class ITextEditor;
|
||||||
|
class BaseTextEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
@@ -86,6 +89,9 @@ public:
|
|||||||
|
|
||||||
void emitDocumentUpdated(CPlusPlus::Document::Ptr doc);
|
void emitDocumentUpdated(CPlusPlus::Document::Ptr doc);
|
||||||
|
|
||||||
|
void stopEditorSelectionsUpdate()
|
||||||
|
{ m_updateEditorSelectionsTimer->stop(); }
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void projectPathChanged(const QString &projectPath);
|
void projectPathChanged(const QString &projectPath);
|
||||||
|
|
||||||
@@ -102,6 +108,8 @@ private Q_SLOTS:
|
|||||||
void onAboutToRemoveProject(ProjectExplorer::Project *project);
|
void onAboutToRemoveProject(ProjectExplorer::Project *project);
|
||||||
void onSessionUnloaded();
|
void onSessionUnloaded();
|
||||||
void onProjectAdded(ProjectExplorer::Project *project);
|
void onProjectAdded(ProjectExplorer::Project *project);
|
||||||
|
void postEditorUpdate();
|
||||||
|
void updateEditorSelections();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<QString, QByteArray> buildWorkingCopyList();
|
QMap<QString, QByteArray> buildWorkingCopyList();
|
||||||
@@ -163,6 +171,15 @@ private:
|
|||||||
enum {
|
enum {
|
||||||
MAX_SELECTION_COUNT = 5
|
MAX_SELECTION_COUNT = 5
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Editor {
|
||||||
|
QPointer<TextEditor::BaseTextEditor> widget;
|
||||||
|
QList<QTextEdit::ExtraSelection> selections;
|
||||||
|
};
|
||||||
|
|
||||||
|
QList<Editor> m_todo;
|
||||||
|
|
||||||
|
QTimer *m_updateEditorSelectionsTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
|
|
||||||
#include <texteditor/itexteditor.h>
|
#include <texteditor/itexteditor.h>
|
||||||
|
#include <texteditor/basetexteditor.h>
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
@@ -68,12 +69,14 @@ void CppEditorSupport::setTextEditor(TextEditor::ITextEditor *textEditor)
|
|||||||
updateDocument();
|
updateDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CppEditorSupport::contents() const
|
QString CppEditorSupport::contents()
|
||||||
{
|
{
|
||||||
if (! _textEditor)
|
if (! _textEditor)
|
||||||
return QString();
|
return QString();
|
||||||
|
else if (! _cachedContents.isEmpty())
|
||||||
|
_cachedContents = _textEditor->contents();
|
||||||
|
|
||||||
return _textEditor->contents();
|
return _cachedContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CppEditorSupport::updateDocumentInterval() const
|
int CppEditorSupport::updateDocumentInterval() const
|
||||||
@@ -83,7 +86,20 @@ void CppEditorSupport::setUpdateDocumentInterval(int updateDocumentInterval)
|
|||||||
{ _updateDocumentInterval = updateDocumentInterval; }
|
{ _updateDocumentInterval = updateDocumentInterval; }
|
||||||
|
|
||||||
void CppEditorSupport::updateDocument()
|
void CppEditorSupport::updateDocument()
|
||||||
{ _updateDocumentTimer->start(_updateDocumentInterval); }
|
{
|
||||||
|
if (TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor*>(_textEditor->widget())) {
|
||||||
|
const QList<QTextEdit::ExtraSelection> selections =
|
||||||
|
edit->extraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection);
|
||||||
|
|
||||||
|
if (! selections.isEmpty())
|
||||||
|
edit->setExtraSelections(TextEditor::BaseTextEditor::CodeWarningsSelection,
|
||||||
|
QList<QTextEdit::ExtraSelection>());
|
||||||
|
|
||||||
|
_modelManager->stopEditorSelectionsUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
_updateDocumentTimer->start(_updateDocumentInterval);
|
||||||
|
}
|
||||||
|
|
||||||
void CppEditorSupport::updateDocumentNow()
|
void CppEditorSupport::updateDocumentNow()
|
||||||
{
|
{
|
||||||
@@ -91,7 +107,9 @@ void CppEditorSupport::updateDocumentNow()
|
|||||||
_updateDocumentTimer->start(_updateDocumentInterval);
|
_updateDocumentTimer->start(_updateDocumentInterval);
|
||||||
} else {
|
} else {
|
||||||
_updateDocumentTimer->stop();
|
_updateDocumentTimer->stop();
|
||||||
|
|
||||||
QStringList sourceFiles(_textEditor->file()->fileName());
|
QStringList sourceFiles(_textEditor->file()->fileName());
|
||||||
|
_cachedContents = _textEditor->contents();
|
||||||
_documentParser = _modelManager->refreshSourceFiles(sourceFiles);
|
_documentParser = _modelManager->refreshSourceFiles(sourceFiles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -65,7 +65,7 @@ public:
|
|||||||
int updateDocumentInterval() const;
|
int updateDocumentInterval() const;
|
||||||
void setUpdateDocumentInterval(int updateDocumentInterval);
|
void setUpdateDocumentInterval(int updateDocumentInterval);
|
||||||
|
|
||||||
QString contents() const;
|
QString contents();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void updateDocument();
|
void updateDocument();
|
||||||
@@ -79,6 +79,7 @@ private:
|
|||||||
QTimer *_updateDocumentTimer;
|
QTimer *_updateDocumentTimer;
|
||||||
int _updateDocumentInterval;
|
int _updateDocumentInterval;
|
||||||
QFuture<void> _documentParser;
|
QFuture<void> _documentParser;
|
||||||
|
QString _cachedContents;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user