Skip to content

Commit d912647

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

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/util.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface INote {
5151
v: 1;
5252
uuid: string;
5353
content: string;
54+
title: string;
5455
style: Style;
5556
tags: ITag[];
5657
modified: Date;
@@ -151,6 +152,7 @@ export class Note extends GObject.Object {
151152
v: 1;
152153
uuid: string;
153154
content: string;
155+
title: string;
154156
style: Style;
155157
tag_list: Gio.ListStore<Tag>;
156158
modified: GLib.DateTime;
@@ -201,6 +203,7 @@ export class Note extends GObject.Object {
201203
this.v = note.v;
202204
this.uuid = note.uuid;
203205
this.content = note.content;
206+
this.title = note.title;
204207
this.style = note.style;
205208
this.tag_list = Gio.ListStore.new(Tag.$gtype) as Gio.ListStore<Tag>;
206209
this.tags = note.tags;
@@ -211,13 +214,32 @@ export class Note extends GObject.Object {
211214
this.width = note.width;
212215
this.height = note.height;
213216
this.open = note.open ?? false;
217+
218+
// @ts-expect-error incorrect types
219+
this.bind_property_full(
220+
"content",
221+
this,
222+
"title",
223+
GObject.BindingFlags.SYNC_CREATE,
224+
(_, content) => {
225+
if (!content) return [false, ""];
226+
return [true, content.substring(0, 24)]
227+
},
228+
null
229+
);
230+
231+
this.connect("notify::title", () => {
232+
console.log("title-changed, title-changed")
233+
this.emit('title-changed');
234+
});
214235
}
215236

216237
static generate() {
217238
return new this({
218239
v: 1,
219240
uuid: GLib.uuid_string_random(),
220241
content: "",
242+
title: "",
221243
style: SETTINGS.DEFAULT_STYLE,
222244
tags: [],
223245
modified: new Date(),
@@ -232,6 +254,7 @@ export class Note extends GObject.Object {
232254
v: this.v,
233255
uuid: this.uuid,
234256
content: this.content,
257+
title: this.title,
235258
style: this.style,
236259
tags: this.tags.map((tag) => ({
237260
name: tag.name,
@@ -250,6 +273,7 @@ export class Note extends GObject.Object {
250273
v: this.v,
251274
uuid: this.uuid,
252275
content: this.content,
276+
title: this.title,
253277
style: this.style,
254278
tags: this.tags,
255279
modified: this.modified_date,
@@ -270,6 +294,8 @@ export class Note extends GObject.Object {
270294
// deno-fmt-ignore
271295
content: GObject.ParamSpec.string("content", "Content", "Content of the note", GObject.ParamFlags.READWRITE, ""),
272296
// deno-fmt-ignore
297+
title: GObject.ParamSpec.string("title", "Title", "Title of the note", GObject.ParamFlags.READWRITE, ""),
298+
// deno-fmt-ignore
273299
style: GObject.ParamSpec.int("style", "Style", "Style of the note", GObject.ParamFlags.READWRITE, 0, 100, 0),
274300
// deno-fmt-ignore
275301
tag_list: this.tag_list_pspec,
@@ -282,6 +308,9 @@ export class Note extends GObject.Object {
282308
// deno-fmt-ignore
283309
open: GObject.ParamSpec.boolean("open", "Open", "Whether the note was open when the application was closed", GObject.ParamFlags.READWRITE, false),
284310
},
311+
Signals: {
312+
'title-changed': {},
313+
},
285314
}, this);
286315
}
287316
}

src/window.ts

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

101+
this.update_title();
102+
103+
this.note.connect("title-changed", () => {
104+
this.update_title();
105+
console.log("update_title, update_title")
106+
});
107+
101108
this.connect("close-request", () => {
102109
if (this.deleted) return;
103110

@@ -151,6 +158,14 @@ export class Window extends Adw.ApplicationWindow {
151158
popover.add_child(this.selector, "notestyleswitcher");
152159
}
153160

161+
update_title() {
162+
if (this.note.title === "") {
163+
this.set_title(_("Untitled Note"));
164+
return;
165+
}
166+
this.set_title(this.note.title);
167+
}
168+
154169
last_revealer = false;
155170

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

0 commit comments

Comments
 (0)