Skip to content

Instantly share code, notes, and snippets.

@hoshi-takanori
Created December 31, 2013 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoshi-takanori/8193202 to your computer and use it in GitHub Desktop.
Save hoshi-takanori/8193202 to your computer and use it in GitHub Desktop.
Logging category of NSUndoManager class.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface NSUndoManager (Logging)
@end
@implementation NSUndoManager (Logging)
+ (void)load
{
NSArray *methodNames = @[
@"registerUndoWithTarget:selector:object:",
@"prepareWithInvocationTarget:",
@"canUndo",
@"canRedo",
@"undo",
@"undoNestedGroup",
@"redo",
@"setLevelsOfUndo:",
@"levelsOfUndo",
@"beginUndoGrouping",
@"endUndoGrouping",
@"groupsByEvent",
@"setGroupsByEvent:",
@"groupingLevel",
@"disableUndoRegistration",
@"enableUndoRegistration",
@"isUndoRegistrationEnabled",
@"isUndoing",
@"isRedoing",
@"removeAllActions",
@"removeAllActionsWithTarget:",
@"setActionName:",
@"redoActionName",
@"undoActionName",
@"redoMenuItemTitle",
@"undoMenuItemTitle",
@"redoMenuTitleForUndoActionName:",
@"undoMenuTitleForUndoActionName:",
@"runLoopModes",
@"setRunLoopModes:",
@"setActionIsDiscardable:",
@"undoActionIsDiscardable",
@"redoActionIsDiscardable"
];
for (NSString *name in methodNames) {
Method method1 = class_getInstanceMethod(self, NSSelectorFromString(name));
Method method2 = class_getInstanceMethod(self, NSSelectorFromString([@"hack_" stringByAppendingString:name]));
if (method1 != NULL && method2 != NULL) {
method_exchangeImplementations(method1, method2);
} else {
NSLog(@"skipping %@", name);
}
}
}
// Registering Undo Operations
-(void)hack_registerUndoWithTarget:(id)target selector:(SEL)selector object:(id)anObject
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_registerUndoWithTarget:target selector:selector object:anObject];
}
- (id)hack_prepareWithInvocationTarget:(id)target
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_prepareWithInvocationTarget:target];
}
// Checking Undo Ability
- (BOOL)hack_canUndo
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_canUndo];
}
- (BOOL)hack_canRedo
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_canRedo];
}
// Performing Undo and Redo
- (void)hack_undo
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_undo];
}
- (void)hack_undoNestedGroup
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_undoNestedGroup];
}
- (void)hack_redo
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_redo];
}
// Limiting the Undo Stack
- (void)hack_setLevelsOfUndo:(NSUInteger)levels
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_setLevelsOfUndo:levels];
}
- (NSUInteger)hack_levelsOfUndo
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_levelsOfUndo];
}
// Creating Undo Groups
- (void)hack_beginUndoGrouping
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_beginUndoGrouping];
}
- (void)hack_endUndoGrouping
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_endUndoGrouping];
}
- (BOOL)hack_groupsByEvent
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_groupsByEvent];
}
- (void)hack_setGroupsByEvent:(BOOL)groupsByEvent
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_setGroupsByEvent:groupsByEvent];
}
- (NSInteger)hack_groupingLevel
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_groupingLevel];
}
// Enabling and Disabling Undo
- (void)hack_disableUndoRegistration
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_disableUndoRegistration];
}
- (void)hack_enableUndoRegistration
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_enableUndoRegistration];
}
- (BOOL)hack_isUndoRegistrationEnabled
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_isUndoRegistrationEnabled];
}
// Checking Whether Undo or Redo Is Being Performed
- (BOOL)hack_isUndoing
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_isUndoing];
}
- (BOOL)hack_isRedoing
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_isRedoing];
}
// Clearing Undo Operations
- (void)hack_removeAllActions
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_removeAllActions];
}
- (void)hack_removeAllActionsWithTarget:(id)target
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_removeAllActionsWithTarget:target];
}
// Managing the Action Name
- (void)hack_setActionName:(NSString *)actionName
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_setActionName:actionName];
}
- (NSString *)hack_redoActionName
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_redoActionName];
}
- (NSString *)hack_undoActionName
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_undoActionName];
}
// Getting and Localizing the Menu Item Title
- (NSString *)hack_redoMenuItemTitle
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_redoMenuItemTitle];
}
- (NSString *)hack_undoMenuItemTitle
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_undoMenuItemTitle];
}
- (NSString *)hack_redoMenuTitleForUndoActionName:(NSString *)actionName
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_redoMenuTitleForUndoActionName:actionName];
}
- (NSString *)hack_undoMenuTitleForUndoActionName:(NSString *)actionName
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_undoMenuTitleForUndoActionName:actionName];
}
// Working with Run Loops
- (NSArray *)hack_runLoopModes
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_runLoopModes];
}
- (void)hack_setRunLoopModes:(NSArray *)runLoopModes
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_setRunLoopModes:runLoopModes];
}
// Discardable Undo and Redo Actions
- (void)hack_setActionIsDiscardable:(BOOL)discardable
{
NSLog(@"%@", NSStringFromSelector(_cmd));
[self hack_setActionIsDiscardable:discardable];
}
- (BOOL)hack_undoActionIsDiscardable
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_undoActionIsDiscardable];
}
- (BOOL)hack_redoActionIsDiscardable
{
NSLog(@"%@", NSStringFromSelector(_cmd));
return [self hack_redoActionIsDiscardable];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment