/
GeniusWelcomePanel.m
88 lines (69 loc) · 2.32 KB
/
GeniusWelcomePanel.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Genius
Copyright (C) 2003-2006 John R Chang
Copyright (C) 2007-2008 Chris Miner
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
http://www.gnu.org/licenses/gpl.txt
*/
#import "GeniusWelcomePanel.h"
static NSString * GeniusWelcomePanelDontShowKey = @"dontShowQuizWelcome";
//! Standard NSWindowController subclass for handling the PreQuiz nib.
/*!
@todo Rename this clas to something without Panel in the name.
*/
@implementation GeniusWelcomePanel
//! Creates if needed the singleton GeniusWelcomePanel initializes it.
+ (GeniusWelcomePanel *) sharedWelcomePanel
{
static GeniusWelcomePanel * sController = nil;
if (sController == nil)
sController = [[GeniusWelcomePanel alloc] initWithWindowNibName:@"PreQuiz"];
return sController;
}
//! Presents PreQuiz window with helpful tips regarding memorization work.
/*!
Presents user with opportunity to set a perference that disables this view in the future.
*/
- (BOOL) runModal
{
static BOOL sHasSeenThisSession = NO;
if (sHasSeenThisSession)
return YES;
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
BOOL dontShowPref = [defaults boolForKey:GeniusWelcomePanelDontShowKey];
if (dontShowPref)
return YES;
[[self window] center];
int result = [NSApp runModalForWindow:[self window]];
[self close];
if (result == NSRunAbortedResponse)
return NO;
if ([dontRemindSwitch state] == NSOnState)
[defaults setBool:YES forKey:GeniusWelcomePanelDontShowKey];
sHasSeenThisSession = YES;
return YES;
}
//! The user has elected not to continue with the quiz.
- (IBAction)goBack:(id)sender
{
[NSApp abortModal];
}
//! The quiz should proceed.
- (IBAction)continue:(id)sender
{
[NSApp stopModal];
}
//! The window has been closed.
- (BOOL)windowShouldClose:(id)sender
{
[NSApp abortModal];
return YES;
}
@end