1
0

Helios-Core.st 47 KB

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