From 0c2f3bf1cf7b197ec0f323a21707ca3328b739bd Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 26 Mar 2023 16:46:31 +0100 Subject: [PATCH 1/4] Implement setting for case sensitive search mode --- data/io.elementary.code.gschema.xml | 10 +++++++ src/Widgets/SearchBar.vala | 42 ++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/data/io.elementary.code.gschema.xml b/data/io.elementary.code.gschema.xml index b15cd16055..18efb98306 100644 --- a/data/io.elementary.code.gschema.xml +++ b/data/io.elementary.code.gschema.xml @@ -10,6 +10,11 @@ + + + + + @@ -155,6 +160,11 @@ Whether search is cyclic Whether text searching should cycle back to the beginning of the document after reaching the end of the document. + + "Mixed Case" + When text search is case sensitive + Whether the text search is case sensitive never, always or only when search term is mixed case + false Whether to automatically remove trailing whitespace on saving diff --git a/src/Widgets/SearchBar.vala b/src/Widgets/SearchBar.vala index 50520b9c04..27cf60249e 100644 --- a/src/Widgets/SearchBar.vala +++ b/src/Widgets/SearchBar.vala @@ -24,7 +24,33 @@ namespace Scratch.Widgets { enum CaseSensitiveMode { NEVER, MIXED, - ALWAYS + ALWAYS; + + public string to_string () { + switch (this) { + case NEVER: + return "Never"; + case MIXED: + return "Mixed Case"; + case ALWAYS: + return "Always"; + default: + assert_not_reached (); + } + } + + public static CaseSensitiveMode from_string (string s) { + switch (s) { + case "Never": + return NEVER; + case "Mixed Case": + return MIXED; + case "Always": + return ALWAYS; + default: + assert_not_reached (); + } + } } public weak MainWindow window { get; construct; } @@ -143,6 +169,20 @@ namespace Scratch.Widgets { regex_search_button.toggled.connect (on_search_entry_text_changed); Scratch.settings.bind ("cyclic-search", cycle_search_button, "active", SettingsBindFlags.DEFAULT); + Scratch.settings.bind_with_mapping ( + "case-sensitive-search", + case_sensitive_search_button, "active", + SettingsBindFlags.DEFAULT, + (to_val, from_variant) => { + to_val.set_int (CaseSensitiveMode.from_string (from_variant.get_string ())); + return true; + }, + (from_val, vartype) => { + var mode_s = ((CaseSensitiveMode)(from_val.get_int ())).to_string (); + return new Variant.string (mode_s); + }, + null, null + ); var search_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) { margin_top = 3, From 1cb96dadf4854e71b5b2b0cfbcc732c0158f89a6 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 26 Mar 2023 17:02:52 +0100 Subject: [PATCH 2/4] Implement whole word search setting --- data/io.elementary.code.gschema.xml | 5 +++++ src/Widgets/SearchBar.vala | 1 + 2 files changed, 6 insertions(+) diff --git a/data/io.elementary.code.gschema.xml b/data/io.elementary.code.gschema.xml index 18efb98306..c5a6499e20 100644 --- a/data/io.elementary.code.gschema.xml +++ b/data/io.elementary.code.gschema.xml @@ -160,6 +160,11 @@ Whether search is cyclic Whether text searching should cycle back to the beginning of the document after reaching the end of the document. + + false + Whether search is for whole words + Whether the search should only match whole words. + "Mixed Case" When text search is case sensitive diff --git a/src/Widgets/SearchBar.vala b/src/Widgets/SearchBar.vala index 27cf60249e..5ff8b9ad75 100644 --- a/src/Widgets/SearchBar.vala +++ b/src/Widgets/SearchBar.vala @@ -169,6 +169,7 @@ namespace Scratch.Widgets { regex_search_button.toggled.connect (on_search_entry_text_changed); Scratch.settings.bind ("cyclic-search", cycle_search_button, "active", SettingsBindFlags.DEFAULT); + Scratch.settings.bind ("wholeword-search", whole_word_search_button, "active", SettingsBindFlags.DEFAULT); Scratch.settings.bind_with_mapping ( "case-sensitive-search", case_sensitive_search_button, "active", From 01309c818a34c2cdf63541e4368c18a770111da6 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 26 Mar 2023 17:06:36 +0100 Subject: [PATCH 3/4] Implement regex search setting --- data/io.elementary.code.gschema.xml | 5 +++++ src/Widgets/SearchBar.vala | 1 + 2 files changed, 6 insertions(+) diff --git a/data/io.elementary.code.gschema.xml b/data/io.elementary.code.gschema.xml index c5a6499e20..2ee1dfc293 100644 --- a/data/io.elementary.code.gschema.xml +++ b/data/io.elementary.code.gschema.xml @@ -165,6 +165,11 @@ Whether search is for whole words Whether the search should only match whole words. + + false + Whether search term is a regex expression + Whether the search should use the search term as a regex expression for matching. + "Mixed Case" When text search is case sensitive diff --git a/src/Widgets/SearchBar.vala b/src/Widgets/SearchBar.vala index 5ff8b9ad75..c54cf1b6c6 100644 --- a/src/Widgets/SearchBar.vala +++ b/src/Widgets/SearchBar.vala @@ -170,6 +170,7 @@ namespace Scratch.Widgets { Scratch.settings.bind ("cyclic-search", cycle_search_button, "active", SettingsBindFlags.DEFAULT); Scratch.settings.bind ("wholeword-search", whole_word_search_button, "active", SettingsBindFlags.DEFAULT); + Scratch.settings.bind ("regex-search", regex_search_button, "active", SettingsBindFlags.DEFAULT); Scratch.settings.bind_with_mapping ( "case-sensitive-search", case_sensitive_search_button, "active", From 289e0d2f21d4555a442f4ca70de98ad04ed5820c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 28 Mar 2023 03:56:08 -0700 Subject: [PATCH 4/4] Simplify settings handling (#1296) --- data/io.elementary.code.gschema.xml | 8 ++--- src/Widgets/SearchBar.vala | 49 +++-------------------------- 2 files changed, 9 insertions(+), 48 deletions(-) diff --git a/data/io.elementary.code.gschema.xml b/data/io.elementary.code.gschema.xml index 2ee1dfc293..1794882fa9 100644 --- a/data/io.elementary.code.gschema.xml +++ b/data/io.elementary.code.gschema.xml @@ -11,9 +11,9 @@ - - - + + + @@ -171,7 +171,7 @@ Whether the search should use the search term as a regex expression for matching. - "Mixed Case" + 'mixed' When text search is case sensitive Whether the text search is case sensitive never, always or only when search term is mixed case diff --git a/src/Widgets/SearchBar.vala b/src/Widgets/SearchBar.vala index c54cf1b6c6..a986c99c9f 100644 --- a/src/Widgets/SearchBar.vala +++ b/src/Widgets/SearchBar.vala @@ -24,33 +24,7 @@ namespace Scratch.Widgets { enum CaseSensitiveMode { NEVER, MIXED, - ALWAYS; - - public string to_string () { - switch (this) { - case NEVER: - return "Never"; - case MIXED: - return "Mixed Case"; - case ALWAYS: - return "Always"; - default: - assert_not_reached (); - } - } - - public static CaseSensitiveMode from_string (string s) { - switch (s) { - case "Never": - return NEVER; - case "Mixed Case": - return MIXED; - case "Always": - return ALWAYS; - default: - assert_not_reached (); - } - } + ALWAYS } public weak MainWindow window { get; construct; } @@ -125,9 +99,9 @@ namespace Scratch.Widgets { cycle_search_button = new Granite.SwitchModelButton (_("Cyclic Search")); case_sensitive_search_button = new Gtk.ComboBoxText (); - case_sensitive_search_button.append (null, _("Never")); - case_sensitive_search_button.append (null, _("Mixed Case")); - case_sensitive_search_button.append (null, _("Always")); + case_sensitive_search_button.append ("never", _("Never")); + case_sensitive_search_button.append ("mixed", _("Mixed Case")); + case_sensitive_search_button.append ("always", _("Always")); case_sensitive_search_button.active = 1; var case_sensitive_search_label = new Gtk.Label (_("Case Sensitive")); @@ -171,20 +145,7 @@ namespace Scratch.Widgets { Scratch.settings.bind ("cyclic-search", cycle_search_button, "active", SettingsBindFlags.DEFAULT); Scratch.settings.bind ("wholeword-search", whole_word_search_button, "active", SettingsBindFlags.DEFAULT); Scratch.settings.bind ("regex-search", regex_search_button, "active", SettingsBindFlags.DEFAULT); - Scratch.settings.bind_with_mapping ( - "case-sensitive-search", - case_sensitive_search_button, "active", - SettingsBindFlags.DEFAULT, - (to_val, from_variant) => { - to_val.set_int (CaseSensitiveMode.from_string (from_variant.get_string ())); - return true; - }, - (from_val, vartype) => { - var mode_s = ((CaseSensitiveMode)(from_val.get_int ())).to_string (); - return new Variant.string (mode_s); - }, - null, null - ); + Scratch.settings.bind ("case-sensitive-search", case_sensitive_search_button, "active-id", SettingsBindFlags.DEFAULT); var search_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) { margin_top = 3,