From aa173c59f8c35fbbfeedc4b178cd0473d23d85d8 Mon Sep 17 00:00:00 2001 From: relikd Date: Wed, 15 Aug 2018 20:29:04 +0200 Subject: [PATCH] replaced initial nib with direct code call --- baRSS.xcodeproj/project.pbxproj | 21 ---- baRSS/AppDelegate.h | 30 ----- baRSS/AppDelegate.m | 132 -------------------- baRSS/AppHook.h | 6 +- baRSS/AppHook.m | 126 ++++++++++++++++++- baRSS/Base.lproj/Main.xib | 17 --- baRSS/Info.plist | 40 +++--- baRSS/Preferences/Feeds Tab/SettingsFeeds.m | 4 +- baRSS/StoreCoordinator.m | 6 +- baRSS/main.m | 4 +- 10 files changed, 157 insertions(+), 229 deletions(-) delete mode 100644 baRSS/AppDelegate.h delete mode 100644 baRSS/AppDelegate.m delete mode 100644 baRSS/Base.lproj/Main.xib diff --git a/baRSS.xcodeproj/project.pbxproj b/baRSS.xcodeproj/project.pbxproj index 110d4a2..34086f6 100644 --- a/baRSS.xcodeproj/project.pbxproj +++ b/baRSS.xcodeproj/project.pbxproj @@ -20,9 +20,7 @@ 546FC44421189975007CC3A3 /* SettingsGeneral.xib in Resources */ = {isa = PBXBuildFile; fileRef = 546FC44221189975007CC3A3 /* SettingsGeneral.xib */; }; 546FC4472118A8E6007CC3A3 /* Preferences.xib in Resources */ = {isa = PBXBuildFile; fileRef = 546FC4462118A8E6007CC3A3 /* Preferences.xib */; }; 5477D34E21233C62002BA27F /* FeedConfig+Ext.m in Sources */ = {isa = PBXBuildFile; fileRef = 5477D34D21233C62002BA27F /* FeedConfig+Ext.m */; }; - 54ACC28121061B3B0020715F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 54ACC28021061B3B0020715F /* AppDelegate.m */; }; 54ACC28621061B3C0020715F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 54ACC28521061B3C0020715F /* Assets.xcassets */; }; - 54ACC28921061B3C0020715F /* Main.xib in Resources */ = {isa = PBXBuildFile; fileRef = 54ACC28721061B3C0020715F /* Main.xib */; }; 54ACC28C21061B3C0020715F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 54ACC28B21061B3C0020715F /* main.m */; }; 54ACC29521061E270020715F /* FeedDownload.m in Sources */ = {isa = PBXBuildFile; fileRef = 54ACC29421061E270020715F /* FeedDownload.m */; }; 54ACC29821061FBA0020715F /* Preferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 54ACC29721061FBA0020715F /* Preferences.m */; }; @@ -55,11 +53,8 @@ 5477D34C21233C62002BA27F /* FeedConfig+Ext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FeedConfig+Ext.h"; sourceTree = ""; }; 5477D34D21233C62002BA27F /* FeedConfig+Ext.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "FeedConfig+Ext.m"; sourceTree = ""; }; 54ACC27C21061B3B0020715F /* baRSS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = baRSS.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 54ACC27F21061B3B0020715F /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - 54ACC28021061B3B0020715F /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 54ACC28321061B3B0020715F /* DBv1.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = DBv1.xcdatamodel; sourceTree = ""; }; 54ACC28521061B3C0020715F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 54ACC28821061B3C0020715F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/Main.xib; sourceTree = ""; }; 54ACC28A21061B3C0020715F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54ACC28B21061B3C0020715F /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 54ACC29321061E270020715F /* FeedDownload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FeedDownload.h; sourceTree = ""; }; @@ -155,8 +150,6 @@ 549369F421091E6D001AF895 /* python */, 544B011B2114EE9100386E5C /* AppHook.h */, 544B011C2114EE9100386E5C /* AppHook.m */, - 54ACC27F21061B3B0020715F /* AppDelegate.h */, - 54ACC28021061B3B0020715F /* AppDelegate.m */, 54FE73D1212316CD003EAC65 /* BarMenu.h */, 54FE73D2212316CD003EAC65 /* BarMenu.m */, 54FE73CE21220DEC003EAC65 /* StoreCoordinator.h */, @@ -167,7 +160,6 @@ 54209E932117325100F3B5EF /* DrawImage.m */, 546FC44D2118B357007CC3A3 /* Preferences */, 54ACC28521061B3C0020715F /* Assets.xcassets */, - 54ACC28721061B3C0020715F /* Main.xib */, 54ACC28A21061B3C0020715F /* Info.plist */, 54ACC28B21061B3C0020715F /* main.m */, 54ACC28221061B3B0020715F /* DBv1.xcdatamodeld */, @@ -261,7 +253,6 @@ 546FC43F21188C78007CC3A3 /* SettingsFeeds.xib in Resources */, 544FBD4921064DF0008A260C /* feedparser521.py in Resources */, 544FBD4721064B2F008A260C /* getFeed.py in Resources */, - 54ACC28921061B3C0020715F /* Main.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -278,7 +269,6 @@ 54ACC29521061E270020715F /* FeedDownload.m in Sources */, 5477D34E21233C62002BA27F /* FeedConfig+Ext.m in Sources */, 54ACC28C21061B3C0020715F /* main.m in Sources */, - 54ACC28121061B3B0020715F /* AppDelegate.m in Sources */, 54FE73D3212316CD003EAC65 /* BarMenu.m in Sources */, 544B011A2114B41200386E5C /* ModalSheet.m in Sources */, 54ACC29821061FBA0020715F /* Preferences.m in Sources */, @@ -292,17 +282,6 @@ }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXVariantGroup section */ - 54ACC28721061B3C0020715F /* Main.xib */ = { - isa = PBXVariantGroup; - children = ( - 54ACC28821061B3C0020715F /* Base */, - ); - name = Main.xib; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - /* Begin XCBuildConfiguration section */ 54ACC28E21061B3C0020715F /* Debug */ = { isa = XCBuildConfiguration; diff --git a/baRSS/AppDelegate.h b/baRSS/AppDelegate.h deleted file mode 100644 index c11cc79..0000000 --- a/baRSS/AppDelegate.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// The MIT License (MIT) -// Copyright (c) 2018 Oleg Geier -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -// of the Software, and to permit persons to whom the Software is furnished to do -// so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#import -#import - -@interface AppDelegate : NSObject -@property (readonly, strong) NSPersistentContainer *persistentContainer; -- (IBAction)saveAction:(id)sender; -@end - diff --git a/baRSS/AppDelegate.m b/baRSS/AppDelegate.m deleted file mode 100644 index 6c7061b..0000000 --- a/baRSS/AppDelegate.m +++ /dev/null @@ -1,132 +0,0 @@ -// -// The MIT License (MIT) -// Copyright (c) 2018 Oleg Geier -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -// of the Software, and to permit persons to whom the Software is furnished to do -// so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#import "AppDelegate.h" -#import "PyHandler.h" -#import "BarMenu.h" - -@interface AppDelegate () -@property (strong) BarMenu *barMenu; -@end - -@implementation AppDelegate - -- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - self.barMenu = [BarMenu new]; - [PyHandler prepare]; - printf("up and running\n"); -} - -- (void)applicationWillTerminate:(NSNotification *)aNotification { - [PyHandler shutdown]; -} - -#pragma mark - Core Data stack - -@synthesize persistentContainer = _persistentContainer; - -- (NSPersistentContainer *)persistentContainer { - // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it. - @synchronized (self) { - if (_persistentContainer == nil) { - _persistentContainer = [[NSPersistentContainer alloc] initWithName:@"DBv1"]; - [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) { - if (error != nil) { - NSLog(@"Couldn't read NSPersistentContainer: %@, %@", error, error.userInfo); - abort(); - } - }]; - NSUndoManager *um = [[NSUndoManager alloc] init]; - um.groupsByEvent = NO; - um.levelsOfUndo = 30; - _persistentContainer.viewContext.undoManager = um; - } - } - - return _persistentContainer; -} - -#pragma mark - Core Data Saving and Undo support - -- (IBAction)saveAction:(id)sender { - // Performs the save action for the application, which is to send the save: message to the application's managed object context. Any encountered errors are presented to the user. - NSManagedObjectContext *context = self.persistentContainer.viewContext; - - if (![context commitEditing]) { - NSLog(@"%@:%@ unable to commit editing before saving", [self class], NSStringFromSelector(_cmd)); - } - - NSError *error = nil; - if (context.hasChanges && ![context save:&error]) { - // Customize this code block to include application-specific recovery steps. - [[NSApplication sharedApplication] presentError:error]; - } -} - -- (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)window { - // Returns the NSUndoManager for the application. In this case, the manager returned is that of the managed object context for the application. - return self.persistentContainer.viewContext.undoManager; -} - -- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { - // Save changes in the application's managed object context before the application terminates. - NSManagedObjectContext *context = self.persistentContainer.viewContext; - - if (![context commitEditing]) { - NSLog(@"%@:%@ unable to commit editing to terminate", [self class], NSStringFromSelector(_cmd)); - return NSTerminateCancel; - } - - if (!context.hasChanges) { - return NSTerminateNow; - } - - NSError *error = nil; - if (![context save:&error]) { - - // Customize this code block to include application-specific recovery steps. - BOOL result = [sender presentError:error]; - if (result) { - return NSTerminateCancel; - } - - NSString *question = NSLocalizedString(@"Could not save changes while quitting. Quit anyway?", @"Quit without saves error question message"); - NSString *info = NSLocalizedString(@"Quitting now will lose any changes you have made since the last successful save", @"Quit without saves error question info"); - NSString *quitButton = NSLocalizedString(@"Quit anyway", @"Quit anyway button title"); - NSString *cancelButton = NSLocalizedString(@"Cancel", @"Cancel button title"); - NSAlert *alert = [[NSAlert alloc] init]; - [alert setMessageText:question]; - [alert setInformativeText:info]; - [alert addButtonWithTitle:quitButton]; - [alert addButtonWithTitle:cancelButton]; - - NSInteger answer = [alert runModal]; - - if (answer == NSAlertSecondButtonReturn) { - return NSTerminateCancel; - } - } - - return NSTerminateNow; -} - -@end diff --git a/baRSS/AppHook.h b/baRSS/AppHook.h index 4a6bdeb..3703247 100644 --- a/baRSS/AppHook.h +++ b/baRSS/AppHook.h @@ -21,7 +21,9 @@ // SOFTWARE. #import +#import -@interface AppHook : NSApplication - +@interface AppHook : NSApplication +@property (readonly, strong) NSPersistentContainer *persistentContainer; +- (IBAction)saveAction:(id)sender; @end diff --git a/baRSS/AppHook.m b/baRSS/AppHook.m index 5278eea..8187980 100644 --- a/baRSS/AppHook.m +++ b/baRSS/AppHook.m @@ -21,10 +21,133 @@ // SOFTWARE. #import "AppHook.h" +#import "PyHandler.h" +#import "BarMenu.h" + +@interface AppHook() +@property (strong) BarMenu *barMenu; +@end + +@implementation AppHook + +- (instancetype)init { + self = [super init]; + self.delegate = self; + return self; +} + +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + self.barMenu = [BarMenu new]; + [PyHandler prepare]; + printf("up and running\n"); +} + +- (void)applicationWillTerminate:(NSNotification *)aNotification { + [PyHandler shutdown]; +} + +- (IBAction)closePreferences:(id)sender { + NSLog(@"closing in %@", sender); +} + + +#pragma mark - Core Data stack + + +@synthesize persistentContainer = _persistentContainer; + +- (NSPersistentContainer *)persistentContainer { + // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it. + @synchronized (self) { + if (_persistentContainer == nil) { + _persistentContainer = [[NSPersistentContainer alloc] initWithName:@"DBv1"]; + [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) { + if (error != nil) { + NSLog(@"Couldn't read NSPersistentContainer: %@, %@", error, error.userInfo); + abort(); + } + }]; + NSUndoManager *um = [[NSUndoManager alloc] init]; + um.groupsByEvent = NO; + um.levelsOfUndo = 30; + _persistentContainer.viewContext.undoManager = um; + } + } + + return _persistentContainer; +} + + +#pragma mark - Core Data Saving and Undo support + + +- (IBAction)saveAction:(id)sender { + // Performs the save action for the application, which is to send the save: message to the application's managed object context. Any encountered errors are presented to the user. + NSManagedObjectContext *context = self.persistentContainer.viewContext; + + if (![context commitEditing]) { + NSLog(@"%@:%@ unable to commit editing before saving", [self class], NSStringFromSelector(_cmd)); + } + + NSError *error = nil; + if (context.hasChanges && ![context save:&error]) { + // Customize this code block to include application-specific recovery steps. + [[NSApplication sharedApplication] presentError:error]; + } +} + +- (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)window { + // Returns the NSUndoManager for the application. In this case, the manager returned is that of the managed object context for the application. + return self.persistentContainer.viewContext.undoManager; +} + +- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { + // Save changes in the application's managed object context before the application terminates. + NSManagedObjectContext *context = self.persistentContainer.viewContext; + + if (![context commitEditing]) { + NSLog(@"%@:%@ unable to commit editing to terminate", [self class], NSStringFromSelector(_cmd)); + return NSTerminateCancel; + } + + if (!context.hasChanges) { + return NSTerminateNow; + } + + NSError *error = nil; + if (![context save:&error]) { + + // Customize this code block to include application-specific recovery steps. + BOOL result = [sender presentError:error]; + if (result) { + return NSTerminateCancel; + } + + NSString *question = NSLocalizedString(@"Could not save changes while quitting. Quit anyway?", @"Quit without saves error question message"); + NSString *info = NSLocalizedString(@"Quitting now will lose any changes you have made since the last successful save", @"Quit without saves error question info"); + NSString *quitButton = NSLocalizedString(@"Quit anyway", @"Quit anyway button title"); + NSString *cancelButton = NSLocalizedString(@"Cancel", @"Cancel button title"); + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText:question]; + [alert setInformativeText:info]; + [alert addButtonWithTitle:quitButton]; + [alert addButtonWithTitle:cancelButton]; + + NSInteger answer = [alert runModal]; + + if (answer == NSAlertSecondButtonReturn) { + return NSTerminateCancel; + } + } + return NSTerminateNow; +} + + +#pragma mark - Event Handling, Forward Send Key Down Events + static NSEventModifierFlags fnKeyFlags = NSEventModifierFlagShift | NSEventModifierFlagControl | NSEventModifierFlagOption | NSEventModifierFlagCommand | NSEventModifierFlagFunction; -@implementation AppHook - (void) sendEvent:(NSEvent *)event { if ([event type] == NSEventTypeKeyDown) { if (!event.characters || event.characters.length == 0) { @@ -60,4 +183,5 @@ static NSEventModifierFlags fnKeyFlags = NSEventModifierFlagShift | NSEventModif } [super sendEvent:event]; } + @end diff --git a/baRSS/Base.lproj/Main.xib b/baRSS/Base.lproj/Main.xib deleted file mode 100644 index 8e44460..0000000 --- a/baRSS/Base.lproj/Main.xib +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/baRSS/Info.plist b/baRSS/Info.plist index ead7ad7..96f49c7 100644 --- a/baRSS/Info.plist +++ b/baRSS/Info.plist @@ -2,33 +2,33 @@ - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIconFile - + LSMultipleInstancesProhibited + CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 CFBundleName $(PRODUCT_NAME) - CFBundlePackageType - APPL - CFBundleShortVersionString - 1.0 + CFBundleInfoDictionaryVersion + 6.0 CFBundleVersion 1 - LSMinimumSystemVersion - $(MACOSX_DEPLOYMENT_TARGET) - LSUIElement - - NSHumanReadableCopyright - Copyright © 2018 relikd. All rights reserved. - NSMainNibFile - Main + CFBundleExecutable + $(EXECUTABLE_NAME) NSPrincipalClass AppHook + CFBundlePackageType + APPL + CFBundleIconFile + + LSUIElement + + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + NSHumanReadableCopyright + Copyright © 2018 relikd. All rights reserved. + CFBundleShortVersionString + 1.0 diff --git a/baRSS/Preferences/Feeds Tab/SettingsFeeds.m b/baRSS/Preferences/Feeds Tab/SettingsFeeds.m index aa485c0..5043ccc 100644 --- a/baRSS/Preferences/Feeds Tab/SettingsFeeds.m +++ b/baRSS/Preferences/Feeds Tab/SettingsFeeds.m @@ -21,7 +21,7 @@ // SOFTWARE. #import "SettingsFeeds.h" -#import "AppDelegate.h" +#import "AppHook.h" #import "FeedConfig+Ext.h" #import "ModalSheet.h" #import "ModalFeedEdit.h" @@ -43,7 +43,7 @@ static NSString *dragNodeType = @"baRSS-feed-drag"; - (void)viewDidLoad { [super viewDidLoad]; - self.dataStore.managedObjectContext = [(AppDelegate*)[NSApp delegate] persistentContainer].viewContext; + self.dataStore.managedObjectContext = [(AppHook*)NSApp persistentContainer].viewContext; self.undoManager = self.dataStore.managedObjectContext.undoManager; [self.outlineView registerForDraggedTypes:[NSArray arrayWithObject:dragNodeType]]; [self.dataStore setSortDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"sortIndex" ascending:YES]]]; diff --git a/baRSS/StoreCoordinator.m b/baRSS/StoreCoordinator.m index 8b54696..7fa4984 100644 --- a/baRSS/StoreCoordinator.m +++ b/baRSS/StoreCoordinator.m @@ -21,16 +21,16 @@ // SOFTWARE. #import "StoreCoordinator.h" -#import "AppDelegate.h" +#import "AppHook.h" @implementation StoreCoordinator + (NSManagedObjectContext*)getContext { - return [(AppDelegate*)[NSApp delegate] persistentContainer].viewContext; + return [(AppHook*)NSApp persistentContainer].viewContext; } + (void)save { - [(AppDelegate*)[NSApp delegate] saveAction:nil]; + [(AppHook*)NSApp saveAction:nil]; } + (void)deleteUnreferencedFeeds { diff --git a/baRSS/main.m b/baRSS/main.m index c38652e..2639d0c 100644 --- a/baRSS/main.m +++ b/baRSS/main.m @@ -21,7 +21,9 @@ // SOFTWARE. #import +#import "AppHook.h" int main(int argc, const char * argv[]) { - return NSApplicationMain(argc, argv); + [[AppHook sharedApplication] run]; + return 0; }