Bug 1123125 - hasChild existed in new.js and resources.js, removed from new.js and changed function call to hasChild function existing in resources.js. r=jryans
authorJohn Tungul <jtungul53@yahoo.com>
Thu, 22 Jan 2015 12:04:00 +0100
changeset 225637 92c38ff324f6354bafca16b95143ff96a8fdc54f
parent 225636 df5c6946b5878408f4bb9b9bdb2fddfd05bac2f9
child 225638 95c76c3b01726526eb9ff8152c8d3f8c94a86006
child 225820 8248339059d1af1ecdfa4ba9c9fb1b2d3f64f6cd
push id28173
push usercbook@mozilla.com
push dateMon, 26 Jan 2015 13:24:51 +0000
treeherdermozilla-central@95c76c3b0172 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1123125
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1123125 - hasChild existed in new.js and resources.js, removed from new.js and changed function call to hasChild function existing in resources.js. r=jryans
browser/devtools/projecteditor/lib/plugins/new/new.js
browser/devtools/projecteditor/lib/plugins/rename/rename.js
browser/devtools/projecteditor/lib/stores/resource.js
--- a/browser/devtools/projecteditor/lib/plugins/new/new.js
+++ b/browser/devtools/projecteditor/lib/plugins/new/new.js
@@ -46,17 +46,17 @@ var NewFile = Class({
       let template = "untitled{1}." + extension;
       let name = this.suggestName(parent, template);
 
       tree.promptNew(name, parent, sibling).then(name => {
 
         // XXX: sanitize bad file names.
 
         // If the name is already taken, just add/increment a number.
-        if (this.hasChild(parent, name)) {
+        if (parent.hasChild(name)) {
           let matches = name.match(/([^\d.]*)(\d*)([^.]*)(.*)/);
           template = matches[1] + "{1}" + matches[3] + matches[4];
           name = this.suggestName(parent, template, parseInt(matches[2]) || 2);
         }
 
         return parent.createChild(name);
       }).then(resource => {
         tree.selectResource(resource);
@@ -66,24 +66,15 @@ var NewFile = Class({
   },
 
   suggestName: function(parent, template, start=1) {
     let i = start;
     let name;
     do {
       name = template.replace("\{1\}", i === 1 ? "" : i);
       i++;
-    } while (this.hasChild(parent, name));
+    } while (parent.hasChild(name));
 
     return name;
-  },
-
-  hasChild: function(resource, name) {
-    for (let child of resource.children) {
-      if (child.basename === name) {
-        return true;
-      }
-    }
-    return false;
   }
-})
+});
 exports.NewFile = NewFile;
 registerPlugin(NewFile);
--- a/browser/devtools/projecteditor/lib/plugins/rename/rename.js
+++ b/browser/devtools/projecteditor/lib/plugins/rename/rename.js
@@ -28,17 +28,17 @@ var RenamePlugin = Class({
       let resource = tree.getSelectedResource();
       let parent = resource.parent;
       let oldName = resource.basename;
 
       tree.promptEdit(oldName, resource).then(name => {
         if (name === oldName) {
           return resource;
         }
-        if (resource.hasChild(parent, name)) {
+        if (parent.hasChild(name)) {
           let matches = name.match(/([^\d.]*)(\d*)([^.]*)(.*)/);
           let template = matches[1] + "{1}" + matches[3] + matches[4];
           name = this.suggestName(resource, template, parseInt(matches[2]) || 2);
         }
         return parent.rename(oldName,name);
       }).then(resource => {
         this.host.project.refresh();
         tree.selectResource(resource);
@@ -51,16 +51,16 @@ var RenamePlugin = Class({
 
   suggestName: function(resource, template, start=1) {
     let i = start;
     let name;
     let parent = resource.parent;
     do {
       name = template.replace("\{1\}", i === 1 ? "" : i);
       i++;
-    } while (resource.hasChild(parent, name));
+    } while (parent.hasChild(name));
 
     return name;
   }
 });
 
 exports.RenamePlugin = RenamePlugin;
 registerPlugin(RenamePlugin);
--- a/browser/devtools/projecteditor/lib/stores/resource.js
+++ b/browser/devtools/projecteditor/lib/stores/resource.js
@@ -122,23 +122,22 @@ var Resource = Class({
     resource.parent = this;
     this.children.add(resource);
     this.store.notifyAdd(resource);
     emit(this, "children-changed", this);
     return resource;
   },
 
   /**
-   * Checks a resource has child with specific name.
+   * Checks if current object has child with specific name.
    *
-   * @param Resource resource
    * @param string name
    */
-  hasChild: function(resource, name) {
-    for (let child of resource.children) {
+  hasChild: function(name) {
+    for (let child of this.children) {
       if (child.basename === name) {
         return true;
       }
     }
     return false;
   },
 
   /**