8#include "katemodeconfigpage.h"
10#include "kateautoindent.h"
11#include "kateconfig.h"
12#include "katedocument.h"
13#include "kateglobal.h"
14#include "katesyntaxmanager.h"
17#include "ui_filetypeconfigwidget.h"
19#include "katepartdebug.h"
20#include <KMimeTypeChooser>
28#include <QRegularExpression>
33ModeConfigPage::ModeConfigPage(
QWidget *parent)
34 : KateConfigPage(parent)
43 ui =
new Ui::FileTypeConfigWidget();
44 ui->setupUi(newWidget);
47 const auto modeList = KateHlManager::self()->modeList();
48 for (
const auto &hl : modeList) {
49 const auto section = hl.translatedSection();
50 if (!section.isEmpty()) {
53 ui->cmbHl->addItem(hl.translatedName(),
QVariant(hl.name()));
58 indentationModes <<
i18n(
"Use Default");
60 ui->cmbIndenter->addItems(indentationModes);
72 connect(ui->edtVariables, &VariableLineEdit::textChanged,
this, &ModeConfigPage::slotChanged);
80 ui->sbPriority->setToolTip(ui->sbPriority->whatsThis());
85ModeConfigPage::~ModeConfigPage()
91void ModeConfigPage::apply()
98 if (m_lastType != -1) {
99 ui->gbProperties->setTitle(
i18n(
"Properties of %1", ui->cmbFiletypes->itemText(m_lastType)));
105void ModeConfigPage::reload()
113 for (KateFileType *type : modeList) {
114 KateFileType *t =
new KateFileType();
122void ModeConfigPage::reset()
127void ModeConfigPage::defaults()
132void ModeConfigPage::update()
136 ui->cmbFiletypes->clear();
138 for (KateFileType *type : std::as_const(m_types)) {
139 if (!
type->sectionTranslated().isEmpty()) {
140 ui->cmbFiletypes->addItem(
type->sectionTranslated() +
QLatin1Char(
'/') +
type->nameTranslated());
142 ui->cmbFiletypes->addItem(
type->nameTranslated());
147 int currentIndex = 0;
148 KTextEditor::ViewPrivate *kv =
151 const QString filetypeName = kv->doc()->fileType();
152 for (
int i = 0; i < m_types.
size(); ++i) {
153 if (filetypeName == m_types[i]->name) {
159 ui->cmbFiletypes->setCurrentIndex(currentIndex);
160 typeChanged(currentIndex);
162 ui->cmbFiletypes->setEnabled(ui->cmbFiletypes->count() > 0);
165void ModeConfigPage::deleteType()
167 int type = ui->cmbFiletypes->currentIndex();
169 if (type > -1 && type < m_types.
count()) {
170 delete m_types[
type];
176void ModeConfigPage::newType()
180 for (
int i = 0; i < m_types.
count(); ++i) {
181 KateFileType *
type = m_types.
at(i);
182 if (
type->name == newN) {
183 ui->cmbFiletypes->setCurrentIndex(i);
189 KateFileType *newT =
new KateFileType();
192 newT->hlGenerated =
false;
198 ui->cmbFiletypes->setCurrentIndex(0);
202void ModeConfigPage::save()
204 if (m_lastType != -1) {
205 if (!m_types[m_lastType]->hlGenerated) {
206 m_types[m_lastType]->name = ui->edtName->text();
207 m_types[m_lastType]->section = ui->edtSection->text();
209 if (!m_types[m_lastType]->sectionTranslated().isEmpty()) {
210 ui->cmbFiletypes->setItemText(m_lastType, m_types[m_lastType]->sectionTranslated() +
QLatin1Char(
'/') + m_types[m_lastType]->nameTranslated());
212 ui->cmbFiletypes->setItemText(m_lastType, m_types[m_lastType]->nameTranslated());
215 m_types[m_lastType]->varLine = ui->edtVariables->text();
218 m_types[m_lastType]->priority = ui->sbPriority->value();
219 m_types[m_lastType]->hl = ui->cmbHl->itemData(ui->cmbHl->currentIndex()).toString();
221 if (ui->cmbIndenter->currentIndex() > 0) {
224 m_types[m_lastType]->indenter =
QString();
229void ModeConfigPage::typeChanged(
int type)
233 ui->cmbHl->setEnabled(
true);
234 ui->btnDelete->setEnabled(
true);
235 ui->edtName->setEnabled(
true);
236 ui->edtSection->setEnabled(
true);
238 if (type > -1 && type < m_types.
count()) {
239 KateFileType *t = m_types.
at(type);
241 ui->gbProperties->setTitle(
i18n(
"Properties of %1", ui->cmbFiletypes->itemText(type)));
243 ui->gbProperties->setEnabled(
true);
244 ui->btnDelete->setEnabled(
true);
246 ui->edtName->setText(t->nameTranslated());
247 ui->edtSection->setText(t->sectionTranslated());
248 ui->edtVariables->setText(t->varLine);
251 ui->sbPriority->setValue(t->priority);
253 ui->cmbHl->setEnabled(!t->hlGenerated);
254 ui->btnDelete->setEnabled(!t->hlGenerated);
255 ui->edtName->setEnabled(!t->hlGenerated);
256 ui->edtSection->setEnabled(!t->hlGenerated);
259 for (
int i = 0; i < ui->cmbHl->count(); ++i) {
260 if (ui->cmbHl->itemData(i).toString() == t->hl) {
261 ui->cmbHl->setCurrentIndex(i);
266 int indenterIndex = 0;
270 ui->cmbIndenter->setCurrentIndex(indenterIndex);
272 ui->gbProperties->setTitle(
i18n(
"Properties"));
274 ui->gbProperties->setEnabled(
false);
275 ui->btnDelete->setEnabled(
false);
277 ui->edtName->clear();
278 ui->edtSection->clear();
279 ui->edtVariables->clear();
280 ui->edtFileExtensions->clear();
281 ui->edtMimeTypes->clear();
282 ui->sbPriority->setValue(0);
283 ui->cmbHl->setCurrentIndex(0);
284 ui->cmbIndenter->setCurrentIndex(0);
290void ModeConfigPage::showMTDlg()
293 i18n(
"Select the MimeTypes you want for this file type.\nPlease note that this will automatically edit the associated file extensions as well.");
299 ui->edtFileExtensions->setText(d.chooser()->patterns().join(
QLatin1Char(
';')));
300 ui->edtMimeTypes->setText(d.chooser()->mimeTypes().join(
QLatin1Char(
';')));
304QString ModeConfigPage::name()
const
306 return i18n(
"Modes && Filetypes");
KateModeManager * modeManager()
global mode manager used to manage the modes centrally
static KTextEditor::EditorPrivate * self()
Kate Part Internal stuff ;)
static uint modeNumber(const QString &name)
Maps name -> index.
const QString & modeName() const
mode name
static QStringList listModes()
List all possible modes by name, i.e.
QString i18n(const char *text, const TYPE &arg...)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
const QList< QKeySequence > & reload()
void activated(int index)
QIcon fromTheme(const QString &name)
void textChanged(const QString &text)
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
qsizetype count() const const
void prepend(parameter_type value)
void removeAt(qsizetype i)
void reserve(qsizetype size)
qsizetype size() const const
T qobject_cast(QObject *object)
bool isEmpty() const const
QString join(QChar separator) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)