-
Notifications
You must be signed in to change notification settings - Fork 128
/
MFPreferencesController.m
128 lines (109 loc) · 4.61 KB
/
MFPreferencesController.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//
// MFPreferencesController.m
// MacFusion2
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import "MFPreferencesController.h"
#import "MFCore.h"
#import "MFClient.h"
#import "MFPreferences.h"
#import "MFLogging.h"
#define kMFPrefsPluginToolbarIdentifier @"Plugin"
#define kMFPrefsGeneralToolbarIdentifier @"General"
@implementation MFPreferencesController
- (id)initWithWindowNibName:(NSString *)name {
if (self = [super initWithWindowNibName: name]) {
_client = [MFClient sharedClient];
_sharedPreferences = [MFPreferences sharedPreferences];
}
return self;
}
- (NSArray *)prefsViews {
return [NSArray arrayWithObjects: pluginPrefsView, generalPrefsView, nil];
}
- (void)awakeFromNib {
[agentLoginItemButton setState:mfcGetStateForAgentLoginItem()];
[menuLoginItemButton setState:[_sharedPreferences getBoolForPreference: kMFPrefsAutoloadMenuling]];
NSString *macfuseVersion = mfcGetMacFuseVersion();
NSString *versionString = macfuseVersion ? [NSString stringWithFormat: @"MacFuse Version %@ Found", macfuseVersion] : @"MacFuse not Found!";
[fuseVersionTextField setStringValue: versionString];
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier: @"Preferences"];
[toolbar setDelegate:self];
[toolbar setAllowsUserCustomization:NO];
[toolbar setDisplayMode:NSToolbarDisplayModeIconAndLabel];
[[self window] setToolbar:toolbar];
_prefsViewSizes = [NSMapTable new];
_emptyView = [NSView new];
for(NSView *view in [self prefsViews]) {
NSValue *sizeValue = [NSValue valueWithSize:[view frame].size];
[_prefsViewSizes setObject:sizeValue forKey:view];
}
[self toolbarItemChanged:[[toolbar items] objectAtIndex:0]];
}
- (IBAction)loginItemCheckboxChanged:(id)sender {
if (sender == agentLoginItemButton) {
mfcSetStateForAgentLoginItem([sender state]);
} else if (sender == menuLoginItemButton) {
[[MFPreferences sharedPreferences] setBool:[sender state] forPreference:kMFPrefsAutoloadMenuling];
} else {
MFLogS(self, @"Invalid sender for loginItemCheckboxChanged");
}
}
# pragma mark Toolbar
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag {
NSToolbarItem *item = nil;
if (itemIdentifier == kMFPrefsPluginToolbarIdentifier) {
item = [[NSToolbarItem alloc] initWithItemIdentifier: kMFPrefsPluginToolbarIdentifier];
[item setLabel:@"Plugins"];
[item setImage:[NSImage imageNamed: @"NSAdvanced"]];
} else if (itemIdentifier == kMFPrefsGeneralToolbarIdentifier) {
item = [[NSToolbarItem alloc] initWithItemIdentifier: kMFPrefsGeneralToolbarIdentifier];
[item setLabel:@"General"];
[item setImage:[NSImage imageNamed: @"NSPreferencesGeneral"]];
}
[item setTarget:self];
[item setAction:@selector(toolbarItemChanged:)];
return item;
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
return [NSArray arrayWithObjects:kMFPrefsGeneralToolbarIdentifier, kMFPrefsPluginToolbarIdentifier, nil];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {
return [self toolbarAllowedItemIdentifiers:toolbar];
}
- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar {
return [self toolbarAllowedItemIdentifiers:toolbar];
}
- (IBAction)toolbarItemChanged:(id)sender {
NSView *newView;
if ([sender itemIdentifier] == kMFPrefsPluginToolbarIdentifier) {
newView = pluginPrefsView;
} else if ([sender itemIdentifier] == kMFPrefsGeneralToolbarIdentifier) {
newView = generalPrefsView;
} else {
return;
}
NSWindow *window = [self window];
NSSize size = [[_prefsViewSizes objectForKey: newView] sizeValue];
NSRect windowContentFrame = [window contentRectForFrameRect:[window frame]];
windowContentFrame.origin.y += windowContentFrame.size.height;
windowContentFrame.origin.y -= size.height;
windowContentFrame.size.width = size.width;
windowContentFrame.size.height = size.height;
NSRect newWindowFrame = [window frameRectForContentRect:windowContentFrame];
[[[self window] toolbar] setSelectedItemIdentifier:[sender itemIdentifier]];
[window setContentView:_emptyView];
[window setFrame:newWindowFrame display:YES animate:[window isVisible]];
[window setContentView:newView];
}
@end