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

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: Fixed comments. 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 2395 matching lines...) Expand 10 before | Expand all | Expand 10 after
2406 return path && 2406 return path &&
2407 this.isGDataEnabled() && 2407 this.isGDataEnabled() &&
2408 DirectoryModel.getRootType(path) == DirectoryModel.RootType.GDATA; 2408 DirectoryModel.getRootType(path) == DirectoryModel.RootType.GDATA;
2409 }; 2409 };
2410 2410
2411 FileManager.prototype.getMetadataProvider = function() { 2411 FileManager.prototype.getMetadataProvider = function() {
2412 return this.metadataProvider_; 2412 return this.metadataProvider_;
2413 }; 2413 };
2414 2414
2415 /** 2415 /**
2416 * Creates combobox item based on task.
2417 * @param {Object} task Task to convert.
2418 * @return {Object} Item appendable to combobox drop-down list.
2419 */
2420 FileManager.prototype.createComboboxItem_ = function(task) {
2421 return { label: task.title, iconUrl: task.iconUrl, task: task};
dgozman 2012/05/21 12:40:38 space before }
Dmitry Zvorygin 2012/05/21 13:20:14 Done.
2422 }
2423
2424 /**
2416 * Callback called when tasks for selected files are determined. 2425 * Callback called when tasks for selected files are determined.
2417 * @param {Object} selection Selection is passed here, since this.selection 2426 * @param {Object} selection Selection is passed here, since this.selection
2418 * can change before tasks were found, and we should be accurate. 2427 * can change before tasks were found, and we should be accurate.
2419 * @param {Array.<Task>} tasksList The tasks list. 2428 * @param {Array.<Task>} tasksList The tasks list.
2420 */ 2429 */
2421 FileManager.prototype.onTasksFound_ = function(selection, tasksList) { 2430 FileManager.prototype.onTasksFound_ = function(selection, tasksList) {
2422 this.taskItems_.clear(); 2431 this.taskItems_.clear();
2423 2432
2424 var defaultTask = null; 2433 var defaultTask = null;
2425 var tasksCount = 0; 2434 var tasksCount = 0;
2435
2426 for (var i = 0; i < tasksList.length; i++) { 2436 for (var i = 0; i < tasksList.length; i++) {
2427 var task = tasksList[i]; 2437 var task = tasksList[i];
2428 2438
2429 // Tweak images, titles of internal tasks. 2439 // Tweak images, titles of internal tasks.
2430 var task_parts = task.taskId.split('|'); 2440 var task_parts = task.taskId.split('|');
2431 if (task_parts[0] == this.getExtensionId_()) { 2441 if (task_parts[0] == this.getExtensionId_()) {
2432 if (task_parts[1] == 'play') { 2442 if (task_parts[1] == 'play') {
2433 // TODO(serya): This hack needed until task.iconUrl is working 2443 // TODO(serya): This hack needed until task.iconUrl is working
2434 // (see GetFileTasksFileBrowserFunction::RunImpl). 2444 // (see GetFileTasksFileBrowserFunction::RunImpl).
2435 task.iconUrl = 2445 task.iconUrl =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2474 } else if (task_parts[1] == 'view-in-browser') { 2484 } else if (task_parts[1] == 'view-in-browser') {
2475 task.iconUrl = 2485 task.iconUrl =
2476 chrome.extension.getURL('images/filetype_generic.png'); 2486 chrome.extension.getURL('images/filetype_generic.png');
2477 task.title = str('ACTION_VIEW'); 2487 task.title = str('ACTION_VIEW');
2478 } else if (task_parts[1] == 'install-crx') { 2488 } else if (task_parts[1] == 'install-crx') {
2479 task.iconUrl = 2489 task.iconUrl =
2480 chrome.extension.getURL('images/filetype_generic.png'); 2490 chrome.extension.getURL('images/filetype_generic.png');
2481 task.title = str('INSTALL_CRX'); 2491 task.title = str('INSTALL_CRX');
2482 } 2492 }
2483 } 2493 }
2484 this.taskItems_.addItem(this.renderTaskItem_(task));
2485 tasksCount++; 2494 tasksCount++;
2486 if (defaultTask == null) defaultTask = task; 2495 if (defaultTask == null) defaultTask = task;
2496
2497 // If we have at least two items, then we have to use drop-down list.
2498 if (tasksCount == 2)
2499 this.taskItems_.addDropDownItem(this.createComboboxItem_(defaultTask));
2500
2501 if (tasksCount >= 2)
2502 this.taskItems_.addDropDownItem(this.createComboboxItem_(task));
2487 } 2503 }
2488 2504
2489 this.taskItems_.hidden = tasksCount == 0; 2505 this.taskItems_.hidden = tasksCount == 0;
2490 if (tasksCount > 1) { 2506 if (defaultTask != null)
2491 // Duplicate default task in drop-down list. 2507 this.taskItems_.defaultItem = createComboboxItem_(defaultTask);
2492 this.taskItems_.addItem(this.renderTaskItem_(defaultTask));
2493 }
2494 2508
2495 selection.tasksList = tasksList; 2509 selection.tasksList = tasksList;
2496 if (selection.dispatchDefault) { 2510 if (selection.dispatchDefault) {
2497 // We got a request to dispatch the default task for the selection. 2511 // We got a request to dispatch the default task for the selection.
2498 selection.dispatchDefault = false; 2512 selection.dispatchDefault = false;
2499 this.dispatchDefaultTask_(selection); 2513 this.dispatchDefaultTask_(selection);
2500 } 2514 }
2501 }; 2515 };
2502 2516
2503 FileManager.prototype.renderTaskItem_ = function(task) {
2504 var item = this.document_.createElement('div');
2505 item.className = 'task-item';
2506 item.task = task;
2507
2508 var img = this.document_.createElement('img');
2509 img.src = task.iconUrl;
2510 item.appendChild(img);
2511
2512 var label = this.document_.createElement('div');
2513 label.appendChild(this.document_.createTextNode(task.title));
2514 item.appendChild(label);
2515
2516 return item;
2517 };
2518
2519 FileManager.prototype.getExtensionId_ = function() { 2517 FileManager.prototype.getExtensionId_ = function() {
2520 return chrome.extension.getURL('').split('/')[2]; 2518 return chrome.extension.getURL('').split('/')[2];
2521 }; 2519 };
2522 2520
2523 FileManager.prototype.onExternalLinkClick_ = function(url) { 2521 FileManager.prototype.onExternalLinkClick_ = function(url) {
2524 chrome.tabs.create({url: url}); 2522 chrome.tabs.create({url: url});
2525 if (this.dialogType_ != FileManager.DialogType.FULL_PAGE) { 2523 if (this.dialogType_ != FileManager.DialogType.FULL_PAGE) {
2526 this.onCancel_(); 2524 this.onCancel_();
2527 } 2525 }
2528 }; 2526 };
(...skipping 2126 matching lines...) Expand 10 before | Expand all | Expand 10 after
4655 4653
4656 function closeBanner() { 4654 function closeBanner() {
4657 self.cleanupGDataWelcome_(); 4655 self.cleanupGDataWelcome_();
4658 // Stop showing the welcome banner. 4656 // Stop showing the welcome banner.
4659 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; 4657 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT;
4660 } 4658 }
4661 4659
4662 return maybeShowBanner; 4660 return maybeShowBanner;
4663 }; 4661 };
4664 })(); 4662 })();
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