UI: support for presenter-defined context menus
Each `VDBModelPresenter` can define it's own, model-specific
items by overriding class #contextMenu. These items are then
shown in context menu of "list" applications (subclasses of
`VDBAbstractListApplication`.
This is useful especially for `VDBStackApplication` which sjows
different models (inferiors, threads and frames).
--- a/VDBAbstractListApplication.st Mon Jan 15 09:57:48 2018 +0000
+++ b/VDBAbstractListApplication.st Wed Jan 17 06:46:47 2018 +0000
@@ -98,8 +98,8 @@
"
- MenuEditor new openOnClass:VDBStackApplication andSelector:#contextMenu
- (Menu new fromLiteralArrayEncoding:(VDBStackApplication contextMenu)) startUp
+ MenuEditor new openOnClass:VDBAbstractListApplication andSelector:#contextMenu
+ (Menu new fromLiteralArrayEncoding:(VDBAbstractListApplication contextMenu)) startUp
"
<resource: #menu>
@@ -108,7 +108,12 @@
#(Menu
(
(MenuItem
- label: 'Menu Slice'
+ label: 'Item Menu Slice'
+ submenuChannel: contextMenuItemSlice
+ isMenuSlice: true
+ )
+ (MenuItem
+ label: 'Inspect Menu Slice'
submenuChannel: contextMenuInspectSlice
isMenuSlice: true
)
@@ -285,9 +290,31 @@
!VDBAbstractListApplication methodsFor:'menu'!
contextMenu
- ^ builder menuFor: #contextMenu
+ ^ [
+ (Menu decodeFromLiteralArray: self class contextMenu)
+ receiver:self;
+ findGuiResourcesIn:self;
+ yourself
+ ]
+
+ "Created: / 16-01-2018 / 14:29:05 / jv"
+ "Modified: / 16-01-2018 / 22:02:37 / jv"
+ "Modified (comment): / 16-01-2018 / 23:26:46 / jv"
+!
- "Created: / 12-06-2017 / 12:02:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+contextMenuItemSlice
+ | item menu |
+
+ item := self internalSelectionHolder value.
+ item isNil ifTrue:[
+ menu := Menu new.
+ ] ifFalse:[
+ menu := item contextMenu.
+ ].
+ ^ menu.
+
+ "Created: / 16-01-2018 / 13:37:08 / jv"
+ "Modified: / 16-01-2018 / 22:03:45 / jv"
! !
!VDBAbstractListApplication methodsFor:'menu actions'!
--- a/VDBFrameApplication.st Mon Jan 15 09:57:48 2018 +0000
+++ b/VDBFrameApplication.st Wed Jan 17 06:46:47 2018 +0000
@@ -70,44 +70,6 @@
! !
-!VDBFrameApplication class methodsFor:'menu specs'!
-
-contextMenu
- "This resource specification was automatically generated
- by the MenuEditor of ST/X."
-
- "Do not manually edit this!! If it is corrupted,
- the MenuEditor may not be able to read the specification."
-
-
- "
- MenuEditor new openOnClass:VDBFrameApplication andSelector:#contextMenu
- (Menu new fromLiteralArrayEncoding:(VDBFrameApplication contextMenu)) startUp
- "
-
- <resource: #menu>
-
- ^
- #(Menu
- (
- (MenuItem
- label: 'Copy Value'
- itemValue: doCopyValue
- )
- (MenuItem
- label: '-'
- )
- (MenuItem
- label: 'Menu Slice'
- submenuChannel: contextMenuInspectSlice
- isMenuSlice: true
- )
- )
- nil
- nil
- )
-! !
-
!VDBFrameApplication class methodsFor:'plugIn spec'!
aspectSelectors
@@ -148,10 +110,16 @@
doDoubleClick
"Invoked when user double-clicks to list item."
+
+ | selectedVariablePresenter |
- self doCopyValue
+ selectedVariablePresenter := self internalSelectionHolder value.
+ selectedVariablePresenter notNil ifTrue:[
+ selectedVariablePresenter doCopyValue
+ ].
"Created: / 13-06-2017 / 17:09:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 16-01-2018 / 23:33:12 / jv"
! !
!VDBFrameApplication methodsFor:'aspects'!
@@ -276,14 +244,6 @@
^ self shouldImplement
! !
-!VDBFrameApplication methodsFor:'menu actions'!
-
-doCopyValue
- internalListView setClipboardText: (self selectedVariableHolder value varobj value)
-
- "Modified: / 13-06-2017 / 14:58:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
!VDBFrameApplication class methodsFor:'documentation'!
version_HG
--- a/VDBFramePresenter.st Mon Jan 15 09:57:48 2018 +0000
+++ b/VDBFramePresenter.st Wed Jan 17 06:46:47 2018 +0000
@@ -30,6 +30,37 @@
"
! !
+!VDBFramePresenter class methodsFor:'menu specs'!
+
+contextMenu
+ "This resource specification was automatically generated
+ by the MenuEditor of ST/X."
+
+ "Do not manually edit this!! If it is corrupted,
+ the MenuEditor may not be able to read the specification."
+
+
+ "
+ MenuEditor new openOnClass:VDBFramePresenter andSelector:#contextMenu
+ (Menu new fromLiteralArrayEncoding:(VDBFramePresenter contextMenu)) startUp
+ "
+
+ <resource: #menu>
+
+ ^
+ #(Menu
+ (
+ (MenuItem
+ enabled: canCopyFunctionName
+ label: 'Copy Function Name'
+ itemValue: doCopyFunctionName
+ )
+ )
+ nil
+ nil
+ )
+! !
+
!VDBFramePresenter methodsFor:'accessing'!
frame
@@ -58,6 +89,22 @@
"Created: / 21-09-2014 / 23:38:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!VDBFramePresenter methodsFor:'menu actions'!
+
+canCopyFunctionName
+ ^ frame func notNil
+
+ "Modified: / 16-01-2018 / 22:19:59 / jv"
+!
+
+doCopyFunctionName
+ <resource: #uiCallback>
+
+ self doCopy: frame func.
+
+ "Modified: / 16-01-2018 / 22:36:37 / jv"
+! !
+
!VDBFramePresenter methodsFor:'protocol-accessing'!
fetchChildren
--- a/VDBModelPresenter.st Mon Jan 15 09:57:48 2018 +0000
+++ b/VDBModelPresenter.st Wed Jan 17 06:46:47 2018 +0000
@@ -30,6 +30,30 @@
"
! !
+!VDBModelPresenter class methodsFor:'menu specs'!
+
+contextMenu
+ "This resource specification was automatically generated
+ by the MenuEditor of ST/X."
+
+ "Do not manually edit this!! If it is corrupted,
+ the MenuEditor may not be able to read the specification."
+
+
+ "
+ MenuEditor new openOnClass:VDBModelPresenter andSelector:#contextMenu
+ (Menu new fromLiteralArrayEncoding:(VDBModelPresenter contextMenu)) startUp
+ "
+
+ <resource: #menu>
+
+ ^
+ #(Menu
+ nil nil
+ nil
+ )
+! !
+
!VDBModelPresenter methodsFor:'accessing'!
backgroundColor
@@ -62,6 +86,37 @@
"Created: / 10-06-2017 / 12:24:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!VDBModelPresenter methodsFor:'menu'!
+
+contextMenu
+ | menu |
+
+ menu := Menu decodeFromLiteralArray: self class contextMenu.
+ menu hasItems ifFalse:[ ^ menu ].
+ menu findGuiResourcesIn:self.
+ menu itemsDo:[:item|
+ | itemSelector |
+
+ (itemSelector := item itemValue) isSymbol ifTrue:[
+ item itemValue: [ self perform: itemSelector ]
+ ].
+ ].
+ menu addSeparator.
+ ^ menu
+
+ "Created: / 16-01-2018 / 22:03:53 / jv"
+! !
+
+!VDBModelPresenter methodsFor:'menu actions'!
+
+doCopy: aString
+ <resource: #uiCallback>
+
+ self application window setClipboardText: aString
+
+ "Created: / 16-01-2018 / 22:36:30 / jv"
+! !
+
!VDBModelPresenter methodsFor:'testing'!
isBreakpointPresenter
--- a/VDBVariablePresenter.st Mon Jan 15 09:57:48 2018 +0000
+++ b/VDBVariablePresenter.st Wed Jan 17 06:46:47 2018 +0000
@@ -30,6 +30,36 @@
"
! !
+!VDBVariablePresenter class methodsFor:'menu specs'!
+
+contextMenu
+ "This resource specification was automatically generated
+ by the MenuEditor of ST/X."
+
+ "Do not manually edit this!! If it is corrupted,
+ the MenuEditor may not be able to read the specification."
+
+
+ "
+ MenuEditor new openOnClass:VDBVariablePresenter andSelector:#contextMenu
+ (Menu new fromLiteralArrayEncoding:(VDBVariablePresenter contextMenu)) startUp
+ "
+
+ <resource: #menu>
+
+ ^
+ #(Menu
+ (
+ (MenuItem
+ label: 'Copy Value'
+ itemValue: doCopyValue
+ )
+ )
+ nil
+ nil
+ )
+! !
+
!VDBVariablePresenter methodsFor:'accessing'!
label
@@ -63,6 +93,14 @@
"Created: / 27-02-2015 / 16:00:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!VDBVariablePresenter methodsFor:'menu actions'!
+
+doCopyValue
+ self doCopy: variable varobj value.
+
+ "Created: / 16-01-2018 / 23:28:56 / jv"
+! !
+
!VDBVariablePresenter methodsFor:'testing'!
isVariablePresenter