Helios-Core.st 47 KB

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