Helios-Core.st 47 KB

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