OakDocumentView now manage gutter’s size

This commit is contained in:
Allan Odgaard
2012-08-29 23:43:20 +02:00
parent 9af3c2ff1a
commit 4e9c5c4693
2 changed files with 43 additions and 0 deletions

View File

@@ -25,6 +25,8 @@ PUBLIC @interface OakDocumentView : NSView <GutterViewDelegate, GutterViewColumn
NSMutableArray* topAuxiliaryViews;
NSMutableArray* bottomAuxiliaryViews;
NSInteger isResizingTextView;
IBOutlet NSPanel* tabSizeSelectorPanel;
}
@property (nonatomic, readonly) OakTextView* textView;

View File

@@ -71,11 +71,45 @@ private:
- (BOOL)showResizeThumb { return statusBar.showResizeThumb; }
- (void)setShowResizeThumb:(BOOL)flag { statusBar.showResizeThumb = flag; }
- (void)updateGutterWidth
{
++isResizingTextView;
CGFloat currentWidth = NSWidth(gutterScrollView.frame);
CGFloat desiredWidth = NSWidth(gutterView.frame);
// To avoid problems where width never stabilizes, we only allow size to grow if called recursively
CGFloat gutterWidth = isResizingTextView == 1 ? desiredWidth : std::max(currentWidth, desiredWidth);
NSRect gutterRect = gutterScrollView.frame;
gutterRect.size.width = gutterWidth++; // Increment as we draw the divider
[gutterScrollView setFrame:gutterRect];
NSRect textViewRect = textScrollView.frame;
textViewRect.size.width = NSMaxX(textViewRect) - gutterWidth;
textViewRect.origin.x = gutterWidth;
[textScrollView setFrame:textViewRect];
--isResizingTextView;
}
- (void)updateGutterHeight
{
[gutterView setFrameSize:NSMakeSize(NSWidth(gutterView.frame), NSHeight(textView.frame))];
[gutterView sizeToFit];
[self updateGutterWidth];
}
- (NSRect)gutterDividerRect
{
return NSMakeRect(NSMaxX(gutterScrollView.frame), NSMinY(gutterScrollView.frame), 1, NSHeight(gutterScrollView.frame));
}
- (void)textViewFrameDidChange:(NSNotification*)aNotification;
{
[[NSNotificationCenter defaultCenter] postNotificationName:GVColumnDataSourceDidChange object:self];
[self updateGutterHeight];
}
- (id)initWithFrame:(NSRect)aRect
{
D(DBF_OakDocumentView, bug("%s\n", [NSStringFromRect(aRect) UTF8String]););
@@ -125,6 +159,8 @@ private:
statusBar.autoresizingMask = NSViewWidthSizable;
[self addSubview:statusBar];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textViewFrameDidChange:) name:NSViewFrameDidChangeNotification object:textView];
[self setDocument:document::from_content("", "text.plain")]; // file type is only to avoid potential “no grammar” warnings in console
iterate(keyPath, ObservedTextViewKeyPaths)
@@ -160,6 +196,8 @@ private:
kBookmarksColumnIdentifier : @[ [self gutterImage:@"Bookmark Pressed Template"], [self gutterImage:@"Bookmark Pressed Template"], [self gutterImage:@"Bookmark Pressed Template"] ],
kFoldingsColumnIdentifier : @[ [NSNull null], [self gutterImage:@"Folding Top Pressed Template"], [self gutterImage:@"Folding Collapsed Pressed Template"], [self gutterImage:@"Folding Bottom Pressed Template"] ],
};
[self updateGutterHeight];
}
- (IBAction)makeTextLarger:(id)sender { [self setFont:[NSFont fontWithName:[textView.font fontName] size:[textView.font pointSize] + 1]]; }
@@ -262,6 +300,7 @@ private:
}
[textView setDocument:document];
[self updateGutterHeight];
[self updateStyle];
if(oldDocument)
@@ -304,6 +343,8 @@ private:
D(DBF_OakDocumentView, bug("show line numbers %s\n", BSTR([gutterView visibilityForColumnWithIdentifier:GVLineNumbersColumnIdentifier])););
BOOL isVisibleFlag = ![gutterView visibilityForColumnWithIdentifier:GVLineNumbersColumnIdentifier];
[gutterView setVisibility:isVisibleFlag forColumnWithIdentifier:GVLineNumbersColumnIdentifier];
[gutterView sizeToFit];
[self updateGutterWidth];
if(isVisibleFlag)
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"DocumentView Disable Line Numbers"];