diff options
Diffstat (limited to 'Source/SPBundleEditorController.m')
-rw-r--r-- | Source/SPBundleEditorController.m | 283 |
1 files changed, 196 insertions, 87 deletions
diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index 32f5b581..de779e67 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -33,6 +33,11 @@ #define kGeneralScopeArrayIndex 2 #define kDisabledScopeTag 10 +#define SP_BUNDLEEDITOR_SCOPE_INPUTFIELD_STRING NSLocalizedString(@"Input Field", @"Bundle Editor : Scope dropdown : 'input field' item") +#define SP_BUNDLEEDITOR_SCOPE_DATATABLE_STRING NSLocalizedString(@"Data Table", @"Bundle Editor : Scope dropdown : 'data table' item") +#define SP_BUNDLEEDITOR_SCOPE_GENERAL_STRING NSLocalizedString(@"General", @"Bundle Editor : Scope dropdown : 'general' item") +#define SP_BUNDLEEDITOR_OUTLINE_BUNDLE_TOOLTIP_STRING NSLocalizedString(@"“%@” Bundle",@"Bundle Editor : Outline View : Bundle item : tooltip") + @interface SPBundleEditorController (PrivateAPI) - (void)_updateBundleDataView; @@ -62,6 +67,7 @@ draggedFilePath = nil; oldBundleName = nil; isTableCellEditing = NO; + deletedDefaultBundles = [[NSMutableArray alloc] initWithCapacity:1]; } return self; @@ -96,6 +102,7 @@ [withBlobDataTableArray release]; [shellVariableSuggestions release]; + [deletedDefaultBundles release]; if(touchedBundleArray) [touchedBundleArray release], touchedBundleArray = nil; if(commandBundleTree) [commandBundleTree release], commandBundleTree = nil; @@ -120,10 +127,10 @@ sortDescriptor = [[NSSortDescriptor alloc] initWithKey:kBundleNameKey ascending:YES selector:@selector(localizedCompare:)]; [commandBundleTree setObject:[NSMutableArray array] forKey:kChildrenKey]; - [commandBundleTree setObject:@"BUNDLES" forKey:kBundleNameKey]; - [[commandBundleTree objectForKey:kChildrenKey] addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSMutableArray array], kChildrenKey, NSLocalizedString(@"Input Field", @"input field scope menu label"), kBundleNameKey, nil]]; - [[commandBundleTree objectForKey:kChildrenKey] addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSMutableArray array], kChildrenKey, NSLocalizedString(@"Data Table", @"data table scope menu label"), kBundleNameKey, nil]]; - [[commandBundleTree objectForKey:kChildrenKey] addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSMutableArray array], kChildrenKey, NSLocalizedString(@"General", @"general scope menu label"), kBundleNameKey, nil]]; + [commandBundleTree setObject:NSLocalizedString(@"BUNDLES",@"Bundle Editor : Outline View : 'BUNDLES' item") forKey:kBundleNameKey]; + [[commandBundleTree objectForKey:kChildrenKey] addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSMutableArray array], kChildrenKey, SP_BUNDLEEDITOR_SCOPE_INPUTFIELD_STRING, kBundleNameKey, nil]]; + [[commandBundleTree objectForKey:kChildrenKey] addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSMutableArray array], kChildrenKey, SP_BUNDLEEDITOR_SCOPE_DATATABLE_STRING, kBundleNameKey, nil]]; + [[commandBundleTree objectForKey:kChildrenKey] addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSMutableArray array], kChildrenKey, SP_BUNDLEEDITOR_SCOPE_GENERAL_STRING, kBundleNameKey, nil]]; // Init all needed menus inputGeneralScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; @@ -166,60 +173,60 @@ NSDictionary *menuItemTitles = [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects: - NSLocalizedString(@"None", @"none menu item label"), - - NSLocalizedString(@"None", @"none menu item label"), - NSLocalizedString(@"Selected Text", @"selected text menu item label"), - NSLocalizedString(@"Entire Content", @"entire content menu item label"), - - NSLocalizedString(@"None", @"none menu item label"), - NSLocalizedString(@"Selected Rows (TSV)", @"selected rows (TSV) menu item label"), - NSLocalizedString(@"Selected Rows (CSV)", @"selected rows (CSV) menu item label"), - NSLocalizedString(@"Selected Rows (SQL)", @"selected rows (SQL) menu item label"), - NSLocalizedString(@"Table Content (TSV)", @"table content (TSV) menu item label"), - NSLocalizedString(@"Table Content (CSV)", @"table content (CSV) menu item label"), - NSLocalizedString(@"Table Content (SQL)", @"table content (SQL) menu item label"), - - NSLocalizedString(@"None", @"none menu item label"), - NSLocalizedString(@"Insert as Text", @"insert as text item label"), - NSLocalizedString(@"Insert as Snippet", @"insert as snippet item label"), - NSLocalizedString(@"Replace Selection", @"replace selection item label"), - NSLocalizedString(@"Replace Entire Content", @"replace entire content item label"), - NSLocalizedString(@"Show as Text Tooltip", @"show as text tooltip item label"), - NSLocalizedString(@"Show as HTML Tooltip", @"show as html tooltip item label"), - NSLocalizedString(@"Show as HTML", @"show as html item label"), - - NSLocalizedString(@"None", @"none menu item label"), - NSLocalizedString(@"Show as Text Tooltip", @"show as text tooltip item label"), - NSLocalizedString(@"Show as HTML Tooltip", @"show as html tooltip item label"), - NSLocalizedString(@"Show as HTML", @"show as html item label"), - - NSLocalizedString(@"None", @"none menu item label"), - NSLocalizedString(@"Show as Text Tooltip", @"show as text tooltip item label"), - NSLocalizedString(@"Show as HTML Tooltip", @"show as html tooltip item label"), - NSLocalizedString(@"Show as HTML", @"show as html item label"), - - NSLocalizedString(@"None", @"none menu item label"), - NSLocalizedString(@"Current Word", @"current word item label"), - NSLocalizedString(@"Current Line", @"current line item label"), - NSLocalizedString(@"Current Query", @"current query item label"), - NSLocalizedString(@"Entire Content", @"entire content item label"), - - NSLocalizedString(@"None", @"none menu item label"), - - NSLocalizedString(@"None", @"none menu item label"), - NSLocalizedString(@"Database changed", @"database changed item label"), - NSLocalizedString(@"Table changed", @"table changed item label"), - NSLocalizedString(@"Table Row changed", @"table row changed item label"), - - NSLocalizedString(@"None", @"none menu item label"), - NSLocalizedString(@"Database changed", @"database changed item label"), - NSLocalizedString(@"Table changed", @"table changed item label"), - - NSLocalizedString(@"exclude BLOB", @"exclude BLOB item label"), - NSLocalizedString(@"include BLOB", @"include BLOB item label"), - NSLocalizedString(@"save BLOB as image file", @"save BLOB as image file item label"), - NSLocalizedString(@"save BLOB as dat file", @"save BLOB as dat file item label"), + NSLocalizedString(@"None", @"Bundle Editor : Scope=General : Input source dropdown: 'None' item"), + + NSLocalizedString(@"None", @"Bundle Editor : Scope=Field : Input source dropdown: 'None' item"), + NSLocalizedString(@"Selected Text", @"Bundle Editor : Scope=Field : Input source dropdown: 'selected text' item"), + NSLocalizedString(@"Entire Content", @"Bundle Editor : Scope=Field : Input source dropdown: 'entire content' item"), + + NSLocalizedString(@"None", @"Bundle Editor : Scope=Data-Table : Input source dropdown: 'none' item"), + NSLocalizedString(@"Selected Rows (TSV)", @"Bundle Editor : Scope=Data-Table : Input source dropdown: 'selected rows as tab-separated' item"), + NSLocalizedString(@"Selected Rows (CSV)", @"Bundle Editor : Scope=Data-Table : Input source dropdown: 'selected rows as comma-separated' item"), + NSLocalizedString(@"Selected Rows (SQL)", @"Bundle Editor : Scope=Data-Table : Input source dropdown: 'selected rows as SQL' item"), + NSLocalizedString(@"Table Content (TSV)", @"Bundle Editor : Scope=Data-Table : Input source dropdown: 'table content as tab-separated' item"), + NSLocalizedString(@"Table Content (CSV)", @"Bundle Editor : Scope=Data-Table : Input source dropdown: 'table content as comma-separated' item"), + NSLocalizedString(@"Table Content (SQL)", @"Bundle Editor : Scope=Data-Table : Input source dropdown: 'table content as SQL' item"), + + NSLocalizedString(@"None", @"Bundle Editor : Scope=Field : Output dropdown : 'none' item"), + NSLocalizedString(@"Insert as Text", @"Bundle Editor : Scope=Field : Output dropdown : 'insert as text' item"), + NSLocalizedString(@"Insert as Snippet", @"Bundle Editor : Scope=Field : Output dropdown : 'insert as snippet' item"), + NSLocalizedString(@"Replace Selection", @"Bundle Editor : Scope=Field : Output dropdown : 'replace selection' item"), + NSLocalizedString(@"Replace Entire Content", @"Bundle Editor : Scope=Field : Output dropdown : 'replace entire content' item"), + NSLocalizedString(@"Show as Text Tooltip", @"Bundle Editor : Scope=Field : Output dropdown : 'show as text tooltip' item"), + NSLocalizedString(@"Show as HTML Tooltip", @"Bundle Editor : Scope=Field : Output dropdown : 'show as html tooltip' item"), + NSLocalizedString(@"Show as HTML", @"Bundle Editor : Scope=Field : Output dropdown : 'show as html' item"), + + NSLocalizedString(@"None", @"Bundle Editor : Scope=General : Output dropdown : 'none' item"), + NSLocalizedString(@"Show as Text Tooltip", @"Bundle Editor : Scope=General : Output dropdown : 'show as text tooltip' item"), + NSLocalizedString(@"Show as HTML Tooltip", @"Bundle Editor : Scope=General : Output dropdown : 'show as html tooltip' item"), + NSLocalizedString(@"Show as HTML", @"Bundle Editor : Scope=General : Output dropdown : 'show as html' item"), + + NSLocalizedString(@"None", @"Bundle Editor : Scope=Data-Table : Output dropdown : 'none' item"), + NSLocalizedString(@"Show as Text Tooltip", @"Bundle Editor : Scope=Data-Table : Output dropdown : 'show as text tooltip' item"), + NSLocalizedString(@"Show as HTML Tooltip", @"Bundle Editor : Scope=Data-Table : Output dropdown : 'show as html tooltip' item"), + NSLocalizedString(@"Show as HTML", @"Bundle Editor : Scope=Data-Table : Output dropdown : 'show as html' item"), + + NSLocalizedString(@"None", @"Bundle Editor : Fallback Input source dropdown : 'none' item"), + NSLocalizedString(@"Current Word", @"Bundle Editor : Fallback Input source dropdown : 'current word' item"), + NSLocalizedString(@"Current Line", @"Bundle Editor : Fallback Input source dropdown : 'current line' item"), + NSLocalizedString(@"Current Query", @"Bundle Editor : Fallback Input source dropdown : 'current query' item"), + NSLocalizedString(@"Entire Content", @"Bundle Editor : Fallback Input source dropdown : 'entire content' item"), + + NSLocalizedString(@"None", @"Bundle Editor : Scope=Field : Trigger dropdown : 'none' item"), + + NSLocalizedString(@"None", @"Bundle Editor : Scope=Data-Table : Trigger dropdown : 'none' item"), + NSLocalizedString(@"Database changed", @"Bundle Editor : Scope=Data-Table : Trigger dropdown : 'database changed' item"), + NSLocalizedString(@"Table changed", @"Bundle Editor : Scope=Data-Table : Trigger dropdown : 'table changed' item"), + NSLocalizedString(@"Table Row changed", @"Bundle Editor : Scope=Data-Table : Trigger dropdown : 'table row changed' item"), + + NSLocalizedString(@"None", @"Bundle Editor : Scope=General : Trigger dropdown : 'none' item"), + NSLocalizedString(@"Database changed", @"Bundle Editor : Scope=General : Trigger dropdown : 'database changed' item"), + NSLocalizedString(@"Table changed", @"Bundle Editor : Scope=General : Trigger dropdown : 'table changed' item"), + + NSLocalizedString(@"exclude BLOB", @"Bundle Editor : BLOB dropdown : 'exclude BLOB' item"), + NSLocalizedString(@"include BLOB", @"Bundle Editor : BLOB dropdown : 'include BLOB' item"), + NSLocalizedString(@"save BLOB as image file", @"Bundle Editor : BLOB dropdown : 'save BLOB as image file' item"), + NSLocalizedString(@"save BLOB as dat file", @"Bundle Editor : BLOB dropdown : 'save BLOB as dat file' item"), nil] forKeys:allPopupScopeItems]; @@ -285,15 +292,15 @@ [anItem release]; [inputGeneralScopePopUpMenu compatibleRemoveAllItems]; - anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"General", @"general scope menu label") action:@selector(scopeButtonChanged:) keyEquivalent:@""]; + anItem = [[NSMenuItem alloc] initWithTitle:SP_BUNDLEEDITOR_SCOPE_GENERAL_STRING action:@selector(scopeButtonChanged:) keyEquivalent:@""]; [anItem setTag:kGeneralScopeArrayIndex]; [inputGeneralScopePopUpMenu addItem:anItem]; [anItem release]; - anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Input Field", @"input field scope menu label") action:@selector(scopeButtonChanged:) keyEquivalent:@""]; + anItem = [[NSMenuItem alloc] initWithTitle:SP_BUNDLEEDITOR_SCOPE_INPUTFIELD_STRING action:@selector(scopeButtonChanged:) keyEquivalent:@""]; [anItem setTag:kInputFieldScopeArrayIndex]; [inputGeneralScopePopUpMenu addItem:anItem]; [anItem release]; - anItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Data Table", @"data table scope menu label") action:@selector(scopeButtonChanged:) keyEquivalent:@""]; + anItem = [[NSMenuItem alloc] initWithTitle:SP_BUNDLEEDITOR_SCOPE_DATATABLE_STRING action:@selector(scopeButtonChanged:) keyEquivalent:@""]; [anItem setTag:kDataTableScopeArrayIndex]; [inputGeneralScopePopUpMenu addItem:anItem]; [anItem release]; @@ -316,9 +323,9 @@ SPBundleShellVariableExitNone, SPBundleShellVariableExitReplaceContent, SPBundleShellVariableExitReplaceSelection, - SPBundleShellVariableExitInsertAsHTML, - SPBundleShellVariableExitInsertAsHTMLTooltip, - SPBundleShellVariableExitInsertAsTextTooltip, + SPBundleShellVariableExitShowAsHTML, + SPBundleShellVariableExitShowAsHTMLTooltip, + SPBundleShellVariableExitShowAsTextTooltip, SPBundleShellVariableInputFilePath, SPBundleShellVariableInputTableMetaData, SPBundleShellVariableBundlePath, @@ -350,6 +357,10 @@ nil ] retain]; + if([[NSUserDefaults standardUserDefaults] objectForKey:SPBundleDeletedDefaultBundlesKey]) { + [deletedDefaultBundles setArray:[[NSUserDefaults standardUserDefaults] objectForKey:SPBundleDeletedDefaultBundlesKey]]; + } + [self _initTree]; } @@ -601,11 +612,11 @@ [commandsOutlineView reloadData]; - NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error", @"error") - defaultButton:NSLocalizedString(@"OK", @"OK button") + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error", @"Bundle Editor : Copy-Command-Error : error dialog title") + defaultButton:NSLocalizedString(@"OK", @"Bundle Editor : Copy-Command-Error : OK button") alternateButton:nil otherButton:nil - informativeTextWithFormat:NSLocalizedString(@"Error while duplicating Bundle content.", @"error while duplicating Bundle content")]; + informativeTextWithFormat:NSLocalizedString(@"Error while duplicating Bundle content.", @"Bundle Editor : Copy-Command-Error : Copying failed error message")]; [alert setAlertStyle:NSCriticalAlertStyle]; [alert runModal]; @@ -615,6 +626,8 @@ } [bundle setObject:newFileName forKey:kBundleNameKey]; + [self saveBundle:bundle atPath:nil]; + // Insert duplicate below selected one NSUInteger *currentPath[[currentIndexPath length]]; [currentIndexPath getIndexes:¤tPath]; @@ -709,11 +722,11 @@ [commandsOutlineView abortEditing]; - NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Remove selected Bundle?", @"remove selected bundle message") - defaultButton:NSLocalizedString(@"Remove", @"remove button") - alternateButton:NSLocalizedString(@"Cancel", @"cancel button") + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Remove selected Bundle?", @"Bundle Editor : Remove-Bundle: remove dialog title") + defaultButton:NSLocalizedString(@"Remove", @"Bundle Editor : Remove-Bundle: remove button") + alternateButton:NSLocalizedString(@"Cancel", @"Bundle Editor : Remove-Bundle: cancel button") otherButton:nil - informativeTextWithFormat:NSLocalizedString(@"Are you sure you want to move the selected Bundle to the Trash and remove them respectively?", @"move to trash and remove resp the selected bundle informative message")]; + informativeTextWithFormat:NSLocalizedString(@"Are you sure you want to move the selected Bundle to the Trash and remove them respectively?", @"Bundle Editor : Remove-Bundle: remove dialog message")]; [alert setAlertStyle:NSCriticalAlertStyle]; @@ -763,7 +776,7 @@ */ - (IBAction)showHelp:(id)sender { - [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:NSLocalizedString(@"http://www.sequelpro.com/docs/Bundle_Editor", @"Localized help page for bundle editor - do not localize if no translated webpage is available")]]; + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:SPLOCALIZEDURL_BUNDLEEDITORHELP]]; } /** @@ -798,6 +811,27 @@ [self close]; } +- (IBAction)undeleteDefaultBundles:(id)sender +{ + [NSApp beginSheet:undeleteSheet + modalForWindow:[self window] + modalDelegate:self + didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) + contextInfo:@"undeleteSelectedDefaultBundles"]; +} + +- (IBAction)closeUndeleteDefaultBundlesSheet:(id)sender +{ + + [NSApp endSheet:[sender window] returnCode:[sender tag]]; + + if ([sender respondsToSelector:@selector(orderOut:)]) + [sender orderOut:nil]; + else if ([sender respondsToSelector:@selector(window)]) + [[sender window] orderOut:nil]; + +} + /** * Save all touched bundles to disk and close the Bundle Editor window */ @@ -843,8 +877,8 @@ for(id item in allBundles) { if(![self saveBundle:item atPath:nil]) { closeMe = NO; - NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while saving “%@”.", @"error while saving “%@”"), [item objectForKey:kBundleNameKey]] - defaultButton:NSLocalizedString(@"OK", @"OK button") + NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while saving “%@”.", @"Bundle Editor : Save-and-Close-Error : error dialog title"), [item objectForKey:kBundleNameKey]] + defaultButton:NSLocalizedString(@"OK", @"Bundle Editor : Save-and-Close-Error : OK button") alternateButton:nil otherButton:nil informativeTextWithFormat:@""]; @@ -871,6 +905,7 @@ NSFileManager *fm = [NSFileManager defaultManager]; BOOL isDir = NO; + BOOL isNewBundle = NO; // If passed aPath is nil construct the path from bundle's bundleName. // aPath is mainly used for dragging a bundle from table view. @@ -888,6 +923,7 @@ if(![fm createDirectoryAtPath:aPath withIntermediateDirectories:YES attributes:nil error:nil]) return NO; isDir = YES; + isNewBundle = YES; } // If aPath exists but it's not a folder bail out @@ -908,6 +944,30 @@ kBundleNameKey, nil]]; + + if(!isNewBundle) { + NSError *readError = nil; + NSString *convError = nil; + NSPropertyListFormat format; + NSDictionary *cmdData = nil; + NSData *pData = [NSData dataWithContentsOfFile:cmdFilePath 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(@"“%@” file couldn't be read.", cmdFilePath); + NSBeep(); + if (cmdData) [cmdData release]; + return NO; + } else { + // Check for changes and return if no changes are found + if([[saveDict description] isEqualToString:[cmdData description]]) + return YES; + if([cmdData objectForKey:SPBundleFileIsDefaultBundleKey]) + [saveDict setObject:[NSNumber numberWithBool:YES] forKey:SPBundleFileDefaultBundleWasModifiedKey]; + } + if (cmdData) [cmdData release]; + } + // Remove a given old command.plist file [fm removeItemAtPath:cmdFilePath error:nil]; [saveDict writeToFile:cmdFilePath atomically:YES]; @@ -949,8 +1009,8 @@ NSString *moveToTrashCommand = [NSString stringWithFormat:@"osascript -e 'tell application \"Finder\" to move (POSIX file \"%@\") to the trash'", thePath]; [moveToTrashCommand runBashCommandWithEnvironment:nil atCurrentDirectoryPath:nil error:&error]; if(error != nil) { - NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while moving “%@” to Trash.", @"error while moving “%@” to trash"), thePath] - defaultButton:NSLocalizedString(@"OK", @"OK button") + NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while moving “%@” to Trash.", @"Bundle Editor : Trash-Bundle(s)-Error : error dialog title"), thePath] + defaultButton:NSLocalizedString(@"OK", @"Bundle Editor : Trash-Bundle(s)-Error : OK button") alternateButton:nil otherButton:nil informativeTextWithFormat:[error localizedDescription]]; @@ -960,6 +1020,10 @@ deletionSuccessfully = NO; break; } + if([obj objectForKey:SPBundleFileIsDefaultBundleKey]) { + [deletedDefaultBundles addObject:[NSArray arrayWithObjects:[obj objectForKey:SPBundleFileUUIDKey], [obj objectForKey:SPBundleFileNameKey], nil]]; + [[NSUserDefaults standardUserDefaults] setObject:deletedDefaultBundles forKey:SPBundleDeletedDefaultBundlesKey]; + } [commandsOutlineView reloadData]; } } @@ -978,7 +1042,8 @@ [addButton setEnabled:([[commandBundleTreeController selectionIndexPath] length] > 1)]; } - } else if([contextInfo isEqualToString:@"saveBundle"]) { + } + else if([contextInfo isEqualToString:@"saveBundle"]) { if (returnCode == NSOKButton) { id aBundle = [self _currentSelectedObject]; @@ -998,8 +1063,8 @@ } 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") + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while saving the Bundle.", @"Bundle Editor : Save-Bundle-Error : error dialog title") + defaultButton:NSLocalizedString(@"OK", @"Bundle Editor : Save-Bundle-Error : OK button") alternateButton:nil otherButton:nil informativeTextWithFormat:@""]; @@ -1009,6 +1074,28 @@ } } } + else if([contextInfo isEqualToString:@"undeleteSelectedDefaultBundles"]) { + if(returnCode == 1) { + + NSIndexSet *selectedRows = [undeleteTableView selectedRowIndexes]; + + if(![selectedRows count]) return; + + NSInteger rowIndex; + NSMutableArray *stillUndeletedBundles = [NSMutableArray array]; + for(rowIndex = 0; rowIndex < [deletedDefaultBundles count]; rowIndex++) { + if(![selectedRows containsIndex:rowIndex]) + [stillUndeletedBundles addObject:[deletedDefaultBundles objectAtIndex:rowIndex]]; + } + [deletedDefaultBundles setArray:stillUndeletedBundles]; + [undeleteTableView reloadData]; + [[NSUserDefaults standardUserDefaults] setObject:stillUndeletedBundles forKey:SPBundleDeletedDefaultBundlesKey]; + [[NSUserDefaults standardUserDefaults] synchronize]; + [[NSApp delegate] reloadBundles:nil]; + [self reloadBundles:self]; + + } + } } @@ -1096,6 +1183,24 @@ } #pragma mark - +#pragma mark TableView delegates + +- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView +{ + return [deletedDefaultBundles count]; +} + +- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex +{ + return [[deletedDefaultBundles objectAtIndex:rowIndex] objectAtIndex:1]; +} + +- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex +{ + return NO; +} + +#pragma mark - #pragma mark outline delegates - (BOOL)outlineView:(id)outlineView isItemExpandable:(id)item @@ -1201,7 +1306,7 @@ } - (NSString *)outlineView:(NSOutlineView *)outlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation{ - if([outlineView levelForItem:item] == 0) return NSLocalizedString(@"Installed Bundles", @"Installed Bundles"); + if([outlineView levelForItem:item] == 0) return NSLocalizedString(@"Installed Bundles", @"Bundle Editor : Outline View : 'BUNDLES' item : tooltip"); if([outlineView levelForItem:item] == 1) { NSString *bName = [[item representedObject] objectForKey:kBundleNameKey]; NSUInteger k = 0; @@ -1218,13 +1323,13 @@ } switch([self _scopeIndexForArrangedScopeIndex:k]) { case kInputFieldScopeArrayIndex: - return NSLocalizedString(@"Input Field Scope\ncommands will run on each text input field", @"Input Field Scope\ncommands will run on each text input field tooltip"); + return NSLocalizedString(@"Input Field Scope\ncommands will run on each text input field", @"Bundle Editor : Outline View : 'Input Field' item : tooltip"); break; case kDataTableScopeArrayIndex: - return NSLocalizedString(@"Data Table Scope\ncommands will run on the Content and Query data tables", @"Data Table Scope\ncommands will run on the Content and Query data tables tooltip"); + return NSLocalizedString(@"Data Table Scope\ncommands will run on the Content and Query data tables", @"Bundle Editor : Outline View : 'Data Table' item : tooltip"); break; case kGeneralScopeArrayIndex: - return NSLocalizedString(@"General Scope\ncommands will run application-wide", @"General Scope\ncommands will run application-wide tooltip"); + return NSLocalizedString(@"General Scope\ncommands will run application-wide", @"Bundle Editor : Outline View : 'General' item : tooltip"); break; default: return @""; @@ -1232,25 +1337,25 @@ } if([outlineView levelForItem:item] == 2) { if([[item representedObject] objectForKey:kChildrenKey]) { - return [NSString stringWithFormat:@"“%@” %@", [[item representedObject] objectForKey:kBundleNameKey], NSLocalizedString(@"submenu label", @"submenu label")]; + return [NSString stringWithFormat:NSLocalizedString(@"Bundles in category “%@”",@"Bundle Editor : Outline View : Menu Category item : tooltip"), [[item representedObject] objectForKey:kBundleNameKey]]; } else { if([[item representedObject] objectForKey:SPBundleFileTooltipKey] && [[[item representedObject] objectForKey:SPBundleFileTooltipKey] length]) return [[item representedObject] objectForKey:SPBundleFileTooltipKey]; else - return [NSString stringWithFormat:@"“%@” Bundle", [[item representedObject] objectForKey:kBundleNameKey]]; + return [NSString stringWithFormat:SP_BUNDLEEDITOR_OUTLINE_BUNDLE_TOOLTIP_STRING, [[item representedObject] objectForKey:kBundleNameKey]]; } } if([outlineView levelForItem:item] == 3) { if([[item representedObject] objectForKey:SPBundleFileTooltipKey] && [[[item representedObject] objectForKey:SPBundleFileTooltipKey] length]) return [[item representedObject] objectForKey:SPBundleFileTooltipKey]; else - return [NSString stringWithFormat:@"“%@” Bundle", [[item representedObject] objectForKey:kBundleNameKey]]; + return [NSString stringWithFormat:SP_BUNDLEEDITOR_OUTLINE_BUNDLE_TOOLTIP_STRING, [[item representedObject] objectForKey:kBundleNameKey]]; } return @""; } #pragma mark - -#pragma mark TableView delegate +#pragma mark TableView (outline) delegate /** * Traps enter and esc and edit/cancel without entering next row @@ -1386,6 +1491,10 @@ return ([[commandBundleTreeController selectedObjects] count] == 1 && ![[[commandBundleTreeController selectedObjects] objectAtIndex:0] objectForKey:kChildrenKey]); } + if ( action == @selector(undeleteDefaultBundles:) ) { + return ([deletedDefaultBundles count]) ? YES : NO; + } + return YES; } |