Revision: 26158 http://sourceforge.net/p/bibdesk/svn/26158 Author: hofman Date: 2021-06-07 16:55:07 +0000 (Mon, 07 Jun 2021) Log Message: ----------- Allow more generic control like an NSTextField for complext string editor, in case we want to use it for view based table views
Modified Paths: -------------- trunk/bibdesk/BDSKComplexStringEditor.h trunk/bibdesk/BDSKComplexStringEditor.m trunk/bibdesk/BDSKEditor.m trunk/bibdesk/BDSKMacroWindowController.m trunk/bibdesk/BDSKTextImportController.m Modified: trunk/bibdesk/BDSKComplexStringEditor.h =================================================================== --- trunk/bibdesk/BDSKComplexStringEditor.h 2021-06-07 16:34:37 UTC (rev 26157) +++ trunk/bibdesk/BDSKComplexStringEditor.h 2021-06-07 16:55:07 UTC (rev 26158) @@ -45,7 +45,7 @@ NSTextField *expandedValueTextField; BDSKBackgroundView *backgroundView; BDSKMacroResolver *macroResolver; - NSTableView *tableView; + NSControl *control; NSInteger row; NSInteger column; BOOL enabled; @@ -53,7 +53,7 @@ - (id)initWithMacroResolver:(BDSKMacroResolver *)aMacroResolver enabled:(BOOL)isEnabled; -- (BOOL)attachToTableView:(NSTableView *)aTableView atRow:(NSInteger)aRow column:(NSInteger)aColumn withValue:(NSString *)aString; +- (BOOL)attachToControl:(NSControl *)aControl atRow:(NSInteger)aRow column:(NSInteger)aColumn withValue:(NSString *)aString; @property (nonatomic, assign) IBOutlet NSTextField *expandedValueTextField; @property (nonatomic, assign) IBOutlet BDSKBackgroundView *backgroundView; Modified: trunk/bibdesk/BDSKComplexStringEditor.m =================================================================== --- trunk/bibdesk/BDSKComplexStringEditor.m 2021-06-07 16:34:37 UTC (rev 26157) +++ trunk/bibdesk/BDSKComplexStringEditor.m 2021-06-07 16:55:07 UTC (rev 26158) @@ -48,8 +48,7 @@ - (void)displayValue:(NSString *)stringValue isError:(BOOL)isError; - (void)cellFrameDidChange:(NSNotification *)notification; -- (void)cellWindowDidBecomeKey:(NSNotification *)notification; -- (void)cellWindowDidResignKey:(NSNotification *)notification; +- (void)cellWindowDidChangeKey:(NSNotification *)notification; - (void)registerForNotifications; - (void)unregisterForNotifications; @@ -64,7 +63,7 @@ - (id)initWithMacroResolver:(BDSKMacroResolver *)aMacroResolver enabled:(BOOL)isEnabled { self = [super initWithWindowNibName:@"ComplexStringEditor"]; if (self) { - tableView = nil; + control = nil; macroResolver = [aMacroResolver retain]; row = -1; column = -1; @@ -82,22 +81,23 @@ [super dealloc]; } -- (BOOL)attachToTableView:(NSTableView *)aTableView atRow:(NSInteger)aRow column:(NSInteger)aColumn withValue:(NSString *)aString { +- (BOOL)attachToControl:(NSControl *)aControl atRow:(NSInteger)aRow column:(NSInteger)aColumn withValue:(NSString *)aString { if ([self isAttached]) return NO; // we are already busy editing - tableView = [aTableView retain]; + control = [aControl retain]; row = aRow; column = aColumn; [self window]; // make sure we loaded the nib - [tableView scrollRowToVisible:row]; + if ([control isKindOfClass:[NSTableView class]]) + [(NSTableView *)control scrollRowToVisible:row]; [self displayValue:aString isError:NO]; if (enabled) - [self cellWindowDidBecomeKey:nil]; //draw the focus ring we are covering + [self cellWindowDidChangeKey:nil]; //draw the focus ring we are covering [self cellFrameDidChange:nil]; // reset the frame and show the window - // track changes in the text, the frame and the window's key status of the tableView + // track changes in the text, the frame and the window's key status of the control [self registerForNotifications]; return YES; @@ -104,7 +104,7 @@ } - (BOOL)isAttached { - return (tableView != nil); + return (control != nil); } @end @@ -118,16 +118,16 @@ - (void)registerForNotifications { NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - NSView *contentView = (NSView *)[[tableView enclosingScrollView] contentView] ?: (NSView *)tableView; + NSView *contentView = (NSView *)[[control enclosingScrollView] contentView] ?: (NSView *)control; [nc addObserver:self selector:@selector(controlTextDidChange:) name:NSControlTextDidChangeNotification - object:tableView]; + object:control]; [nc addObserver:self selector:@selector(controlTextDidEndEditing:) name:NSControlTextDidEndEditingNotification - object:tableView]; + object:control]; // observe future changes in the frame and the key status of the window // if the target tableView has a scrollview, we should observe its content view, or we won't notice scrolling @@ -139,41 +139,45 @@ selector:@selector(cellFrameDidChange:) name:NSViewBoundsDidChangeNotification object:contentView]; - [nc addObserver:self - selector:@selector(tableViewColumnDidResize:) - name:NSTableViewColumnDidResizeNotification - object:tableView]; - [nc addObserver:self - selector:@selector(tableViewColumnDidMove:) - name:NSTableViewColumnDidMoveNotification - object:tableView]; + if ([control isKindOfClass:[NSTableView class]]) + [nc addObserver:self + selector:@selector(cellFrameDidChange:) + name:NSTableViewColumnDidResizeNotification + object:control]; + else if (contentView != control) + [nc addObserver:self + selector:@selector(cellFrameDidChange:) + name:NSViewFrameDidChangeNotification + object:control]; if (enabled) { - NSWindow *tableViewWindow = [tableView window]; + NSWindow *controlWindow = [control window]; [nc addObserver:self - selector:@selector(cellWindowDidBecomeKey:) + selector:@selector(cellWindowDidChangeKey:) name:NSWindowDidBecomeKeyNotification - object:tableViewWindow]; + object:controlWindow]; [nc addObserver:self - selector:@selector(cellWindowDidResignKey:) + selector:@selector(cellWindowDidChangeKey:) name:NSWindowDidResignKeyNotification - object:tableViewWindow]; + object:controlWindow]; } } - (void)unregisterForNotifications { NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - NSView *contentView = (NSView *)[[tableView enclosingScrollView] contentView] ?: (NSView *)tableView; + NSView *contentView = (NSView *)[[control enclosingScrollView] contentView] ?: (NSView *)control; - [nc removeObserver:self name:NSControlTextDidChangeNotification object:tableView]; - [nc removeObserver:self name:NSControlTextDidEndEditingNotification object:tableView]; + [nc removeObserver:self name:NSControlTextDidChangeNotification object:control]; + [nc removeObserver:self name:NSControlTextDidEndEditingNotification object:control]; [nc removeObserver:self name:NSViewFrameDidChangeNotification object:contentView]; [nc removeObserver:self name:NSViewBoundsDidChangeNotification object:contentView]; - [nc removeObserver:self name:NSTableViewColumnDidResizeNotification object:tableView]; - [nc removeObserver:self name:NSTableViewColumnDidMoveNotification object:tableView]; + if ([control isKindOfClass:[NSTableView class]]) + [nc removeObserver:self name:NSTableViewColumnDidResizeNotification object:control]; + else if (contentView != control) + [nc removeObserver:self name:NSViewFrameDidChangeNotification object:control]; if (enabled) { - NSWindow *tableViewWindow = [tableView window]; - [nc removeObserver:self name:NSWindowDidBecomeKeyNotification object:tableViewWindow]; - [nc removeObserver:self name:NSWindowDidResignKeyNotification object:tableViewWindow]; + NSWindow *controlWindow = [control window]; + [nc removeObserver:self name:NSWindowDidBecomeKeyNotification object:controlWindow]; + [nc removeObserver:self name:NSWindowDidResignKeyNotification object:controlWindow]; } } @@ -180,11 +184,11 @@ - (void)remove { // we're going away now, so we can unregister for the notifications we registered for earlier [self unregisterForNotifications]; - [[tableView window] removeChildWindow:[self window]]; + [[control window] removeChildWindow:[self window]]; [[self window] orderOut:nil]; // release the temporary objects - BDSKDESTROY(tableView); // we should set this to nil, as we use this as a flag that we are editing + BDSKDESTROY(control); // we should set this to nil, as we use this as a flag that we are editing row = -1; column = -1; } @@ -205,25 +209,27 @@ #pragma mark Frame change and keywindow notification handlers - (void)cellFrameDidChange:(NSNotification *)notification { - NSRectEdge lowerEdge = [tableView isFlipped] ? NSMaxYEdge : NSMinYEdge; - NSRect lowerEdgeRect; + NSRectEdge lowerEdge = [control isFlipped] ? NSMaxYEdge : NSMinYEdge; + NSRect lowerEdgeRect = [control bounds]; NSRect winFrame = [[self window] frame]; CGFloat margin = 4.0; // for the shadow and focus ring CGFloat minWidth = 16.0; // minimal width of the window without margins, so subviews won't get shifted - NSView *contentView = (NSView *)[[tableView enclosingScrollView] contentView] ?: (NSView *)tableView; + NSView *contentView = (NSView *)[[control enclosingScrollView] contentView] ?: (NSView *)control; - lowerEdgeRect = BDSKSliceRect([tableView frameOfCellAtColumn:column row:row], 1.0, lowerEdge); - lowerEdgeRect = NSIntersectionRect(lowerEdgeRect, [contentView visibleRect]); + if ([control isKindOfClass:[NSTableView class]]) + lowerEdgeRect = [(NSTableView *)control frameOfCellAtColumn:column row:row]; + lowerEdgeRect = BDSKSliceRect(lowerEdgeRect, 1.0, lowerEdge); + lowerEdgeRect = NSIntersectionRect(lowerEdgeRect, [control convertRect:[contentView visibleRect] fromView:contentView]); // see if the cell's lower edge is scrolled out of sight if (NSIsEmptyRect(lowerEdgeRect)) { if ([self isWindowVisible]) { - [[tableView window] removeChildWindow:[self window]]; + [[control window] removeChildWindow:[self window]]; [[self window] orderOut:self]; } return; } - lowerEdgeRect = [tableView convertRectToScreen:lowerEdgeRect]; // takes into account isFlipped + lowerEdgeRect = [control convertRectToScreen:lowerEdgeRect]; // takes into account isFlipped winFrame.origin = lowerEdgeRect.origin; winFrame.origin.y -= NSHeight(winFrame); winFrame.size.width = fmax(NSWidth(lowerEdgeRect), minWidth); @@ -231,19 +237,15 @@ [[self window] setFrame:winFrame display:YES]; if ([self isWindowVisible] == NO) { - [[tableView window] addChildWindow:[self window] ordered:NSWindowAbove]; + [[control window] addChildWindow:[self window] ordered:NSWindowAbove]; [[self window] orderFront:self]; } } -- (void)cellWindowDidBecomeKey:(NSNotification *)notification { +- (void)cellWindowDidChangeKey:(NSNotification *)notification { [backgroundView setShowFocusRing:YES]; } -- (void)cellWindowDidResignKey:(NSNotification *)notification { - [backgroundView setShowFocusRing:NO]; -} - #pragma mark Window close delegate method - (void)windowWillClose:(NSNotification *)notification { @@ -270,26 +272,4 @@ [self displayValue:[error localizedDescription] isError:YES]; } -#pragma mark NSTableView notification handlers - -- (void)tableViewColumnDidResize:(NSNotification *)notification { - [self cellFrameDidChange:nil]; -} - -- (void)tableViewColumnDidMove:(NSNotification *)notification { - NSDictionary *userInfo = [notification userInfo]; - NSInteger oldColumn = [[userInfo objectForKey:@"oldColumn"] integerValue]; - NSInteger newColumn = [[userInfo objectForKey:@"newColumn"] integerValue]; - if (oldColumn == column) { - column = newColumn; - } else if (oldColumn < column) { - if (newColumn >= column) - column--; - } else if (oldColumn > column) { - if (newColumn <= column) - column++; - } - [self cellFrameDidChange:nil]; -} - @end Modified: trunk/bibdesk/BDSKEditor.m =================================================================== --- trunk/bibdesk/BDSKEditor.m 2021-06-07 16:34:37 UTC (rev 26157) +++ trunk/bibdesk/BDSKEditor.m 2021-06-07 16:55:07 UTC (rev 26158) @@ -2054,7 +2054,7 @@ return; if (complexStringEditor == nil) complexStringEditor = [[BDSKComplexStringEditor alloc] initWithMacroResolver:[publication macroResolver] enabled:editorFlags.isEditable]; - [complexStringEditor attachToTableView:tableView atRow:row column:1 withValue:object]; + [complexStringEditor attachToControl:tableView atRow:row column:1 withValue:object]; } // this is called when the user actually starts editing Modified: trunk/bibdesk/BDSKMacroWindowController.m =================================================================== --- trunk/bibdesk/BDSKMacroWindowController.m 2021-06-07 16:34:37 UTC (rev 26157) +++ trunk/bibdesk/BDSKMacroWindowController.m 2021-06-07 16:55:07 UTC (rev 26158) @@ -407,7 +407,7 @@ return; if (complexStringEditor == nil) complexStringEditor = [[BDSKComplexStringEditor alloc] initWithMacroResolver:macroResolver enabled:isEditable]; - [complexStringEditor attachToTableView:tableView atRow:row column:1 withValue:object]; + [complexStringEditor attachToControl:tableView atRow:row column:1 withValue:object]; } #pragma mark NSControl text delegate Modified: trunk/bibdesk/BDSKTextImportController.m =================================================================== --- trunk/bibdesk/BDSKTextImportController.m 2021-06-07 16:34:37 UTC (rev 26157) +++ trunk/bibdesk/BDSKTextImportController.m 2021-06-07 16:55:07 UTC (rev 26158) @@ -1078,7 +1078,7 @@ return; if (complexStringEditor == nil) complexStringEditor = [[BDSKComplexStringEditor alloc] initWithMacroResolver:[self macroResolver] enabled:YES]; - [complexStringEditor attachToTableView:itemTableView atRow:row column:1 withValue:object]; + [complexStringEditor attachToControl:itemTableView atRow:row column:1 withValue:object]; } #pragma mark BDSKCitationFormatter and BDSKTextImportItemTableView delegate This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit