зеркало из https://github.com/mozilla/gecko-dev.git
Bug 794898 - Scratchpad should ask for confirmation before closing; r=harth
This commit is contained in:
Родитель
f2641570d6
Коммит
e4a574e991
|
@ -130,12 +130,13 @@ var Scratchpad = {
|
|||
*/
|
||||
_updateTitle: function SP__updateTitle()
|
||||
{
|
||||
if (this.filename) {
|
||||
document.title = (this.editor && this.editor.dirty ? "*" : "") +
|
||||
this.filename;
|
||||
} else {
|
||||
document.title = this._initialWindowTitle;
|
||||
let title = this.filename || this._initialWindowTitle;
|
||||
|
||||
if (this.editor && this.editor.dirty) {
|
||||
title = "*" + title;
|
||||
}
|
||||
|
||||
document.title = title;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1267,7 +1268,7 @@ var Scratchpad = {
|
|||
*/
|
||||
promptSave: function SP_promptSave(aCallback)
|
||||
{
|
||||
if (this.filename && this.editor.dirty) {
|
||||
if (this.editor.dirty) {
|
||||
let ps = Services.prompt;
|
||||
let flags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_SAVE +
|
||||
ps.BUTTON_POS_1 * ps.BUTTON_TITLE_CANCEL +
|
||||
|
|
|
@ -9,7 +9,7 @@ let NetUtil = tempScope.NetUtil;
|
|||
let FileUtils = tempScope.FileUtils;
|
||||
|
||||
// only finish() when correct number of tests are done
|
||||
const expected = 6;
|
||||
const expected = 9;
|
||||
var count = 0;
|
||||
function done()
|
||||
{
|
||||
|
@ -68,16 +68,42 @@ function testSavedFile()
|
|||
|
||||
function testUnsaved()
|
||||
{
|
||||
testUnsavedFileCancel();
|
||||
function setFilename(aScratchpad, aFile) {
|
||||
aScratchpad.setFilename(aFile);
|
||||
}
|
||||
|
||||
testUnsavedFileCancel(setFilename);
|
||||
testUnsavedFileSave(setFilename);
|
||||
testUnsavedFileDontSave(setFilename);
|
||||
testCancelAfterLoad();
|
||||
testUnsavedFileSave();
|
||||
|
||||
function mockSaveFile(aScratchpad) {
|
||||
let SaveFileStub = function (aCallback) {
|
||||
/*
|
||||
* An argument for aCallback must pass Components.isSuccessCode
|
||||
*
|
||||
* A version of isSuccessCode in JavaScript:
|
||||
* function isSuccessCode(returnCode) {
|
||||
* return (returnCode & 0x80000000) == 0;
|
||||
* }
|
||||
*/
|
||||
aCallback(1);
|
||||
};
|
||||
|
||||
aScratchpad.saveFile = SaveFileStub;
|
||||
}
|
||||
|
||||
// Run these tests again but this time without setting a filename to
|
||||
// test that Scratchpad always asks for confirmation on dirty editor.
|
||||
testUnsavedFileCancel(mockSaveFile);
|
||||
testUnsavedFileSave(mockSaveFile);
|
||||
testUnsavedFileDontSave();
|
||||
}
|
||||
|
||||
function testUnsavedFileCancel()
|
||||
function testUnsavedFileCancel(aCallback=function () {})
|
||||
{
|
||||
openScratchpad(function(win) {
|
||||
win.Scratchpad.setFilename("test.js");
|
||||
aCallback(win.Scratchpad, "test.js");
|
||||
win.Scratchpad.editor.dirty = true;
|
||||
|
||||
promptButton = win.BUTTON_POSITION_CANCEL;
|
||||
|
@ -118,11 +144,11 @@ function testCancelAfterLoad()
|
|||
}, {noFocus: true});
|
||||
}
|
||||
|
||||
function testUnsavedFileSave()
|
||||
function testUnsavedFileSave(aCallback=function () {})
|
||||
{
|
||||
openScratchpad(function(win) {
|
||||
win.Scratchpad.importFromFile(gFile, true, function(status, content) {
|
||||
win.Scratchpad.setFilename(gFile.path);
|
||||
aCallback(win.Scratchpad, gFile.path);
|
||||
|
||||
let text = "new text";
|
||||
win.Scratchpad.setText(text);
|
||||
|
@ -140,10 +166,10 @@ function testUnsavedFileSave()
|
|||
}, {noFocus: true});
|
||||
}
|
||||
|
||||
function testUnsavedFileDontSave()
|
||||
function testUnsavedFileDontSave(aCallback=function () {})
|
||||
{
|
||||
openScratchpad(function(win) {
|
||||
win.Scratchpad.setFilename(gFile.path);
|
||||
aCallback(win.Scratchpad, gFile.path);
|
||||
win.Scratchpad.editor.dirty = true;
|
||||
|
||||
promptButton = win.BUTTON_POSITION_DONT_SAVE;
|
||||
|
|
|
@ -32,7 +32,7 @@ function testListeners()
|
|||
{
|
||||
openScratchpad(function(aWin, aScratchpad) {
|
||||
aScratchpad.setText("new text");
|
||||
ok(!isStar(aWin), "no star if scratchpad isn't from a file");
|
||||
ok(isStar(aWin), "show start if scratchpad text changes");
|
||||
|
||||
aScratchpad.editor.dirty = false;
|
||||
ok(!isStar(aWin), "no star before changing text");
|
||||
|
@ -68,7 +68,7 @@ function testRestoreNotFromFile()
|
|||
let [win] = ScratchpadManager.restoreSession(session);
|
||||
openScratchpad(function(aWin, aScratchpad) {
|
||||
aScratchpad.setText("new text");
|
||||
ok(!isStar(win), "no star if restored scratchpad isn't from a file");
|
||||
ok(isStar(win), "show star if restored scratchpad isn't from a file");
|
||||
|
||||
win.close();
|
||||
done();
|
||||
|
|
Загрузка…
Ссылка в новой задаче