diff --git a/src/util.ts b/src/util.ts index 2d002b3..ae69669 100644 --- a/src/util.ts +++ b/src/util.ts @@ -51,6 +51,7 @@ export interface INote { v: 1; uuid: string; content: string; + title: string; style: Style; tags: ITag[]; modified: Date; @@ -151,6 +152,7 @@ export class Note extends GObject.Object { v: 1; uuid: string; content: string; + title: string; style: Style; tag_list: Gio.ListStore; modified: GLib.DateTime; @@ -201,6 +203,7 @@ export class Note extends GObject.Object { this.v = note.v; this.uuid = note.uuid; this.content = note.content; + this.title = note.title; this.style = note.style; this.tag_list = Gio.ListStore.new(Tag.$gtype) as Gio.ListStore; this.tags = note.tags; @@ -211,6 +214,23 @@ export class Note extends GObject.Object { this.width = note.width; this.height = note.height; this.open = note.open ?? false; + + // @ts-expect-error incorrect types + this.bind_property_full( + "content", + this, + "title", + GObject.BindingFlags.SYNC_CREATE, + (_, content) => { + if (!content) return [true, ""]; + let title = content.split("\n")[0].slice(0, 20); + if (title.length != content.length) title += "…"; + return [true, title]; + }, + null + ); + + } static generate() { @@ -218,6 +238,7 @@ export class Note extends GObject.Object { v: 1, uuid: GLib.uuid_string_random(), content: "", + title: "", style: SETTINGS.DEFAULT_STYLE, tags: [], modified: new Date(), @@ -232,6 +253,7 @@ export class Note extends GObject.Object { v: this.v, uuid: this.uuid, content: this.content, + title: this.title, style: this.style, tags: this.tags.map((tag) => ({ name: tag.name, @@ -250,6 +272,7 @@ export class Note extends GObject.Object { v: this.v, uuid: this.uuid, content: this.content, + title: this.title, style: this.style, tags: this.tags, modified: this.modified_date, @@ -270,6 +293,8 @@ export class Note extends GObject.Object { // deno-fmt-ignore content: GObject.ParamSpec.string("content", "Content", "Content of the note", GObject.ParamFlags.READWRITE, ""), // deno-fmt-ignore + title: GObject.ParamSpec.string("title", "Title", "Title of the note", GObject.ParamFlags.READWRITE, ""), + // deno-fmt-ignore style: GObject.ParamSpec.int("style", "Style", "Style of the note", GObject.ParamFlags.READWRITE, 0, 100, 0), // deno-fmt-ignore tag_list: this.tag_list_pspec, diff --git a/src/window.ts b/src/window.ts index 2d971a9..312bdfd 100644 --- a/src/window.ts +++ b/src/window.ts @@ -98,6 +98,20 @@ export class Window extends Adw.ApplicationWindow { this.default_width = note.width; this.default_height = note.height; + this.note.bind_property_full( + "title", + this, + "title", + GObject.BindingFlags.SYNC_CREATE, + (binding, title) => { + if (!title) { + return [true, _("Sticky Note")]; + } + return [true, title]; + }, + null + ); + this.connect("close-request", () => { if (this.deleted) return;