Helios-Core.st 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948
  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. cssClass
  482. ^ 'hl_widget'
  483. !
  484. manager
  485. ^ HLManager current
  486. !
  487. tabClass
  488. ^ self class tabClass
  489. !
  490. wrapper
  491. ^ wrapper
  492. ! !
  493. !HLWidget methodsFor: 'actions'!
  494. confirm: aString ifTrue: aBlock
  495. self manager confirm: aString ifTrue: aBlock
  496. !
  497. execute: aCommand
  498. HLManager current keyBinder
  499. activate;
  500. applyBinding: aCommand asBinding
  501. !
  502. openAsTab
  503. HLManager current addTab: (HLTabWidget on: self labelled: self class tabLabel)
  504. !
  505. request: aString do: aBlock
  506. self manager request: aString do: aBlock
  507. !
  508. request: aString value: valueString do: aBlock
  509. self manager
  510. request: aString
  511. value: valueString
  512. do: aBlock
  513. !
  514. unregister
  515. "This method is called whenever the receiver is closed (as a tab).
  516. Widgets subscribing to announcements should unregister there"
  517. ! !
  518. !HLWidget methodsFor: 'keybindings'!
  519. bindKeyDown: keyDownBlock keyUp: keyUpBlock
  520. self wrapper asJQuery
  521. keydown: keyDownBlock;
  522. keyup: keyUpBlock
  523. !
  524. registerBindings
  525. self registerBindingsOn: self manager keyBinder bindings
  526. !
  527. registerBindingsOn: aBindingGroup
  528. !
  529. unbindKeyDownKeyUp
  530. self wrapper asJQuery
  531. unbind: 'keydown';
  532. unbind: 'keyup'
  533. ! !
  534. !HLWidget methodsFor: 'rendering'!
  535. renderContentOn: html
  536. !
  537. renderOn: html
  538. wrapper := html div
  539. class: self cssClass;
  540. yourself.
  541. [ :renderer | self renderContentOn: renderer ] appendToJQuery: wrapper asJQuery
  542. ! !
  543. !HLWidget methodsFor: 'testing'!
  544. canHaveFocus
  545. ^ false
  546. ! !
  547. !HLWidget methodsFor: 'updating'!
  548. refresh
  549. self wrapper ifNil: [ ^ self ].
  550. self wrapper asJQuery empty.
  551. [ :html | self renderContentOn: html ] appendToJQuery: self wrapper asJQuery
  552. ! !
  553. !HLWidget class methodsFor: 'accessing'!
  554. openAsTab
  555. | instance |
  556. instance := self new.
  557. HLManager current addTab: (HLTabWidget
  558. on: instance
  559. labelled: self tabLabel).
  560. ^ instance
  561. !
  562. tabClass
  563. ^ ''
  564. !
  565. tabLabel
  566. ^ 'Tab'
  567. !
  568. tabPriority
  569. ^ 500
  570. ! !
  571. !HLWidget class methodsFor: 'testing'!
  572. canBeOpenAsTab
  573. ^ false
  574. ! !
  575. HLWidget subclass: #HLFocusableWidget
  576. instanceVariableNames: ''
  577. package: 'Helios-Core'!
  578. !HLFocusableWidget commentStamp!
  579. I am a widget that can be focused.
  580. ## API
  581. Instead of overriding `#renderOn:` as with other `Widget` subclasses, my subclasses should override `#renderContentOn:`.
  582. To bring the focus to the widget, use the `#focus` method.!
  583. !HLFocusableWidget methodsFor: 'accessing'!
  584. focusClass
  585. ^ 'focused'
  586. ! !
  587. !HLFocusableWidget methodsFor: 'events'!
  588. blur
  589. self wrapper asJQuery blur
  590. !
  591. focus
  592. self wrapper asJQuery focus
  593. ! !
  594. !HLFocusableWidget methodsFor: 'rendering'!
  595. renderContentOn: html
  596. !
  597. renderOn: html
  598. wrapper := html div
  599. class: self cssClass;
  600. yourself.
  601. wrapper with: [ self renderContentOn: html ].
  602. wrapper
  603. at: 'tabindex' put: '0';
  604. onBlur: [ self wrapper asJQuery removeClass: self focusClass ];
  605. onFocus: [ self wrapper asJQuery addClass: self focusClass ]
  606. ! !
  607. !HLFocusableWidget methodsFor: 'testing'!
  608. canHaveFocus
  609. ^ true
  610. !
  611. hasFocus
  612. ^ self wrapper notNil and: [ self wrapper asJQuery hasClass: self focusClass ]
  613. ! !
  614. HLFocusableWidget subclass: #HLListWidget
  615. instanceVariableNames: 'items selectedItem'
  616. package: 'Helios-Core'!
  617. !HLListWidget methodsFor: 'accessing'!
  618. cssClassForItem: anObject
  619. ^ ''
  620. !
  621. findListItemFor: anObject
  622. ^ (((wrapper asJQuery find: 'li')
  623. filter: [ :thisArg :otherArg | (thisArg asJQuery data: 'item') = anObject ] currySelf) eq: 0)
  624. !
  625. items
  626. ^ items ifNil: [ items := self defaultItems ]
  627. !
  628. items: aCollection
  629. items := aCollection
  630. !
  631. listCssClassForItem: anObject
  632. ^ self selectedItem = anObject
  633. ifTrue: [ 'active' ]
  634. ifFalse: [ 'inactive' ]
  635. !
  636. positionOf: aListItem
  637. <
  638. return aListItem.parent().children().get().indexOf(aListItem.get(0)) + 1
  639. >
  640. !
  641. selectedItem
  642. ^ selectedItem
  643. !
  644. selectedItem: anObject
  645. selectedItem := anObject
  646. ! !
  647. !HLListWidget methodsFor: 'actions'!
  648. activateFirstListItem
  649. self activateListItem: ((wrapper asJQuery find: 'li.inactive') eq: 0)
  650. !
  651. activateItem: anObject
  652. self activateListItem: (self findListItemFor: anObject)
  653. !
  654. activateListItem: aListItem
  655. | item |
  656. (aListItem get: 0) ifNil: [ ^ self ].
  657. aListItem parent children removeClass: 'active'.
  658. aListItem addClass: 'active'.
  659. self ensureVisible: aListItem.
  660. "Activate the corresponding item"
  661. item := aListItem data: 'item'.
  662. self selectedItem == item ifFalse: [
  663. self selectItem: item ]
  664. !
  665. activateNextListItem
  666. self activateListItem: (self wrapper asJQuery find: 'li.active') next.
  667. "select the first item if none is selected"
  668. (self wrapper asJQuery find: ' .active') get ifEmpty: [
  669. self activateFirstListItem ]
  670. !
  671. activatePreviousListItem
  672. self activateListItem: (self wrapper asJQuery find: 'li.active') prev
  673. !
  674. ensureVisible: aListItem
  675. "Move the scrollbar to show the active element"
  676. | parent position |
  677. (aListItem get: 0) ifNil: [ ^ self ].
  678. position := self positionOf: aListItem.
  679. parent := aListItem parent.
  680. aListItem position top < 0 ifTrue: [
  681. (parent get: 0) scrollTop: ((parent get: 0) scrollTop + aListItem position top - 10) ].
  682. aListItem position top + aListItem height > parent height ifTrue: [
  683. (parent get: 0) scrollTop: ((parent get: 0) scrollTop + aListItem height - (parent height - aListItem position top)) +10 ]
  684. !
  685. focus
  686. super focus.
  687. self items isEmpty ifFalse: [
  688. self selectedItem ifNil: [ self activateFirstListItem ] ]
  689. !
  690. reactivateListItem: aListItem
  691. self activateListItem: aListItem.
  692. self reselectItem: self selectedItem
  693. !
  694. refresh
  695. super refresh.
  696. self selectedItem ifNotNil: [self ensureVisible: (self findListItemFor: self selectedItem)].
  697. !
  698. reselectItem: anObject
  699. !
  700. selectItem: anObject
  701. self selectedItem: anObject
  702. ! !
  703. !HLListWidget methodsFor: 'defaults'!
  704. defaultItems
  705. ^ #()
  706. ! !
  707. !HLListWidget methodsFor: 'events'!
  708. setupKeyBindings
  709. (HLRepeatedKeyDownHandler on: self)
  710. whileKeyDown: 38 do: [ self activatePreviousListItem ];
  711. whileKeyDown: 40 do: [ self activateNextListItem ];
  712. rebindKeys.
  713. self wrapper asJQuery keydown: [ :e |
  714. e which = 13 ifTrue: [
  715. self reselectItem: self selectedItem ] ]
  716. ! !
  717. !HLListWidget methodsFor: 'rendering'!
  718. renderButtonsOn: html
  719. !
  720. renderContentOn: html
  721. html ul
  722. class: 'nav nav-pills nav-stacked';
  723. with: [ self renderListOn: html ].
  724. html div class: 'pane_actions form-actions'; with: [
  725. self renderButtonsOn: html ].
  726. self setupKeyBindings
  727. !
  728. renderItem: anObject on: html
  729. | li |
  730. li := html li.
  731. li asJQuery data: 'item' put: anObject.
  732. li
  733. class: (self listCssClassForItem: anObject);
  734. with: [
  735. html a
  736. with: [
  737. (html tag: 'i') class: (self cssClassForItem: anObject).
  738. self renderItemLabel: anObject on: html ];
  739. onClick: [
  740. self reactivateListItem: li asJQuery ] ]
  741. !
  742. renderItemLabel: anObject on: html
  743. html with: anObject asString
  744. !
  745. renderListOn: html
  746. self items do: [ :each |
  747. self renderItem: each on: html ]
  748. ! !
  749. HLListWidget subclass: #HLNavigationListWidget
  750. instanceVariableNames: 'previous next'
  751. package: 'Helios-Core'!
  752. !HLNavigationListWidget methodsFor: 'accessing'!
  753. next
  754. ^ next
  755. !
  756. next: aWidget
  757. next := aWidget.
  758. aWidget previous = self ifFalse: [ aWidget previous: self ]
  759. !
  760. previous
  761. ^ previous
  762. !
  763. previous: aWidget
  764. previous := aWidget.
  765. aWidget next = self ifFalse: [ aWidget next: self ]
  766. ! !
  767. !HLNavigationListWidget methodsFor: 'actions'!
  768. nextFocus
  769. self next ifNotNil: [ self next focus ]
  770. !
  771. previousFocus
  772. self previous ifNotNil: [ self previous focus ]
  773. ! !
  774. !HLNavigationListWidget methodsFor: 'events'!
  775. setupKeyBindings
  776. super setupKeyBindings.
  777. self wrapper asJQuery keydown: [ :e |
  778. e which = 39 ifTrue: [
  779. self nextFocus ].
  780. e which = 37 ifTrue: [
  781. self previousFocus ] ]
  782. ! !
  783. HLNavigationListWidget subclass: #HLToolListWidget
  784. instanceVariableNames: 'model'
  785. package: 'Helios-Core'!
  786. !HLToolListWidget methodsFor: 'accessing'!
  787. commandCategory
  788. ^ self label
  789. !
  790. label
  791. ^ 'List'
  792. !
  793. menuCommands
  794. "Answer a collection of commands to be put in the cog menu"
  795. ^ ((HLToolCommand concreteClasses
  796. select: [ :each | each isValidFor: self model ])
  797. collect: [ :each | each for: self model ])
  798. select: [ :each |
  799. each category = self commandCategory and: [
  800. each isAction and: [ each isActive ] ] ]
  801. !
  802. model
  803. ^ model
  804. !
  805. model: aBrowserModel
  806. model := aBrowserModel.
  807. self
  808. observeSystem;
  809. observeModel
  810. !
  811. selectedItem: anItem
  812. "Selection changed, update the cog menu"
  813. super selectedItem: anItem.
  814. self updateMenu
  815. ! !
  816. !HLToolListWidget methodsFor: 'actions'!
  817. activateListItem: anItem
  818. self model withChangesDo: [ super activateListItem: anItem ]
  819. !
  820. activateNextListItem
  821. self model withChangesDo: [ super activateNextListItem ]
  822. !
  823. activatePreviousListItem
  824. self model withChangesDo: [ super activatePreviousListItem ]
  825. !
  826. observeModel
  827. !
  828. observeSystem
  829. !
  830. unregister
  831. super unregister.
  832. self model announcer unsubscribe: self.
  833. self model systemAnnouncer unsubscribe: self
  834. ! !
  835. !HLToolListWidget methodsFor: 'rendering'!
  836. renderContentOn: html
  837. self renderHeadOn: html.
  838. super renderContentOn: html
  839. !
  840. renderHeadOn: html
  841. html div
  842. class: 'list-label';
  843. with: [
  844. html with: self label.
  845. self renderMenuOn: html ]
  846. !
  847. renderMenuOn: html
  848. | commands |
  849. commands := self menuCommands.
  850. commands isEmpty ifTrue: [ ^ self ].
  851. html div
  852. class: 'btn-group cog';
  853. with: [
  854. html a
  855. class: 'btn dropdown-toggle';
  856. at: 'data-toggle' put: 'dropdown';
  857. with: [ (html tag: 'i') class: 'icon-chevron-down' ].
  858. html ul
  859. class: 'dropdown-menu pull-right';
  860. with: [
  861. self menuCommands do: [ :each |
  862. html li with: [ html a
  863. with: each menuLabel;
  864. onClick: [ self execute: each ] ] ] ] ]
  865. ! !
  866. !HLToolListWidget methodsFor: 'updating'!
  867. updateMenu
  868. (self wrapper asJQuery find: '.cog') remove.
  869. [ :html | self renderMenuOn: html ]
  870. appendToJQuery: (self wrapper asJQuery find: '.list-label')
  871. ! !
  872. !HLToolListWidget class methodsFor: 'instance creation'!
  873. on: aModel
  874. ^ self new
  875. model: aModel;
  876. yourself
  877. ! !
  878. HLListWidget subclass: #HLTabListWidget
  879. instanceVariableNames: 'callback'
  880. package: 'Helios-Core'!
  881. !HLTabListWidget commentStamp!
  882. I am a widget used to display a list of helios tabs.
  883. When a tab is selected, `callback` is evaluated with the selected tab as argument.!
  884. !HLTabListWidget methodsFor: 'accessing'!
  885. callback
  886. ^ callback ifNil: [ [] ]
  887. !
  888. callback: aBlock
  889. callback := aBlock
  890. ! !
  891. !HLTabListWidget methodsFor: 'actions'!
  892. selectItem: aTab
  893. super selectItem: aTab.
  894. self callback value: aTab
  895. ! !
  896. !HLTabListWidget methodsFor: 'rendering'!
  897. renderItemLabel: aTab on: html
  898. html span
  899. class: aTab cssClass;
  900. with: aTab label
  901. ! !
  902. HLWidget subclass: #HLManager
  903. instanceVariableNames: 'tabs activeTab environment history'
  904. package: 'Helios-Core'!
  905. !HLManager methodsFor: 'accessing'!
  906. activeTab
  907. ^ activeTab
  908. !
  909. environment
  910. "The default environment used by all Helios objects"
  911. ^ environment ifNil: [ environment := self defaultEnvironment ]
  912. !
  913. environment: anEnvironment
  914. environment := anEnvironment
  915. !
  916. history
  917. ^ history ifNil: [ history := OrderedCollection new ]
  918. !
  919. history: aCollection
  920. history := aCollection
  921. !
  922. keyBinder
  923. ^ HLKeyBinder current
  924. !
  925. tabs
  926. ^ tabs ifNil: [ tabs := OrderedCollection new ]
  927. ! !
  928. !HLManager methodsFor: 'actions'!
  929. activate: aTab
  930. self keyBinder flushBindings.
  931. aTab registerBindings.
  932. activeTab := aTab.
  933. self
  934. refresh;
  935. addToHistory: aTab;
  936. show: aTab
  937. !
  938. addTab: aTab
  939. self tabs add: aTab.
  940. self activate: aTab
  941. !
  942. addToHistory: aTab
  943. self removeFromHistory: aTab.
  944. self history add: aTab
  945. !
  946. confirm: aString ifFalse: aBlock
  947. HLConfirmationWidget new
  948. confirmationString: aString;
  949. cancelBlock: aBlock;
  950. show
  951. !
  952. confirm: aString ifTrue: aBlock
  953. HLConfirmationWidget new
  954. confirmationString: aString;
  955. actionBlock: aBlock;
  956. show
  957. !
  958. removeActiveTab
  959. self removeTab: self activeTab
  960. !
  961. removeFromHistory: aTab
  962. self history: (self history reject: [ :each | each == aTab ])
  963. !
  964. removeTab: aTab
  965. (self tabs includes: aTab) ifFalse: [ ^ self ].
  966. self removeFromHistory: aTab.
  967. self tabs remove: aTab.
  968. self keyBinder flushBindings.
  969. aTab remove.
  970. self refresh.
  971. self history ifNotEmpty: [
  972. self history last activate ]
  973. !
  974. request: aString do: aBlock
  975. self
  976. request: aString
  977. value: ''
  978. do: aBlock
  979. !
  980. request: aString value: valueString do: aBlock
  981. HLRequestWidget new
  982. confirmationString: aString;
  983. actionBlock: aBlock;
  984. value: valueString;
  985. show
  986. ! !
  987. !HLManager methodsFor: 'defaults'!
  988. defaultEnvironment
  989. "If helios is loaded from within a frame, answer the parent window environment"
  990. | parent parentSmalltalkGlobals |
  991. parent := window opener ifNil: [ window parent ].
  992. parent ifNil: [ ^ Environment new ].
  993. parentSmalltalkGlobals := (parent at: 'requirejs') value: 'amber_vm/globals'.
  994. parentSmalltalkGlobals ifNil: [ ^ Environment new ].
  995. ^ (parentSmalltalkGlobals at: 'Environment') new
  996. ! !
  997. !HLManager methodsFor: 'initialization'!
  998. setup
  999. self
  1000. registerServices;
  1001. setupEvents.
  1002. self keyBinder
  1003. setupEvents;
  1004. setupHelper
  1005. ! !
  1006. !HLManager methodsFor: 'private'!
  1007. registerServices
  1008. self
  1009. registerInspector;
  1010. registerErrorHandler;
  1011. registerProgressHandler;
  1012. registerTranscript;
  1013. registrFinder
  1014. !
  1015. setupEvents
  1016. "on ctrl keydown, adds a 'navigation' css class to <body>
  1017. for the CodeMirror navigation links. See `HLCodeWidget`."
  1018. 'body' asJQuery keydown: [ :event |
  1019. event ctrlKey ifTrue: [
  1020. 'body' asJQuery addClass: 'navigation' ] ].
  1021. 'body' asJQuery keyup: [ :event |
  1022. 'body' asJQuery removeClass: 'navigation' ]
  1023. ! !
  1024. !HLManager methodsFor: 'rendering'!
  1025. refresh
  1026. '.navbar' asJQuery remove.
  1027. self appendToJQuery: 'body' asJQuery
  1028. !
  1029. renderAddOn: html
  1030. html li
  1031. class: 'dropdown';
  1032. with: [
  1033. html a
  1034. class: 'dropdown-toggle';
  1035. at: 'data-toggle' put: 'dropdown';
  1036. with: [
  1037. html with: 'Open...'.
  1038. (html tag: 'b') class: 'caret' ].
  1039. html ul
  1040. class: 'dropdown-menu';
  1041. with: [
  1042. ((HLWidget withAllSubclasses
  1043. select: [ :each | each canBeOpenAsTab ])
  1044. sorted: [ :a :b | a tabPriority < b tabPriority ])
  1045. do: [ :each |
  1046. html li with: [
  1047. html a
  1048. with: each tabLabel;
  1049. onClick: [ each openAsTab ] ] ] ] ]
  1050. !
  1051. renderContentOn: html
  1052. html div
  1053. class: 'navbar navbar-fixed-top';
  1054. with: [ html div
  1055. class: 'navbar-inner';
  1056. with: [ self renderTabsOn: html ] ]
  1057. !
  1058. renderTabsOn: html
  1059. html ul
  1060. class: 'nav';
  1061. with: [
  1062. self tabs do: [ :each |
  1063. html li
  1064. class: (each isActive ifTrue: [ 'active' ] ifFalse: [ 'inactive' ]);
  1065. with: [
  1066. html a
  1067. with: [
  1068. ((html tag: 'i') class: 'close')
  1069. onClick: [ self removeTab: each ].
  1070. html span
  1071. class: each cssClass;
  1072. with: each displayLabel ];
  1073. onClick: [ each activate ] ] ].
  1074. self renderAddOn: html ]
  1075. !
  1076. show: aTab
  1077. self tabs do: [ :each | each hide ].
  1078. aTab show; focus
  1079. ! !
  1080. !HLManager methodsFor: 'services'!
  1081. registerErrorHandler
  1082. self environment registerErrorHandler: HLErrorHandler new.
  1083. ErrorHandler register: HLErrorHandler new
  1084. !
  1085. registerFinder
  1086. self environment registerFinder: HLFinder new.
  1087. Finder register: HLFinder new
  1088. !
  1089. registerInspector
  1090. self environment registerInspector: HLInspector.
  1091. Inspector register: HLInspector
  1092. !
  1093. registerProgressHandler
  1094. self environment registerProgressHandler: HLProgressHandler new.
  1095. ProgressHandler register: HLProgressHandler new
  1096. !
  1097. registerTranscript
  1098. self environment registerTranscript: HLTranscriptHandler
  1099. ! !
  1100. HLManager class instanceVariableNames: 'current'!
  1101. !HLManager class methodsFor: 'accessing'!
  1102. current
  1103. ^ current ifNil: [ current := self basicNew initialize ]
  1104. ! !
  1105. !HLManager class methodsFor: 'initialization'!
  1106. setup
  1107. self current
  1108. setup;
  1109. appendToJQuery: 'body' asJQuery
  1110. ! !
  1111. !HLManager class methodsFor: 'instance creation'!
  1112. new
  1113. "Use current instead"
  1114. self shouldNotImplement
  1115. ! !
  1116. HLWidget subclass: #HLModalWidget
  1117. instanceVariableNames: 'confirmButtonLabel cancelButtonLabel'
  1118. package: 'Helios-Core'!
  1119. !HLModalWidget commentStamp!
  1120. I implement an abstract modal widget.!
  1121. !HLModalWidget methodsFor: 'accessing'!
  1122. cancelButtonLabel
  1123. ^ cancelButtonLabel ifNil: [ 'Cancel' ]
  1124. !
  1125. cancelButtonLabel: anObject
  1126. cancelButtonLabel := anObject
  1127. !
  1128. confirmButtonLabel
  1129. ^ confirmButtonLabel ifNil: [ 'Confirm' ]
  1130. !
  1131. confirmButtonLabel: anObject
  1132. confirmButtonLabel := anObject
  1133. !
  1134. cssClass
  1135. ^ ''
  1136. ! !
  1137. !HLModalWidget methodsFor: 'actions'!
  1138. cancel
  1139. self remove
  1140. !
  1141. confirm
  1142. "Override in subclasses"
  1143. self remove
  1144. !
  1145. remove
  1146. '.dialog' asJQuery removeClass: 'active'.
  1147. [
  1148. '#overlay' asJQuery remove.
  1149. '.dialog' asJQuery remove
  1150. ] valueWithTimeout: 300
  1151. !
  1152. show
  1153. self appendToJQuery: 'body' asJQuery
  1154. ! !
  1155. !HLModalWidget methodsFor: 'private'!
  1156. giveFocusToButton: aButton
  1157. aButton asJQuery focus
  1158. ! !
  1159. !HLModalWidget methodsFor: 'rendering'!
  1160. hasButtons
  1161. ^ true
  1162. !
  1163. renderButtonsOn: html
  1164. | confirmButton |
  1165. html div
  1166. class: 'buttons';
  1167. with: [
  1168. html button
  1169. class: 'button';
  1170. with: self cancelButtonLabel;
  1171. onClick: [ self cancel ].
  1172. confirmButton := html button
  1173. class: 'button default';
  1174. with: self confirmButtonLabel;
  1175. onClick: [ self confirm ] ].
  1176. self giveFocusToButton:confirmButton
  1177. !
  1178. renderContentOn: html
  1179. | confirmButton |
  1180. html div id: 'overlay'.
  1181. html div
  1182. class: 'dialog ', self cssClass;
  1183. with: [
  1184. self renderMainOn: html.
  1185. self hasButtons ifTrue: [
  1186. self renderButtonsOn: html ] ].
  1187. '.dialog' asJQuery addClass: 'active'.
  1188. self setupKeyBindings
  1189. !
  1190. renderMainOn: html
  1191. !
  1192. setupKeyBindings
  1193. '.dialog' asJQuery keyup: [ :e |
  1194. e keyCode = String esc asciiValue ifTrue: [ self cancel ] ]
  1195. ! !
  1196. HLModalWidget subclass: #HLConfirmationWidget
  1197. instanceVariableNames: 'confirmationString actionBlock cancelBlock'
  1198. package: 'Helios-Core'!
  1199. !HLConfirmationWidget commentStamp!
  1200. I display confirmation messages.
  1201. Instead of creating an instance directly, use `HLWidget >> #confirm:ifTrue:`.!
  1202. !HLConfirmationWidget methodsFor: 'accessing'!
  1203. actionBlock
  1204. ^ actionBlock ifNil: [ [] ]
  1205. !
  1206. actionBlock: aBlock
  1207. actionBlock := aBlock
  1208. !
  1209. cancelBlock
  1210. ^ cancelBlock ifNil: [ [] ]
  1211. !
  1212. cancelBlock: aBlock
  1213. cancelBlock := aBlock
  1214. !
  1215. confirmationString
  1216. ^ confirmationString ifNil: [ 'Confirm' ]
  1217. !
  1218. confirmationString: aString
  1219. confirmationString := aString
  1220. ! !
  1221. !HLConfirmationWidget methodsFor: 'actions'!
  1222. cancel
  1223. self cancelBlock value.
  1224. super cancel
  1225. !
  1226. confirm
  1227. super confirm.
  1228. self actionBlock value
  1229. ! !
  1230. !HLConfirmationWidget methodsFor: 'rendering'!
  1231. renderMainOn: html
  1232. html span with: self confirmationString
  1233. ! !
  1234. HLConfirmationWidget subclass: #HLRequestWidget
  1235. instanceVariableNames: 'input value'
  1236. package: 'Helios-Core'!
  1237. !HLRequestWidget commentStamp!
  1238. I display a modal window requesting user input.
  1239. Instead of creating instances manually, use `HLWidget >> #request:do:` and `#request:value:do:`.!
  1240. !HLRequestWidget methodsFor: 'accessing'!
  1241. cssClass
  1242. ^ 'large'
  1243. !
  1244. value
  1245. ^ value ifNil: [ '' ]
  1246. !
  1247. value: aString
  1248. value := aString
  1249. ! !
  1250. !HLRequestWidget methodsFor: 'actions'!
  1251. confirm
  1252. super confirm.
  1253. self actionBlock value: input asJQuery val
  1254. ! !
  1255. !HLRequestWidget methodsFor: 'private'!
  1256. giveFocusToButton: aButton
  1257. ! !
  1258. !HLRequestWidget methodsFor: 'rendering'!
  1259. renderMainOn: html
  1260. super renderMainOn: html.
  1261. input := html textarea.
  1262. input asJQuery
  1263. val: self value;
  1264. focus
  1265. ! !
  1266. HLModalWidget subclass: #HLProgressWidget
  1267. instanceVariableNames: 'progressBars visible'
  1268. package: 'Helios-Core'!
  1269. !HLProgressWidget commentStamp!
  1270. I am a widget used to display progress modal dialogs.
  1271. My default instance is accessed with `HLProgressWidget class >> #default`.
  1272. See `HLProgressHandler` for usage.!
  1273. !HLProgressWidget methodsFor: 'accessing'!
  1274. progressBars
  1275. ^ progressBars ifNil: [ progressBars := OrderedCollection new ]
  1276. ! !
  1277. !HLProgressWidget methodsFor: 'actions'!
  1278. addProgressBar: aProgressBar
  1279. self show.
  1280. self progressBars add: aProgressBar.
  1281. aProgressBar appendToJQuery: (self wrapper asJQuery find: '.dialog')
  1282. !
  1283. do: aBlock on: aCollection displaying: aString
  1284. | progressBar |
  1285. progressBar := HLProgressBarWidget new
  1286. parent: self;
  1287. label: aString;
  1288. workBlock: aBlock;
  1289. collection: aCollection;
  1290. yourself.
  1291. self addProgressBar: progressBar.
  1292. progressBar start
  1293. !
  1294. flush
  1295. self progressBars do: [ :each |
  1296. self removeProgressBar: each ]
  1297. !
  1298. remove
  1299. self isVisible ifTrue: [
  1300. visible := false.
  1301. super remove ]
  1302. !
  1303. removeProgressBar: aProgressBar
  1304. self progressBars remove: aProgressBar ifAbsent: [].
  1305. aProgressBar wrapper asJQuery remove.
  1306. self progressBars ifEmpty: [ self remove ]
  1307. !
  1308. show
  1309. self isVisible ifFalse: [
  1310. visible := true.
  1311. super show ]
  1312. ! !
  1313. !HLProgressWidget methodsFor: 'rendering'!
  1314. renderMainOn: html
  1315. self progressBars do: [ :each |
  1316. html with: each ]
  1317. ! !
  1318. !HLProgressWidget methodsFor: 'testing'!
  1319. hasButtons
  1320. ^ false
  1321. !
  1322. isVisible
  1323. ^ visible ifNil: [ false ]
  1324. ! !
  1325. HLProgressWidget class instanceVariableNames: 'default'!
  1326. !HLProgressWidget class methodsFor: 'accessing'!
  1327. default
  1328. ^ default ifNil: [ default := self new ]
  1329. ! !
  1330. HLModalWidget subclass: #HLTabSelectionWidget
  1331. instanceVariableNames: 'tabs tabList selectedTab selectCallback cancelCallback confirmCallback'
  1332. package: 'Helios-Core'!
  1333. !HLTabSelectionWidget commentStamp!
  1334. I am a modal window used to select or create tabs.!
  1335. !HLTabSelectionWidget methodsFor: 'accessing'!
  1336. cancelCallback
  1337. ^ cancelCallback ifNil: [ [] ]
  1338. !
  1339. cancelCallback: aBlock
  1340. cancelCallback := aBlock
  1341. !
  1342. confirmCallback
  1343. ^ confirmCallback ifNil: [ [] ]
  1344. !
  1345. confirmCallback: aBlock
  1346. confirmCallback := aBlock
  1347. !
  1348. selectCallback
  1349. ^ selectCallback ifNil: [ [] ]
  1350. !
  1351. selectCallback: aBlock
  1352. selectCallback := aBlock
  1353. !
  1354. selectedTab
  1355. ^ selectedTab
  1356. !
  1357. selectedTab: aTab
  1358. selectedTab := aTab
  1359. !
  1360. tabs
  1361. ^ tabs ifNil: [ #() ]
  1362. !
  1363. tabs: aCollection
  1364. tabs := aCollection
  1365. ! !
  1366. !HLTabSelectionWidget methodsFor: 'actions'!
  1367. cancel
  1368. super cancel.
  1369. self cancelCallback value
  1370. !
  1371. confirm
  1372. super confirm.
  1373. self confirmCallback value: self selectedTab
  1374. !
  1375. selectTab: aTab
  1376. self selectedTab: aTab.
  1377. self selectCallback value: aTab
  1378. !
  1379. setupKeyBindings
  1380. super setupKeyBindings.
  1381. '.dialog' asJQuery keyup: [ :e |
  1382. e keyCode = String cr asciiValue ifTrue: [ self confirm ] ]
  1383. ! !
  1384. !HLTabSelectionWidget methodsFor: 'rendering'!
  1385. renderContentOn: html
  1386. super renderContentOn: html.
  1387. self tabList focus
  1388. !
  1389. renderMainOn: html
  1390. html div
  1391. class: 'title';
  1392. with: 'Tab selection'.
  1393. html with: self tabList
  1394. !
  1395. renderTab: aTab on: html
  1396. html
  1397. span
  1398. class: aTab cssClass;
  1399. with: aTab label
  1400. !
  1401. renderTabsOn: html
  1402. self tabs do: [ :each |
  1403. html li with: [
  1404. html a
  1405. with: [
  1406. self renderTab: each on: html ];
  1407. onClick: [ self selectTab: each ] ] ]
  1408. !
  1409. tabList
  1410. tabList ifNil: [
  1411. tabList := HLTabListWidget new.
  1412. tabList
  1413. callback: [ :tab | self selectTab: tab. tabList focus ];
  1414. selectedItem: self selectedTab;
  1415. items: self tabs ].
  1416. ^ tabList
  1417. ! !
  1418. HLWidget subclass: #HLProgressBarWidget
  1419. instanceVariableNames: 'label parent workBlock collection bar'
  1420. package: 'Helios-Core'!
  1421. !HLProgressBarWidget commentStamp!
  1422. I am a widget used to display a progress bar while iterating over a collection.!
  1423. !HLProgressBarWidget methodsFor: 'accessing'!
  1424. collection
  1425. ^ collection
  1426. !
  1427. collection: aCollection
  1428. collection := aCollection
  1429. !
  1430. label
  1431. ^ label
  1432. !
  1433. label: aString
  1434. label := aString
  1435. !
  1436. parent
  1437. ^ parent
  1438. !
  1439. parent: aProgress
  1440. parent := aProgress
  1441. !
  1442. workBlock
  1443. ^ workBlock
  1444. !
  1445. workBlock: aBlock
  1446. workBlock := aBlock
  1447. ! !
  1448. !HLProgressBarWidget methodsFor: 'actions'!
  1449. evaluateAt: anInteger
  1450. self updateProgress: (anInteger / self collection size) * 100.
  1451. anInteger <= self collection size
  1452. ifTrue: [
  1453. [
  1454. self workBlock value: (self collection at: anInteger).
  1455. self evaluateAt: anInteger + 1 ] valueWithTimeout: 10 ]
  1456. ifFalse: [ [ self remove ] valueWithTimeout: 500 ]
  1457. !
  1458. remove
  1459. self parent removeProgressBar: self
  1460. !
  1461. start
  1462. "Make sure the UI has some time to update itself between each iteration"
  1463. self evaluateAt: 1
  1464. !
  1465. updateProgress: anInteger
  1466. bar asJQuery css: 'width' put: anInteger asString, '%'
  1467. ! !
  1468. !HLProgressBarWidget methodsFor: 'rendering'!
  1469. renderContentOn: html
  1470. html span with: self label.
  1471. html div
  1472. class: 'progress';
  1473. with: [
  1474. bar := html div
  1475. class: 'bar';
  1476. style: 'width: 0%' ]
  1477. ! !
  1478. HLProgressBarWidget class instanceVariableNames: 'default'!
  1479. !HLProgressBarWidget class methodsFor: 'accessing'!
  1480. default
  1481. ^ default ifNil: [ default := self new ]
  1482. ! !