Automatic save and load of a model to a particular file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Automatic save and load of a model to a particular file

Günther Schmidt
Hi,

my application's main window is a document shell. How do I make my
application load or save the model to a predetermined file/location
without any user interference?

ie. when the application starts, the last saved model is automatically
loaded and when the application closes the model is also saved.

Also how can I determine the path to be different in a multi user
environment so that each user would have his/her own data?

Günther


Reply | Threaded
Open this post in threaded view
|

Re: Automatic save and load of a model to a particular file

Martin Rubi
Hello.

> my application's main window is a document shell. How do I make my
> application load or save the model to a predetermined file/location
> without any user interference?

Take a look at the 'binary filling' category in Object. Also, I remember
using the documentation from 'Education Center', it was quite good.

> Also how can I determine the path to be different in a multi user
> environment so that each user would have his/her own data?

You could add these methods and use them, or similar ones:

ShellLibrary>>currentUserApplicationDataPath
"Asnwer the path of the 'Application Data' folder for the current user"
| CSIDL_APPDATA |
CSIDL_APPDATA := 16r001A. "Application data"
^self getFolderPath: CSIDL_APPDATA

ShellLibrary>>currentUserMyDocumentsPath
"Asnwer the path of the 'My Documents' folder for the current user"
| CSIDL_PERSONAL |
CSIDL_PERSONAL := 16r0005. "My Documents"
^self getFolderPath: CSIDL_PERSONAL

ShellLibrary>>getFolderPath: folderId
"Asnwer the path of the folder identified by folderId"
| buffer |
buffer := ByteArray new: File maxPath.
ShellLibrary default
SHGetFolderPath: nil
folder: folderId
token: nil
flags: 0
path: buffer.
^buffer asString

ShellLibrary>>SHGetFolderPath: hwndOwner folder: nFolder token: hToken
flags: dwFlags path: pszPath
" Takes the CSIDL of a folder and returns the pathname.
HRESULT SHGetFolderPath(
HWND hwndOwner,
int nFolder,
HANDLE hToken,
DWORD dwFlags,
LPTSTR pszPath
);"
<stdcall: dword SHGetFolderPathA handle sdword handle sdword lpstr*>
^self invalidCall


Reply | Threaded
Open this post in threaded view
|

Re: Automatic save and load of a model to a particular file

Günther Schmidt
Martin Rubi wrote:

> Hello.
>
>
>>my application's main window is a document shell. How do I make my
>>application load or save the model to a predetermined file/location
>>without any user interference?
>
>
> Take a look at the 'binary filling' category in Object. Also, I remember
> using the documentation from 'Education Center', it was quite good.
>

Martin,

the binary filling category in Object is "low level" the DocumentShell
already has a "high level" implementation, that, so I suppose, makes use
of the "low level" binary filing from Object.

I would just need a way for the application to always use the same file
and do so without prompting the user.

I suppose I could "hack" it myself, but as this is a rather general
problem I'm sure there is already a convention worked out for doing this
sort of thing.

>
>>Also how can I determine the path to be different in a multi user
>>environment so that each user would have his/her own data?
>
>
> You could add these methods and use them, or similar ones:
>
> ShellLibrary>>currentUserApplicationDataPath
> "Asnwer the path of the 'Application Data' folder for the current user"
> | CSIDL_APPDATA |
> CSIDL_APPDATA := 16r001A. "Application data"
> ^self getFolderPath: CSIDL_APPDATA
>
> ShellLibrary>>currentUserMyDocumentsPath
> "Asnwer the path of the 'My Documents' folder for the current user"
> | CSIDL_PERSONAL |
> CSIDL_PERSONAL := 16r0005. "My Documents"
> ^self getFolderPath: CSIDL_PERSONAL
>
> ShellLibrary>>getFolderPath: folderId
> "Asnwer the path of the folder identified by folderId"
> | buffer |
> buffer := ByteArray new: File maxPath.
> ShellLibrary default
> SHGetFolderPath: nil
> folder: folderId
> token: nil
> flags: 0
> path: buffer.
> ^buffer asString
>
> ShellLibrary>>SHGetFolderPath: hwndOwner folder: nFolder token: hToken
> flags: dwFlags path: pszPath
> " Takes the CSIDL of a folder and returns the pathname.
> HRESULT SHGetFolderPath(
> HWND hwndOwner,
> int nFolder,
> HANDLE hToken,
> DWORD dwFlags,
> LPTSTR pszPath
> );"
> <stdcall: dword SHGetFolderPathA handle sdword handle sdword lpstr*>
> ^self invalidCall
>
>

