Skip to content

Commit 1fd0876

Browse files
Commented out unneeded code
1 parent 9de4b4c commit 1fd0876

File tree

2 files changed

+124
-114
lines changed

2 files changed

+124
-114
lines changed

PBIconAndTextCell.m

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ - (id)copyWithZone:(NSZone *)zone
2626
return cell;
2727
}
2828

29-
- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength
30-
{
31-
NSRect textFrame, imageFrame;
32-
NSDivideRect (aRect, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge);
33-
[super selectWithFrame: textFrame inView: controlView editor:textObj delegate:anObject start:selStart length:selLength];
34-
}
29+
//- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength
30+
//{
31+
// NSRect textFrame, imageFrame;
32+
// NSDivideRect (aRect, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge);
33+
// [super selectWithFrame: textFrame inView: controlView editor:textObj delegate:anObject start:selStart length:selLength];
34+
//}
3535

3636
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
3737
{
@@ -69,56 +69,56 @@ - (NSSize)cellSize
6969
// = Hit testing =
7070
// ===============
7171
// Adopted from PhotoSearch Apple sample code
72-
73-
- (NSUInteger)hitTestForEvent:(NSEvent *)event inRect:(NSRect)cellFrame ofView:(NSView *)controlView
74-
{
75-
NSPoint point = [controlView convertPoint:[event locationInWindow] fromView:nil];
76-
77-
NSRect textFrame, imageFrame;
78-
NSDivideRect (cellFrame, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge);
79-
if (NSMouseInRect(point, imageFrame, [controlView isFlipped]))
80-
return NSCellHitContentArea | NSCellHitTrackableArea;
81-
82-
return [super hitTestForEvent:event inRect:cellFrame ofView:controlView];
83-
}
84-
85-
+ (BOOL)prefersTrackingUntilMouseUp
86-
{
87-
// NSCell returns NO for this by default. If you want to have trackMouse:inRect:ofView:untilMouseUp: always track until the mouse is up, then you MUST return YES. Otherwise, strange things will happen.
88-
return YES;
89-
}
90-
91-
- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)flag
92-
{
93-
[self setControlView:controlView];
94-
95-
NSRect textFrame, imageFrame;
96-
NSDivideRect (cellFrame, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge);
97-
while ([theEvent type] != NSLeftMouseUp) {
98-
// This is VERY simple event tracking. We simply check to see if the mouse is in the "i" button or not and dispatch entered/exited mouse events
99-
NSPoint point = [controlView convertPoint:[theEvent locationInWindow] fromView:nil];
100-
BOOL mouseInButton = NSMouseInRect(point, imageFrame, [controlView isFlipped]);
101-
if (mouseDownInButton != mouseInButton) {
102-
mouseDownInButton = mouseInButton;
103-
[controlView setNeedsDisplayInRect:cellFrame];
104-
}
105-
if ([theEvent type] == NSMouseEntered || [theEvent type] == NSMouseExited)
106-
[NSApp sendEvent:theEvent];
107-
// Note that we process mouse entered and exited events and dispatch them to properly handle updates
108-
theEvent = [[controlView window] nextEventMatchingMask:(NSLeftMouseUpMask | NSLeftMouseDraggedMask | NSMouseEnteredMask | NSMouseExitedMask)];
109-
}
110-
111-
// Another way of implementing the above code would be to keep an NSButtonCell as an ivar, and simply call trackMouse:inRect:ofView:untilMouseUp: on it, if the tracking area was inside of it.
112-
if (mouseDownInButton) {
113-
// Send the action, and redisplay
114-
mouseDownInButton = NO;
115-
[controlView setNeedsDisplayInRect:cellFrame];
116-
if (self.action)
117-
[NSApp sendAction:self.action to:self.target from:self];
118-
}
119-
120-
// We return YES since the mouse was released while we were tracking. Not returning YES when you processed the mouse up is an easy way to introduce bugs!
121-
return YES;
122-
}
72+
//
73+
//- (NSUInteger)hitTestForEvent:(NSEvent *)event inRect:(NSRect)cellFrame ofView:(NSView *)controlView
74+
//{
75+
// NSPoint point = [controlView convertPoint:[event locationInWindow] fromView:nil];
76+
//
77+
// NSRect textFrame, imageFrame;
78+
// NSDivideRect (cellFrame, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge);
79+
// if (NSMouseInRect(point, imageFrame, [controlView isFlipped]))
80+
// return NSCellHitContentArea | NSCellHitTrackableArea;
81+
//
82+
// return [super hitTestForEvent:event inRect:cellFrame ofView:controlView];
83+
//}
84+
85+
//+ (BOOL)prefersTrackingUntilMouseUp
86+
//{
87+
// // NSCell returns NO for this by default. If you want to have trackMouse:inRect:ofView:untilMouseUp: always track until the mouse is up, then you MUST return YES. Otherwise, strange things will happen.
88+
// return YES;
89+
//}
90+
//
91+
//- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)flag
92+
//{
93+
// [self setControlView:controlView];
94+
//
95+
// NSRect textFrame, imageFrame;
96+
// NSDivideRect (cellFrame, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge);
97+
// while ([theEvent type] != NSLeftMouseUp) {
98+
// // This is VERY simple event tracking. We simply check to see if the mouse is in the "i" button or not and dispatch entered/exited mouse events
99+
// NSPoint point = [controlView convertPoint:[theEvent locationInWindow] fromView:nil];
100+
// BOOL mouseInButton = NSMouseInRect(point, imageFrame, [controlView isFlipped]);
101+
// if (mouseDownInButton != mouseInButton) {
102+
// mouseDownInButton = mouseInButton;
103+
// [controlView setNeedsDisplayInRect:cellFrame];
104+
// }
105+
// if ([theEvent type] == NSMouseEntered || [theEvent type] == NSMouseExited)
106+
// [NSApp sendEvent:theEvent];
107+
// // Note that we process mouse entered and exited events and dispatch them to properly handle updates
108+
// theEvent = [[controlView window] nextEventMatchingMask:(NSLeftMouseUpMask | NSLeftMouseDraggedMask | NSMouseEnteredMask | NSMouseExitedMask)];
109+
// }
110+
//
111+
// // Another way of implementing the above code would be to keep an NSButtonCell as an ivar, and simply call trackMouse:inRect:ofView:untilMouseUp: on it, if the tracking area was inside of it.
112+
// if (mouseDownInButton) {
113+
// // Send the action, and redisplay
114+
// mouseDownInButton = NO;
115+
// [controlView setNeedsDisplayInRect:cellFrame];
116+
// if (self.action)
117+
// [NSApp sendAction:self.action to:self.target from:self];
118+
// }
119+
//
120+
// // We return YES since the mouse was released while we were tracking. Not returning YES when you processed the mouse up is an easy way to introduce bugs!
121+
// return YES;
122+
//}
123123

