Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Added in Auto Save on Focus Lost (#251)
Browse files Browse the repository at this point in the history
* Added in autosave
* Fixing the checked status on the menu item
  • Loading branch information
stolksdorf authored and brrd committed Jan 18, 2019
1 parent 1f0b1da commit 30f8321
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/abr-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ AbrWindow.prototype = {
win.on("focus", function () {
abrWin.menu.attach();
});
win.on("blur", function () {
var startupCommands = abrWin.config.get("startup-commands");
if (startupCommands.autoSaveOnFocusLost) {
abrWin.execCommand("autosave");
}
});
win.on("closed", function () {
// Destroy the window
abrApp.windows[abrWin.id] = null;
Expand Down
6 changes: 6 additions & 0 deletions app/menu-window.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
"accelerator": "CmdOrCtrl+Shift+S",
"command": "saveAs"
},
{
"labelKey": "menu-save-autosave",
"command": "autoSaveOnFocusLost",
"type": "checkbox",
"checked": "startup-commands:autoSaveOnFocusLost"
},
{
"type": "separator"
},
Expand Down
9 changes: 9 additions & 0 deletions app/renderer/abr-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,15 @@ AbrDocument.prototype = {
return this.save(path, callback);
},

autosave: function(path, callback) {
path = path || this.path;
// Only autosave if it's an existing file
if (!path) {
return false;
}
return this.save(path, callback);
},

initWatcher: function () {
var that = this;
// All dialogs should be displayed only if the window is focused.
Expand Down
15 changes: 15 additions & 0 deletions app/renderer/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ var commands = {
abrDoc.saveAs();
},

autosave: function(win, abrDoc, cm) {
abrDoc.autosave();
},

exportHtml: function(win, abrDoc, cm, param) {
abrDoc.exportHtml(param);
},
Expand Down Expand Up @@ -145,6 +149,17 @@ var commands = {
}
},

autoSaveOnFocusLost: function(win, abrDoc, cm) {
if (cm) {
var flag = cm.getOption("autoSaveOnFocusLost");
cm.setOption("autoSaveOnFocusLost", !flag);
abrDoc.setConfig("startup-commands:autoSaveOnFocusLost", !flag);
} else {
// If cm not loaded yet
abrDoc.commandsToTrigger.push("autoSaveOnFocusLost");
}
},

loadTheme: function (win, abrDoc, cm, param) {
abrDoc.loadTheme(param);
abrDoc.setConfig("theme", param);
Expand Down
3 changes: 2 additions & 1 deletion default/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"showBlocks": false,
"showHiddenCharacters": true,
"showTocPane": false,
"autoCloseBrackets": true
"autoCloseBrackets": true,
"autoSaveOnFocusLost" : false
},
"spellchecker": {
"active": true,
Expand Down
1 change: 1 addition & 0 deletions default/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"menu-open": "Open",
"menu-save": "Save",
"menu-save-as": "Save As…",
"menu-save-autosave": "Save on Focus Lost",
"menu-export-html": "Export as HTML",
"menu-close-document": "Close Document",
"menu-close-window": "Close Window",
Expand Down

0 comments on commit 30f8321

Please sign in to comment.