better drop (class/methods)
authorClaus Gittinger <cg@exept.de>
Fri, 01 May 2009 19:35:48 +0200
changeset 3870 e08a82f2e73f
parent 3869 82b87c5ae995
child 3871 9e5265dc158f
better drop (class/methods)
Workspace.st
--- a/Workspace.st	Fri May 01 19:23:26 2009 +0200
+++ b/Workspace.st	Fri May 01 19:35:48 2009 +0200
@@ -901,27 +901,59 @@
 drop:aDropContext
     "Any object can be dropped into workspace..."
 
-    |textObjects|
+    |textObjects nonTextObjects answer text|
+
+    textObjects := aDropContext dropObjects 
+                            select:[:dropObject | dropObject isTextObject or:[ dropObject isFileObject ]].
+    nonTextObjects := aDropContext dropObjects 
+                            reject:[:dropObject | dropObject isTextObject or:[ dropObject isFileObject ]].
+
+    self dropObjects:textObjects.
 
-    aDropContext dropObjects do:[:dropObject|
-        (dropObject isTextObject or:[ dropObject isFileObject ]) ifTrue:[
-            self dropObjects:(Array with:dropObject)
-            "/ self paste:dropObject theObject asStringWithoutFinalCR
+    nonTextObjects notEmpty ifTrue:[
+        answer := Dialog
+                confirmWithCancel:(resources 
+                                        string:'Drop as textual representation or as object reference ?')
+                labels:(resources array:#('Cancel' 'Reference' 'Name' 'Text'))
+                values:#(nil #ref #name #text)
+                default:4.
+        answer isNil ifTrue:[^ self].
+        (answer == #text or:[answer == #name]) ifTrue:[
+            text := String streamContents:[:s |
+                        nonTextObjects do:[:dropObject |
+                            |obj|
+
+                            obj := dropObject theObject.
+                            obj isMethod ifTrue:[
+                                s nextPutAll:(answer == #name ifTrue:[obj selector] ifFalse:[obj source]).
+                            ] ifFalse:[
+                                obj isClass ifTrue:[
+                                    s nextPutAll:(answer == #name ifTrue:[obj name] ifFalse:[obj source asString])
+                                ] ifFalse:[
+                                    s nextPutAll:(answer == #name ifTrue:[obj className] ifFalse:[obj printString]) .
+                                ].
+                            ].
+                        ].
+                    ].
+            self paste:text.
         ] ifFalse:[
-            name := Dialog 
-                    request:(resources 
-                                string:'Name of new Workspace Variable (refers to the dropped %1):'
-                                with:dropObject theObject class name allBold
-                             )
-                    initialAnswer:'droppedObject'
-                    okLabel:'Add'
-                    title:'Enter Variable Name'.
+            nonTextObjects do:[:dropObject |
+                name := Dialog 
+                        request:(resources 
+                                    string:'Name of the new Workspace Variable (refers to the dropped %1):'
+                                    with:dropObject theObject class name allBold
+                                 )
+                        initialAnswer:'droppedObject'
+                        okLabel:'Add'
+                        title:'Enter Variable Name'.
 
-            name notEmptyOrNil ifTrue:[
-                Workspace addWorkspaceVariable:name.
-                (Workspace workspaceVariableAt:name) value:dropObject theObject.
+                name notEmptyOrNil ifTrue:[
+                    Workspace addWorkspaceVariable:name.
+                    (Workspace workspaceVariableAt:name) value:dropObject theObject.
+                    self paste:name.
+                ].
             ].
-        ].
+        ]
     ].
 
     "Created: / 13-10-2006 / 17:34:07 / cg"
@@ -1699,5 +1731,5 @@
 !Workspace class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.199 2008-12-18 10:45:07 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/Workspace.st,v 1.200 2009-05-01 17:35:48 cg Exp $'
 ! !