Skip to content

Commit

Permalink
Centralize unsaved change confirmation.
Browse files Browse the repository at this point in the history
  • Loading branch information
gskinner committed Jun 18, 2018
1 parent 29d6113 commit aefa89e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 6 additions & 0 deletions dev/src/RegExr.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ export default class RegExr extends EventDispatcher {
resetUnsaved() {
this._savedHash = this.hash;
}

load(state, warn=true) {
if (warn === true) { warn = "You have unsaved changes. Continue without saving?"; }
if (warn && this.unsaved && !confirm(warn)) { return; }
this.state = Utils.clone(state);
}

// private methods:
_initUI() {
Expand Down
3 changes: 1 addition & 2 deletions dev/src/controls/LinkRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ export default class LinkRow {
if (evt.which === 2 || evt.metaKey || evt.ctrlKey) {
window.open(Utils.getPatternURL(this._pattern));
} else {
if (app.unsaved && !confirm("You have unsaved changes. Load pattern without saving?")) { return; }
app.state = Utils.clone(this._pattern);
app.load(this._pattern);
}
}
};
7 changes: 1 addition & 6 deletions dev/src/views/Share.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ export default class Share extends EventDispatcher {
this.nameFld.focus();
this.nameFld.select();
}


this._linkRow.showMessage("<b>Saved.</b> New share link created. Click to copy to clipboard.");
}
}
Expand All @@ -250,10 +248,7 @@ export default class Share extends EventDispatcher {
}

_doNew() {
if (app.unsaved && !confirm("You have unsaved changes. Create new pattern without saving?")) { return; }
app.state = {
flavor: app.flavor.value
}
app.load({flavor: app.flavor.value});
}

_doPrivate() {
Expand Down

0 comments on commit aefa89e

Please sign in to comment.