• 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
Re: clickCount question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: clickCount question


  • Subject: Re: clickCount question
  • From: Julien Jalon <email@hidden>
  • Date: Sun, 20 Jul 2003 16:26:39 +0200

On Sunday, Jul 20, 2003, at 05:35 Europe/Paris, Koen van der Drift wrote:

Hi,

I use a NSTextView delegate (a window controller) to detect a change in the selection of the text. When the selection changes the controller updates another item in the window, that indicates the number of characters in the selection. Now what happens is that when the user doubleclicks in the text, the delegate gets two textViewDidChangeSelection notifications. So the text that displays the number of selected characters changes from the old value to zero to the new value. This doesn't look very nice, so I want to make sure that the item only changes when a double-click occured. How can I change MyTextView so the notification is sent unless a single click took place? Or can textViewDidChangeSelection figure out how many clicks occured?

I only found clickCount from NSEvent - is there a way to get the event in either solutions?


The problem is, on double click, you get 2 events (one with clickCount == 1 and one with clickCount == 2) and the 2 selection change notification which is normal and that you can't avoid. The idea would be to use an NSTimer to defer the selection change notification.

Something like this in your delegate:

[... delegate has a "_selectionChangeTimer" ivar ...]

// a better thing would be to calculate double click interval here
#define DOUBLECLICK_INTERVAL 0.5

- (void)selectionChanged:(NSTimer *)aTimer
{
_selectionChangeTimer = nil;
// do your stuff for selection change
}

- (void)textViewDidChangeSelection:(NSNotification *)aNotification
{
if(_selectionChangeTimer != nil) {
[_selectionChangeTimer invalidate];
}
_selectionChangeTimer = [NSTimer scheduledTimerWithTimeInterval:DOUBLECLICK_INTERVAL target:self selector:@selector(selectionChanged:) userInfo:nil repeats:NO];
}


--
Julien Jalon
http://www.julien-jalon.org/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: clickCount question
      • From: Ben Dougall <email@hidden>
References: 
 >clickCount question (From: Koen van der Drift <email@hidden>)

  • Prev by Date: Re: clickCount question
  • Next by Date: Re: Problem receiving key events in CLI created window
  • Previous by thread: clickCount question
  • Next by thread: Re: clickCount question
  • Index(es):
    • Date
    • Thread