From 66649194b2ae55c279e27527f8de47eb2f0b1438 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 31 Oct 2010 10:26:51 -0400 Subject: [PATCH] Add a singleton |+instance| method to AppDelegate so we don't cast everywhere. --- Source/AppDelegate.h | 4 ++++ Source/AppDelegate.m | 5 +++++ Source/DebuggerConnection.m | 4 ++-- Source/NSXMLElementAdditions.m | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Source/AppDelegate.h b/Source/AppDelegate.h index a9919ee..c92978f 100644 --- a/Source/AppDelegate.h +++ b/Source/AppDelegate.h @@ -33,6 +33,10 @@ @property (readonly) BreakpointController* breakpoint; @property (readonly) LoggingController* loggingController; +// Returns the instance of this class that is acting as the application's +// delegate. ++ (AppDelegate*)instance; + - (IBAction)showDebuggerWindow:(id)sender; - (IBAction)showBreakpointWindow:(id)sender; - (IBAction)showPreferences:(id)sender; diff --git a/Source/AppDelegate.m b/Source/AppDelegate.m index 8239128..941d98a 100644 --- a/Source/AppDelegate.m +++ b/Source/AppDelegate.m @@ -47,6 +47,11 @@ [pool release]; } ++ (AppDelegate*)instance +{ + return (AppDelegate*)[NSApp delegate]; +} + /** * Shows the debugger window */ diff --git a/Source/DebuggerConnection.m b/Source/DebuggerConnection.m index f17697d..07fd033 100644 --- a/Source/DebuggerConnection.m +++ b/Source/DebuggerConnection.m @@ -425,7 +425,7 @@ void SocketAcceptCallback(CFSocketRef socket, - (LogEntry*)recordSend:(NSString*)command { - LoggingController* logger = [(AppDelegate*)[NSApp delegate] loggingController]; + LoggingController* logger = [[AppDelegate instance] loggingController]; LogEntry* entry = [LogEntry newSendEntry:command]; entry.lastReadTransactionID = lastReadTransaction_; entry.lastWrittenTransactionID = lastWrittenTransaction_; @@ -437,7 +437,7 @@ void SocketAcceptCallback(CFSocketRef socket, - (LogEntry*)recordReceive:(NSString*)command { - LoggingController* logger = [(AppDelegate*)[NSApp delegate] loggingController]; + LoggingController* logger = [[AppDelegate instance] loggingController]; LogEntry* entry = [LogEntry newReceiveEntry:command]; entry.lastReadTransactionID = lastReadTransaction_; entry.lastWrittenTransactionID = lastWrittenTransaction_; diff --git a/Source/NSXMLElementAdditions.m b/Source/NSXMLElementAdditions.m index f8a9a63..b3ea0b2 100644 --- a/Source/NSXMLElementAdditions.m +++ b/Source/NSXMLElementAdditions.m @@ -53,7 +53,7 @@ // If this node has children but they haven't been loaded from the backend, // request them asynchronously. if (![self isLeaf] && [children count] < 1) { - [[[(AppDelegate*)[NSApp delegate] debugger] connection] getProperty:[self fullname]]; + [[AppDelegate instance].debugger.connection getProperty:[self fullname]]; } return children; } -- 2.43.5