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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
/*
Grr RSS Reader
Copyright (C) 2006, 2007 Guenther Noack <guenther@unix-ag.uni-kl.de>
Copyright (C) 2009 GNUstep Application Team
Riccardo Mottola
This application 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 3 of the License, or (at your option) any later version.
This application 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
Library General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#import "PreferencesPanel.h"
#import "NSBundle+Extensions.h"
#ifdef __APPLE__
#import "GNUstep.h"
#endif
@implementation PreferencesPanel
// ---------------------------------
// init and dealloc
// ---------------------------------
-(id) init
{
if ((self = [super init]) != nil)
{
NSToolbar *toolbar;
BOOL nibLoaded;
nibLoaded = [NSBundle loadNibNamed:@"PreferencesPanel" owner:self];
if (nibLoaded == NO)
{
NSLog(@"PreferencesPanel: Failed to load nib.");
return nil;
}
RETAIN(window);
RETAIN(replacableView);
ASSIGN(prefComponents, [NSMutableArray new]);
ASSIGN(toolbarItemIdentifiers, [NSMutableArray new]);
ASSIGN(toolbarItems, [NSMutableDictionary new]);
// Set up preferences
[self addPreferencesComponent: [NSBundle instanceForBundleWithName: @"Proxy"]];
[self addPreferencesComponent: [NSBundle instanceForBundleWithName: @"Fonts"]];
toolbar = [(NSToolbar*)[NSToolbar alloc] initWithIdentifier: @"pref panel toolbar"];
[toolbar autorelease];
[toolbar setDelegate: self];
[toolbar setAllowsUserCustomization: NO];
[window setToolbar: toolbar];
[window setFloatingPanel: YES];
}
return self;
}
-(void) dealloc
{
DESTROY(window);
DESTROY(replacableView);
DESTROY(prefComponents);
DESTROY(toolbarItemIdentifiers);
DESTROY(toolbarItems);
[super dealloc];
}
// ---------------------------------
// singleton
// ---------------------------------
+(PreferencesPanel*) shared
{
static PreferencesPanel* singleton = nil;
if (singleton == nil) {
ASSIGN(singleton, [PreferencesPanel new]);
}
return singleton;
}
// ---------------------------------
// adding new panels to the preference panel
// ---------------------------------
-(BOOL) addPreferencesComponent: (id<PreferencesComponent>) aPrefComponent
{
NSToolbarItem* item;
NSAssert(
[prefComponents count] == [toolbarItemIdentifiers count],
@"Internal inconsistency: Number of toolbar items != number of pref panes."
);
[prefComponents addObject: aPrefComponent];
item = [[NSToolbarItem alloc] initWithItemIdentifier: [aPrefComponent prefPaneName]];
[item setLabel: [aPrefComponent prefPaneName]];
[item setImage: [aPrefComponent prefPaneIcon]];
[item setAction: @selector(changeViewAction:)];
[item setTarget: self];
[toolbarItemIdentifiers addObject: [item itemIdentifier]];
[toolbarItems setObject: item forKey: [item itemIdentifier]];
return YES;
}
// ---------------------------------
// NSToolbar delegate
// ---------------------------------
- (NSToolbarItem*)toolbar: (NSToolbar*)toolbar
itemForItemIdentifier: (NSString*)itemIdentifier
willBeInsertedIntoToolbar: (BOOL)flag
{
return [toolbarItems objectForKey: itemIdentifier];
}
// required method
- (NSArray*) toolbarAllowedItemIdentifiers: (NSToolbar*)toolbar
{
return toolbarItemIdentifiers;
}
// required method
- (NSArray*) toolbarDefaultItemIdentifiers: (NSToolbar*)toolbar
{
return toolbarItemIdentifiers;
}
// makes it a completely "selectable" toolbar
- (NSArray*) toolbarSelectableItemIdentifiers: (NSToolbar*)toolbar
{
return toolbarItemIdentifiers;
}
// ---------------------------------
// window open & close
// ---------------------------------
-(void) open
{
[window makeKeyAndOrderFront: self];
}
-(void) close
{
[window close];
}
// ---------------------------------
// executed when a toolbar item is clicked
// ---------------------------------
-(void) changeViewAction: (NSToolbarItem*)sender
{
id<ViewProvidingComponent, NSObject> comp;
NSView* newView;
comp = [prefComponents objectAtIndex:
[toolbarItemIdentifiers indexOfObject: [sender itemIdentifier]]];
NSAssert1(
[comp conformsToProtocol: @protocol(ViewProvidingComponent)],
@"Component %@ should be a view providing component!", comp
);
newView = [comp view];
[newView setFrame: [replacableView frame]];
[[replacableView superview] replaceSubview: replacableView with: newView];
ASSIGN(replacableView, newView);
}
@end
|