Skip to content

Commit 185b2aa

Browse files
committed
Simplify a bit the scribble handling and introduce an editablelabel
1 parent c75c5fb commit 185b2aa

File tree

7 files changed

+174
-70
lines changed

7 files changed

+174
-70
lines changed

data/Application.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ actionbar .themedbutton:focus {
6666
}
6767

6868
/* Obfuscate note */
69-
window.scribbly textview,
70-
window.scribbly editablelabel {
69+
.scribbly {
7170
font-family: "Redacted Script";
7271
}
7372

po/POTFILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
src/Views/NoteView.vala
2+
src/Widgets/EditableLabel.vala
23
src/Widgets/TextView.vala
34
src/Views/PopoverView.vala
45
src/Widgets/ActionBar.vala

src/Views/NoteView.vala

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public class Jorts.NoteView : Gtk.Box {
99
public Gtk.HeaderBar headerbar;
10-
public Gtk.EditableLabel editablelabel;
10+
public Jorts.EditableLabel editablelabel;
1111
public Jorts.TextView textview;
1212
public Jorts.ActionBar actionbar;
1313

@@ -20,6 +20,21 @@
2020
set { mono_set (value);}
2121
}
2222

23+
public bool scribbly {
24+
get { return textview.scribbly;}
25+
set { scribbly_set (value);}
26+
}
27+
28+
public string title {
29+
owned get { return editablelabel.text;}
30+
set { editablelabel.text = value;}
31+
}
32+
33+
public string content {
34+
owned get { return textview.text;}
35+
set { textview.text = value;}
36+
}
37+
2338
construct {
2439
orientation = VERTICAL;
2540
spacing = 0;
@@ -31,16 +46,7 @@
3146
headerbar.add_css_class ("headertitle");
3247

3348
// Defime the label you can edit. Which is editable.
34-
editablelabel = new Gtk.EditableLabel ("") {
35-
xalign = 0.5f,
36-
halign = Gtk.Align.CENTER,
37-
valign = Gtk.Align.CENTER,
38-
tooltip_markup = Granite.markup_accel_tooltip (
39-
{"<Control>L"},
40-
_("Click to edit the title")
41-
)
42-
};
43-
editablelabel.add_css_class (Granite.STYLE_CLASS_TITLE_LABEL);
49+
editablelabel = new Jorts.EditableLabel ();
4450
headerbar.set_title_widget (editablelabel);
4551

4652
textview = new Jorts.TextView ();
@@ -89,13 +95,12 @@
8995
}
9096

9197
private void mono_set (bool if_mono) {
92-
if (if_mono) {
93-
editablelabel.add_css_class ("monospace");
94-
} else {
95-
if ("monospace" in editablelabel.css_classes) {
96-
editablelabel.remove_css_class ("monospace");
97-
}
98-
}
98+
editablelabel.monospace = if_mono;
9999
textview.monospace = if_mono;
100100
}
101+
102+
private void scribbly_set (bool if_scribbly) {
103+
editablelabel.scribbly = if_scribbly;
104+
textview.scribbly = if_scribbly;
105+
}
101106
}

src/Widgets/EditableLabel.vala

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
* A subclass of Gtk.EditableLabel, incorporating some conveniences
10+
*/
11+
public class Jorts.EditableLabel : Granite.Bin {
12+
13+
private Gtk.EditableLabel editablelabel;
14+
public signal void changed ();
15+
16+
public string text {
17+
owned get { return editablelabel.text;}
18+
set { editablelabel.text = value;}
19+
}
20+
21+
public bool editing {
22+
get { return editablelabel.editing;}
23+
set { editablelabel.editing = value;}
24+
}
25+
26+
public bool monospace {
27+
get { return "monospace" in this.css_classes;}
28+
set { mono_set (value);}
29+
}
30+
31+
public bool scribbly {
32+
get { return "scribbly" in this.css_classes;}
33+
set { scribbly_set (value);}
34+
}
35+
36+
construct {
37+
editablelabel = new Gtk.EditableLabel ("") {
38+
xalign = 0.5f,
39+
halign = Gtk.Align.CENTER,
40+
valign = Gtk.Align.CENTER,
41+
tooltip_markup = Granite.markup_accel_tooltip (
42+
{"<Control>L"},
43+
_("Click to edit the title")
44+
)
45+
};
46+
editablelabel.add_css_class (Granite.STYLE_CLASS_TITLE_LABEL);
47+
child = editablelabel;
48+
49+
editablelabel.changed.connect (repeat_change);
50+
}
51+
52+
/**
53+
* Not using a lambda as they tend to memory leak
54+
*/
55+
private void repeat_change () {changed ();}
56+
57+
private void mono_set (bool if_mono) {
58+
if (if_mono) {
59+
this.add_css_class ("monospace");
60+
61+
} else {
62+
if ("monospace" in this.css_classes) {
63+
this.remove_css_class ("monospace");
64+
}
65+
}
66+
}
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+
}
78+
}

