« The one-button mouse is dead! Long live the single button! | Main | On Mentor Systems »

A quickie bit of code

Normally, I'd package this more than just a slug of code, but this is too cool to delay and delay, editing and whatnot.

In the Finder, when you're dragging files from one window to another, after a while, the dragged-to window comes to the top, so that you can better figure out where to put it. This happens even if the Finder isn't the foreground app. This would be cool if other apps did this, as it's quite useful. And spiffy.

Cocoa has some very strange properties that others have commented on. First, it's not something you can simply read and remember. It's something you guess and reference, but that's a good thing. Second, if it's getting difficult, you're probably doing it wrong. Third, it's eerily easy to do difficult things, most of the time.

So, copying this behavior would be tough, requiring timers and extra events and such, right?

Given that this is the delegate for a window, which is called owningWindow, and you've also linked to Carbon (C'mon, all the cool kids mix and match!)

- (IBAction) stealTheShow:(id) sender;
{
    [owningWindow orderFrontRegardless];
}

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
    [self performSelector:@selector(stealTheShow:) withObject:self afterDelay:GetDblTime()/60.0];
    //SNIP...
}

- (void)draggingExited:(id <NSDraggingInfo>)sender
{
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(stealTheShow:) object:self];
    //SNIP...
}

Note to self: make or find a quick app that you can drag formatted text to, and it outputs the appropriate HTML, to preserve all the funky xCode-y formatting without jumping through a few hoops.

For those of you who can't read code, the translation is: Do awesome thing with almost no effort. That is all.

TrackBack

TrackBack URL for this entry:
http://unlogica.com/cgi-bin/mt/mt-tb.cgi/19

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on August 31, 2007 12:41 AM.

The previous post in this blog was The one-button mouse is dead! Long live the single button!.

The next post in this blog is On Mentor Systems.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.35