scide: DocManager - report warnings via the status bar
[supercollider.git] / editors / scapp / GoToPanel.M
blob992416b223ae4184a97dadedb0bf1788d4b1942f
1 /*
2 * GoToPanel.M
3 * SC3lang
5 * Created by j. trutzschler on 02 sept 2003.
6 derived from TextFinder.m by Ali Ozer
8 a panel that searches and selects a line
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #import "GoToPanel.h"
29 #import "SCBase.h"
30 #import "PyrSymbol.h"
31 #include "PyrObject.h"
32 #include "PyrKernel.h"
33 #include "GC.h"
34 #include "VMGlobals.h"
36 @implementation GoToPanel
38 static id sharedSelectLineObject = nil;
40 + (id)sharedInstance
42 if (!sharedSelectLineObject) {
43 [[self allocWithZone:[[NSApplication sharedApplication] zone]] init];
45 return sharedSelectLineObject;
48 - (id)init
50 if (sharedSelectLineObject) {
51 [super dealloc];
52 return sharedSelectLineObject;
55 if (!(self = [super init])) return nil;
57 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidActivate:) name:NSApplicationDidBecomeActiveNotification object:[NSApplication sharedApplication]];
59 sharedSelectLineObject = self;
60 return self;
63 - (void)appDidActivate:(NSNotification *)notification
65 // [self loadFindStringFromPasteboard];
68 - (void) loadUI
70 if (![NSBundle loadNibNamed:@"GoToLinePanel" owner:self]) {
71 post("could not load GoToPanel.nib");
73 if (self == sharedSelectLineObject) [[findTextField window] setFrameAutosaveName:@"Find"];
77 - (NSPanel *)gotoLinePanel
79 if (!findTextField) [self loadUI];
80 return (NSPanel *)[findTextField window];
83 - (void)dealloc
85 if (self != sharedSelectLineObject) {
86 [[NSNotificationCenter defaultCenter] removeObserver:self];
87 [super dealloc];
91 - (NSTextView *)textObjectToSelectIn
93 id obj = [[NSApp mainWindow] firstResponder];
94 return (obj && [obj isKindOfClass:[NSTextView class]]) ? obj : nil;
97 - (void)orderFrontGotoLinePanel:(id)sender
99 NSPanel *panel = [self gotoLinePanel];
100 [findTextField selectText:nil];
101 [panel makeKeyAndOrderFront:nil];
104 - (void)selectLine:(id)sender
106 int linenum = [findTextField intValue];
107 if(!linenum)[self getAndDisplayCurrentLine];
108 else
109 [self prselectLine: linenum];
112 - (void) getAndDisplayCurrentLine
114 NSTextView *localTextView = [self textObjectToSelectIn];
115 NSRange range = [localTextView selectedRange];
116 unsigned select = range.location + 1;
117 if(!select) select = 0;
118 NSLayoutManager *layoutManager = [localTextView layoutManager];
119 unsigned numberOfLines, index, numberOfGlyphs = [layoutManager numberOfGlyphs];
120 NSRange lineRange;
121 for (numberOfLines = 0, index = 0; index < numberOfGlyphs && index<select; numberOfLines++){
123 (void) [layoutManager lineFragmentRectForGlyphAtIndex:index effectiveRange:&lineRange];
124 index = NSMaxRange(lineRange);
126 [findTextField setIntValue: numberOfLines];
127 [localTextView setSelectedRange: lineRange];
128 [localTextView scrollRangeToVisible: lineRange];
131 - (void)prselectLine:(int)linenum
134 NSTextView *localTextView = [self textObjectToSelectIn];
135 NSLayoutManager *layoutManager = [localTextView layoutManager];
136 unsigned numberOfLines, index, numberOfGlyphs = [layoutManager numberOfGlyphs];
137 NSRange lineRange;
138 for (numberOfLines = 0, index = 0; index < numberOfGlyphs && (int)numberOfLines < linenum; numberOfLines++) {
140 (void) [layoutManager lineFragmentRectForGlyphAtIndex:index effectiveRange:&lineRange];
141 index = NSMaxRange(lineRange);
144 [localTextView setSelectedRange: lineRange];
145 [localTextView scrollRangeToVisible: lineRange];
148 @end