-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOfflineViewQueue.m
72 lines (62 loc) · 2.2 KB
/
OfflineViewQueue.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// OfflineViewQueue.m
// Hachidori
//
// Created by 桐間紗路 on 2017/01/08.
// Copyright 2009-2017 MAL Updater OS X Group and James Moy All rights reserved. Code licensed under New BSD License
//
#import "OfflineViewQueue.h"
@interface OfflineViewQueue ()
@end
@implementation OfflineViewQueue
@synthesize delegate;
@dynamic managedObjectContext;
- (NSManagedObjectContext *)managedObjectContext {
AppDelegate *appDelegate = (AppDelegate *)[NSApplication sharedApplication].delegate;
return appDelegate.managedObjectContext;
}
- (instancetype)init{
self = [super initWithWindowNibName:@"OfflineViewQueue"];
if(!self)
return nil;
return self;
}
- (void)windowDidLoad {
[super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}
- (IBAction)clearqueue:(id)sender
{
// Set Up Prompt Message Window
NSAlert * alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Yes"];
[alert addButtonWithTitle:@"No"];
alert.messageText = @"Are you sure you want to clear the Offline Queue?";
alert.informativeText = @"Once done, this action cannot be undone.";
// Set Message type to Warning
alert.alertStyle = NSWarningAlertStyle;
// Show as Sheet on historywindow
[alert beginSheetModalForWindow:self.window
modalDelegate:self
didEndSelector:@selector(clearhistoryended:code:conext:)
contextInfo:NULL];
}
- (void)clearhistoryended:(NSAlert *)alert
code:(int)echoice
conext:(void *)v
{
if (echoice == 1000) {
// Remove All Data
NSManagedObjectContext *moc = self.managedObjectContext;
NSFetchRequest * allQueue = [[NSFetchRequest alloc] init];
allQueue.entity = [NSEntityDescription entityForName:@"OfflineQueue" inManagedObjectContext:moc];
NSError * error = nil;
NSArray * queue = [moc executeFetchRequest:allQueue error:&error];
//error handling goes here
for (NSManagedObject * item in queue) {
[moc deleteObject:item];
}
[moc save:&error];
}
}
@end