Skip to content

Commit 125c207

Browse files
committed
Fix that status line doesn't show correctly in Xcode 6.4 and 7.
This fix completely rewrite the status line implementation. It uses autolayout and binding to show a status line at right position. This may fix the issue #830 since now it uses color from the theme.
1 parent 732f3c7 commit 125c207

8 files changed

+134
-173
lines changed

XVim/IDEEditor+XVim.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@
1212

1313
@interface IDEEditor(XVim)
1414
+ (void)xvim_initialize;
15-
- (void)xvim_didSetupEditor;
16-
- (void)xvim_primitiveInvalidate;
17-
@end
15+
@end

XVim/IDEEditor+XVim.m

+2-51
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,17 @@
1111
#import "IDESourceEditor.h"
1212
#import "Logger.h"
1313
#import "XVim.h"
14+
#import "XVimOptions.h"
15+
#import "NSObject+ExtraData.h"
1416
#import "XVimStatusLine.h"
1517
#import <objc/runtime.h>
1618
#import "NSObject+XVimAdditions.h"
1719

18-
#define DID_REGISTER_OBSERVER_KEY "net.JugglerShu.IDEEditorHook._didRegisterObserver"
1920

2021
@implementation IDEEditor(XVim)
2122

2223
+ (void)xvim_initialize{
23-
[self xvim_swizzleInstanceMethod:@selector(didSetupEditor) with:@selector(xvim_didSetupEditor)];
24-
[self xvim_swizzleInstanceMethod:@selector(primitiveInvalidate) with:@selector(xvim_primitiveInvalidate)];
2524
}
2625

