| [13451] | 1 | //
|
|---|
| 2 | // PreferencesWindowController.m
|
|---|
| 3 | // issueXXX
|
|---|
| 4 | //
|
|---|
| 5 | // Created by Gary Palter on 2/18/10.
|
|---|
| 6 | // Copyright 2010 Clozure Associates. All rights reserved.
|
|---|
| 7 | //
|
|---|
| 8 |
|
|---|
| 9 | #import "PreferencesWindowController.h"
|
|---|
| 10 | #import "FontToNameTransformer.h"
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | @interface PreferencesWindowController (private)
|
|---|
| 14 | - (void)showGeneralPrefs:(id)sender;
|
|---|
| 15 | - (void)showAppearancePrefs:(id)sender;
|
|---|
| 16 | - (void)showDocumentationPrefs:(id)sender;
|
|---|
| 17 | - (void)showEncodingsPrefs:(id)sender;
|
|---|
| 18 | - (void)setContent:(PreferencesView *)view;
|
|---|
| 19 | @end
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | @implementation PreferencesWindowController
|
|---|
| 23 |
|
|---|
| 24 | - (id)init {
|
|---|
| 25 | [NSValueTransformer setValueTransformer:[[FontToNameTransformer alloc] init]
|
|---|
| 26 | forName:@"FontToName"];
|
|---|
| 27 | self = [self initWithWindowNibName:@"preferences"];
|
|---|
| 28 | return self;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | - (void)windowDidLoad {
|
|---|
| 32 | NSWindow *window = [self window];
|
|---|
| 33 | toolbar = [[NSToolbar alloc] initWithIdentifier:@"preferences-window-toolbar"];
|
|---|
| 34 | toolbar.delegate = self;
|
|---|
| 35 | [toolbar setSelectedItemIdentifier:@"appearance"];
|
|---|
| 36 | [window setToolbar:toolbar];
|
|---|
| 37 | [window setShowsToolbarButton:NO];
|
|---|
| 38 | [self showAppearancePrefs:nil];
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
|
|---|
| 42 | itemForItemIdentifier:(NSString *)itemIdentifier
|
|---|
| 43 | willBeInsertedIntoToolbar:(BOOL)willBeInserted {
|
|---|
| 44 | NSToolbarItem *item;
|
|---|
| 45 |
|
|---|
| 46 | if ([itemIdentifier isEqualToString:@"general"]) {
|
|---|
| 47 | item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
|
|---|
| 48 | [item setLabel:@"General"];
|
|---|
| 49 | [item setImage:[NSImage imageNamed:@"General"]];
|
|---|
| 50 | [item setTarget:self];
|
|---|
| 51 | [item setAction:@selector(showGeneralPrefs:)];
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | else if ([itemIdentifier isEqualToString:@"appearance"]) {
|
|---|
| 55 | item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
|
|---|
| 56 | [item setLabel:@"Appearance"];
|
|---|
| 57 | [item setImage:[NSImage imageNamed:@"Appearance"]];
|
|---|
| 58 | [item setTarget:self];
|
|---|
| 59 | [item setAction:@selector(showAppearancePrefs:)];
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | else if ([itemIdentifier isEqualToString:@"documentation"]) {
|
|---|
| 63 | item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
|
|---|
| 64 | [item setLabel:@"Documentation"];
|
|---|
| 65 | [item setImage:[NSImage imageNamed:@"Documentation"]];
|
|---|
| 66 | [item setTarget:self];
|
|---|
| 67 | [item setAction:@selector(showDocumentationPrefs:)];
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | else if ([itemIdentifier isEqualToString:@"encodings"]) {
|
|---|
| 71 | item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
|
|---|
| 72 | [item setLabel:@"Encodings"];
|
|---|
| 73 | [item setImage:[NSImage imageNamed:@"Encodings"]];
|
|---|
| 74 | [item setTarget:self];
|
|---|
| 75 | [item setAction:@selector(showEncodingsPrefs:)];
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | else {
|
|---|
| 79 | NSLog(@"Unknown item identifier -- %@", itemIdentifier);
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | return item;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {
|
|---|
| 86 | return [NSArray arrayWithObjects:@"general", @"appearance", @"documentation",
|
|---|
| 87 | @"encodings", nil];
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
|
|---|
| 91 | return [NSArray arrayWithObjects:@"general", @"appearance", @"documentation",
|
|---|
| 92 | @"encodings", nil];
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar {
|
|---|
| 96 | return [NSArray arrayWithObjects:@"general", @"appearance", @"documentation",
|
|---|
| 97 | @"encodings", nil];
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | - (void)showGeneralPrefs:(id)sender {
|
|---|
| 101 | [[self window] setTitle:@"General"];
|
|---|
| 102 | [self setContent:generalPrefs];
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | - (void)showAppearancePrefs:(id)sender {
|
|---|
| 106 | [[self window] setTitle:@"Appearance"];
|
|---|
| 107 | [self setContent:appearancePrefs];
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | - (void)showDocumentationPrefs:(id)sender {
|
|---|
| 111 | [[self window] setTitle:@"Documentation"];
|
|---|
| 112 | [self setContent:documentationPrefs];
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | - (void)showEncodingsPrefs:(id)sender {
|
|---|
| 116 | [[self window] setTitle:@"Encodings"];
|
|---|
| 117 | [self setContent:encodingsPrefs];
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | - (void)setContent:(PreferencesView *)view {
|
|---|
| 121 | NSWindow *window = [self window];
|
|---|
| 122 | [window setContentView:view];
|
|---|
| 123 |
|
|---|
| 124 | NSRect frame = [window frame];
|
|---|
| 125 | NSSize minSize = [window minSize];
|
|---|
| 126 | NSRect contentRect = [window contentRectForFrameRect:frame];
|
|---|
| 127 |
|
|---|
| 128 | CGFloat dy = view.height - contentRect.size.height;
|
|---|
| 129 |
|
|---|
| 130 | contentRect.origin.y -= dy;
|
|---|
| 131 | contentRect.size.height += dy;
|
|---|
| 132 |
|
|---|
| 133 | contentRect.size.width = (view.width > minSize.width) ? view.width : minSize.width;
|
|---|
| 134 |
|
|---|
| 135 | NSRect newFrame = [window frameRectForContentRect:contentRect];
|
|---|
| 136 | [window setFrame:newFrame display:YES animate:YES];
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 | - (void)showFontPanel:(id)sender {
|
|---|
| 141 | NSLog(@"-[PreferencesWindowController showFontPanel:] invoked");
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | - (void)startSwankListener:(id)sender {
|
|---|
| 145 | NSLog(@"-[PreferencesWindowController startSwankListener:] invoked");
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | @end
|
|---|