diff --git a/Table Tool/Base.lproj/MainMenu.xib b/Table Tool/Base.lproj/MainMenu.xib index 1f37440..a016015 100644 --- a/Table Tool/Base.lproj/MainMenu.xib +++ b/Table Tool/Base.lproj/MainMenu.xib @@ -1,7 +1,8 @@ - - + + - + + @@ -653,6 +654,13 @@ CA + + + + + + + diff --git a/Table Tool/Constants.h b/Table Tool/Constants.h index efe8c9c..6c76184 100644 --- a/Table Tool/Constants.h +++ b/Table Tool/Constants.h @@ -11,3 +11,4 @@ #pragma mark Pasteboard Types extern NSString *TTRowInternalPboardType; +extern NSString *TTQuitOnLastWindowClose; diff --git a/Table Tool/Constants.m b/Table Tool/Constants.m index 5acd612..dfd4d7b 100644 --- a/Table Tool/Constants.m +++ b/Table Tool/Constants.m @@ -11,3 +11,4 @@ #pragma mark Initializing Globals for Pasteboard Types NSString *TTRowInternalPboardType = @"Table Tool Row Internal PasteBoard Type"; +NSString *TTQuitOnLastWindowClose = @"TTQuitOnLastWindowClose"; diff --git a/Table Tool/Document.m b/Table Tool/Document.m index bbc7a46..56079af 100644 --- a/Table Tool/Document.m +++ b/Table Tool/Document.m @@ -26,7 +26,8 @@ @interface Document () { BOOL ignoreColumnDidMoveNotifications; BOOL newFile; BOOL enableEditing; - + BOOL quitOnLastWindowClose; + NSArray *validPBoardTypes; TTErrorViewController *errorController; @@ -48,6 +49,26 @@ - (instancetype)init { newFile = YES; errorCode5 = @"Your are not allowed to save while the input format has an error. Configure the format manually, until no error occurs."; _didSave = NO; + quitOnLastWindowClose = NO; + + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + quitOnLastWindowClose = [userDefaults boolForKey:TTQuitOnLastWindowClose]; + + if (quitOnLastWindowClose == YES){ + + NSMenu *mainMenu = [[NSApplication sharedApplication] mainMenu]; + NSMenu *appMenu = [[mainMenu itemAtIndex:5] submenu]; + + for (NSMenuItem *item in [appMenu itemArray]) { + + NSInteger tag = [item tag]; + + if (tag == 1){ + [item setState:YES]; + } + } + + } [self initValidPBoardTypes]; @@ -64,6 +85,7 @@ -(void)dealloc { - (void)windowControllerDidLoadNib:(NSWindowController *)aController { [super windowControllerDidLoadNib:aController]; + dataCell = [self.tableView.tableColumns.firstObject dataCell]; [self updateTableColumns]; @@ -98,6 +120,11 @@ - (void)windowControllerDidLoadNib:(NSWindowController *)aController { - (void)close { [super close]; + + if (([self.windowControllers count] == 0) && (quitOnLastWindowClose == YES)){ + [NSApp terminate:self]; + } + } @@ -1152,4 +1179,22 @@ -(IBAction)exportFile:(id)sender { -(IBAction)openReadme:(id)sender { [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://github.com/jakob/TableTool/blob/master/README.md"]]; } + +-(IBAction)quitApplicationOnLastWindowClose:(id)sender { + + quitOnLastWindowClose = !quitOnLastWindowClose; + + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + [userDefaults setBool:quitOnLastWindowClose forKey:TTQuitOnLastWindowClose]; + [userDefaults synchronize]; + + if (quitOnLastWindowClose == YES){ + [sender setState:NSControlStateValueOn]; + }else{ + [sender setState:NSControlStateValueOff]; + } + +} + + @end