Helios-Core.st 46 KB

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