Helios-Core.st 45 KB

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