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/SPBundleEditorController.m | 106 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 4 deletions(-) (limited to 'Source/SPBundleEditorController.m') 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 -- cgit v1.2.3