CustomResponderTextView.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2012-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "CustomResponderTextView.h"
  21. #import "StatusNavigationBar.h"
  22. #import "PortraitNavigationController.h"
  23. @implementation CustomResponderTextView
  24. @synthesize overrideNextResponder;
  25. @synthesize pasteImageHandler;
  26. - (UIResponder *)nextResponder {
  27. if (overrideNextResponder != nil)
  28. return overrideNextResponder;
  29. else
  30. return [super nextResponder];
  31. }
  32. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
  33. if (overrideNextResponder != nil)
  34. return NO;
  35. else {
  36. if (action == @selector(paste:) && pasteImageHandler != nil && [UIPasteboard generalPasteboard].image != nil)
  37. return YES;
  38. else if (action == @selector(scanQrCode:))
  39. return YES;
  40. else
  41. return [super canPerformAction:action withSender:sender];
  42. }
  43. }
  44. - (void)paste:(id)sender {
  45. if (pasteImageHandler != nil && [UIPasteboard generalPasteboard].image != nil) {
  46. [pasteImageHandler handlePasteImage];
  47. } else {
  48. [super paste:sender];
  49. }
  50. }
  51. - (void)scanQrCode:(id)sender {
  52. QRScannerViewController *qrController = [[QRScannerViewController alloc] init];
  53. qrController.delegate = self;
  54. qrController.title = NSLocalizedString(@"scan_qr", nil);
  55. UINavigationController *nav = [[PortraitNavigationController alloc] initWithNavigationBarClass:[StatusNavigationBar class] toolbarClass:nil];
  56. [nav pushViewController:qrController animated:NO];
  57. nav.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  58. [self.window.rootViewController presentViewController:nav animated:YES completion:nil];
  59. }
  60. #pragma mark - QR scanner delegate
  61. - (void)qrScannerViewController:(QRScannerViewController *)controller didScanResult:(NSString *)result {
  62. [self insertText:result];
  63. [controller dismissViewControllerAnimated:YES completion:nil];
  64. }
  65. - (void)qrScannerViewControllerDidCancel:(QRScannerViewController *)controller {
  66. [controller dismissViewControllerAnimated:YES completion:nil];
  67. }
  68. @end