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

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

Issue 10411018: [FileBrowser] Added DefaultAction dialog to choose default action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with master. Created 8 years, 7 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) 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 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 /** 583 /**
584 * One-time initialization of dialogs. 584 * One-time initialization of dialogs.
585 */ 585 */
586 FileManager.prototype.initDialogs_ = function() { 586 FileManager.prototype.initDialogs_ = function() {
587 var d = cr.ui.dialogs; 587 var d = cr.ui.dialogs;
588 d.BaseDialog.OK_LABEL = str('OK_LABEL'); 588 d.BaseDialog.OK_LABEL = str('OK_LABEL');
589 d.BaseDialog.CANCEL_LABEL = str('CANCEL_LABEL'); 589 d.BaseDialog.CANCEL_LABEL = str('CANCEL_LABEL');
590 this.alert = new d.AlertDialog(this.dialogDom_); 590 this.alert = new d.AlertDialog(this.dialogDom_);
591 this.confirm = new d.ConfirmDialog(this.dialogDom_); 591 this.confirm = new d.ConfirmDialog(this.dialogDom_);
592 this.prompt = new d.PromptDialog(this.dialogDom_); 592 this.prompt = new d.PromptDialog(this.dialogDom_);
593 this.defaultTaskPicker =
594 new cr.filebrowser.DefaultActionDialog(this.dialogDom_);
593 }; 595 };
594 596
595 /** 597 /**
596 * One-time initialization of various DOM nodes. 598 * One-time initialization of various DOM nodes.
597 */ 599 */
598 FileManager.prototype.initDom_ = function() { 600 FileManager.prototype.initDom_ = function() {
599 // Cache nodes we'll be manipulating. 601 // Cache nodes we'll be manipulating.
600 this.previewThumbnails_ = 602 this.previewThumbnails_ =
601 this.dialogDom_.querySelector('.preview-thumbnails'); 603 this.dialogDom_.querySelector('.preview-thumbnails');
602 this.previewPanel_ = this.dialogDom_.querySelector('.preview-panel'); 604 this.previewPanel_ = this.dialogDom_.querySelector('.preview-panel');
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after
2584 if (defaultTask == null) { 2586 if (defaultTask == null) {
2585 defaultTask = task; 2587 defaultTask = task;
2586 this.taskItems_.defaultItem = this.createComboboxItem_(task); 2588 this.taskItems_.defaultItem = this.createComboboxItem_(task);
2587 task.title = task.title + ' ' + str('DEFAULT_ACTION_LABEL'); 2589 task.title = task.title + ' ' + str('DEFAULT_ACTION_LABEL');
2588 dropDownItems.push(this.createComboboxItem_(task)); 2590 dropDownItems.push(this.createComboboxItem_(task));
2589 } else { 2591 } else {
2590 dropDownItems.push(this.createComboboxItem_(task)); 2592 dropDownItems.push(this.createComboboxItem_(task));
2591 } 2593 }
2592 } 2594 }
2593 2595
2596 var defaultIdx = 0;
2594 this.taskItems_.hidden = dropDownItems.length == 0; 2597 this.taskItems_.hidden = dropDownItems.length == 0;
2595 2598
2596 if (dropDownItems.length > 1) { 2599 if (dropDownItems.length > 1) {
2597 dropDownItems.sort(function(a, b) { 2600 dropDownItems.sort(function(a, b) {
2598 return a.label.localeCompare(b.label); 2601 return a.label.localeCompare(b.label);
2599 }); 2602 });
2600 2603
2601 for (var j = 0; j < dropDownItems.length; j++) { 2604 for (var j = 0; j < dropDownItems.length; j++) {
2602 this.taskItems_.addDropDownItem(dropDownItems[j]); 2605 this.taskItems_.addDropDownItem(dropDownItems[j]);
2606 if (dropDownItems[j].task.taskId == defaultTask.taskId) {
2607 defaultIdx = j;
2608 }
2603 } 2609 }
2610
2611 this.taskItems_.addSeparator();
2612 this.taskItems_.addDropDownItem({
2613 label: str('CHANGE_DEFAULT_MENU_ITEM'),
2614 items: dropDownItems,
2615 defaultIdx: defaultIdx
2616 });
2604 } 2617 }
2605 2618
2606 selection.tasksList = tasksList; 2619 selection.tasksList = tasksList;
2607 if (selection.dispatchDefault) { 2620 if (selection.dispatchDefault) {
2608 // We got a request to dispatch the default task for the selection. 2621 // We got a request to dispatch the default task for the selection.
2609 selection.dispatchDefault = false; 2622 selection.dispatchDefault = false;
2610 this.dispatchDefaultTask_(selection); 2623 this.dispatchDefaultTask_(selection);
2611 } 2624 }
2612 }; 2625 };
2613 2626
2614 FileManager.prototype.getExtensionId_ = function() { 2627 FileManager.prototype.getExtensionId_ = function() {
2615 return chrome.extension.getURL('').split('/')[2]; 2628 return chrome.extension.getURL('').split('/')[2];
2616 }; 2629 };
2617 2630
2618 FileManager.prototype.onExternalLinkClick_ = function(url) { 2631 FileManager.prototype.onExternalLinkClick_ = function(url) {
2619 chrome.tabs.create({url: url}); 2632 chrome.tabs.create({url: url});
2620 if (this.dialogType_ != FileManager.DialogType.FULL_PAGE) { 2633 if (this.dialogType_ != FileManager.DialogType.FULL_PAGE) {
2621 this.onCancel_(); 2634 this.onCancel_();
2622 } 2635 }
2623 }; 2636 };
2624 2637
2638 /**
2639 * Task combobox handler.
2640 *
2641 * @param {Object} event Event containing task which was clicked.
2642 */
2625 FileManager.prototype.onTaskItemClicked_ = function(event) { 2643 FileManager.prototype.onTaskItemClicked_ = function(event) {
2626 this.dispatchFileTask_(event.item.task.taskId, this.selection.urls); 2644 if (event.item.task) {
2645 // Task field doesn't exist on change-default dropdown item.
2646 this.dispatchFileTask_(event.item.task.taskId, this.selection.urls);
2647 } else {
2648 var extensions = [];
2649
2650 for (var i = 0; i < this.selection.urls.length; i++) {
2651 var match = /\.(\w+)$/g.exec(this.selection.urls[i]);
2652 if (match) {
2653 var ext = match[1].toUpperCase();
2654 if (extensions.indexOf(ext) == -1) {
2655 extensions.push(ext);
2656 }
2657 }
2658 }
2659
2660 var format = '';
2661
2662 if (extensions.length != 1) {
2663 format = extensions[0];
2664 }
2665
2666 // Change default was clicked. We should open "change default" dialog.
2667 this.defaultTaskPicker.show(
2668 strf('CHANGE_DEFAULT_CAPTION', format),
2669 event.item.items, event.item.defaultIdx,
2670 this.onDefaultTaskDone_.bind(this));
2671 }
2627 }; 2672 };
2628 2673
2674
2675 /**
2676 * Set's given task as default, when this task is applicable.
2677 * @param {Object} task Task to set as default.
2678 */
2679 FileManager.prototype.onDefaultTaskDone_ = function(task) {
2680 chrome.fileBrowserPrivate.setDefaultTask(task.taskId);
2681
2682 chrome.fileBrowserPrivate.getFileTasks(
2683 this.selection.urls,
2684 this.onTasksFound_.bind(this, this.selection));
2685 }
2686
2629 /** 2687 /**
2630 * Dispatches default task for the current selection. If tasks are not ready 2688 * Dispatches default task for the current selection. If tasks are not ready
2631 * yet, dispatches after task are available. 2689 * yet, dispatches after task are available.
2632 * @param {Object=} opt_selection Object similar to this.selection. 2690 * @param {Object=} opt_selection Object similar to this.selection.
2633 */ 2691 */
2634 FileManager.prototype.dispatchDefaultTask_ = function(opt_selection) { 2692 FileManager.prototype.dispatchDefaultTask_ = function(opt_selection) {
2635 var selection = opt_selection || this.selection; 2693 var selection = opt_selection || this.selection;
2636 2694
2637 if (selection.urls.length == 0) 2695 if (selection.urls.length == 0)
2638 return; 2696 return;
(...skipping 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after
4603 function closeBanner() { 4661 function closeBanner() {
4604 self.cleanupGDataWelcome_(); 4662 self.cleanupGDataWelcome_();
4605 // Stop showing the welcome banner. 4663 // Stop showing the welcome banner.
4606 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; 4664 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT;
4607 } 4665 }
4608 4666
4609 return maybeShowBanner; 4667 return maybeShowBanner;
4610 }; 4668 };
4611 })(); 4669 })();
4612 4670
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698