src/Widgets/TextView.vala

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,52 @@
1111
*/
1212
public class Jorts.TextView : Granite.HyperTextView {
1313

14-
public string text {
15-
owned get {return buffer.text;}
16-
set {buffer.text = value;}
17-
}
14+
public string text {
15+
owned get {return buffer.text;}
16+
set {buffer.text = value;}
17+
}
1818

19-
construct {
20-
buffer = new Gtk.TextBuffer (null);
21-
bottom_margin = 10;
22-
left_margin = 10;
23-
right_margin = 10;
24-
top_margin = 5;
19+
public bool scribbly {
20+
get { return "scribbly" in this.css_classes;}
21+
set { scribbly_set (value);}
22+
}
2523

26-
set_hexpand (true);
27-
set_vexpand (true);
28-
set_wrap_mode (Gtk.WrapMode.WORD_CHAR);
29-
}
24+
construct {
25+
buffer = new Gtk.TextBuffer (null);
26+
bottom_margin = 10;
27+
left_margin = 10;
28+
right_margin = 10;
29+
top_margin = 5;
30+
31+
set_hexpand (true);
32+
set_vexpand (true);
33+
set_wrap_mode (Gtk.WrapMode.WORD_CHAR);
34+
35+
//Application.gsettings.bind ("scribbly-mode-active", this, "scribbly", SettingsBindFlags.DEFAULT);
36+
}
37+
38+
public void paste () {
39+
var clipboard = Gdk.Display.get_default ().get_clipboard ();
40+
clipboard.read_text_async.begin ((null), (obj, res) => {
41+
42+
try {
43+
var pasted_text = clipboard.read_text_async.end (res);
44+
this.buffer.text = pasted_text;
3045

31-
public void paste () {
32-
var clipboard = Gdk.Display.get_default ().get_clipboard ();
33-
clipboard.read_text_async.begin ((null), (obj, res) => {
34-
try {
46+
} catch (Error e) {
47+
print ("Cannot access clipboard: " + e.message);
48+
}
49+
});
50+
}
3551

36-
var pasted_text = clipboard.read_text_async.end (res);
37-
this.buffer.text = pasted_text;
52+
private void scribbly_set (bool if_scribbly) {
53+
if (if_scribbly) {
54+
this.add_css_class ("scribbly");
3855

39-
} catch (Error e) {
40-
print ("Cannot access clipboard: " + e.message);
41-
}
42-
});
56+
} else {
57+
if ("scribbly" in this.css_classes) {
58+
this.remove_css_class ("scribbly");
59+
}
4360
}
61+
}
4462
}

src/Windows/StickyNoteWindow.vala

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
120120
this.notify["is-active"].connect (on_focus_changed);
121121

122122
//The application tells us the squiffly state has changed!
123+
on_scribbly_changed ();
123124
Application.gsettings.changed["scribbly-mode-active"].connect (on_scribbly_changed);
124125

126+
125127
// Respect animation settings for showing ui elements
126128
if (Gtk.Settings.get_default ().gtk_enable_animations && (!Application.gsettings.get_boolean ("hide-bar"))) {
127129
show.connect_after (delayed_show);
@@ -182,43 +184,45 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
182184
}
183185

184186
/**
185-
* Handler for scribbly mode settings changed
187+
* Changes the stylesheet accents to the notes color
188+
* Add or remove the Redacted font if the setting is active
189+
*/
190+
private void on_focus_changed () {
191+
debug ("Focus changed!");
192+
193+
if (this.is_active) {
194+
var stylesheet = "io.elementary.stylesheet." + popover.color.to_string ().ascii_down ();
195+
gtk_settings.gtk_theme_name = stylesheet;
196+
}
197+
}
198+
199+
/**
200+
* Connect-disconnect the whole manage text being scribbled
186201
*/
187202
private void on_scribbly_changed () {
188203
debug ("Scribbly mode changed!");
189204

190205
if (Application.gsettings.get_boolean ("scribbly-mode-active")) {
191-
if (this.is_active == false) {
192-
this.add_css_class ("scribbly");
193-
}
206+
this.notify["is-active"].connect (focus_scribble_unscribble);
194207

195208
} else {
196-
if (this.is_active == false) {
197-
this.remove_css_class ("scribbly");
198-
}
209+
this.notify["is-active"].disconnect (focus_scribble_unscribble);
210+
view.scribbly = false;
199211
}
200212
}
201213

202214
/**
203-
* Changes the stylesheet accents to the notes color
204-
* Add or remove the Redacted font if the setting is active
215+
* Handler connected only when scribbly mode is active
216+
* It just hides or show depending on focus
205217
*/
206-
private void on_focus_changed () {
207-
debug ("Focus changed!");
218+
private void focus_scribble_unscribble () {
219+
debug ("Scribbly mode changed!");
208220

209221
if (this.is_active) {
210-
var stylesheet = "io.elementary.stylesheet." + popover.color.to_string ().ascii_down ();
211-
gtk_settings.gtk_theme_name = stylesheet;
212-
}
222+
view.scribbly = false;
213223

214-
if (Application.gsettings.get_boolean ("scribbly-mode-active")) {
215-
if (this.is_active) {
216-
this.remove_css_class ("scribbly");
217-
} else {
218-
this.add_css_class ("scribbly");
219-
}
220-
} else if ("scribbly" in this.css_classes) {
221-
this.remove_css_class ("scribbly");
224+
} else {
225+
view.scribbly = true;
222226
}
223227
}
224228

@@ -229,15 +233,13 @@ public class Jorts.StickyNoteWindow : Gtk.ApplicationWindow {
229233
public NoteData packaged () {
230234
debug ("Packaging into a noteData…");
231235

232-
var content = this.view.textview.buffer.text;
233-
234236
int width ; int height;
235237
this.get_default_size (out width, out height);
236238

237239
var data = new NoteData (
238-
view.editablelabel.text,
240+
view.title,
239241
popover.color,
240-
content,
242+
view.content,
241243
popover.monospace,
242244
popover.zoom,
243245
width,

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ sources = files (
1212
'Services' / 'NoteManager.vala',
1313
'Services' / 'Themer.vala',
1414

15+
'Widgets' / 'EditableLabel.vala',
1516
'Widgets' / 'TextView.vala',
1617
'Widgets' / 'ActionBar.vala',
1718

0 commit comments

Comments
 (0)