1+ /*
2+ * Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved.
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a
5+ * copy of this software and associated documentation files (the "Software"),
6+ * to deal in the Software without restriction, including without limitation
7+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+ * and/or sell copies of the Software, and to permit persons to whom the
9+ * Software is furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice shall be included in
12+ * all copies or substantial portions of the Software.
13+ *
14+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+ * DEALINGS IN THE SOFTWARE.
21+ *
22+ */
23+
24+
25+ /*global define, $, localStorage, brackets, console */
26+
27+ /**
28+ * Generates the fully configured preferences systems used IN TESTING. This configuration does
29+ * not manipulate the user's preferences.
30+ */
31+ define ( function ( require , exports , module ) {
32+ "use strict" ;
33+
34+ var PreferencesBase = require ( "./PreferencesBase" ) ,
35+
36+ // The SETTINGS_FILENAME is used with a preceding "." within user projects
37+ SETTINGS_FILENAME = "brackets.json" ,
38+ STATE_FILENAME = "state.json" ,
39+
40+ // User-level preferences
41+ userPrefFile = null ;
42+
43+ /**
44+ * A deferred object which is used to indicate PreferenceManager readiness during the start-up.
45+ * @private
46+ * @type {$.Deferred }
47+ */
48+ var _prefManagerReadyDeferred = new $ . Deferred ( ) ;
49+
50+ /**
51+ * A boolean property indicating if the user scope configuration file is malformed.
52+ */
53+ var userScopeCorrupt = false ;
54+
55+ function isUserScopeCorrupt ( ) {
56+ return userScopeCorrupt ;
57+ }
58+
59+ var manager = new PreferencesBase . PreferencesSystem ( ) ;
60+ manager . pauseChangeEvents ( ) ;
61+
62+ // Create a Project scope
63+ var projectStorage = new PreferencesBase . FileStorage ( undefined , true ) ,
64+ projectScope = new PreferencesBase . Scope ( projectStorage ) ,
65+ projectPathLayer = new PreferencesBase . PathLayer ( ) ;
66+
67+ projectScope . addLayer ( projectPathLayer ) ;
68+
69+ var userScopeLoading = manager . addScope ( "user" , new PreferencesBase . MemoryStorage ( ) ) ;
70+
71+ // Set up the .brackets.json file handling
72+ manager . addScope ( "project" , projectScope , {
73+ before : "user"
74+ } ) ;
75+
76+ // Session Scope is for storing prefs in memory only but with the highest precedence.
77+ manager . addScope ( "session" , new PreferencesBase . MemoryStorage ( ) ) ;
78+
79+ // Memory storages take no time to initialize
80+ _prefManagerReadyDeferred . resolve ( ) ;
81+
82+ // "State" is stored like preferences but it is not generally intended to be user-editable.
83+ // It's for more internal, implicit things like window size, working set, etc.
84+ var stateManager = new PreferencesBase . PreferencesSystem ( ) ;
85+ var smUserScope = new PreferencesBase . Scope ( new PreferencesBase . MemoryStorage ( ) ) ;
86+ var stateProjectLayer = new PreferencesBase . ProjectLayer ( ) ;
87+ smUserScope . addLayer ( stateProjectLayer ) ;
88+ var smUserScopeLoading = stateManager . addScope ( "user" , smUserScope ) ;
89+
90+ // Semi-Public API. Use this at your own risk. The public API is in PreferencesManager.
91+ exports . manager = manager ;
92+ exports . projectStorage = projectStorage ;
93+ exports . projectPathLayer = projectPathLayer ;
94+ exports . userScopeLoading = userScopeLoading ;
95+ exports . stateManager = stateManager ;
96+ exports . stateProjectLayer = stateProjectLayer ;
97+ exports . smUserScopeLoading = smUserScopeLoading ;
98+ exports . userPrefFile = userPrefFile ;
99+ exports . isUserScopeCorrupt = isUserScopeCorrupt ;
100+ exports . managerReady = _prefManagerReadyDeferred . promise ( ) ;
101+ exports . STATE_FILENAME = STATE_FILENAME ;
102+ exports . SETTINGS_FILENAME = SETTINGS_FILENAME ;
103+ } ) ;
0 commit comments