Archive for the ‘geekery’ Category

selectable NSToolbarItems and itemIdentifiers in Leopard

Saturday, February 23rd, 2008

Maybe it’s just me, but I couldn’t figure out how to specify an itemIdentifier for a toolbar item in Interface Builder 3.0 (OS X 10.5 Leopard). So I didn’t know what to return from the toolbar’s delegate method toolbarSelectableItemIdentifiers to flag items as selectable. Nor could I just flag an item as selectable directly in IB. The default identifiers given to the items are GUIDs and completely meaningless. I’m guessing these are just oversights in the newly-minted IB. (Prior to Leopard you couldn’t define toolbars in IB at all.)

I also didn’t google any obvious hits on this topic, so here’s my community contribution for today. Specify view tags on your toolbar items in IB instead of identifiers. Then implement toolbarSelectableItemIdentifiers in your delegate to check for the tags you want.

- (NSArray*) toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar
{
	// yarr. leopard be toyin' with me, yarr!
	static NSMutableArray* identifiers = nil;
	if (identifiers == nil) {
		NSArray* items = [toolbar items];
		identifiers = [[NSMutableArray alloc] init];
		for(NSToolbarItem* item in items) {
			if ([item tag] == 1 || [item tag] == 2) {
				[identifiers addObject:[item itemIdentifier]];
			}
		}
	}
	return identifiers;
}

I happened to have two toolbar items I wanted to be selectable, with tags 1 and 2. Modify to suit your needs …

The pirate-speak comment is of course critical to this method’s success.

svn ignore and XCode transient files

Monday, December 24th, 2007

Dipping my toes into the 3Trace project again … for future reference, (and because it’s weirdly hard to google this info) here’s my global-ignore setting in ~/.subversion/config:

global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store *~.nib *.pbxuser .xvpics build *.mode1 *.mode1v3

Stuff after .DS_Store is what I added. I think that’s what you want to keep svn from complaining about transient XCode/Infterface Builder files. According to the XCode docs, you might want to let .pbxuser files through. Will edit this if it turns out to be wrong.

(As an aside, there’s some discussion on Alex’s blog about iWork bundles and subversion. Apple blows away the .svn folder inside iWork document bundles when you save them, making them impossible/annoyingly hard to manage via subversion. I think I’m the only one who thinks they’re justified in doing that, even though I agree that it’s less than ideal behavior. =) )

vernacular mathematics

Friday, November 30th, 2007

Fascinating* talk by Ron Eglash, an “ethno-mathematician,” on his study of fractal organization in vernacular African architecture and urbanism, and also why the machine on which you’re reading this owes its existence to African divination.

* Fascinating, that is, if you’re a complete geek like me.

tricking Safari 2 to redraw its canvas

Thursday, October 11th, 2007

I’ve been having a redraw problem on Safari 2. The only solution I’d found so far that worked for me (found here) is to resize the window by 1 pixel and then resize it back. “Not pretty, but it works.”

This is also working for me:

awesomeness = 0;
safari2ForceRedraw = function() {
	if (awesomeness++ % 2) {
		jQuery('body').css('background', 'url(blank.gif) repeat');
	}
	else {
		jQuery('body').css('background', 'url(blank2.gif) repeat');
	}
}

Basically set the body (or some smaller element if you can get away with it) background to a copy of itself. I used jQuery but I’m guessing it’s not a critical part of this working.

It is critically important that you name the toggle variable “awesomeness.” ‘Cause that’s what Safari 2 is. And there’s more of it every time you call the function.