play around with Scintilla and Lexilla
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include "sciedit.h"
|
||||
#include "appsettings.h"
|
||||
#include "editorviewhelper.h"
|
||||
|
||||
@ -17,12 +18,12 @@
|
||||
#include <KColorSchemeMenu>
|
||||
#include <QSpinBox>
|
||||
|
||||
#include <Qsci/qsciscintilla.h>
|
||||
#include <Qsci/qscilexer.h>
|
||||
#include <ILexer.h>
|
||||
#include <Lexilla.h>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: KXmlGuiWindow(parent)
|
||||
, m_editor(new QsciScintilla(this))
|
||||
, m_editor(new SciEdit(this))
|
||||
, m_cursorPosStatusLabel(new QLabel(QString("Ln: ? Col: ?")))
|
||||
{
|
||||
setCentralWidget(m_editor);
|
||||
@ -30,21 +31,19 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
statusBar()->addPermanentWidget(m_cursorPosStatusLabel);
|
||||
|
||||
QFont font(AppSettings::self()->editorFont());
|
||||
m_editor->setFont(font);
|
||||
m_editor->setMarginsFont(font);
|
||||
m_editor->setStyleFont(font);
|
||||
m_editor->setStyleFont(font, STYLE_LINENUMBER);
|
||||
|
||||
m_editor->setMarginLineNumbers(1, true);
|
||||
m_editor->setMarginWidth(1, 40);
|
||||
m_editor->setFolding(QsciScintilla::BoxedTreeFoldStyle);
|
||||
m_editor->setBraceMatching(QsciScintilla::SloppyBraceMatch);
|
||||
m_editor->setMarginTypeN(1, SC_MARGIN_NUMBER);
|
||||
m_editor->setMarginWidthN(1, m_editor->textWidth(STYLE_LINENUMBER, "_99999"));
|
||||
m_editor->setFolding(SciEdit::BoxFoldType);
|
||||
// m_editor->setBraceMatching(QsciScintilla::SloppyBraceMatch);
|
||||
|
||||
m_editor->setTabWidth(AppSettings::self()->tabWidth());
|
||||
m_editor->setEolMode(QsciScintilla::EolUnix);
|
||||
m_editor->setEOLMode(SC_EOL_LF);
|
||||
|
||||
connect(m_editor, &QsciScintilla::cursorPositionChanged, this, [this](int line, int index){
|
||||
// FIXME: not get called at all?
|
||||
qDebug() << line << index;
|
||||
m_cursorPosStatusLabel->setText(QString("Ln: %1 Col: %2").arg(line, index));
|
||||
connect(m_editor, &SciEdit::cursorPosChanged, this, [this](int line, int index){
|
||||
m_cursorPosStatusLabel->setText(QString("Ln: %1 Col: %2").arg(line).arg(index));
|
||||
});
|
||||
|
||||
setupActions();
|
||||
@ -94,14 +93,12 @@ void MainWindow::setupActions()
|
||||
lexerNoneAction->setText("None (Normal Text)");
|
||||
actionCollection()->addAction(u"lexer_none"_s, lexerNoneAction);
|
||||
connect(lexerNoneAction, &QAction::triggered, this, [this](){
|
||||
m_editor->setLexer(nullptr);
|
||||
// m_editor->setLexer(nullptr);
|
||||
});
|
||||
|
||||
for (int i = 0; i <= LexerGroupActionMenu::LANG_GRP_LAST; i++) {
|
||||
LexerGroupActionMenu::LanguageGroup group = static_cast<LexerGroupActionMenu::LanguageGroup>(i);
|
||||
const QString groupName(LexerGroupActionMenu::groupName(group));
|
||||
LexerGroupActionMenu *lexerGroupMenu = new LexerGroupActionMenu(groupName, group, this);
|
||||
actionCollection()->addAction(QStringLiteral("lexer_group_") % groupName.toLower(), lexerGroupMenu);
|
||||
for (const QChar & group : LexerGroupActionMenu::groups()) {
|
||||
LexerGroupActionMenu *lexerGroupMenu = new LexerGroupActionMenu(group.toUpper(), group, this);
|
||||
actionCollection()->addAction(QStringLiteral("lexer_group_") % group, lexerGroupMenu);
|
||||
connect(lexerGroupMenu, &LexerGroupActionMenu::lexerSelected, this, &MainWindow::applyLexer);
|
||||
}
|
||||
|
||||
@ -121,8 +118,8 @@ void MainWindow::setupActions()
|
||||
toggleWrapModeAction->setCheckable(true);
|
||||
actionCollection()->addAction(u"toggle_wrap_mode"_s, toggleWrapModeAction);
|
||||
connect(toggleWrapModeAction, &QAction::triggered, this, [this, toggleWrapModeAction](){
|
||||
bool switchToWrapNone = m_editor->wrapMode() == QsciScintilla::WrapWord;
|
||||
m_editor->setWrapMode(switchToWrapNone ? QsciScintilla::WrapNone : QsciScintilla::WrapWord);
|
||||
bool switchToWrapNone = m_editor->wrapMode() == SC_WRAP_WORD;
|
||||
m_editor->setWrapMode(switchToWrapNone ? SC_WRAP_NONE : SC_WRAP_WORD);
|
||||
toggleWrapModeAction->setChecked(!switchToWrapNone);
|
||||
});
|
||||
|
||||
@ -132,9 +129,9 @@ void MainWindow::setupActions()
|
||||
// toggleWhitespaceVisibilityAction->setIcon(QIcon::fromTheme(u"text-wrap"_s));
|
||||
actionCollection()->addAction(u"toggle_show_all_characters"_s, toggleWhitespaceVisibilityAction);
|
||||
connect(toggleWhitespaceVisibilityAction, &QAction::triggered, this, [this, toggleWhitespaceVisibilityAction](){
|
||||
bool switchToVisible = m_editor->whitespaceVisibility() == QsciScintilla::WsInvisible;
|
||||
m_editor->setWhitespaceVisibility(switchToVisible ? QsciScintilla::WsVisible : QsciScintilla::WsInvisible);
|
||||
m_editor->setEolVisibility(switchToVisible);
|
||||
bool switchToVisible = m_editor->viewWS() == SCWS_INVISIBLE;
|
||||
m_editor->setViewWS(switchToVisible ? SCWS_VISIBLEALWAYS : SCWS_INVISIBLE);
|
||||
m_editor->setViewEOL(switchToVisible);
|
||||
toggleWhitespaceVisibilityAction->setChecked(switchToVisible);
|
||||
});
|
||||
|
||||
@ -143,7 +140,7 @@ void MainWindow::setupActions()
|
||||
toggleIndentGuideAction->setIcon(QIcon::fromTheme(u"show-guides"_s));
|
||||
actionCollection()->addAction(u"toggle_indent_guide"_s, toggleIndentGuideAction);
|
||||
connect(toggleIndentGuideAction, &QAction::triggered, this, [this](){
|
||||
m_editor->setIndentationGuides(!m_editor->indentationGuides());
|
||||
// m_editor->setIndentationGuides(!m_editor->indentationGuides());
|
||||
});
|
||||
|
||||
// Load themes
|
||||
@ -171,11 +168,8 @@ void MainWindow::showSettings()
|
||||
dialog->show();
|
||||
}
|
||||
|
||||
void MainWindow::applyLexer(const QString &lexer)
|
||||
void MainWindow::applyLexer(const QString &lexerName)
|
||||
{
|
||||
QsciLexer * ret = LexerGroupActionMenu::createLexerByLanguage(lexer);
|
||||
if (ret) {
|
||||
ret->setFont(AppSettings::self()->editorFont());
|
||||
}
|
||||
m_editor->setLexer(ret);
|
||||
Scintilla::ILexer5 * lexer = CreateLexer(lexerName.toStdString().c_str());
|
||||
m_editor->setLexer(lexer);
|
||||
}
|
||||
|
Reference in New Issue
Block a user