| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Called from the main frame when unloading. | 8 * Called from the main frame when unloading. |
| 9 * @param {boolean=} opt_exiting True if the app is exiting. | 9 * @param {boolean=} opt_exiting True if the app is exiting. |
| 10 */ | 10 */ |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 ImageUtil.setAttribute(this.filenameSpacer_, 'renaming', true); | 898 ImageUtil.setAttribute(this.filenameSpacer_, 'renaming', true); |
| 899 this.filenameEdit_.originalValue = this.filenameEdit_.value; | 899 this.filenameEdit_.originalValue = this.filenameEdit_.value; |
| 900 setTimeout(this.filenameEdit_.select.bind(this.filenameEdit_), 0); | 900 setTimeout(this.filenameEdit_.select.bind(this.filenameEdit_), 0); |
| 901 this.onUserAction_(); | 901 this.onUserAction_(); |
| 902 }; | 902 }; |
| 903 | 903 |
| 904 /** | 904 /** |
| 905 * Blur event handler on filename edit box. | 905 * Blur event handler on filename edit box. |
| 906 * | 906 * |
| 907 * @param {Event} event Blur event. | 907 * @param {Event} event Blur event. |
| 908 * @return {boolean} if default action should be prevented. | 908 * @return {Promise} Promise fulfilled on renaming completed. |
| 909 * @private | 909 * @private |
| 910 */ | 910 */ |
| 911 Gallery.prototype.onFilenameEditBlur_ = function(event) { | 911 Gallery.prototype.onFilenameEditBlur_ = function(event) { |
| 912 var item = this.getSingleSelectedItem(); | 912 var item = this.getSingleSelectedItem(); |
| 913 if (item) { | 913 if (item) { |
| 914 var oldEntry = item.getEntry(); | 914 var oldEntry = item.getEntry(); |
| 915 | 915 |
| 916 item.rename(this.filenameEdit_.value).then(function() { | 916 item.rename(this.filenameEdit_.value).then(function() { |
| 917 var event = new Event('content'); | 917 var event = new Event('content'); |
| 918 event.item = item; | 918 event.item = item; |
| 919 event.oldEntry = oldEntry; | 919 event.oldEntry = oldEntry; |
| 920 event.metadata = null; // Metadata unchanged. | 920 event.metadata = null; // Metadata unchanged. |
| 921 this.dataModel_.dispatchEvent(event); | 921 this.dataModel_.dispatchEvent(event); |
| 922 }.bind(this), function(error) { | 922 }.bind(this), function(error) { |
| 923 if (error === 'NOT_CHANGED') | 923 if (error === 'NOT_CHANGED') |
| 924 return; | 924 return Promise.resolve(); |
| 925 this.filenameEdit_.value = | 925 this.filenameEdit_.value = |
| 926 ImageUtil.getDisplayNameFromName(item.getEntry().name); | 926 ImageUtil.getDisplayNameFromName(item.getEntry().name); |
| 927 this.filenameEdit_.focus(); | 927 this.filenameEdit_.focus(); |
| 928 if (typeof error === 'string') | 928 if (typeof error === 'string') |
| 929 this.prompt_.showStringAt('center', error, 5000); | 929 this.prompt_.showStringAt('center', error, 5000); |
| 930 else | 930 else |
| 931 return Promise.reject(error); | 931 return Promise.reject(error); |
| 932 }.bind(this)).catch(function(error) { | 932 }.bind(this)).catch(function(error) { |
| 933 console.error(error.stack || error); | 933 console.error(error.stack || error); |
| 934 }); | 934 }); |
| 935 } | 935 } |
| 936 | 936 |
| 937 ImageUtil.setAttribute(this.filenameSpacer_, 'renaming', false); | 937 ImageUtil.setAttribute(this.filenameSpacer_, 'renaming', false); |
| 938 this.onUserAction_(); | 938 this.onUserAction_(); |
| 939 return Promise.resolve(); |
| 939 }; | 940 }; |
| 940 | 941 |
| 941 /** | 942 /** |
| 942 * Keydown event handler on filename edit box | 943 * Keydown event handler on filename edit box |
| 943 * @private | 944 * @private |
| 944 */ | 945 */ |
| 945 Gallery.prototype.onFilenameEditKeydown_ = function() { | 946 Gallery.prototype.onFilenameEditKeydown_ = function() { |
| 946 switch (event.keyCode) { | 947 switch (event.keyCode) { |
| 947 case 27: // Escape | 948 case 27: // Escape |
| 948 this.filenameEdit_.value = this.filenameEdit_.originalValue; | 949 this.filenameEdit_.value = this.filenameEdit_.originalValue; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 * Initialize the window. | 1022 * Initialize the window. |
| 1022 * @param {Object} backgroundComponents Background components. | 1023 * @param {Object} backgroundComponents Background components. |
| 1023 */ | 1024 */ |
| 1024 window.initialize = function(backgroundComponents) { | 1025 window.initialize = function(backgroundComponents) { |
| 1025 window.loadTimeData.data = backgroundComponents.stringData; | 1026 window.loadTimeData.data = backgroundComponents.stringData; |
| 1026 gallery = new Gallery(backgroundComponents.volumeManager); | 1027 gallery = new Gallery(backgroundComponents.volumeManager); |
| 1027 }; | 1028 }; |
| 1028 | 1029 |
| 1029 /** | 1030 /** |
| 1030 * Loads entries. | 1031 * Loads entries. |
| 1032 * @param {!Array.<Entry>} entries Array of entries. |
| 1033 * @param {!Array.<Entry>} selectedEntries Array of selected entries. |
| 1031 */ | 1034 */ |
| 1032 window.loadEntries = function(entries, selectedEntries) { | 1035 window.loadEntries = function(entries, selectedEntries) { |
| 1033 gallery.load(entries, selectedEntries); | 1036 gallery.load(entries, selectedEntries); |
| 1034 }; | 1037 }; |
| OLD | NEW |