2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) Filippo Cucchetto <filippocucchetto@gmail.com>
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2015-08-26 09:37:55 +02:00
|
|
|
|
|
|
|
|
#include "nimcodestylepreferenceswidget.h"
|
|
|
|
|
#include "ui_nimcodestylepreferenceswidget.h"
|
|
|
|
|
|
2016-06-14 20:33:55 +03:00
|
|
|
#include "../nimconstants.h"
|
2017-04-24 15:52:04 +02:00
|
|
|
#include "../editor/nimeditorfactory.h"
|
2015-08-26 09:37:55 +02:00
|
|
|
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
#include <texteditor/displaysettings.h>
|
|
|
|
|
#include <texteditor/fontsettings.h>
|
|
|
|
|
#include <texteditor/icodestylepreferences.h>
|
|
|
|
|
#include <texteditor/indenter.h>
|
|
|
|
|
#include <texteditor/tabsettings.h>
|
|
|
|
|
#include <texteditor/textdocument.h>
|
|
|
|
|
#include <texteditor/texteditorsettings.h>
|
2017-04-24 15:52:04 +02:00
|
|
|
#include <texteditor/snippets/snippetprovider.h>
|
2015-08-26 09:37:55 +02:00
|
|
|
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
|
|
|
|
|
namespace Nim {
|
|
|
|
|
|
|
|
|
|
NimCodeStylePreferencesWidget::NimCodeStylePreferencesWidget(ICodeStylePreferences *preferences, QWidget *parent)
|
2022-03-29 15:48:15 +02:00
|
|
|
: TextEditor::CodeStyleEditorWidget(parent)
|
2015-08-26 09:37:55 +02:00
|
|
|
, m_preferences(preferences)
|
|
|
|
|
, m_ui(new Ui::NimCodeStylePreferencesWidget())
|
|
|
|
|
{
|
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
m_ui->tabPreferencesWidget->setPreferences(preferences);
|
|
|
|
|
m_ui->previewTextEdit->setPlainText(Nim::Constants::C_NIMCODESTYLEPREVIEWSNIPPET);
|
|
|
|
|
|
|
|
|
|
decorateEditor(TextEditorSettings::fontSettings());
|
|
|
|
|
connect(TextEditorSettings::instance(), &TextEditorSettings::fontSettingsChanged,
|
|
|
|
|
this, &NimCodeStylePreferencesWidget::decorateEditor);
|
|
|
|
|
|
|
|
|
|
connect(m_preferences, &ICodeStylePreferences::currentTabSettingsChanged,
|
|
|
|
|
this, &NimCodeStylePreferencesWidget::updatePreview);
|
|
|
|
|
|
|
|
|
|
setVisualizeWhitespace(true);
|
|
|
|
|
|
|
|
|
|
updatePreview();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NimCodeStylePreferencesWidget::~NimCodeStylePreferencesWidget()
|
|
|
|
|
{
|
|
|
|
|
delete m_ui;
|
|
|
|
|
m_ui = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCodeStylePreferencesWidget::decorateEditor(const FontSettings &fontSettings)
|
|
|
|
|
{
|
|
|
|
|
m_ui->previewTextEdit->textDocument()->setFontSettings(fontSettings);
|
2017-04-24 15:52:04 +02:00
|
|
|
NimEditorFactory::decorateEditor(m_ui->previewTextEdit);
|
2015-08-26 09:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCodeStylePreferencesWidget::setVisualizeWhitespace(bool on)
|
|
|
|
|
{
|
|
|
|
|
DisplaySettings displaySettings = m_ui->previewTextEdit->displaySettings();
|
|
|
|
|
displaySettings.m_visualizeWhitespace = on;
|
|
|
|
|
m_ui->previewTextEdit->setDisplaySettings(displaySettings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimCodeStylePreferencesWidget::updatePreview()
|
|
|
|
|
{
|
|
|
|
|
QTextDocument *doc = m_ui->previewTextEdit->document();
|
|
|
|
|
|
|
|
|
|
const TabSettings &ts = m_preferences
|
|
|
|
|
? m_preferences->currentTabSettings()
|
|
|
|
|
: TextEditorSettings::codeStyle()->tabSettings();
|
|
|
|
|
m_ui->previewTextEdit->textDocument()->setTabSettings(ts);
|
|
|
|
|
|
|
|
|
|
QTextBlock block = doc->firstBlock();
|
|
|
|
|
QTextCursor tc = m_ui->previewTextEdit->textCursor();
|
|
|
|
|
tc.beginEditBlock();
|
|
|
|
|
while (block.isValid()) {
|
2019-01-16 09:37:54 +01:00
|
|
|
m_ui->previewTextEdit->textDocument()->indenter()->indentBlock(block, QChar::Null, ts);
|
2015-08-26 09:37:55 +02:00
|
|
|
block = block.next();
|
|
|
|
|
}
|
|
|
|
|
tc.endEditBlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Nim
|
|
|
|
|
|