WorkspaceApplication.st
changeset 3193 e35a94b5c2a0
parent 3191 52879128b8a3
child 3195 9d0c0c9fade6
--- a/WorkspaceApplication.st	Mon Sep 24 21:01:22 2001 +0200
+++ b/WorkspaceApplication.st	Tue Sep 25 12:08:05 2001 +0200
@@ -1,7 +1,7 @@
 "{ Package: 'stx:libtool' }"
 
 ToolApplicationModel subclass:#WorkspaceApplication
-	instanceVariableNames:''
+	instanceVariableNames:'workspaces tabList selectedWorkspaceIndexHolder workspaceHolder'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Interface-Smalltalk'
@@ -44,7 +44,7 @@
           #name: 'Workspace'
           #min: #(#Point 10 10)
           #max: #(#Point 1024 768)
-          #bounds: #(#Rectangle 170 332 602 573)
+          #bounds: #(#Rectangle 16 46 448 287)
           #menu: #mainMenu
         )
         #component: 
@@ -59,6 +59,19 @@
               #hasBorder: false
               #component: #Workspace
             )
+           #(#NoteBookViewSpec
+              #name: 'NoteBook1'
+              #layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
+              #model: #selectedWorkspaceIndexHolder
+              #menu: #tabList
+              #useIndex: true
+              #accessTabMenuAction: #tabMenuAt:
+              #canvas: #workspaceHolder
+              #canvasInset: 0
+              #canvasFrameLevel: 0
+              #keepCanvasAlive: true
+              #tabLevel: 2
+            )
            )
          
         )
@@ -93,8 +106,8 @@
                #(#MenuItem
                   #label: 'New'
                   #translateLabel: true
+                  #isVisible: false
                   #value: #menuNew
-                  #isVisible: false
                 )
                #(#MenuItem
                   #label: '-'
@@ -127,6 +140,40 @@
             )
           )
          #(#MenuItem
+            #label: 'Workspace'
+            #translateLabel: true
+            #nameKey: #Workspace
+            #submenu: 
+           #(#Menu
+              #(
+               #(#MenuItem
+                  #label: 'Add'
+                  #translateLabel: true
+                  #triggerOnDown: true
+                  #value: #addWorkspace
+                )
+               #(#MenuItem
+                  #label: 'Rename...'
+                  #translateLabel: true
+                  #triggerOnDown: true
+                  #value: #renameWorkspace
+                )
+               #(#MenuItem
+                  #label: '-'
+                )
+               #(#MenuItem
+                  #label: 'Remove'
+                  #translateLabel: true
+                  #triggerOnDown: true
+                  #value: #removeWorkspace
+                  #enabled: #canRemoveWorkspace
+                )
+               )
+              nil
+              nil
+            )
+          )
+         #(#MenuItem
             #label: 'Edit'
             #translateLabel: true
             #submenu: 
@@ -215,77 +262,211 @@
         nil
         nil
       )
+!
+
+tabMenu
+    "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:WorkspaceApplication andSelector:#tabMenu
+     (Menu new fromLiteralArrayEncoding:(WorkspaceApplication tabMenu)) startUp
+    "
+
+    <resource: #menu>
+
+    ^ 
+     #(#Menu
+        #(
+         #(#MenuItem
+            #label: 'Add'
+            #translateLabel: true
+            #triggerOnDown: true
+            #value: #addWorkspace
+          )
+         #(#MenuItem
+            #label: 'Rename...'
+            #translateLabel: true
+            #triggerOnDown: true
+            #value: #renameWorkspace:
+          )
+         #(#MenuItem
+            #label: '-'
+          )
+         #(#MenuItem
+            #label: 'Remove'
+            #translateLabel: true
+            #triggerOnDown: true
+            #value: #removeWorkspace:
+            #enabled: #canRemoveWorkspace:
+          )
+         )
+        nil
+        nil
+      )
 ! !
 
 !WorkspaceApplication methodsFor:'accessing'!
 
