Skip to content

Commit

Permalink
Edit scope and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
carolahp committed Oct 15, 2023
1 parent 2c319d6 commit 05a4b47
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 25 deletions.
25 changes: 20 additions & 5 deletions src/NewTools-Scopes-Browser/ScopeNodesPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,20 @@ ScopeNodesPresenter >> addNode: aNode [
self refreshCheckbox
]

{ #category : 'announcements' }
{ #category : 'as yet unclassified' }
ScopeNodesPresenter >> allScopeNodeTreeRoots [

^ allScopeNodeTreeRoots ifNil: [
allScopeNodeTreeRoots := model allPackagesInEnvironment collect: [
:package | ScopePackageNode on: package ] ]
]

{ #category : 'announcements' }
ScopeNodesPresenter >> announceScopeEdited [

self announcer announce: (ScopeEditedAnnouncement new)
]

{ #category : 'private - presenters' }
ScopeNodesPresenter >> argumentsListMenu [
^ self newMenu
Expand Down Expand Up @@ -222,7 +228,6 @@ ScopeNodesPresenter >> nodesListColumn [
ScopeNodesPresenter >> openScopeNameDialog [

| nameDialog |
self halt.
nameDialog := (ScopeNamePresenter on: model)
newScope: scope;
yourself.
Expand Down Expand Up @@ -287,9 +292,19 @@ ScopeNodesPresenter >> removeNode: aNode [

{ #category : 'initialization' }
ScopeNodesPresenter >> saveScope [
self halt.
self initializeScope.
self openScopeNameDialog

scope
ifNil: [
self initializeScope.
self openScopeNameDialog ]
ifNotNil: [
| editedScope |
editedScope := model newScopeFrom: checkedScopeNodes.
editedScope label: scope label.
model removeScope: scope.
model addScope: editedScope.
self announceScopeEdited.
self close ]
]

{ #category : 'accessing' }
Expand Down
52 changes: 32 additions & 20 deletions src/NewTools-Scopes-Browser/ScopesPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ ScopesPresenter class >> title [
ScopesPresenter >> addScopeToTree: aRBEnvironment [

model addScope: aRBEnvironment.
scopesTree updateRootsKeepingSelection:
(model scopes collect: [ :scope | ScopeScopeNode on: scope ])
asOrderedCollection sorted
self updateScopesTree
]

{ #category : 'operations' }
Expand All @@ -89,7 +87,7 @@ ScopesPresenter >> argumentsListMenu [
visibleIf: [ scopesTree selectedItem isScopeNode ];
iconName: #glamorousEdit;
action: [
self newScopeSelector open ] ];
self editSelectedScope ] ];
addItem: [ :anItem |
anItem
name: 'Rename';
Expand Down Expand Up @@ -135,9 +133,16 @@ ScopesPresenter >> deleteSelectedScope [
scopesTree selectedItems
select: [ :item | item isScopeNode ]
thenDo: [ :item | model removeScope: item ].
scopesTree updateRootsKeepingSelection:
(model scopes collect: [ :scope | ScopeScopeNode on: scope ])
asOrderedCollection sorted.
self updateScopesTree
]

{ #category : 'menu commands' }
ScopesPresenter >> editSelectedScope [

(scopesTree selectedItem isNil or: [
scopesTree selectedItem isScopeNode not ])
ifTrue: [ self inform: 'select a scope' ]
ifFalse: [ self newScopeEditor open ]
]

{ #category : 'initialization' }
Expand All @@ -157,14 +162,16 @@ ScopesPresenter >> initializePresenters [

{ #category : 'initialization' }
ScopesPresenter >> initializeScopesTree [

^ scopesTree
hideColumnHeaders;
addColumn: self nodesListColumn;
children: [ :each | each children sorted ];
beMultipleSelection;
roots:
(model scopes collect: [ :package |
ScopeScopeNode on: package ]) asOrderedCollection sorted;
(model scopes collect: [ :package | ScopeScopeNode on: package ])
asOrderedCollection sorted;
expandRoots;
beResizable;
activateOnDoubleClick;
whenActivatedDo: [ :selection | scopesTree toggleSelectedItems ];
Expand All @@ -180,11 +187,8 @@ ScopesPresenter >> newScopeCreator [
{ #category : 'private' }
ScopesPresenter >> newScopeEditor [

| item |
item := scopesTree selectedItem.
self assert: item isScopeNode.
^ self newScopeCreator
scope: item value;
scope: scopesTree selectedItem value;
yourself
]

Expand Down Expand Up @@ -226,7 +230,6 @@ ScopesPresenter >> openOnCalypso: aScope [
{ #category : 'menu commands' }
ScopesPresenter >> openScopeNameDialog [
| nameDialog |
self halt.
nameDialog := (ScopeNamePresenter on: model)
newScope: scopesTree selectedItem value;
yourself.
Expand Down Expand Up @@ -257,19 +260,21 @@ ScopesPresenter >> performOperation: aSymbol with: anItem [
{ #category : 'refresh' }
ScopesPresenter >> refresh [
scopesTree roots ifEmpty: [ ^ self ].
scopesTree updateRootsKeepingSelection:
(model scopes collect: [ :scope | ScopeScopeNode on: scope ])
asOrderedCollection sorted
self updateScopesTree
]

{ #category : 'initialization' }
ScopesPresenter >> registerEvents [

self announcer
when: ScopeCreatedAnnouncement
do: [ :ann |
do: [ :ann |
model addScope: ann scope.
self addScopeToTree: ann scope ]
for: self.
self announcer
when: ScopeEditedAnnouncement
do: [ self updateScopesTree ]
for: self
]

Expand Down Expand Up @@ -320,8 +325,7 @@ ScopesPresenter >> toolbarButtons [
icon: (self iconNamed: #glamorousEdit);
help: 'Edit selected scope';
action: [
scopesTree selectedItem ifNil: [ ^ self ].
self newScopeEditor open ];
self editSelectedScope ];
yourself).

buttons add: (self newToolbarButton
Expand All @@ -332,3 +336,11 @@ ScopesPresenter >> toolbarButtons [

^ buttons
]

{ #category : 'initialization' }
ScopesPresenter >> updateScopesTree [

scopesTree updateRootsKeepingSelection:
(model scopes collect: [ :scope | ScopeScopeNode on: scope ])
asOrderedCollection sorted
]

0 comments on commit 05a4b47

Please sign in to comment.