1
0

Helios-Core.st 46 KB

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