From b5c4f326fb175499d0b837cb325b9eeea676fb4f Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 19 Nov 2010 10:29:42 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20Editor=20-=20fixed=20saving=20and?= =?UTF-8?q?=20duplicating=20Bundles=20if=20Bundle=20contains=20other=20fil?= =?UTF-8?q?es/folder=20-=20fixed=20adding=20a=20new=20Bundle=20-=20added?= =?UTF-8?q?=20gui=20tooltips=20=E2=80=A2=20SPTooltip=20-=20if=20no=20locat?= =?UTF-8?q?ion=20was=20passed=20and=20first=20responder=20isn't=20a=20text?= =?UTF-8?q?View=20show=20the=20tooltip=20at=20the=20mouse=20location=20?= =?UTF-8?q?=E2=80=A2=20CopyTable=20-=20show=20tooltip=20invoked=20by=20a?= =?UTF-8?q?=20Bundle=20command=20always=20at=20mouse=20location=20?= =?UTF-8?q?=E2=80=A2=20Content=20/=20Custom=20Query=20Table=20-=20suppress?= =?UTF-8?q?=20tooltip=20of=20cell=20content=20if=20another=20tooltip=20(ma?= =?UTF-8?q?inly=20displayed=20by=20a=20Bundle)=20is=20visible=20[shoudl=20?= =?UTF-8?q?be=20improved=20since=20iterating=20through=20the=20window=20li?= =?UTF-8?q?st=20isn't=20so=20good]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/BundleEditor.xib | 126 +++++++++++++++++++++++++++--- Source/SPBundleEditorController.m | 77 ++++++++++++++---- Source/SPCopyTable.m | 6 +- Source/SPCustomQuery.m | 8 ++ Source/SPTableContent.m | 8 ++ Source/SPTooltip.m | 11 ++- 6 files changed, 208 insertions(+), 28 deletions(-) diff --git a/Interfaces/English.lproj/BundleEditor.xib b/Interfaces/English.lproj/BundleEditor.xib index 1701e490..ba16ec40 100644 --- a/Interfaces/English.lproj/BundleEditor.xib +++ b/Interfaces/English.lproj/BundleEditor.xib @@ -23,7 +23,7 @@ YES - + YES @@ -202,7 +202,7 @@ - Save Bundle + Save Bundle… 2147483647 @@ -636,13 +636,13 @@ 268 - {{201, 390}, {166, 18}} + {{201, 390}, {201, 18}} YES -2080244224 131072 - Disable Command + Disable Bundle 1211912703 @@ -919,7 +919,7 @@ 68288064 4326400 - Name: + Menu Label: @@ -2404,10 +2404,12 @@ 685.IBPluginDependency 686.IBPluginDependency 690.IBPluginDependency + 691.IBAttributePlaceholdersKey 691.IBPluginDependency 692.IBAttributePlaceholdersKey 692.IBPluginDependency 693.IBPluginDependency + 695.IBAttributePlaceholdersKey 695.IBPluginDependency 696.IBPluginDependency 700.IBPluginDependency @@ -2443,14 +2445,17 @@ 754.CustomClassName 754.IBPluginDependency 754.ImportedFromIB2 + 768.IBAttributePlaceholdersKey 768.IBPluginDependency 769.IBPluginDependency 770.IBEditorWindowLastContentRect 770.IBPluginDependency + 774.IBAttributePlaceholdersKey 774.IBPluginDependency 775.IBPluginDependency 776.IBEditorWindowLastContentRect 776.IBPluginDependency + 780.IBAttributePlaceholdersKey 780.IBPluginDependency 781.IBPluginDependency 782.IBEditorWindowLastContentRect @@ -2465,18 +2470,24 @@ 796.IBPluginDependency 797.IBPluginDependency 798.IBPluginDependency + 799.IBAttributePlaceholdersKey 799.IBPluginDependency 800.IBPluginDependency 801.IBPluginDependency 802.IBPluginDependency + 804.IBAttributePlaceholdersKey 804.IBPluginDependency + 805.IBAttributePlaceholdersKey 805.IBPluginDependency 806.IBPluginDependency + 807.IBAttributePlaceholdersKey 807.IBPluginDependency 808.IBPluginDependency + 809.IBAttributePlaceholdersKey 809.IBPluginDependency 810.IBPluginDependency 816.IBPluginDependency + 817.IBAttributePlaceholdersKey 817.IBPluginDependency 818.IBPluginDependency 820.IBPluginDependency @@ -2484,6 +2495,7 @@ 822.IBPluginDependency 823.IBPluginDependency 825.IBPluginDependency + 859.IBAttributePlaceholdersKey 859.IBPluginDependency 860.IBPluginDependency 876.IBPluginDependency @@ -2498,9 +2510,9 @@ YES com.apple.InterfaceBuilder.CocoaPlugin - {{224, 50}, {655, 444}} + {{218, 278}, {655, 444}} com.apple.InterfaceBuilder.CocoaPlugin - {{224, 50}, {655, 444}} + {{218, 278}, {655, 444}} {726, 444} @@ -2509,6 +2521,14 @@ com.brandonwalkin.BWToolkit com.brandonwalkin.BWToolkit com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Enter a menu category which will be displayed as submenu containing the Bundle command + + com.apple.InterfaceBuilder.CocoaPlugin ToolTip @@ -2520,6 +2540,14 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Enter the menu label name + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2559,7 +2587,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.brandonwalkin.BWToolkit - {{274, 2}, {204, 71}} + {{268, 230}, {204, 71}} com.brandonwalkin.BWToolkit com.brandonwalkin.BWToolkit com.apple.InterfaceBuilder.CocoaPlugin @@ -2576,14 +2604,38 @@ ImageAndTextCell com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Choose the input source for the command. The desired data will be available as UTF-8 encoded file whose name will be passed as shell variable SP_BUNDLE_INPUT_FILE + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin {{211, 598}, {167, 4}} com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Choose the output action of the Bundle command + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin {{211, 312}, {167, 4}} com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Choose the fallback input source if nothing was selected + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin {{430, 598}, {167, 4}} @@ -2611,18 +2663,66 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Enter the tooltip for the Bundle command menu item + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Click to record a shortcut for the Bundle command (Please note, not every shortcut will work due to global or Sequel Pro key bindings) + + net.wafflesoftware.ShortcutRecorder.IB.Leopard + + ToolTip + + ToolTip + + Bundle Command will be executable in the Query Editor + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Bundle Command will be executable in the data tables of the Content View and Custom Query View + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Bundle Command will be executable in any text input field but not in the Query Editor + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Q2xvc2UgdGhlIEJ1bmRsZSBFZGl0b3Igd2l0aG91dCBzYXZpbmcgKA/ijospA + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2630,6 +2730,14 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Save any changes and close the Bundle Editor (⌘S) + + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2658,7 +2766,7 @@ - 921 + 923 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 = @"" @"" @"