123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- Smalltalk current createPackage: 'Helios-Workspace' properties: #{}!
- Object subclass: #HLCodeModel
- instanceVariableNames: 'announcer environment receiver'
- package: 'Helios-Workspace'!
- !HLCodeModel methodsFor: 'accessing'!
- announcer
- ^ announcer ifNil: [ announcer := Announcer new ]
- !
- environment
- ^ environment ifNil: [ HLManager current environment ]
- !
- environment: anEnvironment
- environment := anEnvironment
- !
- receiver
- ^ receiver ifNil: [ receiver := self defaultReceiver ]
- !
- receiver: anObject
- receiver := anObject
- ! !
- !HLCodeModel methodsFor: 'actions'!
- doIt: someCode
- ^ self environment eval: someCode on: self receiver
- !
- subscribe: aWidget
- aWidget subscribeTo: self announcer
- ! !
- !HLCodeModel methodsFor: 'defaults'!
- defaultReceiver
- ^ DoIt new
- ! !
- !HLCodeModel class methodsFor: 'actions'!
- on: anEnvironment
- ^ self new
- environment: anEnvironment;
- yourself
- ! !
- HLWidget subclass: #HLCodeWidget
- instanceVariableNames: 'model wrapper code editor'
- package: 'Helios-Workspace'!
- !HLCodeWidget methodsFor: 'accessing'!
- announcer
- ^ self model announcer
- !
- contents
- ^ editor getValue
- !
- contents: aString
- editor setValue: aString
- !
- currentLine
- ^editor getLine: (editor getCursor line)
- !
- currentLineOrSelection
- ^editor somethingSelected
- ifFalse: [self currentLine]
- ifTrue: [self selection]
- !
- model
- ^ model ifNil: [
- self model: HLCodeModel new.
- model ]
- !
- model: aModel
- model := aModel
- !
- receiver
- ^ self model receiver
- !
- receiver: anObject
- self model receiver: anObject
- !
- selection
- ^editor getSelection
- !
- selectionEnd
- ^code element selectionEnd
- !
- selectionEnd: anInteger
- code element selectionEnd: anInteger
- !
- selectionStart
- ^code element selectionStart
- !
- selectionStart: anInteger
- code element selectionStart: anInteger
- ! !
- !HLCodeWidget methodsFor: 'actions'!
- clear
- self contents: ''
- !
- doIt
- | result |
- self announcer announce: (HLDoItRequested on: model).
- result:= model doIt: self currentLineOrSelection.
- self announcer announce: (HLDoItExecuted on: model).
- ^ result
- !
- editor
- ^editor
- !
- focus
- self editor focus
- !
- inspectIt
- | newInspector |
-
- self announcer announce: (HLInspectItRequested on: model).
- newInspector := self makeInspectorOn: self doIt.
- newInspector open
- !
- makeInspectorOn: anObject
- ^ HLInspector new
- inspect: anObject;
- yourself
- !
- observeWrapper
- wrapper onKeyDown: [ :e | self onKeyDown: e ]
- !
- print: aString
- | start stop |
- start := HashedCollection new.
- stop := HashedCollection new.
- start at: 'line' put: (editor getCursor: false) line.
- start at: 'ch' put: (editor getCursor: false) ch.
- stop at: 'line' put: (start at: 'line').
- stop at: 'ch' put: ((start at: 'ch') + aString size + 2).
- editor replaceSelection: (editor getSelection, ' ', aString, ' ').
- editor setCursor: (editor getCursor: true).
- editor setSelection: stop end: start
- !
- printIt
- | result |
- result:= self doIt.
-
- self announcer announce: (HLPrintItRequested on: model).
- self print: result printString.
- self focus.
- !
- setEditorOn: aTextarea
- <self['@editor'] = CodeMirror.fromTextArea(aTextarea, {
- theme: 'amber',
- lineNumbers: true,
- enterMode: 'flat',
- matchBrackets: true,
- electricChars: false
- })>
- ! !
- !HLCodeWidget methodsFor: 'reactions'!
- onDoIt
-
- self doIt
- !
- onInspectIt
- self inspectIt
- !
- onKeyDown: anEvent
- <if(anEvent.ctrlKey) {
- if(anEvent.keyCode === 80) { //ctrl+p
- self._onPrintIt();
- anEvent.preventDefault();
- return false;
- }
- if(anEvent.keyCode === 68) { //ctrl+d
- self._onDoIt();
- anEvent.preventDefault();
- return false;
- }
- if(anEvent.keyCode === 73) { //ctrl+i
- self._onInspectIt();
- anEvent.preventDefault();
- return false;
- }
- }>
- !
- onPrintIt
- self printIt
- ! !
- !HLCodeWidget methodsFor: 'rendering'!
- renderContentOn: html
- code := html textarea.
- self setEditorOn: code element.
-
- self observeWrapper
- ! !
- HLWidget subclass: #HLWorkspace
- instanceVariableNames: 'model codeWidget'
- package: 'Helios-Workspace'!
- !HLWorkspace methodsFor: 'accessing'!
- codeWidget
- ^ codeWidget ifNil: [
- codeWidget := HLCodeWidget new
- model: self model code;
- yourself ]
- !
- model
- ^ model ifNil: [
- self model: HLWorkspaceModel new.
- model ]
- !
- model: aModel
- model := aModel.
-
- self codeWidget model: aModel code.
- self observeCodeWidget.
- ! !
- !HLWorkspace methodsFor: 'actions'!
- observeCodeWidget
- ! !
- !HLWorkspace methodsFor: 'reactions'!
- onDoIt
- !
- onInspectIt
- !
- onPrintIt
- ! !
- !HLWorkspace methodsFor: 'rendering'!
- renderContentOn: html
- html with: self codeWidget
- ! !
- !HLWorkspace class methodsFor: 'accessing'!
- tabLabel
- ^ 'Workspace'
- !
- tabPriority
- ^ 10
- ! !
- !HLWorkspace class methodsFor: 'testing'!
- canBeOpenAsTab
- ^ true
- ! !
- Object subclass: #HLWorkspaceModel
- instanceVariableNames: 'announcer environment code'
- package: 'Helios-Workspace'!
- !HLWorkspaceModel methodsFor: 'accessing'!
- announcer
- ^ announcer ifNil: [ announcer := Announcer new ]
- !
- code
- "Answers the code model working for this workspace model"
- ^ code ifNil:[ HLCodeModel on: self environment ]
- !
- environment
- ^ environment ifNil: [ HLManager current environment ]
- !
- environment: anEnvironment
- environment := anEnvironment
- ! !
- !HLWorkspaceModel methodsFor: 'reactions'!
- onKeyDown: anEvent
- <if(anEvent.ctrlKey) {
- if(anEvent.keyCode === 80) { //ctrl+p
- self._printIt();
- anEvent.preventDefault();
- return false;
- }
- if(anEvent.keyCode === 68) { //ctrl+d
- self._doIt();
- anEvent.preventDefault();
- return false;
- }
- if(anEvent.keyCode === 73) { //ctrl+i
- self._inspectIt();
- anEvent.preventDefault();
- return false;
- }
- }>
- ! !
- !HLWorkspaceModel class methodsFor: 'actions'!
- on: anEnvironment
- ^ self new
- environment: anEnvironment;
- yourself
- ! !
|