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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 /** | 522 /** |
523 * One-time initialization of dialogs. | 523 * One-time initialization of dialogs. |
524 */ | 524 */ |
525 FileManager.prototype.initDialogs_ = function() { | 525 FileManager.prototype.initDialogs_ = function() { |
526 var d = cr.ui.dialogs; | 526 var d = cr.ui.dialogs; |
527 d.BaseDialog.OK_LABEL = str('OK_LABEL'); | 527 d.BaseDialog.OK_LABEL = str('OK_LABEL'); |
528 d.BaseDialog.CANCEL_LABEL = str('CANCEL_LABEL'); | 528 d.BaseDialog.CANCEL_LABEL = str('CANCEL_LABEL'); |
529 this.alert = new d.AlertDialog(this.dialogDom_); | 529 this.alert = new d.AlertDialog(this.dialogDom_); |
530 this.confirm = new d.ConfirmDialog(this.dialogDom_); | 530 this.confirm = new d.ConfirmDialog(this.dialogDom_); |
531 this.prompt = new d.PromptDialog(this.dialogDom_); | 531 this.prompt = new d.PromptDialog(this.dialogDom_); |
| 532 this.defaultTaskPicker = |
| 533 new cr.filebrowser.DefaultActionDialog(this.dialogDom_); |
532 }; | 534 }; |
533 | 535 |
534 /** | 536 /** |
535 * One-time initialization of various DOM nodes. | 537 * One-time initialization of various DOM nodes. |
536 */ | 538 */ |
537 FileManager.prototype.initDom_ = function() { | 539 FileManager.prototype.initDom_ = function() { |
538 // Cache nodes we'll be manipulating. | 540 // Cache nodes we'll be manipulating. |
539 this.previewThumbnails_ = | 541 this.previewThumbnails_ = |
540 this.dialogDom_.querySelector('.preview-thumbnails'); | 542 this.dialogDom_.querySelector('.preview-thumbnails'); |
541 this.previewPanel_ = this.dialogDom_.querySelector('.preview-panel'); | 543 this.previewPanel_ = this.dialogDom_.querySelector('.preview-panel'); |
(...skipping 1950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2492 return path && | 2494 return path && |
2493 this.isGDataEnabled() && | 2495 this.isGDataEnabled() && |
2494 DirectoryModel.getRootType(path) == DirectoryModel.RootType.GDATA; | 2496 DirectoryModel.getRootType(path) == DirectoryModel.RootType.GDATA; |
2495 }; | 2497 }; |
2496 | 2498 |
2497 FileManager.prototype.getMetadataProvider = function() { | 2499 FileManager.prototype.getMetadataProvider = function() { |
2498 return this.metadataProvider_; | 2500 return this.metadataProvider_; |
2499 }; | 2501 }; |
2500 | 2502 |
2501 /** | 2503 /** |
| 2504 * Creates combobox item based on task. |
| 2505 * @param {Object} task Task to convert. |
| 2506 * @return {Object} Item appendable to combobox drop-down list. |
| 2507 */ |
| 2508 FileManager.prototype.createComboboxItem_ = function(task) { |
| 2509 return { label: task.title, iconUrl: task.iconUrl, task: task }; |
| 2510 } |
| 2511 |
| 2512 /** |
2502 * Callback called when tasks for selected files are determined. | 2513 * Callback called when tasks for selected files are determined. |
2503 * @param {Object} selection Selection is passed here, since this.selection | 2514 * @param {Object} selection Selection is passed here, since this.selection |
2504 * can change before tasks were found, and we should be accurate. | 2515 * can change before tasks were found, and we should be accurate. |
2505 * @param {Array.<Task>} tasksList The tasks list. | 2516 * @param {Array.<Task>} tasksList The tasks list. |
2506 */ | 2517 */ |
2507 FileManager.prototype.onTasksFound_ = function(selection, tasksList) { | 2518 FileManager.prototype.onTasksFound_ = function(selection, tasksList) { |
2508 this.taskItems_.clear(); | 2519 this.taskItems_.clear(); |
2509 | 2520 |
2510 var defaultTask = null; | 2521 var defaultTask = null; |
2511 var tasksCount = 0; | 2522 var dropDownItems = []; |
| 2523 |
2512 for (var i = 0; i < tasksList.length; i++) { | 2524 for (var i = 0; i < tasksList.length; i++) { |
2513 var task = tasksList[i]; | 2525 var task = tasksList[i]; |
2514 | 2526 |
2515 // Tweak images, titles of internal tasks. | 2527 // Tweak images, titles of internal tasks. |
2516 var task_parts = task.taskId.split('|'); | 2528 var task_parts = task.taskId.split('|'); |
2517 if (task_parts[0] == this.getExtensionId_()) { | 2529 if (task_parts[0] == this.getExtensionId_()) { |
2518 if (task_parts[1] == 'play') { | 2530 if (task_parts[1] == 'play') { |
2519 // TODO(serya): This hack needed until task.iconUrl is working | 2531 // TODO(serya): This hack needed until task.iconUrl is working |
2520 // (see GetFileTasksFileBrowserFunction::RunImpl). | 2532 // (see GetFileTasksFileBrowserFunction::RunImpl). |
2521 task.iconUrl = | 2533 task.iconUrl = |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2560 } else if (task_parts[1] == 'view-in-browser') { | 2572 } else if (task_parts[1] == 'view-in-browser') { |
2561 task.iconUrl = | 2573 task.iconUrl = |
2562 chrome.extension.getURL('images/filetype_generic.png'); | 2574 chrome.extension.getURL('images/filetype_generic.png'); |
2563 task.title = str('ACTION_VIEW'); | 2575 task.title = str('ACTION_VIEW'); |
2564 } else if (task_parts[1] == 'install-crx') { | 2576 } else if (task_parts[1] == 'install-crx') { |
2565 task.iconUrl = | 2577 task.iconUrl = |
2566 chrome.extension.getURL('images/filetype_generic.png'); | 2578 chrome.extension.getURL('images/filetype_generic.png'); |
2567 task.title = str('INSTALL_CRX'); | 2579 task.title = str('INSTALL_CRX'); |
2568 } | 2580 } |
2569 } | 2581 } |
2570 this.taskItems_.addItem(this.renderTaskItem_(task)); | 2582 |
2571 tasksCount++; | 2583 if (defaultTask == null) { |
2572 if (defaultTask == null) defaultTask = task; | 2584 defaultTask = task; |
| 2585 this.taskItems_.defaultItem = this.createComboboxItem_(task); |
| 2586 task.title = task.title + ' ' + str('DEFAULT_ACTION_LABEL'); |
| 2587 dropDownItems.push(this.createComboboxItem_(task)); |
| 2588 } else { |
| 2589 dropDownItems.push(this.createComboboxItem_(task)); |
| 2590 } |
2573 } | 2591 } |
2574 | 2592 |
2575 this.taskItems_.hidden = tasksCount == 0; | 2593 var defaultIdx = 0; |
2576 if (tasksCount > 1) { | 2594 this.taskItems_.hidden = dropDownItems.length == 0; |
2577 // Duplicate default task in drop-down list. | 2595 |
2578 this.taskItems_.addItem(this.renderTaskItem_(defaultTask)); | 2596 if (dropDownItems.length > 1) { |
| 2597 dropDownItems.sort(function(a, b) { |
| 2598 return a.label.localeCompare(b.label); |
| 2599 }); |
| 2600 |
| 2601 for (var j = 0; j < dropDownItems.length; j++) { |
| 2602 this.taskItems_.addDropDownItem(dropDownItems[j]); |
| 2603 if (dropDownItems[j].task.taskId == defaultTask.taskId) { |
| 2604 defaultIdx = j; |
| 2605 } |
| 2606 } |
| 2607 |
| 2608 this.taskItems_.addSeparator(); |
| 2609 this.taskItems_.addDropDownItem({ |
| 2610 label: str('CHANGE_DEFAULT_MENU_ITEM'), |
| 2611 items: dropDownItems, |
| 2612 defaultIdx: defaultIdx |
| 2613 }); |
2579 } | 2614 } |
2580 | 2615 |
2581 selection.tasksList = tasksList; | 2616 selection.tasksList = tasksList; |
2582 if (selection.dispatchDefault) { | 2617 if (selection.dispatchDefault) { |
2583 // We got a request to dispatch the default task for the selection. | 2618 // We got a request to dispatch the default task for the selection. |
2584 selection.dispatchDefault = false; | 2619 selection.dispatchDefault = false; |
2585 this.dispatchDefaultTask_(selection); | 2620 this.dispatchDefaultTask_(selection); |
2586 } | 2621 } |
2587 }; | 2622 }; |
2588 | 2623 |
2589 FileManager.prototype.renderTaskItem_ = function(task) { | |
2590 var item = this.document_.createElement('div'); | |
2591 item.className = 'task-item'; | |
2592 item.task = task; | |
2593 | |
2594 var img = this.document_.createElement('img'); | |
2595 img.src = task.iconUrl; | |
2596 item.appendChild(img); | |
2597 | |
2598 var label = this.document_.createElement('div'); | |
2599 label.appendChild(this.document_.createTextNode(task.title)); | |
2600 item.appendChild(label); | |
2601 | |
2602 return item; | |
2603 }; | |
2604 | |
2605 FileManager.prototype.getExtensionId_ = function() { | 2624 FileManager.prototype.getExtensionId_ = function() { |
2606 return chrome.extension.getURL('').split('/')[2]; | 2625 return chrome.extension.getURL('').split('/')[2]; |
2607 }; | 2626 }; |
2608 | 2627 |
2609 FileManager.prototype.onExternalLinkClick_ = function(url) { | 2628 FileManager.prototype.onExternalLinkClick_ = function(url) { |
2610 chrome.tabs.create({url: url}); | 2629 chrome.tabs.create({url: url}); |
2611 if (this.dialogType_ != FileManager.DialogType.FULL_PAGE) { | 2630 if (this.dialogType_ != FileManager.DialogType.FULL_PAGE) { |
2612 this.onCancel_(); | 2631 this.onCancel_(); |
2613 } | 2632 } |
2614 }; | 2633 }; |
2615 | 2634 |
| 2635 /** |
| 2636 * Task combobox handler. |
| 2637 * |
| 2638 * @param {Object} event Event containing task which was clicked. |
| 2639 */ |
2616 FileManager.prototype.onTaskItemClicked_ = function(event) { | 2640 FileManager.prototype.onTaskItemClicked_ = function(event) { |
2617 this.dispatchFileTask_(event.item.task.taskId, this.selection.urls); | 2641 if (event.item.task) { |
| 2642 // Task field doesn't exist on change-default dropdown item. |
| 2643 this.dispatchFileTask_(event.item.task.taskId, this.selection.urls); |
| 2644 } else { |
| 2645 var extensions = []; |
| 2646 |
| 2647 for (var i = 0; i < this.selection.urls.length; i++) { |
| 2648 var match = /\.(\w+)$/g.exec(this.selection.urls[i]); |
| 2649 if (match) { |
| 2650 var ext = match[1].toUpperCase(); |
| 2651 if (extensions.indexOf(ext) == -1) { |
| 2652 extensions.push(ext); |
| 2653 } |
| 2654 } |
| 2655 } |
| 2656 |
| 2657 var format = ''; |
| 2658 |
| 2659 if (extensions.length != 1) { |
| 2660 format = extensions[0]; |
| 2661 } |
| 2662 |
| 2663 // Change default was clicked. We should open "change default" dialog. |
| 2664 this.defaultTaskPicker.show( |
| 2665 strf('CHANGE_DEFAULT_CAPTION', format), |
| 2666 event.item.items, event.item.defaultIdx, |
| 2667 this.onDefaultTaskDone_.bind(this)); |
| 2668 } |
2618 }; | 2669 }; |
2619 | 2670 |
| 2671 |
| 2672 /** |
| 2673 * Set's given task as default, when this task is applicable. |
| 2674 * @param {Object} task Task to set as default. |
| 2675 */ |
| 2676 FileManager.prototype.onDefaultTaskDone_ = function(task) { |
| 2677 chrome.fileBrowserPrivate.setDefaultTask(task.taskId); |
| 2678 |
| 2679 chrome.fileBrowserPrivate.getFileTasks( |
| 2680 this.selection.urls, |
| 2681 this.onTasksFound_.bind(this, this.selection)); |
| 2682 } |
| 2683 |
2620 /** | 2684 /** |
2621 * Dispatches default task for the current selection. If tasks are not ready | 2685 * Dispatches default task for the current selection. If tasks are not ready |
2622 * yet, dispatches after task are available. | 2686 * yet, dispatches after task are available. |
2623 * @param {Object=} opt_selection Object similar to this.selection. | 2687 * @param {Object=} opt_selection Object similar to this.selection. |
2624 */ | 2688 */ |
2625 FileManager.prototype.dispatchDefaultTask_ = function(opt_selection) { | 2689 FileManager.prototype.dispatchDefaultTask_ = function(opt_selection) { |
2626 var selection = opt_selection || this.selection; | 2690 var selection = opt_selection || this.selection; |
2627 | 2691 |
2628 if (selection.urls.length == 0) | 2692 if (selection.urls.length == 0) |
2629 return; | 2693 return; |
(...skipping 2117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4747 | 4811 |
4748 function closeBanner() { | 4812 function closeBanner() { |
4749 self.cleanupGDataWelcome_(); | 4813 self.cleanupGDataWelcome_(); |
4750 // Stop showing the welcome banner. | 4814 // Stop showing the welcome banner. |
4751 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; | 4815 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; |
4752 } | 4816 } |
4753 | 4817 |
4754 return maybeShowBanner; | 4818 return maybeShowBanner; |
4755 }; | 4819 }; |
4756 })(); | 4820 })(); |
OLD | NEW |