mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
[qwaq] Add a key event listener to Editor
This will allow for easy expansion of editor functionality without messing with the editor itself. In particularly, an editor normally doesn't need to know anything about debugger hot keys.
This commit is contained in:
parent
d96059c70e
commit
16bd047022
2 changed files with 22 additions and 0 deletions
|
@ -4,7 +4,15 @@
|
|||
#include "qwaq-editbuffer.h"
|
||||
#include "qwaq-view.h"
|
||||
|
||||
@class Editor;
|
||||
@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
|
||||
{
|
||||
|
@ -19,8 +27,11 @@
|
|||
Point cursor;
|
||||
unsigned line_count;
|
||||
string filename;
|
||||
ListenerGroup *onEvent;
|
||||
ed_event_t _event;
|
||||
}
|
||||
-initWithRect:(Rect) rect file:(string) filename;
|
||||
-(ListenerGroup *)onEvent;
|
||||
-(string)filename;
|
||||
-scrollUp:(unsigned) count;
|
||||
-scrollDown:(unsigned) count;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <QF/keys.h>
|
||||
#include "color.h"
|
||||
#include "qwaq-editor.h"
|
||||
#include "qwaq-listener.h"
|
||||
|
||||
@implementation Editor
|
||||
|
||||
|
@ -15,9 +16,15 @@
|
|||
linebuffer = [DrawBuffer buffer: { xlen, 1 }];
|
||||
growMode = gfGrowHi;
|
||||
options = ofCanFocus;
|
||||
onEvent = [[ListenerGroup alloc] init];
|
||||
return self;
|
||||
}
|
||||
|
||||
-(ListenerGroup *)onEvent
|
||||
{
|
||||
return onEvent;
|
||||
}
|
||||
|
||||
-(string)filename
|
||||
{
|
||||
return filename;
|
||||
|
@ -46,6 +53,10 @@
|
|||
|
||||
-handleEvent:(qwaq_event_t *) event
|
||||
{
|
||||
// give any listeners a chance to override or extend event handling
|
||||
_event.editor = self;
|
||||
_event.event = event;
|
||||
[onEvent respond: &_event];
|
||||
if (event.what & qe_mouse) {
|
||||
if (event.what == qe_mouseclick) {
|
||||
if (event.mouse.buttons & (1 << 3)) {
|
||||
|
|
Loading…
Reference in a new issue