pineapple-notepad/editorviewhelper.cpp

59 lines
1.5 KiB
C++
Raw Normal View History

2024-06-30 12:51:22 +08:00
#include "editorviewhelper.h"
#include <QActionGroup>
#include <QApplication>
#include <QMenu>
#include <KActionMenu>
2024-07-02 23:47:26 +08:00
#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);
2024-06-30 12:51:22 +08:00
}
2024-07-02 23:47:26 +08:00
return map;
});
2024-06-30 12:51:22 +08:00
2024-07-02 23:47:26 +08:00
std::list<QChar> LexerGroupActionMenu::groups()
{
QList<QChar> keys = languages_group.keys();
std::list<QChar> keysLst(keys.constBegin(), keys.constEnd());
keysLst.unique();
return keysLst;
2024-06-30 12:51:22 +08:00
}
2024-07-02 23:47:26 +08:00
QString LexerGroupActionMenu::displayName(const QString &lexerName)
2024-06-30 12:51:22 +08:00
{
2024-07-02 23:47:26 +08:00
static const QHash<QString, QString> displayNameMap {
{"cpp", "C++"},
{"cmake", "CMake"},
{"hypertext", "HTML"},
{"powershell", "PowerShell"}
};
return displayNameMap.value(lexerName, lexerName);
2024-06-30 12:51:22 +08:00
}
void LexerGroupActionMenu::slotAboutToShow()
{
if (!m_group) {
m_group = new QActionGroup(menu());
} else {
return;
}
2024-07-02 23:47:26 +08:00
for (const QString & name : languages_group.values(m_languageGroup)) {
QAction *a = menu()->addAction(displayName(name), this, [this, name](){
2024-06-30 12:51:22 +08:00
emit lexerSelected(name);
});
a->setActionGroup(m_group);
}
}