Helios-Core.st 35 KB

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