| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 * @fileoverview Element which shows context menus and handles keyboard | 6 * @fileoverview Element which shows context menus and handles keyboard |
| 7 * shortcuts. | 7 * shortcuts. |
| 8 */ | 8 */ |
| 9 cr.define('bookmarks', function() { | 9 cr.define('bookmarks', function() { |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 /** @private */ | 41 /** @private */ |
| 42 hasAnySublabel_: { | 42 hasAnySublabel_: { |
| 43 type: Boolean, | 43 type: Boolean, |
| 44 reflectToAttribute: true, | 44 reflectToAttribute: true, |
| 45 }, | 45 }, |
| 46 | 46 |
| 47 /** @private */ | 47 /** @private */ |
| 48 globalCanEdit_: Boolean, | 48 globalCanEdit_: Boolean, |
| 49 }, | 49 }, |
| 50 | 50 |
| 51 /** @private {?Function} */ |
| 52 confirmOpenCallback_: null, |
| 53 |
| 51 attached: function() { | 54 attached: function() { |
| 52 assert(CommandManager.instance_ == null); | 55 assert(CommandManager.instance_ == null); |
| 53 CommandManager.instance_ = this; | 56 CommandManager.instance_ = this; |
| 54 | 57 |
| 55 this.watch('globalCanEdit_', function(state) { | 58 this.watch('globalCanEdit_', function(state) { |
| 56 return state.prefs.canEdit; | 59 return state.prefs.canEdit; |
| 57 }); | 60 }); |
| 58 this.updateFromStore(); | 61 this.updateFromStore(); |
| 59 | 62 |
| 60 /** @private {function(!Event)} */ | 63 /** @private {function(!Event)} */ |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 currentId = assert(nodes[currentId].parentId); | 333 currentId = assert(nodes[currentId].parentId); |
| 331 if (itemIds.has(currentId)) | 334 if (itemIds.has(currentId)) |
| 332 return; | 335 return; |
| 333 } | 336 } |
| 334 minimizedSet.add(itemId); | 337 minimizedSet.add(itemId); |
| 335 }); | 338 }); |
| 336 return minimizedSet; | 339 return minimizedSet; |
| 337 }, | 340 }, |
| 338 | 341 |
| 339 /** | 342 /** |
| 343 * Open the given |urls| in response to a |command|. May show a confirmation |
| 344 * dialog before opening large numbers of URLs. |
| 340 * @param {!Array<string>} urls | 345 * @param {!Array<string>} urls |
| 341 * @param {Command} command | 346 * @param {Command} command |
| 342 * @private | 347 * @private |
| 343 */ | 348 */ |
| 344 openUrls_: function(urls, command) { | 349 openUrls_: function(urls, command) { |
| 345 assert( | 350 assert( |
| 346 command == Command.OPEN || command == Command.OPEN_NEW_TAB || | 351 command == Command.OPEN || command == Command.OPEN_NEW_TAB || |
| 347 command == Command.OPEN_NEW_WINDOW || | 352 command == Command.OPEN_NEW_WINDOW || |
| 348 command == Command.OPEN_INCOGNITO); | 353 command == Command.OPEN_INCOGNITO); |
| 349 | 354 |
| 350 if (urls.length == 0) | 355 if (urls.length == 0) |
| 351 return; | 356 return; |
| 352 | 357 |
| 353 var incognito = command == Command.OPEN_INCOGNITO; | 358 var openUrlsCallback = function() { |
| 354 if (command == Command.OPEN_NEW_WINDOW || incognito) { | 359 var incognito = command == Command.OPEN_INCOGNITO; |
| 355 chrome.windows.create({url: urls, incognito: incognito}); | 360 if (command == Command.OPEN_NEW_WINDOW || incognito) { |
| 356 } else { | 361 chrome.windows.create({url: urls, incognito: incognito}); |
| 357 if (command == Command.OPEN) | 362 } else { |
| 358 chrome.tabs.create({url: urls.shift(), active: true}); | 363 if (command == Command.OPEN) |
| 359 urls.forEach(function(url) { | 364 chrome.tabs.create({url: urls.shift(), active: true}); |
| 360 chrome.tabs.create({url: url, active: false}); | 365 urls.forEach(function(url) { |
| 361 }); | 366 chrome.tabs.create({url: url, active: false}); |
| 367 }); |
| 368 } |
| 369 }; |
| 370 |
| 371 if (urls.length <= OPEN_CONFIRMATION_LIMIT) { |
| 372 openUrlsCallback(); |
| 373 return; |
| 362 } | 374 } |
| 375 |
| 376 this.confirmOpenCallback_ = openUrlsCallback; |
| 377 var dialog = this.$.openDialog.get(); |
| 378 dialog.querySelector('.body').textContent = |
| 379 loadTimeData.getStringF('openDialogBody', urls.length); |
| 380 dialog.showModal(); |
| 363 }, | 381 }, |
| 364 | 382 |
| 365 /** | 383 /** |
| 366 * Returns all URLs in the given set of nodes and their immediate children. | 384 * Returns all URLs in the given set of nodes and their immediate children. |
| 367 * Note that these will be ordered by insertion order into the |itemIds| | 385 * Note that these will be ordered by insertion order into the |itemIds| |
| 368 * set, and that it is possible to duplicate a URL by passing in both the | 386 * set, and that it is possible to duplicate a URL by passing in both the |
| 369 * parent ID and child ID. | 387 * parent ID and child ID. |
| 370 * @param {!Set<string>} itemIds | 388 * @param {!Set<string>} itemIds |
| 371 * @return {!Array<string>} | 389 * @return {!Array<string>} |
| 372 * @private | 390 * @private |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 * @param {Event} e | 474 * @param {Event} e |
| 457 * @private | 475 * @private |
| 458 */ | 476 */ |
| 459 onMenuMousedown_: function(e) { | 477 onMenuMousedown_: function(e) { |
| 460 if (e.path[0] != this.$.dropdown) | 478 if (e.path[0] != this.$.dropdown) |
| 461 return; | 479 return; |
| 462 | 480 |
| 463 this.closeCommandMenu(); | 481 this.closeCommandMenu(); |
| 464 }, | 482 }, |
| 465 | 483 |
| 484 /** @private */ |
| 485 onOpenCancelTap_: function() { |
| 486 this.$.openDialog.get().cancel(); |
| 487 }, |
| 488 |
| 489 /** @private */ |
| 490 onOpenConfirmTap_: function() { |
| 491 this.confirmOpenCallback_(); |
| 492 this.$.openDialog.get().close(); |
| 493 }, |
| 494 |
| 466 /** | 495 /** |
| 467 * @param {Command} command | 496 * @param {Command} command |
| 468 * @return {string} | 497 * @return {string} |
| 469 * @private | 498 * @private |
| 470 */ | 499 */ |
| 471 getCommandLabel_: function(command) { | 500 getCommandLabel_: function(command) { |
| 472 var multipleNodes = this.menuIds_.size > 1 || | 501 var multipleNodes = this.menuIds_.size > 1 || |
| 473 this.containsMatchingNode_(this.menuIds_, function(node) { | 502 this.containsMatchingNode_(this.menuIds_, function(node) { |
| 474 return !node.url; | 503 return !node.url; |
| 475 }); | 504 }); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 | 577 |
| 549 /** @return {!bookmarks.CommandManager} */ | 578 /** @return {!bookmarks.CommandManager} */ |
| 550 CommandManager.getInstance = function() { | 579 CommandManager.getInstance = function() { |
| 551 return assert(CommandManager.instance_); | 580 return assert(CommandManager.instance_); |
| 552 }; | 581 }; |
| 553 | 582 |
| 554 return { | 583 return { |
| 555 CommandManager: CommandManager, | 584 CommandManager: CommandManager, |
| 556 }; | 585 }; |
| 557 }); | 586 }); |
| OLD | NEW |