From b9b73bd5e6319f26a9b378714701138740630ea3 Mon Sep 17 00:00:00 2001 From: Carolina Hernandez Date: Thu, 9 Nov 2023 09:23:58 -0300 Subject: [PATCH] Implements currentQueryScope variable to store the last selected scope in Calypso Query Browser --- .../ScopesPresenter.class.st | 4 +-- .../ScopesManagesOperationsTest.class.st | 25 +++++++++++++++-- .../RBCompositeEnvironment.extension.st | 11 ++++---- src/NewTools-Scopes/ScopesManager.class.st | 28 +++++++++++++++++-- 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/NewTools-Scopes-Editor/ScopesPresenter.class.st b/src/NewTools-Scopes-Editor/ScopesPresenter.class.st index a5c4e3f05..33fe07033 100644 --- a/src/NewTools-Scopes-Editor/ScopesPresenter.class.st +++ b/src/NewTools-Scopes-Editor/ScopesPresenter.class.st @@ -127,13 +127,13 @@ ScopesPresenter >> argumentsListMenu [ anItem name: 'AND'; visibleIf: [ scopesTree selectedItem isScopeNode ]; - action: [ self andWithScope: scopesTree selectedItem ] ]; + action: [ self andWithScope: scopesTree selectedItem ] ]"; addItem: [ :anItem | anItem name: 'NOT'; visibleIf: [ scopesTree selectedItem isScopeNode ]; - action: [ self notWithScope: scopesTree selectedItem ] ] ] + action: [ self notWithScope: scopesTree selectedItem ] ] "] ] { #category : 'menu commands' } diff --git a/src/NewTools-Scopes-Tests/ScopesManagesOperationsTest.class.st b/src/NewTools-Scopes-Tests/ScopesManagesOperationsTest.class.st index 0c5d79769..64d62311b 100644 --- a/src/NewTools-Scopes-Tests/ScopesManagesOperationsTest.class.st +++ b/src/NewTools-Scopes-Tests/ScopesManagesOperationsTest.class.st @@ -6,7 +6,26 @@ Class { } { #category : 'tests' } -ScopesManagesOperationsTest >> testAddClassAndFillPackageInOrEnvironment [ +ScopesManagesOperationsTest >> testAddClassToOrEnvironment [ + + | packageEnvB classEnv orEnv | + + "empty class environment" + + classEnv := RBBrowserEnvironment new forClasses: { }. + packageEnvB := RBBrowserEnvironment new forPackages: { ScClassB1 package }. + + orEnv := RBOrEnvironment onEnvironment: classEnv or: packageEnvB. + + orEnv addClass: ScClassA1. + orEnv addClass: ScClassA1 class. + + self assert: orEnv allClasses equals: { ScClassA1 . ScClassB1 }. + self assert: orEnv packages equals: { ScClassA1 package . ScClassB1 package } +] + +{ #category : 'tests' } +ScopesManagesOperationsTest >> testAddClassToOrEnvironmentMakingAPackageFull [ | packageEnv classEnvA1 orEnv | @@ -26,7 +45,7 @@ ScopesManagesOperationsTest >> testAddClassAndFillPackageInOrEnvironment [ ] { #category : 'tests' } -ScopesManagesOperationsTest >> testRemoveClassInClassEnvironmentFromOrEnvironment [ +ScopesManagesOperationsTest >> testRemoveClassFromOrEnvironment [ | classEnvA1 packageEnvB orEnv | @@ -41,7 +60,7 @@ ScopesManagesOperationsTest >> testRemoveClassInClassEnvironmentFromOrEnvironmen ] { #category : 'tests' } -ScopesManagesOperationsTest >> testRemoveClassInPackageEnvironmentFromOrEnvironment [ +ScopesManagesOperationsTest >> testRemoveClassFromOrEnvironmentBreakingFullPackage [ | packageEnvA classEnv orEnv | diff --git a/src/NewTools-Scopes/RBCompositeEnvironment.extension.st b/src/NewTools-Scopes/RBCompositeEnvironment.extension.st index 00543ad2c..5d4cba163 100644 --- a/src/NewTools-Scopes/RBCompositeEnvironment.extension.st +++ b/src/NewTools-Scopes/RBCompositeEnvironment.extension.st @@ -18,10 +18,10 @@ RBCompositeEnvironment >> addClass: aClass [ packaEnv := (envs select: [ :env | env isPackageEnvironment ]) anyOne. "Get the classes in the same package as aClass (siblings)" - siblings := classEnv allClasses select: [ :class | + siblings := classEnv classes select: [ :class | class package = aClass package ]. "If the package is now full, then add the package and remove the siblings" - (siblings asSet add: aClass; yourself) size = aClass package definedClasses size ifTrue: [ + (siblings asSet add: aClass; yourself) size = (aClass package definedClasses size * 2) ifTrue: [ siblings do: [ :each | classEnv removeClass: each ]. packaEnv addPackage: aClass package. ^ self ]. @@ -30,9 +30,10 @@ RBCompositeEnvironment >> addClass: aClass [ ] { #category : '*NewTools-Scopes' } -RBCompositeEnvironment >> addPackage: aPackageName [ - self environment addPackage: aPackageName. - self otherEnvironment addPackage: aPackageName +RBCompositeEnvironment >> addPackage: aPackage [ + + self environment addPackage: aPackage. + self otherEnvironment addPackage: aPackage ] { #category : '*NewTools-Scopes' } diff --git a/src/NewTools-Scopes/ScopesManager.class.st b/src/NewTools-Scopes/ScopesManager.class.st index 87ed85317..b9f970eb4 100644 --- a/src/NewTools-Scopes/ScopesManager.class.st +++ b/src/NewTools-Scopes/ScopesManager.class.st @@ -8,7 +8,8 @@ Class { 'scopes', 'environment', 'announcer', - 'defaultScope' + 'defaultScope', + 'currentQueryScope' ], #classVars : [ 'singleInstance' @@ -29,6 +30,16 @@ ScopesManager class >> availableScopes [ ^ self scopes ] +{ #category : 'as yet unclassified' } +ScopesManager class >> currentQueryScope [ + ^ self singleInstance currentQueryScope +] + +{ #category : 'accessing' } +ScopesManager class >> currentQueryScope: aScope [ + self singleInstance currentQueryScope: aScope +] + { #category : 'accessing' } ScopesManager class >> defaultScopeLabel [ @@ -177,6 +188,19 @@ ScopesManager >> announcer [ ^ announcer ifNil: [ announcer := Announcer new ] ] +{ #category : 'accessing' } +ScopesManager >> currentQueryScope [ + ^ currentQueryScope +] + +{ #category : 'accessing' } +ScopesManager >> currentQueryScope: aScope [ + + (scopes includes: aScope) + ifTrue: [ currentQueryScope := aScope ] + ifFalse: [ currentQueryScope := nil ] +] + { #category : 'api' } ScopesManager >> defaultScope [ @@ -219,7 +243,7 @@ ScopesManager >> editScope: aScope withNodes: aCollection [ addedClasses do: [ :aClass | aScope addClass: aClass ]. removedClasses do: [ :aClass | aScope removeClass: aClass ]. - addedPackages do: [ :aPackage | aScope addPackage: aPackage name ]. + addedPackages do: [ :aPackage | aScope addPackage: aPackage ]. removedPackages do: [ :aPackage | aScope removePackage: aPackage name ].