William Bowling is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this again1 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 | //
// AIAdvancedPreferences.m
// Adium
//
// Created by Evan Schoenberg on 4/7/07.
//
#import "AIAdvancedPreferences.h"
#import <Adium/AIAdvancedPreferencePane.h>
#import <Adium/KNShelfSplitView.h>
#import <Adium/AIModularPaneCategoryView.h>
#import <AIUtilities/AIImageTextCell.h>
#import <AIUtilities/AIViewAdditions.h>
#define KEY_ADVANCED_PREFERENCE_SELECTED_ROW @"Preference Advanced Selected Row"
#define KEY_ADVANCED_PREFERENCE_SHELF_WIDTH @"AdvancedPrefs:ShelfWidth"
@interface AIAdvancedPreferences ()
- (void)_configureAdvancedPreferencesTable;
@end
@implementation AIAdvancedPreferences
+ (AIPreferencePane *)preferencePane
{
[adium.preferenceController registerDefaults:[NSDictionary dictionaryWithObject:[NSNumber numberWithDouble:150]
forKey:KEY_ADVANCED_PREFERENCE_SHELF_WIDTH]
forGroup:PREF_GROUP_WINDOW_POSITIONS];
return [super preferencePane];
}
- (NSString *)paneIdentifier
{
return @"Advanced";
}
- (NSString *)paneName{
return AILocalizedString(@"Advanced", "Title of the messages preferences");
}
- (NSString *)nibName{
return @"AdvancedPreferences";
}
- (NSImage *)paneIcon
{
return [NSImage imageNamed:@"pref-advanced"];
}
/*!
* @brief Configure the preference view
*/
- (void)viewDidLoad
{
[shelf_splitView setFrame:[[shelf_splitView superview] frame]];
[shelf_splitView setShelfWidth:[[adium.preferenceController preferenceForKey:KEY_ADVANCED_PREFERENCE_SHELF_WIDTH
group:PREF_GROUP_WINDOW_POSITIONS] doubleValue]];
[tableView_categories accessibilitySetOverrideValue:AILocalizedString(@"Advanced Preference Categories", nil)
forAttribute:NSAccessibilityRoleDescriptionAttribute];
[self _configureAdvancedPreferencesTable];
}
- (void)viewWillClose
{
//Select the previously selected row
[adium.preferenceController setPreference:[NSNumber numberWithInteger:[tableView_categories selectedRow]]
forKey:KEY_ADVANCED_PREFERENCE_SELECTED_ROW
group:PREF_GROUP_WINDOW_POSITIONS];
[adium.preferenceController setPreference:[NSNumber numberWithDouble:[shelf_splitView shelfWidth]]
forKey:KEY_ADVANCED_PREFERENCE_SHELF_WIDTH
group:PREF_GROUP_WINDOW_POSITIONS];
//Close open panes
[loadedAdvancedPanes makeObjectsPerformSelector:@selector(closeView)];
[modularPane removeAllSubviews];
[loadedAdvancedPanes release]; loadedAdvancedPanes = nil;
[_advancedCategoryArray release]; _advancedCategoryArray = nil;
}
/*!
* @brief Returns an array containing all the available advanced preference views
*/
- (NSArray *)advancedCategoryArray
{
if (!_advancedCategoryArray) {
_advancedCategoryArray = [[[adium.preferenceController advancedPaneArray] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] retain];
}
return _advancedCategoryArray;
}
/*!
* @brief Displays the passed AIPreferencePane in the advanced preferences tab of our window
*/
- (void)configureAdvancedPreferencesForPane:(AIAdvancedPreferencePane *)preferencePane
{
//Close open panes
[loadedAdvancedPanes makeObjectsPerformSelector:@selector(closeView)];
[modularPane removeAllSubviews];
[loadedAdvancedPanes release]; loadedAdvancedPanes = nil;
//Load new panes
if (preferencePane) {
loadedAdvancedPanes = [[NSArray arrayWithObject:preferencePane] retain];
[modularPane setPanes:loadedAdvancedPanes];
}
}
/*!
* @brief Configure the advanced preference category table view
*/
- (void)_configureAdvancedPreferencesTable
{
[[tableView_categories enclosingScrollView] setAutohidesScrollers:YES];
AIImageTextCell *cell = [[[AIImageTextCell alloc] initTextCell:@""] autorelease];
[cell setFont:[NSFont systemFontOfSize:11]];
[cell setLineBreakMode:NSLineBreakByTruncatingTail];
[[tableView_categories tableColumnWithIdentifier:@"description"] setDataCell:cell];
//Select the previously selected row
NSInteger row = [[adium.preferenceController preferenceForKey:KEY_ADVANCED_PREFERENCE_SELECTED_ROW
group:PREF_GROUP_WINDOW_POSITIONS] integerValue];
if (row < 0 || row >= [tableView_categories numberOfRows]) row = 1;
[tableView_categories selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
[self tableViewSelectionDidChange:nil];
}
/*!
* @brief Return the number of accounts
*/
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
return [[self advancedCategoryArray] count];
}
/*!
* @brief Return the account description or image
*/
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
NSString *identifier = tableColumn.identifier;
if ([identifier isEqualToString:@"description"]) {
return [[[self advancedCategoryArray] objectAtIndex:row] label];
} else if ([identifier isEqualToString:@"image"]) {
[[tableColumn dataCell] setImageAlignment:NSImageAlignRight];
return [[[self advancedCategoryArray] objectAtIndex:row] image];
}
return nil;
}
/*!
* @brief Update our advanced preferences for the selected pane
*/
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
NSInteger row = [tableView_categories selectedRow];
if (row >= 0 && row < [[self advancedCategoryArray] count]) {
[self configureAdvancedPreferencesForPane:[[self advancedCategoryArray] objectAtIndex:row]];
}
}
@end
|