• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Command-click table in background app SOLVED
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Command-click table in background app SOLVED


  • Subject: Command-click table in background app SOLVED
  • From: Bill Cheeseman <email@hidden>
  • Date: Thu, 01 Jun 2006 08:32:57 -0400
  • Thread-topic: Command-click table in background app SOLVED

on 2006-05-31 9:14 AM, Bill Cheeseman at email@hidden wrote:

> But it still doesn't work when my app is in the background and I
> Command-click on the table.

My pursuit of the -acceptsFirstMouse: approach was a wild goose chase.

An old post from John Randolph about clickthrough in an NSMatrix set me on
the correct course. It turns out that NSTableView, like NSMatrix, interprets
Command-clicking on a table row to require that the clicked row be
deselected -- a bit of Mac UI lore that I had forgotten, or maybe never
knew. So, of course, I couldn't select a table row by Command-clicking it!

The solution is to subclass NSTableView and override -mouseDown: to deal
differently with a Command-click when the application is in the background,
like so:

@implementation PFClickthroughTableView

- (void)mouseDown:(NSEvent *)event {
    if (![NSApp isActive] && ([event modifierFlags] & NSCommandKeyMask)) {
        int row = [self rowAtPoint:[self convertPoint:[event
locationInWindow] fromView:nil]];
        if ([[self delegate] tableView:self shouldSelectRow:row]) {
            [self selectRowIndexes:[NSIndexSet indexSetWithIndex:row]
byExtendingSelection:NO];
            [self sendAction:[self action] to:nil];
        }
        return;
    }
    [super mouseDown:event];
}

@end

This is a special-purpose implementation of the technique. To use it in your
app, you would have to consider modifying it to take into account these
issues, and maybe others:

1. In my app, I want a Command-click to set the selected row. In another
app, you might want to select a column, instead, or something else.

2. I check the -tableView:shouldSelectRow: delegate method. NSTableView's
-selectRowIndexes:byExtendingSelection: does not check this delegate method
itself, but in my application I must do so because I use it to do some
interface tweaking. I haven't tested whether
-selectRowIndexes:byExtendingSelection: sends other delegate methods, such
as -selectionShouldChangeInTableView: or -tableViewSelectionDidChange:.
Anybody using this technique will need to explore this issue.

3. I send the table view's action method for a similar reason: my
application does have an action method for table views.

I would appreciate any thoughts on hidden dangers or better implementations.

--

Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com

PreFab Software - http://www.prefab.com/scripting.html
The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Command-click table in background app SOLVED
      • From: "John C. Randolph" <email@hidden>
    • Re: Command-click table in background app SOLVED
      • From: Bill Cheeseman <email@hidden>
  • Prev by Date: kMDItemTextContent for an item's content - no alternative?
  • Next by Date: Re: Writing NSString to a file
  • Previous by thread: Re: kMDItemTextContent for an item's content - no alternative?
  • Next by thread: Re: Command-click table in background app SOLVED
  • Index(es):
    • Date
    • Thread