Helios-Core.st 45 KB

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