sharedPool access in doIts
authorClaus Gittinger <cg@exept.de>
Thu, 24 Jan 2008 14:50:20 +0100
changeset 7931 99ce6134cbca
parent 7930 19656d40a181
child 7932 78f2fed5f44b
sharedPool access in doIts
WorkspaceApplication.st
--- a/WorkspaceApplication.st	Wed Jan 23 14:24:43 2008 +0100
+++ b/WorkspaceApplication.st	Thu Jan 24 14:50:20 2008 +0100
@@ -12,9 +12,9 @@
 "{ Package: 'stx:libtool' }"
 
 MultiViewToolApplication subclass:#WorkspaceApplication
-	instanceVariableNames:'autoDefineVariables syntaxHolder'
+	instanceVariableNames:'autoDefineVariables syntaxHolder poolsConsideredInDoIts'
 	classVariableNames:'LastFilterBlockString LastProcessingBlockString LastTeaWaitTime
-		DefaultToolBarVisible'
+		DefaultToolBarVisible Sniplets'
 	poolDictionaries:''
 	category:'Interface-Smalltalk'
 !
@@ -58,6 +58,116 @@
     "Created: / 14-07-2007 / 16:42:50 / cg"
 ! !
 
+!WorkspaceApplication class methodsFor:'interface specs'!
+
+manageSnipletsDialogSpec
+    "This resource specification was automatically generated
+     by the UIPainter of ST/X."
+
+    "Do not manually edit this!! If it is corrupted,
+     the UIPainter may not be able to read the specification."
+
+    "
+     UIPainter new openOnClass:WorkspaceApplication andSelector:#manageSnipletsDialogSpec
+     WorkspaceApplication new openInterface:#manageSnipletsDialogSpec
+    "
+
+    <resource: #canvas>
+
+    ^ 
+     #(FullSpec
+        name: manageSnipletsDialogSpec
+        window: 
+       (WindowSpec
+          label: 'Manage Sniplets'
+          name: 'Manage Sniplets'
+          min: (Point 10 10)
+          bounds: (Rectangle 0 0 379 590)
+        )
+        component: 
+       (SpecCollection
+          collection: (
+           (LabelSpec
+              label: 'Sniplet:'
+              name: 'Label1'
+              layout: (LayoutFrame 0 0 0 0 0 1 30 0)
+              translateLabel: true
+              adjust: left
+            )
+           (VariableVerticalPanelSpec
+              name: 'VariableVerticalPanel1'
+              layout: (LayoutFrame 0 0 30 0 0 1 -80 1)
+              component: 
+             (SpecCollection
+                collection: (
+                 (SequenceViewSpec
+                    name: 'List1'
+                    model: selectedSniplet
+                    hasHorizontalScrollBar: true
+                    hasVerticalScrollBar: true
+                    useIndex: true
+                    sequenceList: listOfSniplets
+                  )
+                 (TextEditorSpec
+                    name: 'TextEditor1'
+                    model: selectedSnipletsText
+                    hasHorizontalScrollBar: true
+                    hasVerticalScrollBar: true
+                    viewClassName: ''
+                  )
+                 )
+               
+              )
+              handles: (Any 0.5 1.0)
+            )
+           (HorizontalPanelViewSpec
+              name: 'ButtonPanel'
+              layout: (LayoutFrame 0 0 -30 1 0 1 0 1)
+              horizontalLayout: fitSpace
+              verticalLayout: center
+              horizontalSpace: 3
+              verticalSpace: 3
+              reverseOrderIfOKAtLeft: true
+              component: 
+             (SpecCollection
+                collection: (
+                 (ActionButtonSpec
+                    label: 'Close'
+                    name: 'Button1'
+                    translateLabel: true
+                    model: cancel
+                    extent: (Point 373 22)
+                  )
+                 )
+               
+              )
+            )
+           (ActionButtonSpec
+              label: 'Remove'
+              name: 'Button2'
+              layout: (LayoutFrame 6 0 515 0 131 0 537 0)
+              translateLabel: true
+              model: removeSelectedSniplet
+              enableChannel: removeEnabled
+            )
+           (DividerSpec
+              name: 'Separator1'
+              layout: (LayoutFrame 0 0.0 557 0 0 1.0 561 0)
+            )
+           (ActionButtonSpec
+              label: 'Paste'
+              name: 'Button3'
+              layout: (LayoutFrame -131 1 515 0 -6 1 537 0)
+              translateLabel: true
+              model: pasteSelectedSniplet
+              enableChannel: pasteEnabled
+            )
+           )
+         
+        )
+      )
+! !
+
 !WorkspaceApplication class methodsFor:'menu specs'!
 
 bufferMenu
