mirror of
https://github.com/nickshanks/ResKnife.git
synced 2024-06-15 00:29:29 +00:00
Added paste submenu to hex editor
This commit is contained in:
parent
819e72e9ee
commit
06b207c96d
6
Cocoa/English.lproj/Application.nib/info.nib
generated
6
Cocoa/English.lproj/Application.nib/info.nib
generated
|
@ -3,15 +3,15 @@
|
|||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>340 32 432 426 0 0 1024 746 </string>
|
||||
<string>159 91 432 426 0 0 1152 848 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>29</key>
|
||||
<string>59 443 347 44 0 0 1152 848 </string>
|
||||
</dict>
|
||||
<key>IBFramework Version</key>
|
||||
<string>248.0</string>
|
||||
<string>263.2</string>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5Q110</string>
|
||||
<string>5Q125</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
BIN
Cocoa/English.lproj/Application.nib/objects.nib
generated
BIN
Cocoa/English.lproj/Application.nib/objects.nib
generated
Binary file not shown.
17
Cocoa/Plug-Ins/Hex Editor/English.lproj/PasteMenu.nib/classes.nib
generated
Normal file
17
Cocoa/Plug-Ins/Hex Editor/English.lproj/PasteMenu.nib/classes.nib
generated
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
IBClasses = (
|
||||
{
|
||||
ACTIONS = {pasteAsASCII = id; pasteAsHex = id; pasteAsUnicode = id; };
|
||||
CLASS = FirstResponder;
|
||||
LANGUAGE = ObjC;
|
||||
SUPERCLASS = NSObject;
|
||||
},
|
||||
{
|
||||
CLASS = HexEditorDelegate;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {pasteSubmenu = NSMenu; };
|
||||
SUPERCLASS = NSObject;
|
||||
}
|
||||
);
|
||||
IBVersion = 1;
|
||||
}
|
21
Cocoa/Plug-Ins/Hex Editor/English.lproj/PasteMenu.nib/info.nib
generated
Normal file
21
Cocoa/Plug-Ins/Hex Editor/English.lproj/PasteMenu.nib/info.nib
generated
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
|
||||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>226 310 356 240 0 0 1152 848 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>5</key>
|
||||
<string>226 555 72 66 0 0 1152 848 </string>
|
||||
</dict>
|
||||
<key>IBFramework Version</key>
|
||||
<string>263.2</string>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>5</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5Q125</string>
|
||||
</dict>
|
||||
</plist>
|
BIN
Cocoa/Plug-Ins/Hex Editor/English.lproj/PasteMenu.nib/objects.nib
generated
Normal file
BIN
Cocoa/Plug-Ins/Hex Editor/English.lproj/PasteMenu.nib/objects.nib
generated
Normal file
Binary file not shown.
|
@ -11,6 +11,7 @@
|
|||
IBOutlet NSTextView *hex;
|
||||
IBOutlet NSTextView *offset;
|
||||
IBOutlet NSTextField *message;
|
||||
IBOutlet NSMenu *pasteSubmenu;
|
||||
|
||||
BOOL editedLow;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,20 @@
|
|||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
if( self ) editedLow = NO;
|
||||
if( !self ) return nil;
|
||||
|
||||
editedLow = NO;
|
||||
|
||||
// swap paste: menu item for my own paste submenu
|
||||
{
|
||||
NSMenu *editMenu = [[[NSApp mainMenu] itemAtIndex:2] submenu];
|
||||
NSMenuItem *pasteItem = [editMenu itemAtIndex:[editMenu indexOfItemWithTarget:nil andAction:@selector(paste:)]];
|
||||
[NSBundle loadNibNamed:@"PasteMenu" owner:self];
|
||||
[pasteItem setEnabled:YES];
|
||||
[pasteItem setKeyEquivalent:@""];
|
||||
[pasteItem setKeyEquivalentModifierMask:0];
|
||||
[editMenu setSubmenu:pasteSubmenu forItem:pasteItem];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -116,29 +129,6 @@
|
|||
|
||||
/* delegation methods */
|
||||
|
||||
// I'm going to try a lower level approach overriding NSResponder methods in the HexTextView class.
|
||||
|
||||
/*- (BOOL)textView:(NSTextView *)textView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString;
|
||||
{
|
||||
#warning Every time a character is typed or string pasted, the entire resource is duplicated, operated on and disposed of! Perhaps I could do this in a better way?
|
||||
NSMutableData *data = [NSMutableData dataWithData:[controller data]];
|
||||
NSMutableData *newData = [NSMutableData dataWithBytes:[replacementString cString] length:[replacementString cStringLength]];
|
||||
NSRange range;
|
||||
|
||||
NSLog( @"Delegate received:\ntextView: shouldChangeTextInRange:%@ replacementString:%@", NSStringFromRange(affectedCharRange), replacementString );
|
||||
|
||||
if( textView == hex ) range = [self byteRangeFromHexRange:affectedCharRange];
|
||||
else if( textView == ascii ) range = [self byteRangeFromAsciiRange:affectedCharRange];
|
||||
else return YES;
|
||||
|
||||
#warning Does not cater for delete, forward delete, etc.
|
||||
[data replaceBytesInRange:range withBytes:[newData bytes] length:[newData length]];
|
||||
|
||||
// update resource data - this causes a notification to be sent out, which the plug receives and acts upon to update the text views
|
||||
[[controller resource] setData:data];
|
||||
return NO;
|
||||
}*/
|
||||
|
||||
- (NSRange)textView:(NSTextView *)textView willChangeSelectionFromCharacterRange:(NSRange)oldSelectedCharRange toCharacterRange:(NSRange)newSelectedCharRange
|
||||
{
|
||||
NSRange hexRange, asciiRange, byteRange = NSMakeRange(0,0);
|
||||
|
|
|
@ -75,6 +75,28 @@
|
|||
[super setSelectedRange:newRange affinity:affinity stillSelecting:NO];
|
||||
}
|
||||
|
||||
/* NSText overrides */
|
||||
|
||||
- (void)paste:(id)sender
|
||||
{
|
||||
NSLog( @"paste:" );
|
||||
// be 'smart' - determine if the pasted text is in hex format, such as "5F 3E 04 8E" or ascii.
|
||||
// what about unicode? should I paste "00 63 00 64" as "63 64" ("Paste As ASCII" submenu item)?
|
||||
[super paste:sender];
|
||||
}
|
||||
|
||||
- (void)clear:(id)sender
|
||||
{
|
||||
NSRange selection = [self rangeForUserTextChange];
|
||||
if( selection.length > 0 )
|
||||
[self delete:sender];
|
||||
}
|
||||
|
||||
- (void)delete:(id)sender
|
||||
{
|
||||
[self deleteBackward:sender];
|
||||
}
|
||||
|
||||
/* NSResponder overrides */
|
||||
|
||||
- (void)insertText:(NSString *)string
|
||||
|
@ -82,6 +104,7 @@
|
|||
NSRange selection = [self rangeForUserTextChange], byteSelection;
|
||||
NSMutableData *data = [[[[self window] windowController] data] mutableCopy];
|
||||
NSData *replaceData = [NSData dataWithBytes:[string cString] length:[string cStringLength]];
|
||||
NSLog( @"insertText:" );
|
||||
|
||||
// get selection range
|
||||
if( self == (id) [[self delegate] hex] )
|
||||
|
@ -147,6 +170,7 @@
|
|||
{
|
||||
NSRange selection = [self rangeForUserTextChange], byteSelection;
|
||||
NSMutableData *data = [[[[self window] windowController] data] mutableCopy];
|
||||
NSLog( @"deleteBackward:" );
|
||||
|
||||
// get selection range
|
||||
if( self == (id) [[self delegate] hex] )
|
||||
|
@ -181,6 +205,7 @@
|
|||
{
|
||||
NSRange selection = [self rangeForUserTextChange], byteSelection;
|
||||
NSMutableData *data = [[[[self window] windowController] data] mutableCopy];
|
||||
NSLog( @"deleteForward:" );
|
||||
|
||||
// get selection range
|
||||
if( self == (id) [[self delegate] hex] )
|
||||
|
|
|
@ -716,6 +716,27 @@
|
|||
path = Categories;
|
||||
refType = 4;
|
||||
};
|
||||
F5606FDD02ACF2F701A8010C = {
|
||||
children = (
|
||||
F5606FDE02ACF2F701A8010C,
|
||||
);
|
||||
isa = PBXVariantGroup;
|
||||
name = PasteMenu.nib;
|
||||
path = "";
|
||||
refType = 4;
|
||||
};
|
||||
F5606FDE02ACF2F701A8010C = {
|
||||
isa = PBXFileReference;
|
||||
name = PasteMenu.nib;
|
||||
path = English.lproj/PasteMenu.nib;
|
||||
refType = 4;
|
||||
};
|
||||
F5606FDF02ACF2F701A8010C = {
|
||||
fileRef = F5606FDD02ACF2F701A8010C;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F5730B930159528A01000001 = {
|
||||
isa = PBXFileReference;
|
||||
path = defaults.plist;
|
||||
|
@ -925,6 +946,7 @@
|
|||
F5EF83AF020C08E601A80001,
|
||||
F5EF83C9020C20D801A80001,
|
||||
F54E6225021B6A0901A80001,
|
||||
F5606FDF02ACF2F701A8010C,
|
||||
);
|
||||
isa = PBXResourcesBuildPhase;
|
||||
};
|
||||
|
@ -3776,6 +3798,7 @@
|
|||
F5EF83A7020C08E601A80001,
|
||||
F5EF83A8020C08E601A80001,
|
||||
F5EF83C7020C20D701A80001,
|
||||
F5606FDD02ACF2F701A8010C,
|
||||
F54E6222021B6A0801A80001,
|
||||
F5EF83A9020C08E601A80001,
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue
Block a user