124124
@end

PBSourceViewCell.m

Lines changed: 67 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#import "PBSourceViewCell.h"
1010
#import "PBGitSidebarController.h"
1111
#import "PBSourceViewBadge.h"
12-
#import "GTScaledButtonControl.h"
1312

1413
@interface PBSourceViewCell()
1514
- (NSRect)infoButtonRectForBounds:(NSRect)bounds;
@@ -33,11 +32,6 @@ @implementation PBSourceViewCell
3332
- (NSMenu *) menuForEvent:(NSEvent *)event inRect:(NSRect)rect ofView:(NSOutlineView *)view
3433
{
3534
NSPoint point = [self.controlView convertPoint:[event locationInWindow] fromView:nil];
36-
NSRect infoButtonRect = [self infoButtonRectForBounds:self.controlView.frame];
37-
if (showsActionButton && NSMouseInRect(point, infoButtonRect, [self.controlView isFlipped])){
38-
NSLog(@"elo elo");
39-
return nil;
40-
}
4135
NSInteger row = [view rowAtPoint:point];
4236

4337
PBGitSidebarController *controller = [view delegate];
@@ -99,51 +93,51 @@ - (void)drawInteriorWithFrame:(NSRect)bounds inView:(NSView *)controlView {
9993
}
10094

10195

102-
- (NSUInteger)hitTestForEvent:(NSEvent *)event inRect:(NSRect)cellFrame ofView:(NSView *)controlView {
103-
if (showsActionButton) {
104-
NSPoint point = [controlView convertPoint:[event locationInWindow] fromView:nil];
105-
//
106-
// NSRect titleRect = [self titleRectForBounds:cellFrame];
107-
// if (NSMouseInRect(point, titleRect, [controlView isFlipped])) {
108-
// return NSCellHitContentArea | NSCellHitEditableTextArea;
109-
// }
110-
//
111-
// NSRect imageRect = [self imageRectForBounds:cellFrame];
112-
// if (NSMouseInRect(point, imageRect, [controlView isFlipped])) {
113-
// return NSCellHitContentArea;
114-
// }
115-
//
116-
// // Did we hit the sub title?
117-
// NSAttributedString *attributedSubTitle = [self attributedSubTitle];
118-
// if ([attributedSubTitle length] > 0) {
119-
// NSRect attributedSubTitleRect = [self rectForSubTitleBasedOnTitleRect:titleRect inBounds:cellFrame];
120-
// if (NSMouseInRect(point, attributedSubTitleRect, [controlView isFlipped])) {
121-
// // Notice that this text isn't an editable area. Clicking on it won't begin an editing session.
122-
// return NSCellHitContentArea;
123-
// }
124-
// }
125-
126-
// How about the info button?
127-
NSRect infoButtonRect = [self infoButtonRectForBounds:cellFrame];
128-
if (NSMouseInRect(point, infoButtonRect, [controlView isFlipped])) {
129-
return NSCellHitContentArea | NSCellHitTrackableArea;
130-
}
131-
}
132-
133-
return [super hitTestForEvent:event inRect:cellFrame ofView:controlView];
134-
}
135-
136-
+ (BOOL)prefersTrackingUntilMouseUp {
137-
// NSCell returns NO for this by default. If you want to have trackMouse:inRect:ofView:untilMouseUp: always track until the mouse is up, then you MUST return YES. Otherwise, strange things will happen.
138-
return YES;
139-
}
96+
//- (NSUInteger)hitTestForEvent:(NSEvent *)event inRect:(NSRect)cellFrame ofView:(NSView *)controlView {
97+
// if (showsActionButton) {
98+
// NSPoint point = [controlView convertPoint:[event locationInWindow] fromView:nil];
99+
// //
100+
// // NSRect titleRect = [self titleRectForBounds:cellFrame];
101+
// // if (NSMouseInRect(point, titleRect, [controlView isFlipped])) {
102+
// // return NSCellHitContentArea | NSCellHitEditableTextArea;
103+
// // }
104+
// //
105+
// // NSRect imageRect = [self imageRectForBounds:cellFrame];
106+
// // if (NSMouseInRect(point, imageRect, [controlView isFlipped])) {
107+
// // return NSCellHitContentArea;
108+
// // }
109+
// //
110+
// // // Did we hit the sub title?
111+
// // NSAttributedString *attributedSubTitle = [self attributedSubTitle];
112+
// // if ([attributedSubTitle length] > 0) {
113+
// // NSRect attributedSubTitleRect = [self rectForSubTitleBasedOnTitleRect:titleRect inBounds:cellFrame];
114+
// // if (NSMouseInRect(point, attributedSubTitleRect, [controlView isFlipped])) {
115+
// // // Notice that this text isn't an editable area. Clicking on it won't begin an editing session.
116+
// // return NSCellHitContentArea;
117+
// // }
118+
// // }
119+
//
120+
// // How about the info button?
121+
// NSRect infoButtonRect = [self infoButtonRectForBounds:cellFrame];
122+
// if (NSMouseInRect(point, infoButtonRect, [controlView isFlipped])) {
123+
// return NSCellHitContentArea | NSCellHitTrackableArea;
124+
// }
125+
// }
126+
//
127+
// return [super hitTestForEvent:event inRect:cellFrame ofView:controlView];
128+
//}
129+
130+
//+ (BOOL)prefersTrackingUntilMouseUp {
131+
// // NSCell returns NO for this by default. If you want to have trackMouse:inRect:ofView:untilMouseUp: always track until the mouse is up, then you MUST return YES. Otherwise, strange things will happen.
132+
// return YES;
133+
//}
140134

141135
// Mouse tracking -- the only part we want to track is the "info" button
142136
- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)flag {
143-
[self setControlView:controlView];
144-
137+
// [self setControlView:controlView];
138+
//
145139
NSRect infoButtonRect = [self infoButtonRectForBounds:cellFrame];
146-
while ([theEvent type] != NSLeftMouseUp) {
140+
if ([theEvent type] != NSLeftMouseUp) {
147141
// This is VERY simple event tracking. We simply check to see if the mouse is in the "i" button or not and dispatch entered/exited mouse events
148142
NSPoint point = [controlView convertPoint:[theEvent locationInWindow] fromView:nil];
149143
BOOL mouseInButton = NSMouseInRect(point, infoButtonRect, [controlView isFlipped]);
@@ -160,18 +154,34 @@ - (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *
160154

161155
// Another way of implementing the above code would be to keep an NSButtonCell as an ivar, and simply call trackMouse:inRect:ofView:untilMouseUp: on it, if the tracking area was inside of it.
162156

163-
if (iMouseDownInInfoButton) {
164-
// Send the action, and redisplay
165-
iMouseDownInInfoButton = NO;
166-
[controlView setNeedsDisplayInRect:cellFrame];
167-
NSLog(@"fired");
168-
if (iInfoButtonAction) {
169-
[NSApp sendAction:iInfoButtonAction to:[self target] from:[self controlView]];
157+
NSLog(@"mouse tracking; %@", theEvent);
158+
NSPoint locationOfTouch = [controlView convertPoint:[theEvent locationInWindow] fromView:nil];
159+
160+
BOOL mouseInButton = NSMouseInRect(locationOfTouch, [self infoButtonRectForBounds:cellFrame], [controlView isFlipped]);
161+
if (mouseInButton) {
162+
// show menu
163+
NSMenu *menu = [self menuForEvent:theEvent inRect:cellFrame ofView:controlView];
164+
if (menu){
165+
[NSMenu popUpContextMenu:menu withEvent:theEvent forView:controlView];
170166
}
171167
}
172-
173-
// We return YES since the mouse was released while we were tracking. Not returning YES when you processed the mouse up is an easy way to introduce bugs!
174-
return YES;
168+
169+
if (iMouseDownInInfoButton) {
170+
// Send the action, and redisplay
171+
iMouseDownInInfoButton = NO;
172+
[controlView setNeedsDisplayInRect:cellFrame];
173+
// NSLog(@"fired");
174+
// if (iInfoButtonAction) {
175+
// [NSApp sendAction:iInfoButtonAction to:[self target] from:[self controlView]];
176+
// }
177+
}
178+
179+
return [super trackMouse:theEvent inRect:cellFrame ofView:controlView untilMouseUp:flag];
180+
181+
182+
//
183+
// // We return YES since the mouse was released while we were tracking. Not returning YES when you processed the mouse up is an easy way to introduce bugs!
184+
// return YES;
175185
}
176186

177187

0 commit comments

Comments
 (0)