[qwaq] Clean up Editor's event forwarding

Much less clunky with that container object. With this, I think it will
be useful moving the forwarding into View. Still unsure on that, though.
This commit is contained in:
Bill Currie 2020-03-26 14:16:58 +09:00
parent aac732fc63
commit e018f5cf71
3 changed files with 7 additions and 16 deletions

View file

@ -53,7 +53,7 @@
current_file = [self find_file: state.file];
file_proxy = [[ProxyView alloc] initWithView: current_file];
[[current_file gotoLine:state.line - 1] highlightLine];
[[current_file onEvent] addListener: self :@selector(key_event:)];
[[current_file onEvent] addListener: self :@selector(key_event::)];
//FIXME id<View>?
[source_window insertSelected: (View *) file_proxy];
[source_window setTitle: [current_file filename]];
@ -74,9 +74,9 @@
printf ("%s:%d\n", state.file, state.line);
if (current_file != file) {
[[current_file onEvent] removeListener:self :@selector(key_event:)];
[[current_file onEvent] removeListener:self :@selector(key_event::)];
[file_proxy setView:file];
[[file onEvent] addListener:self :@selector(key_event:)];
[[file onEvent] addListener:self :@selector(key_event::)];
[source_window setTitle: [file filename]];
current_file = file;
}
@ -150,10 +150,10 @@ key_event (Debugger *self, Editor *file, qwaq_event_t *event)
return 0;
}
-(void)key_event: (ed_event_t *)event
-(void)key_event:(Editor *)editor :(qwaq_event_t *)event
{
if (key_event (self, event.editor, event.event)) {
event.event.what = qe_none;
if (key_event (self, editor, event)) {
event.what = qe_none;
}
}

View file

@ -8,12 +8,6 @@
@class EditBuffer;
@class ListenerGroup;
// Data sent to onKeyEvent listeners
typedef struct ed_event_s {
Editor *editor;
struct qwaq_event_s *event;
} ed_event_t;
@interface Editor : View
{
EditBuffer *buffer;
@ -28,7 +22,6 @@ typedef struct ed_event_s {
unsigned line_count;
string filename;
ListenerGroup *onEvent;
ed_event_t _event;
}
-initWithRect:(Rect) rect file:(string) filename;
-(ListenerGroup *)onEvent;

View file

@ -91,13 +91,11 @@ static int handleEvent (Editor *self, qwaq_event_t *event)
[super handleEvent: event];
// give any listeners a chance to override or extend event handling
_event.editor = self;
_event.event = event;
if (event.what & qe_positional) {
event.mouse.x -= xpos;
event.mouse.y -= ypos;
}
[onEvent respond: &_event];
[onEvent respond:self withObject:event];
if (handleEvent (self, event)) {
event.what = qe_none;
}