1
0

Helios-Core.st 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849
  1. Smalltalk current createPackage: 'Helios-Core'!
  2. Object subclass: #HLModel
  3. instanceVariableNames: 'announcer environment'
  4. package: 'Helios-Core'!
  5. !HLModel commentStamp!
  6. I am the abstract superclass of all models of Helios.
  7. I am the "Model" part of the MVC pattern implementation in Helios.
  8. I provide access to an `Environment` object and both a local (model-specific) and global (system-specific) announcer.
  9. The `#withChangesDo:` method is handy for performing model changes ensuring that all widgets are aware of the change and can prevent it from happening.
  10. Modifications of the system should be done via commands (see `HLCommand` and subclasses).!
  11. !HLModel methodsFor: 'accessing'!
  12. announcer
  13. ^ announcer ifNil: [ announcer := Announcer new ]
  14. !
  15. environment
  16. ^ environment ifNil: [ self manager environment ]
  17. !
  18. environment: anEnvironment
  19. environment := anEnvironment
  20. !
  21. manager
  22. ^ HLManager current
  23. !
  24. systemAnnouncer
  25. ^ self environment systemAnnouncer
  26. ! !
  27. !HLModel methodsFor: 'error handling'!
  28. withChangesDo: aBlock
  29. [
  30. self announcer announce: (HLAboutToChange new
  31. actionBlock: aBlock).
  32. aBlock value.
  33. ]
  34. on: HLChangeForbidden
  35. do: [ :ex | ]
  36. ! !
  37. !HLModel methodsFor: 'testing'!
  38. isBrowserModel
  39. ^ false
  40. !
  41. isReferencesModel
  42. ^ false
  43. !
  44. isToolModel
  45. ^ false
  46. ! !
  47. HLModel subclass: #HLToolModel
  48. instanceVariableNames: 'selectedClass selectedPackage selectedProtocol selectedSelector'
  49. package: 'Helios-Core'!
  50. !HLToolModel commentStamp!
  51. I am a model specific to package and class manipulation. All browsers should either use me or a subclass as their model.
  52. I provide methods for package, class, protocol and method manipulation and access, forwarding to my environment.
  53. I also handle compilation of classes and methods as well as compilation and parsing errors.!
  54. !HLToolModel methodsFor: 'accessing'!
  55. allSelectors
  56. ^ self environment allSelectors
  57. !
  58. availableClassNames
  59. ^ self environment availableClassNames
  60. !
  61. availablePackageNames
  62. ^ self environment availablePackageNames
  63. !
  64. availablePackages
  65. ^ self environment availablePackageNames
  66. !
  67. availableProtocols
  68. ^ self environment availableProtocolsFor: self selectedClass
  69. !
  70. packages
  71. ^ self environment packages
  72. !
  73. selectedClass
  74. ^ selectedClass
  75. !
  76. selectedClass: aClass
  77. (self selectedClass = aClass and: [ aClass isNil ])
  78. ifTrue: [ ^ self ].
  79. self withChangesDo: [
  80. selectedClass = aClass ifTrue: [
  81. self selectedProtocol: nil ].
  82. aClass
  83. ifNil: [ selectedClass := nil ]
  84. ifNotNil: [
  85. self selectedPackage: aClass theNonMetaClass package.
  86. self showInstance
  87. ifTrue: [ selectedClass := aClass theNonMetaClass ]
  88. ifFalse: [ selectedClass := aClass theMetaClass ] ].
  89. self selectedProtocol: nil.
  90. self announcer announce: (HLClassSelected on: self selectedClass) ]
  91. !
  92. selectedMethod
  93. ^ self selectedClass ifNotNil: [
  94. self selectedClass methodDictionary
  95. at: selectedSelector
  96. ifAbsent: [ nil ] ]
  97. !
  98. selectedMethod: aCompiledMethod
  99. selectedSelector = aCompiledMethod ifTrue: [ ^ self ].
  100. self withChangesDo: [
  101. aCompiledMethod
  102. ifNil: [ selectedSelector := nil ]
  103. ifNotNil: [
  104. selectedClass := aCompiledMethod methodClass.
  105. selectedPackage := selectedClass theNonMetaClass package.
  106. selectedSelector := aCompiledMethod selector ].
  107. self announcer announce: (HLMethodSelected on: aCompiledMethod) ]
  108. !
  109. selectedPackage
  110. ^ selectedPackage
  111. !
  112. selectedPackage: aPackage
  113. selectedPackage = aPackage ifTrue: [ ^ self ].
  114. self withChangesDo: [
  115. selectedPackage := aPackage.
  116. self selectedClass: nil.
  117. self announcer announce: (HLPackageSelected on: aPackage) ]
  118. !
  119. selectedProtocol
  120. ^ selectedProtocol
  121. !
  122. selectedProtocol: aString
  123. selectedProtocol = aString ifTrue: [ ^ self ].
  124. self withChangesDo: [
  125. selectedProtocol := aString.
  126. self selectedMethod: nil.
  127. self announcer announce: (HLProtocolSelected on: aString) ]
  128. ! !
  129. !HLToolModel methodsFor: 'actions'!
  130. addInstVarNamed: aString
  131. self environment addInstVarNamed: aString to: self selectedClass.
  132. self announcer announce: (HLInstVarAdded new
  133. theClass: self selectedClass;
  134. variableName: aString;
  135. yourself)
  136. !
  137. save: aString
  138. self announcer announce: HLSourceCodeSaved new.
  139. (self shouldCompileClassDefinition: aString)
  140. ifTrue: [ self compileClassDefinition: aString ]
  141. ifFalse: [ self compileMethod: aString ]
  142. !
  143. saveSourceCode
  144. self announcer announce: HLSaveSourceCode new
  145. ! !
  146. !HLToolModel methodsFor: 'commands actions'!
  147. commitPackage
  148. "self
  149. withHelperLabelled: 'Committing package ', self selectedPackage name, '...'
  150. do: [ "self environment commitPackage: self selectedPackage" ]"
  151. !
  152. copyClassTo: aClassName
  153. self withChangesDo: [
  154. self environment
  155. copyClass: self selectedClass theNonMetaClass
  156. to: aClassName ]
  157. !
  158. moveClassToPackage: aPackageName
  159. self withChangesDo: [
  160. self environment
  161. moveClass: self selectedClass theNonMetaClass
  162. toPackage: aPackageName ]
  163. !
  164. moveMethodToClass: aClassName
  165. self withChangesDo: [
  166. self environment
  167. moveMethod: self selectedMethod
  168. toClass: aClassName ]
  169. !
  170. moveMethodToProtocol: aProtocol
  171. self withChangesDo: [
  172. self environment
  173. moveMethod: self selectedMethod
  174. toProtocol: aProtocol ]
  175. !
  176. openClassNamed: aString
  177. | class |
  178. self withChangesDo: [
  179. class := self environment classNamed: aString.
  180. self selectedPackage: class package.
  181. self selectedClass: class ]
  182. !
  183. removeClass
  184. self withChangesDo: [
  185. self manager
  186. confirm: 'Do you REALLY want to remove class ', self selectedClass name
  187. ifTrue: [ self environment removeClass: self selectedClass ] ]
  188. !
  189. removeMethod
  190. self withChangesDo: [
  191. self manager
  192. confirm: 'Do you REALLY want to remove method ', self selectedMethod methodClass name,' >> #', self selectedMethod selector
  193. ifTrue: [ self environment removeMethod: self selectedMethod ] ]
  194. !
  195. removeProtocol
  196. self withChangesDo: [
  197. self manager
  198. confirm: 'Do you REALLY want to remove protocol ', self selectedProtocol
  199. ifTrue: [ self environment
  200. removeProtocol: self selectedProtocol
  201. from: self selectedClass ] ]
  202. !
  203. renameClassTo: aClassName
  204. self withChangesDo: [
  205. self environment
  206. renameClass: self selectedClass theNonMetaClass
  207. to: aClassName ]
  208. !
  209. renameProtocolTo: aString
  210. self withChangesDo: [
  211. self environment
  212. renameProtocol: self selectedProtocol
  213. to: aString
  214. in: self selectedClass ]
  215. ! !
  216. !HLToolModel methodsFor: 'compiling'!
  217. compileClassComment: aString
  218. self environment
  219. compileClassComment: aString
  220. for: self selectedClass
  221. !
  222. compileClassDefinition: aString
  223. self environment compileClassDefinition: aString
  224. !
  225. compileMethod: aString
  226. | method |
  227. self withCompileErrorHandling: [
  228. method := self environment
  229. compileMethod: aString
  230. for: self selectedClass
  231. protocol: self compilationProtocol.
  232. self selectedMethod: method ]
  233. ! !
  234. !HLToolModel methodsFor: 'defaults'!
  235. allProtocol
  236. ^ '-- all --'
  237. !
  238. unclassifiedProtocol
  239. ^ 'as yet unclassified'
  240. ! !
  241. !HLToolModel methodsFor: 'error handling'!
  242. handleCompileError: anError
  243. self announcer announce: (HLCompileErrorRaised new
  244. error: anError;
  245. yourself)
  246. !
  247. handleParseError: anError
  248. | split line column messageToInsert |
  249. split := anError messageText tokenize: ' : '.
  250. messageToInsert := split second.
  251. "21 = 'Parse error on line ' size + 1"
  252. split := split first copyFrom: 21 to: split first size.
  253. split := split tokenize: ' column '.
  254. line := split first.
  255. column := split second.
  256. self announcer announce: (HLParseErrorRaised new
  257. line: line asNumber;
  258. column: column asNumber;
  259. message: messageToInsert;
  260. error: anError;
  261. yourself)
  262. !
  263. handleUnkownVariableError: anError
  264. self announcer announce: (HLUnknownVariableErrorRaised new
  265. error: anError;
  266. yourself)
  267. !
  268. withCompileErrorHandling: aBlock
  269. self environment
  270. evaluate: [
  271. self environment
  272. evaluate: [
  273. self environment
  274. evaluate: aBlock
  275. on: ParseError
  276. do: [:ex | self handleParseError: ex ] ]
  277. on: UnknownVariableError
  278. do: [ :ex | self handleUnkownVariableError: ex ] ]
  279. on: CompilerError
  280. do: [ :ex | self handleCompileError: ex ]
  281. ! !
  282. !HLToolModel methodsFor: 'private'!
  283. compilationProtocol
  284. | currentProtocol |
  285. currentProtocol := self selectedProtocol.
  286. currentProtocol ifNil: [ currentProtocol := self unclassifiedProtocol ].
  287. self selectedMethod ifNotNil: [ currentProtocol := self selectedMethod protocol ].
  288. ^ currentProtocol = self allProtocol
  289. ifTrue: [ self unclassifiedProtocol ]
  290. ifFalse: [ currentProtocol ]
  291. !
  292. withHelperLabelled: aString do: aBlock
  293. "TODO: doesn't belong here"
  294. '#helper' asJQuery remove.
  295. [ :html |
  296. html div
  297. id: 'helper';
  298. with: aString ] appendToJQuery: 'body' asJQuery.
  299. [
  300. aBlock value.
  301. '#helper' asJQuery remove
  302. ]
  303. valueWithTimeout: 10
  304. ! !
  305. !HLToolModel methodsFor: 'testing'!
  306. isToolModel
  307. ^ true
  308. !
  309. shouldCompileClassDefinition: aString
  310. ^ self selectedClass isNil or: [
  311. aString match: '^[A-Z]' ]
  312. ! !
  313. !HLToolModel class methodsFor: 'actions'!
  314. on: anEnvironment
  315. ^ self new
  316. environment: anEnvironment;
  317. yourself
  318. ! !
  319. ProgressHandler subclass: #HLProgressHandler
  320. instanceVariableNames: ''
  321. package: 'Helios-Core'!
  322. !HLProgressHandler commentStamp!
  323. I am a specific progress handler for Helios, displaying progresses in a modal window.!
  324. !HLProgressHandler methodsFor: 'progress handling'!
  325. do: aBlock on: aCollection displaying: aString
  326. HLProgressWidget default
  327. do: aBlock
  328. on: aCollection
  329. displaying: aString
  330. ! !
  331. Widget subclass: #HLTabWidget
  332. instanceVariableNames: 'widget label root'
  333. package: 'Helios-Core'!
  334. !HLTabWidget commentStamp!
  335. I am a widget specialized into building another widget as an Helios tab.
  336. I should not be used directly, `HLWidget class >> #openAsTab` should be used instead.
  337. ## Example
  338. HLWorkspace openAsTab!
  339. !HLTabWidget methodsFor: 'accessing'!
  340. activate
  341. self manager activate: self
  342. !
  343. add
  344. self manager addTab: self
  345. !
  346. cssClass
  347. ^ self widget tabClass
  348. !
  349. displayLabel
  350. ^ self label size > 20
  351. ifTrue: [ (self label first: 20), '...' ]
  352. ifFalse: [ self label ]
  353. !
  354. focus
  355. self widget canHaveFocus ifTrue: [
  356. self widget focus ]
  357. !
  358. label
  359. ^ label ifNil: [ '' ]
  360. !
  361. label: aString
  362. label := aString
  363. !
  364. manager
  365. ^ HLManager current
  366. !
  367. widget
  368. ^ widget
  369. !
  370. widget: aWidget
  371. widget := aWidget
  372. ! !
  373. !HLTabWidget methodsFor: 'actions'!
  374. hide
  375. root ifNotNil: [ root asJQuery css: 'visibility' put: 'hidden' ]
  376. !
  377. registerBindings
  378. self widget registerBindings
  379. !
  380. remove
  381. self widget unregister.
  382. root ifNotNil: [ root asJQuery remove ]
  383. !
  384. show
  385. root
  386. ifNil: [ self appendToJQuery: 'body' asJQuery ]
  387. ifNotNil: [ root asJQuery css: 'visibility' put: 'visible' ]
  388. ! !
  389. !HLTabWidget methodsFor: 'rendering'!
  390. renderOn: html
  391. root := html div
  392. class: 'tab';
  393. yourself.
  394. self renderTab
  395. !
  396. renderTab
  397. root contents: [ :html |
  398. html div
  399. class: 'amber_box';
  400. with: [ self widget renderOn: html ] ]
  401. ! !
  402. !HLTabWidget methodsFor: 'testing'!
  403. isActive
  404. ^ self manager activeTab = self
  405. ! !
  406. !HLTabWidget class methodsFor: 'instance creation'!
  407. on: aWidget labelled: aString
  408. ^ self new
  409. widget: aWidget;
  410. label: aString;
  411. yourself
  412. ! !
  413. Widget subclass: #HLWidget
  414. instanceVariableNames: 'wrapper'
  415. package: 'Helios-Core'!
  416. !HLWidget commentStamp!
  417. I am the abstract superclass of all Helios widgets.
  418. I provide common methods, additional behavior to widgets useful for Helios, like dialog creation, command execution and tab creation.
  419. ## API
  420. 1. Rendering
  421. Instead of overriding `#renderOn:` as with other Widget subclasses, my subclasses should override `#renderContentOn:`.
  422. 2. Refreshing
  423. To re-render a widget, use `#refresh`.
  424. 3. Key bindings registration and tabs
  425. When displayed as a tab, the widget has a chance to register keybindings with the `#registerBindingsOn:` hook method.
  426. 4. Unregistration
  427. When a widget has subscribed to announcements or other actions that need to be cleared when closing the tab, the hook method `#unregister` will be called by helios.
  428. 5. Tabs
  429. To enable a widget class to be open as a tab, override the class-side `#canBeOpenAsTab` method to answer `true`. `#tabClass` and `#tabPriority` can be overridden too to respectively change the css class of the tab and the order of tabs in the main menu.
  430. 6. Command execution
  431. An helios command (instance of `HLCommand` or one of its subclass) can be executed with `#execute:`.!
  432. !HLWidget methodsFor: 'accessing'!
  433. manager
  434. ^ HLManager current
  435. !
  436. tabClass
  437. ^ self class tabClass
  438. !
  439. wrapper
  440. ^ wrapper
  441. ! !
  442. !HLWidget methodsFor: 'actions'!
  443. confirm: aString ifTrue: aBlock
  444. self manager confirm: aString ifTrue: aBlock
  445. !
  446. execute: aCommand
  447. HLManager current keyBinder
  448. activate;
  449. applyBinding: aCommand asBinding
  450. !
  451. openAsTab
  452. HLManager current addTab: (HLTabWidget on: self labelled: self class tabLabel)
  453. !
  454. request: aString do: aBlock
  455. self manager request: aString do: aBlock
  456. !
  457. request: aString value: valueString do: aBlock
  458. self manager
  459. request: aString
  460. value: valueString
  461. do: aBlock
  462. !
  463. unregister
  464. "This method is called whenever the receiver is closed (as a tab).
  465. Widgets subscribing to announcements should unregister there"
  466. ! !
  467. !HLWidget methodsFor: 'keybindings'!
  468. bindKeyDown: keyDownBlock keyUp: keyUpBlock
  469. self wrapper asJQuery
  470. keydown: keyDownBlock;
  471. keyup: keyUpBlock
  472. !
  473. registerBindings
  474. self registerBindingsOn: self manager keyBinder bindings
  475. !
  476. registerBindingsOn: aBindingGroup
  477. !
  478. unbindKeyDownKeyUp
  479. self wrapper asJQuery
  480. unbind: 'keydown';
  481. unbind: 'keyup'
  482. ! !
  483. !HLWidget methodsFor: 'rendering'!
  484. renderContentOn: html
  485. !
  486. renderOn: html
  487. wrapper := html div.
  488. [ :renderer | self renderContentOn: renderer ] appendToJQuery: wrapper asJQuery
  489. ! !
  490. !HLWidget methodsFor: 'testing'!
  491. canHaveFocus
  492. ^ false
  493. ! !
  494. !HLWidget methodsFor: 'updating'!
  495. refresh
  496. self wrapper ifNil: [ ^ self ].
  497. self wrapper asJQuery empty.
  498. [ :html | self renderContentOn: html ] appendToJQuery: self wrapper asJQuery
  499. ! !
  500. !HLWidget class methodsFor: 'accessing'!
  501. openAsTab
  502. HLManager current addTab: (HLTabWidget on: self new labelled: self tabLabel)
  503. !
  504. tabClass
  505. ^ ''
  506. !
  507. tabLabel
  508. ^ 'Tab'
  509. !
  510. tabPriority
  511. ^ 500
  512. ! !
  513. !HLWidget class methodsFor: 'testing'!
  514. canBeOpenAsTab
  515. ^ false
  516. ! !
  517. HLWidget subclass: #HLFocusableWidget
  518. instanceVariableNames: ''
  519. package: 'Helios-Core'!
  520. !HLFocusableWidget commentStamp!
  521. I am a widget that can be focused.
  522. ## API
  523. Instead of overriding `#renderOn:` as with other `Widget` subclasses, my subclasses should override `#renderContentOn:`.
  524. To bring the focus to the widget, use the `#focus` method.!
  525. !HLFocusableWidget methodsFor: 'accessing'!
  526. focusClass
  527. ^ 'focused'
  528. ! !
  529. !HLFocusableWidget methodsFor: 'events'!
  530. blur
  531. self wrapper asJQuery blur
  532. !
  533. focus
  534. self wrapper asJQuery focus
  535. ! !
  536. !HLFocusableWidget methodsFor: 'rendering'!
  537. renderContentOn: html
  538. !
  539. renderOn: html
  540. wrapper := html div
  541. class: 'hl_widget';
  542. yourself.
  543. wrapper with: [ self renderContentOn: html ].
  544. wrapper
  545. at: 'tabindex' put: '0';
  546. onBlur: [ self wrapper asJQuery removeClass: self focusClass ];
  547. onFocus: [ self wrapper asJQuery addClass: self focusClass ]
  548. ! !
  549. !HLFocusableWidget methodsFor: 'testing'!
  550. canHaveFocus
  551. ^ true
  552. !
  553. hasFocus
  554. ^ self wrapper notNil and: [ self wrapper asJQuery hasClass: self focusClass ]
  555. ! !
  556. HLFocusableWidget subclass: #HLListWidget
  557. instanceVariableNames: 'items selectedItem mapping'
  558. package: 'Helios-Core'!
  559. !HLListWidget methodsFor: 'accessing'!
  560. cssClassForItem: anObject
  561. ^ ''
  562. !
  563. items
  564. ^ items ifNil: [ items := self defaultItems ]
  565. !
  566. items: aCollection
  567. items := aCollection
  568. !
  569. listCssClassForItem: anObject
  570. ^ self selectedItem = anObject
  571. ifTrue: [ 'active' ]
  572. ifFalse: [ 'inactive' ]
  573. !
  574. positionOf: aListItem
  575. <
  576. return aListItem.parent().children().get().indexOf(aListItem.get(0)) + 1
  577. >
  578. !
  579. selectedItem
  580. ^ selectedItem
  581. !
  582. selectedItem: anObject
  583. selectedItem := anObject
  584. ! !
  585. !HLListWidget methodsFor: 'actions'!
  586. activateFirstListItem
  587. self activateListItem: ((wrapper asJQuery find: 'li.inactive') eq: 0)
  588. !
  589. activateItem: anObject
  590. self activateListItem: (mapping
  591. at: anObject
  592. ifAbsent: [ ^ self ]) asJQuery
  593. !
  594. activateListItem: aListItem
  595. | item |
  596. (aListItem get: 0) ifNil: [ ^self ].
  597. aListItem parent children removeClass: 'active'.
  598. aListItem addClass: 'active'.
  599. self ensureVisible: aListItem.
  600. "Activate the corresponding item"
  601. item := (self items at: (aListItem attr: 'list-data') asNumber).
  602. self selectedItem == item ifFalse: [
  603. self selectItem: item ]
  604. !
  605. activateNextListItem
  606. self activateListItem: (self wrapper asJQuery find: 'li.active') next.
  607. "select the first item if none is selected"
  608. (self wrapper asJQuery find: ' .active') get ifEmpty: [
  609. self activateFirstListItem ]
  610. !
  611. activatePreviousListItem
  612. self activateListItem: (self wrapper asJQuery find: 'li.active') prev
  613. !
  614. ensureVisible: aListItem
  615. "Move the scrollbar to show the active element"
  616. | parent position |
  617. position := self positionOf: aListItem.
  618. parent := aListItem parent.
  619. aListItem position top < 0 ifTrue: [
  620. (parent get: 0) scrollTop: ((parent get: 0) scrollTop + aListItem position top - 10) ].
  621. aListItem position top + aListItem height > parent height ifTrue: [
  622. (parent get: 0) scrollTop: ((parent get: 0) scrollTop + aListItem height - (parent height - aListItem position top)) +10 ]
  623. !
  624. focus
  625. super focus.
  626. self items isEmpty ifFalse: [
  627. self selectedItem ifNil: [ self activateFirstListItem ] ]
  628. !
  629. refresh
  630. super refresh.
  631. self ensureVisible: (mapping
  632. at: self selectedItem
  633. ifAbsent: [ ^ self ]) asJQuery
  634. !
  635. selectItem: anObject
  636. self selectedItem: anObject
  637. ! !
  638. !HLListWidget methodsFor: 'defaults'!
  639. defaultItems
  640. ^ #()
  641. ! !
  642. !HLListWidget methodsFor: 'events'!
  643. setupKeyBindings
  644. (HLRepeatedKeyDownHandler on: self)
  645. whileKeyDown: 38 do: [ self activatePreviousListItem ];
  646. whileKeyDown: 40 do: [ self activateNextListItem ];
  647. rebindKeys
  648. ! !
  649. !HLListWidget methodsFor: 'initialization'!
  650. initialize
  651. super initialize.
  652. mapping := Dictionary new.
  653. ! !
  654. !HLListWidget methodsFor: 'private'!
  655. registerMappingFrom: anObject to: aTag
  656. mapping at: anObject put: aTag
  657. ! !
  658. !HLListWidget methodsFor: 'rendering'!
  659. renderButtonsOn: html
  660. !
  661. renderContentOn: html
  662. html ul
  663. class: 'nav nav-pills nav-stacked';
  664. with: [ self renderListOn: html ].
  665. html div class: 'pane_actions form-actions'; with: [
  666. self renderButtonsOn: html ].
  667. self setupKeyBindings
  668. !
  669. renderItem: anObject on: html
  670. | li |
  671. li := html li.
  672. self registerMappingFrom: anObject to: li.
  673. li
  674. at: 'list-data' put: (self items indexOf: anObject) asString;
  675. class: (self listCssClassForItem: anObject);
  676. with: [
  677. html a
  678. with: [
  679. (html tag: 'i') class: (self cssClassForItem: anObject).
  680. self renderItemLabel: anObject on: html ];
  681. onClick: [
  682. self activateListItem: li asJQuery ] ]
  683. !
  684. renderItemLabel: anObject on: html
  685. html with: anObject asString
  686. !
  687. renderListOn: html
  688. mapping := Dictionary new.
  689. self items do: [ :each |
  690. self renderItem: each on: html ]
  691. ! !
  692. HLListWidget subclass: #HLNavigationListWidget
  693. instanceVariableNames: 'previous next'
  694. package: 'Helios-Core'!
  695. !HLNavigationListWidget methodsFor: 'accessing'!
  696. next
  697. ^ next
  698. !
  699. next: aWidget
  700. next := aWidget.
  701. aWidget previous = self ifFalse: [ aWidget previous: self ]
  702. !
  703. previous
  704. ^ previous
  705. !
  706. previous: aWidget
  707. previous := aWidget.
  708. aWidget next = self ifFalse: [ aWidget next: self ]
  709. ! !
  710. !HLNavigationListWidget methodsFor: 'actions'!
  711. nextFocus
  712. self next ifNotNil: [ self next focus ]
  713. !
  714. previousFocus
  715. self previous ifNotNil: [ self previous focus ]
  716. ! !
  717. !HLNavigationListWidget methodsFor: 'events'!
  718. setupKeyBindings
  719. super setupKeyBindings.
  720. self wrapper asJQuery keydown: [ :e |
  721. e which = 39 ifTrue: [
  722. self nextFocus ].
  723. e which = 37 ifTrue: [
  724. self previousFocus ] ]
  725. ! !
  726. HLNavigationListWidget subclass: #HLToolListWidget
  727. instanceVariableNames: 'model'
  728. package: 'Helios-Core'!
  729. !HLToolListWidget methodsFor: 'accessing'!
  730. commandCategory
  731. ^ self label
  732. !
  733. label
  734. ^ 'List'
  735. !
  736. menuCommands
  737. "Answer a collection of commands to be put in the cog menu"
  738. ^ ((HLToolCommand concreteClasses
  739. select: [ :each | each isValidFor: self model ])
  740. collect: [ :each | each for: self model ])
  741. select: [ :each |
  742. each category = self commandCategory and: [
  743. each isAction and: [ each isActive ] ] ]
  744. !
  745. model
  746. ^ model
  747. !
  748. model: aBrowserModel
  749. model := aBrowserModel.
  750. self
  751. observeSystem;
  752. observeModel
  753. !
  754. selectedItem: anItem
  755. "Selection changed, update the cog menu"
  756. super selectedItem: anItem.
  757. self updateMenu
  758. ! !
  759. !HLToolListWidget methodsFor: 'actions'!
  760. activateListItem: anItem
  761. self model withChangesDo: [ super activateListItem: anItem ]
  762. !
  763. activateNextListItem
  764. self model withChangesDo: [ super activateNextListItem ]
  765. !
  766. activatePreviousListItem
  767. self model withChangesDo: [ super activatePreviousListItem ]
  768. !
  769. observeModel
  770. !
  771. observeSystem
  772. !
  773. unregister
  774. super unregister.
  775. self model announcer unsubscribe: self.
  776. self model systemAnnouncer unsubscribe: self
  777. ! !
  778. !HLToolListWidget methodsFor: 'rendering'!
  779. renderContentOn: html
  780. self renderHeadOn: html.
  781. super renderContentOn: html
  782. !
  783. renderHeadOn: html
  784. html div
  785. class: 'list-label';
  786. with: [
  787. html with: self label.
  788. self renderMenuOn: html ]
  789. !
  790. renderMenuOn: html
  791. | commands |
  792. commands := self menuCommands.
  793. commands isEmpty ifTrue: [ ^ self ].
  794. html div
  795. class: 'btn-group cog';
  796. with: [
  797. html a
  798. class: 'btn dropdown-toggle';
  799. at: 'data-toggle' put: 'dropdown';
  800. with: [ (html tag: 'i') class: 'icon-cog' ].
  801. html ul
  802. class: 'dropdown-menu pull-right';
  803. with: [
  804. self menuCommands do: [ :each |
  805. html li with: [ html a
  806. with: each menuLabel;
  807. onClick: [ self execute: each ] ] ] ] ]
  808. ! !
  809. !HLToolListWidget methodsFor: 'updating'!
  810. updateMenu
  811. (self wrapper asJQuery find: '.cog') remove.
  812. [ :html | self renderMenuOn: html ]
  813. appendToJQuery: (self wrapper asJQuery find: '.list-label')
  814. ! !
  815. !HLToolListWidget class methodsFor: 'instance creation'!
  816. on: aModel
  817. ^ self new
  818. model: aModel;
  819. yourself
  820. ! !
  821. HLListWidget subclass: #HLTabListWidget
  822. instanceVariableNames: 'callback'
  823. package: 'Helios-Core'!
  824. !HLTabListWidget commentStamp!
  825. I am a widget used to display a list of helios tabs.
  826. When a tab is selected, `callback` is evaluated with the selected tab as argument.!
  827. !HLTabListWidget methodsFor: 'accessing'!
  828. callback
  829. ^ callback ifNil: [ [] ]
  830. !
  831. callback: aBlock
  832. callback := aBlock
  833. ! !
  834. !HLTabListWidget methodsFor: 'actions'!
  835. selectItem: aTab
  836. super selectItem: aTab.
  837. self callback value: aTab
  838. ! !
  839. !HLTabListWidget methodsFor: 'rendering'!
  840. renderItemLabel: aTab on: html
  841. html span
  842. class: aTab cssClass;
  843. with: aTab label
  844. ! !
  845. HLWidget subclass: #HLManager
  846. instanceVariableNames: 'tabs activeTab environment history'
  847. package: 'Helios-Core'!
  848. !HLManager methodsFor: 'accessing'!
  849. activeTab
  850. ^ activeTab
  851. !
  852. environment
  853. "The default environment used by all Helios objects"
  854. ^ environment ifNil: [ environment := self defaultEnvironment ]
  855. !
  856. environment: anEnvironment
  857. environment := anEnvironment
  858. !
  859. history
  860. ^ history ifNil: [ history := OrderedCollection new ]
  861. !
  862. history: aCollection
  863. history := aCollection
  864. !
  865. keyBinder
  866. ^ HLKeyBinder current
  867. !
  868. tabs
  869. ^ tabs ifNil: [ tabs := OrderedCollection new ]
  870. ! !
  871. !HLManager methodsFor: 'actions'!
  872. activate: aTab
  873. self keyBinder flushBindings.
  874. aTab registerBindings.
  875. activeTab := aTab.
  876. self
  877. refresh;
  878. addToHistory: aTab;
  879. show: aTab
  880. !
  881. addTab: aTab
  882. self tabs add: aTab.
  883. self activate: aTab
  884. !
  885. addToHistory: aTab
  886. self removeFromHistory: aTab.
  887. self history add: aTab
  888. !
  889. confirm: aString ifFalse: aBlock
  890. HLConfirmationWidget new
  891. confirmationString: aString;
  892. cancelBlock: aBlock;
  893. show
  894. !
  895. confirm: aString ifTrue: aBlock
  896. HLConfirmationWidget new
  897. confirmationString: aString;
  898. actionBlock: aBlock;
  899. show
  900. !
  901. registerErrorHandler: anErrorHandler
  902. self environment registerErrorHandler: anErrorHandler
  903. !
  904. registerInspector: anInspector
  905. self environment registerInspector: anInspector
  906. !
  907. registerProgressHandler: aProgressHandler
  908. self environment registerProgressHandler: aProgressHandler
  909. !
  910. removeActiveTab
  911. self removeTab: self activeTab
  912. !
  913. removeFromHistory: aTab
  914. self history: (self history reject: [ :each | each == aTab ])
  915. !
  916. removeTab: aTab
  917. (self tabs includes: aTab) ifFalse: [ ^ self ].
  918. self removeFromHistory: aTab.
  919. self tabs remove: aTab.
  920. self keyBinder flushBindings.
  921. aTab remove.
  922. self refresh.
  923. self history ifNotEmpty: [
  924. self history last activate ]
  925. !
  926. request: aString do: aBlock
  927. self
  928. request: aString
  929. value: ''
  930. do: aBlock
  931. !
  932. request: aString value: valueString do: aBlock
  933. HLRequestWidget new
  934. confirmationString: aString;
  935. actionBlock: aBlock;
  936. value: valueString;
  937. show
  938. ! !
  939. !HLManager methodsFor: 'defaults'!
  940. defaultEnvironment
  941. "If helios is loaded from within a frame, answer the parent window environment"
  942. | parent |
  943. parent := window opener ifNil: [ window parent ].
  944. parent ifNil: [ ^ Environment new ].
  945. ^ (((parent at: 'requirejs') value: 'amber_vm/smalltalk')
  946. at: 'Environment') new
  947. ! !
  948. !HLManager methodsFor: 'initialization'!
  949. initialize
  950. super initialize.
  951. HLErrorHandler register.
  952. HLProgressHandler register.
  953. self registerInspector: HLInspector.
  954. self registerErrorHandler: ErrorHandler current.
  955. self registerProgressHandler: ProgressHandler current.
  956. self keyBinder setupEvents
  957. ! !
  958. !HLManager methodsFor: 'rendering'!
  959. refresh
  960. '.navbar' asJQuery remove.
  961. self appendToJQuery: 'body' asJQuery
  962. !
  963. renderAddOn: html
  964. html li
  965. class: 'dropdown';
  966. with: [
  967. html a
  968. class: 'dropdown-toggle';
  969. at: 'data-toggle' put: 'dropdown';
  970. with: [
  971. html with: 'Open...'.
  972. (html tag: 'b') class: 'caret' ].
  973. html ul
  974. class: 'dropdown-menu';
  975. with: [
  976. ((HLWidget withAllSubclasses
  977. select: [ :each | each canBeOpenAsTab ])
  978. sorted: [ :a :b | a tabPriority < b tabPriority ])
  979. do: [ :each |
  980. html li with: [
  981. html a
  982. with: each tabLabel;
  983. onClick: [ each openAsTab ] ] ] ] ]
  984. !
  985. renderContentOn: html
  986. html div
  987. class: 'navbar navbar-fixed-top';
  988. with: [ html div
  989. class: 'navbar-inner';
  990. with: [ self renderTabsOn: html ] ]
  991. !
  992. renderTabsOn: html
  993. html ul
  994. class: 'nav';
  995. with: [
  996. self tabs do: [ :each |
  997. html li
  998. class: (each isActive ifTrue: [ 'active' ] ifFalse: [ 'inactive' ]);
  999. with: [
  1000. html a
  1001. with: [
  1002. ((html tag: 'i') class: 'close')
  1003. onClick: [ self removeTab: each ].
  1004. html span
  1005. class: each cssClass;
  1006. with: each displayLabel ];
  1007. onClick: [ each activate ] ] ].
  1008. self renderAddOn: html ]
  1009. !
  1010. show: aTab
  1011. self tabs do: [ :each | each hide ].
  1012. aTab show; focus
  1013. ! !
  1014. HLManager class instanceVariableNames: 'current'!
  1015. !HLManager class methodsFor: 'accessing'!
  1016. current
  1017. ^ current ifNil: [ current := self basicNew initialize ]
  1018. ! !
  1019. !HLManager class methodsFor: 'initialization'!
  1020. initialize
  1021. self current appendToJQuery: 'body' asJQuery.
  1022. self clearKeydownEvent
  1023. ! !
  1024. !HLManager class methodsFor: 'instance creation'!
  1025. new
  1026. "Use current instead"
  1027. self shouldNotImplement
  1028. ! !
  1029. !HLManager class methodsFor: 'private'!
  1030. clearKeydownEvent
  1031. "Prevent default keydown event with arrow key from scrolling the parent page
  1032. when helios is run inside a frame."
  1033. 'body' asJQuery keydown: [ :e |
  1034. (e keyCode >= 37 and: [ e keyCode <= 40 ])
  1035. ifTrue: [ false ] ]
  1036. ! !
  1037. HLWidget subclass: #HLModalWidget
  1038. instanceVariableNames: ''
  1039. package: 'Helios-Core'!
  1040. !HLModalWidget commentStamp!
  1041. I implement an abstract modal widget.!
  1042. !HLModalWidget methodsFor: 'accessing'!
  1043. cssClass
  1044. ^ ''
  1045. ! !
  1046. !HLModalWidget methodsFor: 'actions'!
  1047. cancel
  1048. self remove
  1049. !
  1050. confirm
  1051. "Override in subclasses"
  1052. self remove
  1053. !
  1054. remove
  1055. '.dialog' asJQuery removeClass: 'active'.
  1056. [
  1057. '#overlay' asJQuery remove.
  1058. '.dialog' asJQuery remove
  1059. ] valueWithTimeout: 300
  1060. !
  1061. show
  1062. self appendToJQuery: 'body' asJQuery
  1063. ! !
  1064. !HLModalWidget methodsFor: 'rendering'!
  1065. hasButtons
  1066. ^ true
  1067. !
  1068. renderButtonsOn: html
  1069. | confirmButton |
  1070. html div
  1071. class: 'buttons';
  1072. with: [
  1073. html button
  1074. class: 'button';
  1075. with: 'Cancel';
  1076. onClick: [ self cancel ].
  1077. confirmButton := html button
  1078. class: 'button default';
  1079. with: 'Confirm';
  1080. onClick: [ self confirm ] ].
  1081. confirmButton asJQuery focus
  1082. !
  1083. renderContentOn: html
  1084. | confirmButton |
  1085. html div id: 'overlay'.
  1086. html div
  1087. class: 'dialog ', self cssClass;
  1088. with: [
  1089. self renderMainOn: html.
  1090. self hasButtons ifTrue: [
  1091. self renderButtonsOn: html ] ].
  1092. '.dialog' asJQuery addClass: 'active'.
  1093. self setupKeyBindings
  1094. !
  1095. renderMainOn: html
  1096. !
  1097. setupKeyBindings
  1098. '.dialog' asJQuery keyup: [ :e |
  1099. e keyCode = String esc asciiValue ifTrue: [ self cancel ] ]
  1100. ! !
  1101. HLModalWidget subclass: #HLConfirmationWidget
  1102. instanceVariableNames: 'confirmationString actionBlock cancelBlock'
  1103. package: 'Helios-Core'!
  1104. !HLConfirmationWidget commentStamp!
  1105. I display confirmation messages.
  1106. Instead of creating an instance directly, use `HLWidget >> #confirm:ifTrue:`.!
  1107. !HLConfirmationWidget methodsFor: 'accessing'!
  1108. actionBlock
  1109. ^ actionBlock ifNil: [ [] ]
  1110. !
  1111. actionBlock: aBlock
  1112. actionBlock := aBlock
  1113. !
  1114. cancelBlock
  1115. ^ cancelBlock ifNil: [ [] ]
  1116. !
  1117. cancelBlock: aBlock
  1118. cancelBlock := aBlock
  1119. !
  1120. confirmationString
  1121. ^ confirmationString ifNil: [ 'Confirm' ]
  1122. !
  1123. confirmationString: aString
  1124. confirmationString := aString
  1125. ! !
  1126. !HLConfirmationWidget methodsFor: 'actions'!
  1127. cancel
  1128. self cancelBlock value.
  1129. super cancel
  1130. !
  1131. confirm
  1132. super confirm.
  1133. self actionBlock value
  1134. ! !
  1135. !HLConfirmationWidget methodsFor: 'rendering'!
  1136. renderMainOn: html
  1137. html span with: self confirmationString
  1138. ! !
  1139. HLConfirmationWidget subclass: #HLRequestWidget
  1140. instanceVariableNames: 'input value'
  1141. package: 'Helios-Core'!
  1142. !HLRequestWidget commentStamp!
  1143. I display a modal window requesting user input.
  1144. Instead of creating instances manually, use `HLWidget >> #request:do:` and `#request:value:do:`.!
  1145. !HLRequestWidget methodsFor: 'accessing'!
  1146. cssClass
  1147. ^ 'large'
  1148. !
  1149. value
  1150. ^ value ifNil: [ '' ]
  1151. !
  1152. value: aString
  1153. value := aString
  1154. ! !
  1155. !HLRequestWidget methodsFor: 'actions'!
  1156. confirm
  1157. super confirm.
  1158. self actionBlock value: input asJQuery val
  1159. ! !
  1160. !HLRequestWidget methodsFor: 'rendering'!
  1161. renderMainOn: html
  1162. super renderMainOn: html.
  1163. input := html textarea.
  1164. input asJQuery val: self value
  1165. ! !
  1166. HLModalWidget subclass: #HLProgressWidget
  1167. instanceVariableNames: 'progressBars visible'
  1168. package: 'Helios-Core'!
  1169. !HLProgressWidget commentStamp!
  1170. I am a widget used to display progress modal dialogs.
  1171. My default instance is accessed with `HLProgressWidget class >> #default`.
  1172. See `HLProgressHandler` for usage.!
  1173. !HLProgressWidget methodsFor: 'accessing'!
  1174. progressBars
  1175. ^ progressBars ifNil: [ progressBars := OrderedCollection new ]
  1176. ! !
  1177. !HLProgressWidget methodsFor: 'actions'!
  1178. addProgressBar: aProgressBar
  1179. self show.
  1180. self progressBars add: aProgressBar.
  1181. aProgressBar appendToJQuery: (self wrapper asJQuery find: '.dialog')
  1182. !
  1183. do: aBlock on: aCollection displaying: aString
  1184. | progressBar |
  1185. progressBar := HLProgressBarWidget new
  1186. parent: self;
  1187. label: aString;
  1188. workBlock: aBlock;
  1189. collection: aCollection;
  1190. yourself.
  1191. self addProgressBar: progressBar.
  1192. progressBar start
  1193. !
  1194. flush
  1195. self progressBars do: [ :each |
  1196. self removeProgressBar: each ]
  1197. !
  1198. remove
  1199. self isVisible ifTrue: [
  1200. visible := false.
  1201. super remove ]
  1202. !
  1203. removeProgressBar: aProgressBar
  1204. self progressBars remove: aProgressBar ifAbsent: [].
  1205. aProgressBar wrapper asJQuery remove.
  1206. self progressBars ifEmpty: [ self remove ]
  1207. !
  1208. show
  1209. self isVisible ifFalse: [
  1210. visible := true.
  1211. super show ]
  1212. ! !
  1213. !HLProgressWidget methodsFor: 'rendering'!
  1214. renderMainOn: html
  1215. self progressBars do: [ :each |
  1216. html with: each ]
  1217. ! !
  1218. !HLProgressWidget methodsFor: 'testing'!
  1219. hasButtons
  1220. ^ false
  1221. !
  1222. isVisible
  1223. ^ visible ifNil: [ false ]
  1224. ! !
  1225. HLProgressWidget class instanceVariableNames: 'default'!
  1226. !HLProgressWidget class methodsFor: 'accessing'!
  1227. default
  1228. ^ default ifNil: [ default := self new ]
  1229. ! !
  1230. HLModalWidget subclass: #HLTabSelectionWidget
  1231. instanceVariableNames: 'tabs tabList selectedTab selectCallback cancelCallback confirmCallback'
  1232. package: 'Helios-Core'!
  1233. !HLTabSelectionWidget commentStamp!
  1234. I am a modal window used to select or create tabs.!
  1235. !HLTabSelectionWidget methodsFor: 'accessing'!
  1236. cancelCallback
  1237. ^ cancelCallback ifNil: [ [] ]
  1238. !
  1239. cancelCallback: aBlock
  1240. cancelCallback := aBlock
  1241. !
  1242. confirmCallback
  1243. ^ confirmCallback ifNil: [ [] ]
  1244. !
  1245. confirmCallback: aBlock
  1246. confirmCallback := aBlock
  1247. !
  1248. selectCallback
  1249. ^ selectCallback ifNil: [ [] ]
  1250. !
  1251. selectCallback: aBlock
  1252. selectCallback := aBlock
  1253. !
  1254. selectedTab
  1255. ^ selectedTab
  1256. !
  1257. selectedTab: aTab
  1258. selectedTab := aTab
  1259. !
  1260. tabs
  1261. ^ tabs ifNil: [ #() ]
  1262. !
  1263. tabs: aCollection
  1264. tabs := aCollection
  1265. ! !
  1266. !HLTabSelectionWidget methodsFor: 'actions'!
  1267. cancel
  1268. super cancel.
  1269. self cancelCallback value
  1270. !
  1271. confirm
  1272. super confirm.
  1273. self confirmCallback value: self selectedTab
  1274. !
  1275. selectTab: aTab
  1276. self selectedTab: aTab.
  1277. self selectCallback value: aTab
  1278. !
  1279. setupKeyBindings
  1280. super setupKeyBindings.
  1281. '.dialog' asJQuery keyup: [ :e |
  1282. e keyCode = String cr asciiValue ifTrue: [ self confirm ] ]
  1283. ! !
  1284. !HLTabSelectionWidget methodsFor: 'rendering'!
  1285. renderContentOn: html
  1286. super renderContentOn: html.
  1287. self tabList focus
  1288. !
  1289. renderMainOn: html
  1290. html div
  1291. class: 'title';
  1292. with: 'Tab selection'.
  1293. html with: self tabList
  1294. !
  1295. renderTab: aTab on: html
  1296. html
  1297. span
  1298. class: aTab cssClass;
  1299. with: aTab label
  1300. !
  1301. renderTabsOn: html
  1302. self tabs do: [ :each |
  1303. html li with: [
  1304. html a
  1305. with: [
  1306. self renderTab: each on: html ];
  1307. onClick: [ self selectTab: each ] ] ]
  1308. !
  1309. tabList
  1310. tabList ifNil: [
  1311. tabList := HLTabListWidget new.
  1312. tabList
  1313. callback: [ :tab | self selectTab: tab. tabList focus ];
  1314. selectedItem: self selectedTab;
  1315. items: self tabs ].
  1316. ^ tabList
  1317. ! !
  1318. HLWidget subclass: #HLProgressBarWidget
  1319. instanceVariableNames: 'label parent workBlock collection bar'
  1320. package: 'Helios-Core'!
  1321. !HLProgressBarWidget commentStamp!
  1322. I am a widget used to display a progress bar while iterating over a collection.!
  1323. !HLProgressBarWidget methodsFor: 'accessing'!
  1324. collection
  1325. ^ collection
  1326. !
  1327. collection: aCollection
  1328. collection := aCollection
  1329. !
  1330. label
  1331. ^ label
  1332. !
  1333. label: aString
  1334. label := aString
  1335. !
  1336. parent
  1337. ^ parent
  1338. !
  1339. parent: aProgress
  1340. parent := aProgress
  1341. !
  1342. workBlock
  1343. ^ workBlock
  1344. !
  1345. workBlock: aBlock
  1346. workBlock := aBlock
  1347. ! !
  1348. !HLProgressBarWidget methodsFor: 'actions'!
  1349. evaluateAt: anInteger
  1350. self updateProgress: (anInteger / self collection size) * 100.
  1351. anInteger <= self collection size
  1352. ifTrue: [
  1353. [
  1354. self workBlock value: (self collection at: anInteger).
  1355. self evaluateAt: anInteger + 1 ] valueWithTimeout: 10 ]
  1356. ifFalse: [ [ self remove ] valueWithTimeout: 500 ]
  1357. !
  1358. remove
  1359. self parent removeProgressBar: self
  1360. !
  1361. start
  1362. "Make sure the UI has some time to update itself between each iteration"
  1363. self evaluateAt: 1
  1364. !
  1365. updateProgress: anInteger
  1366. bar asJQuery css: 'width' put: anInteger asString, '%'
  1367. ! !
  1368. !HLProgressBarWidget methodsFor: 'rendering'!
  1369. renderContentOn: html
  1370. html span with: self label.
  1371. html div
  1372. class: 'progress';
  1373. with: [
  1374. bar := html div
  1375. class: 'bar';
  1376. style: 'width: 0%' ]
  1377. ! !
  1378. HLProgressBarWidget class instanceVariableNames: 'default'!
  1379. !HLProgressBarWidget class methodsFor: 'accessing'!
  1380. default
  1381. ^ default ifNil: [ default := self new ]
  1382. ! !
  1383. HLWidget subclass: #HLSUnit
  1384. instanceVariableNames: ''
  1385. package: 'Helios-Core'!
  1386. !HLSUnit class methodsFor: 'accessing'!
  1387. tabClass
  1388. ^ 'sunit'
  1389. !
  1390. tabLabel
  1391. ^ 'SUnit'
  1392. !
  1393. tabPriority
  1394. ^ 1000
  1395. ! !
  1396. !HLSUnit class methodsFor: 'testing'!
  1397. canBeOpenAsTab
  1398. ^ true
  1399. ! !