FileProvider_wev8.js
1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Ext JS Library 0.20
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/**
* @class Ext.air.FileProvider
* @extends Ext.state.Provider
*
* An Ext state provider implementation for Adobe AIR that stores state in the application
* storage directory.
*
* @constructor
* @param {Object} config
*/
Ext.air.FileProvider = function(config){
Ext.air.FileProvider.superclass.constructor.call(this);
this.defaultState = {
mainWindow : {
width:780,
height:580,
x:10,
y:10
}
};
Ext.apply(this, config);
this.state = this.readState();
var provider = this;
air.NativeApplication.nativeApplication.addEventListener('exiting', function(){
provider.saveState();
});
};
Ext.extend(Ext.air.FileProvider, Ext.state.Provider, {
/**
* @cfg {String} file
* The file name to use for the state file in the application storage directory
*/
file: 'extstate.data',
/**
* @cfg {Object} defaultState
* The default state if no state file can be found
*/
// private
readState : function(){
var stateFile = air.File.applicationStorageDirectory.resolvePath(this.file);
if(!stateFile.exists){
return this.defaultState || {};
}
var stream = new air.FileStream();
stream.open(stateFile, air.FileMode.READ);
var stateData = stream.readObject();
stream.close();
return stateData || this.defaultState || {};
},
// private
saveState : function(name, value){
var stateFile = air.File.applicationStorageDirectory.resolvePath(this.file);
var stream = new air.FileStream();
stream.open(stateFile, air.FileMode.WRITE);
stream.writeObject(this.state);
stream.close();
}
});