aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPAppController.m32
-rw-r--r--Source/SPConstants.h1
-rw-r--r--Source/SPConstants.m1
-rw-r--r--Source/SPTextView.h5
-rw-r--r--Source/SPTextView.m55
5 files changed, 91 insertions, 3 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index 97ea3ba8..34ff1dda 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -461,7 +461,37 @@
}
}
else if([[[filename pathExtension] lowercaseString] isEqualToString:[SPUserBundleFileExtension lowercaseString]]) {
- NSLog(@"Be patient…");
+
+ NSFileManager *fm = [NSFileManager defaultManager];
+
+ NSString *bundlePath = [[NSFileManager defaultManager] applicationSupportDirectoryForSubDirectory:SPBundleSupportFolder error:nil];
+
+ if(!bundlePath) return;
+
+ if(![fm fileExistsAtPath:bundlePath isDirectory:nil]) {
+ if(![fm createDirectoryAtPath:bundlePath withIntermediateDirectories:YES attributes:nil error:nil]) {
+ NSBeep();
+ return;
+ }
+ }
+
+ NSString *newPath = [NSString stringWithFormat:@"%@/%@", bundlePath, [filename lastPathComponent]];
+ if(![fm fileExistsAtPath:newPath isDirectory:nil]) {
+ if(![fm copyItemAtPath:filename toPath:newPath error:nil]) {
+ NSBeep();
+ return;
+ }
+ } else {
+ NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while installing bundle file", @"error while installing bundle file")]
+ defaultButton:NSLocalizedString(@"OK", @"OK button")
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"The bundle ‘%@’ already exists.", @"the bundle ‘%@’ already exists."), [filename lastPathComponent]]];
+
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ [alert runModal];
+ return;
+ }
}
else {
NSLog(@"Only files with the extensions ‘%@’, ‘%@’, ‘%@’ or ‘%@’ are allowed.", SPFileExtensionDefault, SPBundleFileExtension, SPColorThemeFileExtension, SPFileExtensionSQL);
diff --git a/Source/SPConstants.h b/Source/SPConstants.h
index 95660f39..931722ba 100644
--- a/Source/SPConstants.h
+++ b/Source/SPConstants.h
@@ -236,6 +236,7 @@ extern NSString *SPHTMLHelpTemplate;
// Folder names
extern NSString *SPThemesSupportFolder;
+extern NSString *SPBundleSupportFolder;
// Preference key constants
// General Prefpane
diff --git a/Source/SPConstants.m b/Source/SPConstants.m
index d17ddd13..c146e525 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -57,6 +57,7 @@ NSString *SPHTMLHelpTemplate = @"SPMySQLHelpTemplate";
// Folder names
NSString *SPThemesSupportFolder = @"Themes";
+NSString *SPBundleSupportFolder = @"Bundles";
// Preference key constants
// General Prefpane
diff --git a/Source/SPTextView.h b/Source/SPTextView.h
index 69be86d3..e0cb6a32 100644
--- a/Source/SPTextView.h
+++ b/Source/SPTextView.h
@@ -85,6 +85,9 @@
NSColor *otherTextColor;
NSRange queryRange;
BOOL shouldHiliteQuery;
+
+ NSArray *bundleItems;
+
}
@property(retain) NSColor* queryHiliteColor;
@@ -143,4 +146,6 @@
- (BOOL)isSnippetMode;
+- (void)reloadBundleItems;
+
@end
diff --git a/Source/SPTextView.m b/Source/SPTextView.m
index 0686fbb2..910ddd6b 100644
--- a/Source/SPTextView.m
+++ b/Source/SPTextView.m
@@ -130,6 +130,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
isProcessingMirroredSnippets = NO;
completionWasRefreshed = NO;
+ bundleItems = nil;
+
lineNumberView = [[NoodleLineNumberView alloc] initWithScrollView:scrollView];
[scrollView setVerticalRulerView:lineNumberView];
[scrollView setHasHorizontalRuler:NO];
@@ -186,6 +188,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
[prefs addObserver:self forKeyPath:SPCustomQueryEditorTextColor options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:self forKeyPath:SPCustomQueryEditorTabStopWidth options:NSKeyValueObservingOptionNew context:NULL];
[prefs addObserver:self forKeyPath:SPCustomQueryAutoUppercaseKeywords options:NSKeyValueObservingOptionNew context:NULL];
+
}
- (void) setConnection:(MCPConnection *)theConnection withVersion:(NSInteger)majorVersion
@@ -2900,8 +2903,12 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
[[menu itemAtIndex:5] setHidden:YES];
[[menu itemAtIndex:6] setHidden:YES];
}
-
- return menu;
+
+ if(bundleItems && [bundleItems count]) {
+ // TODO add bundle sub menu;
+ }
+
+return menu;
}
/**
@@ -3319,6 +3326,48 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
}
}
+#pragma mark -
+
+- (void)reloadBundleItems
+{
+ NSFileManager *fm = [NSFileManager defaultManager];
+ NSString *bundlePath = [[NSFileManager defaultManager] applicationSupportDirectoryForSubDirectory:SPBundleSupportFolder error:nil];
+
+ if(bundlePath) {
+ NSError *error = nil;
+ NSArray *foundBundles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundlePath error:&error];
+ if (foundBundles && [foundBundles count]) {
+ for(NSString* bundle in foundBundles) {
+ if(![[[bundle pathExtension] lowercaseString] isEqualToString:[SPUserBundleFileExtension lowercaseString]]) continue;
+
+ NSError *readError = nil;
+ NSString *convError = nil;
+ NSPropertyListFormat format;
+ NSDictionary *cmdData = nil;
+ if(bundleItems) [bundleItems retain];
+ NSData *pData = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/info.plist", bundlePath, bundle] options:NSUncachedRead error:&readError];
+
+ cmdData = [[NSPropertyListSerialization propertyListFromData:pData
+ mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain];
+
+ if(!cmdData || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) {
+ NSLog(@"“%@/info.plist” file couldn't be read.", bundle);
+ NSBeep();
+ if (cmdData) [cmdData release];
+ } else {
+ if([cmdData objectForKey:@"name"] && [[cmdData objectForKey:@"name"] length]
+ && [cmdData objectForKey:@"scope"] && [[cmdData objectForKey:@"scope"] isEqualToString:@"editor"])
+ [bundleItems addObject:[cmdData objectForKey:@"name"]];
+ if (cmdData) [cmdData release];
+ }
+
+ }
+ }
+ }
+}
+
+#pragma mark -
+
- (void) dealloc
{
@@ -3341,6 +3390,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
[prefs removeObserver:self forKeyPath:SPCustomQueryEditorTabStopWidth];
[prefs removeObserver:self forKeyPath:SPCustomQueryAutoUppercaseKeywords];
+ if(bundleItems) [bundleItems retain];
+
if (completionIsOpen) [completionPopup close], completionIsOpen = NO;
[prefs release];
[lineNumberView release];