From 5f954b9187d03a23e2987ce28b44e115edf6725c Mon Sep 17 00:00:00 2001 From: Vladimir Samoylenko Date: Thu, 6 Dec 2018 23:23:00 +0200 Subject: [PATCH 1/2] Fix issue #61 feature request: Feature request: quit after all windows are closed #61 To activate featire check in menu Window -> Quit application on last window close --- Table Tool/Base.lproj/MainMenu.xib | 14 +++++++++++--- Table Tool/Document.m | 23 ++++++++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Table Tool/Base.lproj/MainMenu.xib b/Table Tool/Base.lproj/MainMenu.xib index 1f37440..484d2cf 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/Document.m b/Table Tool/Document.m index bbc7a46..8414219 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,7 @@ - (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; [self initValidPBoardTypes]; @@ -98,6 +100,11 @@ - (void)windowControllerDidLoadNib:(NSWindowController *)aController { - (void)close { [super close]; + + if (([self.windowControllers count] == 0) && (quitOnLastWindowClose == YES)){ + [NSApp terminate:self]; + } + } @@ -1152,4 +1159,18 @@ -(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; + + if (quitOnLastWindowClose == YES){ + [sender setState:NSControlStateValueOn]; + }else{ + [sender setState:NSControlStateValueOff]; + } + +} + + @end From 9fe2a2f1dbd8906d2be6f8dbea7e5ccc5d8d677a Mon Sep 17 00:00:00 2001 From: Vladimir Samoylenko Date: Sun, 30 Dec 2018 20:17:45 +0200 Subject: [PATCH 2/2] 30/12/2018 Added feature for saving state for Stefan Peters :) --- Table Tool/Base.lproj/MainMenu.xib | 2 +- Table Tool/Constants.h | 1 + Table Tool/Constants.m | 1 + Table Tool/Document.m | 24 ++++++++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Table Tool/Base.lproj/MainMenu.xib b/Table Tool/Base.lproj/MainMenu.xib index 484d2cf..a016015 100644 --- a/Table Tool/Base.lproj/MainMenu.xib +++ b/Table Tool/Base.lproj/MainMenu.xib @@ -655,7 +655,7 @@ 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 8414219..56079af 100644 --- a/Table Tool/Document.m +++ b/Table Tool/Document.m @@ -51,6 +51,25 @@ - (instancetype)init { _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]; [self addObserver:self forKeyPath:@"fileURL" options:0 context:nil]; @@ -66,6 +85,7 @@ -(void)dealloc { - (void)windowControllerDidLoadNib:(NSWindowController *)aController { [super windowControllerDidLoadNib:aController]; + dataCell = [self.tableView.tableColumns.firstObject dataCell]; [self updateTableColumns]; @@ -1164,6 +1184,10 @@ -(IBAction)quitApplicationOnLastWindowClose:(id)sender { quitOnLastWindowClose = !quitOnLastWindowClose; + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + [userDefaults setBool:quitOnLastWindowClose forKey:TTQuitOnLastWindowClose]; + [userDefaults synchronize]; + if (quitOnLastWindowClose == YES){ [sender setState:NSControlStateValueOn]; }else{