Helios-Core.st 47 KB

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