Helios-Core.st 37 KB

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