From 3f55b5c341c6fe10dd467b439392b0a43d13beaf Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 24 Nov 2010 13:41:31 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20Editor=20-=20further=20work=20to?= =?UTF-8?q?=20display=20Bundle=20commands=20in=20a=20Outline=20view=20orde?= =?UTF-8?q?red=20by=20scopes=20and=20categories=20-=20attention:=20only=20?= =?UTF-8?q?partially=20workable!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/BundleEditor.xib | 1248 ++++++++++++++--------------- Source/SPBundleEditorController.h | 7 +- Source/SPBundleEditorController.m | 315 ++++++-- 3 files changed, 823 insertions(+), 747 deletions(-) diff --git a/Interfaces/English.lproj/BundleEditor.xib b/Interfaces/English.lproj/BundleEditor.xib index dafcc959..fe0dfdbc 100644 --- a/Interfaces/English.lproj/BundleEditor.xib +++ b/Interfaces/English.lproj/BundleEditor.xib @@ -23,7 +23,7 @@ YES - + YES @@ -60,7 +60,7 @@ NSWindow {3.40282e+38, 3.40282e+38} - {726, 444} + {655, 444} 256 @@ -76,6 +76,156 @@ 272 YES + + + 4370 + + YES + + + 2304 + + YES + + + 4370 + {146, 420} + + YES + + + -2147483392 + {{224, 0}, {16, 17}} + + + YES + + bundleName + 143 + 16 + 1000 + + 75628096 + 2048 + + + LucidaGrande + 11 + 3100 + + + 3 + MC4zMzMzMzI5ODU2AA + + + 6 + System + headerTextColor + + 3 + MAA + + + + + 337772096 + 133120 + Text Cell + + + + 6 + System + controlBackgroundColor + + 3 + MC42NjY2NjY2ODY1AA + + + + 6 + System + controlTextColor + + + + 3 + YES + YES + + + + 3 + 0.0 + + 6 + System + _sourceListBackgroundColor + + 1 + MC44MzkyMTU2OTU5IDAuODY2NjY2Njc0NiAwLjg5ODAzOTIyMTgAA + + + + 6 + System + gridColor + + 3 + MC41AA + + + 20 + 1262485504 + + + SPBundleEditorOutlineView + 5 + 15 + 0 + YES + 1 + 1 + 14 + YES + + + {{1, 1}, {146, 420}} + + + + + 4 + + + + -2147483392 + {{224, 17}, {15, 102}} + + + _doScroller: + 0.99585062265396118 + + + + -2147483392 + {{1, 406}, {192, 15}} + + 1 + + _doScroller: + 0.98947370052337646 + + + {{0, 22}, {148, 422}} + + + 562 + + + + QSAAAEEgAABBoAAAQaAAAA + 290 @@ -210,7 +360,7 @@ _popUpItemAction: - + YES YES @@ -222,7 +372,7 @@ _popUpItemAction: - + Reload Bundles @@ -249,180 +399,6 @@ NO 0 - - - 4370 - - YES - - - 2304 - - YES - - - 4370 - {143, 405} - - YES - - - 4352 - {143, 17} - - - - - - -2147483392 - {{198, 0}, {12, 17}} - - - - YES - - name - 140 - 20 - 2000 - - 75628096 - 2048 - Bundles - - LucidaGrande - 11 - 3100 - - - 3 - MC4zMzMzMzI5ODU2AA - - - 6 - System - headerTextColor - - 3 - MAA - - - - - 337772097 - 133120 - Text Cell - - - - 6 - System - controlBackgroundColor - - 3 - MC42NjY2NjY2ODY1AA - - - - 6 - System - controlTextColor - - - - 3 - YES - YES - - - - 3 - 2 - - 6 - System - _sourceListBackgroundColor - - 1 - MC44MzkyMTU2OTU5IDAuODY2NjY2Njc0NiAwLjg5ODAzOTIyMTgAA - - - - 6 - System - gridColor - - 3 - MC41AA - - - 16 - 1262485504 - - - SPQueryFavoriteManagerTable - 5 - 15 - 0 - YES - 1 - 1 - - - {{0, 17}, {143, 405}} - - - - - 4 - - - - -2147483392 - {{198, 17}, {11, 322}} - - 256 - - _doScroller: - 0.94985252618789673 - - - - -2147483392 - {{-100, -100}, {311, 15}} - - 1 - - _doScroller: - 0.99532711505889893 - - - - 2304 - - YES - - - {143, 17} - - - - - 4 - - - - {{0, 22}, {143, 422}} - - - 528 - - - - - - QSAAAEEgAABBkAAAQZAAAA - {142, 444} @@ -1079,31 +1055,21 @@ {{0, 0}, {1920, 1058}} - {726, 466} + {655, 466} {3.40282e+38, 3.40282e+38} SPBundleEditor - + YES - command - name - category - tooltip - disabled bundleName - editor - datatable - inputfield - internalKeyEquivalent YES YES YES YES - YES - YES + children @@ -1178,14 +1144,6 @@ 819 - - - commandBundleArrayController - - - - 826 - addCommandBundle: @@ -1210,30 +1168,6 @@ 829 - - - dataSource - - - - 830 - - - - delegate - - - - 831 - - - - commandsTableView - - - - 832 - delegate @@ -1323,76 +1257,12 @@ 853 - - value: selection.name - - - - - - value: selection.name - value - selection.name - 2 - + + saveAndCloseWindow: + + - 865 - - - - value: selection.category - - - - - - value: selection.category - value - selection.category - 2 - - - 866 - - - - value: selection.tooltip - - - - - - value: selection.tooltip - value - selection.tooltip - 2 - - - 867 - - - - value: arrangedObjects.bundleName - - - - - - value: arrangedObjects.bundleName - value - arrangedObjects.bundleName - 2 - - - 874 - - - - saveAndCloseWindow: - - - - 875 + 875 @@ -1442,14 +1312,6 @@ 906 - - - menu - - - - 907 - removeCommandBundle: @@ -1474,22 +1336,6 @@ 916 - - - value: selection.internalKeyEquivalent - - - - - - value: selection.internalKeyEquivalent - value - selection.internalKeyEquivalent - 2 - - - 919 - saveBundle: @@ -1506,22 +1352,6 @@ 925 - - - value: selection.command - - - - - - value: selection.command - value - selection.command - 2 - - - 927 - delegate @@ -1538,14 +1368,6 @@ 931 - - - nextKeyView - - - - 940 - nextKeyView @@ -1642,14 +1464,6 @@ 953 - - - nextKeyView - - - - 954 - scopeButtonChanged: @@ -1670,10 +1484,146 @@ reloadBundles: - + 959 + + + commandsOutlineView + + + + 971 + + + + dataSource + + + + 976 + + + + delegate + + + + 977 + + + + commandBundleTreeController + + + + 983 + + + + value: arrangedObjects.bundleName + + + + + + value: arrangedObjects.bundleName + value + arrangedObjects.bundleName + 2 + + + 985 + + + + value: selection.name + + + + + + value: selection.name + value + selection.name + 2 + + + 986 + + + + value: selection.command + + + + + + value: selection.command + value + selection.command + 2 + + + 987 + + + + value: selection.category + + + + + + value: selection.category + value + selection.category + 2 + + + 988 + + + + value: selection.tooltip + + + + + + value: selection.tooltip + value + selection.tooltip + 2 + + + 989 + + + + value: selection.internalKeyEquivalent + + + + + + value: selection.internalKeyEquivalent + value + selection.internalKeyEquivalent + 2 + + + 990 + + + + menu + + + + 991 + @@ -1736,24 +1686,12 @@ YES - + Bundle Table View - - 729 - - - YES - - - - - - - 730 @@ -1820,8 +1758,8 @@ - - + + @@ -1836,234 +1774,228 @@ - 748 - - + 876 + + - 749 - + 899 + YES - + + + + - + + Gear Menu + + + 903 + + - 750 - - + 904 + + - 751 - - + 908 + + - 753 - - - YES - - - + 909 + + - 754 - - + 920 + + - 686 - - - YES - - - - - - - - - - - - - - - - - - - - - - - Bundle Content View + 957 + + - 774 - - - YES - - - - Pop Up Button (Output) + 958 + + - 775 - - - YES - - - + 982 + + - 776 - + 962 + YES + + + - + - 788 - + 965 + YES - + - + - 789 - - + 964 + + - 693 - + 963 + + + + + 967 + YES - + - + - 700 - - + 970 + + - 695 - + 686 + YES - + + + + + + + + + + + + + + + + + + + + - - Text Field (Menu Label) - - - 696 - - + + Bundle Content View - 795 - + 820 + YES - + + + + Bordered Scroll View (Command Text View) - 796 - - + 823 + + - 797 - - - YES - - - + 822 + + - 798 - - + 821 + + - 804 - + 938 + YES - + - 780 - + 939 + + + + + 932 + YES - + - Pop Up Button (Input Fallback) + Pop Up Button (Input) - 781 - + 933 + YES - + - + - 782 - - - YES - - + 934 + + - 691 - + 936 + YES - + - Text Field (Menu Category) - 702 - - + 937 + + - 692 - + 859 + YES - + - - 701 - - + + 860 + + 690 @@ -2080,33 +2012,32 @@ - 799 - + 817 + YES - + - Text Field (Tooltip) - 802 - - + 818 + + - 800 - + 804 + YES - + - 801 - - + 824 + + 768 @@ -2130,181 +2061,184 @@ 770 - - YES - - 817 - + 800 + YES - + - 818 - - + 801 + + - 820 - + 799 + YES - - - + - Bordered Scroll View (Command Text View) - - - 821 - - - - - 822 - - + Text Field (Tooltip) - 823 - - + 802 + + - 824 - - + 692 + + + YES + + + - 825 - - - Bundle Commands + 701 + + - 859 - + 691 + YES - + + Text Field (Menu Category) - 860 - - + 702 + + - 876 - - + 780 + + + YES + + + + Pop Up Button (Input Fallback) - 899 - + 781 + YES - - - - + - - Gear Menu + - 903 - - + 782 + + - 904 - - + 797 + + + YES + + + - 908 - - + 798 + + - 909 - - + 795 + + + YES + + + - 920 - - + 796 + + - 932 - + 695 + YES - + - Pop Up Button (Input) + Text Field (Menu Label) - 933 - + 696 + + + + + 693 + YES - + - + - 934 - - + 700 + + - 936 - + 788 + YES - + - 937 - - + 789 + + - 938 - + 774 + YES - + + Pop Up Button (Output) - 939 - - - - - 957 - - + 775 + + + YES + + + - 958 - - + 776 + + @@ -2336,8 +2270,6 @@ 701.IBPluginDependency 702.IBPluginDependency 703.IBPluginDependency - 729.IBPluginDependency - 729.ImportedFromIB2 730.IBPluginDependency 731.IBAttributePlaceholdersKey 731.IBPluginDependency @@ -2352,19 +2284,6 @@ 737.IBPluginDependency 738.IBPluginDependency 741.IBPluginDependency - 748.IBPluginDependency - 749.CustomClassName - 749.IBPluginDependency - 749.ImportedFromIB2 - 750.IBPluginDependency - 750.IBShouldRemoveOnLegacySave - 751.IBPluginDependency - 751.IBShouldRemoveOnLegacySave - 753.IBPluginDependency - 753.ImportedFromIB2 - 754.CustomClassName - 754.IBPluginDependency - 754.ImportedFromIB2 768.IBAttributePlaceholdersKey 768.IBPluginDependency 769.IBPluginDependency @@ -2403,7 +2322,6 @@ 822.IBPluginDependency 823.CustomClassName 823.IBPluginDependency - 825.IBPluginDependency 859.IBAttributePlaceholdersKey 859.IBPluginDependency 860.IBPluginDependency @@ -2426,16 +2344,23 @@ 939.IBPluginDependency 957.IBPluginDependency 958.IBPluginDependency + 962.IBPluginDependency + 963.IBPluginDependency + 964.IBPluginDependency + 965.IBPluginDependency + 967.IBPluginDependency + 970.IBPluginDependency + 982.IBPluginDependency YES com.apple.InterfaceBuilder.CocoaPlugin - {{295, 369}, {655, 444}} + {{226, 478}, {655, 444}} com.apple.InterfaceBuilder.CocoaPlugin - {{295, 369}, {655, 444}} + {{226, 478}, {655, 444}} - {726, 444} + {655, 444} com.apple.InterfaceBuilder.CocoaPlugin com.brandonwalkin.BWToolkit com.brandonwalkin.BWToolkit @@ -2474,8 +2399,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.brandonwalkin.BWToolkit ToolTip @@ -2507,23 +2430,10 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.brandonwalkin.BWToolkit - {{345, 294}, {204, 98}} + {{239, 290}, {204, 98}} com.brandonwalkin.BWToolkit com.brandonwalkin.BWToolkit com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - SPTableView - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - ImageAndTextCell - com.apple.InterfaceBuilder.CocoaPlugin - ToolTip @@ -2617,7 +2527,6 @@ com.apple.InterfaceBuilder.CocoaPlugin SPBundleCommandTextView com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin ToolTip @@ -2654,6 +2563,13 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -2672,7 +2588,7 @@ - 959 + 991 @@ -2685,14 +2601,6 @@ - - ImageAndTextCell - NSTextFieldCell - - IBUserSource - - - NSApplication @@ -2795,14 +2703,6 @@ Source/SPWindowAdditions.h - - SPTableView - NSTableView - - IBUserSource - - - YES @@ -2936,7 +2836,9 @@ YES categoryTextField commandBundleArrayController + commandBundleTreeController commandTextView + commandsOutlineView commandsTableView duplicateMenuItem fallbackLabelField @@ -2954,6 +2856,8 @@ YES NSTextField NSArrayController + NSTreeController + id id NSTableView NSMenuItem @@ -2975,7 +2879,9 @@ YES categoryTextField commandBundleArrayController + commandBundleTreeController commandTextView + commandsOutlineView commandsTableView duplicateMenuItem fallbackLabelField @@ -2999,10 +2905,18 @@ commandBundleArrayController NSArrayController + + commandBundleTreeController + NSTreeController + commandTextView id + + commandsOutlineView + id + commandsTableView NSTableView diff --git a/Source/SPBundleEditorController.h b/Source/SPBundleEditorController.h index a6566e07..b5001e0c 100644 --- a/Source/SPBundleEditorController.h +++ b/Source/SPBundleEditorController.h @@ -25,6 +25,7 @@ #import #import #import "SPBundleCommandTextView.h" +#import "SPOutlineView.h" @class SRRecorderControl; @@ -32,6 +33,7 @@ IBOutlet id commandTextView; IBOutlet NSTableView* commandsTableView; + IBOutlet id commandsOutlineView; IBOutlet NSTextField* nameTextField; IBOutlet NSTextField* tootlipTextField; IBOutlet NSTextField* categoryTextField; @@ -45,9 +47,10 @@ IBOutlet NSMenuItem *revealInFinderMenuItem; IBOutlet SRRecorderControl *keyEquivalentField; - IBOutlet NSArrayController *commandBundleArrayController; + IBOutlet NSTreeController *commandBundleTreeController; NSMutableArray *commandBundleArray; - + NSMutableDictionary *commandBundleTree; + NSString *bundlePath; NSString *draggedFilePath; NSString *oldBundleName; diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index 11c8ad87..b137de13 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -23,6 +23,7 @@ // More info at #import "SPBundleEditorController.h" +#import "SPArrayAdditions.h" @interface SPBundleEditorController (PrivateAPI) @@ -74,6 +75,7 @@ [inputFallbackInputFieldScopeArray release]; if(commandBundleArray) [commandBundleArray release], commandBundleArray = nil; + if(commandBundleTree) [commandBundleTree release], commandBundleTree = nil; if(bundlePath) [bundlePath release], bundlePath = nil; [super dealloc]; @@ -84,6 +86,13 @@ { commandBundleArray = [[NSMutableArray alloc] initWithCapacity:1]; + commandBundleTree = [[NSMutableDictionary alloc] initWithCapacity:1]; + + [commandBundleTree setObject:[NSMutableArray array] forKey:@"children"]; + [commandBundleTree setObject:@"Bundles" forKey:@"bundleName"]; + [[commandBundleTree objectForKey:@"children"] addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSMutableArray array], @"children", NSLocalizedString(@"Input Field", @"input field scope menu label"), @"bundleName", nil]]; + [[commandBundleTree objectForKey:@"children"] addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSMutableArray array], @"children", NSLocalizedString(@"Data Table", @"data table scope menu label"), @"bundleName", nil]]; + [[commandBundleTree objectForKey:@"children"] addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:[NSMutableArray array], @"children", NSLocalizedString(@"General", @"general scope menu label"), @"bundleName", nil]]; // Init all needed menus inputGeneralScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; @@ -224,7 +233,7 @@ - (IBAction)inputPopupButtonChanged:(id)sender { - id currentDict = [commandBundleArray objectAtIndex:[commandsTableView selectedRow]]; + id currentDict = [[commandsOutlineView itemAtRow:[commandsOutlineView selectedRow]] representedObject]; NSMenu* senderMenu = [sender menu]; @@ -248,7 +257,7 @@ - (IBAction)inputFallbackPopupButtonChanged:(id)sender { - id currentDict = [commandBundleArray objectAtIndex:[commandsTableView selectedRow]]; + id currentDict = [[commandsOutlineView itemAtRow:[commandsOutlineView selectedRow]] representedObject]; NSMenu* senderMenu = [sender menu]; @@ -264,7 +273,7 @@ - (IBAction)outputPopupButtonChanged:(id)sender { - id currentDict = [commandBundleArray objectAtIndex:[commandsTableView selectedRow]]; + id currentDict = [[commandsOutlineView itemAtRow:[commandsOutlineView selectedRow]] representedObject]; NSMenu* senderMenu = [sender menu]; @@ -284,7 +293,7 @@ - (IBAction)scopeButtonChanged:(id)sender { - id currentDict = [commandBundleArray objectAtIndex:[commandsTableView selectedRow]]; + id currentDict = [[commandsOutlineView itemAtRow:[commandsOutlineView selectedRow]] representedObject]; NSInteger selectedTag = [sender tag]; @@ -308,7 +317,7 @@ - (IBAction)duplicateCommandBundle:(id)sender { - if ([commandsTableView numberOfSelectedRows] == 1) + if ([commandsOutlineView numberOfSelectedRows] == 1) [self addCommandBundle:self]; else NSBeep(); @@ -324,7 +333,7 @@ // Duplicate a selected Bundle if sender == self if (sender == self) { - NSDictionary *currentDict = [commandBundleArray objectAtIndex:[commandsTableView selectedRow]]; + NSDictionary *currentDict = [[commandsOutlineView itemAtRow:[commandsOutlineView selectedRow]] representedObject]; bundle = [NSMutableDictionary dictionaryWithDictionary:currentDict]; NSString *bundleFileName = [bundle objectForKey:@"bundleName"]; @@ -350,7 +359,7 @@ } if(!copyingWasSuccessful) { - [commandsTableView reloadData]; + [commandsOutlineView reloadData]; NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error", @"error") defaultButton:NSLocalizedString(@"OK", @"OK button") @@ -372,8 +381,8 @@ bundle = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"New Bundle", @"New Name", @"", SPBundleScopeGeneral, nil] forKeys:[NSArray arrayWithObjects:@"bundleName", SPBundleFileNameKey, SPBundleFileCommandKey, SPBundleFileScopeKey, nil]]; } - if ([commandsTableView numberOfSelectedRows] > 0) { - insertIndex = [[commandsTableView selectedRowIndexes] lastIndex]+1; + if ([commandsOutlineView numberOfSelectedRows] > 0) { + insertIndex = [[commandsOutlineView selectedRowIndexes] lastIndex]+1; [commandBundleArray insertObject:bundle atIndex:insertIndex]; } else { @@ -381,18 +390,18 @@ insertIndex = [commandBundleArray count] - 1; } - [commandBundleArrayController rearrangeObjects]; - [commandsTableView reloadData]; + [commandBundleTreeController rearrangeObjects]; + [commandsOutlineView reloadData]; - [commandsTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:insertIndex] byExtendingSelection:NO]; + [commandsOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:insertIndex] byExtendingSelection:NO]; - [commandsTableView scrollRowToVisible:[commandsTableView selectedRow]]; + [commandsOutlineView scrollRowToVisible:[commandsOutlineView selectedRow]]; - [removeButton setEnabled:([commandsTableView numberOfSelectedRows] > 0)]; + [removeButton setEnabled:([[commandBundleTreeController selectedObjects] count] > 0)]; [self _updateInputPopupButton]; - [[self window] makeFirstResponder:commandsTableView]; + [[self window] makeFirstResponder:commandsOutlineView]; } @@ -420,10 +429,10 @@ - (IBAction)revealCommandBundleInFinder:(id)sender { - if([commandsTableView numberOfSelectedRows] != 1) return; + if([commandsOutlineView numberOfSelectedRows] != 1) return; [[NSWorkspace sharedWorkspace] selectFile:[NSString stringWithFormat:@"%@/%@.%@/%@", - bundlePath, [[commandBundleArray objectAtIndex:[commandsTableView selectedRow]] objectForKey:@"bundleName"], SPUserBundleFileExtension, SPBundleFileName] inFileViewerRootedAtPath:nil]; + bundlePath, [[[commandsOutlineView itemAtRow:[commandsOutlineView selectedRow]] representedObject] objectForKey:@"bundleName"], SPUserBundleFileExtension, SPBundleFileName] inFileViewerRootedAtPath:nil]; } @@ -438,7 +447,7 @@ [panel setCanSelectHiddenExtension:YES]; [panel setCanCreateDirectories:YES]; - [panel beginSheetForDirectory:nil file:[[commandBundleArray objectAtIndex:[commandsTableView selectedRow]] objectForKey:@"bundleName"] modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"saveBundle"]; + [panel beginSheetForDirectory:nil file:[[[commandsOutlineView itemAtRow:[commandsOutlineView selectedRow]] representedObject] objectForKey:@"bundleName"] modalForWindow:[self window] modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"saveBundle"]; } - (IBAction)showHelp:(id)sender @@ -467,7 +476,10 @@ // Re-init commandBundleArray [commandBundleArray removeAllObjects]; - [commandsTableView reloadData]; + [[[commandBundleTree objectForKey:@"children"] objectAtIndex:0] setObject:[NSMutableArray array] forKey:@"children"]; + [[[commandBundleTree objectForKey:@"children"] objectAtIndex:1] setObject:[NSMutableArray array] forKey:@"children"]; + [[[commandBundleTree objectForKey:@"children"] objectAtIndex:2] setObject:[NSMutableArray array] forKey:@"children"]; + [commandsOutlineView reloadData]; // Load all installed bundle items if(bundlePath) { @@ -499,7 +511,72 @@ [bundleCommand setObject:[bundle stringByDeletingPathExtension] forKey:@"bundleName"]; [commandBundleArray addObject:bundleCommand]; - + if([[cmdData objectForKey:SPBundleFileScopeKey] isEqualToString:SPBundleScopeInputField]) { + if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length]) { + BOOL catExists = NO; + id children = [[[commandBundleTree objectForKey:@"children"] objectAtIndex:0] objectForKey:@"children"]; + for(id child in children) { + if([child isKindOfClass:[NSDictionary class]] && [child objectForKey:@"children"] && [[child objectForKey:@"bundleName"] isEqualToString:[cmdData objectForKey:SPBundleFileCategoryKey]]) { + [[child objectForKey:@"children"] addObject:bundleCommand]; + catExists = YES; + break; + } + } + if(!catExists) { + NSMutableDictionary *aDict = [NSMutableDictionary dictionary]; + [aDict setObject:[cmdData objectForKey:SPBundleFileCategoryKey] forKey:@"bundleName"]; + [aDict setObject:[NSMutableArray array] forKey:@"children"]; + [[aDict objectForKey:@"children"] addObject:bundleCommand]; + [[[[commandBundleTree objectForKey:@"children"] objectAtIndex:0] objectForKey:@"children"] addObject:aDict]; + } + } else { + [[[[commandBundleTree objectForKey:@"children"] objectAtIndex:0] objectForKey:@"children"] addObject:bundleCommand]; + } + } + else if([[cmdData objectForKey:SPBundleFileScopeKey] isEqualToString:SPBundleScopeDataTable]) { + if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length]) { + BOOL catExists = NO; + id children = [[[commandBundleTree objectForKey:@"children"] objectAtIndex:1] objectForKey:@"children"]; + for(id child in children) { + if([child isKindOfClass:[NSDictionary class]] && [child objectForKey:@"children"] && [[child objectForKey:@"bundleName"] isEqualToString:[cmdData objectForKey:SPBundleFileCategoryKey]]) { + [[child objectForKey:@"children"] addObject:bundleCommand]; + catExists = YES; + break; + } + } + if(!catExists) { + NSMutableDictionary *aDict = [NSMutableDictionary dictionary]; + [aDict setObject:[cmdData objectForKey:SPBundleFileCategoryKey] forKey:@"bundleName"]; + [aDict setObject:[NSMutableArray array] forKey:@"children"]; + [[aDict objectForKey:@"children"] addObject:bundleCommand]; + [[[[commandBundleTree objectForKey:@"children"] objectAtIndex:1] objectForKey:@"children"] addObject:aDict]; + } + } else { + [[[[commandBundleTree objectForKey:@"children"] objectAtIndex:1] objectForKey:@"children"] addObject:bundleCommand]; + } + } + else if([[cmdData objectForKey:SPBundleFileScopeKey] isEqualToString:SPBundleScopeGeneral]) { + if([cmdData objectForKey:SPBundleFileCategoryKey] && [[cmdData objectForKey:SPBundleFileCategoryKey] length]) { + BOOL catExists = NO; + id children = [[[commandBundleTree objectForKey:@"children"] objectAtIndex:2] objectForKey:@"children"]; + for(id child in children) { + if([child isKindOfClass:[NSDictionary class]] && [child objectForKey:@"children"] && [[child objectForKey:@"bundleName"] isEqualToString:[cmdData objectForKey:SPBundleFileCategoryKey]]) { + [[child objectForKey:@"children"] addObject:bundleCommand]; + catExists = YES; + break; + } + } + if(!catExists) { + NSMutableDictionary *aDict = [NSMutableDictionary dictionary]; + [aDict setObject:[cmdData objectForKey:SPBundleFileCategoryKey] forKey:@"bundleName"]; + [aDict setObject:[NSMutableArray array] forKey:@"children"]; + [[aDict objectForKey:@"children"] addObject:bundleCommand]; + [[[[commandBundleTree objectForKey:@"children"] objectAtIndex:2] objectForKey:@"children"] addObject:aDict]; + } + } else { + [[[[commandBundleTree objectForKey:@"children"] objectAtIndex:2] objectForKey:@"children"] addObject:bundleCommand]; + } + } } if (cmdData) [cmdData release]; } @@ -507,11 +584,12 @@ } } - [removeButton setEnabled:([commandsTableView numberOfSelectedRows] > 0)]; + [removeButton setEnabled:([[commandBundleTreeController selectedObjects] count] > 0)]; - [commandBundleArrayController setContent:commandBundleArray]; - [commandBundleArrayController rearrangeObjects]; - [commandsTableView reloadData]; + [commandBundleTreeController setContent:commandBundleTree]; + [commandBundleTreeController rearrangeObjects]; + [commandsOutlineView reloadData]; + [commandsOutlineView expandItem:nil expandChildren:YES]; } @@ -519,7 +597,7 @@ { // Commit all pending edits - if([commandBundleArrayController commitEditing]) { + if([commandBundleTreeController commitEditing]) { // Make the bundleNames unique since they represent folder names NSMutableDictionary *allNames = [NSMutableDictionary dictionary]; @@ -617,15 +695,14 @@ if([contextInfo isEqualToString:@"removeSelectedBundles"]) { if (returnCode == NSAlertDefaultReturn) { - NSIndexSet *indexes = [commandsTableView selectedRowIndexes]; - - // get last index - NSUInteger currentIndex = [indexes lastIndex]; + + NSArray *selObjects = [commandBundleTreeController selectedObjects]; + NSArray *selIndexPaths = [commandBundleTreeController selectionIndexPaths]; - while (currentIndex != NSNotFound) { + for(id obj in selObjects) { // Move already installed Bundles to Trash - NSString *bundleName = [[commandBundleArray objectAtIndex:currentIndex] objectForKey:@"bundleName"]; + NSString *bundleName = [obj objectForKey:@"bundleName"]; NSString *thePath = [NSString stringWithFormat:@"%@/%@.%@", bundlePath, bundleName, SPUserBundleFileExtension]; if([[NSFileManager defaultManager] fileExistsAtPath:thePath isDirectory:nil]) { NSError *error = nil; @@ -647,23 +724,19 @@ break; } } - [commandBundleArray removeObjectAtIndex:currentIndex]; - // get next index (beginning from the end) - currentIndex = [indexes indexLessThanIndex:currentIndex]; } - [commandBundleArrayController rearrangeObjects]; - [commandsTableView reloadData]; + [self reloadBundles:self]; // Set focus to table view to avoid an unstable state - [[self window] makeFirstResponder:commandsTableView]; + [[self window] makeFirstResponder:commandsOutlineView]; - [removeButton setEnabled:([commandsTableView numberOfSelectedRows] > 0)]; + [removeButton setEnabled:([[commandBundleTreeController selectedObjects] count] > 0)]; } } else if([contextInfo isEqualToString:@"saveBundle"]) { if (returnCode == NSOKButton) { - id aBundle = [commandBundleArray objectAtIndex:[commandsTableView selectedRow]]; + id aBundle = [commandBundleArray objectAtIndex:[commandsOutlineView selectedRow]]; NSString *bundleFileName = [aBundle objectForKey:@"bundleName"]; NSString *possibleExisitingBundleFilePath = [NSString stringWithFormat:@"%@/%@.%@", bundlePath, bundleFileName, SPUserBundleFileExtension]; @@ -702,9 +775,9 @@ { if(isTableCellEditing) { - [commandsTableView abortEditing]; + [commandsOutlineView abortEditing]; isTableCellEditing = NO; - [[self window] makeFirstResponder:commandsTableView]; + [[self window] makeFirstResponder:commandsOutlineView]; return NO; } return YES; @@ -715,7 +788,10 @@ { // Clear commandBundleArray if window will close to save memory [commandBundleArray removeAllObjects]; - [commandsTableView reloadData]; + [[[commandBundleTree objectForKey:@"children"] objectAtIndex:0] setObject:[NSMutableArray array] forKey:@"children"]; + [[[commandBundleTree objectForKey:@"children"] objectAtIndex:1] setObject:[NSMutableArray array] forKey:@"children"]; + [[[commandBundleTree objectForKey:@"children"] objectAtIndex:2] setObject:[NSMutableArray array] forKey:@"children"]; + [commandsOutlineView reloadData]; // Remove temporary drag file if any if(draggedFilePath) { @@ -734,7 +810,7 @@ - (void)shortcutRecorder:(SRRecorderControl *)aRecorder keyComboDidChange:(KeyCombo)newKeyCombo { - if([commandsTableView selectedRow] < 0 || [commandsTableView selectedRow] > [commandBundleArray count]) return; + if([commandsOutlineView selectedRow] < 0 || [commandsOutlineView selectedRow] > [commandBundleArray count]) return; // Transform KeyCombo struct to KeyBinding.dict format for NSMenuItems NSMutableString *keyEq = [NSMutableString string]; @@ -753,65 +829,148 @@ [keyEq appendString:@"@"]; [keyEq appendString:theChar]; } - [[commandBundleArray objectAtIndex:[commandsTableView selectedRow]] setObject:keyEq forKey:SPBundleFileKeyEquivalentKey]; + [[[commandsOutlineView itemAtRow:[commandsOutlineView selectedRow]] representedObject] setObject:keyEq forKey:SPBundleFileKeyEquivalentKey]; } #pragma mark - -#pragma mark TableView data source and delegate +#pragma mark outline delegates -/** - * Returns the number of query commandBundleArray. - */ -- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView + +- (BOOL)outlineView:(id)outlineView isItemExpandable:(id)item { - return [commandBundleArray count]; + if([item isKindOfClass:[NSDictionary class]] && [item objectForKey:@"children"]) + return YES; + + return NO; } -- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex +- (NSInteger)outlineView:(id)outlineView numberOfChildrenOfItem:(id)item { - if(oldBundleName) [oldBundleName release], oldBundleName = nil; - oldBundleName = [[[commandBundleArray objectAtIndex:rowIndex] objectForKey:@"bundleName"] retain]; - isTableCellEditing = YES; - return YES; + + if(item == nil) + item = commandBundleTree; + + if([item isKindOfClass:[NSDictionary class]]) + if([item objectForKey:@"children"]) + return [[item objectForKey:@"children"] count]; + else + return [item count]; + + if([item isKindOfClass:[NSArray class]]) + return [item count]; + + return 0; } -/** - * Returns the value for the requested table column and row index. - */ -- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex +- (id)outlineView:(id)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item { - if(![commandBundleArray count]) return @""; + if(item && [item respondsToSelector:@selector(objectForKey:)]) + return [item objectForKey:@"bundleName"]; + return @""; - if([[aTableColumn identifier] isEqualToString:@"name"]) { - if(![[commandBundleArray objectAtIndex:rowIndex] objectForKey:@"name"]) return @"..."; - return [[commandBundleArray objectAtIndex:rowIndex] objectForKey:@"bundleName"]; - } +} - return @""; +- (BOOL)outlineView:outlineView isGroupItem:(id)item +{ + return (![item isLeaf]); +} +- (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item +{ + return (![item isLeaf]); } -- (void)tableViewSelectionDidChange:(NSNotification *)aNotification +- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item { - if([aNotification object] != commandsTableView) return; + return YES; +} + +- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item +{ + return ([item isLeaf]); +} + +- (void)outlineViewSelectionDidChange:(NSNotification *)aNotification +{ + if([aNotification object] != commandsOutlineView) return; [self _updateInputPopupButton]; + } +// - (void)outlineView:(NSOutlineView *)outlineView didClickTableColumn:(NSTableColumn *)tableColumn +// { +// if(outlineView == outlineSchema2) { +// [schemaStatusSplitView setPosition:1000 ofDividerAtIndex:0]; +// [schema12SplitView setPosition:0 ofDividerAtIndex:0]; +// } +// } +// +// - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard +// { +// // Provide data for our custom type, and simple NSStrings. +// [pboard declareTypes:[NSArray arrayWithObjects:DragTableDataFromNavigatorPboardType, DragFromNavigatorPboardType, NSStringPboardType, nil] owner:self]; +// +// // Collect the actual schema paths without leading connection ID +// NSMutableArray *draggedItems = [NSMutableArray array]; +// for(id item in items) { +// id parentObject = [outlineView parentForItem:item] ? [outlineView parentForItem:item] : schemaData; +// if(!parentObject) return NO; +// id parentKeys = [parentObject allKeysForObject:item]; +// if(parentKeys && [parentKeys count] == 1) +// [draggedItems addObject:[[[parentKeys objectAtIndex:0] description] stringByReplacingOccurrencesOfRegex:[NSString stringWithFormat:@"^.*?%@", SPUniqueSchemaDelimiter] withString:@""]]; +// } +// +// // Drag the array with schema paths +// NSMutableData *arraydata = [[[NSMutableData alloc] init] autorelease]; +// NSKeyedArchiver *archiver = [[[NSKeyedArchiver alloc] initForWritingWithMutableData:arraydata] autorelease]; +// [archiver encodeObject:draggedItems forKey:@"itemdata"]; +// [archiver finishEncoding]; +// [pboard setData:arraydata forType:DragFromNavigatorPboardType]; +// +// if([draggedItems count] == 1) { +// NSArray *pathComponents = [[draggedItems objectAtIndex:0] componentsSeparatedByString:SPUniqueSchemaDelimiter]; +// // Is a table? +// if([pathComponents count] == 2) { +// [pboard setString:[NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS %@ SELECT * FROM %@", +// [[pathComponents lastObject] backtickQuotedString], +// [pathComponents componentsJoinedByPeriodAndBacktickQuoted] +// ] forType:DragTableDataFromNavigatorPboardType]; +// } +// } +// // For external destinations provide a comma separated string +// NSMutableString *dragString = [NSMutableString string]; +// for(id item in draggedItems) { +// if([dragString length]) [dragString appendString:@", "]; +// [dragString appendString:[[item componentsSeparatedByString:SPUniqueSchemaDelimiter] componentsJoinedByPeriodAndBacktickQuotedAndIgnoreFirst]]; +// } +// +// if(![dragString length]) return NO; +// +// [pboard setString:dragString forType:NSStringPboardType]; +// return YES; +// } + + +#pragma mark - +#pragma mark TableView data source and delegate + +/** + * Returns the number of query commandBundleArray. + */ + /* * Save spBundle name if inline edited (suppress empty names) and check for renaming and / in the name */ - (void)controlTextDidEndEditing:(NSNotification *)aNotification { - if([aNotification object] != commandsTableView) return; + if([aNotification object] != commandsOutlineView) return; NSString *newBundleName = [[[aNotification userInfo] objectForKey:@"NSFieldEditor"] string]; - NSInteger selectedTableRow = [commandsTableView selectedRow]; - BOOL isValid = YES; if(newBundleName && [newBundleName length] && ![newBundleName rangeOfString:@"/"].length) { @@ -840,10 +999,10 @@ // If not valid reset name to the old one if(!isValid) { if(!oldBundleName) oldBundleName = @"New Name"; - [[commandBundleArray objectAtIndex:selectedTableRow] setObject:oldBundleName forKey:@"bundleName"]; + [[[commandsOutlineView itemAtRow:[commandsOutlineView selectedRow]] representedObject] setObject:oldBundleName forKey:@"bundleName"]; } - [commandsTableView reloadData]; + [commandsOutlineView reloadData]; isTableCellEditing = NO; @@ -867,13 +1026,13 @@ { // Allow to record short-cuts used by the Bundle Editor if([[NSApp mainWindow] firstResponder] == keyEquivalentField) return NO; - return ([commandsTableView numberOfSelectedRows] == 1); + return ([[commandBundleTreeController selectedObjects] count] == 1); } else if ( (action == @selector(removeCommandBundle:)) ) { // Allow to record short-cuts used by the Bundle Editor if([[NSApp mainWindow] firstResponder] == keyEquivalentField) return NO; - return ([commandsTableView numberOfSelectedRows] > 0); + return ([[commandBundleTreeController selectedObjects] count] > 0); } return YES; @@ -898,7 +1057,7 @@ - (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rows toPasteboard:(NSPasteboard*)aPboard { - if([commandsTableView numberOfSelectedRows] != 1 || [rows count] != 1) return NO; + if([commandsOutlineView numberOfSelectedRows] != 1 || [rows count] != 1) return NO; // Remove old temporary drag file if any if(draggedFilePath) { @@ -910,7 +1069,7 @@ NSImage *dragImage; NSPoint dragPosition; - NSDictionary *bundleDict = [commandBundleArray objectAtIndex:[rows firstIndex]]; + NSDictionary *bundleDict = [commandsOutlineView itemAtRow:[rows firstIndex]]; NSString *bundleFileName = [bundleDict objectForKey:@"bundleName"]; NSString *possibleExisitingBundleFilePath = [NSString stringWithFormat:@"%@/%@.%@", bundlePath, bundleFileName, SPUserBundleFileExtension]; @@ -1043,9 +1202,9 @@ NSInteger anIndex; - if([commandsTableView selectedRow] < 0 || [commandsTableView selectedRow] > [commandBundleArray count]) return; + if([commandsOutlineView selectedRow] < 0 || [commandsOutlineView selectedRow] > [commandBundleArray count]) return; - NSDictionary *currentDict = [commandBundleArray objectAtIndex:[commandsTableView selectedRow]]; + NSDictionary *currentDict = [[commandsOutlineView itemAtRow:[commandsOutlineView selectedRow]] representedObject]; NSString *input = [currentDict objectForKey:SPBundleFileInputSourceKey]; if(!input || ![input length]) input = SPBundleInputSourceNone; -- cgit v1.2.3