summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgozman@chromium.org <dgozman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-19 10:27:43 +0000
committerdgozman@chromium.org <dgozman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-19 10:27:43 +0000
commit690c9cac3f30e100f324d8838c18a9c4e4ce943d (patch)
tree6c3cdd4fd4087a6da1ccefa79c4b734c392c9432
parentc370ea3e5e3da8cd3d5deaee79e7820976fb22af (diff)
downloadchromium_src-690c9cac3f30e100f324d8838c18a9c4e4ce943d.zip
chromium_src-690c9cac3f30e100f324d8838c18a9c4e4ce943d.tar.gz
chromium_src-690c9cac3f30e100f324d8838c18a9c4e4ce943d.tar.bz2
Merge 113389 - Fixed the editing of previously edited files
BUG=chromium-os:23768 TEST= Review URL: http://codereview.chromium.org/8818020 TBR=kaznacheev@chromium.org Review URL: http://codereview.chromium.org/8974008 git-svn-id: svn://svn.chromium.org/chrome/branches/963/src@114969 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/resources/file_manager/js/image_editor/gallery.js32
1 files changed, 19 insertions, 13 deletions
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 f8fa8a7..0d2d685 100644
--- a/chrome/browser/resources/file_manager/js/image_editor/gallery.js
+++ b/chrome/browser/resources/file_manager/js/image_editor/gallery.js
@@ -912,6 +912,12 @@ Ribbon.Item.prototype.save = function(
// TODO: Localize?
Ribbon.Item.COPY_SIGNATURE = 'Copy of ';
+Ribbon.Item.REGEXP_COPY_N =
+ new RegExp('^' + Ribbon.Item.COPY_SIGNATURE + '(.+) \\((\\d+)\\)$');
+
+Ribbon.Item.REGEXP_COPY_0 =
+ new RegExp('^' + Ribbon.Item.COPY_SIGNATURE + '(.+)$');
+
Ribbon.Item.prototype.createCopyName_ = function () {
// When saving a modified image we never overwrite the original file (the one
// that existed prior to opening the Gallery. Instead we save to a file named
@@ -931,25 +937,25 @@ 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);
+ // If the file name contains the copy signature add/advance the sequential
+ // number.
+ // TODO(kaznacheev): Check if the name is already taken.
+ var match = Ribbon.Item.REGEXP_COPY_N.exec(name);
+ if (match && match[1] && match[2]) {
+ var copyNumber = parseInt(match[2], 10) + 1;
+ name = match[1] + ' (' + copyNumber + ')';
+ } else {
+ match = Ribbon.Item.REGEXP_COPY_0.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;