Skip to content

Commit 806a8e4

Browse files
committed
move color handling to popover
1 parent 93d51b3 commit 806a8e4

File tree

4 files changed

+48
-49
lines changed

4 files changed

+48
-49
lines changed

src/Application.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Please wait while the app remembers all the things...
207207

208208
private void action_save () {
209209
debug ("[ACTION] Saving...");
210-
manager.save_all.begin ();
210+
manager.save_all ();
211211
}
212212

213213
private void action_reset_settings () {

src/Services/NoteManager.vala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ public class Jorts.NoteManager : Object {
7474
random_data = Jorts.Utils.golden_sticky (random_data);
7575
note = new StickyNoteWindow (application, random_data);
7676
}
77-
77+
7878
/* LETSGO */
7979
open_notes.add (note);
8080
note.show ();
8181
note.present ();
82-
note.changed.connect (save_all);
82+
save_all ();
8383

8484
}
8585

@@ -120,16 +120,15 @@ public class Jorts.NoteManager : Object {
120120

121121
open_notes.remove (note);
122122
note.close ();
123-
save_all.begin ();
123+
save_all ();
124124
}
125125

126126
/*************************************************/
127127
/**
128128
* Cue to immediately write from the active list to the storage
129129
*/
130-
public async void save_all () {
130+
public void save_all () {
131131
debug ("[MANAGER] Save the stickies!");
132-
133132
var array = new Json.Array ();
134133

135134
foreach (Jorts.StickyNoteWindow note in open_notes) {

src/Views/PopoverView.vala

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ public class Jorts.PopoverView : Gtk.Popover {
1515
private Jorts.MonospaceBox monospace_box;
1616
private Jorts.ZoomBox font_size_box;
1717

18+
private Themes _old_color = Jorts.Constants.DEFAULT_THEME;
1819
public Themes color {
19-
get {return color_button_box.color;}
20-
set {color_button_box.color = value;}
20+
get {return _old_color;}
21+
set {on_color_changed (value);}
2122
}
2223

2324
public bool monospace {
@@ -58,13 +59,42 @@ public class Jorts.PopoverView : Gtk.Popover {
5859

5960
child = view;
6061

61-
color_button_box.theme_changed.connect ((selected) => {theme_changed (selected);});
62+
color_button_box.theme_changed.connect (on_color_changed);
6263
monospace_box.monospace_changed.connect (on_monospace_changed);
6364
font_size_box.zoom_changed.connect (on_zoom_changed);
6465
}
6566

6667

6768

69+
/**
70+
* Switches stylesheet
71+
* First use appropriate stylesheet, Then switch the theme classes
72+
*/
73+
private void on_color_changed (Jorts.Themes new_theme) {
74+
debug ("Updating theme to %s".printf (new_theme.to_string ()));
75+
76+
// Avoid deathloop where the handler calls itself
77+
color_button_box.theme_changed.disconnect (on_color_changed);
78+
79+
// Accent
80+
var stylesheet = "io.elementary.stylesheet." + new_theme.to_css_class ();
81+
parent_window.gtk_settings.gtk_theme_name = stylesheet;
82+
83+
// Add remove class
84+
if (_old_color.to_string () in parent_window.css_classes) {
85+
parent_window.remove_css_class (_old_color.to_string ());
86+
}
87+
parent_window.add_css_class (new_theme.to_string ());
88+
89+
// Propagate values
90+
_old_color = new_theme;
91+
color_button_box.color = new_theme;
92+
NoteData.latest_theme = new_theme;
93+
94+
// Cleanup
95+
((Jorts.Application)parent_window.application).manager.save_all ();
96+
color_button_box.theme_changed.connect (on_color_changed);
97+
}
6898

6999
/**
70100
* Switches the .monospace class depending on the note setting
@@ -84,7 +114,8 @@ public class Jorts.PopoverView : Gtk.Popover {
84114
parent_window.view.textview.monospace = monospace;
85115
monospace_box.monospace = monospace;
86116
Jorts.NoteData.latest_mono = monospace;
87-
parent_window.changed ();
117+
118+
((Jorts.Application)parent_window.application).manager.save_all ();
88119
}
89120

90121

@@ -104,7 +135,7 @@ public class Jorts.PopoverView : Gtk.Popover {
104135
case Zoomkind.ZOOM_OUT: zoom_out (); break;
105136
default: zoom_default (); break;
106137
}
107-
((Jorts.Application)parent_window.application).manager.save_all.begin ();
138+
((Jorts.Application)parent_window.application).manager.save_all ();
108139
}
109140

110141
/**

src/Windows/StickyNoteWindow.vala

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
3333
private PopoverView popover;
3434
public TextView textview;
3535

36-
private Themes _old_color;
37-
public Jorts.Themes color {
38-
get { return popover.color;}
39-
set { popover.color = value; on_theme_changed (value);}
40-
}
41-
4236
public NoteData data {
4337
owned get { return packaged ();}
4438
set { load_data (value);}
@@ -47,9 +41,6 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
4741

4842
private static uint debounce_timer_id;
4943

50-
// Connected to by the NoteManager to know it is time to save
51-
public signal void changed ();
52-
5344
private const string ACTION_PREFIX = "app.";
5445
private const string ACTION_DELETE = "action_delete";
5546
private const string ACTION_SHOW_EMOJI = "action_show_emoji";
@@ -140,8 +131,6 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
140131
editableheader.changed.connect (on_editable_changed);
141132
view.textview.buffer.changed.connect (debounce_save);
142133

143-
popover.theme_changed.connect (on_theme_changed);
144-
145134
// Use the color theme of this sticky note when focused
146135
this.notify["is-active"].connect (on_focus_changed);
147136

@@ -190,7 +179,7 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
190179

191180
debounce_timer_id = Timeout.add (Jorts.Constants.DEBOUNCE, () => {
192181
debounce_timer_id = 0;
193-
changed ();
182+
((Jorts.Application)application).manager.save_all ();
194183
return GLib.Source.REMOVE;
195184
});
196185
}
@@ -225,7 +214,7 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
225214
debug ("Focus changed!");
226215

227216
if (this.is_active) {
228-
var stylesheet = "io.elementary.stylesheet." + color.to_string ().ascii_down ();
217+
var stylesheet = "io.elementary.stylesheet." + popover.color.to_string ().ascii_down ();
229218
gtk_settings.gtk_theme_name = stylesheet;
230219
}
231220

@@ -253,13 +242,15 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
253242

254243
var data = new NoteData (
255244
editableheader.text,
256-
color,
245+
popover.color,
257246
content,
258-
view.textview.monospace,
247+
popover.monospace,
259248
popover.zoom,
260249
width,
261250
height);
262251

252+
print (" " + popover.color.to_string ());
253+
263254
return data;
264255
}
265256

@@ -276,29 +267,7 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
276267

277268
popover.zoom = data.zoom;
278269
popover.monospace = data.monospace;
279-
color = data.theme;
280-
}
281-
282-
/**
283-
* Switches stylesheet
284-
* First use appropriate stylesheet, Then switch the theme classes
285-
*/
286-
private void on_theme_changed (Jorts.Themes new_theme) {
287-
debug ("Updating theme to %s".printf (new_theme.to_string ()));
288-
289-
print (" - " + new_theme.to_nicename ());
290-
291-
var stylesheet = "io.elementary.stylesheet." + new_theme.to_css_class ();
292-
this.gtk_settings.gtk_theme_name = stylesheet;
293-
294-
if (_old_color.to_string () in css_classes) {
295-
remove_css_class (_old_color.to_string ());
296-
}
297-
298-
_old_color = new_theme;
299-
add_css_class (new_theme.to_string ());
300-
NoteData.latest_theme = new_theme;
301-
changed ();
270+
popover.color = data.theme;
302271
}
303272

304273
private void action_focus_title () {set_focus (editableheader); editableheader.editing = true;}

0 commit comments

Comments
 (0)