Skip to content
Snippets Groups Projects
Commit a534c271 authored by Leandro Melo's avatar Leandro Melo
Browse files

Generic highlighter: Add Creator's share folder in the fallback definitions search.

This leaves the code prepared if we decide to ship some of the Kate XMLs (still
a pending decision). In this case the installer needs to be "notified" and the
Kate files put in the repo.

An addition check for actual XML files in the searched directories is also added.

Reviewed-by: con
Reviewed-by: Thorbjorn Lindeijer
parent b5edda3c
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,8 @@ DATA_DIRS = \
qmlicons \
qml \
qml-type-descriptions \
qmljsdebugger
qmljsdebugger \
generic-highlighter
!isEmpty(copydata) {
......
......@@ -36,6 +36,7 @@
#include <QtCore/QLatin1Char>
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QStringList>
#ifdef Q_OS_UNIX
#include <QtCore/QProcess>
#endif
......@@ -43,8 +44,11 @@
namespace TextEditor {
namespace Internal {
QString findDefinitionsLocation()
QString findFallbackDefinitionsLocation()
{
QDir dir;
dir.setNameFilters(QStringList(QLatin1String("*.xml")));
#ifdef Q_OS_UNIX
static const QLatin1String kateSyntax[] = {
QLatin1String("/share/apps/katepart/syntax"),
......@@ -54,7 +58,6 @@ QString findDefinitionsLocation()
sizeof(kateSyntax) / sizeof(kateSyntax[0]);
// Some wild guesses.
QDir dir;
for (int i = 0; i < kateSyntaxCount; ++i) {
QStringList paths;
paths << QLatin1String("/usr") + kateSyntax[i]
......@@ -62,7 +65,7 @@ QString findDefinitionsLocation()
<< QLatin1String("/opt") + kateSyntax[i];
foreach (const QString &path, paths) {
dir.setPath(path);
if (dir.exists())
if (dir.exists() && !dir.entryInfoList().isEmpty())
return dir.path();
}
}
......@@ -79,13 +82,17 @@ QString findDefinitionsLocation()
output.remove(QLatin1Char('\n'));
for (int i = 0; i < kateSyntaxCount; ++i) {
dir.setPath(output + kateSyntax[i]);
if (dir.exists())
if (dir.exists() && !dir.entryInfoList().isEmpty())
return dir.path();
}
}
}
#endif
dir.setPath(Core::ICore::instance()->resourcePath() + QLatin1String("/generic-highlighter"));
if (dir.exists() && !dir.entryInfoList().isEmpty())
return dir.path();
return QString();
}
......@@ -139,7 +146,7 @@ void HighlighterSettings::fromSettings(const QString &category, QSettings *s)
else
m_definitionFilesPath = s->value(kDefinitionFilesPath).toString();
if (!s->contains(kFallbackDefinitionFilesPath)) {
m_fallbackDefinitionFilesPath = findDefinitionsLocation();
m_fallbackDefinitionFilesPath = findFallbackDefinitionsLocation();
if (m_fallbackDefinitionFilesPath.isEmpty())
m_useFallbackLocation = false;
else
......
......@@ -88,7 +88,7 @@ inline bool operator!=(const HighlighterSettings &a, const HighlighterSettings &
{ return !a.equals(b); }
namespace Internal {
QString findDefinitionsLocation();
QString findFallbackDefinitionsLocation();
}
} // namespace TextEditor
......
......@@ -171,7 +171,7 @@ void HighlighterSettingsPage::settingsToUI()
void HighlighterSettingsPage::resetDefinitionsLocation()
{
const QString &location = findDefinitionsLocation();
const QString &location = findFallbackDefinitionsLocation();
if (location.isEmpty())
QMessageBox::information(0, tr("Autodetect Definitions"),
tr("No pre-installed definitions could be found."));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment