Index: chrome/browser/resources/file_manager/js/file_manager.js |
diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js |
index 0425871ddecccc762785cebdd196313897c40570..49119652586b2d72d1ec90cbba65519ba7d88e41 100644 |
--- a/chrome/browser/resources/file_manager/js/file_manager.js |
+++ b/chrome/browser/resources/file_manager/js/file_manager.js |
@@ -1137,9 +1137,7 @@ FileManager.prototype = { |
cr.ui.Grid.decorate(this.grid_); |
var self = this; |
- this.grid_.itemConstructor = function(entry) { |
- return self.renderThumbnail_(entry); |
- }; |
+ this.grid_.itemConstructor = GridItem.bind(null, this); |
this.grid_.selectionModel = new this.selectionModelClass_(); |
@@ -1663,8 +1661,29 @@ FileManager.prototype = { |
return box; |
}; |
- FileManager.prototype.renderThumbnail_ = function(entry) { |
- var li = this.document_.createElement('li'); |
+ function GridItem(fileManager, entry) { |
+ var li = fileManager.document_.createElement('li'); |
+ GridItem.decorate(li, fileManager, entry); |
+ return li; |
+ } |
+ |
+ GridItem.prototype = { |
+ __proto__: cr.ui.ListItem.prototype, |
+ |
+ get label() { |
+ return this.querySelector('filename-label').textContent; |
+ }, |
+ set label(value) { |
+ // Grid sets it to entry. Ignore. |
+ } |
+ }; |
+ |
+ GridItem.decorate = function(li, fileManager, entry) { |
+ li.__proto__ = GridItem.prototype; |
+ fileManager.decorateThumbnail_(li, entry); |
+ }; |
+ |
+ FileManager.prototype.decorateThumbnail_ = function(li, entry) { |
li.className = 'thumbnail-item'; |
if (this.showCheckboxes_) |
@@ -1682,12 +1701,10 @@ FileManager.prototype = { |
div.entry = entry; |
li.appendChild(div); |
- |
- cr.defineProperty(li, 'lead', cr.PropertyKind.BOOL_ATTR); |
- cr.defineProperty(li, 'selected', cr.PropertyKind.BOOL_ATTR); |
- return li; |
}; |
+ GridItem.prototype.__proto__ = cr.ui.ListItem.prototype; |
dgozman
2011/12/09 11:14:43
This is already set above.
SeRya
2011/12/09 14:31:13
Removed.
|
+ |
/** |
* Render the type column of the detail table. |
* |
@@ -1735,12 +1752,17 @@ FileManager.prototype = { |
label.appendChild(this.renderIconType_(entry, columnId, table)); |
label.entry = entry; |
label.className = 'detail-name'; |
+ // Filename need to be in a '.filename-label' container for correct |
+ // work of inplace renaming. |
+ var fileName = this.document_.createElement('div'); |
+ fileName.className = 'filename-label'; |
if (this.currentDirEntry_.name == '') { |
- label.appendChild(this.document_.createTextNode( |
+ fileName.appendChild(this.document_.createTextNode( |
dgozman
2011/12/09 11:14:43
You can use instead:
fileName.textContent = this.g
SeRya
2011/12/09 14:31:13
Fixed and extracted to a method to avoid code dupl
|
this.getLabelForRootPath_(entry.name))); |
} else { |
- label.appendChild(this.document_.createTextNode(entry.name)); |
+ fileName.appendChild(this.document_.createTextNode(entry.name)); |
} |
+ label.appendChild(fileName); |
return label; |
}; |
@@ -3250,49 +3272,43 @@ FileManager.prototype = { |
} |
}; |
- FileManager.prototype.findListItem_ = function(event) { |
+ FileManager.prototype.findListItemForEvent_ = function(event, list) { |
var node = event.srcElement; |
+ // Assume list items are direct children of the list. |
+ if (node == list) |
+ return null; |
while (node) { |
- if (node.tagName == 'LI') |
- break; |
- node = node.parentNode; |
+ var parent = node.parentNode; |
+ if (parent == list) |
+ return node; |
+ node = parent; |
} |
- |
- return node; |
+ return null; |
}; |
FileManager.prototype.onGridMouseDown_ = function(event) { |
this.updateCommands_(); |
- if (this.allowRenameClick_(event, event.srcElement.parentNode)) { |
+ var list = this.grid_; |
+ var item = this.findListItemForEvent_(event, list); |
+ if (!item) |
+ return; |
+ if (this.allowRenameClick_(event, list, item)) { |
event.preventDefault(); |
- this.initiateRename_(event.srcElement); |
+ this.initiateRename_(list, item); |
} |
- |
- if (event.button != 1) |
- return; |
- |
- var li = this.findListItem_(event); |
- if (!li) |
- return; |
}; |
FileManager.prototype.onTableMouseDown_ = function(event) { |
this.updateCommands_(); |
- if (this.allowRenameClick_(event, |
- event.srcElement.parentNode.parentNode)) { |
- event.preventDefault(); |
- this.initiateRename_(event.srcElement); |
- } |
- |
- if (event.button != 1) |
- return; |
- |
- var li = this.findListItem_(event); |
- if (!li) { |
- console.log('li not found', event); |
+ var list = this.table_.list; |
+ var item = this.findListItemForEvent_(event, list); |
+ if (!item) |
return; |
+ if (this.allowRenameClick_(event, list, item)) { |
+ event.preventDefault(); |
+ this.initiateRename_(list, item); |
} |
}; |
@@ -3325,7 +3341,7 @@ FileManager.prototype = { |
* Renames can happen on mouse click if the user clicks on a label twice, |
* at least a half second apart. |
*/ |
- FileManager.prototype.allowRenameClick_ = function(event, row) { |
+ FileManager.prototype.allowRenameClick_ = function(event, list, item) { |
if (this.dialogType_ != FileManager.DialogType.FULL_PAGE || |
this.currentDirEntry_ == null || this.currentDirEntry_.name == '' || |
isSystemDirEntry(this.currentDirEntry_)) { |
@@ -3345,15 +3361,15 @@ FileManager.prototype = { |
} |
var now = new Date(); |
- var path = event.srcElement.entry.fullPath; |
+ var index = list.getIndexOfListItem(item); |
var lastLabelClick = this.lastLabelClick_; |
- this.lastLabelClick_ = {path: path, date: now}; |
+ this.lastLabelClick_ = {index: index, date: now}; |
// Rename already in progress. |
if (this.renameInput_.currentEntry) |
return false; |
- if (lastLabelClick && lastLabelClick.path == path) { |
+ if (lastLabelClick && lastLabelClick.index == index) { |
var delay = now - lastLabelClick.date; |
if (delay > 500 && delay < 2000) { |
this.lastLabelClick_ = null; |
@@ -3364,7 +3380,8 @@ FileManager.prototype = { |
return false; |
}; |
- FileManager.prototype.initiateRename_= function(label) { |
+ FileManager.prototype.initiateRename_= function(list, item) { |
+ var label = item.querySelector('.filename-label'); |
var input = this.renameInput_; |
input.value = label.textContent; |
@@ -3383,7 +3400,8 @@ FileManager.prototype = { |
// This has to be set late in the process so we don't handle spurious |
// blur events. |
- input.currentEntry = label.entry; |
+ var index = list.getIndexOfListItem(item); |
+ input.currentEntry = list.dataModel.item(index); |
}; |
FileManager.prototype.onRenameInputKeyDown_ = function(event) { |