Index: chrome/browser/resources/file_manager/js/image_editor/gallery.js |
diff --git a/chrome/browser/resources/file_manager/js/image_editor/gallery.js b/chrome/browser/resources/file_manager/js/image_editor/gallery.js |
index 7a7e21945a89aa98212a1e21cbae9e8532b9c9cd..ce674f2a858f4b4253dac68b1ec7587d8aacf0dd 100644 |
--- a/chrome/browser/resources/file_manager/js/image_editor/gallery.js |
+++ b/chrome/browser/resources/file_manager/js/image_editor/gallery.js |
@@ -873,25 +873,26 @@ Ribbon.Item.prototype.createCopyName_ = function () { |
name = name.substr(0, index); |
} |
- if (name.indexOf(Ribbon.Item.COPY_SIGNATURE) == 0) { |
- // TODO(dgozman): add a number to form 'Copy (X) of File.jpg'. |
- name = name.substr(Ribbon.Item.COPY_SIGNATURE.length); |
+ var regExpCopyN = |
+ new RegExp('^' + Ribbon.Item.COPY_SIGNATURE + '(.+) \\((\\d+)\\)$'); |
dgozman
2011/12/07 06:02:09
You can extract regExp constants and place them ne
Vladislav Kaznacheev
2011/12/07 13:11:14
Done.
|
+ var match = regExpCopyN.exec(name); |
+ if (match && match[1] && match[2]) { |
+ var copyNumber = parseInt(match[2], 10) + 1; |
+ name = match[1] + ' (' + copyNumber + ')'; |
+ } else { |
+ var regExpCopy0 = |
+ new RegExp('^' + Ribbon.Item.COPY_SIGNATURE + '(.+)$'); |
+ match = regExpCopy0.exec(name); |
+ if (match && match[1]) { |
+ name = match[1] + ' (1)'; |
+ } |
} |
var mimeType = this.metadata_.mimeType.toLowerCase(); |
if (mimeType != 'image/jpeg') { |
// Chrome can natively encode only two formats: JPEG and PNG. |
// All non-JPEG images are saved in PNG, hence forcing the file extension. |
- if (mimeType == 'image/png') { |
- ext = '.png'; |
- } else { |
- // All non-JPEG images get 'image/png' mimeType (see |
- // ImageEncoder.MetadataEncoder constructor). |
- // This code can be reached only if someone has added a metadata parser |
- // for a format other than JPEG or PNG. The message below is to remind |
- // that one must also come up with the way to encode the image data. |
- console.error('Image encoding for ' + mimeType + ' is not supported'); |
- } |
+ ext = '.png'; |
} |
return Ribbon.Item.COPY_SIGNATURE + name + ext; |