VDBAbstractListApplication.st
changeset 79 f17d02897d01
parent 78 5b61031de9a7
child 85 48e6c61382b6
--- a/VDBAbstractListApplication.st	Tue Jun 26 13:15:30 2018 +0100
+++ b/VDBAbstractListApplication.st	Tue Jun 26 14:17:50 2018 +0100
@@ -113,11 +113,22 @@
         (
          (MenuItem
             label: 'Item Menu Slice'
+            isVisible: true
             submenuChannel: contextMenuItemSlice
             isMenuSlice: true
           )
          (MenuItem
+            label: 'Copy Menu Slice'
+            isVisible: true
+            submenuChannel: contextMenuCopySlice
+            isMenuSlice: true
+          )
+         (MenuItem
+            label: '-'
+          )
+         (MenuItem
             label: 'Inspect Menu Slice'
+            isVisible: true
             submenuChannel: contextMenuInspectSlice
             isMenuSlice: true
           )
@@ -127,6 +138,41 @@
       )
 !
 
+contextMenuCopySlice
+    "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:VDBAbstractListApplication andSelector:#contextMenuCopySlice
+     (Menu new fromLiteralArrayEncoding:(VDBAbstractListApplication contextMenuCopySlice)) startUp
+    "
+
+    <resource: #menu>
+
+    ^ 
+     #(Menu
+        (
+         (MenuItem
+            label: 'Copy Contents To Clipboard'
+            itemValue: doCopyContents
+            isVisible: true
+          )
+         (MenuItem
+            enabled: hasSelection
+            label: 'Copy Selection To Clipboard'
+            itemValue: doCopySelection
+            isVisible: true
+          )
+         )
+        nil
+        nil
+      )
+!
+
 contextMenuInspectSlice
     "This resource specification was automatically generated
      by the MenuEditor of ST/X."
@@ -369,6 +415,31 @@
 
 !VDBAbstractListApplication methodsFor:'menu actions'!
 
+doCopy:aString 
+    self window setClipboardText:aString
+
+    "Created: / 15-06-2018 / 11:32:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+doCopyContents
+    | contents |
+
+    contents := String streamContents:[:s | self printItemsFrom: 1 to: self internalList size on:s. ].
+    self doCopy:contents.
+
+    "Modified: / 10-08-2018 / 12:52:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+doCopySelection
+    | index contents |
+
+    index := self internalList indexOf: self internalSelection.
+    contents := String streamContents:[:s | self printItemsFrom: index to: index on:s. ].
+    self doCopy:contents.
+
+    "Modified: / 10-08-2018 / 12:54:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 doDoubleClick
     "Invoked when user double-clicks to list item."
 
@@ -418,6 +489,55 @@
     ^self canSelect: item
 
     "Created: / 09-04-2018 / 20:52:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+internalList
+    ^ self internalListHolder value
+
+    "Created: / 10-08-2018 / 12:51:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+internalSelection
+    ^ self internalSelectionHolder value
+
+    "Created: / 10-08-2018 / 12:54:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+printItemsFrom: first to: last on:aStream  
+    | list columns |
+
+    list := self internalList.
+    (internalListView listRenderer isKindOf:ListModelView::TableRenderer) ifTrue:[
+        columns := internalListView listRenderer columnDescriptors.
+    ] ifFalse:[
+        columns := #().
+    ].
+    first to: last do:[:rownr |
+        | item |
+
+        item := list at: rownr.
+        item isHierarchicalItem ifTrue:[
+            aStream next:item level * 2 put:Character space.
+            aStream nextPutAll:item label asString.
+        ] ifFalse:[
+            aStream nextPutAll:item asString.
+        ].
+        columns do:[:column | 
+            | value |
+
+            value := column 
+                    extractColumnFrom:item
+                    rowNr:rownr
+                    on:internalListView.
+            value notNil ifTrue:[
+                aStream tab.
+                aStream nextPutAll:value displayString.
+            ].
+        ].
+        aStream cr.
+    ].
+
+    "Created: / 10-08-2018 / 12:50:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !VDBAbstractListApplication methodsFor:'queries'!