Skip to content

Commit

Permalink
Adds keyboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeAtHPI committed Aug 2, 2023
1 parent afcd61b commit 3e5124c
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 81 deletions.
2 changes: 1 addition & 1 deletion packages/Sandblocks-Core/SBNamedBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SBNamedBlock >> initialize [

super initialize.

self name: 'A Tab'.
self name: 'A Block'.
self block: (SBLabel new contents: 'Some Content').
]

Expand Down
178 changes: 142 additions & 36 deletions packages/Sandblocks-Morphs/SBTabView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ SBTabView class >> example [
SBMorphExample
setUp: [self newEmpty]
cases: {SBMorphExampleCase name: 'example 1' caseBlock: [:m | m]}
extent: 300 @ 300
extent: 300 @ 300.


]

{ #category : #'as yet unclassified' }
Expand All @@ -31,6 +33,26 @@ SBTabView class >> newEmpty [
^ self new updateTabs
]

{ #category : #'as yet unclassified' }
SBTabView class >> registerShortcuts: aProvider [

aProvider registerShortcut: $n command do: #addTab.
aProvider registerShortcut: $w command do: #removeCurrentTab.
aProvider registerShortcut: Character arrowLeft do: #jumpToPrevious.
aProvider registerShortcut: Character arrowRight do: #jumpToNext.

aProvider registerShortcut: $1 do: #jumpToFirstTab.
aProvider registerShortcut: $2 do: #jumpToSecondTab.
aProvider registerShortcut: $3 do: #jumpToThirdTab.
aProvider registerShortcut: $4 do: #jumpToFourthTab.
aProvider registerShortcut: $5 do: #jumpToFifthTab.
aProvider registerShortcut: $6 do: #jumpToSixthTab.
aProvider registerShortcut: $7 do: #jumpToSeventhTab.
aProvider registerShortcut: $8 do: #jumpToEightTab.
aProvider registerShortcut: $9 do: #jumpToNinthTab.

]

{ #category : #'as yet unclassified' }
SBTabView >> active [

Expand All @@ -49,16 +71,6 @@ SBTabView >> activeIndex [
^ activeIndex
]

{ #category : #'as yet unclassified' }
SBTabView >> activeIndex: aNumber [

self activeTab makeSmall.

activeIndex := {aNumber. self namedBlocks size} min.

self updateSelectedTab
]

{ #category : #'as yet unclassified' }
SBTabView >> activeName [

Expand Down Expand Up @@ -95,6 +107,13 @@ SBTabView >> addButton [
layoutInset: (4.0 @ 4.0) sbScaled
]

{ #category : #'as yet unclassified' }
SBTabView >> addTab [
<action>

self add: (self namedBlocks last veryDeepCopy )
]

{ #category : #'as yet unclassified' }
SBTabView >> asTabButton: aNamedBlock [

Expand All @@ -103,15 +122,15 @@ SBTabView >> asTabButton: aNamedBlock [
label: aNamedBlock name do: [self setActive: aNamedBlock];
cornerStyle: #squared;
makeSmall;
hResizing: #spaceFill.
hResizing: #spaceFill;
changeTableLayout;
listDirection: #leftToRight;
addMorphBack: (self deleteButtonFor: aNamedBlock).

aNamedBlock = self active ifTrue: [button makeBold].
button when: #contentsChanged send: #updateNameFor:on: to: self withArguments: {aNamedBlock. button}.

^ button
changeTableLayout;
listDirection: #leftToRight;
addMorphBack: (self deleteButtonFor: aNamedBlock)
]

{ #category : #'as yet unclassified' }
Expand Down Expand Up @@ -149,12 +168,6 @@ SBTabView >> deleteButtonFor: aNamedBlock [
^ delete
]

{ #category : #'as yet unclassified' }
SBTabView >> fixedNumberOfChildren [

^ false
]

{ #category : #'as yet unclassified' }
SBTabView >> initialize [

Expand All @@ -170,6 +183,101 @@ SBTabView >> initialize [
vResizing: #shrinkWrap.
]

{ #category : #'shortcut-utility' }
SBTabView >> jumpToEightTab [

<action>
self jumpToTab: 8

]

{ #category : #'shortcut-utility' }
SBTabView >> jumpToFifthTab [

<action>
self jumpToTab: 5

]

{ #category : #'shortcut-utility' }
SBTabView >> jumpToFirstTab [

<action>
self jumpToTab: 1

]

{ #category : #'shortcut-utility' }
SBTabView >> jumpToFourthTab [

<action>
self jumpToTab: 4

]

{ #category : #'as yet unclassified' }
SBTabView >> jumpToNext [

<action>
self jumpToTab: self activeIndex \\ self namedBlocks size + 1

]

{ #category : #'shortcut-utility' }
SBTabView >> jumpToNinthTab [

<action>
self jumpToTab: 9

]

{ #category : #'as yet unclassified' }
SBTabView >> jumpToPrevious [

<action>
self jumpToTab: self activeIndex - 2 \\ self namedBlocks size + 1

]

{ #category : #'shortcut-utility' }
SBTabView >> jumpToSecondTab [

<action>
self jumpToTab: 2

]

{ #category : #'shortcut-utility' }
SBTabView >> jumpToSeventhTab [

<action>
self jumpToTab: 7

]

{ #category : #'shortcut-utility' }
SBTabView >> jumpToSixthTab [

<action>
self jumpToTab: 6

]

{ #category : #'as yet unclassified' }
SBTabView >> jumpToTab: anIndex [

self namedBlocks at: anIndex ifPresent: [:block | self setActive: block]

]

{ #category : #'shortcut-utility' }
SBTabView >> jumpToThirdTab [

<action>
self jumpToTab: 3

]

{ #category : #'as yet unclassified' }
SBTabView >> namedBlocks [

Expand All @@ -193,18 +301,6 @@ SBTabView >> namedBlocks: aCollectionOfSBNamedBlocks activeIndex: aNumber [
self updateTabs.
]

{ #category : #'as yet unclassified' }
SBTabView >> newEmptyChildNear: aBlock before: aBoolean [

^ SBNamedBlock new
]

{ #category : #'as yet unclassified' }
SBTabView >> objectInterfaceNear: aBlock at: aSymbol [

^ {[:o | o isKindOf: SBNamedBlock ]}
]

{ #category : #'as yet unclassified' }
SBTabView >> remove: aNamedBlock [

Expand All @@ -219,12 +315,19 @@ SBTabView >> remove: aNamedBlock [
self updateTabs
]

{ #category : #'as yet unclassified' }
SBTabView >> removeCurrentTab [
<action>

self remove: self active
]

{ #category : #'as yet unclassified' }
SBTabView >> setActive: aNamedBlock [

self activeTab makeSmall.

activeIndex := self namedBlocks indexOf: aNamedBlock ifAbsent: 1.
activeIndex := (self namedBlocks indexOf: aNamedBlock ifAbsent: 1).

self updateSelectedTab
]
Expand All @@ -251,7 +354,8 @@ SBTabView >> updateSelectedTab [
(self tabs at: activeIndex) makeBold.

"so that bold text does not go over its borders"
self tabs do: [:aButton | aButton widgetMorph hResizing: self hResizing]
self tabs do: [:aButton | aButton widgetMorph hResizing: self hResizing].
self triggerEvent: #changedActive.
]

{ #category : #'as yet unclassified' }
Expand All @@ -261,5 +365,7 @@ SBTabView >> updateTabs [

self
buildTabs;
buildView
buildView.

self triggerEvent: #changedActive
]
Loading

0 comments on commit 3e5124c

Please sign in to comment.