Skip to content

Commit

Permalink
ODB Input Manager installer is version sensitive
Browse files Browse the repository at this point in the history
The Integration prefs pane states which version of the input manager
currently is installed.  The Input Manager version is bumped from 1.0
to 1.1.
  • Loading branch information
nico authored and b4winckler committed Mar 1, 2008
1 parent 8ee6c93 commit 042108b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/MacVim/English.lproj/Preferences.nib/classes.nib

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified src/MacVim/English.lproj/Preferences.nib/keyedobjects.nib
Binary file not shown.
1 change: 1 addition & 0 deletions src/MacVim/MMPreferenceController.h
Expand Up @@ -22,6 +22,7 @@
IBOutlet NSPopUpButton *editors;
IBOutlet NSButton *installOdbButton;
IBOutlet NSButton *uninstallOdbButton;
IBOutlet NSTextField* obdBundleVersionLabel;

}

Expand Down
71 changes: 67 additions & 4 deletions src/MacVim/MMPreferenceController.m
Expand Up @@ -83,6 +83,10 @@ @interface MMPreferenceController (Private)
- (void)updateIntegrationPane;
- (void)setOdbEditorByName:(NSString *)name;
- (NSString *)odbEditorBundleIdentifier;
- (NSString *)odbBundleSourceDir;
- (NSString *)versionOfBundle:(NSString *)bundlePath;
- (NSString *)odbBundleInstalledVersion;
- (NSString *)odbBundleInstallVersion;
@end

@implementation MMPreferenceController
Expand Down Expand Up @@ -201,6 +205,8 @@ - (void)updateIntegrationPane
// user changes settings in terminal, the changes are reflected in the
// dialog)

NSString *versionString;

// Check if ODB path exists before calling isFilePackageAtPath: otherwise
// an error is output to stderr on Tiger.
BOOL odbIsInstalled =
Expand All @@ -210,16 +216,44 @@ - (void)updateIntegrationPane
// enable/disable buttons
if (odbIsInstalled) {
[installOdbButton setTitle:@"Update"];
[installOdbButton setEnabled:YES]; //XXX: only if there'a new version
[uninstallOdbButton setEnabled:YES];
[editors setEnabled:YES];

NSString *installVersion = [self odbBundleInstallVersion];
NSString *installedVersion = [self odbBundleInstalledVersion];
switch ([installedVersion compare:installVersion
options:NSNumericSearch]) {
case NSOrderedAscending:
versionString = [NSString stringWithFormat:
@"Latest version is %@, you have %@.",
installVersion, installedVersion];
[installOdbButton setEnabled:YES];
break;
case NSOrderedSame:
versionString = [NSString stringWithFormat:
@"Latest version is %@. You have the latest version.",
installVersion];
[installOdbButton setEnabled:NO];
break;
case NSOrderedDescending:
versionString = [NSString stringWithFormat:
@"Latest version is %@, you have %@.",
installVersion, installedVersion];
[installOdbButton setEnabled:NO];
break;
}
} else {
[installOdbButton setTitle:@"Install"];
[installOdbButton setEnabled:YES];
[uninstallOdbButton setEnabled:NO];
[editors setEnabled:NO];

versionString = [NSString stringWithFormat:@"Latest version is %@.",
[self odbBundleInstallVersion]];
}

[obdBundleVersionLabel setStringValue:versionString];

// make sure the right editor is selected on the popup button
NSString *selectedTitle = kOdbEditorNameNone;
NSArray* keys = [supportedOdbEditors
Expand Down Expand Up @@ -259,11 +293,40 @@ - (void)odbEditorChanged:(id)sender
[self setOdbEditorByName:[sender title]];
}

- (NSString *)odbBundleSourceDir
{
return [[[NSBundle mainBundle] resourcePath]
stringByAppendingString:@"/Edit in ODBEditor"];
}

// Returns the CFBundleVersion of a bundle. This assumes a bundle exists
// at bundlePath.
- (NSString *)versionOfBundle:(NSString *)bundlePath
{
// -[NSBundle initWithPath:] caches a bundle, so if the bundle is replaced
// with a new bundle on disk, we get the old version. So we can't use it :-(

NSString *infoPath = [bundlePath
stringByAppendingString:@"/Contents/Info.plist"];
NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:infoPath];
return [info objectForKey:@"CFBundleVersion"];
}

- (NSString *)odbBundleInstalledVersion
{
return [self versionOfBundle:ODBEDITOR_PATH];
}

- (NSString *)odbBundleInstallVersion
{
return [self versionOfBundle:[[self odbBundleSourceDir]
stringByAppendingString:@"/Edit in ODBEditor.bundle"]];
}

- (IBAction)installOdb:(id)sender
{
NSString *source = [[[NSBundle mainBundle] resourcePath]
stringByAppendingString: @"/Edit in ODBEditor"];

NSString *source = [self odbBundleSourceDir];

// It doesn't hurt to rm -rf the InputManager even if it's not there,
// the code is simpler that way.
NSArray *cmd = [NSArray arrayWithObjects:
Expand Down
6 changes: 3 additions & 3 deletions src/MacVim/edit-in-odb/Info.plist
Expand Up @@ -6,20 +6,20 @@
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>org.slashpunt.edit_in_odbeditor</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<string>1.1</string>
<key>NSPrincipalClass</key>
<string>EditInODBEditor</string>
</dict>
Expand Down

0 comments on commit 042108b

Please sign in to comment.