OLD | NEW |
---|---|
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 /** | 5 /** |
6 * FileManager constructor. | 6 * FileManager constructor. |
7 * | 7 * |
8 * FileManager objects encapsulate the functionality of the file selector | 8 * FileManager objects encapsulate the functionality of the file selector |
9 * dialogs, as well as the full screen file manager application (though the | 9 * dialogs, as well as the full screen file manager application (though the |
10 * latter is not yet implemented). | 10 * latter is not yet implemented). |
(...skipping 29 matching lines...) Expand all Loading... | |
40 this.dialogType_ = this.params_.type || FileManager.DialogType.FULL_PAGE; | 40 this.dialogType_ = this.params_.type || FileManager.DialogType.FULL_PAGE; |
41 | 41 |
42 metrics.recordEnum('Create', this.dialogType_, | 42 metrics.recordEnum('Create', this.dialogType_, |
43 [FileManager.DialogType.SELECT_FOLDER, | 43 [FileManager.DialogType.SELECT_FOLDER, |
44 FileManager.DialogType.SELECT_SAVEAS_FILE, | 44 FileManager.DialogType.SELECT_SAVEAS_FILE, |
45 FileManager.DialogType.SELECT_OPEN_FILE, | 45 FileManager.DialogType.SELECT_OPEN_FILE, |
46 FileManager.DialogType.SELECT_OPEN_MULTI_FILE, | 46 FileManager.DialogType.SELECT_OPEN_MULTI_FILE, |
47 FileManager.DialogType.FULL_PAGE]); | 47 FileManager.DialogType.FULL_PAGE]); |
48 | 48 |
49 // TODO(dgozman): This will be changed to LocaleInfo. | 49 // TODO(dgozman): This will be changed to LocaleInfo. |
50 this.locale_ = new v8Locale(navigator.language); | 50 this.locale_ = new v8Locale(navigator.language); |
dgozman
2012/05/21 15:45:41
Should this be changed as well?
Oleg Eterevsky
2012/05/21 15:53:55
I'd rather do it once v8Intl is in the stable vers
| |
51 | 51 |
52 this.initFileSystem_(); | 52 this.initFileSystem_(); |
53 this.initDom_(); | 53 this.initDom_(); |
54 this.initDialogType_(); | 54 this.initDialogType_(); |
55 this.dialogDom_.style.opacity = '1'; | 55 this.dialogDom_.style.opacity = '1'; |
56 } | 56 } |
57 | 57 |
58 /** | 58 /** |
59 * Maximum delay in milliseconds for updating thumbnails in the bottom panel | 59 * Maximum delay in milliseconds for updating thumbnails in the bottom panel |
60 * to mitigate flickering. If images load faster then the delay they replace | 60 * to mitigate flickering. If images load faster then the delay they replace |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 var IMAGE_HOVER_PREVIEW_SIZE = 200; | 114 var IMAGE_HOVER_PREVIEW_SIZE = 200; |
115 | 115 |
116 /** | 116 /** |
117 * The minimum about of time to display the butter bar for, in ms. | 117 * The minimum about of time to display the butter bar for, in ms. |
118 * Justification is 1000ms for minimum display time plus 300ms for transition | 118 * Justification is 1000ms for minimum display time plus 300ms for transition |
119 * duration. | 119 * duration. |
120 */ | 120 */ |
121 var MINIMUM_BUTTER_DISPLAY_TIME_MS = 1300; | 121 var MINIMUM_BUTTER_DISPLAY_TIME_MS = 1300; |
122 | 122 |
123 /** | 123 /** |
124 * Number of milliseconds in a day. | |
125 */ | |
126 var MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000; | |
127 | |
128 /** | |
124 * Item for the Grid View. | 129 * Item for the Grid View. |
125 * @constructor | 130 * @constructor |
126 */ | 131 */ |
127 function GridItem(fileManager, entry) { | 132 function GridItem(fileManager, entry) { |
128 var li = fileManager.document_.createElement('li'); | 133 var li = fileManager.document_.createElement('li'); |
129 GridItem.decorate(li, fileManager, entry); | 134 GridItem.decorate(li, fileManager, entry); |
130 return li; | 135 return li; |
131 } | 136 } |
132 | 137 |
133 GridItem.prototype = { | 138 GridItem.prototype = { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 | 326 |
322 /** | 327 /** |
323 * Continue initializing the file manager after resolving roots. | 328 * Continue initializing the file manager after resolving roots. |
324 */ | 329 */ |
325 FileManager.prototype.init_ = function() { | 330 FileManager.prototype.init_ = function() { |
326 metrics.startInterval('Load.DOM'); | 331 metrics.startInterval('Load.DOM'); |
327 this.initCommands_(); | 332 this.initCommands_(); |
328 | 333 |
329 this.metadataCache_ = MetadataCache.createFull(); | 334 this.metadataCache_ = MetadataCache.createFull(); |
330 | 335 |
331 this.shortDateFormatter_ = | 336 this.dateFormatter_ = v8Intl.DateTimeFormat( |
332 this.locale_.createDateTimeFormat({'dateType': 'medium'}); | 337 undefined, |
dgozman
2012/05/21 15:45:41
Comment what undefined means.
Oleg Eterevsky
2012/05/21 15:53:55
Done.
| |
338 {year: 'numeric', month: 'short', day: 'numeric', | |
339 hour: 'numeric', minute: 'numeric'}); | |
340 this.timeFormatter_ = v8Intl.DateTimeFormat( | |
341 undefined, {hour: 'numeric', minute: 'numeric'}); | |
333 | 342 |
334 this.collator_ = this.locale_.createCollator({ | 343 this.collator_ = this.locale_.createCollator({ |
335 'numeric': true, 'ignoreCase': true, 'ignoreAccents': true}); | 344 'numeric': true, 'ignoreCase': true, 'ignoreAccents': true}); |
336 | 345 |
337 // Optional list of file types. | 346 // Optional list of file types. |
338 this.fileTypes_ = this.params_.typeList; | 347 this.fileTypes_ = this.params_.typeList; |
339 | 348 |
340 this.showCheckboxes_ = | 349 this.showCheckboxes_ = |
341 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || | 350 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || |
342 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); | 351 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
664 this.initGrid_(); | 673 this.initGrid_(); |
665 this.initRootsList_(); | 674 this.initRootsList_(); |
666 | 675 |
667 var listType = FileManager.ListType.DETAIL; | 676 var listType = FileManager.ListType.DETAIL; |
668 if (FileManager.DialogType.isModal(this.dialogType_)) | 677 if (FileManager.DialogType.isModal(this.dialogType_)) |
669 listType = window.localStorage['listType-' + this.dialogType_] || | 678 listType = window.localStorage['listType-' + this.dialogType_] || |
670 FileManager.ListType.DETAIL; | 679 FileManager.ListType.DETAIL; |
671 this.setListType(listType); | 680 this.setListType(listType); |
672 | 681 |
673 this.textSearchState_ = {text: '', date: new Date()}; | 682 this.textSearchState_ = {text: '', date: new Date()}; |
683 | |
684 // Update metadata once per minute to change 'Today' and 'Yesterday' | |
dgozman
2012/05/21 15:45:41
Wrong comment?
Oleg Eterevsky
2012/05/21 15:53:55
Done.
| |
685 // modification time on | |
686 var today = new Date(); | |
687 today.setHours(0); | |
688 today.setMinutes(0); | |
689 today.setSeconds(0); | |
690 today.setMilliseconds(0); | |
691 setTimeout(this.dailyUpdateModificationTime_.bind(this), | |
692 today.getTime() + MILLISECONDS_IN_DAY - Date.now() + 1000); | |
674 }; | 693 }; |
675 | 694 |
676 FileManager.prototype.initRootsList_ = function() { | 695 FileManager.prototype.initRootsList_ = function() { |
677 this.rootsList_ = this.dialogDom_.querySelector('#roots-list'); | 696 this.rootsList_ = this.dialogDom_.querySelector('#roots-list'); |
678 cr.ui.List.decorate(this.rootsList_); | 697 cr.ui.List.decorate(this.rootsList_); |
679 this.rootsList_.startBatchUpdates(); | 698 this.rootsList_.startBatchUpdates(); |
680 | 699 |
681 var self = this; | 700 var self = this; |
682 this.rootsList_.itemConstructor = function(entry) { | 701 this.rootsList_.itemConstructor = function(entry) { |
683 return self.renderRoot_(entry); | 702 return self.renderRoot_(entry); |
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1955 div.className = 'date'; | 1974 div.className = 'date'; |
1956 | 1975 |
1957 this.updateDate_(div, | 1976 this.updateDate_(div, |
1958 this.metadataCache_.getCached(entry, 'filesystem')); | 1977 this.metadataCache_.getCached(entry, 'filesystem')); |
1959 return div; | 1978 return div; |
1960 }; | 1979 }; |
1961 | 1980 |
1962 FileManager.prototype.updateDate_ = function(div, filesystemProps) { | 1981 FileManager.prototype.updateDate_ = function(div, filesystemProps) { |
1963 if (!filesystemProps) { | 1982 if (!filesystemProps) { |
1964 div.textContent = '...'; | 1983 div.textContent = '...'; |
1984 return; | |
1985 } | |
1986 | |
1987 var modTime = filesystemProps.modificationTime; | |
1988 var today = new Date(); | |
1989 today.setHours(0); | |
1990 today.setMinutes(0); | |
1991 today.setSeconds(0); | |
1992 today.setMilliseconds(0); | |
1993 | |
1994 if (modTime >= today && | |
1995 modTime < today.getTime() + MILLISECONDS_IN_DAY) { | |
1996 div.textContent = strf('TIME_TODAY', this.timeFormatter_.format(modTime)); | |
1997 } else if (modTime >= today - MILLISECONDS_IN_DAY && modTime < today) { | |
1998 div.textContent = strf('TIME_YESTERDAY', | |
1999 this.timeFormatter_.format(modTime)); | |
1965 } else { | 2000 } else { |
1966 div.textContent = | 2001 div.textContent = |
1967 this.shortDateFormatter_.format(filesystemProps.modificationTime); | 2002 this.dateFormatter_.format(filesystemProps.modificationTime); |
1968 } | 2003 } |
1969 }; | 2004 }; |
1970 | 2005 |
1971 FileManager.prototype.renderOffline_ = function(entry, columnId, table) { | 2006 FileManager.prototype.renderOffline_ = function(entry, columnId, table) { |
1972 var doc = this.document_; | 2007 var doc = this.document_; |
1973 var div = doc.createElement('div'); | 2008 var div = doc.createElement('div'); |
1974 div.className = 'offline'; | 2009 div.className = 'offline'; |
1975 | 2010 |
1976 if (entry.isDirectory) | 2011 if (entry.isDirectory) |
1977 return div; | 2012 return div; |
(...skipping 27 matching lines...) Expand all Loading... | |
2005 // observer registered to update the UI. | 2040 // observer registered to update the UI. |
2006 | 2041 |
2007 this.metadataCache_.clear(entries, 'filesystem'); | 2042 this.metadataCache_.clear(entries, 'filesystem'); |
2008 this.metadataCache_.get(entries, 'filesystem', null); | 2043 this.metadataCache_.get(entries, 'filesystem', null); |
2009 if (this.isOnGData()) { | 2044 if (this.isOnGData()) { |
2010 this.metadataCache_.clear(entries, 'gdata'); | 2045 this.metadataCache_.clear(entries, 'gdata'); |
2011 this.metadataCache_.get(entries, 'gdata', null); | 2046 this.metadataCache_.get(entries, 'gdata', null); |
2012 } | 2047 } |
2013 }; | 2048 }; |
2014 | 2049 |
2050 FileManager.prototype.dailyUpdateModificationTime_ = function() { | |
2051 var fileList = this.directoryModel_.getFileList(); | |
2052 var urls = []; | |
2053 for (var i = 0; i < fileList.length; i++) { | |
2054 urls.push(fileList.item(i).toURL()); | |
2055 } | |
2056 this.metadataCache_.get( | |
2057 urls, 'filesystem', | |
dgozman
2012/05/21 15:45:41
Passing entries instead of urls will greatly speed
Oleg Eterevsky
2012/05/21 15:53:55
Done.
| |
2058 this.updateMetadataInUI_.bind(this, 'filesystem', urls)); | |
2059 | |
2060 setTimeout(this.dailyUpdateModificationTime_.bind(this), | |
2061 MILLISECONDS_IN_DAY); | |
2062 }; | |
2063 | |
2015 FileManager.prototype.updateMetadataInUI_ = function( | 2064 FileManager.prototype.updateMetadataInUI_ = function( |
2016 type, urls, properties) { | 2065 type, urls, properties) { |
2017 if (this.listType_ != FileManager.ListType.DETAIL) return; | 2066 if (this.listType_ != FileManager.ListType.DETAIL) return; |
2018 | 2067 |
2019 var items = {}; | 2068 var items = {}; |
2020 var entries = {}; | 2069 var entries = {}; |
2021 var dm = this.directoryModel_.getFileList(); | 2070 var dm = this.directoryModel_.getFileList(); |
2022 for (var index = 0; index < dm.length; index++) { | 2071 for (var index = 0; index < dm.length; index++) { |
2023 var listItem = this.currentList_.getListItemByIndex(index); | 2072 var listItem = this.currentList_.getListItemByIndex(index); |
2024 if (!listItem) continue; | 2073 if (!listItem) continue; |
(...skipping 2630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4655 | 4704 |
4656 function closeBanner() { | 4705 function closeBanner() { |
4657 self.cleanupGDataWelcome_(); | 4706 self.cleanupGDataWelcome_(); |
4658 // Stop showing the welcome banner. | 4707 // Stop showing the welcome banner. |
4659 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; | 4708 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; |
4660 } | 4709 } |
4661 | 4710 |
4662 return maybeShowBanner; | 4711 return maybeShowBanner; |
4663 }; | 4712 }; |
4664 })(); | 4713 })(); |
OLD | NEW |