-- Application.applescript -- -- Created by Tomasz Kukielka on Sun Jan 20 2002. -- Copyright (c) 2002 Abracode Inc. All rights reserved. -- Application.applescript property gPrefs : null -- generic object for handling preferences -- implements primitive methods and one property: prefs version -- Obj-C wrapper funcions implemented in PrefsWrapper.m -- are called for getting and setting the prefs script GenericPrefs property mVersion : 0 on GetPrefsVersion() set my mVersion to GetPrefsIntegerForKey("VERSION") return my mVersion end GetPrefsVersion on SavePrefs() if my mVersion is equal to 0 then -- on first save set version to something different from 0 set my mVersion to 1 end if SetPrefsIntegerForKey("VERSION", my mVersion) end SavePrefs on GetPrefsObjectForKey(theKey) return call method "getPrefsObjectForKey:" with parameter theKey end GetPrefsObjectForKey on GetPrefsIntegerForKey(theKey) return call method "getPrefsIntegerForKey:" with parameter theKey end GetPrefsIntegerForKey on GetPrefsBoolForKey(theKey) return call method "getPrefsBoolForKey:" with parameter theKey end GetPrefsBoolForKey on GetPrefsFloatForKey(theKey) return call method "getPrefsFloatForKey:" with parameter theKey end GetPrefsFloatForKey on GetPrefsStringForKey(theKey) return call method "getPrefsStringForKey:" with parameter theKey end GetPrefsStringForKey on SetPrefsObjectForKey(theKey, prefValue) call method "setPrefsObject:forKey:" with parameters {prefValue, theKey} end SetPrefsObjectForKey on SetPrefsIntegerForKey(theKey, prefValue) call method "setPrefsInteger:forKey:" with parameters {prefValue, theKey} end SetPrefsIntegerForKey on SetPrefsBoolForKey(theKey, prefValue) call method "setPrefsBool:forKey:" with parameters {prefValue, theKey} end SetPrefsBoolForKey on SetPrefsFloatForKey(theKey, prefValue) call method "setPrefsFloat:forKey:" with parameters {prefValue, theKey} end SetPrefsFloatForKey end script on CreateMyPrefs() script MyPrefs property parent : GenericPrefs property mCurrPrefsVersion : 1 property mRefresh : 1 property mCopyPath : 1 property mTouchModif : 1 property mTouchCreat : 1 property mToggleLock : 1 property mToggleExtVis : 1 property mSetType : 1 property mFileInfo : 1 on ReadPrefs() GetPrefsVersion() if my mVersion is not equal to my mCurrPrefsVersion then -- set default values set my mVersion to my mCurrPrefsVersion set my mRefresh to 1 set my mCopyPath to 1 set my mTouchModif to 1 set my mTouchCreat to 1 set my mToggleLock to 1 set my mToggleExtVis to 1 set my mSetType to 1 set my mFileInfo to 1 else -- read prefs set my mRefresh to GetPrefsIntegerForKey("ACTIVE_REFRESH") set my mCopyPath to GetPrefsIntegerForKey("ACTIVE_COPY_PATH") set my mTouchModif to GetPrefsIntegerForKey("ACTIVE_TOUCH_MODIF") set my mTouchCreat to GetPrefsIntegerForKey("ACTIVE_TOUCH_CREAT") set my mToggleLock to GetPrefsIntegerForKey("ACTIVE_TOGGLE_LOCK") set my mToggleExtVis to GetPrefsIntegerForKey("ACTIVE_TOGGLE_EXT_VIS") set my mSetType to GetPrefsIntegerForKey("ACTIVE_SET_TYPE") set my mFileInfo to GetPrefsIntegerForKey("ACTIVE_FILE_INFO") end if end ReadPrefs on SavePrefs() if my mVersion is equal to 0 then -- on first save set version to something different from 0 set my mVersion to 1 end if -- call parent method first continue SavePrefs() SetPrefsIntegerForKey("ACTIVE_REFRESH", my mRefresh) SetPrefsIntegerForKey("ACTIVE_COPY_PATH", my mCopyPath) SetPrefsIntegerForKey("ACTIVE_TOUCH_MODIF", my mTouchModif) SetPrefsIntegerForKey("ACTIVE_TOUCH_CREAT", my mTouchCreat) SetPrefsIntegerForKey("ACTIVE_TOGGLE_LOCK", my mToggleLock) SetPrefsIntegerForKey("ACTIVE_TOGGLE_EXT_VIS", my mToggleExtVis) SetPrefsIntegerForKey("ACTIVE_SET_TYPE", my mSetType) SetPrefsIntegerForKey("ACTIVE_FILE_INFO", my mFileInfo) end SavePrefs end script return MyPrefs end CreateMyPrefs on clicked theObject set theName to the name of theObject if theName is "OK" then tell window "Preferences" if gPrefs is not equal to null then set mRefresh of gPrefs to state of control "Refresh" set mCopyPath of gPrefs to state of control "CopyPath" set mTouchModif of gPrefs to state of control "TouchModif" set mTouchCreat of gPrefs to state of control "TouchCreat" set mToggleLock of gPrefs to state of control "ToggleLock" set mToggleExtVis of gPrefs to state of control "ToggleExtVis" set mSetType of gPrefs to state of control "SetType" set mFileInfo of gPrefs to state of control "FileInfo" tell gPrefs to SavePrefs() end if end tell close window "Preferences" quit else if theName is "Cancel" then close window "Preferences" quit end if end clicked on will open theObject if gPrefs is equal to null then set gPrefs to my CreateMyPrefs() end if set theName to the name of theObject if theName is equal to "Preferences" then if gPrefs is not equal to null then tell gPrefs to ReadPrefs() tell window "Preferences" set state of control "Refresh" to (mRefresh of gPrefs) set state of control "CopyPath" to (mCopyPath of gPrefs) set state of control "TouchModif" to (mTouchModif of gPrefs) set state of control "TouchCreat" to (mTouchCreat of gPrefs) set state of control "ToggleLock" to (mToggleLock of gPrefs) set state of control "ToggleExtVis" to (mToggleExtVis of gPrefs) set state of control "SetType" to (mSetType of gPrefs) set state of control "FileInfo" to (mFileInfo of gPrefs) end tell end if end if end will open on choose menu item theObject (*Add your script here.*) end choose menu item on update menu item theObject (*Add your script here.*) end update menu item on will finish launching theObject end will finish launching