|
@@ -20,20 +20,52 @@ class KMSecondaryPDFView: CPDFView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- var synchronizedPDFView: CPDFView?
|
|
|
+ private var _synchronizedPDFView: CPDFView?
|
|
|
+ var synchronizedPDFView: CPDFView? {
|
|
|
+ get {
|
|
|
+ return self._synchronizedPDFView
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ if self._synchronizedPDFView != newValue {
|
|
|
+ if self.synchronizeZoom {
|
|
|
+ self._stopObservingSynchronizedPDFView()
|
|
|
+ }
|
|
|
+ self._synchronizedPDFView = newValue
|
|
|
+ if self.synchronizeZoom {
|
|
|
+ self._startObservingSynchronizedPDFView()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
var synchronizeZoom = false
|
|
|
var switching = false
|
|
|
- var selectsText = false
|
|
|
+ private var _selectsText = false
|
|
|
+ var selectsText: Bool {
|
|
|
+ get {
|
|
|
+ return self._selectsText
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ if self._selectsText != newValue {
|
|
|
+ self._selectsText = newValue
|
|
|
+ if newValue == false {
|
|
|
+// [self setCurrentSelection:RUNNING_AFTER(10_11) ? [[[PDFSelection alloc] initWithDocument:[self document]] autorelease] : nil];
|
|
|
+ self.currentSelection = CPDFSelection(document: self.document)
|
|
|
+ }
|
|
|
+ self.toolModeButton?.state = self.selectsText ? .on : .off
|
|
|
+// [[NSUserDefaults standardUserDefaults] setBool:selectsText forKey:SKLastSecondarySelectsTextKey];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
var startScale: CGFloat = 0.0
|
|
|
|
|
|
|
|
|
private var SKDefaultScaleMenuLabels = ["=", "Auto", "10%", "20%", "25%", "35%", "50%", "60%", "71%", "85%", "100%", "120%", "141%", "170%", "200%", "300%", "400%", "600%", "800%", "1000%", "1200%", "1400%", "1700%", "2000%"]
|
|
|
private var SKDefaultScaleMenuFactors = [0.0, 0.0, 0.1, 0.2, 0.25, 0.35, 0.5, 0.6, 0.71, 0.85, 1.0, 1.2, 1.41, 1.7, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 17.0, 20.0]
|
|
|
-
|
|
|
|
|
|
// #define SKMinDefaultScaleMenuFactor (SKDefaultScaleMenuFactors[2])
|
|
|
private var SKMinDefaultScaleMenuFactor = 0.1
|
|
|
-// #define SKDefaultScaleMenuFactorsCount (sizeof(SKDefaultScaleMenuFactors) / sizeof(CGFloat))
|
|
|
private var SKDefaultScaleMenuFactorsCount = 24
|
|
|
|
|
|
|
|
@@ -47,6 +79,12 @@ class KMSecondaryPDFView: CPDFView {
|
|
|
// Drawing code here.
|
|
|
}
|
|
|
|
|
|
+ deinit {
|
|
|
+ KMPrint("KMSecondaryPDFView deinit.")
|
|
|
+
|
|
|
+ NotificationCenter.default.removeObserver(self)
|
|
|
+ }
|
|
|
+
|
|
|
override init(frame frameRect: NSRect) {
|
|
|
super.init(frame: frameRect)
|
|
|
|
|
@@ -67,14 +105,12 @@ class KMSecondaryPDFView: CPDFView {
|
|
|
self.synchronizedPDFView = nil
|
|
|
self.synchronizeZoom = false
|
|
|
// self.selectsText = [[NSUserDefaults standardUserDefaults] boolForKey:SKLastSecondarySelectsTextKey];
|
|
|
-// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePageChangedNotification:)
|
|
|
-// name:PDFViewPageChangedNotification object:self];
|
|
|
+
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(handlePageChangedNotification), name: NSNotification.Name.CPDFViewPageChanged, object: self)
|
|
|
// if ([PDFView instancesRespondToSelector:@selector(magnifyWithEvent:)] == NO || [PDFView instanceMethodForSelector:@selector(magnifyWithEvent:)] == [NSView instanceMethodForSelector:@selector(magnifyWithEvent:)])
|
|
|
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePDFViewScaleChangedNotification:)
|
|
|
// name:PDFViewScaleChangedNotification object:self];
|
|
|
-// [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
|
|
|
-
|
|
|
-
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
|
|
|
}
|
|
|
|
|
|
private func _initControlView() {
|
|
@@ -129,8 +165,8 @@ class KMSecondaryPDFView: CPDFView {
|
|
|
self.scalePopUpButton?.refusesFirstResponder = true
|
|
|
|
|
|
// hook it up
|
|
|
-// [scalePopUpButton setTarget:self];
|
|
|
-// [scalePopUpButton setAction:@selector(scalePopUpAction:)];
|
|
|
+ self.scalePopUpButton?.target = self
|
|
|
+ self.scalePopUpButton?.action = #selector(scalePopUpAction)
|
|
|
}
|
|
|
|
|
|
if (self.pagePopUpButton == nil) {
|
|
@@ -145,15 +181,14 @@ class KMSecondaryPDFView: CPDFView {
|
|
|
// set a suitable font, the control size is 0, 1 or 2
|
|
|
self.pagePopUpButton?.font = .toolTipsFont(ofSize: CONTROL_FONT_SIZE)
|
|
|
|
|
|
-// [self reloadPagePopUpButton];
|
|
|
+ self.reloadPagePopUpButton()
|
|
|
|
|
|
// don't let it become first responder
|
|
|
self.pagePopUpButton?.refusesFirstResponder = true
|
|
|
|
|
|
// hook it up
|
|
|
-// [pagePopUpButton setTarget:self];
|
|
|
-// [pagePopUpButton setAction:@selector(pagePopUpAction:)];
|
|
|
-
|
|
|
+ self.pagePopUpButton?.target = self
|
|
|
+ self.pagePopUpButton?.action = #selector(pagePopUpAction)
|
|
|
}
|
|
|
|
|
|
if (self.toolModeButton == nil) {
|
|
@@ -163,15 +198,16 @@ class KMSecondaryPDFView: CPDFView {
|
|
|
self.toolModeButton?.setButtonType(.onOff)
|
|
|
self.toolModeButton?.bezelStyle = .texturedSquare
|
|
|
// self.toolModeButton?.image = NSImage(named: SKImageNameTextToolAdorn)
|
|
|
+ self.toolModeButton?.image = NSImage(named: "TextToolAdorn")
|
|
|
|
|
|
-// self.toolModeButton?.state = self.selectsText
|
|
|
+ self.toolModeButton?.state = self.selectsText ? .on : .off
|
|
|
|
|
|
// don't let it become first responder
|
|
|
self.toolModeButton?.refusesFirstResponder = true
|
|
|
|
|
|
// hook it up
|
|
|
-// [toolModeButton setTarget:self];
|
|
|
-// [toolModeButton setAction:@selector(toolModeButtonAction:)];
|
|
|
+ self.toolModeButton?.target = self
|
|
|
+ self.toolModeButton?.action = #selector(toolModeButtonAction)
|
|
|
}
|
|
|
|
|
|
if (self._controlView == nil) {
|
|
@@ -207,371 +243,233 @@ class KMSecondaryPDFView: CPDFView {
|
|
|
super.autoScales = false
|
|
|
}
|
|
|
super.scaleFactor = self.synchronizedPDFView != nil ? self.synchronizedPDFView!.scaleFactor : 1.0
|
|
|
-// [self startObservingSynchronizedPDFView];
|
|
|
+ self._startObservingSynchronizedPDFView()
|
|
|
if (flag) {
|
|
|
self.scalePopUpButton?.selectItem(at: 0)
|
|
|
}
|
|
|
} else {
|
|
|
-// [self stopObservingSynchronizedPDFView];
|
|
|
-// [self setScaleFactor:[self scaleFactor] adjustPopup:flag];
|
|
|
+ self._stopObservingSynchronizedPDFView()
|
|
|
+ self.setScaleFactor(self.scaleFactor, adjustPopup: flag)
|
|
|
}
|
|
|
self.switching = savedSwitching
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- static NSString *SKDefaultScaleMenuLabels[] = {@"=", @"Auto", @"10%", @"20%", @"25%", @"35%", @"50%", @"60%", @"71%", @"85%", @"100%", @"120%", @"141%", @"170%", @"200%", @"300%", @"400%", @"600%", @"800%", @"1000%", @"1200%", @"1400%", @"1700%", @"2000%"};
|
|
|
- static CGFloat SKDefaultScaleMenuFactors[] = {0.0, 0.0, 0.1, 0.2, 0.25, 0.35, 0.5, 0.6, 0.71, 0.85, 1.0, 1.2, 1.41, 1.7, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 17.0, 20.0};
|
|
|
-
|
|
|
- #define SKMinDefaultScaleMenuFactor (SKDefaultScaleMenuFactors[2])
|
|
|
- #define SKDefaultScaleMenuFactorsCount (sizeof(SKDefaultScaleMenuFactors) / sizeof(CGFloat))
|
|
|
-
|
|
|
- #define CONTROL_FONT_SIZE 10.0
|
|
|
- #define CONTROL_HEIGHT 15.0
|
|
|
- #define CONTROL_WIDTH_OFFSET 20.0
|
|
|
-
|
|
|
- - (void)commonInitialization {
|
|
|
- scalePopUpButton = nil;
|
|
|
- pagePopUpButton = nil;
|
|
|
- synchronizedPDFView = nil;
|
|
|
- synchronizeZoom = NO;
|
|
|
- selectsText = [[NSUserDefaults standardUserDefaults] boolForKey:SKLastSecondarySelectsTextKey];
|
|
|
-
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePageChangedNotification:)
|
|
|
- name:PDFViewPageChangedNotification object:self];
|
|
|
- if ([PDFView instancesRespondToSelector:@selector(magnifyWithEvent:)] == NO || [PDFView instanceMethodForSelector:@selector(magnifyWithEvent:)] == [NSView instanceMethodForSelector:@selector(magnifyWithEvent:)])
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePDFViewScaleChangedNotification:)
|
|
|
- name:PDFViewScaleChangedNotification object:self];
|
|
|
- [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
|
|
|
- }
|
|
|
-
|
|
|
- - (void)themeChanged:(NSNotification *)notification {
|
|
|
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
- [self updateViewColor];
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- - (id)initWithFrame:(NSRect)frameRect {
|
|
|
- self = [super initWithFrame:frameRect];
|
|
|
- if (self) {
|
|
|
- [self commonInitialization];
|
|
|
- }
|
|
|
- return self;
|
|
|
- }
|
|
|
-
|
|
|
- - (id)initWithCoder:(NSCoder *)decoder {
|
|
|
- self = [super initWithCoder:decoder];
|
|
|
- if (self) {
|
|
|
- [self commonInitialization];
|
|
|
- }
|
|
|
- return self;
|
|
|
- }
|
|
|
-
|
|
|
- - (void)dealloc {
|
|
|
- [[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
- SKDESTROY(synchronizedPDFView);
|
|
|
- SKDESTROY(scalePopUpButton);
|
|
|
- SKDESTROY(pagePopUpButton);
|
|
|
- SKDESTROY(toolModeButton);
|
|
|
- SKDESTROY(controlView);
|
|
|
- [super dealloc];
|
|
|
- }
|
|
|
-
|
|
|
- - (void)setDocument:(PDFDocument *)document {
|
|
|
- if ([self document])
|
|
|
- [[NSNotificationCenter defaultCenter] removeObserver:self name:PDFDocumentDidUnlockNotification object:[self document]];
|
|
|
- [super setDocument:document];
|
|
|
- [self reloadPagePopUpButton];
|
|
|
- if (document && [document isLocked])
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleDocumentDidUnlockNotification:)
|
|
|
- name:PDFDocumentDidUnlockNotification object:document];
|
|
|
- }
|
|
|
-
|
|
|
- - (void)updateViewColor {
|
|
|
- self.controlView.wantsLayer = YES;
|
|
|
- if([KMAppearance isDarkMode]){
|
|
|
- self.controlView.layer.backgroundColor = [NSColor colorWithRed:37/255. green:37/255. blue:38/255. alpha:1].CGColor;
|
|
|
- } else {
|
|
|
- self.controlView.layer.backgroundColor = [NSColor colorWithRed:250/255. green:250/255. blue:250/255. alpha:1].CGColor;
|
|
|
- }
|
|
|
- self.controlView.layer.backgroundColor = [KMAppearance KMColor_Layout_L0].CGColor;
|
|
|
- }
|
|
|
-
|
|
|
- #pragma mark Popup buttons
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- - (void)reloadPagePopUpButton {
|
|
|
- NSArray *labels = [[self document] pageLabels];
|
|
|
- NSUInteger count = [pagePopUpButton numberOfItems];
|
|
|
- NSSize size = NSMakeSize(1000.0, 1000.0);
|
|
|
- NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:[pagePopUpButton font], NSFontAttributeName, nil];
|
|
|
- __block CGFloat maxWidth = 0.0;
|
|
|
- __block NSUInteger maxIndex = 0;
|
|
|
-
|
|
|
- while (count--)
|
|
|
- [pagePopUpButton removeItemAtIndex:count];
|
|
|
-
|
|
|
- if ([labels count] > 0) {
|
|
|
- [labels enumerateObjectsUsingBlock:^(id label, NSUInteger i, BOOL *stop) {
|
|
|
- CGFloat width = NSWidth([label boundingRectWithSize:size options:0 attributes:attrs]);
|
|
|
- if (width > maxWidth) {
|
|
|
- maxWidth = width;
|
|
|
- maxIndex = i;
|
|
|
- }
|
|
|
- [pagePopUpButton addItemWithTitle:label];
|
|
|
- }];
|
|
|
-
|
|
|
- sizePopUpToItemAtIndex(pagePopUpButton, maxIndex);
|
|
|
-
|
|
|
- [pagePopUpButton selectItemAtIndex:[[self currentPage] pageIndex]];
|
|
|
-
|
|
|
- if (controlView)
|
|
|
- [controlView setFrameSize:NSMakeSize(NSWidth([toolModeButton frame]) + NSWidth([pagePopUpButton frame]) + NSWidth([scalePopUpButton frame]), NSHeight([controlView frame]))];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- - (NSView *)controlView {
|
|
|
-
|
|
|
- if (scalePopUpButton == nil) {
|
|
|
-
|
|
|
- // create it
|
|
|
- scalePopUpButton = [[NSPopUpButton allocWithZone:[self zone]] initWithFrame:NSMakeRect(0.0, 0.0, 1.0, 1.0) pullsDown:NO];
|
|
|
-
|
|
|
- [[scalePopUpButton cell] setControlSize:NSSmallControlSize];
|
|
|
- [scalePopUpButton setBordered:NO];
|
|
|
- [scalePopUpButton setEnabled:YES];
|
|
|
- [scalePopUpButton setRefusesFirstResponder:YES];
|
|
|
- [[scalePopUpButton cell] setUsesItemFromMenu:YES];
|
|
|
-
|
|
|
- // set a suitable font, the control size is 0, 1 or 2
|
|
|
- [scalePopUpButton setFont:[NSFont toolTipsFontOfSize:CONTROL_FONT_SIZE]];
|
|
|
-
|
|
|
- NSUInteger cnt, numberOfDefaultItems = SKDefaultScaleMenuFactorsCount;
|
|
|
- id curItem;
|
|
|
- NSString *label;
|
|
|
- CGFloat width, maxWidth = 0.0;
|
|
|
- NSSize size = NSMakeSize(1000.0, 1000.0);
|
|
|
- NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:[scalePopUpButton font], NSFontAttributeName, nil];
|
|
|
- NSUInteger maxIndex = 0;
|
|
|
-
|
|
|
- // fill it
|
|
|
- for (cnt = 0; cnt < numberOfDefaultItems; cnt++) {
|
|
|
- label = [[NSBundle mainBundle] localizedStringForKey:SKDefaultScaleMenuLabels[cnt] value:@"" table:@"ZoomValues"];
|
|
|
- width = NSWidth([label boundingRectWithSize:size options:0 attributes:attrs]);
|
|
|
- if (width > maxWidth) {
|
|
|
- maxWidth = width;
|
|
|
- maxIndex = cnt;
|
|
|
- }
|
|
|
- [scalePopUpButton addItemWithTitle:label];
|
|
|
- curItem = [scalePopUpButton itemAtIndex:cnt];
|
|
|
- [curItem setRepresentedObject:(SKDefaultScaleMenuFactors[cnt] > 0.0 ? [NSNumber numberWithDouble:SKDefaultScaleMenuFactors[cnt]] : nil)];
|
|
|
- }
|
|
|
- // select the appropriate item, adjusting the scaleFactor if necessary
|
|
|
- if([self synchronizeZoom])
|
|
|
- [self setSynchronizeZoom:YES adjustPopup:YES];
|
|
|
- else if([self autoScales])
|
|
|
- [self setScaleFactor:0.0 adjustPopup:YES];
|
|
|
- else
|
|
|
- [self setScaleFactor:[self scaleFactor] adjustPopup:YES];
|
|
|
-
|
|
|
- // Make sure the popup is big enough to fit the largest cell
|
|
|
- sizePopUpToItemAtIndex(scalePopUpButton, maxIndex);
|
|
|
-
|
|
|
- // don't let it become first responder
|
|
|
- [scalePopUpButton setRefusesFirstResponder:YES];
|
|
|
-
|
|
|
- // hook it up
|
|
|
- [scalePopUpButton setTarget:self];
|
|
|
- [scalePopUpButton setAction:@selector(scalePopUpAction:)];
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if (pagePopUpButton == nil) {
|
|
|
-
|
|
|
- // create it
|
|
|
- pagePopUpButton = [[NSPopUpButton allocWithZone:[self zone]] initWithFrame:NSMakeRect(0.0, 0.0, 1.0, 1.0) pullsDown:NO];
|
|
|
-
|
|
|
- [[pagePopUpButton cell] setControlSize:NSSmallControlSize];
|
|
|
- [pagePopUpButton setBordered:NO];
|
|
|
- [pagePopUpButton setEnabled:YES];
|
|
|
- [pagePopUpButton setRefusesFirstResponder:YES];
|
|
|
- [[pagePopUpButton cell] setUsesItemFromMenu:YES];
|
|
|
-
|
|
|
- // set a suitable font, the control size is 0, 1 or 2
|
|
|
- [pagePopUpButton setFont:[NSFont toolTipsFontOfSize:CONTROL_FONT_SIZE]];
|
|
|
-
|
|
|
- [self reloadPagePopUpButton];
|
|
|
-
|
|
|
- // don't let it become first responder
|
|
|
- [pagePopUpButton setRefusesFirstResponder:YES];
|
|
|
-
|
|
|
- // hook it up
|
|
|
- [pagePopUpButton setTarget:self];
|
|
|
- [pagePopUpButton setAction:@selector(pagePopUpAction:)];
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if (toolModeButton == nil) {
|
|
|
-
|
|
|
- // create it
|
|
|
- toolModeButton = [[NSButton alloc] initWithFrame:NSMakeRect(0.0, 0.0, 17.0, 15.0)];
|
|
|
-
|
|
|
- [toolModeButton setButtonType:NSOnOffButton];
|
|
|
- [toolModeButton setBezelStyle:NSBezelStyleTexturedSquare];
|
|
|
- [toolModeButton setImage:[NSImage imageNamed:SKImageNameTextToolAdorn]];
|
|
|
-
|
|
|
- [toolModeButton setState:[self selectsText]];
|
|
|
-
|
|
|
- // don't let it become first responder
|
|
|
- [toolModeButton setRefusesFirstResponder:YES];
|
|
|
-
|
|
|
- // hook it up
|
|
|
- [toolModeButton setTarget:self];
|
|
|
- [toolModeButton setAction:@selector(toolModeButtonAction:)];
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if (controlView == nil) {
|
|
|
-
|
|
|
- NSRect toolRect = [toolModeButton frame], pageRect = [pagePopUpButton frame], scaleRect = [scalePopUpButton frame], tmpRect;
|
|
|
-
|
|
|
- controlView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, NSWidth(toolRect) + NSWidth(pageRect) + NSWidth(scaleRect), CONTROL_HEIGHT)];
|
|
|
-
|
|
|
- [toolModeButton setAutoresizingMask:NSViewMaxXMargin | NSViewMaxYMargin];
|
|
|
- [pagePopUpButton setAutoresizingMask:NSViewMaxXMargin | NSViewMaxYMargin];
|
|
|
- [scalePopUpButton setAutoresizingMask:NSViewMinXMargin | NSViewMaxYMargin];
|
|
|
- NSDivideRect([controlView bounds], &toolRect, &tmpRect, NSWidth(toolRect), NSMinXEdge);
|
|
|
- NSDivideRect(tmpRect, &pageRect, &scaleRect, NSWidth(pageRect), NSMinXEdge);
|
|
|
- [toolModeButton setFrame:toolRect];
|
|
|
- [pagePopUpButton setFrame:pageRect];
|
|
|
- [scalePopUpButton setFrame:scaleRect];
|
|
|
- [controlView addSubview:toolModeButton];
|
|
|
- [controlView addSubview:pagePopUpButton];
|
|
|
- [controlView addSubview:scalePopUpButton];
|
|
|
- controlView.wantsLayer = YES;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return controlView;
|
|
|
- }
|
|
|
-
|
|
|
- - (void)scalePopUpAction:(id)sender {
|
|
|
- NSNumber *selectedFactorObject = [[sender selectedItem] representedObject];
|
|
|
- if (selectedFactorObject)
|
|
|
- [self setScaleFactor:[selectedFactorObject doubleValue] adjustPopup:NO];
|
|
|
- else if ([sender indexOfSelectedItem] == 0)
|
|
|
- [self setSynchronizeZoom:YES adjustPopup:NO];
|
|
|
- else
|
|
|
- [self setAutoScales:YES adjustPopup:NO];
|
|
|
- }
|
|
|
-
|
|
|
- - (void)pagePopUpAction:(id)sender {
|
|
|
- [self goToPage:[[self document] pageAtIndex:[sender indexOfSelectedItem]]];
|
|
|
- }
|
|
|
-
|
|
|
- - (void)toolModeButtonAction:(id)sender {
|
|
|
- [self setSelectsText:[(NSButton *)sender state]];
|
|
|
- }
|
|
|
-
|
|
|
- - (void)setSynchronizedPDFView:(PDFView *)newSynchronizedPDFView {
|
|
|
- if (synchronizedPDFView != newSynchronizedPDFView) {
|
|
|
- if ([self synchronizeZoom])
|
|
|
- [self stopObservingSynchronizedPDFView];
|
|
|
- [synchronizedPDFView release];
|
|
|
- synchronizedPDFView = [newSynchronizedPDFView retain];
|
|
|
- if ([self synchronizeZoom])
|
|
|
- [self startObservingSynchronizedPDFView];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- - (void)setSynchronizeZoom:(BOOL)newSync {
|
|
|
- [self setSynchronizeZoom:newSync adjustPopup:YES];
|
|
|
- }
|
|
|
-
|
|
|
- - (void)setSynchronizeZoom:(BOOL)newSync adjustPopup:(BOOL)flag {
|
|
|
- if (synchronizeZoom != newSync) {
|
|
|
- BOOL savedSwitching = switching;
|
|
|
- switching = YES;
|
|
|
- synchronizeZoom = newSync;
|
|
|
- if (newSync) {
|
|
|
- if ([self autoScales])
|
|
|
- [super setAutoScales:NO];
|
|
|
- [super setScaleFactor:synchronizedPDFView ? [synchronizedPDFView scaleFactor] : 1.0];
|
|
|
- [self startObservingSynchronizedPDFView];
|
|
|
- if (flag)
|
|
|
- [scalePopUpButton selectItemAtIndex:0];
|
|
|
- } else {
|
|
|
- [self stopObservingSynchronizedPDFView];
|
|
|
- [self setScaleFactor:[self scaleFactor] adjustPopup:flag];
|
|
|
- }
|
|
|
- switching = savedSwitching;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- - (void)setSelectsText:(BOOL)newSelectsText {
|
|
|
- if (newSelectsText != selectsText) {
|
|
|
- selectsText = newSelectsText;
|
|
|
- if (selectsText == NO)
|
|
|
- [self setCurrentSelection:RUNNING_AFTER(10_11) ? [[[PDFSelection alloc] initWithDocument:[self document]] autorelease] : nil];
|
|
|
- [toolModeButton setState:selectsText ? NSOnState : NSOffState];
|
|
|
- [[NSUserDefaults standardUserDefaults] setBool:selectsText forKey:SKLastSecondarySelectsTextKey];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- - (IBAction)zoomIn:(id)sender{
|
|
|
- NSUInteger numberOfDefaultItems = SKDefaultScaleMenuFactorsCount;
|
|
|
- NSUInteger i = [self lowerIndexForScaleFactor:[self scaleFactor]];
|
|
|
- if (i < numberOfDefaultItems - 1) i++;
|
|
|
- [self setScaleFactor:SKDefaultScaleMenuFactors[i] adjustPopup:YES];
|
|
|
- }
|
|
|
-
|
|
|
- - (IBAction)zoomOut:(id)sender{
|
|
|
- NSUInteger i = [self upperIndexForScaleFactor:[self scaleFactor]];
|
|
|
- if (i > 2) i--;
|
|
|
- [self setScaleFactor:SKDefaultScaleMenuFactors[i] adjustPopup:YES];
|
|
|
- }
|
|
|
-
|
|
|
- - (BOOL)canZoomIn{
|
|
|
- if ([super canZoomIn] == NO)
|
|
|
- return NO;
|
|
|
- NSUInteger numberOfDefaultItems = SKDefaultScaleMenuFactorsCount;
|
|
|
- NSUInteger i = [self lowerIndexForScaleFactor:[self scaleFactor]];
|
|
|
- return i < numberOfDefaultItems - 1;
|
|
|
- }
|
|
|
-
|
|
|
- - (BOOL)canZoomOut{
|
|
|
- if ([super canZoomOut] == NO)
|
|
|
- return NO;
|
|
|
- NSUInteger i = [self upperIndexForScaleFactor:[self scaleFactor]];
|
|
|
- return i > 2;
|
|
|
- }
|
|
|
-
|
|
|
- - (BOOL)performKeyEquivalent:(NSEvent *)theEvent { return NO; }
|
|
|
-
|
|
|
- - (IBAction)toggleDisplayAsBookFromMenu:(id)sender {
|
|
|
- [self setDisplaysAsBook:[self displaysAsBook] == NO];
|
|
|
- }
|
|
|
+ @objc func themeChanged(_ notification: Notification) {
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
+ self.updateViewColor()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override var document: CPDFDocument! {
|
|
|
+ get {
|
|
|
+ return super.document
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ if super.document != nil {
|
|
|
+ NotificationCenter.default.removeObserver(self, name: NSNotification.Name.CPDFDocumentDidUnlock, object: self.document)
|
|
|
+ }
|
|
|
+ super.document = newValue
|
|
|
+ self.reloadPagePopUpButton()
|
|
|
+
|
|
|
+ if newValue != nil && newValue.isLocked {
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(handleDocumentDidUnlockNotification), name: NSNotification.Name.CPDFDocumentDidUnlock, object: newValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func updateViewColor() {
|
|
|
+ self.controlView?.wantsLayer = true
|
|
|
+ if KMAppearance.isDarkMode() {
|
|
|
+ self.controlView?.layer?.backgroundColor = NSColor(red: 37/255.0, green: 37/255.0, blue: 38/255.0, alpha: 1).cgColor
|
|
|
+ } else {
|
|
|
+ self.controlView?.layer?.backgroundColor = NSColor(red: 250/255.0, green: 250/255.0, blue: 250/255.0, alpha: 1).cgColor
|
|
|
+ }
|
|
|
+ self.controlView?.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: - Popup buttons
|
|
|
+
|
|
|
+ func reloadPagePopUpButton() {
|
|
|
+ let labels = self.document?.pageLabels() ?? []
|
|
|
+ var count = self.pagePopUpButton?.numberOfItems ?? 0
|
|
|
+ var size = NSMakeSize(1000, 1000)
|
|
|
+ var attrs = [NSAttributedString.Key.font : self.pagePopUpButton?.font ?? NSFont.toolTipsFont(ofSize: CONTROL_FONT_SIZE)]
|
|
|
+ var maxWidth = 0.0
|
|
|
+ var maxIndex = 0
|
|
|
+
|
|
|
+// while (count--)
|
|
|
+// [pagePopUpButton removeItemAtIndex:count];
|
|
|
+ while count > 0 {
|
|
|
+ count -= 1
|
|
|
+ self.pagePopUpButton?.removeItem(at: count)
|
|
|
+ }
|
|
|
+
|
|
|
+ if labels.count > 0 {
|
|
|
+ for (i, label) in labels.enumerated() {
|
|
|
+ var width = NSWidth(label.boundingRect(with: size, options: NSString.DrawingOptions(rawValue: 0), attributes: attrs))
|
|
|
+ if (width > maxWidth) {
|
|
|
+ maxWidth = width;
|
|
|
+ maxIndex = i
|
|
|
+ }
|
|
|
+ self.pagePopUpButton?.addItem(withTitle: label)
|
|
|
+ }
|
|
|
+
|
|
|
+ self.sizePopUpToItemAtIndex(self.pagePopUpButton, anIndex: UInt(maxIndex))
|
|
|
+ self.pagePopUpButton?.selectItem(at: self.currentPageIndex)
|
|
|
+ if (self.controlView != nil) {
|
|
|
+ // [controlView setFrameSize:NSMakeSize(NSWidth([toolModeButton frame]) + NSWidth([pagePopUpButton frame]) + NSWidth([scalePopUpButton frame]), NSHeight([controlView frame]))];
|
|
|
+ let w = NSWidth(self.toolModeButton?.frame ?? .zero) + NSWidth(self.pagePopUpButton?.frame ?? .zero) + NSWidth(self.scalePopUpButton?.frame ?? .zero)
|
|
|
+ let h = NSHeight(self.controlView?.frame ?? .zero)
|
|
|
+ self.controlView?.setFrameSize(NSMakeSize(w, h))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- - (IBAction)toggleDisplayPageBreaksFromMenu:(id)sender {
|
|
|
- [self setDisplaysPageBreaks:[self displaysPageBreaks] == NO];
|
|
|
+ @objc func scalePopUpAction(_ sender: NSPopUpButton) {
|
|
|
+ let selectedFactorObject = sender.selectedItem?.representedObject
|
|
|
+ if (selectedFactorObject != nil) {
|
|
|
+ self.setScaleFactor(selectedFactorObject as! CGFloat, adjustPopup: false)
|
|
|
+ } else if (sender.indexOfSelectedItem == 0) {
|
|
|
+ self.setSynchronizeZoom(true, adjustPopup: false)
|
|
|
+ } else {
|
|
|
+ self.setAutoScales(true, adjustPopup: false)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- - (void)doActualSize:(id)sender {
|
|
|
- [self setScaleFactor:1.0];
|
|
|
+ @objc func pagePopUpAction(_ sender: NSPopUpButton) {
|
|
|
+ self.go(toPageIndex: sender.indexOfSelectedItem, animated: false)
|
|
|
}
|
|
|
|
|
|
- - (void)doPhysicalSize:(id)sender {
|
|
|
- [self setPhysicalScaleFactor:1.0];
|
|
|
+ @objc func toolModeButtonAction(_ sender: NSButton) {
|
|
|
+ self.selectsText = sender.state == .on
|
|
|
}
|
|
|
+
|
|
|
+ override var canZoomIn: Bool {
|
|
|
+ if super.canZoomIn == false {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ let numberOfDefaultItems = SKDefaultScaleMenuFactorsCount
|
|
|
+ let i = self.lowerIndex(for: self.scaleFactor)
|
|
|
+ return i < numberOfDefaultItems - 1
|
|
|
+ }
|
|
|
+
|
|
|
+ override func zoomIn(_ sender: Any!) {
|
|
|
+ let numberOfDefaultItems = SKDefaultScaleMenuFactorsCount
|
|
|
+ var i = self.lowerIndex(for: self.scaleFactor)
|
|
|
+ if i < numberOfDefaultItems-1 {
|
|
|
+ i += 1
|
|
|
+ }
|
|
|
+ self.setScaleFactor(SKDefaultScaleMenuFactors[Int(i)], adjustPopup: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ override var canZoomOut: Bool {
|
|
|
+ if super.canZoomOut == false {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ let i = self.upperIndex(for: self.scaleFactor)
|
|
|
+ return i > 2
|
|
|
+ }
|
|
|
+
|
|
|
+ override func zoomOut(_ sender: Any!) {
|
|
|
+ var i = self.upperIndex(for: self.scaleFactor)
|
|
|
+ if i > 2 {
|
|
|
+ i -= 1
|
|
|
+ }
|
|
|
+ self.setScaleFactor(SKDefaultScaleMenuFactors[Int(i)], adjustPopup: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ override func performKeyEquivalent(with event: NSEvent) -> Bool {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func toggleDisplayAsBookFromMenu(_ sender: AnyObject?) {
|
|
|
+ self.displaysAsBook = !self.displaysAsBook
|
|
|
+ }
|
|
|
+
|
|
|
+ @IBAction func toggleDisplayPageBreaksFromMenu(_ sender: AnyObject?) {
|
|
|
+ self.displaysPageBreaks = !self.displaysPageBreaks
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func doActualSize(_ sender: AnyObject?) {
|
|
|
+ self.scaleFactor = 1.0
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func doPhysicalSize(_ sender: AnyObject?) {
|
|
|
+// [self setPhysicalScaleFactor:1.0];
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func changeToolMode(_ sender: NSMenuItem?) {
|
|
|
+ self.selectsText = ((sender?.tag ?? 0) == 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ override func menu(for event: NSEvent) -> NSMenu? {
|
|
|
+// static NSSet *selectionActions = nil;
|
|
|
+// if (selectionActions == nil)
|
|
|
+// selectionActions = [[NSSet alloc] initWithObjects:@"copy:", @":", @":", @":", @":", nil];
|
|
|
+ var selectionActions = ["copy:", "_searchInSpotlight:", "_searchInGoogle:", "_searchInDictionary:", "_revealSelection:"]
|
|
|
+ var menu = super.menu(for: event)
|
|
|
+ var item: NSMenuItem?
|
|
|
+
|
|
|
+ if self.selectsText == false {
|
|
|
+ self.currentSelection = CPDFSelection(document: self.document)
|
|
|
+ while let cnt = menu?.numberOfItems, cnt > 0 {
|
|
|
+// while ([menu numberOfItems]) {
|
|
|
+// item = [menu itemAtIndex:0];
|
|
|
+ item = menu?.item(at: 0)
|
|
|
+ if item!.isSeparatorItem || selectionActions.contains(NSStringFromSelector(item!.action!)) {
|
|
|
+ // if ([item isSeparatorItem] || [self validateMenuItem:item] == NO || [selectionActions containsObject:NSStringFromSelector([item action])])
|
|
|
+ // [menu removeItemAtIndex:0];
|
|
|
+ menu?.removeItem(at: 0)
|
|
|
+ } else {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var i = menu?.indexOfItem(withTarget: self, andAction: NSSelectorFromString("_setDoublePageScrolling:"))
|
|
|
+ if (i == -1) {
|
|
|
+ i = menu?.indexOfItem(withTarget: self, andAction: NSSelectorFromString("_toggleContinuous:"))
|
|
|
+ }
|
|
|
+ if let data = i, data != -1 {
|
|
|
+// var displayMode = self.displayViewMode()
|
|
|
+// [menu insertItem:[NSMenuItem separatorItem] atIndex:++i];
|
|
|
+ i! += 1
|
|
|
+ menu?.insertItem(.separator(), at: i!)
|
|
|
+// if (displayMode == kPDFDisplayTwoUp || displayMode == kPDFDisplayTwoUpContinuous) {
|
|
|
+// item = [menu insertItemWithTitle:NSLocalizedString(@"Book Mode", @"Menu item title") action:@selector(toggleDisplayAsBookFromMenu:) keyEquivalent:@"" atIndex:++i];
|
|
|
+// [item setTarget:self];
|
|
|
+// }
|
|
|
+// item = [menu insertItemWithTitle:NSLocalizedString(@"Page Breaks", @"Menu item title") action:@selector(toggleDisplayPageBreaksFromMenu:) keyEquivalent:@"" atIndex:++i];
|
|
|
+ i! += 1
|
|
|
+ item = menu?.insertItem(withTitle: KMLocalizedString("Page Breaks", "Menu item title"), action: #selector(toggleDisplayPageBreaksFromMenu), target: self, at: i!)
|
|
|
+ }
|
|
|
+
|
|
|
+ i = menu?.indexOfItem(withTarget: self, andAction: NSSelectorFromString("_setActualSize:"))
|
|
|
+ if let data = i, data != -1 {
|
|
|
+ menu?.item(at: i!)?.action = #selector(doActualSize)
|
|
|
+ item = menu?.insertItem(withTitle: KMLocalizedString("Physical Size", "Menu item title"), action: #selector(doPhysicalSize), target: self, at: i! + 1)
|
|
|
+// [item setKeyEquivalentModifierMask:NSAlternateKeyMask];
|
|
|
+// [item setAlternate:YES];
|
|
|
+ }
|
|
|
+
|
|
|
+// i = i == NSNotFound || i == 0 ? [menu numberOfItems] : i - 1;
|
|
|
+ i = menu?.indexOfItem(withTarget: self, andAction: NSSelectorFromString("goToNextPage:"))
|
|
|
+ if i == NSNotFound || i == 0 {
|
|
|
+ i = menu?.numberOfItems
|
|
|
+ } else if i != nil {
|
|
|
+ i = i! - 1
|
|
|
+ }
|
|
|
|
|
|
- - (void)changeToolMode:(id)sender {
|
|
|
- [self setSelectsText:(BOOL)[sender tag]];
|
|
|
- }
|
|
|
+ menu?.insertItem(withTitle: KMLocalizedString("Scroll Tool", "Menu item title"), action: #selector(changeToolMode), target: self, at: i!)
|
|
|
+ menu?.insertItem(withTitle: KMLocalizedString("Text Tool", "Menu item title"), action: #selector(changeToolMode), target: self, at: i!)
|
|
|
+ menu?.insertItem(.separator(), at: i!)
|
|
|
+
|
|
|
+ return menu
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
|
|
|
// we don't want to steal the printDocument: action from the responder chain
|
|
|
- (void)printDocument:(id)sender{}
|
|
@@ -580,77 +478,6 @@ class KMSecondaryPDFView: CPDFView {
|
|
|
return aSelector != @selector(printDocument:) && [super respondsToSelector:aSelector];
|
|
|
}
|
|
|
|
|
|
- - (NSMenu *)menuForEvent:(NSEvent *)theEvent {
|
|
|
- static NSSet *selectionActions = nil;
|
|
|
- if (selectionActions == nil)
|
|
|
- selectionActions = [[NSSet alloc] initWithObjects:@"copy:", @"_searchInSpotlight:", @"_searchInGoogle:", @"_searchInDictionary:", @"_revealSelection:", nil];
|
|
|
- NSMenu *menu = [super menuForEvent:theEvent];
|
|
|
- NSMenuItem *item;
|
|
|
-
|
|
|
- if ([self selectsText] == NO) {
|
|
|
- [self setCurrentSelection:RUNNING_AFTER(10_11) ? [[[PDFSelection alloc] initWithDocument:[self document]] autorelease] : nil];
|
|
|
- while ([menu numberOfItems]) {
|
|
|
- item = [menu itemAtIndex:0];
|
|
|
- if ([item isSeparatorItem] || [self validateMenuItem:item] == NO || [selectionActions containsObject:NSStringFromSelector([item action])])
|
|
|
- [menu removeItemAtIndex:0];
|
|
|
- else
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- NSInteger i = [menu indexOfItemWithTarget:self andAction:NSSelectorFromString(@"_setDoublePageScrolling:")];
|
|
|
- if (i == -1)
|
|
|
- i = [menu indexOfItemWithTarget:self andAction:NSSelectorFromString(@"_toggleContinuous:")];
|
|
|
- if (i != -1) {
|
|
|
- PDFDisplayMode displayMode = [self displayMode];
|
|
|
- [menu insertItem:[NSMenuItem separatorItem] atIndex:++i];
|
|
|
- if (displayMode == kPDFDisplayTwoUp || displayMode == kPDFDisplayTwoUpContinuous) {
|
|
|
- item = [menu insertItemWithTitle:NSLocalizedString(@"Book Mode", @"Menu item title") action:@selector(toggleDisplayAsBookFromMenu:) keyEquivalent:@"" atIndex:++i];
|
|
|
- [item setTarget:self];
|
|
|
- }
|
|
|
- item = [menu insertItemWithTitle:NSLocalizedString(@"Page Breaks", @"Menu item title") action:@selector(toggleDisplayPageBreaksFromMenu:) keyEquivalent:@"" atIndex:++i];
|
|
|
- [item setTarget:self];
|
|
|
- }
|
|
|
- i = [menu indexOfItemWithTarget:self andAction:NSSelectorFromString(@"_setActualSize:")];
|
|
|
- if (i != -1) {
|
|
|
- [[menu itemAtIndex:i] setAction:@selector(doActualSize:)];
|
|
|
- item = [menu insertItemWithTitle:NSLocalizedString(@"Physical Size", @"Menu item title") action:@selector(doPhysicalSize:) target:self atIndex:i + 1];
|
|
|
- [item setKeyEquivalentModifierMask:NSAlternateKeyMask];
|
|
|
- [item setAlternate:YES];
|
|
|
- }
|
|
|
-
|
|
|
- i = [menu indexOfItemWithTarget:self andAction:NSSelectorFromString(@"goToNextPage:")];
|
|
|
- i = i == NSNotFound || i == 0 ? [menu numberOfItems] : i - 1;
|
|
|
-
|
|
|
- [menu insertItemWithTitle:NSLocalizedString(@"Scroll Tool", @"Menu item title") action:@selector(changeToolMode:) target:self tag:0 atIndex:i];
|
|
|
- [menu insertItemWithTitle:NSLocalizedString(@"Text Tool", @"Menu item title") action:@selector(changeToolMode:) target:self tag:1 atIndex:i];
|
|
|
- [menu insertItem:[NSMenuItem separatorItem]atIndex:i];
|
|
|
-
|
|
|
- return menu;
|
|
|
- }
|
|
|
-
|
|
|
- - (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
|
|
|
- if ([menuItem action] == @selector(toggleDisplayAsBookFromMenu:)) {
|
|
|
- [menuItem setState:[self displaysAsBook] ? NSOnState : NSOffState];
|
|
|
- return YES;
|
|
|
- } else if ([menuItem action] == @selector(toggleDisplayPageBreaksFromMenu:)) {
|
|
|
- [menuItem setState:[self displaysPageBreaks] ? NSOnState : NSOffState];
|
|
|
- return YES;
|
|
|
- } else if ([menuItem action] == @selector(doActualSize:)) {
|
|
|
- [menuItem setState:fabs([self scaleFactor] - 1.0) < 0.1 ? NSOnState : NSOffState];
|
|
|
- return YES;
|
|
|
- } else if ([menuItem action] == @selector(doPhysicalSize:)) {
|
|
|
- [menuItem setState:([self autoScales] || fabs([self physicalScaleFactor] - 1.0 ) > 0.01) ? NSOffState : NSOnState];
|
|
|
- return YES;
|
|
|
- } else if ([menuItem action] == @selector(changeToolMode:)) {
|
|
|
- [menuItem setState:[self selectsText] == (BOOL)[menuItem tag] ? NSOnState : NSOffState];
|
|
|
- return YES;
|
|
|
- } else if ([[SKSecondaryPDFView superclass] instancesRespondToSelector:_cmd]) {
|
|
|
- return [super validateMenuItem:menuItem];
|
|
|
- }
|
|
|
- return YES;
|
|
|
- }
|
|
|
-
|
|
|
#pragma mark Gestures
|
|
|
|
|
|
- (void)beginGestureWithEvent:(NSEvent *)theEvent {
|
|
@@ -750,40 +577,42 @@ class KMSecondaryPDFView: CPDFView {
|
|
|
else
|
|
|
[super setCursorForAreaOfInterest:area];
|
|
|
}
|
|
|
-
|
|
|
- #pragma mark Notification handling
|
|
|
-
|
|
|
- - (void)startObservingSynchronizedPDFView {
|
|
|
- if (synchronizedPDFView)
|
|
|
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSynchronizedScaleChangedNotification:)
|
|
|
- name:PDFViewScaleChangedNotification object:synchronizedPDFView];
|
|
|
- }
|
|
|
-
|
|
|
- - (void)stopObservingSynchronizedPDFView {
|
|
|
- if (synchronizedPDFView)
|
|
|
- [[NSNotificationCenter defaultCenter] removeObserver:self name:PDFViewScaleChangedNotification object:synchronizedPDFView];
|
|
|
- }
|
|
|
-
|
|
|
- - (void)handlePageChangedNotification:(NSNotification *)notification {
|
|
|
- [pagePopUpButton selectItemAtIndex:[[self document] indexForPage:[self currentPage]]];
|
|
|
- }
|
|
|
-
|
|
|
- - (void)handleSynchronizedScaleChangedNotification:(NSNotification *)notification {
|
|
|
- if ([self synchronizeZoom])
|
|
|
- [self setScaleFactor:[synchronizedPDFView scaleFactor]];
|
|
|
- }
|
|
|
-
|
|
|
- - (void)handleDocumentDidUnlockNotification:(NSNotification *)notification {
|
|
|
- [self reloadPagePopUpButton];
|
|
|
- }
|
|
|
-
|
|
|
- - (void)handlePDFViewScaleChangedNotification:(NSNotification *)notification {
|
|
|
- if ([self autoScales] == NO && [self synchronizeZoom] == NO)
|
|
|
- [self setScaleFactor:fmax([self scaleFactor], SKMinDefaultScaleMenuFactor) adjustPopup:YES];
|
|
|
- }
|
|
|
-
|
|
|
*/
|
|
|
|
|
|
+ // MARK: - mark Notification handling
|
|
|
+
|
|
|
+ private func _startObservingSynchronizedPDFView() {
|
|
|
+ if self.synchronizedPDFView != nil {
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(handleSynchronizedScaleChangedNotification), name: NSNotification.Name.CPDFViewScaleChanged, object: self.synchronizedPDFView)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func _stopObservingSynchronizedPDFView() {
|
|
|
+ if self.synchronizedPDFView != nil {
|
|
|
+ NotificationCenter.default.removeObserver(self, name: NSNotification.Name.CPDFViewScaleChanged, object: self.synchronizedPDFView)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func handlePageChangedNotification(_ notification: Notification) {
|
|
|
+ self.pagePopUpButton?.selectItem(at: self.currentPageIndex)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func handleSynchronizedScaleChangedNotification(_ notification: Notification) {
|
|
|
+ if self.synchronizeZoom {
|
|
|
+ self.scaleFactor = self.synchronizedPDFView?.scaleFactor ?? 0.0
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func handleDocumentDidUnlockNotification(_ notification: Notification) {
|
|
|
+ self.reloadPagePopUpButton()
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func handlePDFViewScaleChangedNotification(_ notification: Notification) {
|
|
|
+ if self.autoScales == false && self.synchronizeZoom == false {
|
|
|
+ self.setScaleFactor(fmax(self.scaleFactor, SKMinDefaultScaleMenuFactor), adjustPopup: true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
func sizePopUpToItemAtIndex(_ popUpButton: NSPopUpButton?, anIndex: UInt) {
|
|
|
var i = popUpButton?.indexOfSelectedItem
|
|
|
popUpButton?.selectItem(at: Int(anIndex))
|
|
@@ -821,7 +650,7 @@ class KMSecondaryPDFView: CPDFView {
|
|
|
_newScaleFactor = SKDefaultScaleMenuFactors[Int(i)];
|
|
|
}
|
|
|
if self.autoScales {
|
|
|
-// [self setAutoScales:NO adjustPopup:NO];
|
|
|
+ self.setAutoScales(false, adjustPopup: false)
|
|
|
}
|
|
|
super.scaleFactor = _newScaleFactor
|
|
|
self.switching = savedSwitching
|
|
@@ -891,3 +720,35 @@ class KMSecondaryPDFView: CPDFView {
|
|
|
return upper
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+extension KMSecondaryPDFView: NSMenuItemValidation {
|
|
|
+ func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
|
|
|
+ let action = menuItem.action
|
|
|
+ if action == #selector(toggleDisplayAsBookFromMenu) {
|
|
|
+ menuItem.state = self.displaysAsBook ? .on : .off
|
|
|
+ return true
|
|
|
+ } else if action == #selector(toggleDisplayPageBreaksFromMenu) {
|
|
|
+ menuItem.state = self.displaysPageBreaks ? .on : .off
|
|
|
+ return true
|
|
|
+ } else if action == #selector(doActualSize) {
|
|
|
+// [menuItem setState:fabs([self scaleFactor] - 1.0) < 0.1 ? NSOnState : NSOffState];
|
|
|
+ menuItem.state = (self.scaleFactor-1.0) < 0.1 ? .on : .off
|
|
|
+ return true
|
|
|
+ } else if action == #selector(doPhysicalSize) {
|
|
|
+// [menuItem setState:([self autoScales] || fabs([self physicalScaleFactor] - 1.0 ) > 0.01) ? NSOffState : NSOnState];
|
|
|
+// return YES;
|
|
|
+ } else if action == #selector(changeToolMode) {
|
|
|
+// [menuItem setState:[self selectsText] == (BOOL)[menuItem tag] ? NSOnState : NSOffState];
|
|
|
+ if self.selectsText {
|
|
|
+ menuItem.state = menuItem.tag == 1 ? .on : .off
|
|
|
+ } else {
|
|
|
+ menuItem.state = menuItem.tag == 0 ? .on : .off
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+// else if ([[SKSecondaryPDFView superclass] instancesRespondToSelector:_cmd]) {
|
|
|
+// return [super validateMenuItem:menuItem];
|
|
|
+// }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+}
|