[Clickdrag-cvs] ClickDrag ClickDrag.h,1.3,1.4 ClickDrag.m,1.4,1.5
Status: Pre-Alpha
Brought to you by:
stevecheckoway
|
From: Steve C. <ste...@us...> - 2004-08-31 10:45:35
|
Update of /cvsroot/clickdrag/ClickDrag In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27502 Modified Files: ClickDrag.h ClickDrag.m Log Message: ClickDrag now has per application preferences. Index: ClickDrag.m =================================================================== RCS file: /cvsroot/clickdrag/ClickDrag/ClickDrag.m,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- ClickDrag.m 31 Aug 2004 08:20:59 -0000 1.4 +++ ClickDrag.m 31 Aug 2004 10:45:27 -0000 1.5 @@ -5,23 +5,28 @@ @implementation ClickDrag + (void) load { -#if 0 - Boolean b; - CFStringRef name = (CFStringRef)[[NSProcessInfo processInfo] processName]; + SEL finishedSel = @selector(finishedLaunching:); + NSString *nName = @"NSApplicationDidFinishLaunchingNotification"; - if (CFPreferencesGetAppBooleanValue(name, CFSTR("com.sc.clickdrag"), &b)) -#endif - { - [ClickDragWindow poseAsClass:[NSWindow class]]; - gClickDrag = [[ClickDrag alloc] init]; - } + [ClickDragWindow poseAsClass:[NSWindow class]]; + gClickDrag = [[ClickDrag alloc] init]; + [[NSNotificationCenter defaultCenter] addObserver:gClickDrag + selector:finishedSel + name:nName + object:nil]; } - (id) init { + Boolean dummy; + CFStringRef name = (CFStringRef)[[NSProcessInfo processInfo] processName]; + CFStringRef appID = CFSTR("com.sc.clickdrag"); + [super init]; mDragging = NO; mResizing = NO; + CFPreferencesAppSynchronize(appID); + mEnabled = CFPreferencesGetAppBooleanValue(name, appID, &dummy); return self; } @@ -34,10 +39,7 @@ int deltaX; int deltaY; - if (!window) - return NO; - - if ([window isSheet]) + if (!mEnabled || !window || [window isSheet]) return NO; switch (type) @@ -83,12 +85,12 @@ mX = location.x; mY = location.y; rect = [window frame]; - if (location.y < rect.size.height / 3) + if (mY < rect.size.height / 3) { mFromBottom = YES; mFromTop = NO; } - else if (location.y > 2 * rect.size.height / 3) + else if (mY > 2 * rect.size.height / 3) { mFromBottom = NO; mFromTop = YES; @@ -98,12 +100,12 @@ mFromBottom = NO; mFromTop = NO; } - if (location.x < rect.size.width / 3) + if (mX < rect.size.width / 3) { mFromLeft = YES; mFromRight = NO; } - else if (location.x > 2 * rect.size.width / 3) + else if (mX > 2 * rect.size.width / 3) { mFromLeft = NO; mFromRight = YES; @@ -245,9 +247,55 @@ } return YES; } + +- (void) changeCDState:(id)sender +{ + CFStringRef name = (CFStringRef)[[NSProcessInfo processInfo] processName]; + CFStringRef appID = CFSTR("com.sc.clickdrag"); + + mEnabled = !mEnabled; + [(id<NSMenuItem>)sender setTitle:(mEnabled ? @"Disable ClickDrag" : + @"Enable ClickDrag")]; + CFPreferencesSetAppValue(name, mEnabled ? kCFBooleanTrue : kCFBooleanFalse, + appID); + CFPreferencesAppSynchronize(appID); +} + +- (void) finishedLaunching:(NSNotification *)notification +{ + NSMenu *menu = [[[NSApp mainMenu] itemAtIndex:0] submenu]; + NSArray *items = [menu itemArray]; + id<NSMenuItem> item; + int index; + + for (index = 0; index < [items count]; ++index) + { + NSString *title = [(NSMenuItem *)[items objectAtIndex:index] title]; + + if ([title hasPrefix:@"Preferences"]) + break; + } + + if (index == [items count]) + --index; // before Quit + else + ++index; // after Preferences + item = [menu insertItemWithTitle:(mEnabled ? @"Disable ClickDrag" : + @"Enable ClickDrag") + action:@selector(changeCDState:) + keyEquivalent:@"" + atIndex:index]; + [item setTarget:self]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +- (BOOL) validateMenuItem:(id<NSMenuItem>)menuItem +{ + return YES; +} @end -ClickDrag *gClickDrag = nil; +ClickDrag *gClickDrag; /* * Copyright (c) 2004 Steve Checkoway Index: ClickDrag.h =================================================================== RCS file: /cvsroot/clickdrag/ClickDrag/ClickDrag.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- ClickDrag.h 31 Aug 2004 08:18:21 -0000 1.3 +++ ClickDrag.h 31 Aug 2004 10:45:27 -0000 1.4 @@ -14,11 +14,12 @@ */ @interface ClickDrag : NSObject { - @private; + @private BOOL mDragging; BOOL mResizing; BOOL mFromBottom, mFromTop, mFromRight, mFromLeft; int mX, mY; + BOOL mEnabled; } /*! @method @@ -43,6 +44,27 @@ process the event as it sees fit. */ - (BOOL) handleEvent:(NSEvent *)event forWindow:(NSWindow *)window; + +/*! + @method + @abstract Invoked when the menu item is selected. + @discussion Updates the preferences based on the current value. +*/ +- (void) changeCDState:(id)sender; + +/*! + @method + @abstract Called when the application finishes launching. + @discussion This method sets up the ClickDrag menu item. +*/ +- (void) finishedLaunching:(NSNotification *)notification; + +/*! + @method + @abstract Always returns YES. + @discussion Always returns YES. +*/ +- (BOOL) validateMenuItem:(id<NSMenuItem>)menuItem; @end /*! |