forked from mgorbach/macfusion2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MFClientFSUI.m
123 lines (102 loc) · 4.3 KB
/
MFClientFSUI.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
//
// MFClientFSUI.m
// MacFusion2
//
// Created by Michael Gorbach on 3/30/08.
// Copyright 2008 Michael Gorbach. All rights reserved.
//
// 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 "MFClientFSUI.h"
#import "MFAdvancedViewController.h"
#import "MGTransitioningTabView.h"
#import "MFLogging.h"
NSString *kMFUIMainViewKey=@"main";
NSString *kMFUIAdvancedViewKey=@"advanced";
NSString *kMFUIMacfusionAdvancedViewKey=@"macfusion";
@implementation MFClientFS (MFClientFSUI)
- (NSViewController *)viewControllerForKey:(NSString *)key {
NSViewController *delegateViewController = [delegate viewControllerForKey:key];
if (delegateViewController) {
return delegateViewController;
}
// Macfusion's own keys
if (key == kMFUIMacfusionAdvancedViewKey) {
NSViewController *macfusionAdvancedController = [[MFAdvancedViewController alloc] initWithNibName:@"macfusionAdvancedView"bundle: [NSBundle bundleForClass: [self class]]];
[macfusionAdvancedController setTitle:@"Macfusion"];
return macfusionAdvancedController;
}
return nil;
}
- (NSArray *)configurationViewControllers {
if (!viewControllers) {
NSArray *configurationViewControllerKeys = [delegate viewControllerKeys];
NSMutableArray *configurationViewControllers = [NSMutableArray array];
if (!configurationViewControllerKeys || [configurationViewControllerKeys count] == 0) {
MFLogS(self, @"Delegate specifies no configuration view controllers!");
return nil;
}
for(NSString *key in configurationViewControllerKeys) {
NSViewController *delegateViewController = [self viewControllerForKey:key];
if (delegateViewController) {
[configurationViewControllers addObject: delegateViewController];
}
}
[configurationViewControllers makeObjectsPerformSelector:@selector(setRepresentedObject:) withObject:self];
viewControllers = [configurationViewControllers copy];
}
return viewControllers;
}
- (NSView *)addTopViewToView:(NSView *)originalView {
if (!topViewController) {
NSBundle *bundle = [NSBundle bundleForClass: [MFClientFS class]];
topViewController = [[NSViewController alloc] initWithNibName: @"topView" bundle: bundle];
[topViewController setRepresentedObject: self];
}
NSRect nameViewFrame = [[topViewController view] frame];
NSRect originalViewFrame = [originalView frame];
NSSize newViewSize = NSMakeSize( originalViewFrame.size.width, originalViewFrame.size.height + nameViewFrame.size.height);
NSView *newView = [NSView new];
[newView setFrameOrigin: NSMakePoint(0, 0)];
[newView setFrameSize: newViewSize];
[newView addSubview: [topViewController view]];
[newView addSubview: originalView];
[[topViewController view] setFrameOrigin: NSMakePoint( -11, originalViewFrame.size.height)];
[newView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
return newView;
}
- (NSView *)editingView {
NSArray *configurationViewControllers = [self configurationViewControllers];
if (!editingTabView) {
NSTabView *tabView = [MGTransitioningTabView new];
[tabView setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
[tabView setControlSize:NSSmallControlSize];
float view_width = 300;
float tabview_x = 20;
float tabview_y = 38;
if (configurationViewControllers && [configurationViewControllers count] > 0) {
for(NSViewController *viewController in configurationViewControllers) {
NSTabViewItem *tabViewItem = [NSTabViewItem new];
[tabViewItem setLabel:[viewController title] ? [viewController title] : @"No title"];
[tabViewItem setView:[viewController view]];
[tabView addTabViewItem:tabViewItem];
}
[tabView setFrame:NSMakeRect( 0, 0, tabview_x+view_width, tabview_y+150 )];
editingTabView = tabView;
} else {
MFLogSO(self, @"No view loaded for fs %@", [self name]);
return nil;
}
}
return editingTabView;
}
@end