Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/NotepadNext/ApplicationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ CREATE_SETTING(Editor, WordWrap, wordWrap, bool, false)
CREATE_SETTING(Editor, FontName, fontName, QString, QStringLiteral("Courier New"))
CREATE_SETTING(Editor, FontSize, fontSize, int, []() { return qApp->font().pointSize() + 2; })
CREATE_SETTING(Editor, AdditionalWordChars, additionalWordChars, QString, QStringLiteral(""));
CREATE_SETTING(Editor, DefaultEOLMode, defaultEOLMode, QString, QStringLiteral(""))
1 change: 1 addition & 0 deletions src/NotepadNext/ApplicationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,5 @@ class ApplicationSettings : public QSettings
DEFINE_SETTING(FontName, fontName, QString);
DEFINE_SETTING(FontSize, fontSize, int);
DEFINE_SETTING(AdditionalWordChars, additionalWordChars, QString);
DEFINE_SETTING(DefaultEOLMode, defaultEOLMode, QString)
};
19 changes: 16 additions & 3 deletions src/NotepadNext/EditorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,21 @@ void EditorManager::setupEditor(ScintillaNext *editor)
editor->setIndentationGuides(settings->showIndentGuide() ? SC_IV_LOOKBOTH : SC_IV_NONE);
editor->setWrapMode(settings->wordWrap() ? SC_WRAP_WORD : SC_WRAP_NONE);

// TODO: make this optional
editor->setEOLMode(detectEOLMode(editor));
int detectedEOLMode = detectEOLMode(editor);
if (detectedEOLMode == -1) {
if (!settings->defaultEOLMode().isEmpty()) {
const int eol = ScintillaNext::stringToEolMode(settings->defaultEOLMode().toLower());

if (eol != -1)
editor->setEOLMode(eol);
else
qWarning("Unexpected DefaultEOLMode: %s", qUtf8Printable(settings->defaultEOLMode()));
}
// else it will just stay whatever EOL mode it was when it was created
}
else {
editor->setEOLMode(detectedEOLMode);
}

// Decorators
SmartHighlighter *s = new SmartHighlighter(editor);
Expand Down Expand Up @@ -366,6 +379,6 @@ int EditorManager::detectEOLMode(ScintillaNext *editor) const
return SC_EOL_LF;
}
else {
return editor->eOLMode();
return -1;
}
}
24 changes: 24 additions & 0 deletions src/NotepadNext/ScintillaNext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ ScintillaNext *ScintillaNext::fromFile(const QString &filePath, bool tryToCreate
return editor;
}

QString ScintillaNext::eolModeToString(int eolMode)
{
if (eolMode == SC_EOL_CRLF)
return QStringLiteral("crlf");
else if (eolMode == SC_EOL_CR)
return QStringLiteral("cr");
else if (eolMode == SC_EOL_LF)
return QStringLiteral("lf");
else
return QString(); // unknown
}

int ScintillaNext::stringToEolMode(QString eolMode)
{
if (eolMode == QStringLiteral("crlf"))
return SC_EOL_CRLF;
else if (eolMode == QStringLiteral("cr"))
return SC_EOL_CR;
else if (eolMode == QStringLiteral("lf"))
return SC_EOL_LF;
else
return -1;
}

int ScintillaNext::allocateIndicator(const QString &name)
{
return indicatorResources.requestResource(name);
Expand Down
2 changes: 2 additions & 0 deletions src/NotepadNext/ScintillaNext.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class ScintillaNext : public ScintillaEdit
virtual ~ScintillaNext();

static ScintillaNext *fromFile(const QString &filePath, bool tryToCreate=false);
static QString eolModeToString(int eolMode);
static int stringToEolMode(QString eolMode);

int allocateIndicator(const QString &name);

Expand Down
18 changes: 18 additions & 0 deletions src/NotepadNext/dialogs/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "NotepadNextApplication.h"
#include "TranslationManager.h"
#include "ui_PreferencesDialog.h"
#include "ScintillaNext.h"

#include <QMessageBox>

Expand Down Expand Up @@ -78,6 +79,23 @@ PreferencesDialog::PreferencesDialog(ApplicationSettings *settings, QWidget *par
ui->spbDefaultFontSize->setValue(settings->fontSize());
connect(ui->spbDefaultFontSize, QOverload<int>::of(&QSpinBox::valueChanged), settings, &ApplicationSettings::setFontSize);
connect(settings, &ApplicationSettings::fontSizeChanged, ui->spbDefaultFontSize, &QSpinBox::setValue);

ui->comboBoxLineEndings->addItem(tr("System Default"), QString(""));
ui->comboBoxLineEndings->addItem(tr("Windows (CR LF)"), ScintillaNext::eolModeToString(SC_EOL_CRLF));
ui->comboBoxLineEndings->addItem(tr("Linux (LF)"), ScintillaNext::eolModeToString(SC_EOL_LF));
ui->comboBoxLineEndings->addItem(tr("Macintosh (CR)"), ScintillaNext::eolModeToString(SC_EOL_CR));

// Select the current one
int index = ui->comboBoxLineEndings->findData(settings->defaultEOLMode());
ui->comboBoxLineEndings->setCurrentIndex(index == -1 ? 0 : index);

connect(ui->comboBoxLineEndings, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) {
settings->setDefaultEOLMode(ui->comboBoxLineEndings->itemData(index).toString());
});
connect(settings, &ApplicationSettings::defaultEOLModeChanged, this, [=](QString defaultEOLMode) {
int index = ui->comboBoxLineEndings->findData(defaultEOLMode);
ui->comboBoxLineEndings->setCurrentIndex(index == -1 ? 0 : index);
});
}

PreferencesDialog::~PreferencesDialog()
Expand Down
Loading
Loading