diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPAppController.m | 4 | ||||
-rw-r--r-- | Source/SPBundleEditorController.h | 11 | ||||
-rw-r--r-- | Source/SPBundleEditorController.m | 106 | ||||
-rw-r--r-- | Source/SPEditSheetTextView.m | 14 |
4 files changed, 126 insertions, 9 deletions
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 <Cocoa/Cocoa.h> #import <ShortcutRecorder/ShortcutRecorder.h> +#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 |