ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/MacOSX/prefs_macosx.mm
Revision: 1.1
Committed: 2007-07-28T15:46:17Z (17 years, 3 months ago) by asvitkine
Branch: MAIN
Log Message:
more prefs stuff

File Contents

# User Rev Content
1 asvitkine 1.1 /*
2     * $Id: extfs_macosx.mm,v 1.9 2007/01/24 02:37:06 asvitkine Exp $
3     *
4     * prefs_macosx.mm - Enables access to SheepShaver preferences while
5     * SheepShaver is running (on Mac OS X).
6     *
7     * Copyright (C) 2007 Alexei Svitkine
8     *
9     * This program is free software; you can redistribute it and/or modify
10     * it under the terms of the GNU General Public License as published by
11     * the Free Software Foundation; either version 2 of the License, or
12     * (at your option) any later version.
13     *
14     * This program is distributed in the hope that it will be useful,
15     * but WITHOUT ANY WARRANTY; without even the implied warranty of
16     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     * GNU General Public License for more details.
18     *
19     * You should have received a copy of the GNU General Public License
20     * along with this program; if not, write to the Free Software
21     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22     */
23    
24    
25     #include "sysdeps.h"
26    
27     #include <Cocoa/Cocoa.h>
28    
29     #include "PrefsEditor.h"
30    
31     @interface SheepShaverMain : NSObject
32     NSArray *nibObjects;
33     NSWindow *prefsWindow;
34     @end
35    
36     @implementation SheepShaverMain
37    
38    
39     - (NSArray*) loadPrefsNibFile
40     {
41     NSNib *nib = [[NSNib alloc] initWithNibNamed:@"MainMenu" bundle:nil];
42     NSArray *objects = nil;
43    
44     if (![nib instantiateNibWithOwner:self topLevelObjects:&objects]) {
45     NSLog(@"Could not load Prefs NIB file!\n");
46     return nil;
47     }
48    
49     NSLog(@"%d objects loaded\n", [objects count]);
50    
51     // Release the raw nib data.
52     [nib release];
53    
54     // Release the top-level objects so that they are just owned by the array.
55     [objects makeObjectsPerformSelector:@selector(release)];
56    
57     prefsWindow = nil;
58     for (int i = 0; i < [objects count]; i++) {
59     NSObject *object = [objects objectAtIndex:i];
60     NSLog(@"Got %@", object);
61    
62     if ([object isKindOfClass:[NSWindow class]]) {
63     prefsWindow = (NSWindow *) object;
64     break;
65     }
66     }
67    
68     if (prefsWindow == nil) {
69     NSLog(@"Could not find NSWindow in Prefs NIB file!\n");
70     return nil;
71     }
72    
73     return objects;
74     }
75    
76    
77     - (void) openPreferences:(id)sender
78     {
79     if (nibObjects == nil) {
80     nibObjects = [self loadPrefsNibFile];
81     if (nibObjects == nil)
82     return;
83     [nibObjects retain];
84     }
85    
86     [NSApp runModalForWindow:prefsWindow];
87     }
88    
89     @end
90    
91     /*
92     * Initialization
93     */
94    
95     void prefs_init(void)
96     {
97     NSMenu *appMenu;
98     NSMenuItem *menuItem;
99    
100     appMenu = [[[NSApp mainMenu] itemAtIndex:0] submenu];
101     menuItem = [[NSMenuItem alloc] initWithTitle:@"Preferences..." action:@selector(openPreferences:) keyEquivalent:@","];
102     [appMenu insertItem:menuItem atIndex:2];
103     [appMenu insertItem:[NSMenuItem separatorItem] atIndex:3];
104     [menuItem release];
105    
106     [NSApp setDelegate:[[SheepShaverMain alloc] init]];
107     }
108    
109    
110     /*
111     * Deinitialization
112     */
113    
114     void prefs_exit(void)
115     {
116     }