;;; bottle.k -- Initializer for the editor. ;;; Copyright (c) 2008 Takashi Yamamiya ;;; All rights reserved. ;;; ;;; Permission is hereby granted, free of charge, to any person obtaining a ;;; copy of this software and associated documentation files (the 'Software'), ;;; to deal in the Software without restriction, including without limitation ;;; the rights to use, copy, modify, merge, publish, distribute, and/or sell ;;; copies of the Software, and to permit persons to whom the Software is ;;; furnished to do so, provided that the above copyright notice(s) and this ;;; permission notice appear in all copies of the Software and that both the ;;; above copyright notice(s) and this permission notice appear in supporting ;;; documentation. ;;; ;;; THE SOFTWARE IS PROVIDED 'AS IS'. USE ENTIRELY AT YOUR OWN RISK. (define TextView (import "TextView")) (define KeyDownEvent (import "KeyDownEvent")) (define SDL (import "SDL")) (define true (import "true")) (define false (import "false")) (define editor [TextView default]) (if [[OS arguments] isEmpty] [[TextView default] load: [[editor baseDirectory], '"welcome.txt"]] [[TextView default] load: [[OS arguments] first]]) ;; In SDL, key (= SDL virtual keysym) is cleverly chosen to map to ASCII (define [TextView handleKeyDownEvent: event] (let () ;[StdOut print: [event key]] (or (and [event controlPressed] (== [event key] '122) [self undo]) ; z (and [event controlPressed] (== [event key] '47) [self undo]) ; / (and [event controlPressed] (== [event key] '112) [self xUp: event]) ; p (and [event controlPressed] (== [event key] '110) [self xDown: event]) ; n (and [event controlPressed] (== [event key] '102) [self xRight: event]) ;f (and [event controlPressed] (== [event key] '98) [self xLeft: event]) ;b (and [event controlPressed] (== [event key] '101) [self xEOL: event]) ;e (and [event controlPressed] (== [event key] '97) [self xBOL: event]) ;a (and [event altPressed] (== [event key] '119) [self copy]) ;w (and [event controlPressed] (== [event key] '119) [self cut]) ;w (and [event controlPressed] (== [event key] '121) [self paste]) ;y (and [event controlPressed] (== [event key] '107) [self killLine]) ;k (and [event controlPressed] (== [event key] '32) [self isSelecting: true]) ;SPC (and [event controlPressed] (== [event key] '103) [self keyboardQuit]) ;g (and [event altPressed] (== [event key] '100) [self xDoit: event]) ;d (and [event altPressed] (== [event key] '112) [self xPrintIt: event]) ;p (and [event altPressed] (== [event key] '115) [self save]) ;s (and [event altPressed] (== [event key] '114) (load "bottle.k")) ;r (and (== [event key] [SDL SDLK_BACKSPACE]) [self xBackspace: event]) (and (== [event key] [SDL SDLK_UP]) [self xUp: event]) (and (== [event key] [SDL SDLK_DOWN]) [self xDown: event]) (and (== [event key] [SDL SDLK_RIGHT]) [self xRight: event]) (and (== [event key] [SDL SDLK_LEFT]) [self xLeft: event]) (and (== [event ucs4] '13) [self xInsert: '10]) ;; \r -> \n (and (< '0 [event ucs4]) (< [event ucs4] '256) [self xInsert: [event ucs4]]) )))