Skip to content

Commit

Permalink
Merge pull request #143 from anig1scur/main
Browse files Browse the repository at this point in the history
  • Loading branch information
vixalien authored Oct 30, 2024
2 parents 9a22dc8 + ee60b6f commit 6c40104
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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
14 changes: 14 additions & 0 deletions src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 6c40104

Please sign in to comment.