WorkspaceApplication.st
changeset 3154 859688212191
child 3160 9cae0009d9f0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WorkspaceApplication.st	Wed Sep 12 09:24:25 2001 +0200
@@ -0,0 +1,324 @@
+"{ Package: 'stx:libtool' }"
+
+ToolApplicationModel subclass:#WorkspaceApplication
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Interface-Smalltalk'
+!
+
+
+!WorkspaceApplication class methodsFor:'interface specs'!
+
+windowSpec
+    "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:#windowSpec
+     WorkspaceApplication new openInterface:#windowSpec
+     WorkspaceApplication open
+    "
+
+    <resource: #canvas>
+
+    ^ 
+     #(#FullSpec
+        #name: #windowSpec
+        #window: 
+       #(#WindowSpec
+          #label: 'Workspace'
+          #name: 'Workspace'
+          #min: #(#Point 10 10)
+          #max: #(#Point 1024 768)
+          #bounds: #(#Rectangle 170 332 602 573)
+          #menu: #mainMenu
+        )
+        #component: 
+       #(#SpecCollection
+          #collection: #(
+           #(#ArbitraryComponentSpec
+              #name: 'WorkspaceView'
+              #layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
+              #hasHorizontalScrollBar: true
+              #hasVerticalScrollBar: true
+              #miniScrollerVertical: false
+              #hasBorder: false
+              #component: #Workspace
+            )
+           )
+         
+        )
+      )
+! !
+
+!WorkspaceApplication class methodsFor:'menu specs'!
+
+mainMenu
+    "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:#mainMenu
+     (Menu new fromLiteralArrayEncoding:(WorkspaceApplication mainMenu)) startUp
+    "
+
+    <resource: #menu>
+
+    ^ 
+     #(#Menu
+        #(
+         #(#MenuItem
+            #label: 'File'
+            #translateLabel: true
+            #submenu: 
+           #(#Menu
+              #(
+               #(#MenuItem
+                  #label: 'New'
+                  #translateLabel: true
+                  #value: #menuNew
+                  #isVisible: false
+                )
+               #(#MenuItem
+                  #label: '-'
+                  #isVisible: false
+                )
+               #(#MenuItem
+                  #label: 'Load File...'
+                  #translateLabel: true
+                  #value: #menuLoad
+                )
+               #(#MenuItem
+                  #label: '-'
+                )
+               #(#MenuItem
+                  #label: 'Save As...'
+                  #translateLabel: true
+                  #value: #menuSaveAs
+                )
+               #(#MenuItem
+                  #label: '-'
+                )
+               #(#MenuItem
+                  #label: 'Exit'
+                  #translateLabel: true
+                  #value: #closeRequest
+                )
+               )
+              nil
+              nil
+            )
+          )
+         #(#MenuItem
+            #label: 'Edit'
+            #translateLabel: true
+            #submenu: 
+           #(#Menu
+              #(
+               #(#MenuItem
+                  #label: 'Copy'
+                  #translateLabel: true
+                  #value: #copySelection
+                )
+               #(#MenuItem
+                  #label: 'Cut'
+                  #translateLabel: true
+                  #value: #cutSelection
+                )
+               #(#MenuItem
+                  #label: 'Paste'
+                  #translateLabel: true
+                  #value: #paste
+                )
+               )
+              nil
+              nil
+            )
+          )
+         #(#MenuItem
+            #label: 'Smalltalk'
+            #translateLabel: true
+            #submenu: 
+           #(#Menu
+              #(
+               #(#MenuItem
+                  #label: 'DoIt'
+                  #translateLabel: true
+                  #value: #doIt
+                )
+               #(#MenuItem
+                  #label: 'PrintIt'
+                  #translateLabel: true
+                  #value: #printIt
+                )
+               #(#MenuItem
+                  #label: 'InspectIt'
+                  #translateLabel: true
+                  #value: #inspectIt
+                )
+               #(#MenuItem
+                  #label: '-'
+                )
+               #(#MenuItem
+                  #label: 'Browse'
+                  #translateLabel: true
+                  #value: #browseIt
+                )
+               )
+              nil
+              nil
+            )
+          )
+         #(#MenuItem
+            #label: 'Help'
+            #translateLabel: true
+            #startGroup: #right
+            #submenu: 
+           #(#Menu
+              #(
+               #(#MenuItem
+                  #label: 'Documentation'
+                  #translateLabel: true
+                  #value: #openDocumentation
+                )
+               #(#MenuItem
+                  #label: '-'
+                )
+               #(#MenuItem
+                  #label: 'About this Application'
+                  #translateLabel: true
+                  #value: #openAboutThisApplication
+                )
+               )
+              nil
+              nil
+            )
+          )
+         )
+        nil
+        nil
+      )
+! !
+
+!WorkspaceApplication methodsFor:'accessing'!
+
+workspaceView
+    ^ (builder componentAt:#WorkspaceView)
+! !
+
+!WorkspaceApplication methodsFor:'initialization & release'!
+
+closeRequest
+    (self askIfModified:'Close without saving ?' 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'!
+
+browseIt
+    self workspaceView browseIt
+!
+
+copySelection
+    self workspaceView copySelection
+!
+
+cutSelection
+    self workspaceView cutSelection
+!
+
+doIt
+    self workspaceView doIt
+!
+
+inspectIt
+    self workspaceView inspectIt
+!
+
+menuLoad
+    |file|
+
+    (self askIfModified:'Text was modified. Load anyway ?' yesButton:'Load').
+    file := Dialog requestFileName:'Load file:'.
+    file size > 0 ifTrue:[
+       self workspaceView contents:file asFilename contentsOfEntireFile.
+    ]
+!
+
+menuSaveAs
+    |file|
+
+    (self askIfModified:'Text was modified. Save anyway ?' yesButton:'Load').
+    file := Dialog requestFileName:'Save file:'.
+    file size > 0 ifTrue:[
+       self workspaceView saveAs:file.
+    ]
+!
+
+openDocumentation
+    "opens the documentation file"
+
+    self openHTMLDocument: 'tools/misc/TOP.html#WORKSPACE'
+!
+
+paste
+    self workspaceView paste
+!
+
+printIt
+    self workspaceView printIt
+! !
+
+!WorkspaceApplication methodsFor:'private'!
+
+askIfModified:question yesButton:yesButtonText
+    "tell user, that code has been modified - let her confirm"
+
+    |textView|
+
+    textView := self workspaceView.
+    (textView modified not or:[textView contentsWasSaved]) ifTrue:[
+        ^ true
+    ].
+    (Dialog 
+        confirm:(resources string:question) withCRs
+        yesLabel:(resources at:yesButtonText)
+        noLabel:(resources at:'Cancel'))
+    ifTrue:[
+        "/ reset modified flag so question is asked only once
+        textView modified:false.
+        ^ true
+    ].
+    ^ false
+
+    "Modified: 2.10.1997 / 14:23:47 / stefan"
+! !
+
+!WorkspaceApplication class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libtool/WorkspaceApplication.st,v 1.1 2001-09-12 07:24:25 cg Exp $'
+! !