diff --git a/src/SystemCommands-MethodCommands/SycPushDownMethodCommand.class.st b/src/SystemCommands-MethodCommands/SycPushDownMethodCommand.class.st index ad5cc01e18d..a7dbacfd5f5 100644 --- a/src/SystemCommands-MethodCommands/SycPushDownMethodCommand.class.st +++ b/src/SystemCommands-MethodCommands/SycPushDownMethodCommand.class.st @@ -67,7 +67,7 @@ SycPushDownMethodCommand >> selectMethods [ selectedMethods := methods copy asOrderedCollection. class := methods first origin. dialog := RBMethodsSelectionPresenter - label: class name,' - Select all methods to push down' + label: 'Push down methods from ', class name withItems: (class methods sort: [ :a :b | a asString < b asString ]) asOrderedCollection selecting: selectedMethods. dialog cancelled ifTrue: [ CmdCommandAborted signal ]. diff --git a/src/SystemCommands-MethodCommands/SycPushUpMethodCommand.class.st b/src/SystemCommands-MethodCommands/SycPushUpMethodCommand.class.st index c74a082efc3..3e1e3dc230d 100644 --- a/src/SystemCommands-MethodCommands/SycPushUpMethodCommand.class.st +++ b/src/SystemCommands-MethodCommands/SycPushUpMethodCommand.class.st @@ -4,6 +4,9 @@ I am a command to push up given methods Class { #name : #SycPushUpMethodCommand, #superclass : #SycMethodCommand, + #instVars : [ + 'superclass' + ], #category : #'SystemCommands-MethodCommands' } @@ -26,13 +29,11 @@ SycPushUpMethodCommand class >> methodShortcutActivation [ { #category : #execution } SycPushUpMethodCommand >> asRefactorings [ - |dialog refactoring| + | refactoring | refactoring := RBPullUpMethodRefactoring - pullUp: methods + pullUp: (methods collect: #selector) from: methods first origin. - refactoring setOption: #superClass toUse: [ :ref | - dialog := RBPushUpPreviewPresenter on: ref. - dialog cancelled ifTrue: [ CmdCommandAborted signal ]]. + refactoring superClass: superclass. ^ OrderedCollection with: refactoring ] @@ -56,3 +57,26 @@ SycPushUpMethodCommand >> execute [ SycPushUpMethodCommand >> isComplexRefactoring [ ^true ] + +{ #category : #execution } +SycPushUpMethodCommand >> prepareFullExecutionInContext: aToolContext [ + super prepareFullExecutionInContext: aToolContext. + self selectMethodsAndSuperclass. +] + +{ #category : #execution } +SycPushUpMethodCommand >> selectMethodsAndSuperclass [ + | selectedMethods dialog class classes | + selectedMethods := methods copy asOrderedCollection. + class := methods first origin. + classes := class allSuperclasses removeAllSuchThat: [ :each | each == Object or: [ each == ProtoObject ] ]. + dialog := RBSelectClassAndMethodsPresenter + label: 'Methods to be pull up' + dropLabel: 'Pull up methods of ', class name, ' to:' + withItems: (class methods sort: [ :a :b | a asString < b asString ]) asOrderedCollection + selecting: selectedMethods + dropItems: classes + acceptBlock: [ :item :items | superclass := item. + methods := items ]. + dialog cancelled ifTrue: [ CmdCommandAborted signal ]. +] diff --git a/src/SystemCommands-RefactoringSupport/RBAbstractSelectionPresenter.class.st b/src/SystemCommands-RefactoringSupport/RBAbstractSelectionPresenter.class.st new file mode 100644 index 00000000000..baa66775aaa --- /dev/null +++ b/src/SystemCommands-RefactoringSupport/RBAbstractSelectionPresenter.class.st @@ -0,0 +1,72 @@ +Class { + #name : #RBAbstractSelectionPresenter, + #superclass : #RBItemsSelectionPresenter, + #instVars : [ + 'dropList', + 'dropLabel', + 'acceptBlock' + ], + #category : #'SystemCommands-RefactoringSupport' +} + +{ #category : #specs } +RBAbstractSelectionPresenter class >> defaultSpec [ + ^ SpBoxLayout newVertical + add: #dropLabel withConstraints: [ :c | c height: self labelHeight ]; + add: + (SpBoxLayout newHorizontal + add: #dropList ; + yourself) withConstraints: [ :c | c height: self toolbarHeight ]; + add: #label withConstraints: [ :c | c height: self buttonHeight ]; + add: + (SpBoxLayout newHorizontal + add: #table; + yourself); + yourself +] + +{ #category : #specs } +RBAbstractSelectionPresenter class >> label: aString dropLabel: aString2 withItems: coll1 selecting: coll2 dropItems: coll3 acceptBlock: aBlock [ + ^ self new + label: aString + dropLabel: aString2 + withItems: coll1 + selecting: coll2 + dropItems: coll3 + acceptBlock: aBlock; + openModalWithSpec +] + +{ #category : #actions } +RBAbstractSelectionPresenter >> accept [ + acceptBlock value: self selectedItem value: selectedItems +] + +{ #category : #initialization } +RBAbstractSelectionPresenter >> initializeDropList [ + dropList := self newDropList. + dropList + display: [ :scope | scope name ]; + iconBlock: [ :e | e systemIcon ] +] + +{ #category : #initialization } +RBAbstractSelectionPresenter >> initializeWidgets [ + super initializeWidgets . + dropLabel := self newLabel. + self initializeDropList. +] + +{ #category : #initialization } +RBAbstractSelectionPresenter >> label: aString dropLabel: aString2 withItems: coll1 selecting: coll2 dropItems: coll3 acceptBlock: aBlock [ + self label: aString withItems: coll1 selecting: coll2. + dropLabel label: aString2. + dropList items: coll3. + acceptBlock := aBlock. + +] + +{ #category : #accessing } +RBAbstractSelectionPresenter >> selectedItem [ + ^ dropList selectedItem +] diff --git a/src/SystemCommands-RefactoringSupport/RBItemsSelectionPresenter.class.st b/src/SystemCommands-RefactoringSupport/RBItemsSelectionPresenter.class.st index 0a4b74eb3cf..c255ad6f290 100644 --- a/src/SystemCommands-RefactoringSupport/RBItemsSelectionPresenter.class.st +++ b/src/SystemCommands-RefactoringSupport/RBItemsSelectionPresenter.class.st @@ -28,7 +28,7 @@ Class { #category : #'SystemCommands-RefactoringSupport' } -{ #category : #visiting } +{ #category : #specs } RBItemsSelectionPresenter class >> defaultSpec [ ^ SpBoxLayout newVertical add: #label withConstraints: [ :c | c height: self buttonHeight ]; @@ -39,7 +39,7 @@ RBItemsSelectionPresenter class >> defaultSpec [ yourself ] -{ #category : #visiting } +{ #category : #specs } RBItemsSelectionPresenter class >> label: aString withItems: coll1 selecting: coll2 [ ^ self new label: aString withItems: coll1 selecting: coll2; diff --git a/src/SystemCommands-RefactoringSupport/RBPushDownPreviewPresenter.class.st b/src/SystemCommands-RefactoringSupport/RBPushDownPreviewPresenter.class.st deleted file mode 100644 index 778ccb04321..00000000000 --- a/src/SystemCommands-RefactoringSupport/RBPushDownPreviewPresenter.class.st +++ /dev/null @@ -1,138 +0,0 @@ -" -I am a preview of push down method refactoring. I can select the methods of class to push down - -EXAMPLES -------------------------------------------------- - -RBPushDownPreview on: RBPushDownPreview withSelectors: Array new. - -Instance Variables -------------------------------------------------- - -table: A table to display the possible methods to push down -label: Title of table -class: class of selected methods -selectedMethods: A list with selected methods -refactoring: A subclass of RBRefactoring (RBPushUpRefactoring, RBPushDownRefactoring) to update according to the view modifications -" -Class { - #name : #RBPushDownPreviewPresenter, - #superclass : #SpPresenter, - #instVars : [ - 'table', - 'label', - 'class', - 'selectedMethods', - 'refactoring' - ], - #category : #'SystemCommands-RefactoringSupport' -} - -{ #category : #specs } -RBPushDownPreviewPresenter class >> defaultSpec [ - ^ SpBoxLayout newVertical - add: #label withConstraints: [ :c | c height: self buttonHeight ]; - add: - (SpBoxLayout newHorizontal - add: #table; - yourself); - yourself -] - -{ #category : #examples } -RBPushDownPreviewPresenter class >> example [ -