Helios-Core.st 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823
  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. findListItemFor: anObject
  562. ^(((wrapper asJQuery find: 'li')
  563. filter: [:thisArg :otherArg | (thisArg asJQuery data: 'item') = anObject] currySelf) eq: 0)
  564. !
  565. items
  566. ^ items ifNil: [ items := self defaultItems ]
  567. !
  568. items: aCollection
  569. items := aCollection
  570. !
  571. listCssClassForItem: anObject
  572. ^ self selectedItem = anObject
  573. ifTrue: [ 'active' ]
  574. ifFalse: [ 'inactive' ]
  575. !
  576. positionOf: aListItem
  577. <
  578. return aListItem.parent().children().get().indexOf(aListItem.get(0)) + 1
  579. >
  580. !
  581. selectedItem
  582. ^ selectedItem
  583. !
  584. selectedItem: anObject
  585. selectedItem := anObject
  586. ! !
  587. !HLListWidget methodsFor: 'actions'!
  588. activateFirstListItem
  589. self activateListItem: ((wrapper asJQuery find: 'li.inactive') eq: 0)
  590. !
  591. activateItem: anObject
  592. self activateListItem: (self findListItemFor: anObject)
  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 := aListItem data: 'item'.
  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. (aListItem get: 0) ifNil: [ ^self ].
  618. position := self positionOf: aListItem.
  619. parent := aListItem parent.
  620. aListItem position top < 0 ifTrue: [
  621. (parent get: 0) scrollTop: ((parent get: 0) scrollTop + aListItem position top - 10) ].
  622. aListItem position top + aListItem height > parent height ifTrue: [
  623. (parent get: 0) scrollTop: ((parent get: 0) scrollTop + aListItem height - (parent height - aListItem position top)) +10 ]
  624. !
  625. focus
  626. super focus.
  627. self items isEmpty ifFalse: [
  628. self selectedItem ifNil: [ self activateFirstListItem ] ]
  629. !
  630. refresh
  631. super refresh.
  632. self ensureVisible: (self findListItemFor: self selectedItem)
  633. !
  634. selectItem: anObject
  635. self selectedItem: anObject
  636. ! !
  637. !HLListWidget methodsFor: 'defaults'!
  638. defaultItems
  639. ^ #()
  640. ! !
  641. !HLListWidget methodsFor: 'events'!
  642. setupKeyBindings
  643. (HLRepeatedKeyDownHandler on: self)
  644. whileKeyDown: 38 do: [ self activatePreviousListItem ];
  645. whileKeyDown: 40 do: [ self activateNextListItem ];
  646. rebindKeys
  647. ! !
  648. !HLListWidget methodsFor: 'rendering'!
  649. renderButtonsOn: html
  650. !
  651. renderContentOn: html
  652. html ul
  653. class: 'nav nav-pills nav-stacked';
  654. with: [ self renderListOn: html ].
  655. html div class: 'pane_actions form-actions'; with: [
  656. self renderButtonsOn: html ].
  657. self setupKeyBindings
  658. !
  659. renderItem: anObject on: html
  660. | li |
  661. li := html li.
  662. li asJQuery data: 'item' put: anObject.
  663. li
  664. class: (self listCssClassForItem: anObject);
  665. with: [
  666. html a
  667. with: [
  668. (html tag: 'i') class: (self cssClassForItem: anObject).
  669. self renderItemLabel: anObject on: html ];
  670. onClick: [
  671. self activateListItem: li asJQuery ] ]
  672. !
  673. renderItemLabel: anObject on: html
  674. html with: anObject asString
  675. !
  676. renderListOn: html
  677. self items do: [ :each |
  678. self renderItem: each on: html ]
  679. ! !
  680. HLListWidget subclass: #HLNavigationListWidget
  681. instanceVariableNames: 'previous next'
  682. package: 'Helios-Core'!
  683. !HLNavigationListWidget methodsFor: 'accessing'!
  684. next
  685. ^ next
  686. !
  687. next: aWidget
  688. next := aWidget.
  689. aWidget previous = self ifFalse: [ aWidget previous: self ]
  690. !
  691. previous
  692. ^ previous
  693. !
  694. previous: aWidget
  695. previous := aWidget.
  696. aWidget next = self ifFalse: [ aWidget next: self ]
  697. ! !
  698. !HLNavigationListWidget methodsFor: 'actions'!
  699. activateItem: anObject
  700. self activateListItem: ((wrapper asJQuery find: 'li[list-data="', (self items indexOf: anObject ifAbsent: [ ^self ]) asString, '"]') eq: 0)
  701. !
  702. nextFocus
  703. self next ifNotNil: [ self next focus ]
  704. !
  705. previousFocus
  706. self previous ifNotNil: [ self previous focus ]
  707. ! !
  708. !HLNavigationListWidget methodsFor: 'events'!
  709. setupKeyBindings
  710. super setupKeyBindings.
  711. self wrapper asJQuery keydown: [ :e |
  712. e which = 39 ifTrue: [
  713. self nextFocus ].
  714. e which = 37 ifTrue: [
  715. self previousFocus ] ]
  716. ! !
  717. HLNavigationListWidget subclass: #HLToolListWidget
  718. instanceVariableNames: 'model'
  719. package: 'Helios-Core'!
  720. !HLToolListWidget methodsFor: 'accessing'!
  721. commandCategory
  722. ^ self label
  723. !
  724. label
  725. ^ 'List'
  726. !
  727. menuCommands
  728. "Answer a collection of commands to be put in the cog menu"
  729. ^ ((HLToolCommand concreteClasses
  730. select: [ :each | each isValidFor: self model ])
  731. collect: [ :each | each for: self model ])
  732. select: [ :each |
  733. each category = self commandCategory and: [
  734. each isAction and: [ each isActive ] ] ]
  735. !
  736. model
  737. ^ model
  738. !
  739. model: aBrowserModel
  740. model := aBrowserModel.
  741. self
  742. observeSystem;
  743. observeModel
  744. !
  745. selectedItem: anItem
  746. "Selection changed, update the cog menu"
  747. super selectedItem: anItem.
  748. self updateMenu
  749. ! !
  750. !HLToolListWidget methodsFor: 'actions'!
  751. activateListItem: anItem
  752. self model withChangesDo: [ super activateListItem: anItem ]
  753. !
  754. activateNextListItem
  755. self model withChangesDo: [ super activateNextListItem ]
  756. !
  757. activatePreviousListItem
  758. self model withChangesDo: [ super activatePreviousListItem ]
  759. !
  760. observeModel
  761. !
  762. observeSystem
  763. !
  764. unregister
  765. super unregister.
  766. self model announcer unsubscribe: self.
  767. self model systemAnnouncer unsubscribe: self
  768. ! !
  769. !HLToolListWidget methodsFor: 'rendering'!
  770. renderContentOn: html
  771. self renderHeadOn: html.
  772. super renderContentOn: html
  773. !
  774. renderHeadOn: html
  775. html div
  776. class: 'list-label';
  777. with: [
  778. html with: self label.
  779. self renderMenuOn: html ]
  780. !
  781. renderMenuOn: html
  782. | commands |
  783. commands := self menuCommands.
  784. commands isEmpty ifTrue: [ ^ self ].
  785. html div
  786. class: 'btn-group cog';
  787. with: [
  788. html a
  789. class: 'btn dropdown-toggle';
  790. at: 'data-toggle' put: 'dropdown';
  791. with: [ (html tag: 'i') class: 'icon-cog' ].
  792. html ul
  793. class: 'dropdown-menu pull-right';
  794. with: [
  795. self menuCommands do: [ :each |
  796. html li with: [ html a
  797. with: each menuLabel;
  798. onClick: [ self execute: each ] ] ] ] ]
  799. ! !
  800. !HLToolListWidget methodsFor: 'updating'!
  801. updateMenu
  802. (self wrapper asJQuery find: '.cog') remove.
  803. [ :html | self renderMenuOn: html ]
  804. appendToJQuery: (self wrapper asJQuery find: '.list-label')
  805. ! !
  806. !HLToolListWidget class methodsFor: 'instance creation'!
  807. on: aModel
  808. ^ self new
  809. model: aModel;
  810. yourself
  811. ! !
  812. HLListWidget subclass: #HLTabListWidget
  813. instanceVariableNames: 'callback'
  814. package: 'Helios-Core'!
  815. !HLTabListWidget commentStamp!
  816. I am a widget used to display a list of helios tabs.
  817. When a tab is selected, `callback` is evaluated with the selected tab as argument.!
  818. !HLTabListWidget methodsFor: 'accessing'!
  819. callback
  820. ^ callback ifNil: [ [] ]
  821. !
  822. callback: aBlock
  823. callback := aBlock
  824. ! !
  825. !HLTabListWidget methodsFor: 'actions'!
  826. selectItem: aTab
  827. super selectItem: aTab.
  828. self callback value: aTab
  829. ! !
  830. !HLTabListWidget methodsFor: 'rendering'!
  831. renderItemLabel: aTab on: html
  832. html span
  833. class: aTab cssClass;
  834. with: aTab label
  835. ! !
  836. HLWidget subclass: #HLManager
  837. instanceVariableNames: 'tabs activeTab environment history'
  838. package: 'Helios-Core'!
  839. !HLManager methodsFor: 'accessing'!
  840. activeTab
  841. ^ activeTab
  842. !
  843. environment
  844. "The default environment used by all Helios objects"
  845. ^ environment ifNil: [ environment := self defaultEnvironment ]
  846. !
  847. environment: anEnvironment
  848. environment := anEnvironment
  849. !
  850. history
  851. ^ history ifNil: [ history := OrderedCollection new ]
  852. !
  853. history: aCollection
  854. history := aCollection
  855. !
  856. keyBinder
  857. ^ HLKeyBinder current
  858. !
  859. tabs
  860. ^ tabs ifNil: [ tabs := OrderedCollection new ]
  861. ! !
  862. !HLManager methodsFor: 'actions'!
  863. activate: aTab
  864. self keyBinder flushBindings.
  865. aTab registerBindings.
  866. activeTab := aTab.
  867. self
  868. refresh;
  869. addToHistory: aTab;
  870. show: aTab
  871. !
  872. addTab: aTab
  873. self tabs add: aTab.
  874. self activate: aTab
  875. !
  876. addToHistory: aTab
  877. self removeFromHistory: aTab.
  878. self history add: aTab
  879. !
  880. confirm: aString ifFalse: aBlock
  881. HLConfirmationWidget new
  882. confirmationString: aString;
  883. cancelBlock: aBlock;
  884. show
  885. !
  886. confirm: aString ifTrue: aBlock
  887. HLConfirmationWidget new
  888. confirmationString: aString;
  889. actionBlock: aBlock;
  890. show
  891. !
  892. registerErrorHandler: anErrorHandler
  893. self environment registerErrorHandler: anErrorHandler
  894. !
  895. registerInspector: anInspector
  896. self environment registerInspector: anInspector
  897. !
  898. registerProgressHandler: aProgressHandler
  899. self environment registerProgressHandler: aProgressHandler
  900. !
  901. removeActiveTab
  902. self removeTab: self activeTab
  903. !
  904. removeFromHistory: aTab
  905. self history: (self history reject: [ :each | each == aTab ])
  906. !
  907. removeTab: aTab
  908. (self tabs includes: aTab) ifFalse: [ ^ self ].
  909. self removeFromHistory: aTab.
  910. self tabs remove: aTab.
  911. self keyBinder flushBindings.
  912. aTab remove.
  913. self refresh.
  914. self history ifNotEmpty: [
  915. self history last activate ]
  916. !
  917. request: aString do: aBlock
  918. self
  919. request: aString
  920. value: ''
  921. do: aBlock
  922. !
  923. request: aString value: valueString do: aBlock
  924. HLRequestWidget new
  925. confirmationString: aString;
  926. actionBlock: aBlock;
  927. value: valueString;
  928. show
  929. ! !
  930. !HLManager methodsFor: 'defaults'!
  931. defaultEnvironment
  932. "If helios is loaded from within a frame, answer the parent window environment"
  933. | parent parentSmalltalk |
  934. parent := window opener ifNil: [ window parent ].
  935. parent ifNil: [ ^ Environment new ].
  936. parentSmalltalk := (parent at: 'requirejs') value: 'amber_vm/smalltalk'.
  937. parentSmalltalk ifNil: [ ^ Environment new ].
  938. ^ (parentSmalltalk at: 'Environment') new
  939. ! !
  940. !HLManager methodsFor: 'initialization'!
  941. initialize
  942. super initialize.
  943. HLErrorHandler register.
  944. HLProgressHandler register.
  945. self registerInspector: HLInspector.
  946. self registerErrorHandler: ErrorHandler current.
  947. self registerProgressHandler: ProgressHandler current.
  948. self keyBinder setupEvents
  949. ! !
  950. !HLManager methodsFor: 'rendering'!
  951. refresh
  952. '.navbar' asJQuery remove.
  953. self appendToJQuery: 'body' asJQuery
  954. !
  955. renderAddOn: html
  956. html li
  957. class: 'dropdown';
  958. with: [
  959. html a
  960. class: 'dropdown-toggle';
  961. at: 'data-toggle' put: 'dropdown';
  962. with: [
  963. html with: 'Open...'.
  964. (html tag: 'b') class: 'caret' ].
  965. html ul
  966. class: 'dropdown-menu';
  967. with: [
  968. ((HLWidget withAllSubclasses
  969. select: [ :each | each canBeOpenAsTab ])
  970. sorted: [ :a :b | a tabPriority < b tabPriority ])
  971. do: [ :each |
  972. html li with: [
  973. html a
  974. with: each tabLabel;
  975. onClick: [ each openAsTab ] ] ] ] ]
  976. !
  977. renderContentOn: html
  978. html div
  979. class: 'navbar navbar-fixed-top';
  980. with: [ html div
  981. class: 'navbar-inner';
  982. with: [ self renderTabsOn: html ] ]
  983. !
  984. renderTabsOn: html
  985. html ul
  986. class: 'nav';
  987. with: [
  988. self tabs do: [ :each |
  989. html li
  990. class: (each isActive ifTrue: [ 'active' ] ifFalse: [ 'inactive' ]);
  991. with: [
  992. html a
  993. with: [
  994. ((html tag: 'i') class: 'close')
  995. onClick: [ self removeTab: each ].
  996. html span
  997. class: each cssClass;
  998. with: each displayLabel ];
  999. onClick: [ each activate ] ] ].
  1000. self renderAddOn: html ]
  1001. !
  1002. show: aTab
  1003. self tabs do: [ :each | each hide ].
  1004. aTab show; focus
  1005. ! !
  1006. HLManager class instanceVariableNames: 'current'!
  1007. !HLManager class methodsFor: 'accessing'!
  1008. current
  1009. ^ current ifNil: [ current := self basicNew initialize ]
  1010. ! !
  1011. !HLManager class methodsFor: 'initialization'!
  1012. initialize
  1013. self current appendToJQuery: 'body' asJQuery
  1014. ! !
  1015. !HLManager class methodsFor: 'instance creation'!
  1016. new
  1017. "Use current instead"
  1018. self shouldNotImplement
  1019. ! !
  1020. HLWidget subclass: #HLModalWidget
  1021. instanceVariableNames: ''
  1022. package: 'Helios-Core'!
  1023. !HLModalWidget commentStamp!
  1024. I implement an abstract modal widget.!
  1025. !HLModalWidget methodsFor: 'accessing'!
  1026. cssClass
  1027. ^ ''
  1028. ! !
  1029. !HLModalWidget methodsFor: 'actions'!
  1030. cancel
  1031. self remove
  1032. !
  1033. confirm
  1034. "Override in subclasses"
  1035. self remove
  1036. !
  1037. remove
  1038. '.dialog' asJQuery removeClass: 'active'.
  1039. [
  1040. '#overlay' asJQuery remove.
  1041. '.dialog' asJQuery remove
  1042. ] valueWithTimeout: 300
  1043. !
  1044. show
  1045. self appendToJQuery: 'body' asJQuery
  1046. ! !
  1047. !HLModalWidget methodsFor: 'rendering'!
  1048. hasButtons
  1049. ^ true
  1050. !
  1051. renderButtonsOn: html
  1052. | confirmButton |
  1053. html div
  1054. class: 'buttons';
  1055. with: [
  1056. html button
  1057. class: 'button';
  1058. with: 'Cancel';
  1059. onClick: [ self cancel ].
  1060. confirmButton := html button
  1061. class: 'button default';
  1062. with: 'Confirm';
  1063. onClick: [ self confirm ] ].
  1064. confirmButton asJQuery focus
  1065. !
  1066. renderContentOn: html
  1067. | confirmButton |
  1068. html div id: 'overlay'.
  1069. html div
  1070. class: 'dialog ', self cssClass;
  1071. with: [
  1072. self renderMainOn: html.
  1073. self hasButtons ifTrue: [
  1074. self renderButtonsOn: html ] ].
  1075. '.dialog' asJQuery addClass: 'active'.
  1076. self setupKeyBindings
  1077. !
  1078. renderMainOn: html
  1079. !
  1080. setupKeyBindings
  1081. '.dialog' asJQuery keyup: [ :e |
  1082. e keyCode = String esc asciiValue ifTrue: [ self cancel ] ]
  1083. ! !
  1084. HLModalWidget subclass: #HLConfirmationWidget
  1085. instanceVariableNames: 'confirmationString actionBlock cancelBlock'
  1086. package: 'Helios-Core'!
  1087. !HLConfirmationWidget commentStamp!
  1088. I display confirmation messages.
  1089. Instead of creating an instance directly, use `HLWidget >> #confirm:ifTrue:`.!
  1090. !HLConfirmationWidget methodsFor: 'accessing'!
  1091. actionBlock
  1092. ^ actionBlock ifNil: [ [] ]
  1093. !
  1094. actionBlock: aBlock
  1095. actionBlock := aBlock
  1096. !
  1097. cancelBlock
  1098. ^ cancelBlock ifNil: [ [] ]
  1099. !
  1100. cancelBlock: aBlock
  1101. cancelBlock := aBlock
  1102. !
  1103. confirmationString
  1104. ^ confirmationString ifNil: [ 'Confirm' ]
  1105. !
  1106. confirmationString: aString
  1107. confirmationString := aString
  1108. ! !
  1109. !HLConfirmationWidget methodsFor: 'actions'!
  1110. cancel
  1111. self cancelBlock value.
  1112. super cancel
  1113. !
  1114. confirm
  1115. super confirm.
  1116. self actionBlock value
  1117. ! !
  1118. !HLConfirmationWidget methodsFor: 'rendering'!
  1119. renderMainOn: html
  1120. html span with: self confirmationString
  1121. ! !
  1122. HLConfirmationWidget subclass: #HLRequestWidget
  1123. instanceVariableNames: 'input value'
  1124. package: 'Helios-Core'!
  1125. !HLRequestWidget commentStamp!
  1126. I display a modal window requesting user input.
  1127. Instead of creating instances manually, use `HLWidget >> #request:do:` and `#request:value:do:`.!
  1128. !HLRequestWidget methodsFor: 'accessing'!
  1129. cssClass
  1130. ^ 'large'
  1131. !
  1132. value
  1133. ^ value ifNil: [ '' ]
  1134. !
  1135. value: aString
  1136. value := aString
  1137. ! !
  1138. !HLRequestWidget methodsFor: 'actions'!
  1139. confirm
  1140. super confirm.
  1141. self actionBlock value: input asJQuery val
  1142. ! !
  1143. !HLRequestWidget methodsFor: 'rendering'!
  1144. renderMainOn: html
  1145. super renderMainOn: html.
  1146. input := html textarea.
  1147. input asJQuery val: self value
  1148. ! !
  1149. HLModalWidget subclass: #HLProgressWidget
  1150. instanceVariableNames: 'progressBars visible'
  1151. package: 'Helios-Core'!
  1152. !HLProgressWidget commentStamp!
  1153. I am a widget used to display progress modal dialogs.
  1154. My default instance is accessed with `HLProgressWidget class >> #default`.
  1155. See `HLProgressHandler` for usage.!
  1156. !HLProgressWidget methodsFor: 'accessing'!
  1157. progressBars
  1158. ^ progressBars ifNil: [ progressBars := OrderedCollection new ]
  1159. ! !
  1160. !HLProgressWidget methodsFor: 'actions'!
  1161. addProgressBar: aProgressBar
  1162. self show.
  1163. self progressBars add: aProgressBar.
  1164. aProgressBar appendToJQuery: (self wrapper asJQuery find: '.dialog')
  1165. !
  1166. do: aBlock on: aCollection displaying: aString
  1167. | progressBar |
  1168. progressBar := HLProgressBarWidget new
  1169. parent: self;
  1170. label: aString;
  1171. workBlock: aBlock;
  1172. collection: aCollection;
  1173. yourself.
  1174. self addProgressBar: progressBar.
  1175. progressBar start
  1176. !
  1177. flush
  1178. self progressBars do: [ :each |
  1179. self removeProgressBar: each ]
  1180. !
  1181. remove
  1182. self isVisible ifTrue: [
  1183. visible := false.
  1184. super remove ]
  1185. !
  1186. removeProgressBar: aProgressBar
  1187. self progressBars remove: aProgressBar ifAbsent: [].
  1188. aProgressBar wrapper asJQuery remove.
  1189. self progressBars ifEmpty: [ self remove ]
  1190. !
  1191. show
  1192. self isVisible ifFalse: [
  1193. visible := true.
  1194. super show ]
  1195. ! !
  1196. !HLProgressWidget methodsFor: 'rendering'!
  1197. renderMainOn: html
  1198. self progressBars do: [ :each |
  1199. html with: each ]
  1200. ! !
  1201. !HLProgressWidget methodsFor: 'testing'!
  1202. hasButtons
  1203. ^ false
  1204. !
  1205. isVisible
  1206. ^ visible ifNil: [ false ]
  1207. ! !
  1208. HLProgressWidget class instanceVariableNames: 'default'!
  1209. !HLProgressWidget class methodsFor: 'accessing'!
  1210. default
  1211. ^ default ifNil: [ default := self new ]
  1212. ! !
  1213. HLModalWidget subclass: #HLTabSelectionWidget
  1214. instanceVariableNames: 'tabs tabList selectedTab selectCallback cancelCallback confirmCallback'
  1215. package: 'Helios-Core'!
  1216. !HLTabSelectionWidget commentStamp!
  1217. I am a modal window used to select or create tabs.!
  1218. !HLTabSelectionWidget methodsFor: 'accessing'!
  1219. cancelCallback
  1220. ^ cancelCallback ifNil: [ [] ]
  1221. !
  1222. cancelCallback: aBlock
  1223. cancelCallback := aBlock
  1224. !
  1225. confirmCallback
  1226. ^ confirmCallback ifNil: [ [] ]
  1227. !
  1228. confirmCallback: aBlock
  1229. confirmCallback := aBlock
  1230. !
  1231. selectCallback
  1232. ^ selectCallback ifNil: [ [] ]
  1233. !
  1234. selectCallback: aBlock
  1235. selectCallback := aBlock
  1236. !
  1237. selectedTab
  1238. ^ selectedTab
  1239. !
  1240. selectedTab: aTab
  1241. selectedTab := aTab
  1242. !
  1243. tabs
  1244. ^ tabs ifNil: [ #() ]
  1245. !
  1246. tabs: aCollection
  1247. tabs := aCollection
  1248. ! !
  1249. !HLTabSelectionWidget methodsFor: 'actions'!
  1250. cancel
  1251. super cancel.
  1252. self cancelCallback value
  1253. !
  1254. confirm
  1255. super confirm.
  1256. self confirmCallback value: self selectedTab
  1257. !
  1258. selectTab: aTab
  1259. self selectedTab: aTab.
  1260. self selectCallback value: aTab
  1261. !
  1262. setupKeyBindings
  1263. super setupKeyBindings.
  1264. '.dialog' asJQuery keyup: [ :e |
  1265. e keyCode = String cr asciiValue ifTrue: [ self confirm ] ]
  1266. ! !
  1267. !HLTabSelectionWidget methodsFor: 'rendering'!
  1268. renderContentOn: html
  1269. super renderContentOn: html.
  1270. self tabList focus
  1271. !
  1272. renderMainOn: html
  1273. html div
  1274. class: 'title';
  1275. with: 'Tab selection'.
  1276. html with: self tabList
  1277. !
  1278. renderTab: aTab on: html
  1279. html
  1280. span
  1281. class: aTab cssClass;
  1282. with: aTab label
  1283. !
  1284. renderTabsOn: html
  1285. self tabs do: [ :each |
  1286. html li with: [
  1287. html a
  1288. with: [
  1289. self renderTab: each on: html ];
  1290. onClick: [ self selectTab: each ] ] ]
  1291. !
  1292. tabList
  1293. tabList ifNil: [
  1294. tabList := HLTabListWidget new.
  1295. tabList
  1296. callback: [ :tab | self selectTab: tab. tabList focus ];
  1297. selectedItem: self selectedTab;
  1298. items: self tabs ].
  1299. ^ tabList
  1300. ! !
  1301. HLWidget subclass: #HLProgressBarWidget
  1302. instanceVariableNames: 'label parent workBlock collection bar'
  1303. package: 'Helios-Core'!
  1304. !HLProgressBarWidget commentStamp!
  1305. I am a widget used to display a progress bar while iterating over a collection.!
  1306. !HLProgressBarWidget methodsFor: 'accessing'!
  1307. collection
  1308. ^ collection
  1309. !
  1310. collection: aCollection
  1311. collection := aCollection
  1312. !
  1313. label
  1314. ^ label
  1315. !
  1316. label: aString
  1317. label := aString
  1318. !
  1319. parent
  1320. ^ parent
  1321. !
  1322. parent: aProgress
  1323. parent := aProgress
  1324. !
  1325. workBlock
  1326. ^ workBlock
  1327. !
  1328. workBlock: aBlock
  1329. workBlock := aBlock
  1330. ! !
  1331. !HLProgressBarWidget methodsFor: 'actions'!
  1332. evaluateAt: anInteger
  1333. self updateProgress: (anInteger / self collection size) * 100.
  1334. anInteger <= self collection size
  1335. ifTrue: [
  1336. [
  1337. self workBlock value: (self collection at: anInteger).
  1338. self evaluateAt: anInteger + 1 ] valueWithTimeout: 10 ]
  1339. ifFalse: [ [ self remove ] valueWithTimeout: 500 ]
  1340. !
  1341. remove
  1342. self parent removeProgressBar: self
  1343. !
  1344. start
  1345. "Make sure the UI has some time to update itself between each iteration"
  1346. self evaluateAt: 1
  1347. !
  1348. updateProgress: anInteger
  1349. bar asJQuery css: 'width' put: anInteger asString, '%'
  1350. ! !
  1351. !HLProgressBarWidget methodsFor: 'rendering'!
  1352. renderContentOn: html
  1353. html span with: self label.
  1354. html div
  1355. class: 'progress';
  1356. with: [
  1357. bar := html div
  1358. class: 'bar';
  1359. style: 'width: 0%' ]
  1360. ! !
  1361. HLProgressBarWidget class instanceVariableNames: 'default'!
  1362. !HLProgressBarWidget class methodsFor: 'accessing'!
  1363. default
  1364. ^ default ifNil: [ default := self new ]
  1365. ! !
  1366. HLWidget subclass: #HLSUnit
  1367. instanceVariableNames: ''
  1368. package: 'Helios-Core'!
  1369. !HLSUnit class methodsFor: 'accessing'!
  1370. tabClass
  1371. ^ 'sunit'
  1372. !
  1373. tabLabel
  1374. ^ 'SUnit'
  1375. !
  1376. tabPriority
  1377. ^ 1000
  1378. ! !
  1379. !HLSUnit class methodsFor: 'testing'!
  1380. canBeOpenAsTab
  1381. ^ true
  1382. ! !