From 823ce1e87ff4d2a333ff64c17ef818a3afbffca7 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 19 Nov 2010 12:26:45 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Bundle=20Editor=20-=20minor=20fixes=20-=20c?= =?UTF-8?q?ommand=20textView=20is=20now=20a=20SPEditSheetTextView=20for=20?= =?UTF-8?q?better=20undo=20behaviour=20and=20font=20storing=20in=20the=20P?= =?UTF-8?q?refs=20if=20changed=20-=20if=20Bundle=20Editor=20is=20already?= =?UTF-8?q?=20opened=20^=E2=8C=A5=E2=8C=98B=20brings=20it=20to=20the=20fro?= =?UTF-8?q?nt=20=E2=80=A2=20the=20installation=20of=20spTheme=20and=20spBu?= =?UTF-8?q?ndle=20files=20(via=20eg=20double-clicking=20at=20them=20in=20F?= =?UTF-8?q?inder)=20now=20moves=20the=20files=20to=20SP's=20application=20?= =?UTF-8?q?folder=20(if=20successful)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 4 +- Source/SPBundleEditorController.h | 11 +++- Source/SPBundleEditorController.m | 106 ++++++++++++++++++++++++++++++++++++-- Source/SPEditSheetTextView.m | 14 ++++- 4 files changed, 126 insertions(+), 9 deletions(-) (limited to 'Source') diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 2003a9e6..d5a3cef2 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -459,7 +459,7 @@ NSString *newPath = [NSString stringWithFormat:@"%@/%@", themePath, [filename lastPathComponent]]; if(![fm fileExistsAtPath:newPath isDirectory:nil]) { - if(![fm copyItemAtPath:filename toPath:newPath error:nil]) { + if(![fm moveItemAtPath:filename toPath:newPath error:nil]) { NSBeep(); return; } @@ -492,7 +492,7 @@ NSString *newPath = [NSString stringWithFormat:@"%@/%@", bundlePath, [filename lastPathComponent]]; if(![fm fileExistsAtPath:newPath isDirectory:nil]) { - if(![fm copyItemAtPath:filename toPath:newPath error:nil]) { + if(![fm moveItemAtPath:filename toPath:newPath error:nil]) { NSBeep(); return; } diff --git a/Source/SPBundleEditorController.h b/Source/SPBundleEditorController.h index 90ed03f1..5ab3a534 100644 --- a/Source/SPBundleEditorController.h +++ b/Source/SPBundleEditorController.h @@ -24,12 +24,13 @@ #import #import +#import "SPEditSheetTextView.h" @class SRRecorderControl; @interface SPBundleEditorController : NSWindowController { - IBOutlet NSTextView* commandTextView; + IBOutlet id commandTextView; IBOutlet NSTableView* commandsTableView; IBOutlet NSTextField* nameTextField; IBOutlet NSTextField* tootlipTextField; @@ -74,6 +75,11 @@ NSArray *inputFallbackEditorScopeArray; NSArray *inputFallbackInputFieldScopeArray; + BOOL doGroupDueToChars; + BOOL allowUndo; + BOOL wasCutPaste; + BOOL selectionChanged; + NSUndoManager *esUndoManager; } @@ -91,4 +97,7 @@ - (BOOL)saveBundle:(NSDictionary*)bundle atPath:(NSString*)aPath; +- (void)setWasCutPaste; +- (void)setDoGroupDueToChars; + @end diff --git a/Source/SPBundleEditorController.m b/Source/SPBundleEditorController.m index 574836e2..71b2f7ab 100644 --- a/Source/SPBundleEditorController.m +++ b/Source/SPBundleEditorController.m @@ -85,6 +85,8 @@ - (void)awakeFromNib { + [commandTextView setDelegate:self]; + // Init all needed menus inputEditorScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; inputInputFieldScopePopUpMenu = [[NSMenu alloc] initWithTitle:@""]; @@ -205,6 +207,11 @@ [keyEquivalentField setCanCaptureGlobalHotKeys:YES]; + if([[NSUserDefaults standardUserDefaults] dataForKey:@"BundleEditorFont"]) { + NSFont *nf = [NSUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:@"BundleEditorFont"]]; + [commandTextView setFont:nf]; + } + } #pragma mark - @@ -453,7 +460,12 @@ { // Suppress parsing if window is already opened - if([[self window] isVisible]) return; + if([[self window] isVisible]) { + [super showWindow:sender]; + return; + } + + // Order out window [super showWindow:sender]; @@ -513,6 +525,7 @@ } [commandBundleArrayController setContent:commandBundleArray]; + [commandBundleArrayController rearrangeObjects]; [commandsTableView reloadData]; } @@ -592,18 +605,24 @@ // Build scope key NSMutableString *scopes = [NSMutableString string]; - if([bundle objectForKey:SPBundleScopeQueryEditor]) { + if([bundle objectForKey:SPBundleScopeQueryEditor] && [[bundle objectForKey:SPBundleScopeQueryEditor] intValue]) { if([scopes length]) [scopes appendString:@" "]; [scopes appendString:SPBundleScopeQueryEditor]; } - if([bundle objectForKey:SPBundleScopeInputField]) { + if([bundle objectForKey:SPBundleScopeInputField] && [[bundle objectForKey:SPBundleScopeInputField] intValue]) { if([scopes length]) [scopes appendString:@" "]; [scopes appendString:SPBundleScopeInputField]; } - if([bundle objectForKey:SPBundleScopeDataTable]) { + if([bundle objectForKey:SPBundleScopeDataTable] && [[bundle objectForKey:SPBundleScopeInputField] intValue]) { if([scopes length]) [scopes appendString:@" "]; [scopes appendString:SPBundleScopeDataTable]; } + if(![scopes length]) { + // For safety reasons + [scopes setString:[NSString stringWithFormat:@"%@ %@ %@", SPBundleScopeQueryEditor, SPBundleScopeInputField, SPBundleScopeDataTable]]; + [saveDict setObject:SPBundleInputSourceNone forKey:SPBundleFileInputSourceKey]; + [saveDict setObject:SPBundleOutputActionNone forKey:SPBundleFileOutputActionKey]; + } [saveDict setObject:scopes forKey:SPBundleFileScopeKey]; // Remove unnecessary keys @@ -961,6 +980,84 @@ } +#pragma mark - +#pragma mark NSTextView delegates + +/** + * Traps any editing in editTextView to allow undo grouping only if the text buffer was really changed. + * Inform the run loop delayed for larger undo groups. + */ +- (void)textDidChange:(NSNotification *)aNotification +{ + + if([aNotification object] != commandTextView) return; + + [NSObject cancelPreviousPerformRequestsWithTarget:self + selector:@selector(setAllowedUndo) + object:nil]; + + // If conditions match create an undo group + NSInteger cycleCounter; + if( ( wasCutPaste || allowUndo || doGroupDueToChars ) && ![esUndoManager isUndoing] && ![esUndoManager isRedoing] ) { + allowUndo = NO; + wasCutPaste = NO; + doGroupDueToChars = NO; + selectionChanged = NO; + + cycleCounter = 0; + while([esUndoManager groupingLevel] > 0) { + [esUndoManager endUndoGrouping]; + cycleCounter++; + } + while([esUndoManager groupingLevel] < cycleCounter) + [esUndoManager beginUndoGrouping]; + + cycleCounter = 0; + } + + [self performSelector:@selector(setAllowedUndo) withObject:nil afterDelay:0.09]; + +} + + +#pragma mark - +#pragma mark UndoManager methods + +/** + * Establish and return an UndoManager for editTextView + */ +- (NSUndoManager*)undoManagerForTextView:(NSTextView*)aTextView +{ + if (!esUndoManager) + esUndoManager = [[NSUndoManager alloc] init]; + + return esUndoManager; +} + +/** + * Set variable if something in editTextView was cutted or pasted for creating better undo grouping. + */ +- (void)setWasCutPaste +{ + wasCutPaste = YES; +} + +/** + * Will be invoke delayed for creating better undo grouping according to type speed (see [self textDidChange:]). + */ +- (void)setAllowedUndo +{ + allowUndo = YES; +} + +/** + * Will be set if according to characters typed in editTextView for creating better undo grouping. + */ +- (void)setDoGroupDueToChars +{ + doGroupDueToChars = YES; +} + @end #pragma mark - @@ -1055,5 +1152,6 @@ } + @end diff --git a/Source/SPEditSheetTextView.m b/Source/SPEditSheetTextView.m index 7ac5185f..bd0c5a88 100644 --- a/Source/SPEditSheetTextView.m +++ b/Source/SPEditSheetTextView.m @@ -53,14 +53,16 @@ - (IBAction)paste:(id)sender { // Try to create an undo group - [[self delegate] setWasCutPaste]; + if([[self delegate] respondsToSelector:@selector(setWasCutPaste)]) + [[self delegate] setWasCutPaste]; [super paste:sender]; } - (IBAction)cut:(id)sender { // Try to create an undo group - [[self delegate] setWasCutPaste]; + if([[self delegate] respondsToSelector:@selector(setWasCutPaste)]) + [[self delegate] setWasCutPaste]; [super cut:sender]; } @@ -126,6 +128,12 @@ [[self delegate] setDoGroupDueToChars]; } + + if([[[[self delegate] class] description] isEqualToString:@"SPBundleEditorController"]) { + [super keyDown: theEvent]; + return; + } + // Check for assign key equivalents inside user-defined bundle commands NSDictionary *keyEquivalents = [[NSApp delegate] bundleKeyEquivalentsForScope:SPBundleScopeInputField]; if([keyEquivalents count]) { @@ -332,6 +340,8 @@ { if([[[[self delegate] class] description] isEqualToString:@"SPFieldEditorController"]) [[NSUserDefaults standardUserDefaults] setObject:[NSArchiver archivedDataWithRootObject:[self font]] forKey:@"FieldEditorSheetFont"]; + else if([[[[self delegate] class] description] isEqualToString:@"SPBundleEditorController"]) + [[NSUserDefaults standardUserDefaults] setObject:[NSArchiver archivedDataWithRootObject:[self font]] forKey:@"BundleEditorFont"]; } // Action receiver for a font change in the font panel -- cgit v1.2.3