MultiViewToolApplication.st
changeset 7475 54b889153fc7
parent 6863 4e2e267622eb
child 7650 12fcca896ba0
--- a/MultiViewToolApplication.st	Wed Oct 25 15:03:32 2006 +0200
+++ b/MultiViewToolApplication.st	Wed Oct 25 15:03:36 2006 +0200
@@ -9,7 +9,6 @@
  other person.  No title to or ownership of the software is
  hereby transferred.
 "
-
 "{ Package: 'stx:libtool' }"
 
 ToolApplicationModel subclass:#MultiViewToolApplication
@@ -47,23 +46,265 @@
 !MultiViewToolApplication class methodsFor:'interface specs'!
 
 windowSpec
-    "raise an error: must be redefined in concrete subclass(es)"
+    "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>
 
-    ^ self subclassResponsibility
+    ^ 
+     #(FullSpec
+        name: windowSpec
+        window: 
+       (WindowSpec
+          label: 'Workspace'
+          name: 'Workspace'
+          min: (Point 10 10)
+          bounds: (Rectangle 0 0 432 241)
+          menu: mainMenu
+        )
+        component: 
+       (SpecCollection
+          collection: (
+           (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:
+              destroyTabAction: destroyTab:
+              canvas: workspaceHolder
+              canvasInset: 0
+              keepCanvasAlive: true
+              tabLevel: 1
+            )
+           )
+         
+        )
+      )
 ! !
 
 !MultiViewToolApplication class methodsFor:'menu specs'!
 
 mainMenu
-    "raise an error: must be redefined in concrete subclass(es)"
+    "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:MultiViewToolApplication andSelector:#mainMenu
+     (Menu new fromLiteralArrayEncoding:(MultiViewToolApplication mainMenu)) startUp
+    "
+
+    <resource: #menu>
 
-    ^ self subclassResponsibility
+    ^ 
+     #(Menu
+        (
+         (MenuItem
+            label: 'File'
+            translateLabel: true
+            submenu: 
+           (Menu
+              (
+               (MenuItem
+                  label: 'New Editor'
+                  itemValue: newWorkspace
+                  translateLabel: true
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'Load File...'
+                  itemValue: menuLoad
+                  translateLabel: true
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'Save As...'
+                  itemValue: menuSaveAs
+                  translateLabel: true
+                )
+               (MenuItem
+                  enabled: hasMultipleBuffersHolder
+                  label: 'Save all As...'
+                  itemValue: menuSaveAllAs
+                  translateLabel: true
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'Print...'
+                  itemValue: menuPrint
+                  translateLabel: true
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'Exit'
+                  itemValue: closeRequest
+                  translateLabel: true
+                )
+               )
+              nil
+              nil
+            )
+          )
+         (MenuItem
+            label: 'Buffers'
+            nameKey: Buffer
+            translateLabel: true
+            submenu: 
+           (Menu
+              (
+               (MenuItem
+                  label: 'Add Buffer'
+                  itemValue: addWorkspace
+                  translateLabel: true
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'Rename...'
+                  itemValue: renameWorkspace
+                  translateLabel: true
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  enabled: canRemoveWorkspace
+                  label: 'Remove Buffer'
+                  itemValue: removeWorkspace
+                  translateLabel: true
+                )
+               )
+              nil
+              nil
+            )
+          )
+         (MenuItem
+            label: 'Edit'
+            translateLabel: true
+            submenu: 
+           (Menu
+              (
+               (MenuItem
+                  enabled: hasSelectionInActiveWorkspace
+                  label: 'Cut'
+                  itemValue: cutSelection
+                  translateLabel: true
+                )
+               (MenuItem
+                  enabled: hasSelectionInActiveWorkspace
+                  label: 'Copy'
+                  itemValue: copySelection
+                  translateLabel: true
+                )
+               (MenuItem
+                  label: 'Paste'
+                  itemValue: paste
+                  translateLabel: true
+                )
+               (MenuItem
+                  label: '-'
+                )
+               (MenuItem
+                  label: 'Select All'
+                  itemValue: selectAll
+                  translateLabel: true
+                )
+               )
+              nil
+              nil
+            )
+          )
+         (MenuItem
+            label: 'MENU_Help'
+            translateLabel: true
+            startGroup: conditionalRight
+            submenu: 
+           (Menu
+              (
+               (MenuItem
+                  label: 'About this Application...'
+                  itemValue: openAboutThisApplication
+                  translateLabel: true
+                )
+               )
+              nil
+              nil
+            )
+          )
+         )
+        nil
+        nil
+      )
 !
 
 tabMenu
-    "raise an error: must be redefined in concrete subclass(es)"
+    "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>
 