-workspaceView
-    ^ (builder componentAt:#WorkspaceView)
+selectedWorkspace
+    |wsIndex|
+
+    workspaces isNil ifTrue:[
+        workspaces := OrderedCollection new.
+    ].
+    wsIndex := self selectedWorkspaceIndexHolder value.
+    wsIndex == 0 ifTrue:[
+        ^ nil
+    ].
+
+    workspaces size < wsIndex ifTrue:[
+        workspaces grow:wsIndex.
+        workspaces at:wsIndex put:(HVScrollableView for:Workspace).
+    ].
+    ^ workspaces at:wsIndex
+!
+
+tabMenuAt:index
+    |m i|
+
+    m := self class tabMenu.
+    m := m decodeAsLiteralArray.
+    i := m detectItem:[:item | item value == #removeWorkspace:] ifNone:nil.
+    i notNil ifTrue:[
+        i argument:index.
+        index ~~ self selectedWorkspaceIndexHolder value ifTrue:[
+            "/ for now: if that buffer is modified,
+            "/ do not allow removing.
+            "/ (must be brought to front, in order for check-for-modification to work)
+            (workspaces at:index) modified ifTrue:[
+                i disable
+            ].
+        ].
+    ].
+    i := m detectItem:[:item | item value == #renameWorkspace:] ifNone:nil.
+    i notNil ifTrue:[
+        i argument:index.
+    ].
+
+    m findGuiResourcesIn:self.
+    ^ m
+!
+
+workspace
+    |wsIndex|
+
+    workspaces isNil ifTrue:[
+        workspaces := OrderedCollection new.
+    ].
+    wsIndex := self selectedWorkspaceIndexHolder value.
+    workspaces size < wsIndex ifTrue:[
+        workspaces grow:wsIndex.
+        workspaces at:wsIndex put:(HVScrollableView for:Workspace).
+    ].
+    ^ workspaces at:wsIndex
+!
+
+workspaceHolder
+    workspaceHolder isNil ifTrue:[
+        workspaceHolder := ValueHolder with:(self selectedWorkspace)..
+    ].
+    ^ workspaceHolder
+! !
+
+!WorkspaceApplication methodsFor:'aspects'!
+
+selectedWorkspaceIndexHolder
+    selectedWorkspaceIndexHolder isNil ifTrue:[
+        selectedWorkspaceIndexHolder := 1 asValue.
+        selectedWorkspaceIndexHolder onChangeSend:#workspaceSelectionChanged to:self.
+    ].
+    ^ selectedWorkspaceIndexHolder.
+!
+
+tabList
+    tabList isNil ifTrue:[
+        tabList := List new.
+    ].
+    ^ tabList.
+! !
+
+!WorkspaceApplication methodsFor:'aspects - queries'!
+
+canRemoveWorkspace
+    ^ self tabList size > 1
 ! !
 
 !WorkspaceApplication methodsFor:'initialization & release'!
 
 closeRequest
-    (self askIfModified:'Close without saving ?' yesButton:'Close') ifFalse:[
+    (self askIfModified:'Text was modified. Close anyway ?' yesButton:'Close') ifFalse:[
         ^ self
     ].
 
     ^ super closeRequest
-!
-
-postBuildWith:aBuilder
-    "This is a hook method generated by the Browser.
-     It will be invoked during the initialization of your app/dialog,
-     after all of the visual components have been built, 
-     but BEFORE the top window is made visible.
-     Add any app-specific actions here (reading files, setting up
-     values etc.)"
-
-    "/ add any code here ...
-
-    ^ super postBuildWith:aBuilder
 ! !
 
 !WorkspaceApplication methodsFor:'menu actions'!
 
+addWorkspace
+    |tabList wsIndex|
+
+    tabList := self tabList.
+    wsIndex := tabList size + 1.
+    wsIndex == 1 ifTrue:[
+        "/ first - add a name for the first tab
+        tabList add:(self window label). "/ 'Workspace'.
+        wsIndex := wsIndex + 1.
+    ].
+
+    tabList add:('Workspace%1' bindWith:wsIndex).
+    workspaces grow:wsIndex.
+    workspaces at:wsIndex put:(HVScrollableView for:Workspace).
+    self selectedWorkspaceIndexHolder value:wsIndex   
+!
+
 browseIt
-    self workspaceView browseIt
+    self selectedWorkspace browseIt
 !
 
 copySelection
-    self workspaceView copySelection
+    self selectedWorkspace copySelection
 !
 
 cutSelection
-    self workspaceView cutSelection
+    self selectedWorkspace cutSelection
 !
 
 doIt
-    self workspaceView doIt
+    self selectedWorkspace doIt
 !
 
 inspectIt
-    self workspaceView inspectIt
+    self selectedWorkspace inspectIt
 !
 
 menuLoad
-    |file|
+    |file ws|
 
-    (self askIfModified:'Text was modified. Load anyway ?' yesButton:'Load').
+    (self askIfModified:'Text was modified. Load anyway ?' yesButton:'Load') ifFalse:[ ^ self].
+
     file := Dialog requestFileName:'Load file:'.
     file size > 0 ifTrue:[
-       self workspaceView contents:file asFilename contentsOfEntireFile.
+        (ws := self selectedWorkspace) contents:file asFilename contentsOfEntireFile.
+        ws modified:false.        
     ]
 !
 
 menuSaveAs
-    |file|
+    |file ws|
 
-    file := Dialog 
-                requestFileName:'Save file:'
-                default:'file.wsp'. 
+    file := Dialog requestFileName:'Save file:' default:'file.wsp'. 
     file size > 0 ifTrue:[
-       self workspaceView saveAs:file.
+        (ws := self selectedWorkspace) saveAs:file.
+        ws modified:false.
     ]
 !
 
@@ -296,11 +477,70 @@
 !
 
 paste
-    self workspaceView paste
+    self selectedWorkspace paste
 !
 
 printIt
-    self workspaceView printIt
+    self selectedWorkspace printIt
+!
+
+removeWorkspace
+    self removeWorkspace:(self selectedWorkspaceIndexHolder value)
+!
+
+removeWorkspace:wsIndex
+    |tabList newWsIndex|
+
+    wsIndex == self selectedWorkspaceIndexHolder value ifTrue:[
+        (self askIfModified:'Text was modified. Remove anyway ?' yesButton:'Remove') ifFalse:[
+            ^ self
+        ].
+    ].
+
+    tabList := self tabList.
+
+    wsIndex == tabList size ifTrue:[
+        newWsIndex := wsIndex - 1.
+    ] ifFalse:[
+        newWsIndex := wsIndex.
+    ].
+
+    tabList removeIndex:wsIndex.
+    (workspaces at:wsIndex) destroy.
+    workspaces removeIndex:wsIndex.
+
+    tabList size == 1 ifTrue:[
+        self window label:(tabList at:1).
+        tabList removeIndex:1
+    ].
+
+    self selectedWorkspaceIndexHolder value:newWsIndex.
+    "/ to force change (update workspaceHolder - even if same index)
+    self selectedWorkspaceIndexHolder changed:#value.   
+!
+
+renameWorkspace
+    self renameWorkspace:(self selectedWorkspaceIndexHolder value)
+!
+
+renameWorkspace:wsIndex
+    |tabList oldName newName|
+
+    tabList := self tabList.
+    tabList isEmpty ifTrue:[
+        oldName := self window label
+    ] ifFalse:[
+        oldName := tabList at:wsIndex.
+    ].
+    newName := Dialog request:(resources string:'New Name for %1:' with:oldName) initialAnswer:oldName.
+    newName size == 0 ifTrue:[ ^ self].
+
+    tabList notEmpty ifTrue:[
+        tabList at:wsIndex put:newName.
+    ].
+    wsIndex == self selectedWorkspaceIndexHolder value ifTrue:[
+        self window label:newName.
+    ].
 ! !
 
 !WorkspaceApplication methodsFor:'private'!
@@ -310,7 +550,7 @@
 
     |textView|
 
-    textView := self workspaceView.
+    textView := self selectedWorkspace.
     (textView modified not or:[textView contentsWasSaved]) ifTrue:[
         ^ true
     ].
@@ -326,10 +566,23 @@
     ^ false
 
     "Modified: 2.10.1997 / 14:23:47 / stefan"
+!
+
+workspaceSelectionChanged
+    |wsIndex windowLabel|
+
+    "/ self selected
+    self workspaceHolder value:(self selectedWorkspace).
+    wsIndex := self selectedWorkspaceIndexHolder value.
+
+    wsIndex ~~ 0 ifTrue:[
+        windowLabel := tabList at:wsIndex ifAbsent:nil.
+        windowLabel notNil ifTrue:[self window label:windowLabel].
+    ].
 ! !
 
 !WorkspaceApplication class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/WorkspaceApplication.st,v 1.3 2001-09-24 13:39:53 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/WorkspaceApplication.st,v 1.4 2001-09-25 10:08:05 cg Exp $'
 ! !