Helios-Core.st 35 KB

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