From 79bf97de1dc30afb75a07958ff99b6f95473383e Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sun, 21 Nov 2010 19:42:42 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20line=20numbering=20and=20current=20?= =?UTF-8?q?line=20highlighting=20to=20Bundle=20Editor's=20command=20text?= =?UTF-8?q?=20view=20=E2=80=A2=20made=20each=20Bundle=20in/ouptut=20file?= =?UTF-8?q?=20name=20unique=20to=20allow=20to=20run=20different=20Bundle?= =?UTF-8?q?=20commands=20at=20the=20same=20time=20=E2=80=A2=20fixed=20mino?= =?UTF-8?q?r=20issues=20for=20Bundle=20Editor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/BundleEditor.xib | 36 ++++++- Source/SPBundleCommandTextView.h | 9 ++ Source/SPBundleCommandTextView.m | 150 +++++++++++++++++++++++++++--- Source/SPBundleEditorController.m | 13 ++- Source/SPCopyTable.m | 9 +- Source/SPStringAdditions.m | 9 +- Source/SPTextView.m | 9 +- Source/SPTextViewAdditions.m | 9 +- 8 files changed, 204 insertions(+), 40 deletions(-) diff --git a/Interfaces/English.lproj/BundleEditor.xib b/Interfaces/English.lproj/BundleEditor.xib index fc95329a..5bbbb3c9 100644 --- a/Interfaces/English.lproj/BundleEditor.xib +++ b/Interfaces/English.lproj/BundleEditor.xib @@ -468,7 +468,7 @@ 1 - 11555 + 11299 0 @@ -1760,6 +1760,14 @@ 929 + + + commandScrollView + + + + 931 + @@ -1826,6 +1834,7 @@ + Bundle Table View 729 @@ -1982,6 +1991,7 @@ + Bundle Content View 774 @@ -1991,6 +2001,7 @@ + Pop Up Button (Output) 775 @@ -2045,6 +2056,7 @@ + Text Field (Menu Label) 696 @@ -2096,6 +2108,7 @@ + Pop Up Button (Input Fallback) 781 @@ -2122,6 +2135,7 @@ + Text Field (Menu Category) 702 @@ -2164,6 +2178,7 @@ + Text Field (Tooltip) 802 @@ -2206,6 +2221,7 @@ + Pop Up Button (Input) 769 @@ -2301,6 +2317,7 @@ + Bordered Scroll View (Command Text View) 821 @@ -2510,9 +2527,9 @@ YES com.apple.InterfaceBuilder.CocoaPlugin - {{251, 39}, {655, 444}} + {{515, 73}, {655, 444}} com.apple.InterfaceBuilder.CocoaPlugin - {{251, 39}, {655, 444}} + {{515, 73}, {655, 444}} {726, 444} @@ -2767,7 +2784,7 @@ - 929 + 931 @@ -2904,6 +2921,17 @@ SPBundleCommandTextView NSTextView + + commandScrollView + NSScrollView + + + commandScrollView + + commandScrollView + NSScrollView + + IBDocumentRelativeSource ../../Source/SPBundleCommandTextView.h diff --git a/Source/SPBundleCommandTextView.h b/Source/SPBundleCommandTextView.h index e39ec1dd..fb9cef62 100644 --- a/Source/SPBundleCommandTextView.h +++ b/Source/SPBundleCommandTextView.h @@ -22,13 +22,22 @@ // // More info at +#import "NoodleLineNumberView.h" + @interface SPBundleCommandTextView : NSTextView { + + IBOutlet NSScrollView *commandScrollView; + + NSUserDefaults *prefs; + BOOL textWasChanged; + NoodleLineNumberView *lineNumberView; } - (NSUInteger)characterIndexOfPoint:(NSPoint)aPoint; - (void)insertFileContentOfFile:(NSString *)aPath; - (void)saveChangedFontInUserDefaults; +- (void) setTabStops; @end diff --git a/Source/SPBundleCommandTextView.m b/Source/SPBundleCommandTextView.m index a840101a..72618dbc 100644 --- a/Source/SPBundleCommandTextView.m +++ b/Source/SPBundleCommandTextView.m @@ -37,6 +37,66 @@ return self; } +- (void)dealloc +{ + + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [prefs removeObserver:self forKeyPath:SPCustomQueryEditorTabStopWidth]; + [prefs release]; + [lineNumberView release]; +} + +- (void) awakeFromNib +{ + + prefs = [[NSUserDefaults standardUserDefaults] retain]; + + [prefs addObserver:self forKeyPath:SPCustomQueryEditorTabStopWidth options:NSKeyValueObservingOptionNew context:NULL]; + + if([[NSUserDefaults standardUserDefaults] dataForKey:@"BundleEditorFont"]) { + NSFont *nf = [NSUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] dataForKey:@"BundleEditorFont"]]; + [self setFont:nf]; + } + + lineNumberView = [[NoodleLineNumberView alloc] initWithScrollView:commandScrollView]; + [commandScrollView setVerticalRulerView:lineNumberView]; + [commandScrollView setHasHorizontalRuler:NO]; + [commandScrollView setHasVerticalRuler:YES]; + [commandScrollView setRulersVisible:YES]; + + // Re-define tab stops for a better editing + [self setTabStops]; + +} + +- (void)drawRect:(NSRect)rect +{ + // Draw background only for screen display but not while printing + if([NSGraphicsContext currentContextDrawingToScreen]) { + + // Draw textview's background since due to the snippet highlighting we're responsible for it. + [[NSColor whiteColor] setFill]; + NSRectFill(rect); + + if (![self selectedRange].length && [[self string] length]) { + NSRange r = [[self string] lineRangeForRange:NSMakeRange([self selectedRange].location, 0)]; + NSUInteger rectCount; + [[self textStorage] ensureAttributesAreFixedInRange:r]; + NSRectArray queryRects = [[self layoutManager] rectArrayForCharacterRange: r + withinSelectedCharacterRange: r + inTextContainer: [self textContainer] + rectCount: &rectCount ]; + [[NSColor colorWithCalibratedRed:0.95f green:0.95f blue:0.95f alpha:1.0f] setFill]; + NSRectFillListUsingOperation(queryRects, rectCount, NSCompositeSourceOver); + } + } + + [super drawRect:rect]; + +} + +#pragma mark - + - (IBAction)undo:(id)sender { textWasChanged = NO; @@ -75,24 +135,53 @@ [super cut:sender]; } -/** - * Validate undo and redo menu items - */ -- (BOOL)validateMenuItem:(NSMenuItem *)menuItem +- (void) setTabStops { - - if ([menuItem action] == @selector(undo:)) { - return ([[self undoManager] canUndo]); + NSFont *tvFont = [self font]; + NSInteger i; + NSTextTab *aTab; + NSMutableArray *myArrayOfTabs; + NSMutableParagraphStyle *paragraphStyle; + + BOOL oldEditableStatus = [self isEditable]; + [self setEditable:YES]; + + NSInteger tabStopWidth = [prefs integerForKey:SPCustomQueryEditorTabStopWidth]; + if(tabStopWidth < 1) tabStopWidth = 1; + + float tabWidth = NSSizeToCGSize([[NSString stringWithString:@" "] sizeWithAttributes:[NSDictionary dictionaryWithObject:tvFont forKey:NSFontAttributeName]]).width; + tabWidth = (float)tabStopWidth * tabWidth; + + NSInteger numberOfTabs = 256/tabStopWidth; + myArrayOfTabs = [NSMutableArray arrayWithCapacity:numberOfTabs]; + aTab = [[NSTextTab alloc] initWithType:NSLeftTabStopType location:tabWidth]; + [myArrayOfTabs addObject:aTab]; + [aTab release]; + for(i=1; i