replaced initial nib with direct code call

This commit is contained in:
relikd
2018-08-15 20:29:04 +02:00
parent c4110cd160
commit aa173c59f8
10 changed files with 157 additions and 229 deletions

View File

@@ -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 <Cocoa/Cocoa.h>
#import <CoreData/CoreData.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (readonly, strong) NSPersistentContainer *persistentContainer;
- (IBAction)saveAction:(id)sender;
@end

View File

@@ -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

View File

@@ -21,7 +21,9 @@
// SOFTWARE.
#import <Cocoa/Cocoa.h>
#import <CoreData/CoreData.h>
@interface AppHook : NSApplication
@interface AppHook : NSApplication <NSApplicationDelegate>
@property (readonly, strong) NSPersistentContainer *persistentContainer;
- (IBAction)saveAction:(id)sender;
@end

View File

@@ -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

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14113" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14113"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
<connections>
<outlet property="delegate" destination="Voe-Tx-rLC" id="GzC-gU-4Uq"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
</objects>
</document>

View File

@@ -2,33 +2,33 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
<string></string>
<key>LSMultipleInstancesProhibited</key>
<true/>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2018 relikd. All rights reserved.</string>
<key>NSMainNibFile</key>
<string>Main</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>NSPrincipalClass</key>
<string>AppHook</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleIconFile</key>
<string></string>
<key>LSUIElement</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2018 relikd. All rights reserved.</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
</dict>
</plist>

View File

@@ -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]]];

View File

@@ -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 {

View File

@@ -21,7 +21,9 @@
// SOFTWARE.
#import <Cocoa/Cocoa.h>
#import "AppHook.h"
int main(int argc, const char * argv[]) {
return NSApplicationMain(argc, argv);
[[AppHook sharedApplication] run];
return 0;
}