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

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

Issue 7583041: Adding a format device button to UI. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: file_manager.js update Created 9 years, 4 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 var g_slideshow_data = null; 10 var g_slideshow_data = null;
(...skipping 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 if (pendingFiles.length) { 1464 if (pendingFiles.length) {
1465 cacheEntrySize(pendingFiles.pop(), cacheNextFile); 1465 cacheEntrySize(pendingFiles.pop(), cacheNextFile);
1466 } else { 1466 } else {
1467 self.dispatchEvent(new cr.Event('selection-summarized')); 1467 self.dispatchEvent(new cr.Event('selection-summarized'));
1468 } 1468 }
1469 }; 1469 };
1470 1470
1471 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { 1471 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) {
1472 // Since unmount task cannot be defined in terms of file patterns, 1472 // Since unmount task cannot be defined in terms of file patterns,
1473 // we manually include it here, if all selected items are mount points. 1473 // we manually include it here, if all selected items are mount points.
1474 this.taskButtons_.innerHTML = '';
1474 chrome.fileBrowserPrivate.getFileTasks( 1475 chrome.fileBrowserPrivate.getFileTasks(
1475 selection.urls, 1476 selection.urls,
1476 this.onTasksFound_.bind(this, 1477 this.onTasksFound_.bind(this,
1477 this.shouldShowUnmount_(selection.urls))); 1478 this.shouldShowUnmount_(selection.urls)));
1478 } 1479 }
1479 1480
1480 cacheNextFile(); 1481 cacheNextFile();
1481 }; 1482 };
1482 1483
1483 FileManager.prototype.onMetadataResult_ = function(fileURL, metadata) { 1484 FileManager.prototype.onMetadataResult_ = function(fileURL, metadata) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 * @param {Array.<Task>} tasksList The tasks list. 1543 * @param {Array.<Task>} tasksList The tasks list.
1543 */ 1544 */
1544 FileManager.prototype.onTasksFound_ = function(unmount, tasksList) { 1545 FileManager.prototype.onTasksFound_ = function(unmount, tasksList) {
1545 if (unmount) { 1546 if (unmount) {
1546 tasksList.push({ 1547 tasksList.push({
1547 taskId: this.getExtensionId_() + '|unmount-archive', 1548 taskId: this.getExtensionId_() + '|unmount-archive',
1548 iconUrl: '', 1549 iconUrl: '',
1549 title: '' 1550 title: ''
1550 }); 1551 });
1551 } 1552 }
1552
1553 this.taskButtons_.innerHTML = '';
1554 for (var i = 0; i < tasksList.length; i++) { 1553 for (var i = 0; i < tasksList.length; i++) {
1555 var task = tasksList[i]; 1554 var task = tasksList[i];
1556 1555
1557 // Tweak images, titles of internal tasks. 1556 // Tweak images, titles of internal tasks.
1558 var task_parts = task.taskId.split('|'); 1557 var task_parts = task.taskId.split('|');
1559 if (task_parts[0] == this.getExtensionId_()) { 1558 if (task_parts[0] == this.getExtensionId_()) {
1560 if (task_parts[1] == 'preview') { 1559 if (task_parts[1] == 'preview') {
1561 // TODO(serya): This hack needed until task.iconUrl get working 1560 // TODO(serya): This hack needed until task.iconUrl get working
1562 // (see GetFileTasksFileBrowserFunction::RunImpl). 1561 // (see GetFileTasksFileBrowserFunction::RunImpl).
1563 task.iconUrl = 1562 task.iconUrl =
(...skipping 15 matching lines...) Expand all
1579 } else if (task_parts[1] == 'mount-archive') { 1578 } else if (task_parts[1] == 'mount-archive') {
1580 task.iconUrl = 1579 task.iconUrl =
1581 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); 1580 chrome.extension.getURL('images/icon_mount_archive_16x16.png');
1582 task.title = str('MOUNT_ARCHIVE'); 1581 task.title = str('MOUNT_ARCHIVE');
1583 } else if (task_parts[1] == 'unmount-archive') { 1582 } else if (task_parts[1] == 'unmount-archive') {
1584 task.iconUrl = 1583 task.iconUrl =
1585 chrome.extension.getURL('images/icon_unmount_archive_16x16.png'); 1584 chrome.extension.getURL('images/icon_unmount_archive_16x16.png');
1586 task.title = str('UNMOUNT_ARCHIVE'); 1585 task.title = str('UNMOUNT_ARCHIVE');
1587 } 1586 }
1588 } 1587 }
1588 this.renderTaskButton_(task);
1589 }
1590 // This needs to be done in sparate function, as check requires
1591 // asynchronous function calls.
1592 this.maybeRenderFormattingTask_();
1593 };
1589 1594
1590 var button = this.document_.createElement('button'); 1595 FileManager.prototype.renderTaskButton_ = function(task) {
1591 button.addEventListener('click', this.onTaskButtonClicked_.bind(this)); 1596 var button = this.document_.createElement('button');
1592 button.className = 'task-button'; 1597 button.addEventListener('click', this.onTaskButtonClicked_.bind(this));
1593 button.task = task; 1598 button.className = 'task-button';
1599 button.task = task;
1594 1600
1595 var img = this.document_.createElement('img'); 1601 var img = this.document_.createElement('img');
1596 img.src = task.iconUrl; 1602 img.src = task.iconUrl;
1597 1603
1598 button.appendChild(img); 1604 button.appendChild(img);
1599 button.appendChild(this.document_.createTextNode(task.title)); 1605 button.appendChild(this.document_.createTextNode(task.title));
1600 1606
1601 this.taskButtons_.appendChild(button); 1607 this.taskButtons_.appendChild(button);
1608 };
1609
1610 /**
1611 * Checks whether formatting task should be displayed and if the answer is
1612 * affirmative renders it. Includes asynchronous calls, so it's splitted into
1613 * three parts.
1614 */
1615 FileManager.prototype.maybeRenderFormattingTask_ = function() {
1616 // Not to make unnecesary getMountPoints() call we doublecheck if there is
1617 // only one selected entry.
1618 if(this.selection.entries.length != 1)
1619 return;
1620
1621 function onMountPointsFound(mountPoints) {
1622 this.mountPoints_ = mountPoints;
1623
1624 function normalize(x) {
1625 if(x[0] == '/')
1626 return x.slice(1);
1627 else
1628 return x;
1629 }
1630
1631 function onVolumeMetadataFound(volumeMetadata) {
tbarzic 2011/08/11 00:58:18 what if selection has changed by now?
sidor 2011/08/11 04:28:51 Hmm... Then we are screwed. But hey, to change the
tbarzic 2011/08/11 04:49:48 maybe you could do something like if (this.selecti
sidor.dev 2011/08/11 18:39:43 Done.
1632 if (volumeMetadata.deviceType == "flash") {
1633 var task = {
1634 taskId: this.getExtensionId_() + '|format-device',
1635 iconUrl: chrome.extension.getURL('images/filetype_generic.png'),
1636 title: str('FORMAT_DEVICE')
1637 };
1638 this.renderTaskButton_(task);
1639 }
1640 }
1641
1642 if(this.selection.entries.length != 1)
1643 return;
1644 var maybeMountPath = this.selection.entries[0].fullPath;
tbarzic 2011/08/11 00:58:18 why maybe here?
sidor 2011/08/11 04:28:51 Because it might be a regular directory path.
tbarzic 2011/08/11 04:49:48 maybe entryPath or selectedPath would be better na
sidor.dev 2011/08/11 18:39:43 Done.
1645 for (var i = 0; i < mountPoints.length; i++) {
1646 if (mountPoints[i].mountType == "device" &&
1647 normalize(mountPoints[i].mountPath) == normalize(maybeMountPath)) {
1648 chrome.fileBrowserPrivate.getVolumeMetadata(mountPoints[i].sourceUrl,
1649 onVolumeMetadataFound.bind(this));
1650 return;
1651 }
1652 }
1602 } 1653 }
1654
1655 chrome.fileBrowserPrivate.getMountPoints(onMountPointsFound.bind(this));
1603 }; 1656 };
1604 1657
1605 FileManager.prototype.getExtensionId_ = function() { 1658 FileManager.prototype.getExtensionId_ = function() {
1606 return chrome.extension.getURL('').split('/')[2]; 1659 return chrome.extension.getURL('').split('/')[2];
1607 }; 1660 };
1608 1661
1609 FileManager.prototype.onTaskButtonClicked_ = function(event) { 1662 FileManager.prototype.onTaskButtonClicked_ = function(event) {
1610 chrome.fileBrowserPrivate.executeTask(event.srcElement.task.taskId, 1663 chrome.fileBrowserPrivate.executeTask(event.srcElement.task.taskId,
1611 this.selection.urls); 1664 this.selection.urls);
1612 }; 1665 };
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 chrome.fileBrowserPrivate.viewFiles(urls, id); 1712 chrome.fileBrowserPrivate.viewFiles(urls, id);
1660 } else if (id == 'mount-archive') { 1713 } else if (id == 'mount-archive') {
1661 for (var index = 0; index < urls.length; ++index) { 1714 for (var index = 0; index < urls.length; ++index) {
1662 this.mountRequests_.push(urls[index]); 1715 this.mountRequests_.push(urls[index]);
1663 chrome.fileBrowserPrivate.addMount(urls[index], 'file', {}); 1716 chrome.fileBrowserPrivate.addMount(urls[index], 'file', {});
1664 } 1717 }
1665 } else if (id == 'unmount-archive') { 1718 } else if (id == 'unmount-archive') {
1666 for (var index = 0; index < urls.length; ++index) { 1719 for (var index = 0; index < urls.length; ++index) {
1667 chrome.fileBrowserPrivate.removeMount(urls[index]); 1720 chrome.fileBrowserPrivate.removeMount(urls[index]);
1668 } 1721 }
1722 } else if (id == 'format-device') {
1723 if (!confirm(str('FORMATTING_WARNING')))
1724 return;
1725 chrome.fileBrowserPrivate.formatDevice(urls[0]);
1669 } 1726 }
1670 }; 1727 };
1671 1728
1672 /** 1729 /**
1673 * Determines whether unmount task should present for selected files. 1730 * Determines whether unmount task should present for selected files.
1674 */ 1731 */
1675 FileManager.prototype.shouldShowUnmount_ = function(urls) { 1732 FileManager.prototype.shouldShowUnmount_ = function(urls) {
1676 for (var index = 0; index < urls.length; ++index) { 1733 for (var index = 0; index < urls.length; ++index) {
1677 // Each url should be a mount point. 1734 // Each url should be a mount point.
1678 var path = urls[index]; 1735 var path = urls[index];
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after
3006 3063
3007 if (msg) { 3064 if (msg) {
3008 console.log('no no no'); 3065 console.log('no no no');
3009 this.alert.show(msg, onAccept); 3066 this.alert.show(msg, onAccept);
3010 return false; 3067 return false;
3011 } 3068 }
3012 3069
3013 return true; 3070 return true;
3014 }; 3071 };
3015 })(); 3072 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698