Skip to content

Commit 289e0d2

Browse files
authored
Simplify settings handling (#1296)
1 parent 2b54c9d commit 289e0d2

File tree

2 files changed

+9
-48
lines changed

2 files changed

+9
-48
lines changed

data/io.elementary.code.gschema.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<value nick="Always" value="2" />
1212
</enum>
1313
<enum id="io.elementary.code.case-sensitive-mode">
14-
<value nick="Never" value="0" />
15-
<value nick="Mixed Case" value="1" />
16-
<value nick="Always" value="2" />
14+
<value nick="never" value="0" />
15+
<value nick="mixed" value="1" />
16+
<value nick="always" value="2" />
1717
</enum>
1818

1919
<schema path="/io/elementary/code/saved-state/" id="io.elementary.code.saved-state" gettext-domain="io.elementary.code">
@@ -171,7 +171,7 @@
171171
<description>Whether the search should use the search term as a regex expression for matching.</description>
172172
</key>
173173
<key name="case-sensitive-search" enum="io.elementary.code.case-sensitive-mode">
174-
<default>"Mixed Case"</default>
174+
<default>'mixed'</default>
175175
<summary>When text search is case sensitive</summary>
176176
<description>Whether the text search is case sensitive never, always or only when search term is mixed case</description>
177177
</key>

src/Widgets/SearchBar.vala

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,7 @@ namespace Scratch.Widgets {
2424
enum CaseSensitiveMode {
2525
NEVER,
2626
MIXED,
27-
ALWAYS;
28-
29-
public string to_string () {
30-
switch (this) {
31-
case NEVER:
32-
return "Never";
33-
case MIXED:
34-
return "Mixed Case";
35-
case ALWAYS:
36-
return "Always";
37-
default:
38-
assert_not_reached ();
39-
}
40-
}
41-
42-
public static CaseSensitiveMode from_string (string s) {
43-
switch (s) {
44-
case "Never":
45-
return NEVER;
46-
case "Mixed Case":
47-
return MIXED;
48-
case "Always":
49-
return ALWAYS;
50-
default:
51-
assert_not_reached ();
52-
}
53-
}
27+
ALWAYS
5428
}
5529

5630
public weak MainWindow window { get; construct; }
@@ -125,9 +99,9 @@ namespace Scratch.Widgets {
12599
cycle_search_button = new Granite.SwitchModelButton (_("Cyclic Search"));
126100

127101
case_sensitive_search_button = new Gtk.ComboBoxText ();
128-
case_sensitive_search_button.append (null, _("Never"));
129-
case_sensitive_search_button.append (null, _("Mixed Case"));
130-
case_sensitive_search_button.append (null, _("Always"));
102+
case_sensitive_search_button.append ("never", _("Never"));
103+
case_sensitive_search_button.append ("mixed", _("Mixed Case"));
104+
case_sensitive_search_button.append ("always", _("Always"));
131105
case_sensitive_search_button.active = 1;
132106

133107
var case_sensitive_search_label = new Gtk.Label (_("Case Sensitive"));
@@ -171,20 +145,7 @@ namespace Scratch.Widgets {
171145
Scratch.settings.bind ("cyclic-search", cycle_search_button, "active", SettingsBindFlags.DEFAULT);
172146
Scratch.settings.bind ("wholeword-search", whole_word_search_button, "active", SettingsBindFlags.DEFAULT);
173147
Scratch.settings.bind ("regex-search", regex_search_button, "active", SettingsBindFlags.DEFAULT);
174-
Scratch.settings.bind_with_mapping (
175-
"case-sensitive-search",
176-
case_sensitive_search_button, "active",
177-
SettingsBindFlags.DEFAULT,
178-
(to_val, from_variant) => {
179-
to_val.set_int (CaseSensitiveMode.from_string (from_variant.get_string ()));
180-
return true;
181-
},
182-
(from_val, vartype) => {
183-
var mode_s = ((CaseSensitiveMode)(from_val.get_int ())).to_string ();
184-
return new Variant.string (mode_s);
185-
},
186-
null, null
187-
);
148+
Scratch.settings.bind ("case-sensitive-search", case_sensitive_search_button, "active-id", SettingsBindFlags.DEFAULT);
188149

189150
var search_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
190151
margin_top = 3,

0 commit comments

Comments
 (0)