Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: chrome/browser/resources/file_manager/js/file_manager.js

Issue 9565002: Fixing paste operation in File Browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/file_manager/css/file_manager.css ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Setting the src of an img to an empty string can crash the browser, so we 5 // Setting the src of an img to an empty string can crash the browser, so we
6 // use an empty 1x1 gif instead. 6 // use an empty 1x1 gif instead.
7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,'
8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D';
9 9
10 /** 10 /**
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 /** 123 /**
124 * Return a translated string. 124 * Return a translated string.
125 * 125 *
126 * Wrapper function to make dealing with translated strings more concise. 126 * Wrapper function to make dealing with translated strings more concise.
127 * Equivilant to localStrings.getString(id). 127 * Equivilant to localStrings.getString(id).
128 * 128 *
129 * @param {string} id The id of the string to return. 129 * @param {string} id The id of the string to return.
130 * @return {string} The translated string. 130 * @return {string} The translated string.
131 */ 131 */
132 function str(id) { 132 function str(id) {
133 return localStrings.getString(id); 133 return localStrings.getString(id) || ('UNLOCALIZED STRING ' + id);
134 } 134 }
135 135
136 /** 136 /**
137 * Return a translated string with arguments replaced. 137 * Return a translated string with arguments replaced.
138 * 138 *
139 * Wrapper function to make dealing with translated strings more concise. 139 * Wrapper function to make dealing with translated strings more concise.
140 * Equivilant to localStrings.getStringF(id, ...). 140 * Equivilant to localStrings.getStringF(id, ...).
141 * 141 *
142 * @param {string} id The id of the string to return. 142 * @param {string} id The id of the string to return.
143 * @param {...string} The values to replace into the string. 143 * @param {...string} The values to replace into the string.
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 } 937 }
938 this.dialogDom_.appendChild(butter); 938 this.dialogDom_.appendChild(butter);
939 939
940 var self = this; 940 var self = this;
941 941
942 setTimeout(function () { 942 setTimeout(function () {
943 if (self.currentButter_) 943 if (self.currentButter_)
944 self.hideButter(); 944 self.hideButter();
945 945
946 self.currentButter_ = butter; 946 self.currentButter_ = butter;
947 self.currentButter_.classList.remove('before-show');
948 947
949 self.updateButter(message, opt_options); 948 self.updateButter(message, opt_options);
950 }); 949 });
951 950
952 return butter; 951 return butter;
953 }; 952 };
954 953
955 FileManager.prototype.showButterError = function(message, opt_options) { 954 FileManager.prototype.showButterError = function(message, opt_options) {
956 var butter = this.showButter(message, opt_options); 955 var butter = this.showButter(message, opt_options);
957 butter.classList.add('error'); 956 butter.classList.add('error');
(...skipping 11 matching lines...) Expand all
969 timeout = 10 * 1000; 968 timeout = 10 * 1000;
970 } 969 }
971 970
972 if (this.butterTimer_) 971 if (this.butterTimer_)
973 clearTimeout(this.butterTimer_); 972 clearTimeout(this.butterTimer_);
974 973
975 if (timeout) { 974 if (timeout) {
976 var self = this; 975 var self = this;
977 this.butterTimer_ = setTimeout(function() { 976 this.butterTimer_ = setTimeout(function() {
978 self.hideButter(); 977 self.hideButter();
979 self.butterTimer_ == null; 978 self.butterTimer_ = null;
980 }, timeout); 979 }, timeout);
981 } 980 }
982 981
983 var butter = this.currentButter_; 982 var butter = this.currentButter_;
984 butter.querySelector('.butter-message').textContent = message; 983 butter.querySelector('.butter-message').textContent = message;
985 984 if (message) {
985 // The butter bar is made visible on the first non-empty message.
986 butter.classList.remove('before-show');
987 }
986 if (opt_options && 'progress' in opt_options) { 988 if (opt_options && 'progress' in opt_options) {
987 butter.querySelector('.progress-track').style.width = 989 butter.querySelector('.progress-track').style.width =
988 (opt_options.progress*100) + '%'; 990 (opt_options.progress*100) + '%';
989 } 991 }
990 992
991 butter.style.left = ((this.dialogDom_.clientWidth - 993 butter.style.left = ((this.dialogDom_.clientWidth -
992 butter.clientWidth) / 2) + 'px'; 994 butter.clientWidth) / 2) + 'px';
993 }; 995 };
994 996
995 FileManager.prototype.hideButter = function() { 997 FileManager.prototype.hideButter = function() {
996 if (this.currentButter_) { 998 if (this.currentButter_) {
997 this.currentButter_.style.top = '50px'; 999 this.currentButter_.classList.add('after-show');
998 this.currentButter_.style.opacity = '0';
999 1000
1000 var butter = this.currentButter_; 1001 var butter = this.currentButter_;
1001 setTimeout(function() { 1002 setTimeout(function() {
1002 butter.parentNode.removeChild(butter); 1003 butter.parentNode.removeChild(butter);
1003 }, 1000); 1004 }, 1000);
1004 1005
1005 this.currentButter_ = null; 1006 this.currentButter_ = null;
1006 } 1007 }
1007 }; 1008 };
1008 1009
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 * 1056 *
1056 * @return {boolean} True if "paste" command can be executed for current 1057 * @return {boolean} True if "paste" command can be executed for current
1057 * directory. 1058 * directory.
1058 */ 1059 */
1059 1060
1060 var canPaste = false; 1061 var canPaste = false;
1061 var clipboardCanPaste = function(event) { 1062 var clipboardCanPaste = function(event) {
1062 event.preventDefault(); 1063 event.preventDefault();
1063 // Here we need to use lower case as clipboardData.types return lower 1064 // Here we need to use lower case as clipboardData.types return lower
1064 // case DomStringList. 1065 // case DomStringList.
1065 if (event.clipboardData.types.contains('fs/iscut')) 1066 if (event.clipboardData &&
1067 event.clipboardData.types &&
1068 event.clipboardData.types.indexOf('fs/iscut') != -1)
1066 canPaste = true; 1069 canPaste = true;
1067 }; 1070 };
1068 1071
1069 this.document_.removeEventListener('paste', this.pasteFromClipboardBind_); 1072 this.document_.removeEventListener('paste', this.pasteFromClipboardBind_);
1070 this.document_.addEventListener('paste', clipboardCanPaste); 1073 this.document_.addEventListener('paste', clipboardCanPaste);
1071 this.document_.execCommand('paste'); 1074 this.document_.execCommand('paste');
1072 this.document_.removeEventListener('paste', clipboardCanPaste); 1075 this.document_.removeEventListener('paste', clipboardCanPaste);
1073 this.document_.addEventListener('paste', this.pasteFromClipboardBind_); 1076 this.document_.addEventListener('paste', this.pasteFromClipboardBind_);
1074 return canPaste && !readonly; 1077 return canPaste && !readonly;
1075 }; 1078 };
(...skipping 1781 matching lines...) Expand 10 before | Expand all | Expand 10 after
2857 this.updateCommands_(); 2860 this.updateCommands_();
2858 this.blinkSelection(); 2861 this.blinkSelection();
2859 }; 2862 };
2860 2863
2861 /** 2864 /**
2862 * Queue up a file copy operation based on the current system clipboard. 2865 * Queue up a file copy operation based on the current system clipboard.
2863 */ 2866 */
2864 FileManager.prototype.pasteFromClipboard_ = function(event) { 2867 FileManager.prototype.pasteFromClipboard_ = function(event) {
2865 event.preventDefault(); 2868 event.preventDefault();
2866 2869
2867 if (!event.clipboardData.getData('fs/isCut')) 2870 if (!event.clipboardData.getData('fs/isCut'))
dgozman 2012/03/01 08:28:40 Do we need similar checks here?
Vladislav Kaznacheev 2012/03/01 08:33:02 For some reason this is not happening. On 2012/03/
2868 return; 2871 return;
2869 2872
2870 this.showButter(str('PASTE_STARTED'), {timeout: 0}); 2873 // Pass an empty string so that the butter bar remains invisible until
2874 // the first progress update. This prevents the flicker on short operations.
2875 this.showButter('', {timeout: 0});
2871 2876
2872 var clipboard = { 2877 var clipboard = {
2873 isCut: event.clipboardData.getData('fs/isCut'), 2878 isCut: event.clipboardData.getData('fs/isCut'),
2874 sourceDir: event.clipboardData.getData('fs/sourcedir'), 2879 sourceDir: event.clipboardData.getData('fs/sourcedir'),
2875 directories: event.clipboardData.getData('fs/directories'), 2880 directories: event.clipboardData.getData('fs/directories'),
2876 files: event.clipboardData.getData('fs/files') 2881 files: event.clipboardData.getData('fs/files')
2877 }; 2882 };
2878 2883
2879 this.copyManager_.paste(clipboard, 2884 this.copyManager_.paste(clipboard,
2880 this.directoryModel_.currentEntry, 2885 this.directoryModel_.currentEntry,
(...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after
3932 }); 3937 });
3933 }, onError); 3938 }, onError);
3934 3939
3935 function onError(err) { 3940 function onError(err) {
3936 console.log('Error while checking free space: ' + err); 3941 console.log('Error while checking free space: ' + err);
3937 setTimeout(doCheck, 1000 * 60); 3942 setTimeout(doCheck, 1000 * 60);
3938 } 3943 }
3939 } 3944 }
3940 } 3945 }
3941 })(); 3946 })();
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/css/file_manager.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698