Finished implenting custom browser support

With this change, another localized string for OTHER_BROWSER will be
needed as well.

I've also set the project to use 2 spaces for tabs by default since that
is the coding style you use in the project.
This commit is contained in:
James Hurst
2014-08-16 14:34:26 -04:00
parent be03656ce9
commit 8c1e6733e8
5 changed files with 62 additions and 12 deletions

View File

@@ -1510,7 +1510,9 @@
4C77E36515B84A240093A587 /* Frameworks */,
4C77E36315B84A240093A587 /* Products */,
);
indentWidth = 2;
sourceTree = "<group>";
tabWidth = 2;
};
4C77E36315B84A240093A587 /* Products */ = {
isa = PBXGroup;

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment defaultVersion="1080" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MPWorkflowSettingsController">
@@ -91,7 +91,7 @@
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ehI-gq-lsb">
<rect key="frame" x="116" y="113" width="134" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Default Browser" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" enabled="NO" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="7YX-EA-9KA" id="7Ip-sU-sAK">
<popUpButtonCell key="cell" type="push" title="Default Browser" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="7YX-EA-9KA" id="7Ip-sU-sAK">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" title="OtherViews" id="XgO-Tj-QjO">
@@ -129,4 +129,4 @@
</constraints>
</customView>
</objects>
</document>
</document>

View File

@@ -621,9 +621,17 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
if(!scheme) {
webURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", [selectedEntry.url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
}
[[NSWorkspace sharedWorkspace] openURL:webURL];
/* Add custom browser support */
//[[NSWorkspace sharedWorkspace] openURLs:@[webURL] withAppBundleIdentifier:@"org.mozilla.firefox" options:NSWorkspaceLaunchAsync additionalEventParamDescriptor:nil launchIdentifiers:NULL];
NSString *browserBundleID = [[NSUserDefaults standardUserDefaults] objectForKey:kMPSettingsKeyBrowserBundleId];
BOOL launched = NO;
if (browserBundleID) {
launched = [[NSWorkspace sharedWorkspace] openURLs:@[webURL] withAppBundleIdentifier:browserBundleID options:NSWorkspaceLaunchAsync additionalEventParamDescriptor:nil launchIdentifiers:NULL];
}
if (!launched) {
[[NSWorkspace sharedWorkspace] openURL:webURL];
}
}
}

View File

@@ -44,13 +44,26 @@
#pragma mark Actions
- (void)selectBrowser:(id)sender {
NSString *browserBundleId = [sender representedObject];
NSLog(@"New default Browser: %@", browserBundleId);
[[NSUserDefaults standardUserDefaults] setObject:browserBundleId forKey:kMPSettingsKeyBrowserBundleId];
[[NSUserDefaults standardUserDefaults] synchronize];
[self _updateBrowserSelection];
}
- (void)showCustomBrowserSelection:(id)sender {
NSAssert(NO,@"Not implemented!");
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setDirectoryURL:[NSURL URLWithString:@"/Applications"]];
[openPanel setAllowsMultipleSelection:NO];
[openPanel setCanChooseDirectories:NO];
[openPanel setCanChooseFiles:YES];
[openPanel setAllowedFileTypes:@[@"app"]];
[openPanel beginSheetModalForWindow:[[self view] window] completionHandler:^(NSInteger result) {
if(result == NSFileHandlingPanelOKButton) {
NSMenuItem *customBrowser = [[NSMenuItem alloc] init];
[customBrowser setRepresentedObject:[[NSBundle bundleWithPath:[[openPanel URL] path]] bundleIdentifier]];
[self selectBrowser:customBrowser];
}
}];
}
#pragma mark Helper
@@ -58,8 +71,15 @@
/* Use a delegate ? */
NSMenu *browserMenu = [[NSMenu alloc] init];
[self.browserPopup setMenu:browserMenu];
[browserMenu addItemWithTitle:NSLocalizedString(@"DEFAULT_BROWSER", "Default Browser") action:NULL keyEquivalent:@""];
NSMenuItem *defaultItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"DEFAULT_BROWSER", "Default Browser") action:@selector(selectBrowser:) keyEquivalent:@""];
[defaultItem setRepresentedObject:nil];
[defaultItem setTarget:self];
[browserMenu addItem:defaultItem];
NSString *currentDefaultBrowser = [[NSUserDefaults standardUserDefaults] objectForKey:kMPSettingsKeyBrowserBundleId];
NSMenuItem *selectedItem = defaultItem;
[browserMenu addItem:[NSMenuItem separatorItem]];
for(NSString *bundleIdentifier in [self _bundleIdentifierForHTTPS]) {
@@ -69,16 +89,36 @@
[browserItem setRepresentedObject:bundleIdentifier];
[browserItem setTarget:self];
[browserMenu addItem:browserItem];
if ([bundleIdentifier isEqualToString:currentDefaultBrowser]) {
selectedItem = browserItem;
}
}
if([[browserMenu itemArray] count] > 2) {
[browserMenu addItem:[NSMenuItem separatorItem]];
}
NSMenuItem *selectOtherBrowserItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"OTHER_BROWSER", "Selecte Browser")
if (currentDefaultBrowser != nil && selectedItem == defaultItem) {
NSString *bundlePath = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:currentDefaultBrowser];
if (bundlePath != nil) {
NSString *browserName = [[NSFileManager defaultManager] displayNameAtPath:bundlePath];
NSMenuItem *browserItem = [[NSMenuItem alloc] initWithTitle:browserName action:@selector(selectBrowser:) keyEquivalent:@""];
[browserItem setRepresentedObject:currentDefaultBrowser];
[browserItem setTarget:self];
[browserMenu addItem:browserItem];
selectedItem = browserItem;
}
}
NSMenuItem *selectOtherBrowserItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"OTHER_BROWSER", "Select Browser")
action:@selector(showCustomBrowserSelection:)
keyEquivalent:@""];
[selectOtherBrowserItem setTarget:self];
[browserMenu addItem:selectOtherBrowserItem];
[self.browserPopup selectItem:selectedItem];
}
- (NSArray *)_bundleIdentifierForHTTPS {

Binary file not shown.