Helios-Core.st 44 KB

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