@@ -192,6 +302,24 @@
             label: '-'
           )
          (MenuItem
+            label: 'Copy as Sniplet...'
+            itemValue: addSelectionToSniplets
+            translateLabel: true
+          )
+         (MenuItem
+            label: 'Paste Sniplet...'
+            itemValue: pasteSniplet
+            translateLabel: true
+          )
+         (MenuItem
+            label: 'Manage Sniplets...'
+            itemValue: manageSniplets
+            translateLabel: true
+          )
+         (MenuItem
+            label: '-'
+          )
+         (MenuItem
             label: 'Select All'
             itemValue: selectAll
             translateLabel: true
@@ -321,8 +449,6 @@
         nil
         nil
       )
-
-    "Modified: / 31-10-2007 / 16:46:25 / cg"
 !
 
 fileMenu
@@ -723,6 +849,19 @@
             label: '-'
           )
          (MenuItem
+            label: 'Add SharedPool...'
+            itemValue: addSharedPool
+            translateLabel: true
+          )
+         (MenuItem
+            label: 'Remove SharedPool...'
+            itemValue: removeSharedPool
+            translateLabel: true
+          )
+         (MenuItem
+            label: '-'
+          )
+         (MenuItem
             enabled: anyWorkspaceVariableIsDefined
             label: 'Inspect Workspace Variables'
             itemValue: inspectWorkspaceVariables
@@ -1178,6 +1317,65 @@
     "Created: / 29-05-2007 / 19:08:45 / cg"
 !
 
+addSelectionToSniplets
+    |selection snipletsBaseName snipletsName nr|
+
+    selection := (self selectedWorkspacesTextView selection ? '') asString.
+    selection isEmpty ifTrue:[
+        Dialog information:(resources string:'Nothing Selected').
+        ^ self
+    ].
+
+    snipletsBaseName := Dialog request:(resources string:'Name of Sniplet:').
+    snipletsBaseName isNil ifTrue:[
+        ^ self
+    ].
+    snipletsBaseName isEmpty ifTrue:[
+        snipletsBaseName := Time now asString.
+    ].
+    Sniplets isNil ifTrue:[
+        Sniplets := Dictionary new.
+    ].
+
+    snipletsName := snipletsBaseName.
+    (Sniplets includesKey:snipletsName) ifTrue:[
+        (Dialog confirm:(resources string:'Replace existing sniplet named "%1" ?' with:snipletsName))
+        ifFalse:[
+            [Sniplets includesKey:snipletsName] whileTrue:[
+                nr := (nr ? 1) + 1.
+                snipletsName := (snipletsBaseName,'(%1)') bindWith:nr
+            ].
+        ]
+    ].
+    Sniplets at:snipletsName put:selection
+
+    "Modified: / 24-11-2006 / 12:44:16 / cg"
+!
+
+addSharedPool
+    |allPools poolToAdd|
+
+    allPools := SharedPool allSubclasses collect:[:p | p name].
+    allPools removeAll:(poolsConsideredInDoIts ? #()).
+
+    poolToAdd := Dialog 
+                choose:'Select a SharedPool to Add (To be known in doIt-Evaluations):'
+                fromList:allPools
+                lines:15.
+    poolToAdd isNil ifTrue:[
+        ^ self
+    ].
+    poolsConsideredInDoIts isNil ifTrue:[
+        poolsConsideredInDoIts := (Set new).
+    ].
+    poolsConsideredInDoIts add:poolToAdd.
+    workspaces do:[:ws |
+        ws poolsConsideredInDoIts:poolsConsideredInDoIts.
+    ].
+
+    "Modified: / 24-11-2006 / 12:44:16 / cg"
+!
+
 addTeaTimer
     |l dt tEnd answer|
 
@@ -1348,6 +1546,51 @@
     wsvars inspect
 !
 
+manageSniplets
+    |bindings listOfSniplets removeAction pasteAction
+     hasSelectionHolder removeEnabledHolder pasteEnabledHolder
+     selectedSnipletHolder selectedSnipletsTextHolder selectedSnipletsName|
+
+    listOfSniplets := List withAll:(Sniplets keys asOrderedCollection sort).
+    selectedSnipletsTextHolder := '' asValue.
+
+    selectedSnipletHolder := nil asValue.
+    selectedSnipletHolder onChangeEvaluate:[
+        (selectedSnipletHolder value) isNil ifTrue:[
+            selectedSnipletsName := nil.
+            selectedSnipletsTextHolder value:''.
+        ] ifFalse:[
+            selectedSnipletsName := listOfSniplets at:(selectedSnipletHolder value).
+            selectedSnipletsTextHolder value:(Sniplets at:selectedSnipletsName).
+        ].
+    ].
+
+    hasSelectionHolder := BlockValue with:[:m | m value notNil] argument:selectedSnipletHolder.
+    removeEnabledHolder := hasSelectionHolder.
+    pasteEnabledHolder := hasSelectionHolder.
+
+    removeAction := [
+        Sniplets removeKey:selectedSnipletsName.
+        listOfSniplets remove:selectedSnipletsName.
+    ].
+
+    pasteAction := [
+        |text|
+        text := Sniplets at:selectedSnipletsName.
+        self paste:text
+    ].
+
+    bindings := IdentityDictionary new.
+    bindings at:#listOfSniplets put:listOfSniplets.
+    bindings at:#selectedSniplet put:selectedSnipletHolder asValue.
+    bindings at:#selectedSnipletsText put:selectedSnipletsTextHolder.
+    bindings at:#removeSelectedSniplet put:removeAction.
+    bindings at:#pasteSelectedSniplet put:pasteAction.
+    bindings at:#removeEnabled put:removeEnabledHolder.
+
+    self openDialogInterface:#manageSnipletsDialogSpec withBindings:bindings
+!
+
 newEvaluationWorkspace
     self class openEvaluationWorkspace
 
@@ -1369,6 +1612,23 @@
     self printIt
 !
 
+pasteSniplet
+    |allSniplets snipletToPaste|
+
+    allSniplets := Sniplets keys asOrderedCollection sort.
+
+    snipletToPaste := Dialog 
+                choose:'Paste Sniplet:'
+                fromList:allSniplets
+                lines:10.
+    snipletToPaste isNil ifTrue:[
+        ^ self
+    ].
+    self paste:(Sniplets at:snipletToPaste).
+
+    "Modified: / 24-11-2006 / 12:44:16 / cg"
+!
+
 printIt
     self selectedWorkspacesTextView printIt
 !
@@ -1496,6 +1756,30 @@
     Smalltalk removeKey:nameKey
 !
 
+removeSharedPool
+    |poolToRemove|
+
+    poolsConsideredInDoIts isEmptyOrNil ifTrue:[
+        Dialog information:'No pools have been added yet'.
+        ^ self.
+    ].
+
+    poolToRemove := Dialog 
+                choose:'Pool to Remove (No longer known in doIt-Evaluations):'
+                fromList:(poolsConsideredInDoIts asOrderedCollection sort)
+                lines:10.
+
+    poolToRemove isNil ifTrue:[
+        ^ self
+    ].
+    poolsConsideredInDoIts remove:poolToRemove.
+    workspaces do:[:ws |
+        ws poolsConsideredInDoits:poolsConsideredInDoIts.
+    ].
+
+    "Modified: / 24-11-2006 / 12:44:16 / cg"
+!
+
 removeWorkspaceVariable
     |name selection wsVarNames|
 
@@ -1811,6 +2095,7 @@
 
     ws := (HVScrollableView for:Workspace).
     ws autoDefineVariables:autoDefineVariables.
+    ws poolsConsideredInDoIts:poolsConsideredInDoIts.
     ^ ws
 !
 
@@ -1880,5 +2165,5 @@
 !WorkspaceApplication class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/WorkspaceApplication.st,v 1.144 2007-11-02 10:08:12 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/WorkspaceApplication.st,v 1.145 2008-01-24 13:50:20 cg Exp $'
 ! !