From e5bcd0e52ab216b1b8585aa92de0b8686d45a851 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Wed, 18 Sep 2013 07:40:00 +0200 Subject: [PATCH] Bug 913722 - Last project remains displayed after deleting. r=ochameau --- .../devtools/app-manager/content/projects.js | 43 ++++++++++++++++--- .../app-manager/content/projects.xhtml | 2 +- .../devtools/app-manager/content/template.js | 8 ++++ .../app-manager/test/test_template.html | 31 ++++++++++--- 4 files changed, 70 insertions(+), 14 deletions(-) diff --git a/browser/devtools/app-manager/content/projects.js b/browser/devtools/app-manager/content/projects.js index 6fe906fef01..bc62a99195e 100644 --- a/browser/devtools/app-manager/content/projects.js +++ b/browser/devtools/app-manager/content/projects.js @@ -171,8 +171,34 @@ let UI = { }); }, - remove: function(location) { - AppProjects.remove(location); + remove: function(location, event) { + if (event) { + // We don't want the "click" event to be propagated to the project item. + // That would trigger `selectProject()`. + event.stopPropagation(); + } + + let item = document.getElementById(location); + + let toSelect = document.querySelector(".project-item.selected"); + toSelect = toSelect ? toSelect.id : ""; + + if (toSelect == location) { + toSelect = null; + let sibling; + if (item.previousElementSibling) { + sibling = item.previousElementSibling; + } else { + sibling = item.nextElementSibling; + } + if (sibling && !!AppProjects.get(sibling.id)) { + toSelect = sibling.id; + } + } + + AppProjects.remove(location).then(() => { + this.selectProject(toSelect); + }); }, _getProjectManifestURL: function (project) { @@ -326,15 +352,20 @@ let UI = { break; } } - if (idx == projects.length) { - // Not found - return; - } let oldButton = document.querySelector(".project-item.selected"); if (oldButton) { oldButton.classList.remove("selected"); } + + if (idx == projects.length) { + // Not found. Empty lense. + let lense = document.querySelector("#lense"); + lense.setAttribute("template-for", '{"path":"","childSelector":""}'); + this.template._processFor(lense); + return; + } + let button = document.getElementById(location); button.classList.add("selected"); diff --git a/browser/devtools/app-manager/content/projects.xhtml b/browser/devtools/app-manager/content/projects.xhtml index d625a262e12..fd35cc288eb 100644 --- a/browser/devtools/app-manager/content/projects.xhtml +++ b/browser/devtools/app-manager/content/projects.xhtml @@ -39,7 +39,7 @@
-
+

diff --git a/browser/devtools/app-manager/content/template.js b/browser/devtools/app-manager/content/template.js index ae162a72178..9314067dd00 100644 --- a/browser/devtools/app-manager/content/template.js +++ b/browser/devtools/app-manager/content/template.js @@ -331,10 +331,18 @@ Template.prototype = { !("childSelector" in json)) { throw new Error("missing property"); } + if (rootPath) { json.path = rootPath + "." + json.path; } + if (!json.path) { + // Nothing to show. + this._unregisterNodes(e.querySelectorAll("[template]")); + e.innerHTML = ""; + return; + } + let templateParent = this._doc.querySelector(json.childSelector); if (!templateParent) { throw new Error("can't find child"); diff --git a/browser/devtools/app-manager/test/test_template.html b/browser/devtools/app-manager/test/test_template.html index 8f5aa351608..1830f91f715 100644 --- a/browser/devtools/app-manager/test/test_template.html +++ b/browser/devtools/app-manager/test/test_template.html @@ -14,14 +14,16 @@ -
+
+
ttt foo2:foo_l10n/bar_l10n -
+
meh
+
xx0 a @@ -40,7 +42,8 @@ xxx foo2:foo2_l10n/bar_l10n -
+
meh2
+
xx0 a @@ -58,7 +61,8 @@ xxx foo2:yyy/zzz -
+
+
xx0 a @@ -76,7 +80,8 @@ xxx foo2:yyy/zzz -
+
+
xx0 a @@ -109,7 +114,8 @@ xxx foo2:yyy/zzz -
+
+
xx0 a @@ -135,7 +141,7 @@ -