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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 /** | 488 /** |
489 * One-time initialization of dialogs. | 489 * One-time initialization of dialogs. |
490 */ | 490 */ |
491 FileManager.prototype.initDialogs_ = function() { | 491 FileManager.prototype.initDialogs_ = function() { |
492 var d = cr.ui.dialogs; | 492 var d = cr.ui.dialogs; |
493 d.BaseDialog.OK_LABEL = str('OK_LABEL'); | 493 d.BaseDialog.OK_LABEL = str('OK_LABEL'); |
494 d.BaseDialog.CANCEL_LABEL = str('CANCEL_LABEL'); | 494 d.BaseDialog.CANCEL_LABEL = str('CANCEL_LABEL'); |
495 this.alert = new d.AlertDialog(this.dialogDom_); | 495 this.alert = new d.AlertDialog(this.dialogDom_); |
496 this.confirm = new d.ConfirmDialog(this.dialogDom_); | 496 this.confirm = new d.ConfirmDialog(this.dialogDom_); |
497 this.prompt = new d.PromptDialog(this.dialogDom_); | 497 this.prompt = new d.PromptDialog(this.dialogDom_); |
498 this.defaultTaskPicker = | |
499 new cr.filebrowser.DefaultActionDialog(this.dialogDom_); | |
498 }; | 500 }; |
499 | 501 |
500 /** | 502 /** |
501 * One-time initialization of various DOM nodes. | 503 * One-time initialization of various DOM nodes. |
502 */ | 504 */ |
503 FileManager.prototype.initDom_ = function() { | 505 FileManager.prototype.initDom_ = function() { |
504 // Cache nodes we'll be manipulating. | 506 // Cache nodes we'll be manipulating. |
505 this.previewThumbnails_ = | 507 this.previewThumbnails_ = |
506 this.dialogDom_.querySelector('.preview-thumbnails'); | 508 this.dialogDom_.querySelector('.preview-thumbnails'); |
507 this.previewPanel_ = this.dialogDom_.querySelector('.preview-panel'); | 509 this.previewPanel_ = this.dialogDom_.querySelector('.preview-panel'); |
(...skipping 1918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2426 } else if (task_parts[1] == 'view-in-browser') { | 2428 } else if (task_parts[1] == 'view-in-browser') { |
2427 task.iconUrl = | 2429 task.iconUrl = |
2428 chrome.extension.getURL('images/filetype_generic.png'); | 2430 chrome.extension.getURL('images/filetype_generic.png'); |
2429 task.title = str('ACTION_VIEW'); | 2431 task.title = str('ACTION_VIEW'); |
2430 } else if (task_parts[1] == 'install-crx') { | 2432 } else if (task_parts[1] == 'install-crx') { |
2431 task.iconUrl = | 2433 task.iconUrl = |
2432 chrome.extension.getURL('images/filetype_generic.png'); | 2434 chrome.extension.getURL('images/filetype_generic.png'); |
2433 task.title = str('INSTALL_CRX'); | 2435 task.title = str('INSTALL_CRX'); |
2434 } | 2436 } |
2435 } | 2437 } |
2438 | |
2439 var label = task.title; | |
2440 if (defaultTask == null) { | |
2441 defaultTask = task; | |
2442 label = label + ' ' + str('DEFAULT_ACTION_LABEL'); | |
2443 } | |
2444 | |
2436 if (tasksList.length > 1) | 2445 if (tasksList.length > 1) |
2437 this.taskItems_.addItem({label: task.title, | 2446 this.taskItems_.addItem({label: label, |
2438 iconUrl: task.iconUrl, task: task}); | 2447 iconUrl: task.iconUrl, task: task}); |
2448 | |
2439 tasksCount++; | 2449 tasksCount++; |
2440 if (defaultTask == null) defaultTask = task; | 2450 |
2441 } | 2451 } |
2442 | 2452 |
2443 this.taskItems_.hidden = tasksCount == 0; | 2453 this.taskItems_.hidden = tasksCount == 0; |
2444 if (defaultTask != null) { | 2454 if (defaultTask != null) { |
2445 this.taskItems_.defaultItem = ({label: defaultTask.title, | 2455 this.taskItems_.defaultItem = ({label: defaultTask.title, |
2446 iconUrl: defaultTask.iconUrl, task: defaultTask}); | 2456 iconUrl: defaultTask.iconUrl, task: defaultTask}); |
2447 } | 2457 } |
2448 | 2458 |
2459 if (tasksList.length > 1) { | |
dgozman
2012/05/18 14:50:06
use tasksCount, which is not the same as tasksList
Dmitry Zvorygin
2012/05/22 14:32:59
Done.
| |
2460 this.taskItems_.addSeparator(); | |
2461 this.taskItems_.addItem( | |
2462 {label: str('CHANGE_DEFAULT_MENU_ITEM'), taskList: tasksList}); | |
2463 } | |
2464 | |
2449 selection.tasksList = tasksList; | 2465 selection.tasksList = tasksList; |
2450 if (selection.dispatchDefault) { | 2466 if (selection.dispatchDefault) { |
2451 // We got a request to dispatch the default task for the selection. | 2467 // We got a request to dispatch the default task for the selection. |
2452 selection.dispatchDefault = false; | 2468 selection.dispatchDefault = false; |
2453 this.dispatchDefaultTask_(selection); | 2469 this.dispatchDefaultTask_(selection); |
2454 } | 2470 } |
2455 }; | 2471 }; |
2456 | 2472 |
2457 FileManager.prototype.getExtensionId_ = function() { | 2473 FileManager.prototype.getExtensionId_ = function() { |
2458 return chrome.extension.getURL('').split('/')[2]; | 2474 return chrome.extension.getURL('').split('/')[2]; |
2459 }; | 2475 }; |
2460 | 2476 |
2461 FileManager.prototype.onExternalLinkClick_ = function(url) { | 2477 FileManager.prototype.onExternalLinkClick_ = function(url) { |
2462 chrome.tabs.create({url: url}); | 2478 chrome.tabs.create({url: url}); |
2463 if (this.dialogType_ != FileManager.DialogType.FULL_PAGE) { | 2479 if (this.dialogType_ != FileManager.DialogType.FULL_PAGE) { |
2464 this.onCancel_(); | 2480 this.onCancel_(); |
2465 } | 2481 } |
2466 }; | 2482 }; |
2467 | 2483 |
2484 /** | |
2485 * Task combobox handler. | |
2486 * | |
2487 * @param {Object} event Event containing task which was clicked. | |
2488 */ | |
2468 FileManager.prototype.onTaskItemClicked_ = function(event) { | 2489 FileManager.prototype.onTaskItemClicked_ = function(event) { |
2469 this.dispatchFileTask_(event.item.task.taskId, this.selection.urls); | 2490 if (event.item.task) { |
2491 this.dispatchFileTask_(event.item.task.taskId, this.selection.urls); | |
2492 } else { | |
dgozman
2012/05/18 14:50:06
We should have a comment that item without task mu
Dmitry Zvorygin
2012/05/22 14:32:59
Done.
| |
2493 var extensions = []; | |
2494 | |
2495 for (var i = 0; i < this.selection.urls.length; i++) { | |
2496 var ext = /\.(\w+)$/g.exec(this.selection.urls[i])[1].toUpperCase(); | |
dgozman
2012/05/18 14:50:06
There may be no extension.
Dmitry Zvorygin
2012/05/22 14:32:59
Done.
| |
2497 if (extensions.indexOf(ext) == -1) { | |
2498 extensions.push(ext); | |
2499 } | |
2500 } | |
2501 | |
2502 // Change default was clicked. We should open "change default" dialog. | |
2503 this.defaultTaskPicker.show( | |
2504 strf('CHANGE_DEFAULT_CAPTION', | |
dgozman
2012/05/18 14:50:06
We don't want to show all extensions in the captio
Dmitry Zvorygin
2012/05/22 14:32:59
Done.
| |
2505 extensions.join(', ')), | |
dgozman
2012/05/18 14:50:06
indentation
Dmitry Zvorygin
2012/05/22 14:32:59
Done.
| |
2506 event.item.taskList, this.onDefaultTaskDone_.bind(this)); | |
2507 } | |
2470 }; | 2508 }; |
2471 | 2509 |
2510 | |
2511 /** | |
2512 * Set's given task as default, when this task is applicable. | |
2513 * @param {Object} task Task to set as default. | |
2514 */ | |
2515 FileManager.prototype.onDefaultTaskDone_ = function(task) { | |
2516 chrome.fileBrowserPrivate.setDefaultTask(task.taskId); | |
2517 | |
2518 chrome.fileBrowserPrivate.getFileTasks( | |
2519 this.selection.urls, | |
2520 this.onTasksFound_.bind(this, this.selection)); | |
2521 } | |
2522 | |
2472 /** | 2523 /** |
2473 * Dispatches default task for the current selection. If tasks are not ready | 2524 * Dispatches default task for the current selection. If tasks are not ready |
2474 * yet, dispatches after task are available. | 2525 * yet, dispatches after task are available. |
2475 * @param {Object=} opt_selection Object similar to this.selection. | 2526 * @param {Object=} opt_selection Object similar to this.selection. |
2476 */ | 2527 */ |
2477 FileManager.prototype.dispatchDefaultTask_ = function(opt_selection) { | 2528 FileManager.prototype.dispatchDefaultTask_ = function(opt_selection) { |
2478 var selection = opt_selection || this.selection; | 2529 var selection = opt_selection || this.selection; |
2479 | 2530 |
2480 if (selection.urls.length == 0) | 2531 if (selection.urls.length == 0) |
2481 return; | 2532 return; |
(...skipping 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4471 | 4522 |
4472 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner); | 4523 this.directoryModel_.addEventListener('scan-completed', maybeShowBanner); |
4473 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner); | 4524 this.directoryModel_.addEventListener('rescan-completed', maybeShowBanner); |
4474 | 4525 |
4475 var style = this.document_.createElement('link'); | 4526 var style = this.document_.createElement('link'); |
4476 style.rel = 'stylesheet'; | 4527 style.rel = 'stylesheet'; |
4477 style.href = 'css/gdrive_welcome.css'; | 4528 style.href = 'css/gdrive_welcome.css'; |
4478 this.document_.head.appendChild(style); | 4529 this.document_.head.appendChild(style); |
4479 }; | 4530 }; |
4480 })(); | 4531 })(); |
OLD | NEW |