diff --git a/data/io.elementary.code.gschema.xml b/data/io.elementary.code.gschema.xml
index 0f78a64f7..0a8ba0f70 100644
--- a/data/io.elementary.code.gschema.xml
+++ b/data/io.elementary.code.gschema.xml
@@ -207,6 +207,11 @@
Whether to automatically remove trailing whitespace on saving
Whether trailing whitespace should be removed from a document whenever it is saved, including on autosave.
+
+ true
+ Show source language syntax highlighting
+ Whether the document should display the style scheme for the associated language.
+
diff --git a/src/Dialogs/PreferencesDialog.vala b/src/Dialogs/PreferencesDialog.vala
index 53288c398..b8fae810a 100644
--- a/src/Dialogs/PreferencesDialog.vala
+++ b/src/Dialogs/PreferencesDialog.vala
@@ -28,6 +28,7 @@ public class Scratch.Dialogs.Preferences : Granite.Dialog {
"smart-cut-copy",
_("Cutting or copying without an active selection will cut or copy the entire current line")
));
+ general_box.add (new SettingSwitch (_("Highlight syntax"), "highlight-syntax"));
var indent_width = new Gtk.SpinButton.with_range (1, 24, 1);
Scratch.settings.bind ("indent-width", indent_width, "value", DEFAULT);
diff --git a/src/Services/Document.vala b/src/Services/Document.vala
index ae4bf524f..a5d04b75d 100644
--- a/src/Services/Document.vala
+++ b/src/Services/Document.vala
@@ -238,6 +238,7 @@ namespace Scratch.Services {
set_strip_trailing_whitespace ();
settings.changed["show-mini-map"].connect (set_minimap);
settings.changed["strip-trailing-on-save"].connect (set_strip_trailing_whitespace);
+ settings.changed["highlight-syntax"].connect (set_syntax_highlighting);
var source_grid = new Gtk.Grid () {
orientation = Gtk.Orientation.HORIZONTAL,
@@ -450,7 +451,7 @@ namespace Scratch.Services {
}
// Change syntax highlight
- this.source_view.change_syntax_highlight_from_file (this.file);
+ set_syntax_highlighting ();
source_view.buffer.set_modified (false);
original_content = source_view.buffer.text;
@@ -711,7 +712,8 @@ namespace Scratch.Services {
}
delete_backup (current_file.get_uri () + "~");
- this.source_view.change_syntax_highlight_from_file (this.file);
+ set_syntax_highlighting ();
+
}
// Calling function responsible for restoring original
}
@@ -723,7 +725,13 @@ namespace Scratch.Services {
return is_saved;
}
- public bool move (File new_dest) {
+ private void set_syntax_highlighting () {
+ this.source_view.change_syntax_highlight_from_file (
+ settings.get_boolean ("highlight-syntax") ? this.file : null
+ );
+ }
+
+ public bool move (File new_dest) {
this.file = new_dest;
this.save.begin ();
diff --git a/src/Widgets/SourceView.vala b/src/Widgets/SourceView.vala
index c03ddafba..609923659 100644
--- a/src/Widgets/SourceView.vala
+++ b/src/Widgets/SourceView.vala
@@ -213,7 +213,12 @@ namespace Scratch.Widgets {
return !start.equal (end);
}
- public void change_syntax_highlight_from_file (File file) {
+ public void change_syntax_highlight_from_file (File? file) {
+ if (file == null) {
+ // Remove all highlighting
+ language = null;
+ }
+
try {
var info = file.query_info ("standard::*", FileQueryInfoFlags.NONE, null);
var mime_type = ContentType.get_mime_type (