Revision: 6507
http://skim-app.svn.sourceforge.net/skim-app/?rev=6507&view=rev
Author: hofman
Date: 2010-04-30 15:12:06 +0000 (Fri, 30 Apr 2010)
Log Message:
-----------
use separate controller class for script menu
Modified Paths:
--------------
trunk/SKApplicationController.m
trunk/SKScriptMenu.h
trunk/SKScriptMenu.m
Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m 2010-04-30 14:54:15 UTC (rev 6506)
+++ trunk/SKApplicationController.m 2010-04-30 15:12:06 UTC (rev 6507)
@@ -146,7 +146,8 @@
[[[NSApp mainMenu] itemAtIndex:BOOKMARKS_MENU_INDEX]
setRepresentedObject:[[SKBookmarkController sharedBookmarkController]
bookmarkRoot]];
- [SKScriptMenu setupScriptMenu];
+ // this creates the script menu if needed
+ (void)[NSApp scriptMenu];
[[NSColorPanel sharedColorPanel] setShowsAlpha:YES];
}
Modified: trunk/SKScriptMenu.h
===================================================================
--- trunk/SKScriptMenu.h 2010-04-30 14:54:15 UTC (rev 6506)
+++ trunk/SKScriptMenu.h 2010-04-30 15:12:06 UTC (rev 6507)
@@ -39,9 +39,6 @@
#import <Cocoa/Cocoa.h>
-...@interface SKScriptMenu : NSMenu <NSMenuDelegate> {
- FSEventStreamRef streamRef;
- NSArray *sortDescriptors;
-}
-+ (void)setupScriptMenu;
+...@interface NSApplication (SKScriptMenu)
+- (NSMenu *)scriptMenu;
@end
Modified: trunk/SKScriptMenu.m
===================================================================
--- trunk/SKScriptMenu.m 2010-04-30 14:54:15 UTC (rev 6506)
+++ trunk/SKScriptMenu.m 2010-04-30 15:12:06 UTC (rev 6507)
@@ -46,79 +46,84 @@
#define FILENAME_KEY @"filename"
#define CONTENT_KEY @"content"
-...@interface SKScriptMenu (Private)
-- (id)initWithPaths:(NSArray *)scriptFolders;
+...@interface SKScriptMenuController : NSObject <NSMenuDelegate> {
+ NSMenu *scriptMenu;
+ FSEventStreamRef streamRef;
+ NSArray *sortDescriptors;
+}
+
+...@property (nonatomic, readonly) NSMenu *scriptMenu;
+
++ (id)sharedController;
+
- (void)handleApplicationWillTerminateNotification:(NSNotification
*)notification;
- (NSArray *)directoryContentsAtPath:(NSString *)path
recursionDepth:(NSInteger)depth;
- (void)executeScript:(id)sender;
+
@end
-...@implementation SKScriptMenu
+...@implementation SKScriptMenuController
-static SKScriptMenu *sharedMenu = nil;
+...@synthesize scriptMenu;
+
static BOOL menuNeedsUpdate = NO;
-+ (void)setupScriptMenu {
- if (sharedMenu)
- return;
-
- NSInteger itemIndex = [[NSApp mainMenu] numberOfItems] - 1;
- if (itemIndex <= 0)
- return;
-
- NSFileManager *fm = [NSFileManager defaultManager];
- NSMutableArray *scriptFolders = [NSMutableArray array];
- BOOL isDir;
-
- for (NSString *folder in [fm applicationSupportDirectories]) {
- folder = [folder stringByAppendingPathComponent:SCRIPTS_FOLDER_NAME];
- if ([fm fileExistsAtPath:folder isDirectory:&isDir] && isDir)
- [scriptFolders addObject:folder];
- }
-
- if ([scriptFolders count] == 0)
- return;
-
- sharedMenu = [[self allocWithZone:[NSMenu menuZone]]
initWithPaths:scriptFolders];
- NSMenuItem *menuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]]
initWithTitle:SCRIPTS_MENU_TITLE action:NULL keyEquivalent:@""];
- [menuItem setImage:[NSImage imageNamed:@"ScriptMenu"]];
- [menuItem setSubmenu:sharedMenu];
- [[NSApp mainMenu] insertItem:menuItem atIndex:itemIndex];
- [menuItem release];
++ (id)sharedController {
+ static SKScriptMenuController *sharedController = nil;
+ if (sharedController == nil)
+ sharedController = [[self alloc] init];
+ return sharedController;
}
static void fsevents_callback(FSEventStreamRef streamRef, void
*clientCallBackInfo, int numEvents, const char *const eventPaths[], const
FSEventStreamEventFlags *eventMasks, const uint64_t *eventIDs) {
menuNeedsUpdate = YES;
}
-- (id)initWithPaths:(NSArray *)scriptFolders {
- if (self = [super initWithTitle:SCRIPTS_MENU_TITLE]) {
- sortDescriptors = [[NSArray alloc] initWithObjects:[[[NSSortDescriptor
alloc] initWithKey:FILENAME_KEY ascending:YES
selector:@selector(localizedCaseInsensitiveNumericCompare:)] autorelease], nil];
+- (id)init {
+ if (self = [super init]) {
- streamRef = FSEventStreamCreate(kCFAllocatorDefault,
-
(FSEventStreamCallback)&fsevents_callback, // callback
- NULL, // context
- (CFArrayRef)scriptFolders, //
pathsToWatch
- kFSEventStreamEventIdSinceNow, //
sinceWhen
- 1.0, // latency
- kFSEventStreamCreateFlagWatchRoot); //
flags
- if (streamRef) {
- FSEventStreamScheduleWithRunLoop(streamRef, CFRunLoopGetCurrent(),
kCFRunLoopDefaultMode);
- FSEventStreamStart(streamRef);
+ NSInteger itemIndex = [[NSApp mainMenu] numberOfItems] - 1;
+ NSFileManager *fm = [NSFileManager defaultManager];
+ NSMutableArray *scriptFolders = [NSMutableArray array];
+ BOOL isDir;
+
+ for (NSString *folder in [fm applicationSupportDirectories]) {
+ folder = [folder
stringByAppendingPathComponent:SCRIPTS_FOLDER_NAME];
+ if ([fm fileExistsAtPath:folder isDirectory:&isDir] && isDir)
+ [scriptFolders addObject:folder];
+ }
+
+ if (itemIndex > 0 && [scriptFolders count]) {
- [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleApplicationWillTerminateNotification:)
name:NSApplicationWillTerminateNotification object:NSApp];
- [self setDelegate:self];
- menuNeedsUpdate = YES;
+ scriptMenu = [[NSMenu allocWithZone:[NSMenu menuZone]]
initWithTitle:SCRIPTS_MENU_TITLE];
+ NSMenuItem *menuItem = [[NSMenuItem allocWithZone:[NSMenu
menuZone]] initWithTitle:SCRIPTS_MENU_TITLE action:NULL keyEquivalent:@""];
+ [menuItem setImage:[NSImage imageNamed:@"ScriptMenu"]];
+ [menuItem setSubmenu:scriptMenu];
+ [[NSApp mainMenu] insertItem:menuItem atIndex:itemIndex];
+ [menuItem release];
+
+ sortDescriptors = [[NSArray alloc]
initWithObjects:[[[NSSortDescriptor alloc] initWithKey:FILENAME_KEY
ascending:YES selector:@selector(localizedCaseInsensitiveNumericCompare:)]
autorelease], nil];
+
+ streamRef = FSEventStreamCreate(kCFAllocatorDefault,
+
(FSEventStreamCallback)&fsevents_callback, // callback
+ NULL, // context
+ (CFArrayRef)scriptFolders, //
pathsToWatch
+ kFSEventStreamEventIdSinceNow, //
sinceWhen
+ 1.0, // latency
+
kFSEventStreamCreateFlagWatchRoot); // flags
+ if (streamRef) {
+ FSEventStreamScheduleWithRunLoop(streamRef,
CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
+ FSEventStreamStart(streamRef);
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleApplicationWillTerminateNotification:)
name:NSApplicationWillTerminateNotification object:NSApp];
+ [scriptMenu setDelegate:self];
+ menuNeedsUpdate = YES;
+ }
}
}
return self;
}
-- (id)initWithTitle:(NSString *)aTitle {
- [self release];
- return nil;
-}
-
- (void)handleApplicationWillTerminateNotification:(NSNotification
*)notification {
if (streamRef) {
FSEventStreamStop(streamRef);
@@ -126,7 +131,7 @@
FSEventStreamRelease(streamRef);
streamRef = NULL;
}
- [self setDelegate:nil];
+ [scriptMenu setDelegate:nil];
}
static NSString *menuItemTitle(NSString *path) {
@@ -281,3 +286,12 @@
}
@end
+
+
+...@implementation NSApplication (SKScriptMenu)
+
+- (NSMenu *)scriptMenu {
+ return [[SKScriptMenuController sharedController] scriptMenu];
+}
+
+...@end
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit