Skip to content

Commit 746a476

Browse files
committed
introduce a scribblycontroller
1 parent b02c77a commit 746a476

File tree

7 files changed

+77
-80
lines changed

7 files changed

+77
-80
lines changed

data/Application.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ actionbar .themedbutton:focus {
6565
}
6666

6767
/* Obfuscate note */
68-
.scribbly {
68+
window.scribbly textview.view,
69+
window.scribbly editablelabel {
6970
font-family: "Redacted Script";
7071
}
7172

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2017-2024 Lains
4+
* 2025 Stella & Charlie (teamcons.carrd.co)
5+
* 2025 Contributions from the ellie_Commons community (github.com/ellie-commons/)
6+
*/
7+
8+
/*************************************************/
9+
/**
10+
* Responsible to apply RedactedScript font
11+
*/
12+
public class Jorts.ScribblyController : Object {
13+
14+
private Jorts.StickyNoteWindow window;
15+
16+
private bool _scribble;
17+
public bool scribble {
18+
get { return _scribble;}
19+
set { scribble_follow_focus (value);}
20+
};
21+
22+
public ScribblyController (Jorts.StickyNoteWindow window) {
23+
this.window = window;
24+
}
25+
26+
construct {
27+
Application.gsettings.bind (
28+
"scribbly-mode-active",
29+
this, "scribble",
30+
SettingsBindFlags.DEFAULT);
31+
}
32+
33+
/**
34+
* Connect-disconnect the whole manage text being scribbled
35+
*/
36+
private void scribble_follow_focus (bool is_activated) {
37+
debug ("Scribbly mode changed!");
38+
39+
if (is_activated) {
40+
window.notify["is-active"].connect (focus_scribble_unscribble);
41+
scribbly_set (!window.is_active);
42+
43+
} else {
44+
window.notify["is-active"].disconnect (focus_scribble_unscribble);
45+
scribbly_set (false);
46+
}
47+
48+
_scribble = is_activated;
49+
}
50+
51+
/**
52+
* Handler connected only when scribbly mode is active
53+
*/
54+
private void focus_scribble_unscribble () {
55+
debug ("Scribbly mode changed!");
56+
scribbly_set (!window.is_active);
57+
}
58+
59+
/**
60+
* Wrapper to abstract setting/removing CSS as a book
61+
*/
62+
private void scribbly_set (bool if_scribbly) {
63+
if (if_scribbly) {
64+
window.add_css_class ("scribbly");
65+
66+
} else {
67+
if ("scribbly" in window.css_classes) {
68+
window.remove_css_class ("scribbly");
69+
}
70+
}
71+
}
72+
}

src/Views/NoteView.vala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
set { mono_set (value);}
2121
}
2222

23-
public bool scribbly {
24-
get { return textview.scribbly;}
25-
set { scribbly_set (value);}
26-
}
27-
2823
public string title {
2924
owned get { return editablelabel.text;}
3025
set { editablelabel.text = value;}
@@ -88,9 +83,4 @@
8883
editablelabel.monospace = if_mono;
8984
textview.monospace = if_mono;
9085
}
91-
92-
private void scribbly_set (bool if_scribbly) {
93-
editablelabel.scribbly = if_scribbly;
94-
textview.scribbly = if_scribbly;
95-
}
9686
}

src/Widgets/EditableLabel.vala

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ public class Jorts.EditableLabel : Granite.Bin {
2828
set { mono_set (value);}
2929
}
3030

31-
public bool scribbly {
32-
get { return "scribbly" in this.css_classes;}
33-
set { scribbly_set (value);}
34-
}
35-
3631
construct {
3732
editablelabel = new Gtk.EditableLabel ("") {
3833
xalign = 0.5f,
@@ -64,15 +59,4 @@ public class Jorts.EditableLabel : Granite.Bin {
6459
}
6560
}
6661
}
67-
68-
private void scribbly_set (bool if_scribbly) {
69-
if (if_scribbly) {
70-
this.add_css_class ("scribbly");
71-
72-
} else {
73-
if ("scribbly" in this.css_classes) {
74-
this.remove_css_class ("scribbly");
75-
}
76-
}
77-
}
7862
}

