forked from qt-creator/qt-creator
Generic highlighter: Prevent overlapping in the mime type registration.
Also add a progress bar for the registration process.
This commit is contained in:
@@ -70,9 +70,13 @@
|
||||
using namespace TextEditor;
|
||||
using namespace Internal;
|
||||
|
||||
Manager::Manager() : m_downloadingDefinitions(false)
|
||||
Manager::Manager() :
|
||||
m_downloadingDefinitions(false),
|
||||
m_registeringMimeTypes(false),
|
||||
m_queuedMimeTypeRegistrations(0)
|
||||
{
|
||||
connect(&m_mimeTypeWatcher, SIGNAL(resultReadyAt(int)), this, SLOT(registerMimeType(int)));
|
||||
connect(&m_mimeTypeWatcher, SIGNAL(finished()), this, SLOT(registerMimeTypesFinished()));
|
||||
connect(&m_downloadWatcher, SIGNAL(finished()), this, SLOT(downloadDefinitionsFinished()));
|
||||
}
|
||||
|
||||
@@ -138,10 +142,19 @@ bool Manager::isBuildingDefinition(const QString &id) const
|
||||
|
||||
void Manager::registerMimeTypes()
|
||||
{
|
||||
clear();
|
||||
QFuture<Core::MimeType> future =
|
||||
if (!m_registeringMimeTypes) {
|
||||
m_registeringMimeTypes = true;
|
||||
clear();
|
||||
QFuture<Core::MimeType> future =
|
||||
QtConcurrent::run(&Manager::gatherDefinitionsMimeTypes, this);
|
||||
m_mimeTypeWatcher.setFuture(future);
|
||||
m_mimeTypeWatcher.setFuture(future);
|
||||
Core::ICore::instance()->progressManager()->addTask(future,
|
||||
tr("Registering definitions"),
|
||||
Constants::TASK_REGISTER_DEFINITIONS);
|
||||
} else {
|
||||
// QFutures returned from QConcurrent::run cannot be cancelled. So the queue.
|
||||
++m_queuedMimeTypeRegistrations;
|
||||
}
|
||||
}
|
||||
|
||||
void Manager::gatherDefinitionsMimeTypes(QFutureInterface<Core::MimeType> &future)
|
||||
@@ -217,6 +230,15 @@ void Manager::registerMimeType(int index) const
|
||||
Core::ICore::instance()->mimeDatabase()->addMimeType(mimeType);
|
||||
}
|
||||
|
||||
void Manager::registerMimeTypesFinished()
|
||||
{
|
||||
m_registeringMimeTypes = false;
|
||||
if (m_queuedMimeTypeRegistrations > 0) {
|
||||
--m_queuedMimeTypeRegistrations;
|
||||
registerMimeTypes();
|
||||
}
|
||||
}
|
||||
|
||||
QSharedPointer<HighlightDefinitionMetaData> Manager::parseMetadata(const QFileInfo &fileInfo)
|
||||
{
|
||||
static const QLatin1Char kSemiColon(';');
|
||||
@@ -332,7 +354,7 @@ void Manager::downloadDefinitions(const QList<QUrl> &urls)
|
||||
m_downloadWatcher.setFuture(future);
|
||||
Core::ICore::instance()->progressManager()->addTask(future,
|
||||
tr("Downloading definitions"),
|
||||
Constants::TASK_DOWNLOAD);
|
||||
Constants::TASK_DOWNLOAD_DEFINITIONS);
|
||||
}
|
||||
|
||||
void Manager::downloadDefinitionsFinished()
|
||||
|
@@ -56,6 +56,8 @@ namespace Internal {
|
||||
class HighlightDefinition;
|
||||
class DefinitionDownloader;
|
||||
|
||||
// This is the generic highlighter manager. It is not thread-safe.
|
||||
|
||||
class Manager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -82,6 +84,7 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void registerMimeType(int index) const;
|
||||
void registerMimeTypesFinished();
|
||||
void downloadAvailableDefinitionsListFinished();
|
||||
void downloadDefinitionsFinished();
|
||||
|
||||
@@ -94,6 +97,10 @@ private:
|
||||
QList<HighlightDefinitionMetaData> parseAvailableDefinitionsList(QIODevice *device) const;
|
||||
void clear();
|
||||
|
||||
bool m_downloadingDefinitions;
|
||||
bool m_registeringMimeTypes;
|
||||
int m_queuedMimeTypeRegistrations;
|
||||
|
||||
QHash<QString, QString> m_idByName;
|
||||
QHash<QString, QString> m_idByMimeType;
|
||||
QHash<QString, QSharedPointer<HighlightDefinition> > m_definitions;
|
||||
@@ -101,7 +108,6 @@ private:
|
||||
QSet<QString> m_isBuilding;
|
||||
|
||||
QList<DefinitionDownloader *> m_downloaders;
|
||||
bool m_downloadingDefinitions;
|
||||
QNetworkAccessManager m_networkManager;
|
||||
|
||||
QFutureWatcher<void> m_downloadWatcher;
|
||||
|
@@ -88,7 +88,8 @@ const char * const GOTO_PREVIOUS_WORD_WITH_SELECTION = "TextEditor.GotoPreviousW
|
||||
const char * const GOTO_NEXT_WORD_WITH_SELECTION = "TextEditor.GotoNextWordWithSelection";
|
||||
const char * const C_TEXTEDITOR_MIMETYPE_TEXT = "text/plain";
|
||||
const char * const INFO_SYNTAX_DEFINITION = "TextEditor.InfoSyntaxDefinition";
|
||||
const char * const TASK_DOWNLOAD = "TextEditor.Task.Download";
|
||||
const char * const TASK_DOWNLOAD_DEFINITIONS = "TextEditor.Task.Download";
|
||||
const char * const TASK_REGISTER_DEFINITIONS = "TextEditor.Task.Register";
|
||||
|
||||
// Text color and style categories
|
||||
const char * const C_TEXT = "Text";
|
||||
|
Reference in New Issue
Block a user