Skip to content
Closed
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
5 changes: 5 additions & 0 deletions data/io.elementary.code.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@
<summary>Whether to automatically remove trailing whitespace on saving</summary>
<description>Whether trailing whitespace should be removed from a document whenever it is saved, including on autosave.</description>
</key>
<key name="highlight-syntax" type="b">
<default>true</default>
<summary>Show source language syntax highlighting</summary>
<description>Whether the document should display the style scheme for the associated language.</description>
</key>
</schema>

<schema path="/io/elementary/code/services/" id="io.elementary.code.services" gettext-domain="io.elementary.code">
Expand Down
1 change: 1 addition & 0 deletions src/Dialogs/PreferencesDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 11 additions & 3 deletions src/Services/Document.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand All @@ -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 ();

Expand Down
7 changes: 6 additions & 1 deletion src/Widgets/SourceView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Loading