Permalink
Browse files

Merged in Jan's changes; removed spinner disabling from Python actions

  • Loading branch information...
1 parent 10a9a0c commit 1a6632578dc3739100c93a55bf5f346b558788e2 @onecrayon committed Dec 9, 2009
@@ -70,10 +70,8 @@ - (id)initWithDictionary:(NSDictionary *)dictionary bundlePath:(NSString *)myBun
if (defaults != nil) {
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithContentsOfFile:defaults]];
}
- TEASymlinkHandler *symController;
- symController = [[TEASymlinkHandler alloc] init];
- [symController refresh];
- [symController dealloc];
+
+ [[TEASymlinkHandler sharedHandler] refresh];
}
return self;
View
@@ -125,7 +125,7 @@ - (BOOL)performActionWithContext:(id)context error:(NSError **)outError {
// Initialize our common variables
CETextRecipe *recipe = [CETextRecipe textRecipe];
NSArray *ranges = [context selectedRanges];
- NSString *outString;
+ NSString *outString = nil;
NSString *file = [self findScript:[self script]];
if (file == nil) {
@@ -160,14 +160,12 @@ - (BOOL)performActionWithContext:(id)context error:(NSError **)outError {
if ([inputStr isEqualToString:@""]) {
if ([[self alternate] isEqualToString:@"document"]) {
// Use the document's context as the input
- [inputStr release];
inputStr = [context string];
} else if ([[self alternate] isEqualToString:@"line"]) {
// Use the current line's content as the input
NSRange linerange = [[context lineStorage] lineRangeForIndex:range.location];
// Discard the linebreak at the end of the line
range = NSMakeRange(linerange.location, linerange.length - 1);
- [inputStr release];
inputStr = [[context string] substringWithRange:range];
} else if ([[self alternate] isEqualToString:@"word"]) {
// Use the current word as the input
@@ -177,12 +175,10 @@ - (BOOL)performActionWithContext:(id)context error:(NSError **)outError {
// Use the current character as the input if possible
if (range.location > 0) {
range = NSMakeRange(range.location - 1, 1);
- [inputStr release];
inputStr = [[context string] substringWithRange:range];
}
}
// Set our source appropriately
- [source release];
source = @"alt";
}
} else if ([[self input] isEqualToString:@"document"]) {
@@ -211,7 +207,7 @@ - (BOOL)performActionWithContext:(id)context error:(NSError **)outError {
NSData *data;
data = [[outPipe fileHandleForReading] readDataToEndOfFile];
- outString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+ outString = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
[task waitUntilExit];
[task release];
@@ -257,7 +253,7 @@ - (BOOL)performActionWithContext:(id)context error:(NSError **)outError {
xhtmlStr = [defaults stringForKey:@"TEASelfClosingString"];
}
// Replace the $E_XHTML placeholder if it exists
- NSMutableString *snippetStr = [outString copy];
+ NSMutableString *snippetStr = [[outString mutableCopy] autorelease];
[snippetStr replaceOccurrencesOfString:@"$E_XHTML" withString:xhtmlStr];
// Convert to snippet
CETextSnippet *snippet = [CETextSnippet snippetWithString:snippetStr];
@@ -72,9 +72,7 @@ - (void)editInsertedRowInTable:(NSTableView *)targetTable
- (IBAction)toggleUserActions:(id)sender
{
// Performs the symlink refresh when user actions are toggled
- TEASymlinkHandler *symController = [[TEASymlinkHandler alloc] init];
- [symController rebuild];
- [symController dealloc];
+ [[TEASymlinkHandler sharedHandler] rebuild];
}
- (IBAction)customActionsHelp:(id)sender
@@ -15,10 +15,9 @@
}
--(void)rebuild;
--(void)refresh;
--(void)parseSupportFolders;
--(BOOL)symlink:(NSString *)link isValidForPath:(NSString *)path;
--(BOOL)customActionsEnabled;
++ (TEASymlinkHandler *)sharedHandler;
+
+- (void)rebuild;
+- (void)refresh;
@end
@@ -13,102 +13,118 @@
@implementation TEASymlinkHandler
-// If enabled, add new files, otherwise remove all symlinks
--(void)rebuild {
- if ([self customActionsEnabled]) {
- [self parseSupportFolders];
- } else {
- // Remove all symlinks
- NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.onecrayon.tea.espresso"];
- NSString *symFolder = [[bundle bundlePath] stringByAppendingPathComponent:@"TextActions"];
- NSFileManager *fileManager = [NSFileManager defaultManager];
- // Grab the contents of the TextActions folder
- NSArray *contents = [fileManager contentsOfDirectoryAtPath:symFolder error:NULL];
- // Process the symlinks
- for (NSString *path in contents) {
- if ([[[fileManager attributesOfItemAtPath:[symFolder stringByAppendingPathComponent:path] error:NULL] fileType] isEqualToString:NSFileTypeSymbolicLink]) {
- NSError *error = nil;
- if (![fileManager removeItemAtPath:[symFolder stringByAppendingPathComponent:path] error:&error]) {
- NSLog(@"Error removing symlink: %@ for %@", [error localizedDescription], path);
- }
- }
- }
- }
++ (void)load
+{
+ [super load];
+
+ // This is really a bit of a hacky way to approach this, but it works...
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ [[self sharedHandler] rebuild];
+ [pool drain];
+}
++ (TEASymlinkHandler *)sharedHandler
+{
+ static TEASymlinkHandler *sharedHandler = nil;
+ if (sharedHandler == nil)
+ sharedHandler = [[self alloc] init];
+ return sharedHandler;
}
-// If enabled, run our standard check for new files
--(void)refresh {
- if ([self customActionsEnabled]) {
- [self parseSupportFolders];
- }
+- (NSBundle *)TEABundle
+{
+ return [NSBundle bundleWithIdentifier:@"com.onecrayon.tea.espresso"];
+}
+
+// Test if custom actions are enabled at this time
+- (BOOL)hasCustomActionsEnabled
+{
+ return [[NSUserDefaults standardUserDefaults] boolForKey:@"TEAEnableUserActions"];
}
// Walk over the support folder and look for new files
--(void)parseSupportFolders {
- NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.onecrayon.tea.espresso"];
- NSString *symFolder = [[bundle bundlePath] stringByAppendingPathComponent:@"TextActions"];
+- (void)parseSupportFolders
+{
+ NSString *symbolicLinksFolder = [[[self TEABundle] bundlePath] stringByAppendingPathComponent:@"TextActions"];
+
// For backwards compatibility with early TEA versions, I need to support the TEA folder
- NSArray *paths = [NSArray arrayWithObjects:[@"~/Library/Application Support/Espresso/Support/TextActions/" stringByExpandingTildeInPath],
- [@"~/Library/Application Support/Espresso/TEA/TextActions/" stringByExpandingTildeInPath], nil];
+ NSArray *directoriesWithXML = [NSArray arrayWithObjects:[@"~/Library/Application Support/Espresso/Support/TextActions/" stringByExpandingTildeInPath], [@"~/Library/Application Support/Espresso/TEA/TextActions/" stringByExpandingTildeInPath], nil];
NSFileManager *fileManager = [NSFileManager defaultManager];
+
// Process both folders
- for (NSString *directory in paths) {
- NSDirectoryEnumerator *dirEnumerator = [fileManager enumeratorAtPath:directory];
+ for (NSString *directoryWithXML in directoriesWithXML) {
- NSString *file;
- BOOL keepRunning = YES;
- // Using keepRunning instead of standard iterator setup to prevent autorelease memory problem:
- // http://www.cocoadev.com/index.pl?NSDirectoryEnumerator (near the bottom)
- while (keepRunning) {
- file = [dirEnumerator nextObject];
- if (file == nil) {
- keepRunning = NO;
- break;
- }
- if ([[file pathExtension] isEqualToString:@"xml"]) {
- // Create an autorelease pool so we can reinstantiate all these variables each loop
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ NSArray *subpaths = [fileManager subpathsOfDirectoryAtPath:directoryWithXML error:NULL];
+ for (NSString *subpath in subpaths) {
+
+ // If we found an XML file, we add a symlink to it
+ if ([subpath.pathExtension isEqualToString:@"xml"]) {
- NSString *basename = [file lastPathComponent];
- // This stuff changes in the next while loop
- NSString *fileStub = [basename copy];
- BOOL priorLink = NO;
- NSUInteger count = 1;
- while ([fileManager fileExistsAtPath:[symFolder stringByAppendingPathComponent:fileStub]]) {
- // If we already have a link, set priorLink to YES and break
- if ([self symlink:[symFolder stringByAppendingPathComponent:fileStub] isValidForPath:file]) {
- priorLink = YES;
+ NSString *fileName = [subpath lastPathComponent];
+ NSString *filePath = [directoryWithXML stringByAppendingPathComponent:subpath];
+
+ BOOL hasValidSymbolicLink = NO;
+ NSUInteger numericSuffix = 1;
+ while ([fileManager fileExistsAtPath:[symbolicLinksFolder stringByAppendingPathComponent:fileName]]) {
+
+ // See if we already have a valid symbolic link for the file we want to point to
+ NSString *symbolicLinkPath = [symbolicLinksFolder stringByAppendingPathComponent:fileName];
+ hasValidSymbolicLink = ([[[fileManager attributesOfItemAtPath:symbolicLinkPath error:NULL] fileType] isEqualToString:NSFileTypeSymbolicLink] && [[fileManager destinationOfSymbolicLinkAtPath:symbolicLinkPath error:NULL] isEqualToString:filePath]);
+
+ if (hasValidSymbolicLink) {
break;
- } else {
- // Otherwise, bump our number up and try again
- [fileStub release];
- fileStub = [[NSString stringWithFormat:@"%lu", (unsigned long)count] stringByAppendingString:basename];
- count = count + 1;
+ }
+ else {
+ fileName = [NSString stringWithFormat:@"%@ %lu", fileName, (unsigned long)numericSuffix];
+ numericSuffix++;
}
}
- if (!priorLink) {
+
+ if (!hasValidSymbolicLink) {
NSError *error = nil;
- if (![fileManager createSymbolicLinkAtPath:[symFolder stringByAppendingPathComponent:fileStub] withDestinationPath:[directory stringByAppendingPathComponent:file] error:&error]) {
- NSLog(@"Error creating symlink: %@ for %@ => %@", [error localizedDescription], [symFolder stringByAppendingPathComponent:fileStub], [directory stringByAppendingPathComponent:file]);
+ if (![fileManager createSymbolicLinkAtPath:[symbolicLinksFolder stringByAppendingPathComponent:fileName] withDestinationPath:filePath error:&error]) {
+ NSLog(@"TEA: Error creating symlink: %@ for %@ => %@", [error localizedDescription], [symbolicLinksFolder stringByAppendingPathComponent:fileName], filePath);
}
}
- // Release the pool
- [pool drain];
}
}
}
}
--(BOOL)symlink:(NSString *)link isValidForPath:(NSString *)path {
- NSFileManager *fileManager = [NSFileManager defaultManager];
- return ([[[fileManager attributesOfItemAtPath:link error:NULL] fileType] isEqualToString:NSFileTypeSymbolicLink] && [[fileManager destinationOfSymbolicLinkAtPath:link error:NULL] isEqualToString:path]);
+#pragma mark -
+
+// If enabled, add new files, otherwise remove all symlinks
+- (void)rebuild
+{
+ if ([self hasCustomActionsEnabled]) {
+ [self parseSupportFolders];
+ }
+ else {
+ // Remove all symlinks
+ NSString *symFolder = [[[self TEABundle] bundlePath] stringByAppendingPathComponent:@"TextActions"];
+
+ // Process the symlinks
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ for (NSString *path in [fileManager contentsOfDirectoryAtPath:symFolder error:NULL]) {
+
+ NSString *symbolicLinkPath = [symFolder stringByAppendingPathComponent:path];
+ if ([[[fileManager attributesOfItemAtPath:symbolicLinkPath error:NULL] fileType] isEqualToString:NSFileTypeSymbolicLink]) {
+ NSError *error = nil;
+ if (![fileManager removeItemAtPath:symbolicLinkPath error:&error]) {
+ NSLog(@"Error removing symlink: %@ for %@", [error localizedDescription], path);
+ }
+ }
+ }
+ }
+
}
-// Test if custom actions are enabled at this time
--(BOOL)customActionsEnabled {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- return [defaults boolForKey:@"TEAEnableUserActions"];
+// If enabled, run our standard check for new files
+- (void)refresh
+{
+ if ([self hasCustomActionsEnabled]) {
+ [self parseSupportFolders];
+ }
}
@end
@@ -86,7 +86,8 @@ - (IBAction) cancel:(id)sender {
[NSApp endSheet:[self customSheet] returnCode:0];
}
-- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
+- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
+{
if (returnCode == 1) {
// Doing this here, because Python might be starting up, which could take a while
[[self spinner] startAnimation:self];
@@ -98,6 +99,11 @@ - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextIn
// NOTE: in init, the instance gets a retain count of 1
id actionLoader = [[TEAPythonLoaderClass alloc] init];
BOOL returnValue = [actionLoader actInContext:[self myContext] forAction:self];
+ //if (returnValue == NO)
+ // NSBeep();
+
+ // Turn off the spinner
+ [[self spinner] stopAnimation:self];
// NOTE: release the actionLoader, decrementing its retain count to 0, which leads to its deallocation
[actionLoader release];
@@ -71,7 +71,7 @@ - (BOOL)performActionWithContext:(id)context error:(NSError **)outError {
// Now that Python and the TEAPythonLoader class are initialized, send the info to TEAPythonLoader
Class TEAPythonLoaderClass = NSClassFromString(@"TEAPythonLoader");
- id actionLoader = [[TEAPythonLoaderClass alloc] init];
+ id actionLoader = [[[TEAPythonLoaderClass alloc] init] autorelease];
return [actionLoader actInContext:context forAction:self];
}
@@ -37,7 +37,5 @@ def replacements(match):
insertions.addReplacementString_forRange_(text, range)
insertions.setUndoActionName_(operation.title())
context.applyTextRecipe_(insertions)
- # spinner is turned on in the Objective-C action
- actionObject.spinner().stopAnimation_(actionObject)
return True
@@ -79,9 +79,6 @@ def is_space(char):
tea.insert_snippet_over_range(context, result, rng, undo_name)
- # spinner is turned on in the Objective-C action
- actionObject.spinner().stopAnimation_(actionObject)
-
return True
def get_current_line_padding(context):
@@ -8,11 +8,11 @@
/* Begin PBXBuildFile section */
3B86F9AD10C7E3A900C5CF8D /* TEAPreferencesView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3B86F9AB10C7E3A900C5CF8D /* TEAPreferencesView.xib */; };
+ 3DF9526E10CEAAA800C51C0D /* TEASymlinkHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 3DF9526D10CEAAA800C51C0D /* TEASymlinkHandler.m */; };
7A219FF9106B2BDA00F114B6 /* TEAPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A219FF8106B2BDA00F114B6 /* TEAPreferences.m */; };
7A21A070106BCC6D00F114B6 /* TEASpacesPerTabsSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7A21A06E106BCC6D00F114B6 /* TEASpacesPerTabsSheet.xib */; };
7A38EEF91095F09B008DD984 /* TEALoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A38EEF81095F09B008DD984 /* TEALoader.m */; };
7A59D8FE106A7CB90078C92C /* Defaults.plist in Resources */ = {isa = PBXBuildFile; fileRef = 7A59D8FD106A7CB90078C92C /* Defaults.plist */; };
- 7A91067A10C8D134004BF837 /* TEASymlinkHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A91067910C8D134004BF837 /* TEASymlinkHandler.m */; };
7AEBC32B10C4C17B00A05230 /* TEAUserInput.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AEBC32A10C4C17B00A05230 /* TEAUserInput.m */; };
7AEBC33110C4C43A00A05230 /* TEAEnterAbbreviationSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7AEBC32F10C4C43A00A05230 /* TEAEnterAbbreviationSheet.xib */; };
7AEEF40410652918006B7765 /* Python.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7AEEF40310652918006B7765 /* Python.framework */; };
@@ -40,14 +40,14 @@
1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
32DBCF630370AF2F00C91783 /* Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Prefix.pch; sourceTree = "<group>"; };
3B86F9AC10C7E3A900C5CF8D /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = src/Resources/English.lproj/TEAPreferencesView.xib; sourceTree = "<group>"; };
+ 3DF9526C10CEAAA800C51C0D /* TEASymlinkHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TEASymlinkHandler.h; path = src/Classes/TEASymlinkHandler.h; sourceTree = "<group>"; };
+ 3DF9526D10CEAAA800C51C0D /* TEASymlinkHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TEASymlinkHandler.m; path = src/Classes/TEASymlinkHandler.m; sourceTree = "<group>"; };
7A219FF7106B2BDA00F114B6 /* TEAPreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TEAPreferences.h; path = src/Classes/TEAPreferences.h; sourceTree = "<group>"; };
7A219FF8106B2BDA00F114B6 /* TEAPreferences.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TEAPreferences.m; path = src/Classes/TEAPreferences.m; sourceTree = "<group>"; };
7A21A06F106BCC6D00F114B6 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = src/Resources/English.lproj/TEASpacesPerTabsSheet.xib; sourceTree = "<group>"; };
7A38EEF71095F09B008DD984 /* TEALoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TEALoader.h; path = src/Classes/TEALoader.h; sourceTree = "<group>"; };
7A38EEF81095F09B008DD984 /* TEALoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TEALoader.m; path = src/Classes/TEALoader.m; sourceTree = "<group>"; };
7A59D8FD106A7CB90078C92C /* Defaults.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Defaults.plist; path = src/Resources/Defaults.plist; sourceTree = "<group>"; };
- 7A91067810C8D134004BF837 /* TEASymlinkHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TEASymlinkHandler.h; path = src/Classes/TEASymlinkHandler.h; sourceTree = "<group>"; };
- 7A91067910C8D134004BF837 /* TEASymlinkHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TEASymlinkHandler.m; path = src/Classes/TEASymlinkHandler.m; sourceTree = "<group>"; };
7AEBC32910C4C17B00A05230 /* TEAUserInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TEAUserInput.h; path = src/Classes/TEAUserInput.h; sourceTree = "<group>"; };
7AEBC32A10C4C17B00A05230 /* TEAUserInput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TEAUserInput.m; path = src/Classes/TEAUserInput.m; sourceTree = "<group>"; };
7AEBC33010C4C43A00A05230 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = src/Resources/English.lproj/TEAEnterAbbreviationSheet.xib; sourceTree = "<group>"; };
@@ -117,10 +117,10 @@
7A219FF8106B2BDA00F114B6 /* TEAPreferences.m */,
7A38EEF71095F09B008DD984 /* TEALoader.h */,
7A38EEF81095F09B008DD984 /* TEALoader.m */,
+ 3DF9526C10CEAAA800C51C0D /* TEASymlinkHandler.h */,
+ 3DF9526D10CEAAA800C51C0D /* TEASymlinkHandler.m */,
7AEBC32910C4C17B00A05230 /* TEAUserInput.h */,
7AEBC32A10C4C17B00A05230 /* TEAUserInput.m */,
- 7A91067810C8D134004BF837 /* TEASymlinkHandler.h */,
- 7A91067910C8D134004BF837 /* TEASymlinkHandler.m */,
);
name = Classes;
sourceTree = "<group>";
@@ -240,7 +240,7 @@
7A219FF9106B2BDA00F114B6 /* TEAPreferences.m in Sources */,
7A38EEF91095F09B008DD984 /* TEALoader.m in Sources */,
7AEBC32B10C4C17B00A05230 /* TEAUserInput.m in Sources */,
- 7A91067A10C8D134004BF837 /* TEASymlinkHandler.m in Sources */,
+ 3DF9526E10CEAAA800C51C0D /* TEASymlinkHandler.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -339,6 +339,7 @@
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
BUNDLE_LOADER = "$(APPLICATION_PATH)/Contents/MacOS/Espresso";
GCC_ENABLE_OBJC_GC = supported;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
HEADER_SEARCH_PATHS = "$(APPLICATION_PATH)/Contents/Headers";
ONLY_ACTIVE_ARCH = NO;
PREBINDING = NO;

0 comments on commit 1a66325

Please sign in to comment.