Skip to content

Commit

Permalink
Setting for line wrap in Scintilla editors
Browse files Browse the repository at this point in the history
A new setting is added to the 'SQL' tab of the Preferences dialog. It
enables the line wrapping in the editors with none/character/word/
whitespace boundaries.

See comments in issue sqlitebrowser#1173.
  • Loading branch information
mgrojo committed Mar 28, 2018
1 parent a242a58 commit 85dbe7b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/ExtendedScintilla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ ExtendedScintilla::ExtendedScintilla(QWidget* parent) :
// adjusts the scroll width to be narrower.
setScrollWidthTracking(true);

// Visual flags for when wrap lines is enabled
setWrapVisualFlags(QsciScintilla::WrapFlagByBorder);

// Connect signals
connect(this, SIGNAL(linesChanged()), this, SLOT(updateLineNumberAreaWidth()));

Expand Down Expand Up @@ -155,6 +158,9 @@ void ExtendedScintilla::reloadLexerSettings(QsciLexer *lexer)
setTabWidth(Settings::getValue("editor", "tabsize").toInt());
lexer->refreshProperties();

// Set wrap lines
setWrapMode(static_cast<QsciScintilla::WrapMode>(Settings::getValue("editor", "wrap_lines").toInt()));

// Check if error indicators are enabled and clear them if they just got disabled
showErrorIndicators = Settings::getValue("editor", "error_indicators").toBool();
if(!showErrorIndicators)
Expand Down
2 changes: 2 additions & 0 deletions src/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ void PreferencesDialog::loadSettings()
ui->spinEditorFontSize->setValue(Settings::getValue("editor", "fontsize").toInt());
ui->spinTabSize->setValue(Settings::getValue("editor", "tabsize").toInt());
ui->spinLogFontSize->setValue(Settings::getValue("log", "fontsize").toInt());
ui->wrapComboBox->setCurrentIndex(Settings::getValue("editor", "wrap_lines").toInt());
ui->checkAutoCompletion->setChecked(Settings::getValue("editor", "auto_completion").toBool());
ui->checkCompleteUpper->setEnabled(Settings::getValue("editor", "auto_completion").toBool());
ui->checkCompleteUpper->setChecked(Settings::getValue("editor", "upper_keywords").toBool());
Expand Down Expand Up @@ -221,6 +222,7 @@ void PreferencesDialog::saveSettings()
Settings::setValue("editor", "fontsize", ui->spinEditorFontSize->value());
Settings::setValue("editor", "tabsize", ui->spinTabSize->value());
Settings::setValue("log", "fontsize", ui->spinLogFontSize->value());
Settings::setValue("editor", "wrap_lines", ui->wrapComboBox->currentIndex());
Settings::setValue("editor", "auto_completion", ui->checkAutoCompletion->isChecked());
Settings::setValue("editor", "upper_keywords", ui->checkCompleteUpper->isChecked());
Settings::setValue("editor", "error_indicators", ui->checkErrorIndicators->isChecked());
Expand Down
50 changes: 42 additions & 8 deletions src/PreferencesDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@
<item row="0" column="1">
<widget class="QFontComboBox" name="comboEditorFont"/>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_20">
<property name="text">
<string>Code co&amp;mpletion</string>
Expand All @@ -1000,14 +1000,14 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QCheckBox" name="checkAutoCompletion">
<property name="text">
<string>enabled</string>
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label_24">
<property name="text">
<string>Keywords in &amp;UPPER CASE</string>
Expand All @@ -1017,7 +1017,7 @@
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QCheckBox" name="checkCompleteUpper">
<property name="toolTip">
<string>When set, the SQL keywords are completed in UPPER CASE letters.</string>
Expand All @@ -1027,7 +1027,7 @@
</property>
</widget>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Error indicators</string>
Expand All @@ -1037,7 +1037,7 @@
</property>
</widget>
</item>
<item row="6" column="1">
<item row="7" column="1">
<widget class="QCheckBox" name="checkErrorIndicators">
<property name="toolTip">
<string>When set, the SQL code lines that caused errors during the last execution are highlighted and the results frame indicates the error in the background</string>
Expand All @@ -1047,7 +1047,7 @@
</property>
</widget>
</item>
<item row="7" column="0">
<item row="8" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Hori&amp;zontal tiling</string>
Expand All @@ -1057,7 +1057,7 @@
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="QCheckBox" name="checkHorizontalTiling">
<property name="toolTip">
<string>If enabled the SQL code editor and the result table view are shown side by side instead of one over the other.</string>
Expand All @@ -1067,6 +1067,40 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="wrapComboBox">
<item>
<property name="text">
<string>Never</string>
</property>
</item>
<item>
<property name="text">
<string>At word boundaries</string>
</property>
</item>
<item>
<property name="text">
<string>At character boundaries</string>
</property>
</item>
<item>
<property name="text">
<string>At whitespace boundaries</string>
</property>
</item>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="wrapLabel">
<property name="text">
<string>Wrap lines</string>
</property>
<property name="buddy">
<cstring>wrapComboBox</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down
4 changes: 4 additions & 0 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ QVariant Settings::getDefaultValue(const QString& group, const QString& name)
}
}

// editor/wrap_lines
if(group == "editor" && name == "wrap_lines")
return 0; // QsciScintilla::WrapNone

// editor/auto_completion?
if(group == "editor" && name == "auto_completion")
return true;
Expand Down

0 comments on commit 85dbe7b

Please sign in to comment.