that's certainly some help, but when you think about, Dolphin itself is
doing that already, so a mechanism must already exist, finding "my own
files" creating a "Dolphin Smalltalk" directory and so on.....

I suppose I should investigate Dolphins start up procedure.

I can think of several different ways of doing this

1. would be some code in the Session Runtime Manager
2. Some code in the class side of the applications shell, #defaultModel
maybe
3. on the instance side of the applications shell, #onViewAvailable or so

I'd just like to know if there's a recommended way, some way that would
not give away that I'm such an amateur. ;-)

Günther


Reply | Threaded
Open this post in threaded view
|

Re: Automatic save and load of a model to a particular file

Günther Schmidt
In reply to this post by Martin Rubi
Martin Rubi wrote:

> Hello.
>
>
>>my application's main window is a document shell. How do I make my
>>application load or save the model to a predetermined file/location
>>without any user interference?
>
>
> Take a look at the 'binary filling' category in Object. Also, I remember
> using the documentation from 'Education Center', it was quite good.
>

Martin,

the binary filling category in Object is "low level" the DocumentShell
already has a "high level" implementation, that, so I suppose, makes use
of the "low level" binary filing from Object. It basically just needs to
be given a filename through user interaction once every time it runs.

I would just need a way for the application to always use the same file
and do so without prompting the user.

I suppose I could "hack" it myself, but as this is a rather general
problem I'm sure there is already a convention worked out for doing this
sort of thing.

>
>>Also how can I determine the path to be different in a multi user
>>environment so that each user would have his/her own data?
>
>
> You could add these methods and use them, or similar ones:
>
> ShellLibrary>>currentUserApplicationDataPath
> "Asnwer the path of the 'Application Data' folder for the current user"
> | CSIDL_APPDATA |
> CSIDL_APPDATA := 16r001A. "Application data"
> ^self getFolderPath: CSIDL_APPDATA
>
> ShellLibrary>>currentUserMyDocumentsPath
> "Asnwer the path of the 'My Documents' folder for the current user"
> | CSIDL_PERSONAL |
> CSIDL_PERSONAL := 16r0005. "My Documents"
> ^self getFolderPath: CSIDL_PERSONAL
>
> ShellLibrary>>getFolderPath: folderId
> "Asnwer the path of the folder identified by folderId"
> | buffer |
> buffer := ByteArray new: File maxPath.
> ShellLibrary default
> SHGetFolderPath: nil
> folder: folderId
> token: nil
> flags: 0
> path: buffer.
> ^buffer asString
>
> ShellLibrary>>SHGetFolderPath: hwndOwner folder: nFolder token: hToken
> flags: dwFlags path: pszPath
> " Takes the CSIDL of a folder and returns the pathname.
> HRESULT SHGetFolderPath(
> HWND hwndOwner,
> int nFolder,
> HANDLE hToken,
> DWORD dwFlags,
> LPTSTR pszPath
> );"
> <stdcall: dword SHGetFolderPathA handle sdword handle sdword lpstr*>
> ^self invalidCall
>
>

that's certainly some help, but when you think about, Dolphin itself is
doing that already, somehow, so a mechanism must already exist, finding
"my own files" creating a "Dolphin Smalltalk" directory and so on.....

I suppose I should investigate Dolphins start up procedure.

I can think of several different ways of doing this

1. would be some code in the Session Runtime Manager (which is where I'm
putting my money on).
2. Some code in the class side of the applications shell, #defaultModel
maybe
3. on the instance side of the applications shell, #onViewAvailable or so

I'd just like to know if there's a recommended way, some way that would
not give away that I'm such an amateur. ;-)

Günther