Skip to content

Commit

Permalink
feat(composer): remember spellchecker enabled state (#673)
Browse files Browse the repository at this point in the history
* feat(composer): remember spellchecker enabled state

* fix: memory leak
  • Loading branch information
GeopJr authored Nov 30, 2023
1 parent 6041989 commit 204dd16
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions data/dev.geopjr.Tuba.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
<key name="advanced-boost-dialog" type="b">
<default>false</default>
</key>
<key name="spellchecker-enabled" type="b">
<default>true</default>
</key>

<key name="window-x" type="i">
<default>-1</default>
Expand Down
13 changes: 11 additions & 2 deletions src/Dialogs/Composer/EditorPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ public class Tuba.EditorPage : ComposerPage {
editor.grab_focus ();
}

#if LIBSPELLING
protected Spelling.TextBufferAdapter adapter;
private void update_spelling_settings () {
settings.spellchecker_enabled = adapter.enabled;
}
#endif

protected void install_editor () {
recount_chars.connect (() => {
remaining_chars = char_limit;
Expand Down Expand Up @@ -142,11 +149,13 @@ public class Tuba.EditorPage : ComposerPage {
editor.remove_css_class ("view");

#if LIBSPELLING
var adapter = new Spelling.TextBufferAdapter ((GtkSource.Buffer) editor.buffer, Spelling.Checker.get_default ());
adapter = new Spelling.TextBufferAdapter ((GtkSource.Buffer) editor.buffer, Spelling.Checker.get_default ());

editor.extra_menu = adapter.get_menu_model ();
editor.insert_action_group ("spelling", adapter);
adapter.enabled = true;

adapter.enabled = settings.spellchecker_enabled;
adapter.notify["enabled"].connect (update_spelling_settings);
#endif

#if GSPELL && !LIBSPELLING
Expand Down
4 changes: 3 additions & 1 deletion src/Services/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Tuba.Settings : GLib.Settings {
public bool use_blurhash { get; set; }
public bool group_push_notifications { get; set; }
public bool advanced_boost_dialog { get; set; }
public bool spellchecker_enabled { get; set; }

public string[] muted_notification_types { get; set; default = {}; }
private static string[] keys_to_init = {
Expand All @@ -45,7 +46,8 @@ public class Tuba.Settings : GLib.Settings {
"default-content-type",
"use-blurhash",
"group-push-notifications",
"advanced-boost-dialog"
"advanced-boost-dialog",
"spellchecker-enabled"
};

public Settings () {
Expand Down

0 comments on commit 204dd16

Please sign in to comment.