Raising a tab will check its modified date. Fixes #25

This commit is contained in:
Thomas Wilburn 2013-09-20 17:39:04 -07:00
parent 2b92737e60
commit 7cffe61ad6
3 changed files with 34 additions and 2 deletions

View file

@ -1,4 +1,4 @@
define(["dom2"], function() {
define(["editor", "dom2"], function(editor) {
return function(text, buttons, callback) {
if (typeof buttons == "function" || typeof buttons == "undefined") {
@ -30,6 +30,7 @@ define(["dom2"], function() {
modal.remove();
var value = JSON.parse(this.value);
if (callback) callback(value);
editor.focus();
};
buttons.forEach(function(options) {
@ -42,13 +43,18 @@ define(["dom2"], function() {
}
button.innerHTML = options.label;
button.value = options.value;
if (options.focus) {
button.className = "default";
}
buttonRow.append(button);
button.on("click", clickButton);
});
setTimeout(function() {
//ensure focus, even from palette (which normally refocuses editor)
modal.find("button").focus();
var button = modal.find("button.default");
if (!button) button = modal.find("button");
button.focus();
});
}

View file

@ -53,6 +53,29 @@ define([
sessions.renderTabs();
});
});
command.on("session:check-file", function() {
var tab = sessions.getCurrent();
if (!tab.file) return;
tab.file.entry.file(function(entry) {
if (tab.modifiedAt && entry.lastModifiedDate > tab.modifiedAt) {
if (tab.modified) {
dialog(
"This file has been modified since the last time it was saved. Would you like to reload?",
[{label: "Reload", value: true}, {label: "Cancel", value: false, focus: true}],
function(confirmed) {
if (confirmed) {
command.fire("session:revert-file");
} else {
tab.modifiedAt = new Date();
}
}
);
} else {
command.fire("session:revert-file");
}
}
});
});
command.on("session:open-settings-file", function(name) {
Settings.load(name, function() {

View file

@ -19,6 +19,7 @@ define([
if (file) {
session.file = file;
session.fileName = file.entry.name;
session.modifiedAt = new Date();
} else {
session.fileName = "untitled.txt";
}
@ -46,6 +47,7 @@ define([
var whenOpen = function() {
self.file.write(content, c);
self.modified = false;
self.modifiedAt = new Date();
renderTabs();
};
@ -233,6 +235,7 @@ define([
var raiseTab = function(index) {
var tab = tabs[index];
tab.raise();
command.fire("session:check-file");
};
var switchTab = function(shift) {