3229
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2013 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libview2' }"
|
|
13 |
|
|
14 |
ApplicationModel subclass:#ApplicationWithFileHistory
|
|
15 |
instanceVariableNames:''
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Interface-Framework'
|
|
19 |
!
|
|
20 |
|
|
21 |
ApplicationWithFileHistory class instanceVariableNames:'fileHistory'
|
|
22 |
|
|
23 |
"
|
|
24 |
The following class instance variables are inherited by this class:
|
|
25 |
|
|
26 |
ApplicationModel - ClassResources
|
|
27 |
Model -
|
|
28 |
Object -
|
|
29 |
"
|
|
30 |
!
|
|
31 |
|
|
32 |
!ApplicationWithFileHistory class methodsFor:'documentation'!
|
|
33 |
|
|
34 |
copyright
|
|
35 |
"
|
|
36 |
COPYRIGHT (c) 2013 by Claus Gittinger
|
|
37 |
All Rights Reserved
|
|
38 |
|
|
39 |
This software is furnished under a license and may be used
|
|
40 |
only in accordance with the terms of that license and with the
|
|
41 |
inclusion of the above copyright notice. This software may not
|
|
42 |
be provided or otherwise made available to, or used by, any
|
|
43 |
other person. No title to or ownership of the software is
|
|
44 |
hereby transferred.
|
|
45 |
"
|
|
46 |
!
|
|
47 |
|
|
48 |
documentation
|
|
49 |
"
|
|
50 |
Support code for applications with a persistent history of
|
|
51 |
previously opened files.
|
|
52 |
|
|
53 |
[author:]
|
|
54 |
Claus Gittinger
|
|
55 |
|
|
56 |
[see also:]
|
|
57 |
StandardSystemView
|
|
58 |
WindowGroup DeviceWorkstation
|
|
59 |
"
|
|
60 |
! !
|
|
61 |
|
|
62 |
!ApplicationWithFileHistory class methodsFor:'file history support'!
|
|
63 |
|
|
64 |
addToFileHistory:aFilename
|
|
65 |
|fileHistory|
|
|
66 |
|
|
67 |
fileHistory := self fileHistory.
|
|
68 |
fileHistory synchronized:[
|
|
69 |
fileHistory addFirst:aFilename asFilename.
|
|
70 |
fileHistory size > self fileHistorySize ifTrue:[
|
|
71 |
fileHistory removeLast.
|
|
72 |
].
|
|
73 |
self makeFileHistoryPersistent
|
|
74 |
]
|
|
75 |
|
|
76 |
"Modified: / 09-11-2010 / 16:07:14 / cg"
|
|
77 |
!
|
|
78 |
|
|
79 |
directoryForFileHistory
|
|
80 |
^ Filename homeDirectory / '.smalltalk' / (self nameWithoutPrefix)
|
|
81 |
|
|
82 |
"
|
|
83 |
self directoryForFileHistory
|
|
84 |
"
|
|
85 |
!
|
|
86 |
|
|
87 |
fetchFileHistoryFromPersistentStore
|
|
88 |
|k index value dir fn|
|
|
89 |
|
|
90 |
fileHistory := OrderedSet new.
|
|
91 |
|
|
92 |
OperatingSystem isMSWINDOWSlike ifTrue:[
|
|
93 |
k := self registryKeyForFileHistory.
|
|
94 |
index := 1.
|
|
95 |
[
|
|
96 |
value := k valueNamed:(index printString).
|
|
97 |
value notNil
|
|
98 |
] whileTrue:[
|
|
99 |
fileHistory add:value asFilename.
|
|
100 |
index := index + 1
|
|
101 |
].
|
|
102 |
] ifFalse:[
|
|
103 |
dir := self directoryForFileHistory.
|
|
104 |
dir exists ifTrue:[
|
|
105 |
fn := dir / 'history'.
|
|
106 |
fn exists ifTrue:[
|
|
107 |
fileHistory addAll:(fn contents collect:[:s | s asFilename])
|
|
108 |
]
|
|
109 |
]
|
|
110 |
]
|
|
111 |
!
|
|
112 |
|
|
113 |
fileHistory
|
|
114 |
fileHistory isNil ifTrue:[
|
|
115 |
self initializeFileHistory
|
|
116 |
].
|
|
117 |
^ fileHistory
|
|
118 |
!
|
|
119 |
|
|
120 |
fileHistorySize
|
|
121 |
"defines the number of remembered files in the history"
|
|
122 |
|
|
123 |
^ 20.
|
|
124 |
!
|
|
125 |
|
|
126 |
initializeFileHistory
|
|
127 |
fileHistory := OrderedSet new.
|
|
128 |
self fetchFileHistoryFromPersistentStore.
|
|
129 |
!
|
|
130 |
|
|
131 |
makeFileHistoryPersistent
|
|
132 |
|k index dir fn|
|
|
133 |
|
|
134 |
OperatingSystem isMSWINDOWSlike ifTrue:[
|
|
135 |
k := self registryKeyForFileHistory.
|
|
136 |
fileHistory doWithIndex:[:filePath :index |
|
|
137 |
k valueNamed:(index printString) put:filePath asFilename pathName.
|
|
138 |
].
|
|
139 |
|
|
140 |
"/ remove the remaining keys
|
|
141 |
index := fileHistory size + 1.
|
|
142 |
[
|
|
143 |
k deleteValueNamed:(index printString)
|
|
144 |
] whileTrue:[
|
|
145 |
index := index + 1
|
|
146 |
].
|
|
147 |
] ifFalse:[
|
|
148 |
(dir := self directoryForFileHistory) exists ifFalse:[
|
|
149 |
dir recursiveMakeDirectory
|
|
150 |
].
|
|
151 |
fn := dir / 'history'.
|
|
152 |
fn contents:(fileHistory collect:[:fn | fn pathName]).
|
|
153 |
]
|
|
154 |
!
|
|
155 |
|
|
156 |
registryKeyForApplication
|
|
157 |
"HKEY_CURRENT_USER\Software\Exept\SmalltalkX\<appname>"
|
|
158 |
|
|
159 |
|k_software k_exept k_stx k_app keyName|
|
|
160 |
|
|
161 |
OperatingSystem isMSWINDOWSlike ifTrue:[
|
|
162 |
keyName := self nameWithoutPrefix.
|
|
163 |
|
|
164 |
k_software := Win32OperatingSystem registryEntry key:'HKEY_CURRENT_USER\Software\'.
|
|
165 |
(k_exept := k_software subKeyNamed:'Exept') isNil ifTrue:[
|
|
166 |
k_exept := k_software createSubKeyNamed:'Exept'
|
|
167 |
].
|
|
168 |
(k_stx := k_exept subKeyNamed:'SmalltalkX') isNil ifTrue:[
|
|
169 |
k_stx := k_exept createSubKeyNamed:'SmalltalkX'
|
|
170 |
].
|
|
171 |
(k_app := k_stx subKeyNamed:keyName) isNil ifTrue:[
|
|
172 |
k_app := k_stx createSubKeyNamed:keyName
|
|
173 |
].
|
|
174 |
^ k_app
|
|
175 |
].
|
|
176 |
|
|
177 |
^ nil
|
|
178 |
|
|
179 |
"
|
|
180 |
self registryKeyForApplication
|
|
181 |
"
|
|
182 |
|
|
183 |
"Created: / 11-01-2011 / 19:58:26 / cg"
|
|
184 |
!
|
|
185 |
|
|
186 |
registryKeyForFileHistory
|
|
187 |
"HKEY_CURRENT_USER\Software\Exept\SmalltalkX\<appName>\History"
|
|
188 |
|
|
189 |
|k_app k_history|
|
|
190 |
|
|
191 |
OperatingSystem isMSWINDOWSlike ifTrue:[
|
|
192 |
k_app := self registryKeyForApplication.
|
|
193 |
(k_history := k_app subKeyNamed:'History') isNil ifTrue:[
|
|
194 |
k_history := k_app createSubKeyNamed:'History'
|
|
195 |
].
|
|
196 |
^ k_history
|
|
197 |
].
|
|
198 |
|
|
199 |
^ nil
|
|
200 |
|
|
201 |
"
|
|
202 |
self registryKeyForFileHistory
|
|
203 |
"
|
|
204 |
! !
|
|
205 |
|
|
206 |
!ApplicationWithFileHistory class methodsFor:'documentation'!
|
|
207 |
|
|
208 |
version
|
|
209 |
^ '$Header: /cvs/stx/stx/libview2/ApplicationWithFileHistory.st,v 1.1 2013-09-05 22:23:55 cg Exp $'
|
|
210 |
!
|
|
211 |
|
|
212 |
version_CVS
|
|
213 |
^ '$Header: /cvs/stx/stx/libview2/ApplicationWithFileHistory.st,v 1.1 2013-09-05 22:23:55 cg Exp $'
|
|
214 |
! !
|
|
215 |
|