Skip to content

Commit aff18f8

Browse files
authored
HeaderBar: Correctly load color button states (#930)
* GSchema: Correct indendation * HeaderBar: Correctly load color button states * Revert "GSchema: Correct indendation" This reverts commit 7519f7b.
1 parent a75a235 commit aff18f8

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

src/Widgets/HeaderBar.vala

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ namespace Scratch.Widgets {
2828
public Gtk.Button templates_button;
2929
public Code.FormatBar format_bar;
3030

31+
private const string STYLE_SCHEME_HIGH_CONTRAST = "classic";
32+
private const string STYLE_SCHEME_LIGHT = "solarized-light";
33+
private const string STYLE_SCHEME_DARK = "solarized-dark";
34+
3135
public HeaderBar () {
3236
Object (
3337
has_subtitle: false,
@@ -115,23 +119,26 @@ namespace Scratch.Widgets {
115119
font_size_grid.add (zoom_default_button);
116120
font_size_grid.add (zoom_in_button);
117121

118-
var color_button_white = new Gtk.RadioButton (null);
122+
// Intentionally never attached so we can have a non-selected state
123+
var color_button_none = new Gtk.RadioButton (null);
124+
125+
var color_button_white = new Gtk.RadioButton.from_widget (color_button_none);
119126
color_button_white.halign = Gtk.Align.CENTER;
120127
color_button_white.tooltip_text = _("High Contrast");
121128

122129
var color_button_white_context = color_button_white.get_style_context ();
123130
color_button_white_context.add_class ("color-button");
124131
color_button_white_context.add_class ("color-white");
125132

126-
var color_button_light = new Gtk.RadioButton.from_widget (color_button_white);
133+
var color_button_light = new Gtk.RadioButton.from_widget (color_button_none);
127134
color_button_light.halign = Gtk.Align.CENTER;
128135
color_button_light.tooltip_text = _("Solarized Light");
129136

130137
var color_button_light_context = color_button_light.get_style_context ();
131138
color_button_light_context.add_class ("color-button");
132139
color_button_light_context.add_class ("color-light");
133140

134-
var color_button_dark = new Gtk.RadioButton.from_widget (color_button_white);
141+
var color_button_dark = new Gtk.RadioButton.from_widget (color_button_none);
135142
color_button_dark.halign = Gtk.Align.CENTER;
136143
color_button_dark.tooltip_text = _("Solarized Dark");
137144

@@ -214,32 +221,34 @@ namespace Scratch.Widgets {
214221
var gtk_settings = Gtk.Settings.get_default ();
215222

216223
switch (Scratch.settings.get_string ("style-scheme")) {
217-
case "high-contrast":
218-
color_button_white.active = true;
219-
break;
220-
case "solarized-light":
221-
color_button_light.active = true;
222-
break;
223-
case "solarized-dark":
224-
color_button_dark.active = true;
225-
break;
224+
case STYLE_SCHEME_HIGH_CONTRAST:
225+
color_button_white.active = true;
226+
break;
227+
case STYLE_SCHEME_LIGHT:
228+
color_button_light.active = true;
229+
break;
230+
case STYLE_SCHEME_DARK:
231+
color_button_dark.active = true;
232+
break;
233+
default:
234+
color_button_none.active = true;
226235
}
227236

228237
color_button_dark.clicked.connect (() => {
229238
Scratch.settings.set_boolean ("prefer-dark-style", true);
230-
Scratch.settings.set_string ("style-scheme", "solarized-dark");
239+
Scratch.settings.set_string ("style-scheme", STYLE_SCHEME_DARK);
231240
gtk_settings.gtk_application_prefer_dark_theme = true;
232241
});
233242

234243
color_button_light.clicked.connect (() => {
235244
Scratch.settings.set_boolean ("prefer-dark-style", false);
236-
Scratch.settings.set_string ("style-scheme", "solarized-light");
245+
Scratch.settings.set_string ("style-scheme", STYLE_SCHEME_LIGHT);
237246
gtk_settings.gtk_application_prefer_dark_theme = false;
238247
});
239248

240249
color_button_white.clicked.connect (() => {
241250
Scratch.settings.set_boolean ("prefer-dark-style", false);
242-
Scratch.settings.set_string ("style-scheme", "classic");
251+
Scratch.settings.set_string ("style-scheme", STYLE_SCHEME_HIGH_CONTRAST);
243252
gtk_settings.gtk_application_prefer_dark_theme = false;
244253
});
245254
}

0 commit comments

Comments
 (0)