59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
#include "editorviewhelper.h"
|
|
|
|
#include <QActionGroup>
|
|
#include <QApplication>
|
|
#include <QMenu>
|
|
|
|
#include <KActionMenu>
|
|
|
|
#include "ILexer.h"
|
|
#include "Lexilla.h"
|
|
|
|
const QMultiMap<QChar, QString> languages_group = std::visit([]() -> QMultiMap<QChar, QString> {
|
|
int lexerCount = GetLexerCount();
|
|
char buffer[114];
|
|
QMultiMap<QChar, QString> map;
|
|
for (int i = 0; i < lexerCount; i++) {
|
|
GetLexerName(i, buffer, 114);
|
|
QString lexerName(buffer);
|
|
map.insert(lexerName.at(0).toLower(), lexerName);
|
|
}
|
|
return map;
|
|
});
|
|
|
|
std::list<QChar> LexerGroupActionMenu::groups()
|
|
{
|
|
QList<QChar> keys = languages_group.keys();
|
|
std::list<QChar> keysLst(keys.constBegin(), keys.constEnd());
|
|
keysLst.unique();
|
|
return keysLst;
|
|
}
|
|
|
|
QString LexerGroupActionMenu::displayName(const QString &lexerName)
|
|
{
|
|
static const QHash<QString, QString> displayNameMap {
|
|
{"cpp", "C++"},
|
|
{"cmake", "CMake"},
|
|
{"hypertext", "HTML"},
|
|
{"powershell", "PowerShell"}
|
|
};
|
|
|
|
return displayNameMap.value(lexerName, lexerName);
|
|
}
|
|
|
|
void LexerGroupActionMenu::slotAboutToShow()
|
|
{
|
|
if (!m_group) {
|
|
m_group = new QActionGroup(menu());
|
|
} else {
|
|
return;
|
|
}
|
|
|
|
for (const QString & name : languages_group.values(m_languageGroup)) {
|
|
QAction *a = menu()->addAction(displayName(name), this, [this, name](){
|
|
emit lexerSelected(name);
|
|
});
|
|
a->setActionGroup(m_group);
|
|
}
|
|
}
|