<commit_before>#import <objc/runtime.h>
#import "SDMCommon.h"
#import "SDMVersioning.h"

#import "Safari/BrowserController.h"
#import "Safari/Application.h"
#import "SDDownloadManager.h"
#import "UIKitExtra/UIToolbarButton.h"

NSString * const kSDMAssociatedPortraitDownloadButton = @"kSDMAssociatedPortraitDownloadButton";
NSString * const kSDMAssociatedActionButton = @"kSDMAssociatedActionButton";
NSString * const kSDMAssociatedBookmarksButton = @"kSDMAssociatedBookmarksButton";

@interface BrowserController (SDMAdditions)
- (void)toggleDownloadManagerFromButtonBar;
@end

@interface BrowserButtonBar (Private)
- (NSArray *)buttonItems;
- (void)setButtonItems:(NSArray *)buttonItems;
- (void)registerButtonGroup:(int)group withButtons:(int *)buttons withCount:(int)count;
- (void)showButtonGroup:(int)group withDuration:(NSTimeInterval)duration;
@end

static NSString *portraitIconFilename(void) {
	NSString *name = @"Download";
	if(SDM$WildCat) return @"DownloadT.png";
	return SDMSystemVersionGE(_SDM_iOS_4_0) ? name : [name stringByAppendingString:@".png"];
}

static NSString *landscapeIconFilename(void) {
	NSString *name = @"DownloadSmall";
	return SDMSystemVersionGE(_SDM_iOS_4_0) ? name : [name stringByAppendingString:@".png"];
}

static void initCustomToolbar(void) {
	Class BrowserController = objc_getClass("BrowserController");
	Class BrowserButtonBar = objc_getClass("BrowserButtonBar");
	BrowserController *bcont = [BrowserController sharedBrowserController];
	BrowserButtonBar *buttonBar = MSHookIvar<BrowserButtonBar *>(bcont, "_buttonBar");
	CFMutableDictionaryRef _groups = MSHookIvar<CFMutableDictionaryRef>(buttonBar, "_groups");
	int cg = MSHookIvar<int>(buttonBar, "_currentButtonGroup");
	NSArray *_buttonItems = [buttonBar buttonItems];
	
	NSMutableArray *mutButtonItems = [_buttonItems mutableCopy];

	id x = [BrowserButtonBar imageButtonItemWithName:portraitIconFilename()
						     tag:61
						  action:@selector(toggleDownloadManagerFromButtonBar)
						  target:[NSValue valueWithNonretainedObject:[%c(BrowserController) sharedBrowserController]]];

	[mutButtonItems addObject:x];
	CFDictionaryRemoveValue(_groups, (void*)1);

	if(!SDM$WildCat) {
		// Landscape (non-iPad)
		id y = [BrowserButtonBar imageButtonItemWithName:landscapeIconFilename()
							     tag:62
							  action:@selector(toggleDownloadManagerFromButtonBar)
							  target:[NSValue valueWithNonretainedObject:[%c(BrowserController) sharedBrowserController]]];
		[mutButtonItems addObject:y];
		CFDictionaryRemoveValue(_groups, (void*)2);
	}

	
	[buttonBar setButtonItems:mutButtonItems];
	[mutButtonItems release];
	
	int portraitGroup[]  = {5, 7, 15, 1, 61, 3};
	int landscapeGroup[] = {6, 8, 16, 2, 62, 4};

	if(SDM$WildCat) { // The iPad has a different button order than the iPhone.
		portraitGroup[0] = 5;
		portraitGroup[1] = 7;
		portraitGroup[2] = 3;
		portraitGroup[3] = 1;
		portraitGroup[4] = 15;
		portraitGroup[5] = 61;<commit_msg>Tiny bit of clean-up - Don't unnecessarily fetch classes (Custom Toolbar (Old))<commit_after>#import <objc/runtime.h>
#import "SDMCommon.h"
#import "SDMVersioning.h"

#import "Safari/BrowserController.h"
#import "Safari/Application.h"
#import "SDDownloadManager.h"
#import "UIKitExtra/UIToolbarButton.h"

NSString * const kSDMAssociatedPortraitDownloadButton = @"kSDMAssociatedPortraitDownloadButton";
NSString * const kSDMAssociatedActionButton = @"kSDMAssociatedActionButton";
NSString * const kSDMAssociatedBookmarksButton = @"kSDMAssociatedBookmarksButton";

@interface BrowserController (SDMAdditions)
- (void)toggleDownloadManagerFromButtonBar;
@end

@interface BrowserButtonBar (Private)
- (NSArray *)buttonItems;
- (void)setButtonItems:(NSArray *)buttonItems;
- (void)registerButtonGroup:(int)group withButtons:(int *)buttons withCount:(int)count;
- (void)showButtonGroup:(int)group withDuration:(NSTimeInterval)duration;
@end

static NSString *portraitIconFilename(void) {
	NSString *name = @"Download";
	if(SDM$WildCat) return @"DownloadT.png";
	return SDMSystemVersionGE(_SDM_iOS_4_0) ? name : [name stringByAppendingString:@".png"];
}

static NSString *landscapeIconFilename(void) {
	NSString *name = @"DownloadSmall";
	return SDMSystemVersionGE(_SDM_iOS_4_0) ? name : [name stringByAppendingString:@".png"];
}

static void initCustomToolbar(void) {
	BrowserController *bcont = [SDM$BrowserController sharedBrowserController];
	BrowserButtonBar *buttonBar = MSHookIvar<BrowserButtonBar *>(bcont, "_buttonBar");
	CFMutableDictionaryRef _groups = MSHookIvar<CFMutableDictionaryRef>(buttonBar, "_groups");
	int cg = MSHookIvar<int>(buttonBar, "_currentButtonGroup");
	NSArray *_buttonItems = [buttonBar buttonItems];
	
	NSMutableArray *mutButtonItems = [_buttonItems mutableCopy];

	id x = [%c(BrowserButtonBar) imageButtonItemWithName:portraitIconFilename()
						     tag:61
						  action:@selector(toggleDownloadManagerFromButtonBar)
						  target:[NSValue valueWithNonretainedObject:[SDM$BrowserController sharedBrowserController]]];

	[mutButtonItems addObject:x];
	CFDictionaryRemoveValue(_groups, (void*)1);

	if(!SDM$WildCat) {
		// Landscape (non-iPad)
		id y = [%c(BrowserButtonBar) imageButtonItemWithName:landscapeIconFilename()
							     tag:62
							  action:@selector(toggleDownloadManagerFromButtonBar)
							  target:[NSValue valueWithNonretainedObject:[SDM$BrowserController sharedBrowserController]]];
		[mutButtonItems addObject:y];
		CFDictionaryRemoveValue(_groups, (void*)2);
	}

	
	[buttonBar setButtonItems:mutButtonItems];
	[mutButtonItems release];
	
	int portraitGroup[]  = {5, 7, 15, 1, 61, 3};
	int landscapeGroup[] = {6, 8, 16, 2, 62, 4};

	if(SDM$WildCat) { // The iPad has a different button order than the iPhone.
		portraitGroup[0] = 5;
		portraitGroup[1] = 7;
		portraitGroup[2] = 3;
		portraitGroup[3] = 1;
		portraitGroup[4] = 15;
		portraitGroup[5] = 61;
{'fraction_non_alphanumeric': 0.1190719890822245, 'fraction_numerical': 0.013647219379051518, 'mean_word_length': 7.009562841530054, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7296705', 'n_tokens_mistral': 2090, 'n_tokens_neox': 1853, 'n_words': 355}