[qwaq] Support base filename and cursor fetching

Getting the base filename and the current cursor position is needed for
execute-to-line support in the debugger.
This commit is contained in:
Bill Currie 2021-06-08 16:50:30 +09:00
parent c06acd3b53
commit c818a2abf9
2 changed files with 34 additions and 3 deletions

View file

@ -21,9 +21,13 @@
Point cursor;
unsigned line_count;
string filename;
string filepath;
}
+(Editor *)withRect:(Rect)rect file:(string)filename;
+(Editor *)withRect:(Rect)rect file:(string)filename path:(string)filepath;
-(string)filename;
-(string)filepath;
-(Point)cursor;
-scrollUp:(unsigned) count;
-scrollDown:(unsigned) count;
-scrollLeft:(unsigned) count;

View file

@ -7,13 +7,18 @@
@implementation Editor
-initWithRect:(Rect) rect file:(string) filename
-initWithRect:(Rect) rect file:(string) filename path:(string) filepath
{
if (!(self = [super initWithRect: rect])) {
return nil;
}
self.filename = str_hold (filename);
buffer = [[EditBuffer withFile:filename] retain];
if (filepath != filename) {
self.filepath = str_hold (filepath);
} else {
self.filepath = filename;
}
buffer = [[EditBuffer withFile:filepath] retain];
line_count = [buffer countLines: {0, [buffer textSize]}];
linebuffer = [[DrawBuffer buffer: { xlen, 1 }] retain];
growMode = gfGrowHi;
@ -25,11 +30,23 @@
+(Editor *)withRect:(Rect)rect file:(string)filename
{
return [[[self alloc] initWithRect:rect file:filename] autorelease];
return [[[self alloc] initWithRect:rect
file:filename
path:filename] autorelease];
}
+(Editor *)withRect:(Rect)rect file:(string)filename path:(string)filepath
{
return [[[self alloc] initWithRect:rect
file:filename
path:filepath] autorelease];
}
-(void)dealloc
{
if (filepath != filename) {
str_free (filepath);
}
str_free (filename);
[vScrollBar release];
[buffer release];
@ -42,6 +59,16 @@
return filename;
}
-(string)filepath
{
return filepath;
}
-(Point)cursor
{
return cursor;
}
-draw
{
[super draw];