-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMNLineNumberingTextView.m
128 lines (83 loc) · 2.48 KB
/
MNLineNumberingTextView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//
// LineNumberingTextView.m
// SampleApp
//
// Created by Masatoshi Nishikata on 06/03/24.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//
#import <SproutedInterface/MNLineNumberingTextView.h>
@implementation MNLineNumberingTextView
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void) awakeFromNib
{
MNLineNumberingTextStorage* ts = [[MNLineNumberingTextStorage alloc] init];
[[self layoutManager] replaceTextStorage:ts];
[[self textStorage] setDelegate:self];
NSScrollView* scrollView = [self enclosingScrollView];
// *** set up main text View *** //
//textView setting -- add ruler to textView
MNLineNumberingRulerView* aNumberingRulerView =
[[MNLineNumberingRulerView alloc] initWithScrollView:scrollView
orientation:NSVerticalRuler];
[scrollView setVerticalRulerView:aNumberingRulerView ];
//configuration
[scrollView setHasVerticalRuler:YES];
[scrollView setHasHorizontalRuler:NO];
[scrollView setRulersVisible:YES];
[aNumberingRulerView release];
}
/*
- (void)awakeFromNib
{
if ([[self superclass] instancesRespondToSelector:@selector(awakeFromNib)]) {
[super awakeFromNib];
}
}
*/
-(void)dealloc
{
[super dealloc];
}
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
{
NSMenuItem* customMenuItem;
NSMenu* aContextMenu = [super menuForEvent:theEvent];
//add separator
customMenuItem = [NSMenuItem separatorItem];
[customMenuItem setRepresentedObject:@"MN"];
[aContextMenu addItem:customMenuItem ];
//
customMenuItem = [[NSMenuItem alloc] initWithTitle:@"Show/Hide Gutter"
action:@selector(toggleGutterVisiblity) keyEquivalent:@""];
[customMenuItem setRepresentedObject:@"MN"];
[aContextMenu addItem:customMenuItem ];
[customMenuItem release];
//
//
customMenuItem = [[NSMenuItem alloc] initWithTitle:@"Jump to..."
action:@selector(jumpTo) keyEquivalent:@""];
[customMenuItem setRepresentedObject:@"MN"];
[aContextMenu addItem:customMenuItem ];
[customMenuItem release];
return aContextMenu;
}
-(void)toggleGutterVisiblity
{
NSRulerView* rv = [[self enclosingScrollView] verticalRulerView];
[rv setVisible:![rv isVisible]];
}
-(void)jumpTo
{
[[[self enclosingScrollView] verticalRulerView] startSheet];
}
- (void)textStorageDidProcessEditing:(NSNotification *)aNotification
{
[[[self enclosingScrollView] verticalRulerView] setNeedsDisplay:YES];
}
@end