27-
- (void)xvim_didSetupEditor{
28-
29-
[self xvim_didSetupEditor];
30-
31-
// If you do not like status line comment out folloing.
32-
// ---- FROM HERE ----
33-
NSView* container = nil;
34-
if( [NSStringFromClass([self class]) isEqualToString:@"IDESourceCodeComparisonEditor"] ){
35-
container = [(IDESourceCodeComparisonEditor*)self layoutView];
36-
}
37-
else if( [NSStringFromClass([self class]) isEqualToString:@"IDESourceCodeEditor"] ){
38-
container = [(IDESourceCodeEditor*)self containerView];
39-
}else{
40-
return;
41-
}
42-
43-
if (container != nil) {
44-
XVimStatusLine *status = [XVimStatusLine associateOf:container];
45-
if (status == nil) {
46-
// Insert status line
47-
[container setPostsFrameChangedNotifications:YES];
48-
status = [[XVimStatusLine alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
49-
[container addSubview:status];
50-
[status associateWith:container];
51-
status.editor = self;
52-
53-
// Layout
54-
[[NSNotificationCenter defaultCenter] addObserver:status selector:@selector(didContainerFrameChanged:) name:NSViewFrameDidChangeNotification object:container];
55-
[status layoutStatus:container];
56-
[container performSelector:@selector(invalidateLayout)];
57-
58-
// For % register and to notify contents of editor is changed
59-
[self addObserver:[XVim instance] forKeyPath:@"document" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:(__bridge void*)self];
60-
objc_setAssociatedObject(self, DID_REGISTER_OBSERVER_KEY, [NSNumber numberWithBool:YES], OBJC_ASSOCIATION_RETAIN);
61-
}
62-
}
63-
//---- TO HERE ----
64-
}
65-
66-
- (void)xvim_primitiveInvalidate {
67-
IDEEditor *editor = (IDEEditor *)self;
68-
NSNumber *didRegisterObserver = objc_getAssociatedObject(editor, DID_REGISTER_OBSERVER_KEY);
69-
if ([didRegisterObserver boolValue]) {
70-
[editor removeObserver:[XVim instance] forKeyPath:@"document"];
71-
}
72-
73-
[self xvim_primitiveInvalidate];
74-
}
7526

7627
@end

XVim/IDESourceCodeEditor+XVim.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
@interface IDESourceCodeEditor(XVim)
1313
+ (void)xvim_initialize;
1414
- (NSArray*) xvim_textView:(NSTextView *)textView willChangeSelectionFromCharacterRanges:(NSArray *)oldSelectedCharRanges toCharacterRanges:(NSArray *)newSelectedCharRanges;
15+
- (id)xvim_initWithNibName:(NSString*)arg1 bundle:(NSBundle*)arg2 document:(IDEEditorDocument*)arg3;
1516
@end

XVim/IDESourceCodeEditor+XVim.m

+79
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,98 @@
88

99
#import "IDESourceCodeEditor+XVim.h"
1010
#import "IDEKit.h"
11+
#import "DVTFoundation.h"
1112
#import "XVimWindow.h"
1213
#import "Logger.h"
1314
#import "XVimStatusLine.h"
1415
#import "XVim.h"
1516
#import "NSObject+XVimAdditions.h"
17+
#import "NSobject+ExtraData.h"
1618

1719
@implementation IDESourceCodeEditor(XVim)
1820
+ (void)xvim_initialize{
1921
[self xvim_swizzleInstanceMethod:@selector(textView:willChangeSelectionFromCharacterRanges:toCharacterRanges:) with:@selector(xvim_textView:willChangeSelectionFromCharacterRanges:toCharacterRanges:)];
22+
[self xvim_swizzleInstanceMethod:@selector(initWithNibName:bundle:document:) with:@selector(xvim_initWithNibName:bundle:document:)];
2023
}
2124

2225
- (NSArray*) xvim_textView:(NSTextView *)textView willChangeSelectionFromCharacterRanges:(NSArray *)oldSelectedCharRanges toCharacterRanges:(NSArray *)newSelectedCharRanges
2326
{
2427
return newSelectedCharRanges;
2528
}
29+
30+
- (id)xvim_initWithNibName:(NSString*)name bundle:(NSBundle*)bundle document:(IDEEditorDocument*)doc{
31+
id obj = [self xvim_initWithNibName:name bundle:bundle document:doc];
32+
NSView* container = [[obj view] contentView];
33+
34+
// Insert status line
35+
if( nil != container ){
36+
// TODO: Observe DVTFontAndColorSourceTextSettingsChangedNotification to change color of status bar
37+
DVTSourceTextScrollView* scrollView = [self mainScrollView];
38+
[scrollView setTranslatesAutoresizingMaskIntoConstraints:NO]; // To use autolayout we need set this NO
39+
40+
// Add status view
41+
XVimStatusLine* status = [[XVimStatusLine alloc] initWithString:doc.filePath.pathString];
42+
[status setTranslatesAutoresizingMaskIntoConstraints:NO];
43+
[container addSubview:status];
44+
45+
// Bind its visibility to 'laststatus'
46+
XVimLaststatusTransformer* transformer = [[XVimLaststatusTransformer alloc] init];
47+
[status bind:@"hidden" toObject:[[XVim instance] options] withKeyPath:@"laststatus" options:@{NSValueTransformerBindingOption:transformer}];
48+
49+
50+
// View autolayout constraints (for the source view and status bar)
51+
52+
// Same width with the parent
53+
[container addConstraint:[NSLayoutConstraint constraintWithItem:scrollView
54+
attribute:NSLayoutAttributeWidth
55+
relatedBy:NSLayoutRelationEqual
56+
toItem:container
57+
attribute:NSLayoutAttributeWidth
58+
multiplier:1.0
59+
constant:0.0]];
60+
61+
// ScrollView's left position is 0
62+
[container addConstraint:[NSLayoutConstraint constraintWithItem:scrollView
63+
attribute:NSLayoutAttributeLeft
64+
relatedBy:NSLayoutRelationEqual
65+
toItem:container
66+
attribute:NSLayoutAttributeLeft
67+
multiplier:1.0
68+
constant:0.0]];
69+
// Position scrollView above the status bar
70+
[container addConstraint:[NSLayoutConstraint constraintWithItem:scrollView
71+
attribute:NSLayoutAttributeBottom
72+
relatedBy:NSLayoutRelationEqual
73+
toItem:status
74+
attribute:NSLayoutAttributeTop
75+
multiplier:1.0
76+
constant:0]];
77+
// ScrollView fills to top of the container view
78+
[container addConstraint:[NSLayoutConstraint constraintWithItem:scrollView
79+
attribute:NSLayoutAttributeTop
80+
relatedBy:NSLayoutRelationEqual
81+
toItem:container
82+
attribute:NSLayoutAttributeTop
83+
multiplier:1.0
84+
constant:0.0]];
85+
// Place Status line at bottom edge
86+
[container addConstraint:[NSLayoutConstraint constraintWithItem:status
87+
attribute:NSLayoutAttributeBottom
88+
relatedBy:NSLayoutRelationEqual
89+
toItem:container
90+
attribute:NSLayoutAttributeBottom
91+
multiplier:1.0
92+
constant:0.0]];
93+
// Status line width fills the container
94+
[container addConstraint:[NSLayoutConstraint constraintWithItem:status
95+
attribute:NSLayoutAttributeWidth
96+
relatedBy:NSLayoutRelationEqual
97+
toItem:container
98+
attribute:NSLayoutAttributeWidth
99+
multiplier:1.0
100+
constant:0.0]];
101+
}
102+
103+
return obj;
104+
}
26105
@end

XVim/Logger.m

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "Logger.h"
1010
#import <objc/runtime.h>
1111
#import <Foundation/Foundation.h>
12+
#import "DVTKit.h"
1213

1314
#define LOGGER_DEFAULT_NAME @"LoggerDefaultName"
1415

@@ -235,14 +236,17 @@ + (void) traceViewInfo:(NSView*)obj subView:(BOOL)sub{
235236
[Logger traceViewInfoImpl:obj subView:sub prefix:@""];
236237
}
237238

239+
238240
+ (void)traceView:(NSView*)view depth:(NSUInteger)depth{
239241
NSMutableString* str = [[NSMutableString alloc] init];
240242
for( NSUInteger i = 0 ; i < depth; i++ ){
241243
[str appendString:@" "];
242244
}
243245
[str appendString:@"%p:%@ (Tag:%d)"];
244-
NSLog(str, view, NSStringFromClass([view class]),
245-
[view tag]);
246+
if( [view isKindOfClass:NSClassFromString(@"DVTControllerContentView")]){
247+
[str appendFormat:@" <--- %@", [(DVTControllerContentView*)view viewController].description];
248+
}
249+
NSLog(str, view, NSStringFromClass([view class]), [view tag]);
246250
for(NSView* v in [view subviews] ){
247251
[self traceView:v depth:depth+1];
248252
}

XVim/XVim.m

-9
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,6 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
229229
}else{
230230
[[Logger defaultLogger] setLogFile:nil];
231231
}
232-
} else if( [keyPath isEqualToString:@"document"] ){
233-
NSString *documentPath = [[[object document] fileURL] path];
234-
self.document = documentPath;
235-
IDEEditor* editor = (__bridge IDEEditor*)context;
236-
237-
if (documentPath != nil) {
238-
NSDictionary *userInfo = @{XVimDocumentPathKey:documentPath, XVimStatusLineIDEEditorKey:editor};
239-
[[NSNotificationCenter defaultCenter] postNotificationName:XVimDocumentChangedNotification object:nil userInfo:userInfo];
240-
}
241232
}
242233
}
243234

XVim/XVimStatusLine.h

+4-9
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@
88

99
#import <Cocoa/Cocoa.h>
1010

11-
extern NSString* const XVimStatusLineIDEEditorKey;
12-
13-
@class IDEEditor;
14-
15-
@interface XVimStatusLine : NSView
16-
@property (weak,nonatomic) IDEEditor* editor;
17-
- (void)layoutStatus:(NSView*)container;
11+
@interface XVimLaststatusTransformer : NSValueTransformer
12+
@end
1813

19-
+ (XVimStatusLine*)associateOf:(id)object;
20-
- (void)associateWith:(id)object;
14+
@interface XVimStatusLine : NSTextField
15+
- (id)initWithString:(NSString*)str;
2116
@end

0 commit comments

Comments
 (0)