Skip to content

Instantly share code, notes, and snippets.

@csexton
Forked from atr000/menu.mm
Created December 17, 2009 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csexton/258830 to your computer and use it in GitHub Desktop.
Save csexton/258830 to your computer and use it in GitHub Desktop.
- (void)installButtonBeforeItem:(NSString *)beforeItem toToolbar:(NSString *)toolbarIdentifier
{
log_enter();
NSToolbar *toolbar = nil;
for (NSWindow *window in [NSApp orderedWindows]) {
if (NO == [[[window toolbar] identifier] isEqualToString:toolbarIdentifier]) continue;
toolbar = [window toolbar];
if ([toolbar respondsToSelector:@selector(onepasswordSetDelegate:)]) {
[toolbar setDelegate:[toolbar delegate]]; // this will call a swizzled method
}
else {
[toolbar setDelegate:[[OPBrowserToolbarDelegate alloc] initWithDelegate:[toolbar delegate]]];
}
}
// must do this only once as all changes are propagated across all toolbars with the same identifier
NSDictionary *settings = [toolbar configurationDictionary];
if ([self hide1PasswordButton]) return;
NSInteger buttonIndex = [self indexOf1PasswordButtonInToolbar:settings anchorItem:beforeItem];
settings = [self toolbarSettingsWithout1PasswordButton:settings];
if (settings) {
[toolbar setConfigurationFromDictionary:settings];
}
settings = [self toolbarSettings:settings with1PasswordButtonAtIndex:buttonIndex];
if (settings) {
[toolbar setConfigurationFromDictionary:settings];
}
// [toolbar validateVisibleItems];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment