Skip to content

Commit 1d8a526

Browse files
committed
feat: update title on note content change
1 parent 9a22dc8 commit 1d8a526

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
project('sticky-notes',
2-
version: '0.2.1',
2+
version: '0.2.2',
33
meson_version: '>= 0.62.0',
44
default_options: [ 'warning_level=2', 'werror=false', ],
55
)

src/view.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class AbstractStickyNote extends Gtk.TextView {
4242
"tag-toggle": {
4343
param_types: [GObject.TYPE_STRING, GObject.TYPE_BOOLEAN],
4444
},
45+
"content-changed": {},
4546
"selection-changed": {},
4647
"link-selected": {
4748
param_types: [GObject.TYPE_STRING],
@@ -429,6 +430,7 @@ export class WriteableStickyNote extends AbstractStickyNote {
429430
this.update_links();
430431
if (this.buffer.text == this.note!.content) return;
431432
this.change("content", this.buffer.text);
433+
this.emit("content-changed");
432434
});
433435

434436
this.buffer.connect("mark-set", () => {

src/window.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ export class Window extends Adw.ApplicationWindow {
9898
this.default_width = note.width;
9999
this.default_height = note.height;
100100

101+
this.update_title();
102+
101103
this.connect("close-request", () => {
102104
if (this.deleted) return;
103105

@@ -121,6 +123,7 @@ export class Window extends Adw.ApplicationWindow {
121123

122124
this.view = new WriteableStickyNote(note);
123125
this.view.connect("selection-changed", this.check_tags.bind(this));
126+
this.view.connect("content-changed", this.update_title.bind(this));
124127
this.view.connect(
125128
"tag-toggle",
126129
(_view: WriteableStickyNote, tag: string, active: boolean) => {
@@ -151,6 +154,16 @@ export class Window extends Adw.ApplicationWindow {
151154
popover.add_child(this.selector, "notestyleswitcher");
152155
}
153156

157+
update_title() {
158+
const maxLength = 24;
159+
let title = this.note.content || `Sticky Note ${this.note.uuid}`;
160+
161+
if (title.length > maxLength) {
162+
title = title.substring(0, maxLength) + "...";
163+
}
164+
this.set_title(title);
165+
}
166+
154167
last_revealer = false;
155168

156169
update_link(selected: boolean, text: string) {

0 commit comments

Comments
 (0)