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

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

Issue 10391184: [FileBrowser] Migrated ComboButton to menu as dropdown. (Closed) Base URL: improved-actions-menu-126927
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
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 2481 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 return path && 2492 return path &&
2493 this.isGDataEnabled() && 2493 this.isGDataEnabled() &&
2494 DirectoryModel.getRootType(path) == DirectoryModel.RootType.GDATA; 2494 DirectoryModel.getRootType(path) == DirectoryModel.RootType.GDATA;
2495 }; 2495 };
2496 2496
2497 FileManager.prototype.getMetadataProvider = function() { 2497 FileManager.prototype.getMetadataProvider = function() {
2498 return this.metadataProvider_; 2498 return this.metadataProvider_;
2499 }; 2499 };
2500 2500
2501 /** 2501 /**
2502 * Creates combobox item based on task.
2503 * @param {Object} task Task to convert.
2504 * @return {Object} Item appendable to combobox drop-down list.
2505 */
2506 FileManager.prototype.createComboboxItem_ = function(task) {
2507 return { label: task.title, iconUrl: task.iconUrl, task: task };
2508 }
2509
2510 /**
2502 * Callback called when tasks for selected files are determined. 2511 * Callback called when tasks for selected files are determined.
2503 * @param {Object} selection Selection is passed here, since this.selection 2512 * @param {Object} selection Selection is passed here, since this.selection
2504 * can change before tasks were found, and we should be accurate. 2513 * can change before tasks were found, and we should be accurate.
2505 * @param {Array.<Task>} tasksList The tasks list. 2514 * @param {Array.<Task>} tasksList The tasks list.
2506 */ 2515 */
2507 FileManager.prototype.onTasksFound_ = function(selection, tasksList) { 2516 FileManager.prototype.onTasksFound_ = function(selection, tasksList) {
2508 this.taskItems_.clear(); 2517 this.taskItems_.clear();
2509 2518
2510 var defaultTask = null; 2519 var defaultTask = null;
2511 var tasksCount = 0; 2520 var dropDownItems = [];
2521
2512 for (var i = 0; i < tasksList.length; i++) { 2522 for (var i = 0; i < tasksList.length; i++) {
2513 var task = tasksList[i]; 2523 var task = tasksList[i];
2514 2524
2515 // Tweak images, titles of internal tasks. 2525 // Tweak images, titles of internal tasks.
2516 var task_parts = task.taskId.split('|'); 2526 var task_parts = task.taskId.split('|');
2517 if (task_parts[0] == this.getExtensionId_()) { 2527 if (task_parts[0] == this.getExtensionId_()) {
2518 if (task_parts[1] == 'play') { 2528 if (task_parts[1] == 'play') {
2519 // TODO(serya): This hack needed until task.iconUrl is working 2529 // TODO(serya): This hack needed until task.iconUrl is working
2520 // (see GetFileTasksFileBrowserFunction::RunImpl). 2530 // (see GetFileTasksFileBrowserFunction::RunImpl).
2521 task.iconUrl = 2531 task.iconUrl =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2560 } else if (task_parts[1] == 'view-in-browser') { 2570 } else if (task_parts[1] == 'view-in-browser') {
2561 task.iconUrl = 2571 task.iconUrl =
2562 chrome.extension.getURL('images/filetype_generic.png'); 2572 chrome.extension.getURL('images/filetype_generic.png');
2563 task.title = str('ACTION_VIEW'); 2573 task.title = str('ACTION_VIEW');
2564 } else if (task_parts[1] == 'install-crx') { 2574 } else if (task_parts[1] == 'install-crx') {
2565 task.iconUrl = 2575 task.iconUrl =
2566 chrome.extension.getURL('images/filetype_generic.png'); 2576 chrome.extension.getURL('images/filetype_generic.png');
2567 task.title = str('INSTALL_CRX'); 2577 task.title = str('INSTALL_CRX');
2568 } 2578 }
2569 } 2579 }
2570 this.taskItems_.addItem(this.renderTaskItem_(task)); 2580
2571 tasksCount++; 2581 if (defaultTask == null) {
2572 if (defaultTask == null) defaultTask = task; 2582 defaultTask = task;
2583 this.taskItems_.defaultItem = this.createComboboxItem_(task);
2584 task.title = task.title + ' ' + str('DEFAULT_ACTION_LABEL');
2585 dropDownItems.push(this.createComboboxItem_(task));
2586 } else {
2587 dropDownItems.push(this.createComboboxItem_(task));
2588 }
2573 } 2589 }
2574 2590
2575 this.taskItems_.hidden = tasksCount == 0; 2591 this.taskItems_.hidden = dropDownItems.length == 0;
2576 if (tasksCount > 1) { 2592
2577 // Duplicate default task in drop-down list. 2593 if (dropDownItems.length > 1) {
2578 this.taskItems_.addItem(this.renderTaskItem_(defaultTask)); 2594 dropDownItems.sort(function(a, b) {
2595 return a.label.localeCompare(b.label);
2596 });
2597
2598 for (var j = 0; j < dropDownItems.length; j++) {
2599 this.taskItems_.addDropDownItem(dropDownItems[j]);
2600 }
2579 } 2601 }
2580 2602
2581 selection.tasksList = tasksList; 2603 selection.tasksList = tasksList;
2582 if (selection.dispatchDefault) { 2604 if (selection.dispatchDefault) {
2583 // We got a request to dispatch the default task for the selection. 2605 // We got a request to dispatch the default task for the selection.
2584 selection.dispatchDefault = false; 2606 selection.dispatchDefault = false;
2585 this.dispatchDefaultTask_(selection); 2607 this.dispatchDefaultTask_(selection);
2586 } 2608 }
2587 }; 2609 };
2588 2610
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() { 2611 FileManager.prototype.getExtensionId_ = function() {
2606 return chrome.extension.getURL('').split('/')[2]; 2612 return chrome.extension.getURL('').split('/')[2];
2607 }; 2613 };
2608 2614
2609 FileManager.prototype.onExternalLinkClick_ = function(url) { 2615 FileManager.prototype.onExternalLinkClick_ = function(url) {
2610 chrome.tabs.create({url: url}); 2616 chrome.tabs.create({url: url});
2611 if (this.dialogType_ != FileManager.DialogType.FULL_PAGE) { 2617 if (this.dialogType_ != FileManager.DialogType.FULL_PAGE) {
2612 this.onCancel_(); 2618 this.onCancel_();
2613 } 2619 }
2614 }; 2620 };
(...skipping 2132 matching lines...) Expand 10 before | Expand all | Expand 10 after
4747 4753
4748 function closeBanner() { 4754 function closeBanner() {
4749 self.cleanupGDataWelcome_(); 4755 self.cleanupGDataWelcome_();
4750 // Stop showing the welcome banner. 4756 // Stop showing the welcome banner.
4751 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; 4757 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT;
4752 } 4758 }
4753 4759
4754 return maybeShowBanner; 4760 return maybeShowBanner;
4755 }; 4761 };
4756 })(); 4762 })();
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/js/combobutton.js ('k') | chrome/browser/resources/file_manager/main.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698