Skip to content

Commit

Permalink
Save metadata when they change, instead of relying on hide/show events
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed Sep 29, 2020
1 parent 037dff5 commit 4041ce4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions notes@maestroschan.fr/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class NotesManager {
if (deletedNoteId < this._allNotes.length) {
this._allNotes[deletedNoteId] = lastNote;
lastNote.id = deletedNoteId;
this._allNotes[deletedNoteId].onlySave();
this._allNotes[deletedNoteId].onlySave(true);
}
this._deleteNoteFiles(this._allNotes.length);
}
Expand Down Expand Up @@ -204,7 +204,7 @@ class NotesManager {
_hideNotes () {
this._onlyHideNotes();
this._allNotes.forEach(function (n) {
n.onlySave();
n.onlySave(false);
}); // TODO delay that
}

Expand Down Expand Up @@ -317,7 +317,7 @@ class NotesManager {
SETTINGS.disconnect(this._settingsSignals['auto-focus']);

this._allNotes.forEach(function (n) {
n.onlySave();
n.onlySave(false);
n.destroy();
});

Expand Down
38 changes: 19 additions & 19 deletions notes@maestroschan.fr/noteBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ var NoteBox = class NoteBox {
//----------------------------------------------------------------------

this._grabHelper = new GrabHelper.GrabHelper(this.noteEntry)
if (Extension.AUTO_FOCUS) { // TODO dynamically update this
if (Extension.AUTO_FOCUS) { // TODO dynamically update this setting
this.noteEntry.connect('enter-event', this._getKeyFocus.bind(this));
this.noteEntry.connect('leave-event', this._leaveKeyFocus.bind(this));
} else {
Expand Down Expand Up @@ -325,21 +325,17 @@ var NoteBox = class NoteBox {
}
}

// XXX unused
// hide () {
// this.onlyHide();
// this.onlySave();
// }

onlyHide () {
this.actor.visible = false;
if (Extension.Z_POSITION == 'above-all') {
Main.layoutManager.untrackChrome(this.actor);
}
}

onlySave () {
this._saveState();
onlySave (withMetadata) {
if(withMetadata) {
this._saveState();
}
this._saveText();
}

Expand All @@ -362,6 +358,8 @@ var NoteBox = class NoteBox {

_applyTitleChange () {
// TODO
// ...
this.onlySave(true);
}

_applyActorStyle () {
Expand Down Expand Up @@ -404,7 +402,7 @@ var NoteBox = class NoteBox {

_redraw () {
this.actor.get_parent().set_child_above_sibling(this.actor, null);
this.onlySave(); // XXX maybe not
this.onlySave(true);
}

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -470,12 +468,6 @@ var NoteBox = class NoteBox {
this.grabY = Math.floor(event.get_coords()[1]);
}

_onRelease (actor, event) {
this._isResizing = false;
this._isMoving = false;
this.onlySave();
}

_onResizeMotion (actor, event) {
if (!this._isResizing) { return; }
let x = Math.floor(event.get_coords()[0]);
Expand Down Expand Up @@ -519,6 +511,12 @@ var NoteBox = class NoteBox {
this.grabY = event_y;
}

_onRelease (actor, event) {
this._isResizing = false;
this._isMoving = false;
this.onlySave(true);
}

//--------------------------------------------------------------------------
// "Public" methods called by the NoteOptionsMenu's code -------------------

Expand All @@ -527,6 +525,7 @@ var NoteBox = class NoteBox {
this._fontSize += delta;
this._applyNoteStyle();
}
this.onlySave(true);
}

/*
Expand All @@ -535,9 +534,9 @@ var NoteBox = class NoteBox {
* 'r,g,b' format. Then, the text coloration and the CSS is updated.
*/
applyColor (r, g, b) {
if (Number.isNaN(r)) { r = 255; }
if (Number.isNaN(g)) { g = 255; }
if (Number.isNaN(b)) { b = 255; }
if (Number.isNaN(r)) r = 255;
if (Number.isNaN(g)) g = 255;
if (Number.isNaN(b)) b = 255;
r = Math.min(Math.max(0, r), 255);
g = Math.min(Math.max(0, g), 255);
b = Math.min(Math.max(0, b), 255);
Expand All @@ -549,6 +548,7 @@ var NoteBox = class NoteBox {
}
this._applyNoteStyle();
this._applyActorStyle();
this.onlySave(true);
}

//--------------------------------------------------------------------------
Expand Down

1 comment on commit 4041ce4

@maoschanz
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#43

Please sign in to comment.