-    ^ self subclassResponsibility
+    ^
+     #(#Menu
+        #(
+         #(#MenuItem
+            #label: 'Add Tab'
+            #translateLabel: true
+            "/ #triggerOnDown: true
+            #value: #addWorkspace
+          )
+         #(#MenuItem
+            #label: '-'
+          )
+         #(#MenuItem
+            #label: 'Remove Tab'
+            #translateLabel: true
+            "/ #triggerOnDown: true
+            #value: #removeWorkspace:
+            #enabled: #canRemoveWorkspace:
+          )
+         #(#MenuItem
+            #label: '-'
+          )
+         #(#MenuItem
+            #label: 'Rename...'
+            #translateLabel: true
+            "/ #triggerOnDown: true
+            #value: #renameWorkspace:
+          )
+         )
+        nil
+        nil
+      )
 ! !
 
 !MultiViewToolApplication class methodsFor:'queries'!
@@ -176,6 +417,32 @@
     ^ v notNil and:[v selectionAsString size > 0]
 ! !
 
+!MultiViewToolApplication methodsFor:'defaults'!
+
+defaultFileNameForLoad
+   ^ 'file.txt'
+
+    "Created: / 25-10-2006 / 14:56:19 / cg"
+!
+
+defaultFileNameForSave
+    ^ 'file.txt'
+
+    "Modified: / 25-10-2006 / 14:54:13 / cg"
+!
+
+defaultFileNameForSaveAll
+   ^ 'file.txt'
+
+    "Modified: / 25-10-2006 / 14:55:50 / cg"
+!
+
+defaultPatternLoad
+   ^ '*.txt'
+
+    "Created: / 25-10-2006 / 14:57:18 / cg"
+! !
+
 !MultiViewToolApplication methodsFor:'menu-actions'!
 
 addWindow:aWindow named:name
@@ -207,18 +474,78 @@
 "/    workspaceHolder value:aWindow.
 !
 
-defaultFileNameForSave
-    ^ 'file.wsp'
-!
-
-defaultFileNameForSaveAll
-   ^ 'file.wsp'
+addWorkspace
+    self addWindow:(self createWorkspace) named:'Workspace%1'
 !
 
 destroyTab:tabIndex
     self removeWorkspace:tabIndex
 !
 
+loadFile:aFileName 
+    self loadFile:aFileName encoding:nil
+!
+
+loadFile:aFileName encoding:encodingSymbolOrNil
+    |lbl|
+
+    lbl := aFileName asFilename withoutSuffix baseName.
+    self loadFile:aFileName encoding:encodingSymbolOrNil label:lbl.
+!
+
+loadFile:aFileName encoding:encodingSymbolOrNil label:label
+    |file ws|
+
+    file := aFileName asFilename.
+    ws := self selectedWorkspacesTextView.
+    [
+        |contents|
+
+        contents := file contents.
+        encodingSymbolOrNil notNil ifTrue:[
+            contents := contents encodeFrom:encodingSymbolOrNil into:#'unicode'.
+            ws externalEncoding:encodingSymbolOrNil.
+        ].
+        ws contents:contents.
+        ws defaultFileNameForFileDialog:file pathName.
+    ] on:StreamError do:[:ex|
+        Dialog warn:(resources string:'Cannot open %1: %2' with:file asString with:ex description).
+        ^ self
+    ].
+    ws modified:false.
+
+    tabList size <= 1 ifTrue:[
+        self window label:label.
+    ] ifFalse:[
+        tabList at:self selectedWorkspaceIndexHolder value put:label
+    ]
+!
+
+menuLoad
+    |file|
+
+    (self askIfModified:'Text was modified. Load anyway ?' yesButton:'Load') ifFalse:[ ^ self].
+
+    file := Dialog 
+                requestFileName:(resources string:'Load file') 
+                default:(self defaultFileNameForLoad) 
+                pattern:(self defaultPatternLoad).
+    file size ~~ 0 ifTrue:[
+        self loadFile:file
+    ]
+
+    "Modified: / 25-10-2006 / 14:57:34 / cg"
+!
+
+menuPrint
+    |ws|
+
+    ws := self selectedWorkspacesTextView.
+    ws doPrint
+
+    "Created: / 25-10-2006 / 15:01:51 / cg"
+!
+
 menuSaveAllAs
     self 
         askForFile:'Save all Buffers into:' 
@@ -255,6 +582,8 @@
 
 newWorkspace
     self class new openWithExtent:(self builder window extent).
+
+    "Modified: / 25-10-2006 / 14:39:15 / cg"
 !
 
 removeWorkspace
@@ -407,9 +736,12 @@
 !
 
 createWorkspace
-    "raise an error: must be redefined in concrete subclass(es)"
+    |ws|
 
-    ^ self subclassResponsibility
+    ws := (HVScrollableView for:EditTextView).
+    ^ ws
+
+    "Modified: / 25-10-2006 / 14:34:19 / cg"
 !
 
 isModifiedWorkspace:aView
@@ -459,5 +791,5 @@
 !MultiViewToolApplication class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/MultiViewToolApplication.st,v 1.11 2006-08-09 12:48:41 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/MultiViewToolApplication.st,v 1.12 2006-10-25 13:03:36 cg Exp $'
 ! !