Helios-KeyBindings.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. smalltalk.addPackage('Helios-KeyBindings', {});
  2. smalltalk.addClass('HLBinding', smalltalk.Object, ['key', 'label'], 'Helios-KeyBindings');
  3. smalltalk.addMethod(
  4. "_applyOn_",
  5. smalltalk.method({
  6. selector: "applyOn:",
  7. category: 'actions',
  8. fn: function (aKeyBinder) {
  9. var self = this;
  10. smalltalk.send(self, "_subclassResponsibility", []);
  11. return self;
  12. },
  13. args: ["aKeyBinder"],
  14. source: "applyOn: aKeyBinder\x0a\x09self subclassResponsibility",
  15. messageSends: ["subclassResponsibility"],
  16. referencedClasses: []
  17. }),
  18. smalltalk.HLBinding);
  19. smalltalk.addMethod(
  20. "_isBindingAction",
  21. smalltalk.method({
  22. selector: "isBindingAction",
  23. category: 'testing',
  24. fn: function () {
  25. var self = this;
  26. return false;
  27. },
  28. args: [],
  29. source: "isBindingAction\x0a\x09^ false",
  30. messageSends: [],
  31. referencedClasses: []
  32. }),
  33. smalltalk.HLBinding);
  34. smalltalk.addMethod(
  35. "_isBindingGroup",
  36. smalltalk.method({
  37. selector: "isBindingGroup",
  38. category: 'testing',
  39. fn: function () {
  40. var self = this;
  41. return false;
  42. },
  43. args: [],
  44. source: "isBindingGroup\x0a\x09^ false",
  45. messageSends: [],
  46. referencedClasses: []
  47. }),
  48. smalltalk.HLBinding);
  49. smalltalk.addMethod(
  50. "_key",
  51. smalltalk.method({
  52. selector: "key",
  53. category: 'accessing',
  54. fn: function () {
  55. var self = this;
  56. return self['@key'];
  57. },
  58. args: [],
  59. source: "key\x0a\x09^ key",
  60. messageSends: [],
  61. referencedClasses: []
  62. }),
  63. smalltalk.HLBinding);
  64. smalltalk.addMethod(
  65. "_key_",
  66. smalltalk.method({
  67. selector: "key:",
  68. category: 'accessing',
  69. fn: function (anInteger) {
  70. var self = this;
  71. self['@key'] = anInteger;
  72. return self;
  73. },
  74. args: ["anInteger"],
  75. source: "key: anInteger\x0a\x09key := anInteger",
  76. messageSends: [],
  77. referencedClasses: []
  78. }),
  79. smalltalk.HLBinding);
  80. smalltalk.addMethod(
  81. "_label",
  82. smalltalk.method({
  83. selector: "label",
  84. category: 'accessing',
  85. fn: function () {
  86. var self = this;
  87. return self['@label'];
  88. },
  89. args: [],
  90. source: "label\x0a\x09^ label",
  91. messageSends: [],
  92. referencedClasses: []
  93. }),
  94. smalltalk.HLBinding);
  95. smalltalk.addMethod(
  96. "_label_",
  97. smalltalk.method({
  98. selector: "label:",
  99. category: 'accessing',
  100. fn: function (aString) {
  101. var self = this;
  102. self['@label'] = aString;
  103. return self;
  104. },
  105. args: ["aString"],
  106. source: "label: aString\x0a\x09label := aString",
  107. messageSends: [],
  108. referencedClasses: []
  109. }),
  110. smalltalk.HLBinding);
  111. smalltalk.addMethod(
  112. "_renderOn_html_",
  113. smalltalk.method({
  114. selector: "renderOn:html:",
  115. category: 'rendering',
  116. fn: function (aBindingHelper, html) {
  117. var self = this;
  118. return self;
  119. },
  120. args: ["aBindingHelper", "html"],
  121. source: "renderOn: aBindingHelper html: html",
  122. messageSends: [],
  123. referencedClasses: []
  124. }),
  125. smalltalk.HLBinding);
  126. smalltalk.addMethod(
  127. "_shortcut",
  128. smalltalk.method({
  129. selector: "shortcut",
  130. category: 'accessing',
  131. fn: function () {
  132. var self = this;
  133. var $1;
  134. $1 = smalltalk.send(smalltalk.String || String, "_fromCharCode_", [smalltalk.send(self, "_key", [])]);
  135. return $1;
  136. },
  137. args: [],
  138. source: "shortcut\x0a\x09^ String fromCharCode: self key",
  139. messageSends: ["fromCharCode:", "key"],
  140. referencedClasses: ["String"]
  141. }),
  142. smalltalk.HLBinding);
  143. smalltalk.addMethod(
  144. "_on_labelled_",
  145. smalltalk.method({
  146. selector: "on:labelled:",
  147. category: 'instance creation',
  148. fn: function (anInteger, aString) {
  149. var self = this;
  150. var $2, $3, $1;
  151. $2 = smalltalk.send(self, "_new", []);
  152. smalltalk.send($2, "_key_", [anInteger]);
  153. smalltalk.send($2, "_label_", [aString]);
  154. $3 = smalltalk.send($2, "_yourself", []);
  155. $1 = $3;
  156. return $1;
  157. },
  158. args: ["anInteger", "aString"],
  159. source: "on: anInteger labelled: aString\x0a\x09^ self new\x0a \x09key: anInteger;\x0a label: aString;\x0a yourself",
  160. messageSends: ["key:", "new", "label:", "yourself"],
  161. referencedClasses: []
  162. }),
  163. smalltalk.HLBinding.klass);
  164. smalltalk.addClass('HLBindingAction', smalltalk.HLBinding, ['callback'], 'Helios-KeyBindings');
  165. smalltalk.addMethod(
  166. "_applyOn_",
  167. smalltalk.method({
  168. selector: "applyOn:",
  169. category: 'actions',
  170. fn: function (aKeyBinder) {
  171. var self = this;
  172. smalltalk.send(aKeyBinder, "_applyBindingAction_", [self]);
  173. return self;
  174. },
  175. args: ["aKeyBinder"],
  176. source: "applyOn: aKeyBinder\x0a\x09aKeyBinder applyBindingAction: self",
  177. messageSends: ["applyBindingAction:"],
  178. referencedClasses: []
  179. }),
  180. smalltalk.HLBindingAction);
  181. smalltalk.addMethod(
  182. "_callback",
  183. smalltalk.method({
  184. selector: "callback",
  185. category: 'accessing',
  186. fn: function () {
  187. var self = this;
  188. return self['@callback'];
  189. },
  190. args: [],
  191. source: "callback\x0a\x09^ callback",
  192. messageSends: [],
  193. referencedClasses: []
  194. }),
  195. smalltalk.HLBindingAction);
  196. smalltalk.addMethod(
  197. "_callback_",
  198. smalltalk.method({
  199. selector: "callback:",
  200. category: 'accessing',
  201. fn: function (aBlock) {
  202. var self = this;
  203. self['@callback'] = aBlock;
  204. return self;
  205. },
  206. args: ["aBlock"],
  207. source: "callback: aBlock\x0a\x09callback := aBlock",
  208. messageSends: [],
  209. referencedClasses: []
  210. }),
  211. smalltalk.HLBindingAction);
  212. smalltalk.addMethod(
  213. "_isBindingAction",
  214. smalltalk.method({
  215. selector: "isBindingAction",
  216. category: 'testing',
  217. fn: function () {
  218. var self = this;
  219. return true;
  220. },
  221. args: [],
  222. source: "isBindingAction\x0a\x09^ true",
  223. messageSends: [],
  224. referencedClasses: []
  225. }),
  226. smalltalk.HLBindingAction);
  227. smalltalk.addClass('HLBindingGroup', smalltalk.HLBinding, ['bindings'], 'Helios-KeyBindings');
  228. smalltalk.addMethod(
  229. "_add_",
  230. smalltalk.method({
  231. selector: "add:",
  232. category: 'accessing',
  233. fn: function (aBinding) {
  234. var self = this;
  235. var $1;
  236. $1 = smalltalk.send(smalltalk.send(self, "_bindings", []), "_add_", [aBinding]);
  237. return $1;
  238. },
  239. args: ["aBinding"],
  240. source: "add: aBinding\x0a\x09^ self bindings add: aBinding",
  241. messageSends: ["add:", "bindings"],
  242. referencedClasses: []
  243. }),
  244. smalltalk.HLBindingGroup);
  245. smalltalk.addMethod(
  246. "_addActionKey_labelled_callback_",
  247. smalltalk.method({
  248. selector: "addActionKey:labelled:callback:",
  249. category: 'accessing',
  250. fn: function (anInteger, aString, aBlock) {
  251. var self = this;
  252. var $1, $2;
  253. $1 = smalltalk.send(smalltalk.HLBindingAction || HLBindingAction, "_on_labelled_", [anInteger, aString]);
  254. smalltalk.send($1, "_callback_", [aBlock]);
  255. $2 = smalltalk.send($1, "_yourself", []);
  256. smalltalk.send(self, "_add_", [$2]);
  257. return self;
  258. },
  259. args: ["anInteger", "aString", "aBlock"],
  260. source: "addActionKey: anInteger labelled: aString callback: aBlock\x0a\x09self add: ((HLBindingAction on: anInteger labelled: aString)\x0a \x09callback: aBlock;\x0a yourself)",
  261. messageSends: ["add:", "callback:", "on:labelled:", "yourself"],
  262. referencedClasses: ["HLBindingAction"]
  263. }),
  264. smalltalk.HLBindingGroup);
  265. smalltalk.addMethod(
  266. "_addActionKey_labelled_command_",
  267. smalltalk.method({
  268. selector: "addActionKey:labelled:command:",
  269. category: 'accessing',
  270. fn: function (anInteger, aString, aCommand) {
  271. var self = this;
  272. var $1, $2;
  273. $1 = smalltalk.send(smalltalk.HLBindingAction || HLBindingAction, "_on_labelled_", [anInteger, aString]);
  274. smalltalk.send($1, "_command_", [aCommand]);
  275. $2 = smalltalk.send($1, "_yourself", []);
  276. smalltalk.send(self, "_add_", [$2]);
  277. return self;
  278. },
  279. args: ["anInteger", "aString", "aCommand"],
  280. source: "addActionKey: anInteger labelled: aString command: aCommand\x0a\x09self add: ((HLBindingAction on: anInteger labelled: aString)\x0a \x09command: aCommand;\x0a yourself)",
  281. messageSends: ["add:", "command:", "on:labelled:", "yourself"],
  282. referencedClasses: ["HLBindingAction"]
  283. }),
  284. smalltalk.HLBindingGroup);
  285. smalltalk.addMethod(
  286. "_addGroupKey_labelled_",
  287. smalltalk.method({
  288. selector: "addGroupKey:labelled:",
  289. category: 'accessing',
  290. fn: function (anInteger, aString) {
  291. var self = this;
  292. smalltalk.send(self, "_add_", [smalltalk.send(smalltalk.HLBindingGroup || HLBindingGroup, "_on_labelled_", [anInteger, aString])]);
  293. return self;
  294. },
  295. args: ["anInteger", "aString"],
  296. source: "addGroupKey: anInteger labelled: aString\x0a\x09self add: (HLBindingGroup on: anInteger labelled: aString)",
  297. messageSends: ["add:", "on:labelled:"],
  298. referencedClasses: ["HLBindingGroup"]
  299. }),
  300. smalltalk.HLBindingGroup);
  301. smalltalk.addMethod(
  302. "_applyOn_",
  303. smalltalk.method({
  304. selector: "applyOn:",
  305. category: 'actions',
  306. fn: function (aKeyBinder) {
  307. var self = this;
  308. smalltalk.send(aKeyBinder, "_applyBindingGroup_", [self]);
  309. return self;
  310. },
  311. args: ["aKeyBinder"],
  312. source: "applyOn: aKeyBinder\x0a\x09aKeyBinder applyBindingGroup: self",
  313. messageSends: ["applyBindingGroup:"],
  314. referencedClasses: []
  315. }),
  316. smalltalk.HLBindingGroup);
  317. smalltalk.addMethod(
  318. "_at_",
  319. smalltalk.method({
  320. selector: "at:",
  321. category: 'accessing',
  322. fn: function (aString) {
  323. var self = this;
  324. var $1;
  325. $1 = smalltalk.send(smalltalk.send(self, "_bindings", []), "_detect_ifNone_", [function (each) {return smalltalk.send(smalltalk.send(each, "_label", []), "__eq", [aString]);}, function () {return nil;}]);
  326. return $1;
  327. },
  328. args: ["aString"],
  329. source: "at: aString\x0a\x09^ self bindings \x0a \x09detect: [ :each | each label = aString ]\x0a \x09ifNone: [ nil ]",
  330. messageSends: ["detect:ifNone:", "=", "label", "bindings"],
  331. referencedClasses: []
  332. }),
  333. smalltalk.HLBindingGroup);
  334. smalltalk.addMethod(
  335. "_atKey_",
  336. smalltalk.method({
  337. selector: "atKey:",
  338. category: 'accessing',
  339. fn: function (anInteger) {
  340. var self = this;
  341. var $1;
  342. $1 = smalltalk.send(smalltalk.send(self, "_bindings", []), "_detect_ifNone_", [function (each) {return smalltalk.send(smalltalk.send(each, "_key", []), "__eq", [anInteger]);}, function () {return nil;}]);
  343. return $1;
  344. },
  345. args: ["anInteger"],
  346. source: "atKey: anInteger\x0a\x09^ self bindings \x0a \x09detect: [ :each | each key = anInteger ]\x0a \x09ifNone: [ nil ]",
  347. messageSends: ["detect:ifNone:", "=", "key", "bindings"],
  348. referencedClasses: []
  349. }),
  350. smalltalk.HLBindingGroup);
  351. smalltalk.addMethod(
  352. "_bindings",
  353. smalltalk.method({
  354. selector: "bindings",
  355. category: 'accessing',
  356. fn: function () {
  357. var self = this;
  358. var $1;
  359. if (($receiver = self['@bindings']) == nil || $receiver == undefined) {
  360. self['@bindings'] = smalltalk.send(smalltalk.OrderedCollection || OrderedCollection, "_new", []);
  361. $1 = self['@bindings'];
  362. } else {
  363. $1 = self['@bindings'];
  364. }
  365. return $1;
  366. },
  367. args: [],
  368. source: "bindings\x0a\x09^ bindings ifNil: [ bindings := OrderedCollection new ]",
  369. messageSends: ["ifNil:", "new"],
  370. referencedClasses: ["OrderedCollection"]
  371. }),
  372. smalltalk.HLBindingGroup);
  373. smalltalk.addMethod(
  374. "_isBindingGroup",
  375. smalltalk.method({
  376. selector: "isBindingGroup",
  377. category: 'testing',
  378. fn: function () {
  379. var self = this;
  380. return true;
  381. },
  382. args: [],
  383. source: "isBindingGroup\x0a\x09^ true",
  384. messageSends: [],
  385. referencedClasses: []
  386. }),
  387. smalltalk.HLBindingGroup);
  388. smalltalk.addMethod(
  389. "_renderOn_html_",
  390. smalltalk.method({
  391. selector: "renderOn:html:",
  392. category: 'rendering',
  393. fn: function (aBindingHelper, html) {
  394. var self = this;
  395. smalltalk.send(aBindingHelper, "_renderBindingGroup_on_", [self, html]);
  396. return self;
  397. },
  398. args: ["aBindingHelper", "html"],
  399. source: "renderOn: aBindingHelper html: html\x0a\x09aBindingHelper renderBindingGroup: self on: html",
  400. messageSends: ["renderBindingGroup:on:"],
  401. referencedClasses: []
  402. }),
  403. smalltalk.HLBindingGroup);
  404. smalltalk.addClass('HLKeyBinder', smalltalk.Object, ['modifierKey', 'active', 'helper', 'bindings', 'selectedBinding'], 'Helios-KeyBindings');
  405. smalltalk.addMethod(
  406. "_activate",
  407. smalltalk.method({
  408. selector: "activate",
  409. category: 'actions',
  410. fn: function () {
  411. var self = this;
  412. self['@active'] = true;
  413. smalltalk.send(smalltalk.send(self, "_helper", []), "_show", []);
  414. return self;
  415. },
  416. args: [],
  417. source: "activate\x0a\x09active := true.\x0a\x09self helper show",
  418. messageSends: ["show", "helper"],
  419. referencedClasses: []
  420. }),
  421. smalltalk.HLKeyBinder);
  422. smalltalk.addMethod(
  423. "_activationKey",
  424. smalltalk.method({
  425. selector: "activationKey",
  426. category: 'accessing',
  427. fn: function () {
  428. var self = this;
  429. return 32;
  430. },
  431. args: [],
  432. source: "activationKey\x0a\x09\x22SPACE\x22\x0a\x09^ 32",
  433. messageSends: [],
  434. referencedClasses: []
  435. }),
  436. smalltalk.HLKeyBinder);
  437. smalltalk.addMethod(
  438. "_applyBinding_",
  439. smalltalk.method({
  440. selector: "applyBinding:",
  441. category: 'actions',
  442. fn: function (aBinding) {
  443. var self = this;
  444. smalltalk.send(aBinding, "_applyOn_", [self]);
  445. return self;
  446. },
  447. args: ["aBinding"],
  448. source: "applyBinding: aBinding\x0a aBinding applyOn: self",
  449. messageSends: ["applyOn:"],
  450. referencedClasses: []
  451. }),
  452. smalltalk.HLKeyBinder);
  453. smalltalk.addMethod(
  454. "_applyBindingAction_",
  455. smalltalk.method({
  456. selector: "applyBindingAction:",
  457. category: 'actions',
  458. fn: function (aBinding) {
  459. var self = this;
  460. smalltalk.send(smalltalk.send(aBinding, "_callback", []), "_value", []);
  461. smalltalk.send(self, "_deactivate", []);
  462. return self;
  463. },
  464. args: ["aBinding"],
  465. source: "applyBindingAction: aBinding\x0a aBinding callback value.\x0a\x09self deactivate",
  466. messageSends: ["value", "callback", "deactivate"],
  467. referencedClasses: []
  468. }),
  469. smalltalk.HLKeyBinder);
  470. smalltalk.addMethod(
  471. "_applyBindingGroup_",
  472. smalltalk.method({
  473. selector: "applyBindingGroup:",
  474. category: 'actions',
  475. fn: function (aBinding) {
  476. var self = this;
  477. self['@selectedBinding'] = aBinding;
  478. smalltalk.send(smalltalk.send(self, "_helper", []), "_refresh", []);
  479. return self;
  480. },
  481. args: ["aBinding"],
  482. source: "applyBindingGroup: aBinding\x0a selectedBinding := aBinding.\x0a self helper refresh",
  483. messageSends: ["refresh", "helper"],
  484. referencedClasses: []
  485. }),
  486. smalltalk.HLKeyBinder);
  487. smalltalk.addMethod(
  488. "_bindings",
  489. smalltalk.method({
  490. selector: "bindings",
  491. category: 'accessing',
  492. fn: function () {
  493. var self = this;
  494. var $1;
  495. if (($receiver = self['@bindings']) == nil || $receiver == undefined) {
  496. self['@bindings'] = smalltalk.send(smalltalk.HLBindingGroup || HLBindingGroup, "_new", []);
  497. $1 = self['@bindings'];
  498. } else {
  499. $1 = self['@bindings'];
  500. }
  501. return $1;
  502. },
  503. args: [],
  504. source: "bindings\x0a\x09^ bindings ifNil: [ bindings := HLBindingGroup new ]",
  505. messageSends: ["ifNil:", "new"],
  506. referencedClasses: ["HLBindingGroup"]
  507. }),
  508. smalltalk.HLKeyBinder);
  509. smalltalk.addMethod(
  510. "_deactivate",
  511. smalltalk.method({
  512. selector: "deactivate",
  513. category: 'actions',
  514. fn: function () {
  515. var self = this;
  516. self['@active'] = false;
  517. self['@selectedBinding'] = nil;
  518. smalltalk.send(smalltalk.send(self, "_helper", []), "_hide", []);
  519. return self;
  520. },
  521. args: [],
  522. source: "deactivate\x0a\x09active := false.\x0a selectedBinding := nil.\x0a\x09self helper hide",
  523. messageSends: ["hide", "helper"],
  524. referencedClasses: []
  525. }),
  526. smalltalk.HLKeyBinder);
  527. smalltalk.addMethod(
  528. "_escapeKey",
  529. smalltalk.method({
  530. selector: "escapeKey",
  531. category: 'accessing',
  532. fn: function () {
  533. var self = this;
  534. return 27;
  535. },
  536. args: [],
  537. source: "escapeKey\x0a\x09\x22ESC\x22\x0a\x09^ 27",
  538. messageSends: [],
  539. referencedClasses: []
  540. }),
  541. smalltalk.HLKeyBinder);
  542. smalltalk.addMethod(
  543. "_flushBindings",
  544. smalltalk.method({
  545. selector: "flushBindings",
  546. category: 'actions',
  547. fn: function () {
  548. var self = this;
  549. self['@bindings'] = nil;
  550. self['@helper'] = nil;
  551. return self;
  552. },
  553. args: [],
  554. source: "flushBindings\x0a\x09bindings := nil.\x0a helper := nil",
  555. messageSends: [],
  556. referencedClasses: []
  557. }),
  558. smalltalk.HLKeyBinder);
  559. smalltalk.addMethod(
  560. "_handleActiveKeyDown_",
  561. smalltalk.method({
  562. selector: "handleActiveKeyDown:",
  563. category: 'events',
  564. fn: function (event) {
  565. var self = this;
  566. var $1, $2;
  567. $1 = smalltalk.send(smalltalk.send(smalltalk.send(event, "_which", []), "__eq", [smalltalk.send(self, "_escapeKey", [])]), "_or_", [function () {return smalltalk.send(smalltalk.send(smalltalk.send(event, "_which", []), "__eq", [71]), "_and_", [function () {return smalltalk.send(event, "_ctrlKey", []);}]);}]);
  568. if (smalltalk.assert($1)) {
  569. smalltalk.send(self, "_deactivate", []);
  570. smalltalk.send(event, "_preventDefault", []);
  571. return false;
  572. }
  573. $2 = smalltalk.send(self, "_handleBindingFor_", [event]);
  574. return $2;
  575. },
  576. args: ["event"],
  577. source: "handleActiveKeyDown: event\x0a\x0a\x09\x22ESC or ctrl+g deactivate the keyBinder\x22\x0a\x09(event which = self escapeKey or: [\x0a\x09\x09event which = 71 and: [ event ctrlKey ] ])\x0a \x09ifTrue: [ \x0a \x09self deactivate.\x0a\x09\x09\x09\x09event preventDefault.\x0a\x09\x09\x09\x09^ false ].\x0a \x0a \x22Handle the keybinding\x22\x0a ^ self handleBindingFor: event",
  578. messageSends: ["ifTrue:", "deactivate", "preventDefault", "or:", "and:", "ctrlKey", "=", "which", "escapeKey", "handleBindingFor:"],
  579. referencedClasses: []
  580. }),
  581. smalltalk.HLKeyBinder);
  582. smalltalk.addMethod(
  583. "_handleBindingFor_",
  584. smalltalk.method({
  585. selector: "handleBindingFor:",
  586. category: 'events',
  587. fn: function (anEvent) {
  588. var self = this;
  589. var binding;
  590. binding = smalltalk.send(smalltalk.send(self, "_selectedBinding", []), "_atKey_", [smalltalk.send(anEvent, "_which", [])]);
  591. if (($receiver = binding) == nil || $receiver == undefined) {
  592. } else {
  593. smalltalk.send(self, "_applyBinding_", [binding]);
  594. smalltalk.send(anEvent, "_preventDefault", []);
  595. return false;
  596. }
  597. return self;
  598. },
  599. args: ["anEvent"],
  600. source: "handleBindingFor: anEvent\x0a\x09| binding |\x0a binding := self selectedBinding atKey: anEvent which.\x0a \x0a binding ifNotNil: [ \x0a \x09self applyBinding: binding.\x0a\x09\x09anEvent preventDefault.\x0a\x09\x09^ false ]",
  601. messageSends: ["atKey:", "which", "selectedBinding", "ifNotNil:", "applyBinding:", "preventDefault"],
  602. referencedClasses: []
  603. }),
  604. smalltalk.HLKeyBinder);
  605. smalltalk.addMethod(
  606. "_handleInactiveKeyDown_",
  607. smalltalk.method({
  608. selector: "handleInactiveKeyDown:",
  609. category: 'events',
  610. fn: function (event) {
  611. var self = this;
  612. var $1, $2;
  613. $1 = smalltalk.send(smalltalk.send(event, "_which", []), "__eq", [smalltalk.send(self, "_activationKey", [])]);
  614. if (smalltalk.assert($1)) {
  615. $2 = smalltalk.send(event, "_ctrlKey", []);
  616. if (smalltalk.assert($2)) {
  617. smalltalk.send(self, "_activate", []);
  618. smalltalk.send(event, "_preventDefault", []);
  619. return false;
  620. }
  621. }
  622. return self;
  623. },
  624. args: ["event"],
  625. source: "handleInactiveKeyDown: event\x0a event which = self activationKey ifTrue: [\x0a \x09\x09event ctrlKey ifTrue: [\x0a\x09\x09\x09\x09\x09self activate. \x0a \x09\x09 event preventDefault. \x0a \x09^ false ] ]",
  626. messageSends: ["ifTrue:", "activate", "preventDefault", "ctrlKey", "=", "activationKey", "which"],
  627. referencedClasses: []
  628. }),
  629. smalltalk.HLKeyBinder);
  630. smalltalk.addMethod(
  631. "_handleKeyDown_",
  632. smalltalk.method({
  633. selector: "handleKeyDown:",
  634. category: 'events',
  635. fn: function (event) {
  636. var self = this;
  637. var $2, $1;
  638. $2 = smalltalk.send(self, "_isActive", []);
  639. if (smalltalk.assert($2)) {
  640. $1 = smalltalk.send(self, "_handleActiveKeyDown_", [event]);
  641. } else {
  642. $1 = smalltalk.send(self, "_handleInactiveKeyDown_", [event]);
  643. }
  644. return $1;
  645. },
  646. args: ["event"],
  647. source: "handleKeyDown: event\x0a\x09^ self isActive\x0a \x09ifTrue: [ self handleActiveKeyDown: event ]\x0a \x09ifFalse: [ self handleInactiveKeyDown: event ]",
  648. messageSends: ["ifTrue:ifFalse:", "handleActiveKeyDown:", "handleInactiveKeyDown:", "isActive"],
  649. referencedClasses: []
  650. }),
  651. smalltalk.HLKeyBinder);
  652. smalltalk.addMethod(
  653. "_helper",
  654. smalltalk.method({
  655. selector: "helper",
  656. category: 'accessing',
  657. fn: function () {
  658. var self = this;
  659. var $1;
  660. if (($receiver = self['@helper']) == nil || $receiver == undefined) {
  661. self['@helper'] = smalltalk.send(smalltalk.HLKeyBinderHelper || HLKeyBinderHelper, "_on_", [self]);
  662. $1 = self['@helper'];
  663. } else {
  664. $1 = self['@helper'];
  665. }
  666. return $1;
  667. },
  668. args: [],
  669. source: "helper\x0a\x09^ helper ifNil: [ helper := HLKeyBinderHelper on: self ]",
  670. messageSends: ["ifNil:", "on:"],
  671. referencedClasses: ["HLKeyBinderHelper"]
  672. }),
  673. smalltalk.HLKeyBinder);
  674. smalltalk.addMethod(
  675. "_initialize",
  676. smalltalk.method({
  677. selector: "initialize",
  678. category: 'initialization',
  679. fn: function () {
  680. var self = this;
  681. smalltalk.send(self, "_initialize", [], smalltalk.Object);
  682. self['@active'] = false;
  683. return self;
  684. },
  685. args: [],
  686. source: "initialize\x0a\x09super initialize.\x0a active := false",
  687. messageSends: ["initialize"],
  688. referencedClasses: []
  689. }),
  690. smalltalk.HLKeyBinder);
  691. smalltalk.addMethod(
  692. "_isActive",
  693. smalltalk.method({
  694. selector: "isActive",
  695. category: 'testing',
  696. fn: function () {
  697. var self = this;
  698. var $1;
  699. if (($receiver = self['@active']) == nil || $receiver == undefined) {
  700. $1 = false;
  701. } else {
  702. $1 = self['@active'];
  703. }
  704. return $1;
  705. },
  706. args: [],
  707. source: "isActive\x0a\x09^ active ifNil: [ false ]",
  708. messageSends: ["ifNil:"],
  709. referencedClasses: []
  710. }),
  711. smalltalk.HLKeyBinder);
  712. smalltalk.addMethod(
  713. "_selectedBinding",
  714. smalltalk.method({
  715. selector: "selectedBinding",
  716. category: 'accessing',
  717. fn: function () {
  718. var self = this;
  719. var $1;
  720. if (($receiver = self['@selectedBinding']) == nil ||
  721. $receiver == undefined) {
  722. $1 = smalltalk.send(self, "_bindings", []);
  723. } else {
  724. $1 = self['@selectedBinding'];
  725. }
  726. return $1;
  727. },
  728. args: [],
  729. source: "selectedBinding\x0a\x09^ selectedBinding ifNil: [ self bindings ]",
  730. messageSends: ["ifNil:", "bindings"],
  731. referencedClasses: []
  732. }),
  733. smalltalk.HLKeyBinder);
  734. smalltalk.addMethod(
  735. "_setupEvents",
  736. smalltalk.method({
  737. selector: "setupEvents",
  738. category: 'events',
  739. fn: function () {
  740. var self = this;
  741. smalltalk.send(smalltalk.send(window, "_jQuery_", ["body"]), "_keydown_", [function (event) {return smalltalk.send(self, "_handleKeyDown_", [event]);}]);
  742. return self;
  743. },
  744. args: [],
  745. source: "setupEvents\x0a\x09(window jQuery: 'body') keydown: [ :event | self handleKeyDown: event ]",
  746. messageSends: ["keydown:", "handleKeyDown:", "jQuery:"],
  747. referencedClasses: []
  748. }),
  749. smalltalk.HLKeyBinder);
  750. smalltalk.addMethod(
  751. "_systemIsMac",
  752. smalltalk.method({
  753. selector: "systemIsMac",
  754. category: 'testing',
  755. fn: function () {
  756. var self = this;
  757. var $1;
  758. $1 = smalltalk.send(smalltalk.send(navigator, "_platform", []), "_match_", ["Mac"]);
  759. return $1;
  760. },
  761. args: [],
  762. source: "systemIsMac\x0a\x09^ navigator platform match: 'Mac'",
  763. messageSends: ["match:", "platform"],
  764. referencedClasses: []
  765. }),
  766. smalltalk.HLKeyBinder);
  767. smalltalk.addClass('HLKeyBinderHelper', smalltalk.HLWidget, ['keyBinder'], 'Helios-KeyBindings');
  768. smalltalk.addMethod(
  769. "_hide",
  770. smalltalk.method({
  771. selector: "hide",
  772. category: 'actions',
  773. fn: function () {
  774. var self = this;
  775. smalltalk.send(smalltalk.send(self['@rootDiv'], "_asJQuery", []), "_remove", []);
  776. return self;
  777. },
  778. args: [],
  779. source: "hide\x0a\x09rootDiv asJQuery remove",
  780. messageSends: ["remove", "asJQuery"],
  781. referencedClasses: []
  782. }),
  783. smalltalk.HLKeyBinderHelper);
  784. smalltalk.addMethod(
  785. "_keyBinder",
  786. smalltalk.method({
  787. selector: "keyBinder",
  788. category: 'accessing',
  789. fn: function () {
  790. var self = this;
  791. return self['@keyBinder'];
  792. },
  793. args: [],
  794. source: "keyBinder\x0a\x09^ keyBinder",
  795. messageSends: [],
  796. referencedClasses: []
  797. }),
  798. smalltalk.HLKeyBinderHelper);
  799. smalltalk.addMethod(
  800. "_keyBinder_",
  801. smalltalk.method({
  802. selector: "keyBinder:",
  803. category: 'accessing',
  804. fn: function (aKeyBinder) {
  805. var self = this;
  806. self['@keyBinder'] = aKeyBinder;
  807. return self;
  808. },
  809. args: ["aKeyBinder"],
  810. source: "keyBinder: aKeyBinder\x0a\x09keyBinder := aKeyBinder",
  811. messageSends: [],
  812. referencedClasses: []
  813. }),
  814. smalltalk.HLKeyBinderHelper);
  815. smalltalk.addMethod(
  816. "_registerBindings",
  817. smalltalk.method({
  818. selector: "registerBindings",
  819. category: 'keyBindings',
  820. fn: function () {
  821. var self = this;
  822. return self;
  823. },
  824. args: [],
  825. source: "registerBindings\x0a\x09\x22Do nothing\x22",
  826. messageSends: [],
  827. referencedClasses: []
  828. }),
  829. smalltalk.HLKeyBinderHelper);
  830. smalltalk.addMethod(
  831. "_renderBindingGroup_on_",
  832. smalltalk.method({
  833. selector: "renderBindingGroup:on:",
  834. category: 'rendering',
  835. fn: function (aBindingGroup, html) {
  836. var self = this;
  837. var $1, $3, $4, $5, $6, $2;
  838. smalltalk.send(smalltalk.send(smalltalk.send(aBindingGroup, "_bindings", []), "_sorted_", [function (a, b) {return smalltalk.send(smalltalk.send(a, "_key", []), "__lt", [smalltalk.send(b, "_key", [])]);}]), "_do_", [function (each) {$1 = smalltalk.send(html, "_span", []);smalltalk.send($1, "_class_", ["command"]);$2 = smalltalk.send($1, "_with_", [function () {$3 = smalltalk.send(html, "_span", []);smalltalk.send($3, "_class_", ["label"]);$4 = smalltalk.send($3, "_with_", [smalltalk.send(smalltalk.send(each, "_shortcut", []), "_asLowercase", [])]);$4;$5 = smalltalk.send(html, "_a", []);smalltalk.send($5, "_class_", ["action"]);smalltalk.send($5, "_with_", [smalltalk.send(each, "_label", [])]);$6 = smalltalk.send($5, "_onClick_", [function () {return smalltalk.send(smalltalk.send(self, "_keyBinder", []), "_applyBinding_", [each]);}]);return $6;}]);return $2;}]);
  839. return self;
  840. },
  841. args: ["aBindingGroup", "html"],
  842. source: "renderBindingGroup: aBindingGroup on: html\x0a\x09(aBindingGroup bindings \x0a \x09sorted: [ :a :b | a key < b key ])\x0a do: [ :each |\x0a\x09\x09\x09html span class: 'command'; with: [\x0a\x09\x09\x09\x09html span class: 'label'; with: each shortcut asLowercase.\x0a \x09\x09\x09\x09html a \x0a \x09class: 'action'; \x0a with: each label;\x0a \x09\x09\x09\x09\x09onClick: [ self keyBinder applyBinding: each ] ] ]",
  843. messageSends: ["do:", "class:", "span", "with:", "asLowercase", "shortcut", "a", "label", "onClick:", "applyBinding:", "keyBinder", "sorted:", "<", "key", "bindings"],
  844. referencedClasses: []
  845. }),
  846. smalltalk.HLKeyBinderHelper);
  847. smalltalk.addMethod(
  848. "_renderBindingOn_",
  849. smalltalk.method({
  850. selector: "renderBindingOn:",
  851. category: 'rendering',
  852. fn: function (html) {
  853. var self = this;
  854. smalltalk.send(smalltalk.send(self, "_selectedBinding", []), "_renderOn_html_", [self, html]);
  855. return self;
  856. },
  857. args: ["html"],
  858. source: "renderBindingOn: html\x0a\x09self selectedBinding renderOn: self html: html",
  859. messageSends: ["renderOn:html:", "selectedBinding"],
  860. referencedClasses: []
  861. }),
  862. smalltalk.HLKeyBinderHelper);
  863. smalltalk.addMethod(
  864. "_renderContentOn_",
  865. smalltalk.method({
  866. selector: "renderContentOn:",
  867. category: 'rendering',
  868. fn: function (html) {
  869. var self = this;
  870. var $1, $3, $2;
  871. $1 = smalltalk.send(html, "_div", []);
  872. smalltalk.send($1, "_class_", ["key_helper"]);
  873. $2 = smalltalk.send($1, "_with_", [function () {smalltalk.send(self, "_renderSelectionOn_", [html]);$3 = smalltalk.send(self, "_renderBindingOn_", [html]);return $3;}]);
  874. return self;
  875. },
  876. args: ["html"],
  877. source: "renderContentOn: html\x0a\x09html div class: 'key_helper'; with: [\x0a \x09self \x0a \x09renderSelectionOn:html;\x0a \x09renderBindingOn: html ]",
  878. messageSends: ["class:", "div", "with:", "renderSelectionOn:", "renderBindingOn:"],
  879. referencedClasses: []
  880. }),
  881. smalltalk.HLKeyBinderHelper);
  882. smalltalk.addMethod(
  883. "_renderSelectionOn_",
  884. smalltalk.method({
  885. selector: "renderSelectionOn:",
  886. category: 'rendering',
  887. fn: function (html) {
  888. var self = this;
  889. var $1, $4, $3, $2;
  890. $1 = smalltalk.send(html, "_span", []);
  891. smalltalk.send($1, "_class_", ["selected"]);
  892. $4 = smalltalk.send(smalltalk.send(self, "_selectedBinding", []), "_label", []);
  893. if (($receiver = $4) == nil || $receiver == undefined) {
  894. $3 = "Action";
  895. } else {
  896. $3 = $4;
  897. }
  898. $2 = smalltalk.send($1, "_with_", [$3]);
  899. return self;
  900. },
  901. args: ["html"],
  902. source: "renderSelectionOn: html\x0a\x09\x09html span \x0a \x09class: 'selected'; \x0a with: (self selectedBinding label ifNil: [ 'Action' ])",
  903. messageSends: ["class:", "span", "with:", "ifNil:", "label", "selectedBinding"],
  904. referencedClasses: []
  905. }),
  906. smalltalk.HLKeyBinderHelper);
  907. smalltalk.addMethod(
  908. "_selectedBinding",
  909. smalltalk.method({
  910. selector: "selectedBinding",
  911. category: 'accessing',
  912. fn: function () {
  913. var self = this;
  914. var $1;
  915. $1 = smalltalk.send(smalltalk.send(self, "_keyBinder", []), "_selectedBinding", []);
  916. return $1;
  917. },
  918. args: [],
  919. source: "selectedBinding\x0a\x09^ self keyBinder selectedBinding",
  920. messageSends: ["selectedBinding", "keyBinder"],
  921. referencedClasses: []
  922. }),
  923. smalltalk.HLKeyBinderHelper);
  924. smalltalk.addMethod(
  925. "_show",
  926. smalltalk.method({
  927. selector: "show",
  928. category: 'actions',
  929. fn: function () {
  930. var self = this;
  931. smalltalk.send(self, "_appendToJQuery_", [smalltalk.send("body", "_asJQuery", [])]);
  932. return self;
  933. },
  934. args: [],
  935. source: "show\x0a\x09self appendToJQuery: 'body' asJQuery",
  936. messageSends: ["appendToJQuery:", "asJQuery"],
  937. referencedClasses: []
  938. }),
  939. smalltalk.HLKeyBinderHelper);
  940. smalltalk.addMethod(
  941. "_on_",
  942. smalltalk.method({
  943. selector: "on:",
  944. category: 'instance creation',
  945. fn: function (aKeyBinder) {
  946. var self = this;
  947. var $2, $3, $1;
  948. $2 = smalltalk.send(self, "_new", []);
  949. smalltalk.send($2, "_keyBinder_", [aKeyBinder]);
  950. $3 = smalltalk.send($2, "_yourself", []);
  951. $1 = $3;
  952. return $1;
  953. },
  954. args: ["aKeyBinder"],
  955. source: "on: aKeyBinder\x0a\x09^ self new\x0a \x09keyBinder: aKeyBinder;\x0a yourself",
  956. messageSends: ["keyBinder:", "new", "yourself"],
  957. referencedClasses: []
  958. }),
  959. smalltalk.HLKeyBinderHelper.klass);