diff --git a/src/Gt4CSS/GtCSSCoderModel.class.st b/src/Gt4CSS/GtCSSCoderModel.class.st index 4ca8972..16fe023 100644 --- a/src/Gt4CSS/GtCSSCoderModel.class.st +++ b/src/Gt4CSS/GtCSSCoderModel.class.st @@ -8,6 +8,11 @@ Class { #category : #'Gt4CSS-Model' } +{ #category : #addons } +GtCSSCoderModel class >> contextHeaderMenuAddOnsPragma [ + ^#gtCoderHeaderContextMenuAddOns +] + { #category : #'instance creation' } GtCSSCoderModel class >> forMethod: aCompiledMethod [ ^ self new forMethod: aCompiledMethod @@ -116,6 +121,54 @@ GtCSSCoderModel >> addContextMenuAddOns: anAst to: coderAddOns from: aCoderViewM ifNotNil: [ :anAction | anAction priority: 10.5 ] ] ] ] ] +{ #category : #'add-ons' } +GtCSSCoderModel >> addFormatMethodAst: anAst to: coderAddOns [ + + (self + addContextMenuItemFrom: GtSourceCoderFormatShortcut new + group: BrMenuItemGroupConfiguration refactoring + withId: nil + to: coderAddOns) ifNotNil: [:anAction | anAction priority: 250] +] + +{ #category : #'add-ons - header' } +GtCSSCoderModel >> addHeaderFormatMethodSelector: aSelector ast: anAst to: coderAddOns [ + + (self + addContextMenuItemFrom: GtSourceCoderFormatShortcut new + group: BrMenuItemGroupConfiguration refactoring + withId: nil + to: coderAddOns) ifNotNil: [:anAction | anAction priority: 250] +] + +{ #category : #'add-ons - header' } +GtCSSCoderModel >> addImplementorsHeaderContextMenuAddOnsSelector: aSelector ast: anAst to: coderAddOns [ + + ^coderAddOns + addContextMenuItem: GtSourceCoderBrowseImplementorsShortcut new name + group: BrMenuItemGroupConfiguration navigation + action: + [:aCoderViewModel :anEditorElement | + anEditorElement phlow + spawnObject: aCoderViewModel coder selector gtImplementors] + id: nil + shortcutKey: nil +] + +{ #category : #'add-ons - header' } +GtCSSCoderModel >> addReferencesHeaderContextMenuAddOnsSelector: aSelector ast: anAst to: coderAddOns [ + + ^coderAddOns + addContextMenuItem: GtSourceCoderBrowseReferencesShortcut new name + group: BrMenuItemGroupConfiguration navigation + action: + [:aCoderViewModel :anEditorElement | + anEditorElement phlow + spawnObject: aCoderViewModel coder selector gtReferences] + id: nil + shortcutKey: nil +] + { #category : #converting } GtCSSCoderModel >> asCoderViewModel [ ^ GtCSSCoderViewModel new diff --git a/src/Gt4CSS/GtCSSCoderViewModel.class.st b/src/Gt4CSS/GtCSSCoderViewModel.class.st index 94eef60..a8fd05c 100644 --- a/src/Gt4CSS/GtCSSCoderViewModel.class.st +++ b/src/Gt4CSS/GtCSSCoderViewModel.class.st @@ -34,7 +34,43 @@ GtCSSCoderViewModel >> compiledMethod [ ^self coderModel compiledMethod ] -{ #category : #'as yet unclassified' } +{ #category : #'private - addons' } +GtCSSCoderViewModel >> computeHeaderContextMenuAstAddOns [ + + | aCoderModel newAddOns pragmas theAst | + aCoderModel := self coderModel. + theAst := aCoderModel astSync. + pragmas := aCoderModel + pragmasNamed: aCoderModel class contextHeaderMenuAddOnsPragma + inHierarchy: aCoderModel class. + newAddOns := aCoderModel newAddOns. + theAst + ifNotNil: + [pragmas do: + [:eachPragma | + + [aCoderModel perform: eachPragma methodSelector + withEnoughArguments: + {aCoderModel selector. + theAst. + newAddOns. + self}] + on: Error + do: + [:anError | + "emit as a beacon signal" + anError emit. + (NonInteractiveTranscript stderr) + nextPut: $[; + print: eachPragma method printString; + nextPut: $]; + space; + print: anError; + cr]]]. + ^newAddOns +] + +{ #category : #'api - accessing' } GtCSSCoderViewModel >> currentSelectorPromise [ ^ self coderModel currentSelectorPromise ] @@ -54,7 +90,7 @@ GtCSSCoderViewModel >> highlighter: aStyler [ self coder highlighter: aStyler ] -{ #category : #'as yet unclassified' } +{ #category : #testing } GtCSSCoderViewModel >> isMeta [ "Return true if the method is implemented in a pharo metaclass (~ class side)" diff --git a/src/Gt4CSS/GtCSSSourceCoderEditorElement.class.st b/src/Gt4CSS/GtCSSSourceCoderEditorElement.class.st index 91406f0..71f3db9 100644 --- a/src/Gt4CSS/GtCSSSourceCoderEditorElement.class.st +++ b/src/Gt4CSS/GtCSSSourceCoderEditorElement.class.st @@ -4,6 +4,30 @@ Class { #category : #'Gt4CSS-UI' } +{ #category : #'as yet unclassified' } +GtCSSSourceCoderEditorElement >> createHeaderContextMenu [ + "wait for the addons to be computed" + + | aMenu aMenuItemsPromise | + aMenu := BrMenuItems new. + aMenu beGroupedElementType. + aMenuItemsPromise := self textualCoderViewModel addOns asyncThen: + [:theAddOns | + "extra context menu items that depend on ast and view model state such as selection" + | theItems theContextMenuAstAddons theMenuItems | + theContextMenuAstAddons := self textualCoderViewModel + computeHeaderContextMenuAstAddOns. + theItems := theAddOns contextMenuActions + , theContextMenuAstAddons contextMenuActions. + theItems := theItems reject: [:e | e title isNil]. + theMenuItems := theItems + collect: [:eachAction | eachAction asBrMenuItemForCoderElement: self] + thenReject: #isNil. + self enqueueTask: (BlTaskAction new action: [aMenu items: theMenuItems])]. + self enqueueTask: (BlPromiseTask new promise: aMenuItemsPromise). + ^aMenu +] + { #category : #initialization } GtCSSSourceCoderEditorElement >> defaultTextEditorModel [ ^ GtLSPEditorModel withEditorMode: self defaultTextEditorMode diff --git a/src/Gt4CSS/GtCSSSourceCoderExpandedContentElement.class.st b/src/Gt4CSS/GtCSSSourceCoderExpandedContentElement.class.st index 8747c92..62762dd 100644 --- a/src/Gt4CSS/GtCSSSourceCoderExpandedContentElement.class.st +++ b/src/Gt4CSS/GtCSSSourceCoderExpandedContentElement.class.st @@ -84,15 +84,17 @@ GtCSSSourceCoderExpandedContentElement >> updateAptitude: editor [ | aptitude | aptitude := GtLSPEditorAptitude new. aptitude lspFile: self lspFile. - textualCoderViewModel ifNotNil: [ - aptitude styler: textualCoderViewModel compositeStyler ]. + textualCoderViewModel + ifNotNil: [aptitude styler: textualCoderViewModel compositeStyler]. editor aptitude: aptitude. - textualCoderViewModel ifNotNil: [self updateHeaderLabel]. - editor - addAptitude: (BrGlamorousWithExplicitContextMenuAptitude menu: [ editor createContextMenu ]) + textualCoderViewModel ifNotNil: [self updateHeaderLabel: editor]. + editor addAptitude: (BrGlamorousWithExplicitContextMenuAptitude + menu: [editor createContextMenu]) ] { #category : #updating } -GtCSSSourceCoderExpandedContentElement >> updateHeaderLabel [ +GtCSSSourceCoderExpandedContentElement >> updateHeaderLabel: editor [ label text: textualCoderViewModel coder selector asRopedText. + label addAptitude: (BrGlamorousWithExplicitContextMenuAptitude + menu: [editor createHeaderContextMenu]) ]