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

Side by Side Diff: ui/file_manager/gallery/js/slide_mode.js

Issue 638383002: Disable edit and print button when there is no selection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved the disable/enable logic. Created 6 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * Slide mode displays a single image and has a set of controls to navigate 8 * Slide mode displays a single image and has a set of controls to navigate
9 * between the images and to edit an image. 9 * between the images and to edit an image.
10 * 10 *
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 util.createChild(this.container_, 'tool slideshow-toolbar'); 190 util.createChild(this.container_, 'tool slideshow-toolbar');
191 util.createChild(slideShowToolbar, 'slideshow-play'). 191 util.createChild(slideShowToolbar, 'slideshow-play').
192 addEventListener('click', this.toggleSlideshowPause_.bind(this)); 192 addEventListener('click', this.toggleSlideshowPause_.bind(this));
193 util.createChild(slideShowToolbar, 'slideshow-end'). 193 util.createChild(slideShowToolbar, 'slideshow-end').
194 addEventListener('click', this.stopSlideshow_.bind(this)); 194 addEventListener('click', this.stopSlideshow_.bind(this));
195 195
196 // Editor. 196 // Editor.
197 197
198 this.editButton_ = this.toolbar_.querySelector('button.edit'); 198 this.editButton_ = this.toolbar_.querySelector('button.edit');
199 this.editButton_.title = this.displayStringFunction_('GALLERY_EDIT'); 199 this.editButton_.title = this.displayStringFunction_('GALLERY_EDIT');
200 this.editButton_.setAttribute('disabled', ''); // Disabled by default. 200 this.editButton_.disabled = true; // Disabled by default.
201 this.editButton_.addEventListener('click', this.toggleEditor.bind(this)); 201 this.editButton_.addEventListener('click', this.toggleEditor.bind(this));
202 202
203 this.printButton_ = this.toolbar_.querySelector('button.print'); 203 this.printButton_ = this.toolbar_.querySelector('button.print');
204 this.printButton_.title = this.displayStringFunction_('GALLERY_PRINT'); 204 this.printButton_.title = this.displayStringFunction_('GALLERY_PRINT');
205 this.printButton_.setAttribute('disabled', ''); // Disabled by default. 205 this.printButton_.disabled = true; // Disabled by default.
206 this.printButton_.addEventListener('click', this.print_.bind(this)); 206 this.printButton_.addEventListener('click', this.print_.bind(this));
207 207
208 this.editBarSpacer_ = this.toolbar_.querySelector('.edit-bar-spacer'); 208 this.editBarSpacer_ = this.toolbar_.querySelector('.edit-bar-spacer');
209 this.editBarMain_ = util.createChild(this.editBarSpacer_, 'edit-main'); 209 this.editBarMain_ = util.createChild(this.editBarSpacer_, 'edit-main');
210 210
211 this.editBarMode_ = util.createChild(this.container_, 'edit-modal'); 211 this.editBarMode_ = util.createChild(this.container_, 'edit-modal');
212 this.editBarModeWrapper_ = util.createChild( 212 this.editBarModeWrapper_ = util.createChild(
213 this.editBarMode_, 'edit-modal-wrapper dimmable'); 213 this.editBarMode_, 'edit-modal-wrapper dimmable');
214 this.editBarModeWrapper_.hidden = true; 214 this.editBarModeWrapper_.hidden = true;
215 215
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 347
348 this.viewport_.resetView(); 348 this.viewport_.resetView();
349 if (this.getItemCount_() === 0) { 349 if (this.getItemCount_() === 0) {
350 this.errorBanner_.clear(); 350 this.errorBanner_.clear();
351 commitDone(); 351 commitDone();
352 } else { 352 } else {
353 this.commitItem_(commitDone); 353 this.commitItem_(commitDone);
354 } 354 }
355 355
356 // Disable the slide-mode only buttons when leaving. 356 // Disable the slide-mode only buttons when leaving.
357 this.editButton_.setAttribute('disabled', ''); 357 this.editButton_.disabled = true;
358 this.printButton_.setAttribute('disabled', ''); 358 this.printButton_.disabled = true;
359 359
360 // Disable touch operation. 360 // Disable touch operation.
361 this.touchHandlers_.enabled = false; 361 this.touchHandlers_.enabled = false;
362 }; 362 };
363 363
364 364
365 /** 365 /**
366 * Execute an action when the editor is not busy. 366 * Execute an action when the editor is not busy.
367 * 367 *
368 * @param {function()} action Function to execute. 368 * @param {function()} action Function to execute.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 }; 428 };
429 429
430 /** 430 /**
431 * Selection change handler. 431 * Selection change handler.
432 * 432 *
433 * Commits the current image and displays the newly selected image. 433 * Commits the current image and displays the newly selected image.
434 * @private 434 * @private
435 */ 435 */
436 SlideMode.prototype.onSelection_ = function() { 436 SlideMode.prototype.onSelection_ = function() {
437 if (this.selectionModel_.selectedIndexes.length === 0) 437 if (this.selectionModel_.selectedIndexes.length === 0)
438 return; // Temporary empty selection. 438 return; // Ignore temporary empty selection.
439 439
440 // Forget the saved selection if the user changed the selection manually. 440 // Forget the saved selection if the user changed the selection manually.
441 if (!this.isSlideshowOn_()) 441 if (!this.isSlideshowOn_())
442 this.savedSelection_ = null; 442 this.savedSelection_ = null;
443 443
444 if (this.getSelectedIndex() === this.displayedIndex_) 444 if (this.getSelectedIndex() === this.displayedIndex_)
445 return; // Do not reselect. 445 return; // Do not reselect.
446 446
447 this.commitItem_(this.loadSelectedItem_.bind(this)); 447 this.commitItem_(this.loadSelectedItem_.bind(this));
448 }; 448 };
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 // The next item is now at the same index as the removed one, so we need 574 // The next item is now at the same index as the removed one, so we need
575 // to correct displayIndex_ so that loadSelectedItem_ does not think 575 // to correct displayIndex_ so that loadSelectedItem_ does not think
576 // we are re-selecting the same item (and does right-to-left slide-in 576 // we are re-selecting the same item (and does right-to-left slide-in
577 // animation). 577 // animation).
578 this.displayedIndex_ = event.index - 1; 578 this.displayedIndex_ = event.index - 1;
579 this.select(event.index); 579 this.select(event.index);
580 } else if (this.dataModel_.length) { 580 } else if (this.dataModel_.length) {
581 // Removed item is the rightmost, but there are more items. 581 // Removed item is the rightmost, but there are more items.
582 this.select(event.index - 1); // Select the new last index. 582 this.select(event.index - 1); // Select the new last index.
583 } else { 583 } else {
584 // No items left. Unload the image and show the banner. 584 // No items left. Unload the image, disable edit and print button, and
585 // show the banner.
585 this.commitItem_(function() { 586 this.commitItem_(function() {
586 this.unloadImage_(); 587 this.unloadImage_();
588 this.printButton_.disabled = true;
589 this.editButton_.disabled = true;
587 this.errorBanner_.show('GALLERY_NO_IMAGES'); 590 this.errorBanner_.show('GALLERY_NO_IMAGES');
588 }.bind(this)); 591 }.bind(this));
589 } 592 }
590 }.bind(this), 0); 593 }.bind(this), 0);
591 }; 594 };
592 595
593 /** 596 /**
594 * @param {number} direction -1 for left, 1 for right. 597 * @param {number} direction -1 for left, 1 for right.
595 * @return {number} Next index in the given direction, with wrapping. 598 * @return {number} Next index in the given direction, with wrapping.
596 * @private 599 * @private
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 713
711 var extIndex = entry.name.lastIndexOf('.'); 714 var extIndex = entry.name.lastIndexOf('.');
712 var ext = extIndex < 0 ? '' : 715 var ext = extIndex < 0 ? '' :
713 entry.name.substr(extIndex + 1).toLowerCase(); 716 entry.name.substr(extIndex + 1).toLowerCase();
714 if (ext === 'jpeg') ext = 'jpg'; 717 if (ext === 'jpeg') ext = 'jpg';
715 ImageUtil.metrics.recordEnum( 718 ImageUtil.metrics.recordEnum(
716 ImageUtil.getMetricName('FileType'), ext, ImageUtil.FILE_TYPES); 719 ImageUtil.getMetricName('FileType'), ext, ImageUtil.FILE_TYPES);
717 720
718 // Enable or disable buttons for editing and printing. 721 // Enable or disable buttons for editing and printing.
719 if (error) { 722 if (error) {
720 this.editButton_.setAttribute('disabled', ''); 723 this.editButton_.disabled = true;
721 this.printButton_.setAttribute('disabled', ''); 724 this.printButton_.disabled = true;
722 } else { 725 } else {
723 this.editButton_.removeAttribute('disabled'); 726 this.editButton_.disabled = false;
724 this.printButton_.removeAttribute('disabled'); 727 this.printButton_.disabled = false;
725 } 728 }
726 729
727 // For once edited image, disallow the 'overwrite' setting change. 730 // For once edited image, disallow the 'overwrite' setting change.
728 ImageUtil.setAttribute(this.options_, 'saved', 731 ImageUtil.setAttribute(this.options_, 'saved',
729 !this.getSelectedItem().isOriginal()); 732 !this.getSelectedItem().isOriginal());
730 733
731 chrome.storage.local.get(SlideMode.OVERWRITE_BUBBLE_KEY, 734 chrome.storage.local.get(SlideMode.OVERWRITE_BUBBLE_KEY,
732 function(values) { 735 function(values) {
733 var times = values[SlideMode.OVERWRITE_BUBBLE_KEY] || 0; 736 var times = values[SlideMode.OVERWRITE_BUBBLE_KEY] || 0;
734 if (times < SlideMode.OVERWRITE_BUBBLE_MAX_TIMES) { 737 if (times < SlideMode.OVERWRITE_BUBBLE_MAX_TIMES) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 break; 852 break;
850 } 853 }
851 return true; // Consume all keystrokes in the slideshow mode. 854 return true; // Consume all keystrokes in the slideshow mode.
852 } 855 }
853 856
854 if (this.isEditing() && this.editor_.onKeyDown(event)) 857 if (this.isEditing() && this.editor_.onKeyDown(event))
855 return true; 858 return true;
856 859
857 switch (keyID) { 860 switch (keyID) {
858 case 'Ctrl-U+0050': // Ctrl+'p' prints the current image. 861 case 'Ctrl-U+0050': // Ctrl+'p' prints the current image.
859 if (!this.printButton_.hasAttribute('disabled')) 862 if (!this.printButton_.disabled)
860 this.print_(); 863 this.print_();
861 break; 864 break;
862 865
863 case 'U+0045': // 'e' toggles the editor. 866 case 'U+0045': // 'e' toggles the editor.
864 if (!this.editButton_.hasAttribute('disabled')) 867 if (!this.editButton_.disabled)
865 this.toggleEditor(event); 868 this.toggleEditor(event);
866 break; 869 break;
867 870
868 case 'U+001B': // Escape 871 case 'U+001B': // Escape
869 if (this.isEditing()) { 872 if (this.isEditing()) {
870 this.toggleEditor(event); 873 this.toggleEditor(event);
871 } else if (this.viewport_.isZoomed()) { 874 } else if (this.viewport_.isZoomed()) {
872 this.viewport_.resetView(); 875 this.viewport_.resetView();
873 this.touchHandlers_.stopOperation(); 876 this.touchHandlers_.stopOperation();
874 this.imageView_.applyViewportChange(); 877 this.imageView_.applyViewportChange();
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 TouchHandler.prototype.onMouseWheel_ = function(event) { 1562 TouchHandler.prototype.onMouseWheel_ = function(event) {
1560 var viewport = this.slideMode_.getViewport(); 1563 var viewport = this.slideMode_.getViewport();
1561 if (!this.enabled_ || !viewport.isZoomed()) 1564 if (!this.enabled_ || !viewport.isZoomed())
1562 return; 1565 return;
1563 this.stopOperation(); 1566 this.stopOperation();
1564 viewport.setOffset( 1567 viewport.setOffset(
1565 viewport.getOffsetX() + event.wheelDeltaX, 1568 viewport.getOffsetX() + event.wheelDeltaX,
1566 viewport.getOffsetY() + event.wheelDeltaY); 1569 viewport.getOffsetY() + event.wheelDeltaY);
1567 this.slideMode_.applyViewportChange(); 1570 this.slideMode_.applyViewportChange();
1568 }; 1571 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698