Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface INote {
v: 1;
uuid: string;
content: string;
title: string;
style: Style;
tags: ITag[];
modified: Date;
Expand Down Expand Up @@ -151,6 +152,7 @@ export class Note extends GObject.Object {
v: 1;
uuid: string;
content: string;
title: string;
style: Style;
tag_list: Gio.ListStore<Tag>;
modified: GLib.DateTime;
Expand Down Expand Up @@ -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<Tag>;
this.tags = note.tags;
Expand All @@ -211,13 +214,31 @@ 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() {
return new this({
v: 1,
uuid: GLib.uuid_string_random(),
content: "",
title: "",
style: SETTINGS.DEFAULT_STYLE,
tags: [],
modified: new Date(),
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ export class Window extends Adw.ApplicationWindow {
this.default_width = note.width;
this.default_height = note.height;

this.note.bind_property(
"title",
this,
"title",
GObject.BindingFlags.SYNC_CREATE
);

this.connect("close-request", () => {
if (this.deleted) return;

Expand Down
Loading