Skip to content

Commit

Permalink
Extend PolyglotNotebook
Browse files Browse the repository at this point in the history
- Add option to show language scopes
- Add menu to sidebar and enable support for shortcuts
  • Loading branch information
fniephaus committed Jun 28, 2021
1 parent 3545e00 commit 94a02ff
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
*TruffleSqueak-Tools-Editor-Core
addModelItemsToWindowMenu: aMenu

aMenu addLine.
aMenu
addUpdating: #toggleShowLanguageScopesLabel
target: self
action: #toggleShowLanguageScopes.

Smalltalk at: #PolyglotEditor ifPresent: [ :unused |
aMenu addLine.
aMenu
add: 'open in Polyglot Editor'
target: self
selector: #openInPolyglotEditor.
aMenu addLine ].
selector: #openInPolyglotEditor ].

super addModelItemsToWindowMenu: aMenu
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"class" : {
},
"instance" : {
"addModelItemsToWindowMenu:" : "fn 5/13/2020 16:26",
"addModelItemsToWindowMenu:" : "fn 6/28/2021 16:10",
"openInPolyglotEditor" : "fn 5/13/2020 12:06" } }
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ run
result ifNotNil: [self output displayResult: result.
self cellContainer changed: #submorphs].
self cellContainer notebook changed: #getList.
self cellContainer notebook changed: #expandRootsRequested.
self cellContainer notebook showLanguageScopes ifFalse: [
self cellContainer notebook changed: #expandRootsRequested ]
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"outputs:" : "fn 3/25/2019 18:49",
"outputsAsJson" : "fn 3/25/2019 18:17",
"remove" : "fn 3/27/2019 11:16",
"run" : "fn 6/20/2019 16:00",
"run" : "fn 6/28/2021 16:09",
"up" : "fn 3/27/2019 11:16" } }
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ buildSidebar: builder
model: self;
nodeClass: PNBBindingsWrapper;
roots: #getList;
"keyPress: #explorerKey:from:event:;"
keyPress: #explorerKey:from:event:;
getSelected: #currentSelection;
"setSelected: #currentSelection:;"
setSelected: #currentSelection:;
"setSelectedParent: #currentParent:;"
"menu: #genericMenu:;"
menu: #genericMenu:;
"dragItem: #getDragItem:;"
columns: (PNBBindingsWrapper showContentsInColumns
ifTrue: [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ buildWith: builder
window := builder build: windowSpec.
(window allMorphs select: [:m | m isKindOf: PluggableButtonMorphPlus ]) do: [:b | b borderWidth: 0].
(window allMorphs detect: [:m | m isKindOf: PluggableTreeMorph ]) borderWidth: 0; color: (Color fromString: '#F5F5F5').
self changed: #expandRootsRequested.
self showLanguageScopes ifFalse: [ self changed: #expandRootsRequested ].
^ window.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
model
currentSelection: anObject

self currentSelection == anObject ifTrue: [^ self].

currentSelection := anObject.

self changed: #currentSelection.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
model
currentSelection

^ 1
^ currentSelection
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
actions
explorerKey: aChar from: view event: event

event anyModifierKeyPressed ifFalse: [^ false].

self currentSelection ifNotNil: [ :obj |
aChar == $i ifTrue: [obj value inspect. ^ true].
aChar == $I ifTrue: [obj value explore. ^ true] ].

^ false
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
actions
genericMenu: aMenu
^ aMenu
add: 'inspect (i)'
target: self currentSelection value
selector: #inspect;
add: 'explore (I)'
target: self currentSelection value
selector: #explore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
model
getList
^ {'bindings' -> cellContainer bindings }
^ {'bindings' -> cellContainer bindings },
(self showLanguageScopes
ifTrue: [ Polyglot availableLanguages collect: [ :ea |
ea getName asString -> (Polyglot primitiveGetScope: ea getId asSymbol) ] ]
ifFalse: [ #() ])
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
actions
getMenu: shiftKeyState
^ (shiftKeyState not or: [Preferences noviceMode])
ifTrue: [TextEditor yellowButtonMenu]
ifFalse: [TextEditor shiftedYellowButtonMenu]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
showLanguageScopes
^ showLanguageScopes ifNil: [ showLanguageScopes := false ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
actions
toggleShowLanguageScopes
showLanguageScopes := self showLanguageScopes not.
self changed: #getList
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
actions
toggleShowLanguageScopesLabel

^self showLanguageScopes
ifTrue: [ '<on> show language scopes' ]
ifFalse: [ '<off> show language scopes' ]
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@
"actionRunAll" : "fn 3/30/2019 00:29",
"actionSave" : "fn 3/26/2019 11:55",
"buildCodePaneWith:" : "fn 3/27/2019 10:07",
"buildSidebar:" : "fn 2/10/2020 16:44",
"buildSidebar:" : "fn 6/28/2021 16:22",
"buildSwitchesWith:" : "fn 3/27/2019 10:38",
"buildWith:" : "fn 3/27/2019 10:36",
"buildWith:" : "fn 6/28/2021 16:09",
"buttonHeight" : "fn 3/27/2019 10:39",
"cellContainer" : "fn 4/13/2019 23:23",
"cellContainer:" : "fn 3/26/2019 11:31",
"contents" : "fn 4/13/2019 23:35",
"contentsSelection" : "fn 3/26/2019 09:19",
"currentSelection" : "fn 3/26/2019 09:22",
"currentSelection" : "fn 6/28/2021 16:16",
"currentSelection:" : "fn 6/28/2021 16:16",
"defaultWindowColor" : "fn 3/26/2019 12:06",
"getList" : "fn 6/27/2021 17:20",
"explorerKey:from:event:" : "fn 6/28/2021 16:17",
"genericMenu:" : "fn 6/28/2021 16:24",
"getList" : "fn 6/28/2021 16:07",
"getMenu:" : "fn 6/28/2021 16:21",
"showLanguageScopes" : "fn 6/28/2021 16:06",
"toggleShowLanguageScopes" : "fn 6/28/2021 16:12",
"toggleShowLanguageScopesLabel" : "fn 6/28/2021 16:12",
"topConstantHeightFrame:fromLeft:width:" : "fn 3/26/2019 09:32",
"uniformWindowColor" : "fn 3/26/2019 12:06" } }
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
],
"commentStamp" : "",
"instvars" : [
"cellContainer" ],
"cellContainer",
"currentSelection",
"showLanguageScopes" ],
"name" : "PolyglotNotebook",
"pools" : [
],
Expand Down

0 comments on commit 94a02ff

Please sign in to comment.