mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Add tooltips to bookmark outliner. allow context-click to set the
selection, not rely on what's already selected (bug 150186)
This commit is contained in:
parent
71195c0ca3
commit
efdc8c89f6
@ -19,12 +19,17 @@
|
|||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||||
|
* Max Horn <max@quendi.de> (Context menu & tooltip code)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import <AppKit/AppKit.h>
|
#import <AppKit/AppKit.h>
|
||||||
|
|
||||||
@interface CHExtendedOutlineView : NSOutlineView {
|
@interface CHExtendedOutlineView : NSOutlineView {
|
||||||
SEL mDeleteAction;
|
SEL mDeleteAction;
|
||||||
|
|
||||||
|
NSRect mOldFrameRect;
|
||||||
|
int mOldRows;
|
||||||
|
BOOL mDelegateTooltipStringForItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)keyDown:(NSEvent*)aEvent;
|
-(void)keyDown:(NSEvent*)aEvent;
|
||||||
@ -32,4 +37,14 @@
|
|||||||
-(void)setDeleteAction: (SEL)deleteAction;
|
-(void)setDeleteAction: (SEL)deleteAction;
|
||||||
-(SEL)deleteAction;
|
-(SEL)deleteAction;
|
||||||
|
|
||||||
|
-(void)setDelegate:(id)anObject;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface NSObject (CHOutlineViewDataSourceToolTips)
|
||||||
|
- (NSString *)outlineView:(NSOutlineView *)outlineView tooltipStringForItem:(id)item;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface NSObject (CHOutlineViewContextMenus)
|
||||||
|
- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item;
|
||||||
@end
|
@end
|
||||||
|
@ -19,20 +19,33 @@
|
|||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||||
|
* Max Horn <max@quendi.de> (Context menu & tooltip code)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "CHExtendedOutlineView.h"
|
#import "CHExtendedOutlineView.h"
|
||||||
|
|
||||||
|
@interface CHExtendedOutlineView (Private)
|
||||||
|
- (void)_updateToolTipRect;
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation CHExtendedOutlineView
|
@implementation CHExtendedOutlineView
|
||||||
|
|
||||||
- (id)initWithFrame:(NSRect)frame
|
- (id)initWithFrame:(NSRect)frame
|
||||||
{
|
{
|
||||||
if ( (self = [super initWithFrame:frame]) ) {
|
if ( (self = [super initWithFrame:frame]) ) {
|
||||||
mDeleteAction = 0;
|
mDeleteAction = 0;
|
||||||
|
// FIXME - this method is *never* called for items that are archived in a nib!
|
||||||
|
// Luckily, object memory is zeroed, so mDeleteAction will be 0 anyway.
|
||||||
|
// I recommend that this method just be removed.
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)awakeFromNib {
|
||||||
|
// Setup the initial NSToolTipRects
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
-(void)setDeleteAction: (SEL)aDeleteAction
|
-(void)setDeleteAction: (SEL)aDeleteAction
|
||||||
{
|
{
|
||||||
mDeleteAction = aDeleteAction;
|
mDeleteAction = aDeleteAction;
|
||||||
@ -43,52 +56,181 @@
|
|||||||
return mDeleteAction;
|
return mDeleteAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
int kReturnKeyCode = 0x24;
|
-(void)setDelegate:(id)anObject
|
||||||
int kDeleteKeyCode = 0x33;
|
{
|
||||||
int kLeftArrowKeyCode = 0x7B;
|
[super setDelegate:anObject];
|
||||||
int kRightArrowKeyCode = 0x7C;
|
mDelegateTooltipStringForItem = [anObject respondsToSelector:@selector(outlineView:tooltipStringForItem:)];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
-(void)keyDown:(NSEvent*)aEvent
|
-(void)keyDown:(NSEvent*)aEvent
|
||||||
{
|
{
|
||||||
// Check for a certain set of special keys.
|
// check each char in the event array. it should be just 1 char, but
|
||||||
|
// just in case we use a loop.
|
||||||
//NSDeleteFunctionKey
|
int len = [[aEvent characters] length];
|
||||||
if ([aEvent keyCode] == kDeleteKeyCode) {
|
for ( int i = 0; i < len; ++i ) {
|
||||||
if (mDeleteAction)
|
unichar c = [[aEvent characters] characterAtIndex:i];
|
||||||
[NSApp sendAction: mDeleteAction to: [self target] from: self];
|
|
||||||
return;
|
// Check for a certain set of special keys.
|
||||||
}
|
|
||||||
else if ([aEvent keyCode] == kReturnKeyCode) {
|
if (c == NSDeleteCharacter || c == NSBackspaceCharacter) {
|
||||||
// Override return to keep the goofy inline editing
|
// delete the bookmark
|
||||||
// from happening.
|
if (mDeleteAction)
|
||||||
if ([self numberOfSelectedRows] == 1)
|
[NSApp sendAction: mDeleteAction to: [self target] from: self];
|
||||||
[NSApp sendAction: [self doubleAction] to: [self target] from: self];
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if ([aEvent keyCode] == kLeftArrowKeyCode ||
|
|
||||||
[aEvent keyCode] == kRightArrowKeyCode)
|
|
||||||
{
|
|
||||||
BOOL expand = ([aEvent keyCode] == kRightArrowKeyCode);
|
|
||||||
if ([self numberOfSelectedRows] == 1) {
|
|
||||||
int index = [self selectedRow];
|
|
||||||
if (index == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
id item = [self itemAtRow: index];
|
|
||||||
if (!item)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (![self isExpandable: item])
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (![self isItemExpanded: item] && expand)
|
|
||||||
[self expandItem: item];
|
|
||||||
else if ([self isItemExpanded: item] && !expand)
|
|
||||||
[self collapseItem: item];
|
|
||||||
}
|
}
|
||||||
}
|
else if (c == NSCarriageReturnCharacter) {
|
||||||
|
// Start editing
|
||||||
|
if ([self numberOfSelectedRows] == 1) {
|
||||||
|
[self editColumn:0 row:[self selectedRow] withEvent:aEvent select:YES];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c == NSLeftArrowFunctionKey || c == NSRightArrowFunctionKey)
|
||||||
|
{
|
||||||
|
BOOL expand = (c == NSRightArrowFunctionKey);
|
||||||
|
if ([self numberOfSelectedRows] == 1) {
|
||||||
|
int index = [self selectedRow];
|
||||||
|
if (index == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
id item = [self itemAtRow: index];
|
||||||
|
if (!item)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (![self isExpandable: item])
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (![self isItemExpanded: item] && expand)
|
||||||
|
[self expandItem: item];
|
||||||
|
else if ([self isItemExpanded: item] && !expand)
|
||||||
|
[self collapseItem: item];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // foreach character
|
||||||
|
|
||||||
return [super keyDown: aEvent];
|
return [super keyDown: aEvent];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Intercept changes to the window frame so we can update our tooltip rects
|
||||||
|
*/
|
||||||
|
- (void)setFrameOrigin:(NSPoint)newOrigin;
|
||||||
|
{
|
||||||
|
[super setFrameOrigin:newOrigin];
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setFrameSize:(NSSize)newSize;
|
||||||
|
{
|
||||||
|
[super setFrameSize:newSize];
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setFrame:(NSRect)frameRect
|
||||||
|
{
|
||||||
|
[super setFrame:frameRect];
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Implement the informal NSToolTipOwner protocol to allow tooltips
|
||||||
|
* on a per-item level.
|
||||||
|
*/
|
||||||
|
- (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag point:(NSPoint)point userData:(void *)data
|
||||||
|
{
|
||||||
|
NSString *result = nil;
|
||||||
|
int rowIndex = [self rowAtPoint:point];
|
||||||
|
if (rowIndex >= 0) {
|
||||||
|
id delegate = [self delegate];
|
||||||
|
id item = [self itemAtRow:rowIndex];
|
||||||
|
|
||||||
|
if (item && mDelegateTooltipStringForItem)
|
||||||
|
result = [delegate outlineView:self tooltipStringForItem:item];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return a context menu depending on which item was clicked.
|
||||||
|
*/
|
||||||
|
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
id item;
|
||||||
|
int rowIndex;
|
||||||
|
NSPoint point;
|
||||||
|
|
||||||
|
point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
rowIndex = [self rowAtPoint:point];
|
||||||
|
|
||||||
|
if (rowIndex >= 0) {
|
||||||
|
// There seems to be a bug in AppKit; selectRow is supposed to
|
||||||
|
// abort editing, but it doesn't, thus we do it manually.
|
||||||
|
[self abortEditing];
|
||||||
|
|
||||||
|
item = [self itemAtRow:rowIndex];
|
||||||
|
if (item) {
|
||||||
|
id delegate = [self delegate];
|
||||||
|
|
||||||
|
// If the item was not selected, select it now
|
||||||
|
if (![self isRowSelected:rowIndex]) {
|
||||||
|
if (![delegate respondsToSelector:@selector(outlineView:shouldSelectItem:)]
|
||||||
|
|| [delegate outlineView:self shouldSelectItem:item])
|
||||||
|
[self selectRow:rowIndex byExtendingSelection:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([delegate respondsToSelector:@selector(outlineView:contextMenuForItem:)])
|
||||||
|
return [delegate outlineView:self contextMenuForItem:item];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Just return the default context menu
|
||||||
|
return [self menu];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation CHExtendedOutlineView (Private)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set up tooltip rects for every row, but only if the frame size or
|
||||||
|
* the number of rows changed since the last invocation.
|
||||||
|
*/
|
||||||
|
- (void)_updateToolTipRect
|
||||||
|
{
|
||||||
|
static NSRect oldFrameRect;
|
||||||
|
static int oldRows = 0;
|
||||||
|
NSRect frameRect;
|
||||||
|
int rows;
|
||||||
|
|
||||||
|
// Only set tooltip rects if the delegate implements outlineView:tooltipStringForItem:
|
||||||
|
if (!mDelegateTooltipStringForItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
frameRect = [self frame];
|
||||||
|
rows = [self numberOfRows];
|
||||||
|
|
||||||
|
// Check if rows or frame changed
|
||||||
|
if (rows != oldRows || !NSEqualRects(oldFrameRect, frameRect))
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
NSRect rect;
|
||||||
|
|
||||||
|
// Remove all old NSToolTipRects
|
||||||
|
[self removeAllToolTips];
|
||||||
|
|
||||||
|
// Add a NSToolTipRect for each row
|
||||||
|
for (i = 0; i < rows; ++i)
|
||||||
|
{
|
||||||
|
rect = [self rectOfRow:i];
|
||||||
|
[self addToolTipRect:rect owner:self userData:NULL];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the current values
|
||||||
|
oldRows = rows;
|
||||||
|
oldFrameRect = frameRect;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -19,12 +19,17 @@
|
|||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||||
|
* Max Horn <max@quendi.de> (Context menu & tooltip code)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import <AppKit/AppKit.h>
|
#import <AppKit/AppKit.h>
|
||||||
|
|
||||||
@interface CHExtendedOutlineView : NSOutlineView {
|
@interface CHExtendedOutlineView : NSOutlineView {
|
||||||
SEL mDeleteAction;
|
SEL mDeleteAction;
|
||||||
|
|
||||||
|
NSRect mOldFrameRect;
|
||||||
|
int mOldRows;
|
||||||
|
BOOL mDelegateTooltipStringForItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)keyDown:(NSEvent*)aEvent;
|
-(void)keyDown:(NSEvent*)aEvent;
|
||||||
@ -32,4 +37,14 @@
|
|||||||
-(void)setDeleteAction: (SEL)deleteAction;
|
-(void)setDeleteAction: (SEL)deleteAction;
|
||||||
-(SEL)deleteAction;
|
-(SEL)deleteAction;
|
||||||
|
|
||||||
|
-(void)setDelegate:(id)anObject;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface NSObject (CHOutlineViewDataSourceToolTips)
|
||||||
|
- (NSString *)outlineView:(NSOutlineView *)outlineView tooltipStringForItem:(id)item;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface NSObject (CHOutlineViewContextMenus)
|
||||||
|
- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item;
|
||||||
@end
|
@end
|
||||||
|
@ -19,20 +19,33 @@
|
|||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||||
|
* Max Horn <max@quendi.de> (Context menu & tooltip code)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "CHExtendedOutlineView.h"
|
#import "CHExtendedOutlineView.h"
|
||||||
|
|
||||||
|
@interface CHExtendedOutlineView (Private)
|
||||||
|
- (void)_updateToolTipRect;
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation CHExtendedOutlineView
|
@implementation CHExtendedOutlineView
|
||||||
|
|
||||||
- (id)initWithFrame:(NSRect)frame
|
- (id)initWithFrame:(NSRect)frame
|
||||||
{
|
{
|
||||||
if ( (self = [super initWithFrame:frame]) ) {
|
if ( (self = [super initWithFrame:frame]) ) {
|
||||||
mDeleteAction = 0;
|
mDeleteAction = 0;
|
||||||
|
// FIXME - this method is *never* called for items that are archived in a nib!
|
||||||
|
// Luckily, object memory is zeroed, so mDeleteAction will be 0 anyway.
|
||||||
|
// I recommend that this method just be removed.
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)awakeFromNib {
|
||||||
|
// Setup the initial NSToolTipRects
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
-(void)setDeleteAction: (SEL)aDeleteAction
|
-(void)setDeleteAction: (SEL)aDeleteAction
|
||||||
{
|
{
|
||||||
mDeleteAction = aDeleteAction;
|
mDeleteAction = aDeleteAction;
|
||||||
@ -43,52 +56,181 @@
|
|||||||
return mDeleteAction;
|
return mDeleteAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
int kReturnKeyCode = 0x24;
|
-(void)setDelegate:(id)anObject
|
||||||
int kDeleteKeyCode = 0x33;
|
{
|
||||||
int kLeftArrowKeyCode = 0x7B;
|
[super setDelegate:anObject];
|
||||||
int kRightArrowKeyCode = 0x7C;
|
mDelegateTooltipStringForItem = [anObject respondsToSelector:@selector(outlineView:tooltipStringForItem:)];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
-(void)keyDown:(NSEvent*)aEvent
|
-(void)keyDown:(NSEvent*)aEvent
|
||||||
{
|
{
|
||||||
// Check for a certain set of special keys.
|
// check each char in the event array. it should be just 1 char, but
|
||||||
|
// just in case we use a loop.
|
||||||
//NSDeleteFunctionKey
|
int len = [[aEvent characters] length];
|
||||||
if ([aEvent keyCode] == kDeleteKeyCode) {
|
for ( int i = 0; i < len; ++i ) {
|
||||||
if (mDeleteAction)
|
unichar c = [[aEvent characters] characterAtIndex:i];
|
||||||
[NSApp sendAction: mDeleteAction to: [self target] from: self];
|
|
||||||
return;
|
// Check for a certain set of special keys.
|
||||||
}
|
|
||||||
else if ([aEvent keyCode] == kReturnKeyCode) {
|
if (c == NSDeleteCharacter || c == NSBackspaceCharacter) {
|
||||||
// Override return to keep the goofy inline editing
|
// delete the bookmark
|
||||||
// from happening.
|
if (mDeleteAction)
|
||||||
if ([self numberOfSelectedRows] == 1)
|
[NSApp sendAction: mDeleteAction to: [self target] from: self];
|
||||||
[NSApp sendAction: [self doubleAction] to: [self target] from: self];
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if ([aEvent keyCode] == kLeftArrowKeyCode ||
|
|
||||||
[aEvent keyCode] == kRightArrowKeyCode)
|
|
||||||
{
|
|
||||||
BOOL expand = ([aEvent keyCode] == kRightArrowKeyCode);
|
|
||||||
if ([self numberOfSelectedRows] == 1) {
|
|
||||||
int index = [self selectedRow];
|
|
||||||
if (index == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
id item = [self itemAtRow: index];
|
|
||||||
if (!item)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (![self isExpandable: item])
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (![self isItemExpanded: item] && expand)
|
|
||||||
[self expandItem: item];
|
|
||||||
else if ([self isItemExpanded: item] && !expand)
|
|
||||||
[self collapseItem: item];
|
|
||||||
}
|
}
|
||||||
}
|
else if (c == NSCarriageReturnCharacter) {
|
||||||
|
// Start editing
|
||||||
|
if ([self numberOfSelectedRows] == 1) {
|
||||||
|
[self editColumn:0 row:[self selectedRow] withEvent:aEvent select:YES];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c == NSLeftArrowFunctionKey || c == NSRightArrowFunctionKey)
|
||||||
|
{
|
||||||
|
BOOL expand = (c == NSRightArrowFunctionKey);
|
||||||
|
if ([self numberOfSelectedRows] == 1) {
|
||||||
|
int index = [self selectedRow];
|
||||||
|
if (index == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
id item = [self itemAtRow: index];
|
||||||
|
if (!item)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (![self isExpandable: item])
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (![self isItemExpanded: item] && expand)
|
||||||
|
[self expandItem: item];
|
||||||
|
else if ([self isItemExpanded: item] && !expand)
|
||||||
|
[self collapseItem: item];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // foreach character
|
||||||
|
|
||||||
return [super keyDown: aEvent];
|
return [super keyDown: aEvent];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Intercept changes to the window frame so we can update our tooltip rects
|
||||||
|
*/
|
||||||
|
- (void)setFrameOrigin:(NSPoint)newOrigin;
|
||||||
|
{
|
||||||
|
[super setFrameOrigin:newOrigin];
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setFrameSize:(NSSize)newSize;
|
||||||
|
{
|
||||||
|
[super setFrameSize:newSize];
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setFrame:(NSRect)frameRect
|
||||||
|
{
|
||||||
|
[super setFrame:frameRect];
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Implement the informal NSToolTipOwner protocol to allow tooltips
|
||||||
|
* on a per-item level.
|
||||||
|
*/
|
||||||
|
- (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag point:(NSPoint)point userData:(void *)data
|
||||||
|
{
|
||||||
|
NSString *result = nil;
|
||||||
|
int rowIndex = [self rowAtPoint:point];
|
||||||
|
if (rowIndex >= 0) {
|
||||||
|
id delegate = [self delegate];
|
||||||
|
id item = [self itemAtRow:rowIndex];
|
||||||
|
|
||||||
|
if (item && mDelegateTooltipStringForItem)
|
||||||
|
result = [delegate outlineView:self tooltipStringForItem:item];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return a context menu depending on which item was clicked.
|
||||||
|
*/
|
||||||
|
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
id item;
|
||||||
|
int rowIndex;
|
||||||
|
NSPoint point;
|
||||||
|
|
||||||
|
point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
rowIndex = [self rowAtPoint:point];
|
||||||
|
|
||||||
|
if (rowIndex >= 0) {
|
||||||
|
// There seems to be a bug in AppKit; selectRow is supposed to
|
||||||
|
// abort editing, but it doesn't, thus we do it manually.
|
||||||
|
[self abortEditing];
|
||||||
|
|
||||||
|
item = [self itemAtRow:rowIndex];
|
||||||
|
if (item) {
|
||||||
|
id delegate = [self delegate];
|
||||||
|
|
||||||
|
// If the item was not selected, select it now
|
||||||
|
if (![self isRowSelected:rowIndex]) {
|
||||||
|
if (![delegate respondsToSelector:@selector(outlineView:shouldSelectItem:)]
|
||||||
|
|| [delegate outlineView:self shouldSelectItem:item])
|
||||||
|
[self selectRow:rowIndex byExtendingSelection:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([delegate respondsToSelector:@selector(outlineView:contextMenuForItem:)])
|
||||||
|
return [delegate outlineView:self contextMenuForItem:item];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Just return the default context menu
|
||||||
|
return [self menu];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation CHExtendedOutlineView (Private)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set up tooltip rects for every row, but only if the frame size or
|
||||||
|
* the number of rows changed since the last invocation.
|
||||||
|
*/
|
||||||
|
- (void)_updateToolTipRect
|
||||||
|
{
|
||||||
|
static NSRect oldFrameRect;
|
||||||
|
static int oldRows = 0;
|
||||||
|
NSRect frameRect;
|
||||||
|
int rows;
|
||||||
|
|
||||||
|
// Only set tooltip rects if the delegate implements outlineView:tooltipStringForItem:
|
||||||
|
if (!mDelegateTooltipStringForItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
frameRect = [self frame];
|
||||||
|
rows = [self numberOfRows];
|
||||||
|
|
||||||
|
// Check if rows or frame changed
|
||||||
|
if (rows != oldRows || !NSEqualRects(oldFrameRect, frameRect))
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
NSRect rect;
|
||||||
|
|
||||||
|
// Remove all old NSToolTipRects
|
||||||
|
[self removeAllToolTips];
|
||||||
|
|
||||||
|
// Add a NSToolTipRect for each row
|
||||||
|
for (i = 0; i < rows; ++i)
|
||||||
|
{
|
||||||
|
rect = [self rectOfRow:i];
|
||||||
|
[self addToolTipRect:rect owner:self userData:NULL];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the current values
|
||||||
|
oldRows = rows;
|
||||||
|
oldFrameRect = frameRect;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -19,12 +19,17 @@
|
|||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||||
|
* Max Horn <max@quendi.de> (Context menu & tooltip code)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import <AppKit/AppKit.h>
|
#import <AppKit/AppKit.h>
|
||||||
|
|
||||||
@interface CHExtendedOutlineView : NSOutlineView {
|
@interface CHExtendedOutlineView : NSOutlineView {
|
||||||
SEL mDeleteAction;
|
SEL mDeleteAction;
|
||||||
|
|
||||||
|
NSRect mOldFrameRect;
|
||||||
|
int mOldRows;
|
||||||
|
BOOL mDelegateTooltipStringForItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)keyDown:(NSEvent*)aEvent;
|
-(void)keyDown:(NSEvent*)aEvent;
|
||||||
@ -32,4 +37,14 @@
|
|||||||
-(void)setDeleteAction: (SEL)deleteAction;
|
-(void)setDeleteAction: (SEL)deleteAction;
|
||||||
-(SEL)deleteAction;
|
-(SEL)deleteAction;
|
||||||
|
|
||||||
|
-(void)setDelegate:(id)anObject;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface NSObject (CHOutlineViewDataSourceToolTips)
|
||||||
|
- (NSString *)outlineView:(NSOutlineView *)outlineView tooltipStringForItem:(id)item;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface NSObject (CHOutlineViewContextMenus)
|
||||||
|
- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item;
|
||||||
@end
|
@end
|
||||||
|
@ -19,20 +19,33 @@
|
|||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||||
|
* Max Horn <max@quendi.de> (Context menu & tooltip code)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "CHExtendedOutlineView.h"
|
#import "CHExtendedOutlineView.h"
|
||||||
|
|
||||||
|
@interface CHExtendedOutlineView (Private)
|
||||||
|
- (void)_updateToolTipRect;
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation CHExtendedOutlineView
|
@implementation CHExtendedOutlineView
|
||||||
|
|
||||||
- (id)initWithFrame:(NSRect)frame
|
- (id)initWithFrame:(NSRect)frame
|
||||||
{
|
{
|
||||||
if ( (self = [super initWithFrame:frame]) ) {
|
if ( (self = [super initWithFrame:frame]) ) {
|
||||||
mDeleteAction = 0;
|
mDeleteAction = 0;
|
||||||
|
// FIXME - this method is *never* called for items that are archived in a nib!
|
||||||
|
// Luckily, object memory is zeroed, so mDeleteAction will be 0 anyway.
|
||||||
|
// I recommend that this method just be removed.
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)awakeFromNib {
|
||||||
|
// Setup the initial NSToolTipRects
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
-(void)setDeleteAction: (SEL)aDeleteAction
|
-(void)setDeleteAction: (SEL)aDeleteAction
|
||||||
{
|
{
|
||||||
mDeleteAction = aDeleteAction;
|
mDeleteAction = aDeleteAction;
|
||||||
@ -43,52 +56,181 @@
|
|||||||
return mDeleteAction;
|
return mDeleteAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
int kReturnKeyCode = 0x24;
|
-(void)setDelegate:(id)anObject
|
||||||
int kDeleteKeyCode = 0x33;
|
{
|
||||||
int kLeftArrowKeyCode = 0x7B;
|
[super setDelegate:anObject];
|
||||||
int kRightArrowKeyCode = 0x7C;
|
mDelegateTooltipStringForItem = [anObject respondsToSelector:@selector(outlineView:tooltipStringForItem:)];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
-(void)keyDown:(NSEvent*)aEvent
|
-(void)keyDown:(NSEvent*)aEvent
|
||||||
{
|
{
|
||||||
// Check for a certain set of special keys.
|
// check each char in the event array. it should be just 1 char, but
|
||||||
|
// just in case we use a loop.
|
||||||
//NSDeleteFunctionKey
|
int len = [[aEvent characters] length];
|
||||||
if ([aEvent keyCode] == kDeleteKeyCode) {
|
for ( int i = 0; i < len; ++i ) {
|
||||||
if (mDeleteAction)
|
unichar c = [[aEvent characters] characterAtIndex:i];
|
||||||
[NSApp sendAction: mDeleteAction to: [self target] from: self];
|
|
||||||
return;
|
// Check for a certain set of special keys.
|
||||||
}
|
|
||||||
else if ([aEvent keyCode] == kReturnKeyCode) {
|
if (c == NSDeleteCharacter || c == NSBackspaceCharacter) {
|
||||||
// Override return to keep the goofy inline editing
|
// delete the bookmark
|
||||||
// from happening.
|
if (mDeleteAction)
|
||||||
if ([self numberOfSelectedRows] == 1)
|
[NSApp sendAction: mDeleteAction to: [self target] from: self];
|
||||||
[NSApp sendAction: [self doubleAction] to: [self target] from: self];
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if ([aEvent keyCode] == kLeftArrowKeyCode ||
|
|
||||||
[aEvent keyCode] == kRightArrowKeyCode)
|
|
||||||
{
|
|
||||||
BOOL expand = ([aEvent keyCode] == kRightArrowKeyCode);
|
|
||||||
if ([self numberOfSelectedRows] == 1) {
|
|
||||||
int index = [self selectedRow];
|
|
||||||
if (index == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
id item = [self itemAtRow: index];
|
|
||||||
if (!item)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (![self isExpandable: item])
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (![self isItemExpanded: item] && expand)
|
|
||||||
[self expandItem: item];
|
|
||||||
else if ([self isItemExpanded: item] && !expand)
|
|
||||||
[self collapseItem: item];
|
|
||||||
}
|
}
|
||||||
}
|
else if (c == NSCarriageReturnCharacter) {
|
||||||
|
// Start editing
|
||||||
|
if ([self numberOfSelectedRows] == 1) {
|
||||||
|
[self editColumn:0 row:[self selectedRow] withEvent:aEvent select:YES];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c == NSLeftArrowFunctionKey || c == NSRightArrowFunctionKey)
|
||||||
|
{
|
||||||
|
BOOL expand = (c == NSRightArrowFunctionKey);
|
||||||
|
if ([self numberOfSelectedRows] == 1) {
|
||||||
|
int index = [self selectedRow];
|
||||||
|
if (index == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
id item = [self itemAtRow: index];
|
||||||
|
if (!item)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (![self isExpandable: item])
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (![self isItemExpanded: item] && expand)
|
||||||
|
[self expandItem: item];
|
||||||
|
else if ([self isItemExpanded: item] && !expand)
|
||||||
|
[self collapseItem: item];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // foreach character
|
||||||
|
|
||||||
return [super keyDown: aEvent];
|
return [super keyDown: aEvent];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Intercept changes to the window frame so we can update our tooltip rects
|
||||||
|
*/
|
||||||
|
- (void)setFrameOrigin:(NSPoint)newOrigin;
|
||||||
|
{
|
||||||
|
[super setFrameOrigin:newOrigin];
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setFrameSize:(NSSize)newSize;
|
||||||
|
{
|
||||||
|
[super setFrameSize:newSize];
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setFrame:(NSRect)frameRect
|
||||||
|
{
|
||||||
|
[super setFrame:frameRect];
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Implement the informal NSToolTipOwner protocol to allow tooltips
|
||||||
|
* on a per-item level.
|
||||||
|
*/
|
||||||
|
- (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag point:(NSPoint)point userData:(void *)data
|
||||||
|
{
|
||||||
|
NSString *result = nil;
|
||||||
|
int rowIndex = [self rowAtPoint:point];
|
||||||
|
if (rowIndex >= 0) {
|
||||||
|
id delegate = [self delegate];
|
||||||
|
id item = [self itemAtRow:rowIndex];
|
||||||
|
|
||||||
|
if (item && mDelegateTooltipStringForItem)
|
||||||
|
result = [delegate outlineView:self tooltipStringForItem:item];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return a context menu depending on which item was clicked.
|
||||||
|
*/
|
||||||
|
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
id item;
|
||||||
|
int rowIndex;
|
||||||
|
NSPoint point;
|
||||||
|
|
||||||
|
point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
rowIndex = [self rowAtPoint:point];
|
||||||
|
|
||||||
|
if (rowIndex >= 0) {
|
||||||
|
// There seems to be a bug in AppKit; selectRow is supposed to
|
||||||
|
// abort editing, but it doesn't, thus we do it manually.
|
||||||
|
[self abortEditing];
|
||||||
|
|
||||||
|
item = [self itemAtRow:rowIndex];
|
||||||
|
if (item) {
|
||||||
|
id delegate = [self delegate];
|
||||||
|
|
||||||
|
// If the item was not selected, select it now
|
||||||
|
if (![self isRowSelected:rowIndex]) {
|
||||||
|
if (![delegate respondsToSelector:@selector(outlineView:shouldSelectItem:)]
|
||||||
|
|| [delegate outlineView:self shouldSelectItem:item])
|
||||||
|
[self selectRow:rowIndex byExtendingSelection:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([delegate respondsToSelector:@selector(outlineView:contextMenuForItem:)])
|
||||||
|
return [delegate outlineView:self contextMenuForItem:item];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Just return the default context menu
|
||||||
|
return [self menu];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation CHExtendedOutlineView (Private)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set up tooltip rects for every row, but only if the frame size or
|
||||||
|
* the number of rows changed since the last invocation.
|
||||||
|
*/
|
||||||
|
- (void)_updateToolTipRect
|
||||||
|
{
|
||||||
|
static NSRect oldFrameRect;
|
||||||
|
static int oldRows = 0;
|
||||||
|
NSRect frameRect;
|
||||||
|
int rows;
|
||||||
|
|
||||||
|
// Only set tooltip rects if the delegate implements outlineView:tooltipStringForItem:
|
||||||
|
if (!mDelegateTooltipStringForItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
frameRect = [self frame];
|
||||||
|
rows = [self numberOfRows];
|
||||||
|
|
||||||
|
// Check if rows or frame changed
|
||||||
|
if (rows != oldRows || !NSEqualRects(oldFrameRect, frameRect))
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
NSRect rect;
|
||||||
|
|
||||||
|
// Remove all old NSToolTipRects
|
||||||
|
[self removeAllToolTips];
|
||||||
|
|
||||||
|
// Add a NSToolTipRect for each row
|
||||||
|
for (i = 0; i < rows; ++i)
|
||||||
|
{
|
||||||
|
rect = [self rectOfRow:i];
|
||||||
|
[self addToolTipRect:rect owner:self userData:NULL];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the current values
|
||||||
|
oldRows = rows;
|
||||||
|
oldFrameRect = frameRect;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -19,12 +19,17 @@
|
|||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||||
|
* Max Horn <max@quendi.de> (Context menu & tooltip code)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import <AppKit/AppKit.h>
|
#import <AppKit/AppKit.h>
|
||||||
|
|
||||||
@interface CHExtendedOutlineView : NSOutlineView {
|
@interface CHExtendedOutlineView : NSOutlineView {
|
||||||
SEL mDeleteAction;
|
SEL mDeleteAction;
|
||||||
|
|
||||||
|
NSRect mOldFrameRect;
|
||||||
|
int mOldRows;
|
||||||
|
BOOL mDelegateTooltipStringForItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)keyDown:(NSEvent*)aEvent;
|
-(void)keyDown:(NSEvent*)aEvent;
|
||||||
@ -32,4 +37,14 @@
|
|||||||
-(void)setDeleteAction: (SEL)deleteAction;
|
-(void)setDeleteAction: (SEL)deleteAction;
|
||||||
-(SEL)deleteAction;
|
-(SEL)deleteAction;
|
||||||
|
|
||||||
|
-(void)setDelegate:(id)anObject;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface NSObject (CHOutlineViewDataSourceToolTips)
|
||||||
|
- (NSString *)outlineView:(NSOutlineView *)outlineView tooltipStringForItem:(id)item;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface NSObject (CHOutlineViewContextMenus)
|
||||||
|
- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item;
|
||||||
@end
|
@end
|
||||||
|
@ -19,20 +19,33 @@
|
|||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||||
|
* Max Horn <max@quendi.de> (Context menu & tooltip code)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "CHExtendedOutlineView.h"
|
#import "CHExtendedOutlineView.h"
|
||||||
|
|
||||||
|
@interface CHExtendedOutlineView (Private)
|
||||||
|
- (void)_updateToolTipRect;
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation CHExtendedOutlineView
|
@implementation CHExtendedOutlineView
|
||||||
|
|
||||||
- (id)initWithFrame:(NSRect)frame
|
- (id)initWithFrame:(NSRect)frame
|
||||||
{
|
{
|
||||||
if ( (self = [super initWithFrame:frame]) ) {
|
if ( (self = [super initWithFrame:frame]) ) {
|
||||||
mDeleteAction = 0;
|
mDeleteAction = 0;
|
||||||
|
// FIXME - this method is *never* called for items that are archived in a nib!
|
||||||
|
// Luckily, object memory is zeroed, so mDeleteAction will be 0 anyway.
|
||||||
|
// I recommend that this method just be removed.
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)awakeFromNib {
|
||||||
|
// Setup the initial NSToolTipRects
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
-(void)setDeleteAction: (SEL)aDeleteAction
|
-(void)setDeleteAction: (SEL)aDeleteAction
|
||||||
{
|
{
|
||||||
mDeleteAction = aDeleteAction;
|
mDeleteAction = aDeleteAction;
|
||||||
@ -43,52 +56,181 @@
|
|||||||
return mDeleteAction;
|
return mDeleteAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
int kReturnKeyCode = 0x24;
|
-(void)setDelegate:(id)anObject
|
||||||
int kDeleteKeyCode = 0x33;
|
{
|
||||||
int kLeftArrowKeyCode = 0x7B;
|
[super setDelegate:anObject];
|
||||||
int kRightArrowKeyCode = 0x7C;
|
mDelegateTooltipStringForItem = [anObject respondsToSelector:@selector(outlineView:tooltipStringForItem:)];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
-(void)keyDown:(NSEvent*)aEvent
|
-(void)keyDown:(NSEvent*)aEvent
|
||||||
{
|
{
|
||||||
// Check for a certain set of special keys.
|
// check each char in the event array. it should be just 1 char, but
|
||||||
|
// just in case we use a loop.
|
||||||
//NSDeleteFunctionKey
|
int len = [[aEvent characters] length];
|
||||||
if ([aEvent keyCode] == kDeleteKeyCode) {
|
for ( int i = 0; i < len; ++i ) {
|
||||||
if (mDeleteAction)
|
unichar c = [[aEvent characters] characterAtIndex:i];
|
||||||
[NSApp sendAction: mDeleteAction to: [self target] from: self];
|
|
||||||
return;
|
// Check for a certain set of special keys.
|
||||||
}
|
|
||||||
else if ([aEvent keyCode] == kReturnKeyCode) {
|
if (c == NSDeleteCharacter || c == NSBackspaceCharacter) {
|
||||||
// Override return to keep the goofy inline editing
|
// delete the bookmark
|
||||||
// from happening.
|
if (mDeleteAction)
|
||||||
if ([self numberOfSelectedRows] == 1)
|
[NSApp sendAction: mDeleteAction to: [self target] from: self];
|
||||||
[NSApp sendAction: [self doubleAction] to: [self target] from: self];
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if ([aEvent keyCode] == kLeftArrowKeyCode ||
|
|
||||||
[aEvent keyCode] == kRightArrowKeyCode)
|
|
||||||
{
|
|
||||||
BOOL expand = ([aEvent keyCode] == kRightArrowKeyCode);
|
|
||||||
if ([self numberOfSelectedRows] == 1) {
|
|
||||||
int index = [self selectedRow];
|
|
||||||
if (index == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
id item = [self itemAtRow: index];
|
|
||||||
if (!item)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (![self isExpandable: item])
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (![self isItemExpanded: item] && expand)
|
|
||||||
[self expandItem: item];
|
|
||||||
else if ([self isItemExpanded: item] && !expand)
|
|
||||||
[self collapseItem: item];
|
|
||||||
}
|
}
|
||||||
}
|
else if (c == NSCarriageReturnCharacter) {
|
||||||
|
// Start editing
|
||||||
|
if ([self numberOfSelectedRows] == 1) {
|
||||||
|
[self editColumn:0 row:[self selectedRow] withEvent:aEvent select:YES];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c == NSLeftArrowFunctionKey || c == NSRightArrowFunctionKey)
|
||||||
|
{
|
||||||
|
BOOL expand = (c == NSRightArrowFunctionKey);
|
||||||
|
if ([self numberOfSelectedRows] == 1) {
|
||||||
|
int index = [self selectedRow];
|
||||||
|
if (index == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
id item = [self itemAtRow: index];
|
||||||
|
if (!item)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (![self isExpandable: item])
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (![self isItemExpanded: item] && expand)
|
||||||
|
[self expandItem: item];
|
||||||
|
else if ([self isItemExpanded: item] && !expand)
|
||||||
|
[self collapseItem: item];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // foreach character
|
||||||
|
|
||||||
return [super keyDown: aEvent];
|
return [super keyDown: aEvent];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Intercept changes to the window frame so we can update our tooltip rects
|
||||||
|
*/
|
||||||
|
- (void)setFrameOrigin:(NSPoint)newOrigin;
|
||||||
|
{
|
||||||
|
[super setFrameOrigin:newOrigin];
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setFrameSize:(NSSize)newSize;
|
||||||
|
{
|
||||||
|
[super setFrameSize:newSize];
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setFrame:(NSRect)frameRect
|
||||||
|
{
|
||||||
|
[super setFrame:frameRect];
|
||||||
|
[self _updateToolTipRect];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Implement the informal NSToolTipOwner protocol to allow tooltips
|
||||||
|
* on a per-item level.
|
||||||
|
*/
|
||||||
|
- (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag point:(NSPoint)point userData:(void *)data
|
||||||
|
{
|
||||||
|
NSString *result = nil;
|
||||||
|
int rowIndex = [self rowAtPoint:point];
|
||||||
|
if (rowIndex >= 0) {
|
||||||
|
id delegate = [self delegate];
|
||||||
|
id item = [self itemAtRow:rowIndex];
|
||||||
|
|
||||||
|
if (item && mDelegateTooltipStringForItem)
|
||||||
|
result = [delegate outlineView:self tooltipStringForItem:item];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return a context menu depending on which item was clicked.
|
||||||
|
*/
|
||||||
|
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
|
||||||
|
{
|
||||||
|
id item;
|
||||||
|
int rowIndex;
|
||||||
|
NSPoint point;
|
||||||
|
|
||||||
|
point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
||||||
|
rowIndex = [self rowAtPoint:point];
|
||||||
|
|
||||||
|
if (rowIndex >= 0) {
|
||||||
|
// There seems to be a bug in AppKit; selectRow is supposed to
|
||||||
|
// abort editing, but it doesn't, thus we do it manually.
|
||||||
|
[self abortEditing];
|
||||||
|
|
||||||
|
item = [self itemAtRow:rowIndex];
|
||||||
|
if (item) {
|
||||||
|
id delegate = [self delegate];
|
||||||
|
|
||||||
|
// If the item was not selected, select it now
|
||||||
|
if (![self isRowSelected:rowIndex]) {
|
||||||
|
if (![delegate respondsToSelector:@selector(outlineView:shouldSelectItem:)]
|
||||||
|
|| [delegate outlineView:self shouldSelectItem:item])
|
||||||
|
[self selectRow:rowIndex byExtendingSelection:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([delegate respondsToSelector:@selector(outlineView:contextMenuForItem:)])
|
||||||
|
return [delegate outlineView:self contextMenuForItem:item];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Just return the default context menu
|
||||||
|
return [self menu];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation CHExtendedOutlineView (Private)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set up tooltip rects for every row, but only if the frame size or
|
||||||
|
* the number of rows changed since the last invocation.
|
||||||
|
*/
|
||||||
|
- (void)_updateToolTipRect
|
||||||
|
{
|
||||||
|
static NSRect oldFrameRect;
|
||||||
|
static int oldRows = 0;
|
||||||
|
NSRect frameRect;
|
||||||
|
int rows;
|
||||||
|
|
||||||
|
// Only set tooltip rects if the delegate implements outlineView:tooltipStringForItem:
|
||||||
|
if (!mDelegateTooltipStringForItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
frameRect = [self frame];
|
||||||
|
rows = [self numberOfRows];
|
||||||
|
|
||||||
|
// Check if rows or frame changed
|
||||||
|
if (rows != oldRows || !NSEqualRects(oldFrameRect, frameRect))
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
NSRect rect;
|
||||||
|
|
||||||
|
// Remove all old NSToolTipRects
|
||||||
|
[self removeAllToolTips];
|
||||||
|
|
||||||
|
// Add a NSToolTipRect for each row
|
||||||
|
for (i = 0; i < rows; ++i)
|
||||||
|
{
|
||||||
|
rect = [self rectOfRow:i];
|
||||||
|
[self addToolTipRect:rect owner:self userData:NULL];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the current values
|
||||||
|
oldRows = rows;
|
||||||
|
oldFrameRect = frameRect;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
Reference in New Issue
Block a user