src/Widgets/TextView.vala

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ public class Jorts.TextView : Granite.HyperTextView {
1616
set {buffer.text = value;}
1717
}
1818

19-
public bool scribbly {
20-
get { return "scribbly" in this.css_classes;}
21-
set { scribbly_set (value);}
22-
}
23-
2419
construct {
2520
buffer = new Gtk.TextBuffer (null);
2621
bottom_margin = 10;
@@ -48,15 +43,4 @@ public class Jorts.TextView : Granite.HyperTextView {
4843
}
4944
});
5045
}
51-
52-
private void scribbly_set (bool if_scribbly) {
53-
if (if_scribbly) {
54-
this.add_css_class ("scribbly");
55-
56-
} else {
57-
if ("scribbly" in this.css_classes) {
58-
this.remove_css_class ("scribbly");
59-
}
60-
}
61-
}
6246
}

src/Windows/StickyNoteWindow.vala

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
2121
public TextView textview;
2222

2323
private Jorts.ZoomController zoomcontroller;
24+
private Jorts.ScribblyController scribblycontroller;
2425

2526
public NoteData data {
2627
owned get { return packaged ();}
@@ -88,7 +89,7 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
8889
title = "" + _(" - Jorts");
8990

9091
zoomcontroller = new Jorts.ZoomController (this);
91-
92+
scribblycontroller = new Jorts.ScribblyController (this);
9293

9394
/*****************************************/
9495
/* HEADERBAR */
@@ -110,7 +111,6 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
110111
/* LOADING */
111112
/****************************************/
112113

113-
on_scribbly_changed ();
114114
load_data (data);
115115

116116
/***************************************************/
@@ -127,10 +127,6 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
127127
// Use the color theme of this sticky note when focused
128128
this.notify["is-active"].connect (on_focus_changed);
129129

130-
//The application tells us the squiffly state has changed!
131-
on_scribbly_changed ();
132-
Application.gsettings.changed["scribbly-mode-active"].connect (on_scribbly_changed);
133-
134130
// Respect animation settings for showing ui elements
135131
if (Gtk.Settings.get_default ().gtk_enable_animations && (!Application.gsettings.get_boolean ("hide-bar"))) {
136132
show.connect_after (delayed_show);
@@ -185,37 +181,6 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
185181
}
186182
}
187183

188-
/**
189-
* Connect-disconnect the whole manage text being scribbled
190-
*/
191-
private void on_scribbly_changed () {
192-
debug ("Scribbly mode changed!");
193-
194-
if (Application.gsettings.get_boolean ("scribbly-mode-active")) {
195-
this.notify["is-active"].connect (focus_scribble_unscribble);
196-
if (this.is_active) { view.scribbly = false;} else { view.scribbly = true;};
197-
198-
} else {
199-
this.notify["is-active"].disconnect (focus_scribble_unscribble);
200-
view.scribbly = false;
201-
}
202-
}
203-
204-
/**
205-
* Handler connected only when scribbly mode is active
206-
* It just hides or show depending on focus
207-
*/
208-
private void focus_scribble_unscribble () {
209-
debug ("Scribbly mode changed!");
210-
211-
if (this.is_active) {
212-
view.scribbly = false;
213-
214-
} else {
215-
view.scribbly = true;
216-
}
217-
}
218-
219184
/**
220185
* Package the note into a NoteData and pass it back.
221186
* Used by NoteManager to pass all informations conveniently for storage

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sources = files (
1010
'Services' / 'Storage.vala',
1111
'Services' / 'NoteManager.vala',
1212
'Services' / 'ZoomController.vala',
13+
'Services' / 'ScribblyController.vala',
1314

1415
'Widgets' / 'EditableLabel.vala',
1516
'Widgets' / 'TextView.vala',

0 commit comments

Comments
 (0)