aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPBundleEditorController.m77
-rw-r--r--Source/SPCopyTable.m6
-rw-r--r--Source/SPCustomQuery.m8
-rw-r--r--Source/SPTableContent.m8
-rw-r--r--Source/SPTooltip.m11
5 files changed, 91 insertions, 19 deletions
diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m
index deb8e0be..574836e2 100644
--- a/Source/SPBundleEditorController.m
+++ b/Source/SPBundleEditorController.m
@@ -325,16 +325,56 @@
// Store pending changes in Query
[[self window] makeFirstResponder:nameTextField];
- // Duplicate a selected favorite if sender == self
+ // Duplicate a selected Bundle if sender == self
if (sender == self) {
NSDictionary *currentDict = [commandBundleArray objectAtIndex:[commandsTableView selectedRow]];
bundle = [NSMutableDictionary dictionaryWithDictionary:currentDict];
- [bundle setObject:[NSString stringWithFormat:@"%@_Copy", [bundle objectForKey:@"bundleName"]] forKey:@"bundleName"];
+
+ NSString *bundleFileName = [bundle objectForKey:@"bundleName"];
+ NSString *newFileName = [NSString stringWithFormat:@"%@_Copy", [bundle objectForKey:@"bundleName"]];
+ NSString *possibleExisitingBundleFilePath = [NSString stringWithFormat:@"%@/%@.%@", bundlePath, bundleFileName, SPUserBundleFileExtension];
+ NSString *newBundleFilePath = [NSString stringWithFormat:@"%@/%@.%@", bundlePath, newFileName, SPUserBundleFileExtension];
+
+ BOOL isDir;
+ BOOL copyingWasSuccessful = YES;
+ // Copy possible existing bundle with content
+ if([[NSFileManager defaultManager] fileExistsAtPath:possibleExisitingBundleFilePath isDirectory:&isDir] && isDir) {
+ if(![[NSFileManager defaultManager] copyItemAtPath:possibleExisitingBundleFilePath toPath:newBundleFilePath error:nil])
+ copyingWasSuccessful = NO;
+ }
+ if(!copyingWasSuccessful) {
+ // try again with new name
+ newFileName = [NSString stringWithFormat:@"%@_%ld", newFileName, (NSUInteger)(random() % 35000)];
+ newBundleFilePath = [NSString stringWithFormat:@"%@/%@.%@", bundlePath, newFileName, SPUserBundleFileExtension];
+ if([[NSFileManager defaultManager] fileExistsAtPath:possibleExisitingBundleFilePath isDirectory:&isDir] && isDir) {
+ if([[NSFileManager defaultManager] copyItemAtPath:possibleExisitingBundleFilePath toPath:newBundleFilePath error:nil])
+ copyingWasSuccessful = YES;
+ }
+ }
+ if(!copyingWasSuccessful) {
+
+ [commandsTableView reloadData];
+
+ NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error", @"error")
+ defaultButton:NSLocalizedString(@"OK", @"OK button")
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:NSLocalizedString(@"Error while duplicating Bundle content.", @"error while duplicating Bundle content")];
+
+ [alert setAlertStyle:NSCriticalAlertStyle];
+ [alert runModal];
+
+ return;
+
+ }
+
+ [bundle setObject:newFileName forKey:@"bundleName"];
+
}
- // Add a new favorite
+ // Add a new Bundle
else {
- bundle = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"New Bundle", @"New Name", @"", nil]
- forKeys:[NSArray arrayWithObjects:@"bundleName", @"name", @"command", nil]];
+ bundle = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"New Bundle", @"New Name", @"", SPBundleScopeInputField, [NSNumber numberWithInt:1], nil]
+ forKeys:[NSArray arrayWithObjects:@"bundleName", SPBundleFileNameKey, SPBundleFileCommandKey, SPBundleFileScopeKey, SPBundleScopeInputField, nil]];
}
if ([commandsTableView numberOfSelectedRows] > 0) {
insertIndex = [[commandsTableView selectedRowIndexes] lastIndex]+1;
@@ -354,6 +394,7 @@
[removeButton setEnabled:([commandsTableView numberOfSelectedRows] > 0)];
[[self window] makeFirstResponder:commandsTableView];
+ [self scopeButtonChanged:nil];
if([commandsTableView numberOfSelectedRows] > 0)
[commandsTableView editColumn:0 row:insertIndex withEvent:nil select:YES];
}
@@ -487,14 +528,7 @@
NSInteger idx = 0;
for(id item in commandBundleArray) {
if([allNames objectForKey:[item objectForKey:@"bundleName"]]) {
- NSInteger i = 0;
- NSString *newName = [NSString stringWithFormat:@"%@_%ld", [item objectForKey:@"bundleName"], i++];
- while([allNames objectForKey:newName]) {
- newName = [NSString stringWithFormat:@"%@_%ld", [item objectForKey:@"bundleName"], i++];
- if(i>100) {
- return NO;
- }
- }
+ NSString *newName = [NSString stringWithFormat:@"%@_%ld", [item objectForKey:@"bundleName"], (NSUInteger)(random() % 35000)];
[[commandBundleArray objectAtIndex:idx] setObject:newName forKey:@"bundleName"];
} else {
[allNames setObject:@"" forKey:[item objectForKey:@"bundleName"]];
@@ -648,7 +682,22 @@
}
} else if([contextInfo isEqualToString:@"saveBundle"]) {
if (returnCode == NSOKButton) {
- if(![self saveBundle:[commandBundleArray objectAtIndex:[commandsTableView selectedRow]] atPath:[sheet filename]]) {
+
+ id aBundle = [commandBundleArray objectAtIndex:[commandsTableView selectedRow]];
+
+ NSString *bundleFileName = [aBundle objectForKey:@"bundleName"];
+ NSString *possibleExisitingBundleFilePath = [NSString stringWithFormat:@"%@/%@.%@", bundlePath, bundleFileName, SPUserBundleFileExtension];
+
+ NSString *savePath = [sheet filename];
+
+ BOOL isDir;
+ BOOL copyingWasSuccessful = YES;
+ // Copy possible existing bundle with content
+ if([[NSFileManager defaultManager] fileExistsAtPath:possibleExisitingBundleFilePath isDirectory:&isDir] && isDir) {
+ if(![[NSFileManager defaultManager] copyItemAtPath:possibleExisitingBundleFilePath toPath:savePath error:nil])
+ copyingWasSuccessful = NO;
+ }
+ if(!copyingWasSuccessful || ![self saveBundle:aBundle atPath:savePath]) {
NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while saving the Bundle.", @"error while saving a Bundle")
defaultButton:NSLocalizedString(@"OK", @"OK button")
alternateButton:nil
diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m
index 045d7856..48aa62f7 100644
--- a/Source/SPCopyTable.m
+++ b/Source/SPCopyTable.m
@@ -898,13 +898,15 @@ NSInteger MENU_EDIT_COPY_AS_SQL = 2003;
if([[cmdData objectForKey:SPBundleFileOutputActionKey] length]
&& ![[cmdData objectForKey:SPBundleFileOutputActionKey] isEqualToString:SPBundleOutputActionNone]) {
NSString *action = [[cmdData objectForKey:SPBundleFileOutputActionKey] lowercaseString];
+ NSPoint pos = [NSEvent mouseLocation];
+ pos.y -= 16;
if([action isEqualToString:SPBundleOutputActionShowAsTextTooltip]) {
- [SPTooltip showWithObject:output];
+ [SPTooltip showWithObject:output atLocation:pos];
}
else if([action isEqualToString:SPBundleOutputActionShowAsHTMLTooltip]) {
- [SPTooltip showWithObject:output ofType:@"html"];
+ [SPTooltip showWithObject:output atLocation:pos ofType:@"html"];
}
}
} else {
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index f81b9750..bfb6f952 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -2186,6 +2186,14 @@
if([[aCell stringValue] length] < 2 || [tableDocumentInstance isWorking]) return nil;
+ // Suppress tooltip if another toolip is already visible, mainly displayed by a Bundle command
+ // TODO has to be improved
+ for(id win in [NSApp orderedWindows]) {
+ if([[[[win contentView] class] description] isEqualToString:@"WebView"]) {
+ return nil;
+ }
+ }
+
NSImage *image;
NSPoint pos = [NSEvent mouseLocation];
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index a1fe54c5..7d694e07 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -3369,6 +3369,14 @@
if([[aCell stringValue] length] < 2 || [tableDocumentInstance isWorking]) return nil;
+ // Suppress tooltip if another toolip is already visible, mainly displayed by a Bundle command
+ // TODO has to be improved
+ for(id win in [NSApp orderedWindows]) {
+ if([[[[win contentView] class] description] isEqualToString:@"WebView"]) {
+ return nil;
+ }
+ }
+
NSImage *image;
NSPoint pos = [NSEvent mouseLocation];
diff --git a/Source/SPTooltip.m b/Source/SPTooltip.m
index f35dc155..e1cccbf9 100644
--- a/Source/SPTooltip.m
+++ b/Source/SPTooltip.m
@@ -268,10 +268,13 @@ static CGFloat slow_in_out (CGFloat t)
return pos;
// Otherwise return the upper left corner of the current keyWindow
} else {
- pos = [[NSApp keyWindow] frame].origin;
- pos.x += 5;
- pos.y += [[NSApp keyWindow] frame].size.height - 23;
+ pos = [NSEvent mouseLocation];
+ pos.y -= 16;
return pos;
+ // pos = [[NSApp keyWindow] frame].origin;
+ // pos.x += 5;
+ // pos.y += [[NSApp keyWindow] frame].size.height - 23;
+ // return pos;
}
}
@@ -280,6 +283,7 @@ static CGFloat slow_in_out (CGFloat t)
// ===========
- (void)setContent:(NSString *)content withOptions:(NSDictionary *)displayOptions
{
+
NSString *fullContent = @"<html>"
@"<head>"
@" <style type='text/css' media='screen'>"
@@ -303,6 +307,7 @@ static CGFloat slow_in_out (CGFloat t)
fullContent = [NSString stringWithFormat:fullContent, transparent ? @"transparent" : bgColor, content];
[[webView mainFrame] loadHTMLString:fullContent baseURL:nil];
+
}
- (void)sizeToContent