Helios-Core.st 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443
  1. Smalltalk createPackage: 'Helios-Core'!
  2. Object subclass: #HLModel
  3. instanceVariableNames: 'announcer environment'
  4. package: 'Helios-Core'!
  5. !HLModel commentStamp!
  6. I am the abstract superclass of all models of Helios.
  7. I am the "Model" part of the MVC pattern implementation in Helios.
  8. I provide access to an `Environment` object and both a local (model-specific) and global (system-specific) announcer.
  9. The `#withChangesDo:` method is handy for performing model changes ensuring that all widgets are aware of the change and can prevent it from happening.
  10. Modifications of the system should be done via commands (see `HLCommand` and subclasses).!
  11. !HLModel methodsFor: 'accessing'!
  12. announcer
  13. ^ announcer ifNil: [ announcer := Announcer new ]
  14. !
  15. environment
  16. ^ environment ifNil: [ self manager environment ]
  17. !
  18. environment: anEnvironment
  19. environment := anEnvironment
  20. !
  21. manager
  22. ^ HLManager current
  23. !
  24. systemAnnouncer
  25. ^ self environment systemAnnouncer
  26. ! !
  27. !HLModel methodsFor: 'error handling'!
  28. withChangesDo: aBlock
  29. [
  30. self announcer announce: (HLAboutToChange new
  31. actionBlock: aBlock;
  32. yourself).
  33. aBlock value.
  34. ]
  35. on: HLChangeForbidden
  36. do: [ :ex | ]
  37. ! !
  38. !HLModel methodsFor: 'testing'!
  39. isBrowserModel
  40. ^ false
  41. !
  42. isReferencesModel
  43. ^ false
  44. !
  45. isToolModel
  46. ^ false
  47. ! !
  48. HLModel subclass: #HLFinder
  49. instanceVariableNames: ''
  50. package: 'Helios-Core'!
  51. !HLFinder commentStamp!
  52. I am the `Finder` service handler of Helios.
  53. Finding a class will open a new class browser, while finding a method will open a references browser.!
  54. !HLFinder methodsFor: 'finding'!
  55. findClass: aClass
  56. HLBrowser openAsTab openClassNamed: aClass name
  57. !
  58. findMethod: aCompiledMethod
  59. HLBrowser openAsTab openMethod: aCompiledMethod
  60. !
  61. findString: aString
  62. | foundClass |
  63. foundClass := self environment classes
  64. detect: [ :each | each name = aString ]
  65. ifNone: [ nil ].
  66. foundClass
  67. ifNil: [ HLReferences openAsTab search: aString ]
  68. ifNotNil: [ self findClass: foundClass ]
  69. ! !
  70. HLModel subclass: #HLToolModel
  71. instanceVariableNames: 'selectedClass selectedPackage selectedProtocol selectedSelector'
  72. package: 'Helios-Core'!
  73. !HLToolModel commentStamp!
  74. I am a model specific to package and class manipulation. All browsers should either use me or a subclass as their model.
  75. I provide methods for package, class, protocol and method manipulation and access, forwarding to my environment.
  76. I also handle compilation of classes and methods as well as compilation and parsing errors.!
  77. !HLToolModel methodsFor: 'accessing'!
  78. allSelectors
  79. ^ self environment allSelectors
  80. !
  81. availableClassNames
  82. ^ self environment availableClassNames
  83. !
  84. availablePackageNames
  85. ^ self environment availablePackageNames
  86. !
  87. availablePackages
  88. ^ self environment availablePackageNames
  89. !
  90. availableProtocols
  91. ^ self environment availableProtocolsFor: self selectedClass
  92. !
  93. forceSelectedClass: aClass
  94. self withChangesDo: [
  95. self
  96. selectedClass: nil;
  97. selectedClass: aClass ]
  98. !
  99. forceSelectedMethod: aMethod
  100. self withChangesDo: [
  101. self
  102. selectedMethod: nil;
  103. selectedMethod: aMethod ]
  104. !
  105. forceSelectedPackage: aPackage
  106. self withChangesDo: [
  107. self
  108. selectedPackage: nil;
  109. selectedPackage: aPackage ]
  110. !
  111. forceSelectedProtocol: aProtocol
  112. self withChangesDo: [
  113. self
  114. selectedProtocol: nil;
  115. selectedProtocol: aProtocol ]
  116. !
  117. packageToCommit
  118. "Answer the package to commit depending on the context:
  119. - if a Method is selected, answer its package
  120. - else answer the `selectedPackage`"
  121. ^ self selectedMethod
  122. ifNil: [ self selectedPackage ]
  123. ifNotNil: [ :method | method package ]
  124. !
  125. packages
  126. ^ self environment packages
  127. !
  128. selectedClass
  129. ^ selectedClass
  130. !
  131. selectedClass: aClass
  132. (self selectedClass = aClass and: [ aClass isNil ])
  133. ifTrue: [ ^ self ].
  134. self withChangesDo: [
  135. aClass
  136. ifNil: [ selectedClass := nil ]
  137. ifNotNil: [
  138. self selectedPackage: aClass theNonMetaClass package.
  139. self showInstance
  140. ifTrue: [ selectedClass := aClass theNonMetaClass ]
  141. ifFalse: [ selectedClass := aClass theMetaClass ] ].
  142. selectedProtocol := nil.
  143. self selectedProtocol: self allProtocol.
  144. self announcer announce: (HLClassSelected on: self selectedClass) ]
  145. !
  146. selectedMethod
  147. ^ self selectedClass ifNotNil: [
  148. self selectedClass methodDictionary
  149. at: selectedSelector
  150. ifAbsent: [ nil ] ]
  151. !
  152. selectedMethod: aCompiledMethod
  153. selectedSelector = aCompiledMethod ifTrue: [ ^ self ].
  154. self withChangesDo: [
  155. aCompiledMethod
  156. ifNil: [ selectedSelector := nil ]
  157. ifNotNil: [
  158. selectedSelector := aCompiledMethod selector.
  159. (selectedClass notNil and: [ selectedClass methodDictionary includesKey: selectedSelector ]) ifFalse: [
  160. selectedClass := aCompiledMethod methodClass.
  161. selectedPackage := selectedClass theNonMetaClass package ] ].
  162. self announcer announce: (HLMethodSelected on: aCompiledMethod) ]
  163. !
  164. selectedPackage
  165. ^ selectedPackage
  166. !
  167. selectedPackage: aPackage
  168. selectedPackage = aPackage ifTrue: [ ^ self ].
  169. self withChangesDo: [
  170. selectedPackage := aPackage.
  171. self selectedClass: nil.
  172. self announcer announce: (HLPackageSelected on: aPackage) ]
  173. !
  174. selectedProtocol
  175. ^ selectedProtocol
  176. !
  177. selectedProtocol: aString
  178. selectedProtocol = aString ifTrue: [ ^ self ].
  179. self withChangesDo: [
  180. selectedProtocol := aString.
  181. self selectedMethod: nil.
  182. self announcer announce: (HLProtocolSelected on: aString) ]
  183. ! !
  184. !HLToolModel methodsFor: 'actions'!
  185. addInstVarNamed: aString
  186. self environment addInstVarNamed: aString to: self selectedClass.
  187. self announcer announce: (HLInstVarAdded new
  188. theClass: self selectedClass;
  189. variableName: aString;
  190. yourself)
  191. !
  192. save: aString
  193. self announcer announce: HLSourceCodeSaved new.
  194. (self shouldCompileDefinition: aString)
  195. ifTrue: [ self compileClassDefinition: aString ]
  196. ifFalse: [ self compileMethod: aString ]
  197. !
  198. saveSourceCode
  199. self announcer announce: HLSaveSourceCode new
  200. ! !
  201. !HLToolModel methodsFor: 'commands actions'!
  202. commitPackageOnSuccess: aBlock onError: anotherBlock
  203. self environment
  204. commitPackage: self packageToCommit
  205. onSuccess: aBlock
  206. onError: anotherBlock
  207. !
  208. copyClassTo: aClassName
  209. self withChangesDo: [
  210. self environment
  211. copyClass: self selectedClass theNonMetaClass
  212. to: aClassName.
  213. self selectedClass: (self environment classNamed: aClassName) ]
  214. !
  215. moveClassToPackage: aPackageName
  216. self withChangesDo: [
  217. self environment
  218. moveClass: self selectedClass theNonMetaClass
  219. toPackage: aPackageName ]
  220. !
  221. moveMethodToClass: aClassName
  222. self withChangesDo: [
  223. self environment
  224. moveMethod: self selectedMethod
  225. toClass: aClassName ]
  226. !
  227. moveMethodToProtocol: aProtocol
  228. self withChangesDo: [
  229. self environment
  230. moveMethod: self selectedMethod
  231. toProtocol: aProtocol ]
  232. !
  233. openClassNamed: aString
  234. | class |
  235. self withChangesDo: [
  236. class := self environment classNamed: aString.
  237. self selectedPackage: class package.
  238. self selectedClass: class ]
  239. !
  240. removeClass
  241. self withChangesDo: [
  242. self manager
  243. confirm: 'Do you REALLY want to remove class ', self selectedClass theNonMetaClass name
  244. ifTrue: [ self environment removeClass: self selectedClass theNonMetaClass ] ]
  245. !
  246. removeMethod
  247. self withChangesDo: [
  248. self manager
  249. confirm: 'Do you REALLY want to remove method ', self selectedMethod methodClass name,' >> #', self selectedMethod selector
  250. ifTrue: [ self environment removeMethod: self selectedMethod ] ]
  251. !
  252. removeProtocol
  253. self withChangesDo: [
  254. self manager
  255. confirm: 'Do you REALLY want to remove protocol ', self selectedProtocol
  256. ifTrue: [ self environment
  257. removeProtocol: self selectedProtocol
  258. from: self selectedClass ] ]
  259. !
  260. renameClassTo: aClassName
  261. self withChangesDo: [
  262. self environment
  263. renameClass: self selectedClass theNonMetaClass
  264. to: aClassName ]
  265. !
  266. renamePackageTo: aPackageName
  267. self withChangesDo: [
  268. self environment
  269. renamePackage: self selectedPackage name
  270. to: aPackageName ]
  271. !
  272. renameProtocolTo: aString
  273. self withChangesDo: [
  274. self environment
  275. renameProtocol: self selectedProtocol
  276. to: aString
  277. in: self selectedClass ]
  278. ! !
  279. !HLToolModel methodsFor: 'compiling'!
  280. compileClassComment: aString
  281. self environment
  282. compileClassComment: aString
  283. for: self selectedClass
  284. !
  285. compileClassDefinition: aString
  286. self environment compileClassDefinition: aString
  287. !
  288. compileMethod: aString
  289. | method |
  290. self withCompileErrorHandling: [
  291. method := self environment
  292. compileMethod: aString
  293. for: self selectedClass
  294. protocol: self compilationProtocol.
  295. self selectedMethod: method ]
  296. ! !
  297. !HLToolModel methodsFor: 'defaults'!
  298. allProtocol
  299. ^ '-- all --'
  300. !
  301. unclassifiedProtocol
  302. ^ 'as yet unclassified'
  303. ! !
  304. !HLToolModel methodsFor: 'error handling'!
  305. handleCompileError: anError
  306. self announcer announce: (HLCompileErrorRaised new
  307. error: anError;
  308. yourself)
  309. !
  310. handleParseError: anError
  311. | split line column messageToInsert |
  312. split := anError messageText tokenize: ' : '.
  313. messageToInsert := split second.
  314. "21 = 'Parse error on line ' size + 1"
  315. split := split first copyFrom: 21 to: split first size.
  316. split := split tokenize: ' column '.
  317. line := split first.
  318. column := split second.
  319. self announcer announce: (HLParseErrorRaised new
  320. line: line asNumber;
  321. column: column asNumber;
  322. message: messageToInsert;
  323. error: anError;
  324. yourself)
  325. !
  326. handleUnkownVariableError: anError
  327. self announcer announce: (HLUnknownVariableErrorRaised new
  328. error: anError;
  329. yourself)
  330. !
  331. withCompileErrorHandling: aBlock
  332. self environment
  333. evaluate: [
  334. self environment
  335. evaluate: [
  336. self environment
  337. evaluate: aBlock
  338. on: ParseError
  339. do: [ :ex | self handleParseError: ex ] ]
  340. on: UnknownVariableError
  341. do: [ :ex | self handleUnkownVariableError: ex ] ]
  342. on: CompilerError
  343. do: [ :ex | self handleCompileError: ex ]
  344. ! !
  345. !HLToolModel methodsFor: 'private'!
  346. compilationProtocol
  347. | currentProtocol |
  348. currentProtocol := self selectedProtocol.
  349. currentProtocol ifNil: [ currentProtocol := self unclassifiedProtocol ].
  350. self selectedMethod ifNotNil: [ currentProtocol := self selectedMethod protocol ].
  351. ^ currentProtocol = self allProtocol
  352. ifTrue: [ self unclassifiedProtocol ]
  353. ifFalse: [ currentProtocol ]
  354. !
  355. withHelperLabelled: aString do: aBlock
  356. "TODO: doesn't belong here"
  357. '#helper' asJQuery remove.
  358. [ :html |
  359. html div
  360. id: 'helper';
  361. with: aString ] appendToJQuery: 'body' asJQuery.
  362. [
  363. aBlock value.
  364. '#helper' asJQuery remove ] fork
  365. ! !
  366. !HLToolModel methodsFor: 'testing'!
  367. isToolModel
  368. ^ true
  369. !
  370. shouldCompileDefinition: aString
  371. ^ self selectedClass isNil or: [
  372. aString match: '^\s*[A-Z]' ]
  373. ! !
  374. !HLToolModel class methodsFor: 'actions'!
  375. on: anEnvironment
  376. ^ self new
  377. environment: anEnvironment;
  378. yourself
  379. ! !
  380. Object subclass: #HLProgressHandler
  381. instanceVariableNames: ''
  382. package: 'Helios-Core'!
  383. !HLProgressHandler commentStamp!
  384. I am a specific progress handler for Helios, displaying progresses in a modal window.!
  385. !HLProgressHandler methodsFor: 'progress handling'!
  386. do: aBlock on: aCollection displaying: aString
  387. HLProgressWidget default
  388. do: aBlock
  389. on: aCollection
  390. displaying: aString
  391. ! !
  392. Widget subclass: #HLWidget
  393. instanceVariableNames: 'wrapper'
  394. package: 'Helios-Core'!
  395. !HLWidget commentStamp!
  396. I am the abstract superclass of all Helios widgets.
  397. I provide common methods, additional behavior to widgets useful for Helios, like dialog creation, command execution and tab creation.
  398. ## API
  399. 1. Rendering
  400. Instead of overriding `#renderOn:` as with other Widget subclasses, my subclasses should override `#renderContentOn:`.
  401. 2. Refreshing
  402. To re-render a widget, use `#refresh`.
  403. 3. Key bindings registration and tabs
  404. When displayed as a tab, the widget has a chance to register keybindings with the `#registerBindingsOn:` hook method.
  405. 4. Unregistration
  406. 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.
  407. 5. Tabs
  408. 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.
  409. 6. Command execution
  410. An helios command (instance of `HLCommand` or one of its subclass) can be executed with `#execute:`.!
  411. !HLWidget methodsFor: 'accessing'!
  412. cssClass
  413. ^ 'hl_widget'
  414. !
  415. manager
  416. ^ HLManager current
  417. !
  418. removeTab
  419. self manager removeTabForWidget: self
  420. !
  421. setTabLabel: aString
  422. self manager announcer announce: (HLTabLabelChanged new
  423. widget: self;
  424. label: aString;
  425. yourself)
  426. !
  427. tabClass
  428. ^ self class tabClass
  429. !
  430. wrapper
  431. ^ wrapper
  432. ! !
  433. !HLWidget methodsFor: 'actions'!
  434. confirm: aString ifTrue: aBlock
  435. self manager confirm: aString ifTrue: aBlock
  436. !
  437. confirm: aString ifTrue: aBlock ifFalse: anotherBlock
  438. self manager
  439. confirm: aString
  440. ifTrue: aBlock
  441. ifFalse: anotherBlock
  442. !
  443. execute: aCommand
  444. HLManager current keyBinder
  445. activate;
  446. applyBinding: aCommand asBinding
  447. !
  448. inform: aString
  449. self manager inform: aString
  450. !
  451. openAsTab
  452. (HLTabWidget on: self labelled: self defaultTabLabel)
  453. add
  454. !
  455. request: aString do: aBlock
  456. self manager request: aString do: aBlock
  457. !
  458. request: aString value: valueString do: aBlock
  459. self manager
  460. request: aString
  461. value: valueString
  462. do: aBlock
  463. !
  464. unregister
  465. "This method is called whenever the receiver is closed (as a tab).
  466. Widgets subscribing to announcements should unregister there"
  467. ! !
  468. !HLWidget methodsFor: 'defaults'!
  469. defaultTabLabel
  470. ^ self class tabLabel
  471. ! !
  472. !HLWidget methodsFor: 'keybindings'!
  473. bindKeyDown: keyDownBlock keyUp: keyUpBlock
  474. self wrapper ifNotNil: [ wrapper
  475. onKeyDown: keyDownBlock;
  476. onKeyUp: keyUpBlock ]
  477. !
  478. registerBindings
  479. self registerBindingsOn: self manager keyBinder bindings
  480. !
  481. registerBindingsOn: aBindingGroup
  482. !
  483. unbindKeyDownKeyUp
  484. self wrapper asJQuery
  485. unbind: 'keydown';
  486. unbind: 'keyup'
  487. ! !
  488. !HLWidget methodsFor: 'rendering'!
  489. renderContentOn: html
  490. !
  491. renderOn: html
  492. wrapper := html div
  493. class: self cssClass;
  494. yourself.
  495. "must do this later, as renderContentOn may want to use self wrapper"
  496. wrapper with: [ self renderContentOn: html ]
  497. ! !
  498. !HLWidget methodsFor: 'testing'!
  499. canHaveFocus
  500. ^ false
  501. ! !
  502. !HLWidget methodsFor: 'updating'!
  503. refresh
  504. self wrapper
  505. ifNotNil: [ :wrap | wrap contents: [ :html | self renderContentOn: html ] ]
  506. ! !
  507. !HLWidget class methodsFor: 'accessing'!
  508. openAsTab
  509. | instance |
  510. instance := self new.
  511. (HLTabWidget
  512. on: instance
  513. labelled: instance defaultTabLabel) add.
  514. ^ instance
  515. !
  516. tabClass
  517. ^ ''
  518. !
  519. tabLabel
  520. ^ 'Tab'
  521. !
  522. tabPriority
  523. ^ 500
  524. ! !
  525. !HLWidget class methodsFor: 'testing'!
  526. canBeOpenAsTab
  527. ^ false
  528. ! !
  529. HLWidget subclass: #HLFocusableWidget
  530. instanceVariableNames: ''
  531. package: 'Helios-Core'!
  532. !HLFocusableWidget commentStamp!
  533. I am a widget that can be focused.
  534. ## API
  535. Instead of overriding `#renderOn:` as with other `Widget` subclasses, my subclasses should override `#renderContentOn:`.
  536. To bring the focus to the widget, use the `#focus` method.!
  537. !HLFocusableWidget methodsFor: 'accessing'!
  538. focusClass
  539. ^ 'focused'
  540. ! !
  541. !HLFocusableWidget methodsFor: 'events'!
  542. blur
  543. self wrapper asJQuery blur
  544. !
  545. focus
  546. self wrapper asJQuery focus
  547. ! !
  548. !HLFocusableWidget methodsFor: 'rendering'!
  549. renderContentOn: html
  550. !
  551. renderOn: html
  552. wrapper := html div
  553. class: self cssClass;
  554. at: 'tabindex' put: '0';
  555. onBlur: [ self wrapper asJQuery removeClass: self focusClass ];
  556. onFocus: [ self wrapper asJQuery addClass: self focusClass ];
  557. yourself.
  558. "must do this later, as renderContentOn may want to use self wrapper"
  559. wrapper with: [ self renderContentOn: html ]
  560. ! !
  561. !HLFocusableWidget methodsFor: 'testing'!
  562. canHaveFocus
  563. ^ true
  564. !
  565. hasFocus
  566. ^ self wrapper notNil and: [ self wrapper asJQuery hasClass: self focusClass ]
  567. ! !
  568. HLFocusableWidget subclass: #HLListWidget
  569. instanceVariableNames: 'items selectedItem'
  570. package: 'Helios-Core'!
  571. !HLListWidget methodsFor: 'accessing'!
  572. activeItemCssClass
  573. ^'active'
  574. !
  575. buttonsDivCssClass
  576. ^ 'pane_actions form-group'
  577. !
  578. cssClassForItem: anObject
  579. ^ ''
  580. !
  581. findListItemFor: anObject
  582. ^ (((wrapper asJQuery find: 'li')
  583. filter: [ :thisArg :otherArg | (thisArg asJQuery data: 'item') = anObject ] currySelf) eq: 0)
  584. !
  585. items
  586. ^ items ifNil: [ items := self defaultItems ]
  587. !
  588. items: aCollection
  589. items := aCollection
  590. !
  591. listCssClass
  592. ^'nav nav-pills nav-stacked'
  593. !
  594. listCssClassForItem: anObject
  595. ^ self selectedItem = anObject
  596. ifTrue: [ self activeItemCssClass ]
  597. ifFalse: [ 'inactive' ]
  598. !
  599. positionOf: aListItem
  600. <inlineJS: '
  601. return aListItem.parent().children().get().indexOf(aListItem.get(0)) + 1
  602. '>
  603. !
  604. selectedItem
  605. ^ selectedItem
  606. !
  607. selectedItem: anObject
  608. selectedItem := anObject
  609. ! !
  610. !HLListWidget methodsFor: 'actions'!
  611. activateFirstListItem
  612. self activateListItem: ((wrapper asJQuery find: 'li.inactive') eq: 0)
  613. !
  614. activateItem: anObject
  615. self activateListItem: (self findListItemFor: anObject)
  616. !
  617. activateListItem: aListItem
  618. | item |
  619. (aListItem get: 0) ifNil: [ ^ self ].
  620. aListItem parent children removeClass: self activeItemCssClass.
  621. aListItem addClass: self activeItemCssClass.
  622. self ensureVisible: aListItem.
  623. "Activate the corresponding item"
  624. item := aListItem data: 'item'.
  625. self selectedItem == item ifFalse: [
  626. self selectItem: item ]
  627. !
  628. activateNextListItem
  629. self activateListItem: (self wrapper asJQuery find: ('li.', self activeItemCssClass)) next.
  630. "select the first item if none is selected"
  631. (self wrapper asJQuery find: (' .', self activeItemCssClass)) get ifEmpty: [
  632. self activateFirstListItem ]
  633. !
  634. activatePreviousListItem
  635. self activateListItem: (self wrapper asJQuery find: ('li.', self activeItemCssClass)) prev
  636. !
  637. ensureVisible: aListItem
  638. "Move the scrollbar to show the active element"
  639. | parent position |
  640. (aListItem get: 0) ifNil: [ ^ self ].
  641. position := self positionOf: aListItem.
  642. parent := aListItem parent.
  643. aListItem position top < 0 ifTrue: [
  644. (parent get: 0) scrollTop: ((parent get: 0) scrollTop + aListItem position top - 10) ].
  645. aListItem position top + aListItem height > parent height ifTrue: [
  646. (parent get: 0) scrollTop: ((parent get: 0) scrollTop + aListItem height - (parent height - aListItem position top)) +10 ]
  647. !
  648. focus
  649. super focus.
  650. self items ifNotEmpty: [
  651. self selectedItem ifNil: [ self activateFirstListItem ] ]
  652. !
  653. reactivateListItem: aListItem
  654. self activateListItem: aListItem.
  655. self reselectItem: self selectedItem
  656. !
  657. refresh
  658. super refresh.
  659. self selectedItem ifNotNil: [self ensureVisible: (self findListItemFor: self selectedItem)].
  660. !
  661. reselectItem: anObject
  662. !
  663. selectItem: anObject
  664. self selectedItem: anObject
  665. ! !
  666. !HLListWidget methodsFor: 'defaults'!
  667. defaultItems
  668. ^ #()
  669. ! !
  670. !HLListWidget methodsFor: 'events'!
  671. setupKeyBindings
  672. (HLRepeatedKeyDownHandler on: self)
  673. whileKeyDown: 38 do: [ self activatePreviousListItem ];
  674. whileKeyDown: 40 do: [ self activateNextListItem ];
  675. rebindKeys.
  676. self wrapper asJQuery keydown: [ :e |
  677. e which = 13 ifTrue: [
  678. self reselectItem: self selectedItem ] ]
  679. ! !
  680. !HLListWidget methodsFor: 'rendering'!
  681. renderButtonsOn: html
  682. !
  683. renderContentOn: html
  684. html ul
  685. class: self listCssClass;
  686. with: [ self renderListOn: html ];
  687. onClick: [ self focus ].
  688. html div class: self buttonsDivCssClass; with: [
  689. self renderButtonsOn: html ].
  690. self setupKeyBindings
  691. !
  692. renderItem: anObject on: html
  693. | li |
  694. li := html li.
  695. li asJQuery data: 'item' put: anObject.
  696. li
  697. class: (self listCssClassForItem: anObject);
  698. with: [
  699. html a
  700. with: [
  701. (html tag: 'i') class: (self cssClassForItem: anObject).
  702. self renderItemLabel: anObject on: html ];
  703. onClick: [
  704. self reactivateListItem: li asJQuery ] ]
  705. !
  706. renderItemLabel: anObject on: html
  707. html with: anObject asString
  708. !
  709. renderListOn: html
  710. self items do: [ :each |
  711. self renderItem: each on: html ]
  712. ! !
  713. HLListWidget subclass: #HLNavigationListWidget
  714. instanceVariableNames: 'previous next'
  715. package: 'Helios-Core'!
  716. !HLNavigationListWidget methodsFor: 'accessing'!
  717. next
  718. ^ next
  719. !
  720. next: aWidget
  721. next := aWidget.
  722. aWidget previous = self ifFalse: [ aWidget previous: self ]
  723. !
  724. previous
  725. ^ previous
  726. !
  727. previous: aWidget
  728. previous := aWidget.
  729. aWidget next = self ifFalse: [ aWidget next: self ]
  730. ! !
  731. !HLNavigationListWidget methodsFor: 'actions'!
  732. nextFocus
  733. self next ifNotNil: [ self next focus ]
  734. !
  735. previousFocus
  736. self previous ifNotNil: [ self previous focus ]
  737. ! !
  738. !HLNavigationListWidget methodsFor: 'events'!
  739. setupKeyBindings
  740. super setupKeyBindings.
  741. self wrapper ifNotNil: [ wrapper onKeyDown: [ :e |
  742. e which = 39 ifTrue: [
  743. self nextFocus ].
  744. e which = 37 ifTrue: [
  745. self previousFocus ] ] ]
  746. ! !
  747. HLNavigationListWidget subclass: #HLToolListWidget
  748. instanceVariableNames: 'model'
  749. package: 'Helios-Core'!
  750. !HLToolListWidget methodsFor: 'accessing'!
  751. commandCategory
  752. ^ self label
  753. !
  754. label
  755. ^ 'List'
  756. !
  757. menuCommands
  758. "Answer a collection of commands to be put in the cog menu"
  759. ^ ((HLToolCommand concreteClasses
  760. select: [ :each | each isValidFor: self model ])
  761. collect: [ :each | each for: self model ])
  762. select: [ :each |
  763. each category = self commandCategory and: [
  764. each isAction and: [ each isActive ] ] ]
  765. !
  766. model
  767. ^ model
  768. !
  769. model: aBrowserModel
  770. model := aBrowserModel.
  771. self
  772. observeSystem;
  773. observeModel
  774. !
  775. selectedItem: anItem
  776. "Selection changed, update the cog menu"
  777. super selectedItem: anItem.
  778. self updateMenu
  779. ! !
  780. !HLToolListWidget methodsFor: 'actions'!
  781. activateListItem: anItem
  782. self model withChangesDo: [ super activateListItem: anItem ]
  783. !
  784. activateNextListItem
  785. self model withChangesDo: [ super activateNextListItem ]
  786. !
  787. activatePreviousListItem
  788. self model withChangesDo: [ super activatePreviousListItem ]
  789. !
  790. observeModel
  791. !
  792. observeSystem
  793. !
  794. reactivateListItem: anItem
  795. self model withChangesDo: [ super reactivateListItem: anItem ]
  796. !
  797. unregister
  798. super unregister.
  799. self model announcer unsubscribe: self.
  800. self model systemAnnouncer unsubscribe: self
  801. ! !
  802. !HLToolListWidget methodsFor: 'rendering'!
  803. renderContentOn: html
  804. self renderHeadOn: html.
  805. super renderContentOn: html
  806. !
  807. renderHeadOn: html
  808. html div
  809. class: 'list-label';
  810. with: [
  811. html with: self label.
  812. self renderMenuOn: html ]
  813. !
  814. renderMenuOn: html
  815. | commands |
  816. commands := self menuCommands.
  817. commands ifEmpty: [ ^ self ].
  818. html div
  819. class: 'btn-group cog context_menu';
  820. with: [
  821. html a
  822. class: 'btn btn-default dropdown-toggle';
  823. at: 'data-toggle' put: 'dropdown';
  824. with: [ (html tag: 'i') class: 'glyphicon glyphicon-chevron-down' ].
  825. html ul
  826. class: 'dropdown-menu pull-right';
  827. with: [
  828. commands do: [ :each |
  829. html li with: [ html a
  830. with: [ html with: each menuLabel;
  831. with: (html span class: 'badge'; with: 'c c') ];
  832. onClick: [ self execute: each ] ] ] ] ]
  833. ! !
  834. !HLToolListWidget methodsFor: 'updating'!
  835. updateMenu
  836. (self wrapper asJQuery find: '.cog') remove.
  837. [ :html | self renderMenuOn: html ]
  838. appendToJQuery: (self wrapper asJQuery find: '.list-label')
  839. ! !
  840. !HLToolListWidget class methodsFor: 'instance creation'!
  841. on: aModel
  842. ^ self new
  843. model: aModel;
  844. yourself
  845. ! !
  846. HLListWidget subclass: #HLTabListWidget
  847. instanceVariableNames: 'callback'
  848. package: 'Helios-Core'!
  849. !HLTabListWidget commentStamp!
  850. I am a widget used to display a list of helios tabs.
  851. When a tab is selected, `callback` is evaluated with the selected tab as argument.!
  852. !HLTabListWidget methodsFor: 'accessing'!
  853. callback
  854. ^ callback ifNil: [ [] ]
  855. !
  856. callback: aBlock
  857. callback := aBlock
  858. ! !
  859. !HLTabListWidget methodsFor: 'actions'!
  860. selectItem: aTab
  861. super selectItem: aTab.
  862. self callback value: aTab
  863. ! !
  864. !HLTabListWidget methodsFor: 'rendering'!
  865. renderItemLabel: aTab on: html
  866. html span
  867. class: aTab cssClass;
  868. with: aTab label
  869. ! !
  870. HLWidget subclass: #HLInformationWidget
  871. instanceVariableNames: 'informationString'
  872. package: 'Helios-Core'!
  873. !HLInformationWidget commentStamp!
  874. I display an information dialog.
  875. ## API
  876. `HLWidget >> #inform:` is a convenience method for creating information dialogs.!
  877. !HLInformationWidget methodsFor: 'accessing'!
  878. informationString
  879. ^ informationString ifNil: [ '' ]
  880. !
  881. informationString: anObject
  882. informationString := anObject
  883. ! !
  884. !HLInformationWidget methodsFor: 'actions'!
  885. remove
  886. [
  887. self wrapper asJQuery fadeOut: 100.
  888. [ self wrapper asJQuery remove ]
  889. valueWithTimeout: 400.
  890. ]
  891. valueWithTimeout: 1500
  892. !
  893. show
  894. self appendToJQuery: 'body' asJQuery
  895. ! !
  896. !HLInformationWidget methodsFor: 'rendering'!
  897. renderContentOn: html
  898. html div
  899. class: 'growl';
  900. with: self informationString.
  901. self remove
  902. ! !
  903. HLWidget subclass: #HLManager
  904. instanceVariableNames: 'tabsWidget environment history announcer rendered'
  905. package: 'Helios-Core'!
  906. !HLManager commentStamp!
  907. HLManager is the entry point Class of Helios.
  908. Its `singleton` instance is created on startup, and rendered on body.!
  909. !HLManager methodsFor: 'accessing'!
  910. activeTab
  911. ^ self tabsWidget activeTab
  912. !
  913. announcer
  914. ^ announcer ifNil: [ announcer := Announcer new ]
  915. !
  916. environment
  917. "The default environment used by all Helios objects"
  918. ^ environment ifNil: [ environment := self defaultEnvironment ]
  919. !
  920. environment: anEnvironment
  921. environment := anEnvironment
  922. !
  923. history
  924. ^ history ifNil: [ history := OrderedCollection new ]
  925. !
  926. history: aCollection
  927. history := aCollection
  928. !
  929. keyBinder
  930. ^ HLKeyBinder current
  931. !
  932. setEditorTheme: aTheme
  933. 'helios.editorTheme' asSetting value: aTheme
  934. !
  935. setTheme: aTheme
  936. | currentTheme |
  937. currentTheme := 'helios.theme' asSettingIfAbsent: 'default'.
  938. 'body' asJQuery
  939. removeClass: currentTheme value;
  940. addClass: aTheme.
  941. 'helios.theme' asSetting value: aTheme
  942. !
  943. tabWidth
  944. ^ (window asJQuery width - 90) / self tabs size
  945. !
  946. tabs
  947. ^ self tabsWidget tabs
  948. !
  949. tabsWidget
  950. ^ tabsWidget ifNil: [ tabsWidget := HLTabsWidget new ]
  951. ! !
  952. !HLManager methodsFor: 'actions'!
  953. activate: aTab
  954. self tabsWidget activate: aTab
  955. !
  956. addTab: aTab
  957. self tabsWidget addTab: aTab
  958. !
  959. confirm: aString ifFalse: aBlock
  960. self
  961. confirm: aString
  962. ifTrue: []
  963. ifFalse: aBlock
  964. !
  965. confirm: aString ifTrue: aBlock
  966. self
  967. confirm: aString
  968. ifTrue: aBlock
  969. ifFalse: []
  970. !
  971. confirm: aString ifTrue: aBlock ifFalse: anotherBlock
  972. HLConfirmationWidget new
  973. confirmationString: aString;
  974. actionBlock: aBlock;
  975. cancelBlock: anotherBlock;
  976. show
  977. !
  978. handleLossOfEnvironmentWithParent: parent
  979. parent at: 'onunload' put: [
  980. self removeBeforeUnloadMessage.
  981. window close ]
  982. !
  983. inform: aString
  984. HLInformationWidget new
  985. informationString: aString;
  986. show
  987. !
  988. removeActiveTab
  989. self tabsWidget removeActiveTab
  990. !
  991. removeBeforeUnloadMessage
  992. <inlineJS: 'window.onbeforeunload = null'>
  993. !
  994. removeTabForWidget: aWidget
  995. self tabsWidget removeTabForWidget: aWidget
  996. !
  997. request: aString do: aBlock
  998. self
  999. request: aString
  1000. value: ''
  1001. do: aBlock
  1002. !
  1003. request: aString value: valueString do: aBlock
  1004. HLRequestWidget new
  1005. confirmationString: aString;
  1006. actionBlock: aBlock;
  1007. value: valueString;
  1008. show
  1009. ! !
  1010. !HLManager methodsFor: 'defaults'!
  1011. defaultEnvironment
  1012. "If helios is loaded from within a frame, answer the parent window environment"
  1013. | parent parentSmalltalkGlobals |
  1014. parent := window opener ifNil: [ window parent ].
  1015. parent ifNil: [ ^ Environment new ].
  1016. [ parentSmalltalkGlobals := ((parent at: 'requirejs') value: 'amber/boot') at: 'globals' ]
  1017. on: Error do: [ parentSmalltalkGlobals := (parent at: 'requirejs') value: 'amber_vm/globals' ].
  1018. parentSmalltalkGlobals ifNil: [ ^ Environment new ].
  1019. self handleLossOfEnvironmentWithParent: parent.
  1020. ^ (parentSmalltalkGlobals at: 'Environment') new
  1021. ! !
  1022. !HLManager methodsFor: 'initialization'!
  1023. initialize
  1024. super initialize.
  1025. rendered := false
  1026. !
  1027. setup
  1028. self
  1029. registerServices;
  1030. setupEvents.
  1031. self keyBinder setupEvents.
  1032. self tabsWidget setupEvents.
  1033. self setupTheme.
  1034. '#helper' asJQuery fadeOut
  1035. ! !
  1036. !HLManager methodsFor: 'private'!
  1037. registerServices
  1038. self
  1039. registerInspector;
  1040. registerErrorHandler;
  1041. registerProgressHandler;
  1042. registerTranscript;
  1043. registerFinder
  1044. !
  1045. setupEvents
  1046. 'body' asJQuery keydown: [ :event |
  1047. "On ctrl keydown, adds a 'navigation' css class to <body>
  1048. for the CodeMirror navigation links. See `HLCodeWidget`."
  1049. event ctrlKey ifTrue: [
  1050. 'body' asJQuery addClass: 'navigation' ] ].
  1051. 'body' asJQuery keyup: [ :event |
  1052. 'body' asJQuery removeClass: 'navigation' ].
  1053. window asJQuery resize: [ :event |
  1054. self refresh ]
  1055. !
  1056. setupTheme
  1057. "self
  1058. setTheme: 'niflheim';
  1059. setEditorTheme: 'niflheim'."
  1060. self
  1061. setTheme: 'default';
  1062. setEditorTheme: 'default'.
  1063. ! !
  1064. !HLManager methodsFor: 'rendering'!
  1065. renderContentOn: html
  1066. html with: self tabsWidget.
  1067. html with: HLWelcomeWidget new.
  1068. self renderDefaultTabs.
  1069. rendered := true
  1070. !
  1071. renderDefaultTabs
  1072. rendered ifFalse: [
  1073. HLWorkspace openAsTab.
  1074. HLBrowser openAsTab ]
  1075. ! !
  1076. !HLManager methodsFor: 'services'!
  1077. registerErrorHandler
  1078. self environment registerErrorHandler: HLErrorHandler new.
  1079. ErrorHandler register: HLErrorHandler new
  1080. !
  1081. registerFinder
  1082. self environment registerFinder: HLFinder new.
  1083. Finder register: HLFinder new
  1084. !
  1085. registerInspector
  1086. self environment registerInspector: HLInspector.
  1087. Inspector register: HLInspector
  1088. !
  1089. registerProgressHandler
  1090. self environment registerProgressHandler: HLProgressHandler new.
  1091. ProgressHandler register: HLProgressHandler new
  1092. !
  1093. registerTranscript
  1094. self environment registerTranscript: HLTranscriptHandler
  1095. ! !
  1096. HLManager class instanceVariableNames: 'current'!
  1097. !HLManager class methodsFor: 'accessing'!
  1098. current
  1099. ^ current ifNil: [ current := self basicNew initialize ]
  1100. ! !
  1101. !HLManager class methodsFor: 'initialization'!
  1102. setup
  1103. self current
  1104. setup;
  1105. appendToJQuery: 'body' asJQuery.
  1106. ('helios.confirmOnExit' settingValueIfAbsent: true) ifTrue: [
  1107. window onbeforeunload: [ 'Do you want to close Amber? All uncommitted changes will be lost.' ] ]
  1108. ! !
  1109. !HLManager class methodsFor: 'instance creation'!
  1110. new
  1111. "Use current instead"
  1112. self shouldNotImplement
  1113. ! !
  1114. HLWidget subclass: #HLModalWidget
  1115. instanceVariableNames: ''
  1116. package: 'Helios-Core'!
  1117. !HLModalWidget commentStamp!
  1118. I implement an abstract modal widget.!
  1119. !HLModalWidget methodsFor: 'actions'!
  1120. remove
  1121. '.dialog' asJQuery removeClass: 'active'.
  1122. [
  1123. '#overlay' asJQuery remove.
  1124. wrapper asJQuery remove
  1125. ] valueWithTimeout: 300
  1126. !
  1127. show
  1128. self appendToJQuery: 'body' asJQuery
  1129. ! !
  1130. !HLModalWidget methodsFor: 'private'!
  1131. giveFocusToButton: aButton
  1132. aButton asJQuery focus
  1133. ! !
  1134. !HLModalWidget methodsFor: 'rendering'!
  1135. hasButtons
  1136. ^ true
  1137. !
  1138. renderButtonsOn: html
  1139. !
  1140. renderContentOn: html
  1141. | confirmButton |
  1142. html div id: 'overlay'.
  1143. html div
  1144. class: 'dialog ', self cssClass;
  1145. with: [
  1146. self renderMainOn: html.
  1147. self hasButtons ifTrue: [
  1148. self renderButtonsOn: html ] ].
  1149. '.dialog' asJQuery addClass: 'active'.
  1150. self setupKeyBindings
  1151. !
  1152. renderMainOn: html
  1153. !
  1154. setupKeyBindings
  1155. '.dialog' asJQuery keyup: [ :e |
  1156. e keyCode = String esc asciiValue ifTrue: [ self cancel ] ]
  1157. ! !
  1158. HLModalWidget subclass: #HLConfirmationWidget
  1159. instanceVariableNames: 'cancelButtonLabel confirmButtonLabel confirmationString actionBlock cancelBlock'
  1160. package: 'Helios-Core'!
  1161. !HLConfirmationWidget commentStamp!
  1162. I display confirmation dialog.
  1163. ## API
  1164. HLWidget contains convenience methods like `HLWidget >> #confirm:ifTrue:` for creating confirmation dialogs.!
  1165. !HLConfirmationWidget methodsFor: 'accessing'!
  1166. actionBlock
  1167. ^ actionBlock ifNil: [ [] ]
  1168. !
  1169. actionBlock: aBlock
  1170. actionBlock := aBlock
  1171. !
  1172. cancelBlock
  1173. ^ cancelBlock ifNil: [ [] ]
  1174. !
  1175. cancelBlock: aBlock
  1176. cancelBlock := aBlock
  1177. !
  1178. cancelButtonLabel
  1179. ^ cancelButtonLabel ifNil: [ 'Cancel' ]
  1180. !
  1181. cancelButtonLabel: aString
  1182. ^ cancelButtonLabel := aString
  1183. !
  1184. confirmButtonLabel
  1185. ^ confirmButtonLabel ifNil: [ 'Confirm' ]
  1186. !
  1187. confirmButtonLabel: aString
  1188. ^ confirmButtonLabel := aString
  1189. !
  1190. confirmationString
  1191. ^ confirmationString ifNil: [ 'Confirm' ]
  1192. !
  1193. confirmationString: aString
  1194. confirmationString := aString
  1195. ! !
  1196. !HLConfirmationWidget methodsFor: 'actions'!
  1197. cancel
  1198. self cancelBlock value.
  1199. self remove
  1200. !
  1201. confirm
  1202. self remove.
  1203. self actionBlock value
  1204. ! !
  1205. !HLConfirmationWidget methodsFor: 'rendering'!
  1206. renderButtonsOn: html
  1207. | confirmButton |
  1208. html div
  1209. class: 'buttons';
  1210. with: [
  1211. html button
  1212. class: 'button';
  1213. with: self cancelButtonLabel;
  1214. onClick: [ self cancel ].
  1215. confirmButton := html button
  1216. class: 'button default';
  1217. with: self confirmButtonLabel;
  1218. onClick: [ self confirm ] ].
  1219. self giveFocusToButton:confirmButton
  1220. !
  1221. renderMainOn: html
  1222. html span
  1223. class: 'head';
  1224. with: self confirmationString
  1225. ! !
  1226. HLConfirmationWidget subclass: #HLRequestWidget
  1227. instanceVariableNames: 'input multiline value'
  1228. package: 'Helios-Core'!
  1229. !HLRequestWidget commentStamp!
  1230. I display a modal window requesting user input.
  1231. ## API
  1232. `HLWidget >> #request:do:` and `#request:value:do:` are convenience methods for creating modal request dialogs.!
  1233. !HLRequestWidget methodsFor: 'accessing'!
  1234. beMultiline
  1235. multiline := true
  1236. !
  1237. beSingleline
  1238. multiline := false
  1239. !
  1240. cssClass
  1241. ^ 'large'
  1242. !
  1243. value
  1244. ^ value ifNil: [ '' ]
  1245. !
  1246. value: aString
  1247. value := aString
  1248. ! !
  1249. !HLRequestWidget methodsFor: 'actions'!
  1250. confirm
  1251. | val |
  1252. val := input asJQuery val.
  1253. self remove.
  1254. self actionBlock value: val
  1255. ! !
  1256. !HLRequestWidget methodsFor: 'private'!
  1257. giveFocusToButton: aButton
  1258. ! !
  1259. !HLRequestWidget methodsFor: 'rendering'!
  1260. renderMainOn: html
  1261. super renderMainOn: html.
  1262. self isMultiline
  1263. ifTrue: [ input := html textarea ]
  1264. ifFalse: [ input := html input
  1265. type: 'text';
  1266. onKeyDown: [ :event |
  1267. event keyCode = 13 ifTrue: [
  1268. self confirm ] ];
  1269. yourself ].
  1270. input asJQuery
  1271. val: self value;
  1272. focus
  1273. ! !
  1274. !HLRequestWidget methodsFor: 'testing'!
  1275. isMultiline
  1276. ^ multiline ifNil: [ true ]
  1277. ! !
  1278. HLModalWidget subclass: #HLProgressWidget
  1279. instanceVariableNames: 'progressBars visible'
  1280. package: 'Helios-Core'!
  1281. !HLProgressWidget commentStamp!
  1282. I am a widget used to display progress modal dialogs.
  1283. My default instance is accessed with `HLProgressWidget class >> #default`.
  1284. See `HLProgressHandler` for usage.!
  1285. !HLProgressWidget methodsFor: 'accessing'!
  1286. progressBars
  1287. ^ progressBars ifNil: [ progressBars := OrderedCollection new ]
  1288. ! !
  1289. !HLProgressWidget methodsFor: 'actions'!
  1290. addProgressBar: aProgressBar
  1291. self show.
  1292. self progressBars add: aProgressBar.
  1293. aProgressBar appendToJQuery: (self wrapper asJQuery find: '.dialog')
  1294. !
  1295. do: aBlock on: aCollection displaying: aString
  1296. | progressBar |
  1297. progressBar := HLProgressBarWidget new
  1298. parent: self;
  1299. label: aString;
  1300. workBlock: aBlock;
  1301. collection: aCollection;
  1302. yourself.
  1303. self addProgressBar: progressBar.
  1304. progressBar start
  1305. !
  1306. flush
  1307. self progressBars do: [ :each |
  1308. self removeProgressBar: each ]
  1309. !
  1310. remove
  1311. self isVisible ifTrue: [
  1312. visible := false.
  1313. super remove ]
  1314. !
  1315. removeProgressBar: aProgressBar
  1316. self progressBars remove: aProgressBar ifAbsent: [].
  1317. aProgressBar wrapper asJQuery remove.
  1318. self progressBars ifEmpty: [ self remove ]
  1319. !
  1320. show
  1321. self isVisible ifFalse: [
  1322. visible := true.
  1323. super show ]
  1324. ! !
  1325. !HLProgressWidget methodsFor: 'rendering'!
  1326. renderMainOn: html
  1327. self progressBars do: [ :each |
  1328. html with: each ]
  1329. ! !
  1330. !HLProgressWidget methodsFor: 'testing'!
  1331. hasButtons
  1332. ^ false
  1333. !
  1334. isVisible
  1335. ^ visible ifNil: [ false ]
  1336. ! !
  1337. HLProgressWidget class instanceVariableNames: 'default'!
  1338. !HLProgressWidget class methodsFor: 'accessing'!
  1339. default
  1340. ^ default ifNil: [ default := self new ]
  1341. ! !
  1342. HLModalWidget subclass: #HLTabSelectionWidget
  1343. instanceVariableNames: 'tabs tabList selectedTab selectCallback cancelCallback confirmCallback'
  1344. package: 'Helios-Core'!
  1345. !HLTabSelectionWidget commentStamp!
  1346. I am a modal window used to select or create tabs.!
  1347. !HLTabSelectionWidget methodsFor: 'accessing'!
  1348. cancelCallback
  1349. ^ cancelCallback ifNil: [ [] ]
  1350. !
  1351. cancelCallback: aBlock
  1352. cancelCallback := aBlock
  1353. !
  1354. confirmCallback
  1355. ^ confirmCallback ifNil: [ [] ]
  1356. !
  1357. confirmCallback: aBlock
  1358. confirmCallback := aBlock
  1359. !
  1360. selectCallback
  1361. ^ selectCallback ifNil: [ [] ]
  1362. !
  1363. selectCallback: aBlock
  1364. selectCallback := aBlock
  1365. !
  1366. selectedTab
  1367. ^ selectedTab
  1368. !
  1369. selectedTab: aTab
  1370. selectedTab := aTab
  1371. !
  1372. tabs
  1373. ^ tabs ifNil: [ #() ]
  1374. !
  1375. tabs: aCollection
  1376. tabs := aCollection
  1377. ! !
  1378. !HLTabSelectionWidget methodsFor: 'actions'!
  1379. cancel
  1380. self remove.
  1381. self cancelCallback value
  1382. !
  1383. confirm
  1384. self remove.
  1385. self confirmCallback value: self selectedTab
  1386. !
  1387. selectTab: aTab
  1388. self selectedTab: aTab.
  1389. self selectCallback value: aTab
  1390. !
  1391. setupKeyBindings
  1392. super setupKeyBindings.
  1393. '.dialog' asJQuery keyup: [ :e |
  1394. e keyCode = String cr asciiValue ifTrue: [ self confirm ] ]
  1395. ! !
  1396. !HLTabSelectionWidget methodsFor: 'rendering'!
  1397. renderButtonsOn: html
  1398. | confirmButton |
  1399. html div
  1400. class: 'buttons';
  1401. with: [
  1402. html button
  1403. class: 'button';
  1404. with: 'Cancel';
  1405. onClick: [ self cancel ].
  1406. confirmButton := html button
  1407. class: 'button default';
  1408. with: 'Select tab';
  1409. onClick: [ self confirm ] ].
  1410. self giveFocusToButton:confirmButton
  1411. !
  1412. renderContentOn: html
  1413. super renderContentOn: html.
  1414. self tabList focus
  1415. !
  1416. renderMainOn: html
  1417. html div
  1418. class: 'title';
  1419. with: 'Tab selection'.
  1420. html with: self tabList
  1421. !
  1422. renderTab: aTab on: html
  1423. html
  1424. span
  1425. class: aTab cssClass;
  1426. with: aTab label
  1427. !
  1428. renderTabsOn: html
  1429. self tabs do: [ :each |
  1430. html li with: [
  1431. html a
  1432. with: [
  1433. self renderTab: each on: html ];
  1434. onClick: [ self selectTab: each ] ] ]
  1435. !
  1436. tabList
  1437. tabList ifNil: [
  1438. tabList := HLTabListWidget new.
  1439. tabList
  1440. callback: [ :tab | self selectTab: tab. tabList focus ];
  1441. selectedItem: self selectedTab;
  1442. items: self tabs ].
  1443. ^ tabList
  1444. ! !
  1445. HLWidget subclass: #HLProgressBarWidget
  1446. instanceVariableNames: 'label parent workBlock collection bar'
  1447. package: 'Helios-Core'!
  1448. !HLProgressBarWidget commentStamp!
  1449. I am a widget used to display a progress bar while iterating over a collection.!
  1450. !HLProgressBarWidget methodsFor: 'accessing'!
  1451. collection
  1452. ^ collection
  1453. !
  1454. collection: aCollection
  1455. collection := aCollection
  1456. !
  1457. label
  1458. ^ label
  1459. !
  1460. label: aString
  1461. label := aString
  1462. !
  1463. parent
  1464. ^ parent
  1465. !
  1466. parent: aProgress
  1467. parent := aProgress
  1468. !
  1469. workBlock
  1470. ^ workBlock
  1471. !
  1472. workBlock: aBlock
  1473. workBlock := aBlock
  1474. ! !
  1475. !HLProgressBarWidget methodsFor: 'actions'!
  1476. evaluateAt: anInteger
  1477. self updateProgress: (anInteger / self collection size) * 100.
  1478. anInteger <= self collection size
  1479. ifTrue: [
  1480. [
  1481. self workBlock value: (self collection at: anInteger).
  1482. self evaluateAt: anInteger + 1 ] fork ]
  1483. ifFalse: [ [ self remove ] valueWithTimeout: 500 ]
  1484. !
  1485. remove
  1486. self parent removeProgressBar: self
  1487. !
  1488. start
  1489. "Make sure the UI has some time to update itself between each iteration"
  1490. self evaluateAt: 1
  1491. !
  1492. updateProgress: anInteger
  1493. bar asJQuery css: 'width' put: anInteger asString, '%'
  1494. ! !
  1495. !HLProgressBarWidget methodsFor: 'rendering'!
  1496. renderContentOn: html
  1497. html span with: self label.
  1498. console log: 'progress bar: '; log: self label.
  1499. html div
  1500. class: 'progress';
  1501. with: [
  1502. bar := html div
  1503. class: 'progress-bar';
  1504. style: 'width: 0%' ]
  1505. ! !
  1506. HLProgressBarWidget class instanceVariableNames: 'default'!
  1507. !HLProgressBarWidget class methodsFor: 'accessing'!
  1508. default
  1509. ^ default ifNil: [ default := self new ]
  1510. ! !
  1511. HLWidget subclass: #HLSpotlightWidget
  1512. instanceVariableNames: 'input'
  1513. package: 'Helios-Core'!
  1514. !HLSpotlightWidget methodsFor: 'accessing'!
  1515. ghostText
  1516. ^ 'Search... (Ctrl+F)'
  1517. !
  1518. inputCompletion
  1519. ^ self manager environment availableClassNames, self manager environment allSelectors
  1520. ! !
  1521. !HLSpotlightWidget methodsFor: 'actions'!
  1522. findMatches: aQueryString andRender: aRenderCallback
  1523. | matches |
  1524. matches := self inputCompletion select: [ :each | each match: aQueryString ].
  1525. aRenderCallback value: matches
  1526. !
  1527. search: aString
  1528. "open a new Browser pointing to aString"
  1529. aString ifNotEmpty: [
  1530. Finder findString: aString ]
  1531. ! !
  1532. !HLSpotlightWidget methodsFor: 'rendering'!
  1533. renderContentOn: html
  1534. input := html input
  1535. class: 'spotlight typeahead';
  1536. placeholder: self ghostText;
  1537. onKeyDown: [ :event |
  1538. event which = 13 ifTrue: [
  1539. self search: input asJQuery val ] ]
  1540. yourself.
  1541. input asJQuery
  1542. typeahead: #{ 'hint' -> true }
  1543. value: #{ 'name' -> 'classesAndSelectors'.
  1544. 'displayKey' -> [ :suggestion | suggestion asString ].
  1545. 'source' -> [ :query :callback | self findMatches: query andRender: callback ]}.
  1546. "use additional datasets for grouping into classes and selectors"
  1547. ! !
  1548. HLWidget subclass: #HLTabWidget
  1549. instanceVariableNames: 'widget label root'
  1550. package: 'Helios-Core'!
  1551. !HLTabWidget commentStamp!
  1552. I am a widget specialized into building another widget as an Helios tab.
  1553. I should not be used directly, `HLWidget class >> #openAsTab` should be used instead.
  1554. ## Example
  1555. HLWorkspace openAsTab!
  1556. !HLTabWidget methodsFor: 'accessing'!
  1557. activate
  1558. self manager activate: self
  1559. !
  1560. cssClass
  1561. ^ self widget tabClass
  1562. !
  1563. focus
  1564. self widget canHaveFocus ifTrue: [
  1565. self widget focus ]
  1566. !
  1567. label
  1568. ^ label ifNil: [ '' ]
  1569. !
  1570. label: aString
  1571. label := aString
  1572. !
  1573. manager
  1574. ^ HLManager current
  1575. !
  1576. widget
  1577. ^ widget
  1578. !
  1579. widget: aWidget
  1580. widget := aWidget
  1581. ! !
  1582. !HLTabWidget methodsFor: 'actions'!
  1583. add
  1584. self manager addTab: self.
  1585. self observeManager
  1586. !
  1587. hide
  1588. root ifNotNil: [ root asJQuery css: 'visibility' put: 'hidden' ]
  1589. !
  1590. observeManager
  1591. self manager announcer
  1592. on: HLTabLabelChanged
  1593. send: #onTabLabelChanged:
  1594. to: self
  1595. !
  1596. registerBindings
  1597. self widget registerBindings
  1598. !
  1599. remove
  1600. self unregister.
  1601. self widget unregister.
  1602. root ifNotNil: [ root asJQuery remove ]
  1603. !
  1604. show
  1605. root
  1606. ifNil: [ self appendToJQuery: 'body' asJQuery ]
  1607. ifNotNil: [ root asJQuery css: 'visibility' put: 'visible' ]
  1608. !
  1609. unregister
  1610. self manager announcer unsubscribe: self
  1611. ! !
  1612. !HLTabWidget methodsFor: 'reactions'!
  1613. onTabLabelChanged: anAnnouncement
  1614. anAnnouncement widget = self widget ifTrue: [
  1615. self label = anAnnouncement label ifFalse: [
  1616. self label: anAnnouncement label.
  1617. self manager refresh ] ]
  1618. ! !
  1619. !HLTabWidget methodsFor: 'rendering'!
  1620. renderOn: html
  1621. root := html div
  1622. class: 'tab';
  1623. yourself.
  1624. self renderTab
  1625. !
  1626. renderTab
  1627. root contents: [ :html |
  1628. html div
  1629. class: 'amber_box';
  1630. with: [ self widget renderOn: html ] ]
  1631. ! !
  1632. !HLTabWidget methodsFor: 'testing'!
  1633. isActive
  1634. ^ self manager activeTab = self
  1635. ! !
  1636. !HLTabWidget class methodsFor: 'instance creation'!
  1637. on: aWidget labelled: aString
  1638. ^ self new
  1639. widget: aWidget;
  1640. label: aString;
  1641. yourself
  1642. ! !
  1643. HLWidget subclass: #HLTabsWidget
  1644. instanceVariableNames: 'tabs activeTab history selectionDisabled spotlight'
  1645. package: 'Helios-Core'!
  1646. !HLTabsWidget methodsFor: 'accessing'!
  1647. activeTab
  1648. ^ activeTab
  1649. !
  1650. history
  1651. ^ history ifNil: [ history := OrderedCollection new ]
  1652. !
  1653. history: aCollection
  1654. history := aCollection
  1655. !
  1656. spotlight
  1657. ^ spotlight ifNil: [ spotlight := HLSpotlightWidget new ]
  1658. !
  1659. tabWidth
  1660. ^ (window asJQuery width - 250) / self tabs size
  1661. !
  1662. tabs
  1663. ^ tabs ifNil: [ tabs := OrderedCollection new ]
  1664. ! !
  1665. !HLTabsWidget methodsFor: 'actions'!
  1666. activate: aTab
  1667. self isSelectionDisabled ifTrue: [ ^ self ].
  1668. self manager keyBinder flushBindings.
  1669. aTab registerBindings.
  1670. activeTab := aTab.
  1671. self
  1672. refresh;
  1673. addToHistory: aTab;
  1674. show: aTab
  1675. !
  1676. activateNextTab
  1677. | nextTab |
  1678. self tabs ifEmpty: [ ^ self ].
  1679. nextTab := self tabs
  1680. at: (self tabs indexOf: self activeTab) + 1
  1681. ifAbsent: [ self tabs first ].
  1682. self activate: nextTab
  1683. !
  1684. activatePreviousTab
  1685. | previousTab |
  1686. self tabs ifEmpty: [ ^ self ].
  1687. previousTab := self tabs
  1688. at: (self tabs indexOf: self activeTab) - 1
  1689. ifAbsent: [ self tabs last ].
  1690. self activate: previousTab
  1691. !
  1692. addTab: aTab
  1693. self tabs add: aTab.
  1694. self activate: aTab
  1695. !
  1696. addToHistory: aTab
  1697. self removeFromHistory: aTab.
  1698. self history add: aTab
  1699. !
  1700. disableSelection
  1701. selectionDisabled := true
  1702. !
  1703. enableSelection
  1704. selectionDisabled := false
  1705. !
  1706. removeActiveTab
  1707. self removeTab: self activeTab
  1708. !
  1709. removeFromHistory: aTab
  1710. self history: (self history reject: [ :each | each == aTab ])
  1711. !
  1712. removeTab: aTab
  1713. (self tabs includes: aTab) ifFalse: [ ^ self ].
  1714. self removeFromHistory: aTab.
  1715. self tabs remove: aTab.
  1716. self manager keyBinder flushBindings.
  1717. aTab remove.
  1718. self refresh.
  1719. self history ifNotEmpty: [
  1720. self history last activate ]
  1721. !
  1722. removeTabForWidget: aWidget
  1723. self removeTab: (self tabs
  1724. detect: [ :each | each widget = aWidget ]
  1725. ifNone: [ ^ self ])
  1726. !
  1727. updateTabsOrder
  1728. tabs := '.nav-tabs li' asJQuery toArray
  1729. collect: [ :each | each at: 'tab-data' ]
  1730. ! !
  1731. !HLTabsWidget methodsFor: 'private'!
  1732. setupEvents
  1733. 'body' asJQuery keydown: [ :event |
  1734. "ctrl+> and ctrl+<"
  1735. (event ctrlKey and: [ event which = 188 ]) ifTrue: [
  1736. self activatePreviousTab.
  1737. event preventDefault ].
  1738. (event ctrlKey and: [ event which = 190 ]) ifTrue: [
  1739. self activateNextTab.
  1740. event preventDefault ] ]
  1741. ! !
  1742. !HLTabsWidget methodsFor: 'rendering'!
  1743. renderAddOn: html
  1744. html div
  1745. class: 'dropdown new_tab';
  1746. with: [
  1747. html a
  1748. class: 'dropdown-toggle';
  1749. at: 'data-toggle' put: 'dropdown';
  1750. with: [
  1751. (html tag: 'b') class: 'caret' ].
  1752. html ul
  1753. class: 'dropdown-menu';
  1754. with: [
  1755. ((HLWidget withAllSubclasses
  1756. select: [ :each | each canBeOpenAsTab ])
  1757. sorted: [ :a :b | a tabPriority < b tabPriority ])
  1758. do: [ :each |
  1759. html li with: [
  1760. html a
  1761. with: each tabLabel;
  1762. onClick: [ each openAsTab ] ] ] ] ]
  1763. !
  1764. renderContentOn: html
  1765. html div
  1766. class: 'navbar navbar-fixed-top';
  1767. with: [ html div
  1768. class: 'navbar-header';
  1769. at: 'role' put: 'tabpanel';
  1770. with: [ self renderTabsOn: html ] ].
  1771. html with: self spotlight.
  1772. self renderAddOn: html
  1773. !
  1774. renderTab: aTab on: html
  1775. | li |
  1776. li := html li
  1777. style: 'width: ', self tabWidth asString, 'px';
  1778. class: (aTab isActive ifTrue: [ 'tab active' ] ifFalse: [ 'tab inactive' ]);
  1779. with: [
  1780. html a
  1781. with: [
  1782. ((html tag: 'i') class: 'close')
  1783. onClick: [ self removeTab: aTab ].
  1784. html span
  1785. class: aTab cssClass;
  1786. title: aTab label;
  1787. with: aTab label ];
  1788. at: 'role' put: 'tab'];
  1789. onClick: [ aTab activate ].
  1790. li asDomNode at: 'tab-data' put: aTab
  1791. !
  1792. renderTabsOn: html
  1793. | ul |
  1794. ul := html ul
  1795. class: 'nav navbar-nav nav-tabs';
  1796. at: 'role' put: 'tablist';
  1797. with: [
  1798. self tabs do: [ :each |
  1799. self renderTab: each on: html ] ].
  1800. ul asJQuery sortable: #{
  1801. 'containment' -> 'parent'.
  1802. 'start' -> [ self disableSelection ].
  1803. 'stop' -> [ [ self enableSelection] valueWithTimeout: 300 ].
  1804. 'update' -> [ self updateTabsOrder ]
  1805. }
  1806. !
  1807. show: aTab
  1808. self tabs do: [ :each | each hide ].
  1809. aTab show; focus
  1810. ! !
  1811. !HLTabsWidget methodsFor: 'testing'!
  1812. isSelectionDisabled
  1813. ^ selectionDisabled ifNil: [ false ]
  1814. ! !
  1815. HLTabsWidget class instanceVariableNames: 'current'!
  1816. HLWidget subclass: #HLWelcomeWidget
  1817. instanceVariableNames: ''
  1818. package: 'Helios-Core'!
  1819. !HLWelcomeWidget methodsFor: 'accessing'!
  1820. cssClass
  1821. ^ 'welcome'
  1822. ! !
  1823. !HLWelcomeWidget methodsFor: 'actions'!
  1824. openClassBrowser
  1825. HLBrowser openAsTab
  1826. !
  1827. openHelp
  1828. !
  1829. openTestRunner
  1830. HLSUnit openAsTab
  1831. !
  1832. openWorkspace
  1833. HLWorkspace openAsTab
  1834. ! !
  1835. !HLWelcomeWidget methodsFor: 'rendering'!
  1836. renderButtonsOn: html
  1837. html button
  1838. class: 'button';
  1839. with: 'Class Browser';
  1840. onClick: [ self openClassBrowser ].
  1841. html button
  1842. class: 'button';
  1843. with: 'Workspace';
  1844. onClick: [ self openWorkspace ].
  1845. html button
  1846. class: 'button';
  1847. with: 'Test Runner';
  1848. onClick: [ self openTestRunner ].
  1849. "html button
  1850. class: 'button';
  1851. with: 'Help';
  1852. onClick: [ self openHelp ]"
  1853. !
  1854. renderContentOn: html
  1855. self
  1856. renderHelpOn: html;
  1857. renderButtonsOn: html
  1858. !
  1859. renderHelpOn: html
  1860. html h2 with: 'No tools are open'.
  1861. html ul with: [
  1862. html li with: 'Perform actions with ctrl + space'.
  1863. html li with: 'Open one of the common tools:' ]
  1864. ! !