Backout fd093acb629e (bug 793031) for causing bug 801660

This commit is contained in:
Ed Morley 2012-10-15 16:24:44 +01:00
parent d925c6eb2a
commit dbfd514e74
3 changed files with 9 additions and 68 deletions

View File

@ -688,18 +688,6 @@ var Scratchpad = {
file.initWithPath(filePath);
}
if (!file.exists()) {
this.notificationBox.appendNotification(
this.strings.GetStringFromName("fileNoLongerExists.notification"),
"file-no-longer-exists",
null,
this.notificationBox.PRIORITY_WARNING_HIGH,
null);
this.clearFiles(aIndex, 1);
return;
}
this.setFilename(file.path);
this.importFromFile(file, false);
this.setRecentFile(file);
@ -841,23 +829,6 @@ var Scratchpad = {
}
},
/**
* Clear a range of files from the list.
*
* @param integer aIndex
* Index of file in menu to remove.
* @param integer aLength
* Number of files from the index 'aIndex' to remove.
*/
clearFiles: function SP_clearFile(aIndex, aLength)
{
let filePaths = this.getRecentFiles();
let branch = Services.prefs.
getBranch("devtools.scratchpad.");
filePaths.splice(aIndex, aLength);
branch.setCharPref("recentFilePaths", JSON.stringify(filePaths));
},
/**
* Clear all recent files.
*/
@ -888,8 +859,11 @@ var Scratchpad = {
let filePaths = this.getRecentFiles();
if (maxRecent < filePaths.length) {
let branch = Services.prefs.
getBranch("devtools.scratchpad.");
let diff = filePaths.length - maxRecent;
this.clearFiles(0, diff);
filePaths.splice(0, diff);
branch.setCharPref("recentFilePaths", JSON.stringify(filePaths));
}
}
},

View File

@ -101,7 +101,7 @@ function testHideMenu()
let menu = gScratchpadWindow.document.getElementById("sp-open_recent-menu");
ok(menu.hasAttribute("hidden"), "The menu was hidden successfully.");
Services.prefs.setIntPref("devtools.scratchpad.recentFilesMax", 2);
Services.prefs.setIntPref("devtools.scratchpad.recentFilesMax", 1);
}
// We have set the recentFilesMax-pref to one (1), this enables the feature,
@ -114,7 +114,7 @@ function testChangedMaxRecent()
lists.recentFiles04 = gScratchpad.getRecentFiles();
is(lists.recentFiles04.length, 2,
is(lists.recentFiles04.length, 1,
"Two recent files were successfully removed from the 'recent files'-list");
let doc = gScratchpadWindow.document;
@ -123,39 +123,13 @@ function testChangedMaxRecent()
let menuitemLabel = popup.children[0].getAttribute("label");
let correctMenuItem = false;
if (menuitemLabel === lists.recentFiles03[2] &&
menuitemLabel === lists.recentFiles04[1]) {
menuitemLabel === lists.recentFiles04[0]) {
correctMenuItem = true;
}
is(correctMenuItem, true,
"Two recent files were successfully removed from the 'Open Recent'-menu");
// We now remove one file from the harddrive and use the recent-menuitem for
// it to make sure the user is notified that the file no longer exists.
// This is tested in testOpenDeletedFile().
gFile02.remove(false);
gFile02 = null;
gScratchpad.openFile(1);
}
// By now we should have two recent files stored in the list but one of the
// files should be missing on the harddrive.
function testOpenDeletedFile() {
let doc = gScratchpadWindow.document;
let popup = doc.getElementById("sp-menu-open_recentPopup");
is(gScratchpad.getRecentFiles().length, 1,
"The missing file was successfully removed from the list.");
// The number of recent files stored, plus the separator and the
// clearRecentMenuItems-item.
is(popup.children.length, 3,
"The missing file was successfully removed from the menu.");
ok(gScratchpad.notificationBox.currentNotification,
"The notification was successfully displayed.");
is(gScratchpad.notificationBox.currentNotification.label,
gScratchpad.strings.GetStringFromName("fileNoLongerExists.notification"),
"The notification label is correct.");
gScratchpad.clearRecentFiles();
}
@ -286,10 +260,6 @@ var PreferenceObserver = {
break;
case 7:
this.timesFired = 8;
testOpenDeletedFile();
break;
case 8:
this.timesFired = 9;
testClearedAll();
break;
}
@ -307,7 +277,8 @@ function test()
registerCleanupFunction(function () {
gFile01.remove(false);
gFile01 = null;
// gFile02 was removed earlier.
gFile02.remove(false);
gFile02 = null;
gFile03.remove(false);
gFile03 = null;
gFile04.remove(false);

View File

@ -78,7 +78,3 @@ browserContext.notification=This scratchpad executes in the Browser context.
# LOCALIZATION NOTE (help.openDocumentationPage): This returns a localized link with
# documentation for Scratchpad on MDN.
help.openDocumentationPage=https://developer.mozilla.org/en/Tools/Scratchpad
# LOCALIZATION NOTE (fileExists.notification): This is the message displayed
# over the top of the the editor when a file does not exist.
fileNoLongerExists.notification=This file no longer exists.