Commits

Virgil Dupras committed b63aeee

Instantiate the main window controller and the sparkle update in-code rather than in MainMenu.xib.

  • Participants
  • Parent commits 2c25cfb
  • Branches xibless

Comments (0)

Files changed (7)

cocoa/controllers/PMAppDelegate.h

 #import <Sparkle/SUUpdater.h>
 #import "HSAboutBox.h"
 #import "PyPdfMasher.h"
+#import "PMMainWindow.h"
 
 @interface PMAppDelegate : NSObject
 {
-    IBOutlet SUUpdater *updater;
-    IBOutlet id mainWindow;
     PyPdfMasher *model;
+    PMMainWindow *mainWindow;
     HSAboutBox *aboutBox;
+    SUUpdater *updater;
 }
 
+@property (readwrite, retain) PyPdfMasher *model;
 @property (readwrite, retain) SUUpdater *updater;
-@property (readwrite, retain) id mainWindow;
-
-- (PyPdfMasher *)model;
+@property (readwrite, retain) PMMainWindow *mainWindow;
 
 - (void)openWebsite;
 - (void)openHelp;

cocoa/controllers/PMAppDelegate.m

 
 @implementation PMAppDelegate
 
+@synthesize model;
 @synthesize updater;
 @synthesize mainWindow;
 
 - (void)awakeFromNib
 {
+    [self setModel:[[[PyPdfMasher alloc] init] autorelease]];
+    [[self model] bindCallback:createCallback(@"FairwareView", self)];
+    [[ProgressController mainProgressController] setWorker:[self model]];
+    [self setUpdater:[[[SUUpdater alloc] init] autorelease]];
+    [self setMainWindow:[[[PMMainWindow alloc] initWithAppDelegate:self] autorelease]];
     [NSApp setMainMenu:createPMMainMenu_UI(self)];
-    // py has to be initialized "lazily" because awakeFromNib's order is undefined, so PMAppDelegate
-    // might be awoken after PMMainWindow, and PMMainWindow needs PyPdfMasher on its own awakeFromNib.
-    // However, we cannot initialize it to nil here because we might overwrite an already initialized
-    // PyPdfMasher.
     aboutBox = nil; // Lazily loaded
+    [[self mainWindow] showWindow:nil];
 }
 
 - (void)dealloc
 {
     [aboutBox release];
-    [model release];
     [super dealloc];
 }
 
-- (PyPdfMasher *)model {
-    if (model == nil) {
-        model = [[PyPdfMasher alloc] init];
-        [model bindCallback:createCallback(@"FairwareView", self)];
-        [[ProgressController mainProgressController] setWorker:model];
-    }
-    return model;
-}
-
 - (void)openWebsite
 {
     [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.hardcoded.net/pdfmasher/"]];

cocoa/controllers/PMMainWindow.h

 */
 
 #import <Cocoa/Cocoa.h>
+#import "PyPdfMasher.h"
 #import "PMEditPane.h"
 #import "PMBuildPane.h"
 #import "HSTextField.h"
 #import "PMElementTable.h"
 #import "PMPageController.h"
-#import "PMAppDelegate.h"
 #import "PMElementTableView.h"
 
+@class PMAppDelegate;
+
 @interface PMMainWindow : NSWindowController
 {
-    IBOutlet PMAppDelegate *appDelegate;
     NSTextField *openedFileLabelView;
     PMElementTableView *elementsTableView;
     NSTabView *topTabView;
 @property (readwrite, retain) NSTabView *topTabView;
 @property (readwrite, retain) NSTabView *bottomTabView;
 
-- (IBAction)loadPDF:(id)sender;
+- (id)initWithAppDelegate:(PMAppDelegate *)aAppDelegate;
+- (void)loadPDF;
 @end

cocoa/controllers/PMMainWindow.m

 @synthesize topTabView;
 @synthesize bottomTabView;
 
-- (void)awakeFromNib
+- (id)initWithAppDelegate:(PMAppDelegate *)aAppDelegate
 {
+    self = [super initWithWindow:nil];
     [self setWindow:createPMMainWindow_UI(self)];
-    app = [appDelegate model];
+    app = (PyPdfMasher *)[aAppDelegate model];
     openedFileLabel = [[HSTextField alloc] initWithPyRef:[app openedFileLabel] view:openedFileLabelView];
     elementTable = [[PMElementTable alloc] initWithPyRef:[app elementTable] tableView:elementsTableView];
     pageController = [[PMPageController alloc] initWithPyRef:[app pageController]];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jobStarted:) name:JobStarted object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jobInProgress:) name:JobInProgress object:nil];
     
-    [self showWindow:nil];
+    return self;
 }
 
 - (void)dealloc
     [super dealloc];
 }
 
