source: trunk/web/addons/job_monarch/lib/extjs/air/src/FileProvider.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

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