mirror of
https://github.com/nickshanks/ResKnife.git
synced 2024-06-22 16:29:36 +00:00
HexWindow text boxes now synchro-scroll.
This commit is contained in:
parent
e8c270d59d
commit
25ffdd2023
Binary file not shown.
|
@ -16,12 +16,14 @@
|
||||||
id resource;
|
id resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resourceDidChange:(NSNotification *)notification;
|
|
||||||
- (void)refreshData:(NSData *)data;
|
|
||||||
|
|
||||||
// conform to the ResKnifePluginProtocol with the inclusion of these methods
|
// conform to the ResKnifePluginProtocol with the inclusion of these methods
|
||||||
- (id)initWithResource:(id)newResource;
|
- (id)initWithResource:(id)newResource;
|
||||||
|
|
||||||
|
// normal methods
|
||||||
|
- (void)resourceDidChange:(NSNotification *)notification;
|
||||||
|
- (void)viewDidScroll:(NSNotification *)notification;
|
||||||
|
- (void)refreshData:(NSData *)data;
|
||||||
|
|
||||||
// accessors
|
// accessors
|
||||||
- (id)resource;
|
- (id)resource;
|
||||||
- (NSData *)data;
|
- (NSData *)data;
|
||||||
|
|
|
@ -13,12 +13,13 @@ NSString *ResourceChangedNotification = @"ResourceChangedNotification";
|
||||||
- (id)initWithResource:(id)newResource
|
- (id)initWithResource:(id)newResource
|
||||||
{
|
{
|
||||||
self = [self initWithWindowNibName:@"HexWindow"];
|
self = [self initWithWindowNibName:@"HexWindow"];
|
||||||
if( self ) [self setWindowFrameAutosaveName:@"Hexadecimal Editor"];
|
if( !self ) return self;
|
||||||
|
|
||||||
// one instance of your principal class will be created for every resource the user wants to edit (similar to Windows apps)
|
// one instance of your principal class will be created for every resource the user wants to edit (similar to Windows apps)
|
||||||
resource = [newResource retain];
|
resource = [newResource retain];
|
||||||
|
|
||||||
// load the window
|
// load the window
|
||||||
|
[self setWindowFrameAutosaveName:@"Hexadecimal Editor"];
|
||||||
// [self setShouldCascadeWindows:YES];
|
// [self setShouldCascadeWindows:YES];
|
||||||
[self window];
|
[self window];
|
||||||
return self;
|
return self;
|
||||||
|
@ -38,6 +39,11 @@ NSString *ResourceChangedNotification = @"ResourceChangedNotification";
|
||||||
// we don't want this notification until we have a window!
|
// we don't want this notification until we have a window!
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resourceDidChange:) name:ResourceChangedNotification object:nil];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resourceDidChange:) name:ResourceChangedNotification object:nil];
|
||||||
|
|
||||||
|
// put other notifications here too, just for togetherness
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidScroll:) name:NSViewBoundsDidChangeNotification object:[[offset enclosingScrollView] contentView]];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidScroll:) name:NSViewBoundsDidChangeNotification object:[[hex enclosingScrollView] contentView]];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidScroll:) name:NSViewBoundsDidChangeNotification object:[[ascii enclosingScrollView] contentView]];
|
||||||
|
|
||||||
// insert the resources' data into the text fields
|
// insert the resources' data into the text fields
|
||||||
[self refreshData:[(id <ResKnifeResourceProtocol>)resource data]];
|
[self refreshData:[(id <ResKnifeResourceProtocol>)resource data]];
|
||||||
|
|
||||||
|
@ -52,6 +58,45 @@ NSString *ResourceChangedNotification = @"ResourceChangedNotification";
|
||||||
[self refreshData:[(id <ResKnifeResourceProtocol>)resource data]];
|
[self refreshData:[(id <ResKnifeResourceProtocol>)resource data]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)viewDidScroll:(NSNotification *)notification
|
||||||
|
{
|
||||||
|
// get object refs for increased speed
|
||||||
|
NSClipView *object = (NSClipView *) [notification object];
|
||||||
|
NSClipView *offsetClip = [[offset enclosingScrollView] contentView];
|
||||||
|
NSClipView *hexClip = [[hex enclosingScrollView] contentView];
|
||||||
|
NSClipView *asciiClip = [[ascii enclosingScrollView] contentView];
|
||||||
|
|
||||||
|
// due to a bug in -[NSView setPostsBoundsChangedNotifications:] (it basically doesn't work), I am having to work around it by removing myself from the notification center and restoring things later on!
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSViewBoundsDidChangeNotification object:nil];
|
||||||
|
|
||||||
|
// when a view scrolls, update the other two
|
||||||
|
if( object != offsetClip )
|
||||||
|
{
|
||||||
|
// [offsetClip setPostsBoundsChangedNotifications:NO];
|
||||||
|
[offsetClip setBoundsOrigin:[object bounds].origin];
|
||||||
|
// [offsetClip setPostsBoundsChangedNotifications:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
if( object != hexClip )
|
||||||
|
{
|
||||||
|
// [hexClip setPostsBoundsChangedNotifications:NO];
|
||||||
|
[hexClip setBoundsOrigin:[object bounds].origin];
|
||||||
|
// [hexClip setPostsBoundsChangedNotifications:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
if( object != asciiClip )
|
||||||
|
{
|
||||||
|
// [asciiClip setPostsBoundsChangedNotifications:NO];
|
||||||
|
[asciiClip setBoundsOrigin:[object bounds].origin];
|
||||||
|
// [asciiClip setPostsBoundsChangedNotifications:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
// restore notifications
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidScroll:) name:NSViewBoundsDidChangeNotification object:offsetClip];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidScroll:) name:NSViewBoundsDidChangeNotification object:hexClip];
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidScroll:) name:NSViewBoundsDidChangeNotification object:asciiClip];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)refreshData:(NSData *)data;
|
- (void)refreshData:(NSData *)data;
|
||||||
{
|
{
|
||||||
// clear delegates (see HexEditorDelegate class for explanation of why)
|
// clear delegates (see HexEditorDelegate class for explanation of why)
|
||||||
|
|
|
@ -2409,8 +2409,6 @@
|
||||||
F5EF83A1020C08E601A80001,
|
F5EF83A1020C08E601A80001,
|
||||||
F5EF83A2020C08E601A80001,
|
F5EF83A2020C08E601A80001,
|
||||||
F5EF83A3020C08E601A80001,
|
F5EF83A3020C08E601A80001,
|
||||||
F5EF83A4020C08E601A80001,
|
|
||||||
F5EF83A5020C08E601A80001,
|
|
||||||
F5EF83A7020C08E601A80001,
|
F5EF83A7020C08E601A80001,
|
||||||
F5EF83A8020C08E601A80001,
|
F5EF83A8020C08E601A80001,
|
||||||
F5EF83C7020C20D701A80001,
|
F5EF83C7020C20D701A80001,
|
||||||
|
@ -2441,16 +2439,6 @@
|
||||||
path = HexTextView.m;
|
path = HexTextView.m;
|
||||||
refType = 4;
|
refType = 4;
|
||||||
};
|
};
|
||||||
F5EF83A4020C08E601A80001 = {
|
|
||||||
isa = PBXFileReference;
|
|
||||||
path = HexWindow.h;
|
|
||||||
refType = 4;
|
|
||||||
};
|
|
||||||
F5EF83A5020C08E601A80001 = {
|
|
||||||
isa = PBXFileReference;
|
|
||||||
path = HexWindow.m;
|
|
||||||
refType = 4;
|
|
||||||
};
|
|
||||||
F5EF83A7020C08E601A80001 = {
|
F5EF83A7020C08E601A80001 = {
|
||||||
isa = PBXFileReference;
|
isa = PBXFileReference;
|
||||||
path = HexWindowController.h;
|
path = HexWindowController.h;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user