diff --git a/Applications/TextMate/resources/English.lproj/MainMenu.xib b/Applications/TextMate/resources/English.lproj/MainMenu.xib index 1eda3274..53a9e021 100644 --- a/Applications/TextMate/resources/English.lproj/MainMenu.xib +++ b/Applications/TextMate/resources/English.lproj/MainMenu.xib @@ -3,12 +3,12 @@ 1070 12C60 - 2844 + 3084 1187.34 625.00 com.apple.InterfaceBuilder.CocoaPlugin - 2844 + 3084 YES @@ -2393,9 +2393,6 @@ OakSubmenuController - - AppStartupController - NSFontManager @@ -2449,14 +2446,6 @@ 153 - - - delegate - - - - 615 - dockMenu @@ -2465,6 +2454,14 @@ 787 + + + delegate + + + + 806 + arrangeInFront: @@ -3721,14 +3718,6 @@ 597 - - - appController - - - - 612 - orderFrontFontPanel: @@ -5257,11 +5246,6 @@ - - 611 - - - 616 @@ -5712,7 +5696,6 @@ 594.IBPluginDependency 595.IBPluginDependency 609.IBPluginDependency - 611.IBPluginDependency 616.IBPluginDependency 618.IBPluginDependency 621.IBPluginDependency @@ -6012,7 +5995,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -6062,7 +6044,7 @@ - 805 + 806 @@ -6202,25 +6184,6 @@ ./Classes/AppController.h - - AppStartupController - NSObject - - appController - AppController - - - appController - - appController - AppController - - - - IBProjectSource - ./Classes/AppStartupController.h - - DocumentController NSObject diff --git a/Applications/TextMate/src/AppController Documents.mm b/Applications/TextMate/src/AppController Documents.mm index 9482133b..d3fe9857 100644 --- a/Applications/TextMate/src/AppController Documents.mm +++ b/Applications/TextMate/src/AppController Documents.mm @@ -10,8 +10,6 @@ OAK_DEBUG_VAR(AppController_Documents); -static NSString* const OakGlobalSessionInfo = @"OakGlobalSessionInfo"; - @implementation AppController (Documents) - (void)newDocument:(id)sender { @@ -202,18 +200,6 @@ static NSString* const OakGlobalSessionInfo = @"OakGlobalSessionInfo"; // = Application Termination = // =========================== -- (void)closeAllWindows:(id)sender -{ - D(DBF_AppController_Documents, bug("\n");); - @autoreleasepool { - for(NSWindow* window in [NSApp windows]) - { - if(window.isVisible) - [window close]; - } - } -} - - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender { D(DBF_AppController_Documents, bug("%s\n", [NSApp windows].description.UTF8String);); diff --git a/Applications/TextMate/src/AppController.h b/Applications/TextMate/src/AppController.h index 37d88940..c2414483 100644 --- a/Applications/TextMate/src/AppController.h +++ b/Applications/TextMate/src/AppController.h @@ -1,7 +1,3 @@ -extern NSString* const OakSessionDidChangeNotification; - -@class OakFilterWindowController; - namespace find_tags { enum @@ -43,8 +39,6 @@ namespace find_tags - (IBAction)newDocumentAndActivate:(id)sender; - (IBAction)openDocumentAndActivate:(id)sender; - -- (void)setup; @end @interface AppController (Documents) diff --git a/Applications/TextMate/src/AppController.mm b/Applications/TextMate/src/AppController.mm index 9f86b795..7ba174bc 100644 --- a/Applications/TextMate/src/AppController.mm +++ b/Applications/TextMate/src/AppController.mm @@ -3,21 +3,29 @@ #import "AboutWindowController.h" #import "InstallBundleItems.h" #import "TMPlugInController.h" -#import -#import -#import -#import -#import +#import "RMateServer.h" #import +#import +#import +#import +#import #import #import -#import #import +#import +#import #import +#import #import -#import +#import +#import #import +#import +#import #import +#import +#import +#import OAK_DEBUG_VAR(AppController); @@ -58,27 +66,142 @@ void OakOpenDocuments (NSArray* paths) document::show(documents); } +BOOL HasDocumentWindow (NSArray* windows) +{ + for(NSWindow* window in windows) + { + if([window.delegate isKindOfClass:[DocumentController class]]) + return YES; + } + return NO; +} + @interface AppController () -@property (nonatomic, retain) OakFilterWindowController* filterWindowController; -@property (nonatomic, retain) AboutWindowController* aboutWindowController; +@property (nonatomic) OakFilterWindowController* filterWindowController; +@property (nonatomic) AboutWindowController* aboutWindowController; +@property (nonatomic) BOOL didFinishLaunching; @end @implementation AppController -- (void)setup +- (void)userDefaultsDidChange:(id)sender { + BOOL disableRmate = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsDisableRMateServerKey]; + NSString* rmateInterface = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsRMateServerListenKey]; + int rmatePort = [[NSUserDefaults standardUserDefaults] integerForKey:kUserDefaultsRMateServerPortKey]; + setup_rmate_server(!disableRmate, [rmateInterface isEqualToString:kRMateServerListenRemote] ? INADDR_ANY : INADDR_LOOPBACK, rmatePort); +} + +- (void)applicationWillFinishLaunching:(NSNotification*)aNotification +{ + D(DBF_AppController, bug("\n");); + settings_t::set_default_settings_path([[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"tmProperties"] fileSystemRepresentation]); + settings_t::set_global_settings_path(path::join(path::home(), "Library/Application Support/TextMate/Global.tmProperties")); + + [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys: + @NO, @"ApplePressAndHoldEnabled", + @25, @"NSRecentDocumentsLimit", + nil]]; + RegisterDefaults(); + [[NSUserDefaults standardUserDefaults] setObject:@NO forKey:@"NSQuitAlwaysKeepsWindows"]; + + std::string dest = path::join(path::home(), "Library/Application Support/TextMate/Managed"); + if(!path::exists(dest)) + { + if(NSString* archive = [[NSBundle mainBundle] pathForResource:@"DefaultBundles" ofType:@"tbz"]) + { + int input, output; + std::string error; + + path::make_dir(dest); + + pid_t pid = network::launch_tbz(dest, input, output, error); + if(pid != -1) + { + int fd = open([archive fileSystemRepresentation], O_RDONLY); + if(fd != -1) + { + char buf[4096]; + ssize_t len; + while((len = read(fd, buf, sizeof(buf))) > 0) + { + if(write(input, buf, len) != len) + { + fprintf(stderr, "*** error wrting bytes to tar\n"); + break; + } + } + close(fd); + } + + if(!network::finish_tbz(pid, input, output, error)) + fprintf(stderr, "%s\n", error.c_str()); + } + else + { + fprintf(stderr, "%s\n", error.c_str()); + } + } + } + + bundles::build_index(path::join(path::home(), "Library/Application Support/TextMate/Cache")); + + [[TMPlugInController sharedInstance] loadAllPlugIns:nil]; + + BOOL disableSessionRestoreKeyDown = ([NSEvent modifierFlags] & NSShiftKeyMask) == NSShiftKeyMask; + BOOL disableSessionRestorePrefs = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsDisableSessionRestoreKey]; + if(!disableSessionRestoreKeyDown && !disableSessionRestorePrefs) + [DocumentController restoreSession]; +} + +- (BOOL)applicationShouldOpenUntitledFile:(NSApplication*)anApplication +{ + D(DBF_AppController, bug("\n");); + return self.didFinishLaunching; +} + +- (void)applicationDidFinishLaunching:(NSNotification*)aNotification +{ + D(DBF_AppController, bug("\n");); + + BOOL disableUntitledAtStartupPrefs = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsDisableNewDocumentAtStartupKey]; + disableUntitledAtStartupPrefs = disableUntitledAtStartupPrefs || getenv("OAK_DISABLE_UNTITLED_FILE") != NULL; + if(!disableUntitledAtStartupPrefs && !HasDocumentWindow([NSApp orderedWindows])) + [self newDocument:self]; + unsetenv("OAK_DISABLE_UNTITLED_FILE"); + + OakSubmitNewCrashReportsInBackground(REST_API @"/crashes"); + [BundlesManager sharedInstance]; // trigger periodic polling of remote bundle index + + SoftwareUpdate* swUpdate = [SoftwareUpdate sharedInstance]; + [swUpdate setSignee:key_chain_t::key_t("org.textmate.duff", "Allan Odgaard", "-----BEGIN PUBLIC KEY-----\nMIIBtjCCASsGByqGSM44BAEwggEeAoGBAPIE9PpXPK3y2eBDJ0dnR/D8xR1TiT9m\n8DnPXYqkxwlqmjSShmJEmxYycnbliv2JpojYF4ikBUPJPuerlZfOvUBC99ERAgz7\nN1HYHfzFIxVo1oTKWurFJ1OOOsfg8AQDBDHnKpS1VnwVoDuvO05gK8jjQs9E5LcH\ne/opThzSrI7/AhUAy02E9H7EOwRyRNLofdtPxpa10o0CgYBKDfcBscidAoH4pkHR\nIOEGTCYl3G2Pd1yrblCp0nCCUEBCnvmrWVSXUTVa2/AyOZUTN9uZSC/Kq9XYgqwj\nhgzqa8h/a8yD+ao4q8WovwGeb6Iso3WlPl8waz6EAPR/nlUTnJ4jzr9t6iSH9owS\nvAmWrgeboia0CI2AH++liCDvigOBhAACgYAFWO66xFvmF2tVIB+4E7CwhrSi2uIk\ndeBrpmNcZZ+AVFy1RXJelNe/cZ1aXBYskn/57xigklpkfHR6DGqpEbm6KC/47Jfy\ny5GEx+F/eBWEePi90XnLinytjmXRmS2FNqX6D15XNG1xJfjociA8bzC7s4gfeTUd\nlpQkBq2z71yitA==\n-----END PUBLIC KEY-----\n")]; + [swUpdate setChannels:[NSDictionary dictionaryWithObjectsAndKeys: + [NSURL URLWithString:REST_API @"/releases/release"], kSoftwareUpdateChannelRelease, + [NSURL URLWithString:REST_API @"/releases/beta"], kSoftwareUpdateChannelBeta, + [NSURL URLWithString:REST_API @"/releases/nightly"], kSoftwareUpdateChannelNightly, + nil]]; + + [TerminalPreferences updateMateIfRequired]; + + [self userDefaultsDidChange:nil]; // setup mate/rmate server + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDefaultsDidChange:) name:NSUserDefaultsDidChangeNotification object:[NSUserDefaults standardUserDefaults]]; + bundlesMenu.delegate = self; themesMenu.delegate = self; spellingMenu.delegate = self; - [NSApp setDelegate:self]; - if([AboutWindowController shouldShowChangesWindow]) { self.aboutWindowController = [[AboutWindowController alloc] init]; [self.aboutWindowController performSelector:@selector(showChangesWindow:) withObject:self afterDelay:0]; } + + self.didFinishLaunching = YES; } +// ========================= +// = Past Startup Delegate = +// ========================= + - (IBAction)newDocumentAndActivate:(id)sender { [NSApp activateIgnoringOtherApps:YES]; diff --git a/Applications/TextMate/src/AppStartup.h b/Applications/TextMate/src/AppStartup.h deleted file mode 100644 index b70718e1..00000000 --- a/Applications/TextMate/src/AppStartup.h +++ /dev/null @@ -1,10 +0,0 @@ -@class AppController; - -@interface AppStartupController : NSObject -{ - IBOutlet AppController* appController; - BOOL disableSessionRestore; -} -@property (nonatomic, retain) NSAppleEventDescriptor* openEvent; -@property (nonatomic, retain) NSArray* openDocumentsArray; -@end diff --git a/Applications/TextMate/src/AppStartup.mm b/Applications/TextMate/src/AppStartup.mm deleted file mode 100644 index 09e294ae..00000000 --- a/Applications/TextMate/src/AppStartup.mm +++ /dev/null @@ -1,165 +0,0 @@ -#import "AppStartup.h" -#import "AppController.h" -#import -#import "ODBEditorSuite.h" -#import "TMPlugInController.h" -#import "RMateServer.h" -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import -#import - -OAK_DEBUG_VAR(AppStartup); - -@implementation AppStartupController -- (void)userDefaultsDidChange:(id)sender -{ - BOOL disableRmate = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsDisableRMateServerKey]; - NSString* rmateInterface = [[NSUserDefaults standardUserDefaults] stringForKey:kUserDefaultsRMateServerListenKey]; - int rmatePort = [[NSUserDefaults standardUserDefaults] integerForKey:kUserDefaultsRMateServerPortKey]; - setup_rmate_server(!disableRmate, [rmateInterface isEqualToString:kRMateServerListenRemote] ? INADDR_ANY : INADDR_LOOPBACK, rmatePort); -} - -- (void)applicationWillFinishLaunching:(NSNotification*)aNotification -{ - D(DBF_AppStartup, bug("\n");); - settings_t::set_default_settings_path([[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"tmProperties"] fileSystemRepresentation]); - settings_t::set_global_settings_path(path::join(path::home(), "Library/Application Support/TextMate/Global.tmProperties")); - - [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys: - @NO, @"ApplePressAndHoldEnabled", - @25, @"NSRecentDocumentsLimit", - nil]]; - RegisterDefaults(); - [[NSUserDefaults standardUserDefaults] setObject:@NO forKey:@"NSQuitAlwaysKeepsWindows"]; - disableSessionRestore = ([NSEvent modifierFlags] & NSShiftKeyMask) == NSShiftKeyMask; - - std::string dest = path::join(path::home(), "Library/Application Support/TextMate/Managed"); - if(!path::exists(dest)) - { - if(NSString* archive = [[NSBundle mainBundle] pathForResource:@"DefaultBundles" ofType:@"tbz"]) - { - int input, output; - std::string error; - - path::make_dir(dest); - - pid_t pid = network::launch_tbz(dest, input, output, error); - if(pid != -1) - { - int fd = open([archive fileSystemRepresentation], O_RDONLY); - if(fd != -1) - { - char buf[4096]; - ssize_t len; - while((len = read(fd, buf, sizeof(buf))) > 0) - { - if(write(input, buf, len) != len) - { - fprintf(stderr, "*** error wrting bytes to tar\n"); - break; - } - } - close(fd); - } - - if(!network::finish_tbz(pid, input, output, error)) - fprintf(stderr, "%s\n", error.c_str()); - } - else - { - fprintf(stderr, "%s\n", error.c_str()); - } - } - } - - bundles::build_index(path::join(path::home(), "Library/Application Support/TextMate/Cache")); -} - -- (BOOL)application:(NSApplication*)theApplication openFile:(NSString*)aPath -{ - D(DBF_AppStartup, bug("%s\n", [aPath UTF8String]);); - self.openEvent = [[NSAppleEventManager sharedAppleEventManager] currentAppleEvent]; - self.openDocumentsArray = @[ aPath ]; - return YES; -} - -- (void)application:(NSApplication*)sender openFiles:(NSArray*)filenames -{ - D(DBF_AppStartup, bug("%s\n", [[filenames description] UTF8String]);); - self.openEvent = [[NSAppleEventManager sharedAppleEventManager] currentAppleEvent]; - self.openDocumentsArray = filenames; - [sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess]; -} - -- (BOOL)applicationShouldOpenUntitledFile:(NSApplication*)anApplication -{ - D(DBF_AppStartup, bug("\n");); - return NO; -} - -- (void)applicationDidFinishLaunching:(NSNotification*)aNotification -{ - D(DBF_AppStartup, bug("\n");); - - OakSubmitNewCrashReportsInBackground(REST_API @"/crashes"); - - [[TMPlugInController sharedInstance] loadAllPlugIns:nil]; - [self userDefaultsDidChange:nil]; // setup mate/rmate server - - [BundlesManager sharedInstance]; // trigger periodic polling of remote bundle index - - BOOL disableSessionRestorePrefs = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsDisableSessionRestoreKey]; - BOOL disableUntitledAtStartupPrefs = [[NSUserDefaults standardUserDefaults] boolForKey:kUserDefaultsDisableNewDocumentAtStartupKey]; - - BOOL didRestoreSession = !disableSessionRestorePrefs && !disableSessionRestore && [DocumentController restoreSession]; - BOOL didOpenDocuments = DidHandleODBEditorEvent([self.openEvent aeDesc]) || ([self.openDocumentsArray count] && (OakOpenDocuments(self.openDocumentsArray), YES)); - if(!disableUntitledAtStartupPrefs && !didRestoreSession && !didOpenDocuments && getenv("OAK_DISABLE_UNTITLED_FILE") == NULL) - document::show(document::create()); - - SoftwareUpdate* swUpdate = [SoftwareUpdate sharedInstance]; - [swUpdate setSignee:key_chain_t::key_t("org.textmate.duff", "Allan Odgaard", "-----BEGIN PUBLIC KEY-----\nMIIBtjCCASsGByqGSM44BAEwggEeAoGBAPIE9PpXPK3y2eBDJ0dnR/D8xR1TiT9m\n8DnPXYqkxwlqmjSShmJEmxYycnbliv2JpojYF4ikBUPJPuerlZfOvUBC99ERAgz7\nN1HYHfzFIxVo1oTKWurFJ1OOOsfg8AQDBDHnKpS1VnwVoDuvO05gK8jjQs9E5LcH\ne/opThzSrI7/AhUAy02E9H7EOwRyRNLofdtPxpa10o0CgYBKDfcBscidAoH4pkHR\nIOEGTCYl3G2Pd1yrblCp0nCCUEBCnvmrWVSXUTVa2/AyOZUTN9uZSC/Kq9XYgqwj\nhgzqa8h/a8yD+ao4q8WovwGeb6Iso3WlPl8waz6EAPR/nlUTnJ4jzr9t6iSH9owS\nvAmWrgeboia0CI2AH++liCDvigOBhAACgYAFWO66xFvmF2tVIB+4E7CwhrSi2uIk\ndeBrpmNcZZ+AVFy1RXJelNe/cZ1aXBYskn/57xigklpkfHR6DGqpEbm6KC/47Jfy\ny5GEx+F/eBWEePi90XnLinytjmXRmS2FNqX6D15XNG1xJfjociA8bzC7s4gfeTUd\nlpQkBq2z71yitA==\n-----END PUBLIC KEY-----\n")]; - [swUpdate setChannels:[NSDictionary dictionaryWithObjectsAndKeys: - [NSURL URLWithString:REST_API @"/releases/release"], kSoftwareUpdateChannelRelease, - [NSURL URLWithString:REST_API @"/releases/beta"], kSoftwareUpdateChannelBeta, - [NSURL URLWithString:REST_API @"/releases/nightly"], kSoftwareUpdateChannelNightly, - nil]]; - - self.openEvent = nil; - self.openDocumentsArray = nil; - unsetenv("OAK_DISABLE_UNTITLED_FILE"); - - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDefaultsDidChange:) name:NSUserDefaultsDidChangeNotification object:[NSUserDefaults standardUserDefaults]]; - [TerminalPreferences updateMateIfRequired]; - - [appController setup]; -} - -- (BOOL)applicationShouldHandleReopen:(NSApplication*)theApplication hasVisibleWindows:(BOOL)flag -{ - D(DBF_AppStartup, bug("%s\n", BSTR(flag));); - return NO; -} - -- (IBAction)newDocument:(id)sender -{ - // avoid NSDocumentController’s implementation -} - -- (BOOL)validateMenuItem:(NSMenuItem*)menuItem -{ - if([menuItem action] == @selector(newDocument:)) - return NO; - return YES; -} -@end \ No newline at end of file