26 #include "katesyntaxmanager.moc"
39 #include <kconfiggroup.h>
41 #include <kcomponentdata.h>
42 #include <kmimetype.h>
45 #include <kcolorscheme.h>
46 #include <kcolorutils.h>
48 #include <kstandarddirs.h>
49 #include <kmessagebox.h>
50 #include <kapplication.h>
52 #include <QtCore/QSet>
53 #include <QtGui/QAction>
54 #include <QtCore/QStringList>
55 #include <QtCore/QTextStream>
58 using namespace KTextEditor;
63 if (comparison == 0) {
66 return comparison < 0;
72 , m_config (
"katesyntaxhighlightingrc", KConfig::NoGlobals)
73 , commonSuffixes (
QString(
".orig;.new;~;.bak;.BAK").split(
';'))
76 , forceNoDCReset(false)
81 for (
int i=0; i < modeList.
count(); i++)
94 lastCtxsReset.
start();
110 if (n < 0 || n >= hlList.
count())
118 for(
int i = 0; i < hlList.
count(); ++i) {
119 if (hlList.
at(i)->name().compare(name, Qt::CaseInsensitive) == 0) {
141 names <<
"Data Type";
142 names <<
"Decimal/Value";
143 names <<
"Base-N Integer";
144 names <<
"Floating Point";
145 names <<
"Character";
152 names <<
"Region Marker";
156 translatedNames <<
i18nc(
"@item:intable Text context",
"Normal");
157 translatedNames <<
i18nc(
"@item:intable Text context",
"Keyword");
158 translatedNames <<
i18nc(
"@item:intable Text context",
"Data Type");
159 translatedNames <<
i18nc(
"@item:intable Text context",
"Decimal/Value");
160 translatedNames <<
i18nc(
"@item:intable Text context",
"Base-N Integer");
161 translatedNames <<
i18nc(
"@item:intable Text context",
"Floating Point");
162 translatedNames <<
i18nc(
"@item:intable Text context",
"Character");
163 translatedNames <<
i18nc(
"@item:intable Text context",
"String");
164 translatedNames <<
i18nc(
"@item:intable Text context",
"Comment");
165 translatedNames <<
i18nc(
"@item:intable Text context",
"Others");
166 translatedNames <<
i18nc(
"@item:intable Text context",
"Alert");
167 translatedNames <<
i18nc(
"@item:intable Text context",
"Function");
169 translatedNames <<
i18nc(
"@item:intable Text context",
"Region Marker");
171 translatedNames <<
i18nc(
"@item:intable Text context",
"Error");
174 return translateNames ? translatedNames[n] : names[n];
179 KColorScheme scheme(QPalette::Active, KColorScheme::View);
180 KColorScheme schemeSelected(QPalette::Active, KColorScheme::Selection);
186 Attribute::Ptr attrib(
new KTextEditor::Attribute());
187 attrib->setForeground( scheme.foreground().color() );
188 attrib->setSelectedForeground( schemeSelected.foreground().color() );
192 Attribute::Ptr attrib(
new KTextEditor::Attribute());
193 attrib->setForeground( scheme.foreground().color() );
194 attrib->setSelectedForeground( schemeSelected.foreground().color() );
195 attrib->setFontBold(
true);
199 Attribute::Ptr attrib(
new KTextEditor::Attribute());
200 attrib->setForeground( scheme.foreground(KColorScheme::LinkText).color() );
201 attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::LinkText).color() );
205 Attribute::Ptr attrib(
new KTextEditor::Attribute());
206 attrib->setForeground( scheme.foreground(KColorScheme::NeutralText).color() );
207 attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NeutralText).color() );
211 Attribute::Ptr attrib(
new KTextEditor::Attribute());
212 attrib->setForeground( scheme.foreground(KColorScheme::NeutralText).color() );
213 attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NeutralText).color() );
217 Attribute::Ptr attrib(
new KTextEditor::Attribute());
218 attrib->setForeground( scheme.foreground(KColorScheme::NeutralText).color() );
219 attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NeutralText).color() );
223 Attribute::Ptr attrib(
new KTextEditor::Attribute());
224 attrib->setForeground( scheme.foreground(KColorScheme::ActiveText).color() );
225 attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::ActiveText).color() );
229 Attribute::Ptr attrib(
new KTextEditor::Attribute());
230 attrib->setForeground( scheme.foreground(KColorScheme::NegativeText).color() );
231 attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NegativeText).color() );
235 Attribute::Ptr attrib(
new KTextEditor::Attribute());
236 attrib->setForeground( scheme.foreground(KColorScheme::InactiveText).color() );
237 attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::InactiveText).color() );
241 Attribute::Ptr attrib(
new KTextEditor::Attribute());
242 attrib->setForeground( scheme.foreground(KColorScheme::PositiveText).color() );
243 attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::PositiveText).color() );
247 Attribute::Ptr attrib(
new KTextEditor::Attribute());
248 attrib->setForeground( scheme.foreground(KColorScheme::NegativeText).color() );
249 attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NegativeText).color() );
250 attrib->setFontBold(
true);
251 attrib->setBackground( scheme.background(KColorScheme::NegativeBackground).color() );
255 Attribute::Ptr attrib(
new KTextEditor::Attribute());
256 attrib->setForeground( scheme.foreground(KColorScheme::VisitedText).color() );
257 attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::VisitedText).color() );
261 Attribute::Ptr attrib(
new KTextEditor::Attribute());
262 attrib->setForeground( scheme.foreground(KColorScheme::LinkText).color() );
263 attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::LinkText).color() );
264 attrib->setBackground( scheme.background(KColorScheme::LinkBackground).color() );
268 Attribute::Ptr attrib(
new KTextEditor::Attribute());
269 attrib->setForeground( scheme.foreground(KColorScheme::NegativeText) );
270 attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NegativeText).color() );
271 attrib->setFontUnderline(
true);
276 "Default Item Styles - Schema " + schema);
280 KTextEditor::Attribute::Ptr i = list.
at(z);
290 tmp=s[0];
if (!tmp.
isEmpty()) {
293 tmp=s[1];
if (!tmp.
isEmpty()) {
294 col=tmp.
toUInt(0,16); i->setSelectedForeground(
QColor(col)); }
296 tmp=s[2];
if (!tmp.
isEmpty()) i->setFontBold(tmp!=
"0");
298 tmp=s[3];
if (!tmp.
isEmpty()) i->setFontItalic(tmp!=
"0");
300 tmp=s[4];
if (!tmp.
isEmpty()) i->setFontStrikeOut(tmp!=
"0");
302 tmp=s[5];
if (!tmp.
isEmpty()) i->setFontUnderline(tmp!=
"0");
304 tmp=s[6];
if (!tmp.
isEmpty()) {
308 i->setBackground(
QColor(col));
311 i->clearBackground();
313 tmp=s[7];
if (!tmp.
isEmpty()) {
317 i->setSelectedBackground(
QColor(col));
320 i->clearProperty(KTextEditor::Attribute::SelectedBackground);
330 KConfigGroup config(cfg,
331 "Default Item Styles - Schema " + schema);
336 KTextEditor::Attribute::Ptr p = list.
at(z);
338 settings<<(p->hasProperty(QTextFormat::ForegroundBrush)?
QString::number(p->foreground().color().rgb(),16):
"");
339 settings<<(p->hasProperty(KTextEditor::Attribute::SelectedForeground)?
QString::number(p->selectedForeground().color().rgb(),16):
"");
340 settings<<(p->hasProperty(QTextFormat::FontWeight)?(p->fontBold()?
"1":
"0"):
"");
341 settings<<(p->hasProperty(QTextFormat::FontItalic)?(p->fontItalic()?
"1":
"0"):
"");
342 settings<<(p->hasProperty(QTextFormat::FontStrikeOut)?(p->fontStrikeOut()?
"1":
"0"):
"");
343 settings<<(p->hasProperty(QTextFormat::FontUnderline)?(p->fontUnderline()?
"1":
"0"):
"");
344 settings<<(p->hasProperty(QTextFormat::BackgroundBrush)?
QString::number(p->background().color().rgb(),16):
"-");
345 settings<<(p->hasProperty(KTextEditor::Attribute::SelectedBackground)?
QString::number(p->selectedBackground().color().rgb(),16):
"-");
346 settings<<(p->hasProperty(QTextFormat::FontFamily)?(p->fontFamily()):
QString());
357 return (
int) hlList.
count();
362 return hlList.
at(n)->name();
367 return hlList.
at(n)->nameTranslated();
372 return hlList.
at(n)->section();
377 return hlList.
at(n)->hidden();
383 return hlDict[name]->getIdentifier();
391 it != hlDict.
end(); ++it )
393 if ( (*it)->getIdentifier() == identifier ) {
412 dynamicCtxsCount = 0;
413 lastCtxsReset.
start();
iterator insert(const Key &key, const T &value)
bool compareKateHighlighting(const KateHighlighting *const left, const KateHighlighting *const right)
QScriptValue i18nc(QScriptContext *context, QScriptEngine *engine)
i18nc("context", "text", arguments [optional])
friend class KateHighlighting
QString nameForIdentifier(const QString &)
Returns the mode name for a given identifier, as e.g.
const T & at(int i) const
static KateGlobal * self()
Kate Part Internal stuff ;)
QString hlNameTranslated(int n)
const QString & nameTranslated() const
static QString defaultStyleName(int n, bool translateNames=false)
QString number(int n, int base)
int count(const T &value) const
void append(const T &value)
const QString & section() const
static uint defaultStyles()
const KateSyntaxModeList & modeList()
Get the mode list.
void setDefaults(const QString &schema, KateAttributeList &, KConfig *cfg=0)
Store and manage the information about Syntax Highlighting.
#define KATE_DYNAMIC_CONTEXTS_RESET_DELAY
KateHlManager * hlManager()
hl manager
KateHighlighting * getHl(int n)
void insert(int i, const T &value)
int nameFind(const QString &name)
void getDefaults(const QString &schema, KateAttributeList &, KConfig *cfg=0)
void prepend(const T &value)
bool contains(const Key &key) const
const QString & name() const
void dropDynamicContexts()
Drop all dynamic contexts.
QString identifierForName(const QString &)
int compare(const QString &other) const
static KateHlManager * self()
uint toUInt(bool *ok, int base) const