-- (IBAction)loadPDF:(id)sender
+- (void)loadPDF
 {
     NSOpenPanel *op = [NSOpenPanel openPanel];
     [op setCanChooseFiles:YES];

cocoa/en.lproj/MainMenu.xib

 			<object class="NSCustomObject" id="1050">
 				<string key="NSClassName">NSApplication</string>
 			</object>
-			<object class="NSCustomObject" id="1038029352">
-				<string key="NSClassName">PMMainWindow</string>
-			</object>
 			<object class="NSCustomObject" id="905305363">
 				<string key="NSClassName">PMAppDelegate</string>
 			</object>
-			<object class="NSCustomObject" id="999396757">
-				<string key="NSClassName">SUUpdater</string>
-			</object>
 		</array>
 		<object class="IBObjectContainer" key="IBDocument.Objects">
 			<array class="NSMutableArray" key="connectionRecords">
 					</object>
 					<int key="connectionID">598</int>
 				</object>
-				<object class="IBConnectionRecord">
-					<object class="IBOutletConnection" key="connection">
-						<string key="label">appDelegate</string>
-						<reference key="source" ref="1038029352"/>
-						<reference key="destination" ref="905305363"/>
-					</object>
-					<int key="connectionID">597</int>
-				</object>
-				<object class="IBConnectionRecord">
-					<object class="IBOutletConnection" key="connection">
-						<string key="label">updater</string>
-						<reference key="source" ref="905305363"/>
-						<reference key="destination" ref="999396757"/>
-					</object>
-					<int key="connectionID">630</int>
-				</object>
-				<object class="IBConnectionRecord">
-					<object class="IBOutletConnection" key="connection">
-						<string key="label">mainWindow</string>
-						<reference key="source" ref="905305363"/>
-						<reference key="destination" ref="1038029352"/>
-					</object>
-					<int key="connectionID">631</int>
-				</object>
 			</array>
 			<object class="IBMutableOrderedSet" key="objectRecords">
 				<array key="orderedObjects">
 						<string key="objectName">Application</string>
 					</object>
 					<object class="IBObjectRecord">
-						<int key="objectID">543</int>
-						<reference key="object" ref="1038029352"/>
-						<reference key="parent" ref="0"/>
-					</object>
-					<object class="IBObjectRecord">
 						<int key="objectID">596</int>
 						<reference key="object" ref="905305363"/>
 						<reference key="parent" ref="0"/>
 					</object>
-					<object class="IBObjectRecord">
-						<int key="objectID">603</int>
-						<reference key="object" ref="999396757"/>
-						<reference key="parent" ref="0"/>
-					</object>
 				</array>
 			</object>
 			<dictionary class="NSMutableDictionary" key="flattenedProperties">
 				<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
 				<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
 				<string key="-3.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-				<string key="543.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
 				<string key="596.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-				<string key="603.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
 			</dictionary>
 			<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
 			<nil key="activeLocalization"/>
 				<object class="IBPartialClassDescription">
 					<string key="className">PMAppDelegate</string>
 					<string key="superclassName">NSObject</string>
-					<dictionary class="NSMutableDictionary" key="actions">
-						<string key="openHelp:">id</string>
-						<string key="openWebsite:">id</string>
-						<string key="showAboutBox:">id</string>
-					</dictionary>
-					<dictionary class="NSMutableDictionary" key="actionInfosByName">
-						<object class="IBActionInfo" key="openHelp:">
-							<string key="name">openHelp:</string>
-							<string key="candidateClassName">id</string>
-						</object>
-						<object class="IBActionInfo" key="openWebsite:">
-							<string key="name">openWebsite:</string>
-							<string key="candidateClassName">id</string>
-						</object>
-						<object class="IBActionInfo" key="showAboutBox:">
-							<string key="name">showAboutBox:</string>
-							<string key="candidateClassName">id</string>
-						</object>
-					</dictionary>
-					<dictionary class="NSMutableDictionary" key="outlets">
-						<string key="mainWindow">id</string>
-						<string key="updater">SUUpdater</string>
-					</dictionary>
-					<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
-						<object class="IBToOneOutletInfo" key="mainWindow">
-							<string key="name">mainWindow</string>
-							<string key="candidateClassName">id</string>
-						</object>
-						<object class="IBToOneOutletInfo" key="updater">
-							<string key="name">updater</string>
-							<string key="candidateClassName">SUUpdater</string>
-						</object>
-					</dictionary>
 					<object class="IBClassDescriptionSource" key="sourceIdentifier">
 						<string key="majorKey">IBProjectSource</string>
 						<string key="minorKey">./Classes/PMAppDelegate.h</string>
 					</object>
 				</object>
-				<object class="IBPartialClassDescription">
-					<string key="className">PMMainWindow</string>
-					<string key="superclassName">NSWindowController</string>
-					<object class="NSMutableDictionary" key="actions">
-						<string key="NS.key.0">loadPDF:</string>
-						<string key="NS.object.0">id</string>
-					</object>
-					<object class="NSMutableDictionary" key="actionInfosByName">
-						<string key="NS.key.0">loadPDF:</string>
-						<object class="IBActionInfo" key="NS.object.0">
-							<string key="name">loadPDF:</string>
-							<string key="candidateClassName">id</string>
-						</object>
-					</object>
-					<object class="NSMutableDictionary" key="outlets">
-						<string key="NS.key.0">appDelegate</string>
-						<string key="NS.object.0">PMAppDelegate</string>
-					</object>
-					<object class="NSMutableDictionary" key="toOneOutletInfosByName">
-						<string key="NS.key.0">appDelegate</string>
-						<object class="IBToOneOutletInfo" key="NS.object.0">
-							<string key="name">appDelegate</string>
-							<string key="candidateClassName">PMAppDelegate</string>
-						</object>
-					</object>
-					<object class="IBClassDescriptionSource" key="sourceIdentifier">
-						<string key="majorKey">IBProjectSource</string>
-						<string key="minorKey">./Classes/PMMainWindow.h</string>
-					</object>
-				</object>
-				<object class="IBPartialClassDescription">
-					<string key="className">SUUpdater</string>
-					<string key="superclassName">NSObject</string>
-					<object class="NSMutableDictionary" key="actions">
-						<string key="NS.key.0">checkForUpdates:</string>
-						<string key="NS.object.0">id</string>
-					</object>
-					<object class="NSMutableDictionary" key="actionInfosByName">
-						<string key="NS.key.0">checkForUpdates:</string>
-						<object class="IBActionInfo" key="NS.object.0">
-							<string key="name">checkForUpdates:</string>
-							<string key="candidateClassName">id</string>
-						</object>
-					</object>
-					<object class="NSMutableDictionary" key="outlets">
-						<string key="NS.key.0">delegate</string>
-						<string key="NS.object.0">id</string>
-					</object>
-					<object class="NSMutableDictionary" key="toOneOutletInfosByName">
-						<string key="NS.key.0">delegate</string>
-						<object class="IBToOneOutletInfo" key="NS.object.0">
-							<string key="name">delegate</string>
-							<string key="candidateClassName">id</string>
-						</object>
-					</object>
-					<object class="IBClassDescriptionSource" key="sourceIdentifier">
-						<string key="majorKey">IBProjectSource</string>
-						<string key="minorKey">./Classes/SUUpdater.h</string>
-					</object>
-				</object>
 			</array>
 		</object>
 		<int key="IBDocument.localizationMode">0</int>

cocoa/ui/main_menu.py

 appMenu.addSeparator()
 appMenu.addItem("Quit PdfMasher", Action(NSApp, 'terminate:'), 'cmd+q')
 
-fileMenu.addItem("Load PDF", Action(owner.mainWindow, 'loadPDF:'), 'cmd+o')
+fileMenu.addItem("Load PDF", Action(owner.mainWindow, 'loadPDF'), 'cmd+o')
 fileMenu.addItem("Close", Action(None, 'performClose:'), 'cmd+w')
 
 editMenu.addItem("Cut", Action(None, 'cut:'), 'cmd+x')

cocoa/ui/main_window.py

 owner.elementsTableView = elementsTable
 
 elementsTable.allowsMultipleSelection = True
-loadButton.action = Action(owner, 'loadPDF:')
+loadButton.action = Action(owner, 'loadPDF')
 
 loadButton.width = 87
 mainTabView.width = 660