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 * Sets 'hidden' property of a cr.ui.Command instance and dispatches | 6 * Sets 'hidden' property of a cr.ui.Command instance and dispatches |
7 * 'hiddenChange' event manually so that associated cr.ui.MenuItem can handle | 7 * 'hiddenChange' event manually so that associated cr.ui.MenuItem can handle |
8 * the event. | 8 * the event. |
9 * TODO(fukino): Remove this workaround when crbug.com/481941 is fixed. | 9 * TODO(fukino): Remove this workaround when crbug.com/481941 is fixed. |
10 * | 10 * |
(...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1481 }, | 1481 }, |
1482 canExecute: function(event, fileManager) { | 1482 canExecute: function(event, fileManager) { |
1483 var currentDirEntry = fileManager.directoryModel.getCurrentDirEntry(); | 1483 var currentDirEntry = fileManager.directoryModel.getCurrentDirEntry(); |
1484 var volumeInfo = currentDirEntry && | 1484 var volumeInfo = currentDirEntry && |
1485 fileManager.volumeManager.getVolumeInfo(currentDirEntry); | 1485 fileManager.volumeManager.getVolumeInfo(currentDirEntry); |
1486 event.canExecute = volumeInfo && !volumeInfo.watchable; | 1486 event.canExecute = volumeInfo && !volumeInfo.watchable; |
1487 event.command.setHidden(!event.canExecute || | 1487 event.command.setHidden(!event.canExecute || |
1488 fileManager.directoryModel.getFileListSelection().getCheckSelectMode()); | 1488 fileManager.directoryModel.getFileListSelection().getCheckSelectMode()); |
1489 } | 1489 } |
1490 }); | 1490 }); |
1491 | |
1492 /** | |
1493 * Refreshes the currently selected directory. | |
1494 */ | |
1495 CommandHandler.COMMANDS_['set-wallpaper'] = /** @type {Command} */ ({ | |
1496 /** | |
1497 * @param {!Event} event Command event. | |
1498 * @param {!FileManager} fileManager FileManager to use. | |
1499 */ | |
1500 execute: function(event, fileManager) { | |
1501 var entry = fileManager.getSelection().entries[0]; | |
1502 new Promise(function(resolve, reject) { | |
1503 entry.file(resolve, reject); | |
1504 }).then(function(blob) { | |
1505 var fileReader = new FileReader(); | |
1506 return new Promise(function(resolve, reject) { | |
1507 fileReader.onload = function() { | |
1508 resolve(this.result); | |
1509 }; | |
1510 fileReader.onError = function(err) { | |
mtomasz
2016/02/12 04:30:51
nit: should it be onerror?
ryoh
2016/02/12 07:37:25
Done.
| |
1511 reject(err); | |
1512 }; | |
1513 fileReader.readAsArrayBuffer(blob); | |
1514 }) | |
1515 }).then(function(arrayBuffer) { | |
1516 chrome.wallpaper.setWallpaper( | |
1517 { | |
1518 'data': arrayBuffer, | |
mtomasz
2016/02/12 04:30:51
nit: no need for '' for keys.
{
data: ...,
la
ryoh
2016/02/12 07:37:25
Done.
| |
1519 'layout': 'CENTER_CROPPED', | |
1520 'filename': 'wallpaper' | |
1521 }, function() {}); | |
1522 }).catch(function() { | |
1523 fileManager.ui.alertDialog.showHtml( | |
1524 '', str('ERROR_INVALID_WALLPAPER'), null, null, null); | |
1525 }); | |
1526 }, | |
1527 canExecute: function(event, fileManager) { | |
1528 var entries = CommandUtil.getCommandEntries(event.target); | |
1529 if (entries.length === 0 ) { | |
1530 event.canExecute = false; | |
1531 event.command.setHidden(true); | |
1532 return; | |
1533 } | |
1534 var type = FileType.getType(entries[0]); | |
1535 if (entries.length !== 1 || type.type !== 'image') { | |
1536 event.canExecute = false; | |
1537 event.command.setHidden(true); | |
1538 return; | |
1539 } | |
1540 | |
1541 event.canExecute = type.subtype === 'JPEG' || type.subtype === 'PNG'; | |
1542 event.command.setHidden(false); | |
1543 } | |
1544 }); | |
OLD | NEW |