forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPreferencesManager.js
More file actions
1 lines (1 loc) · 5.62 KB
/
Copy pathPreferencesManager.js
File metadata and controls
1 lines (1 loc) · 5.62 KB
1
define(function(require,exports,module){var AppInit=require("utils/AppInit"),Commands=require("command/Commands"),CommandManager=require("command/CommandManager"),FileUtils=require("file/FileUtils"),PreferencesBase=require("preferences/PreferencesBase"),FileSystem=require("filesystem/FileSystem"),Strings=require("strings"),PreferencesImpl=require("preferences/PreferencesImpl"),StateManager=require("preferences/StateManager"),_=require("thirdparty/lodash"),currentFilename=null,currentLanguageId=null,projectDirectory=null,projectScopeIsIncluded=!0;function _includeProjectScope(filename){return!(!(filename=filename||currentFilename)||!projectDirectory)&&void 0!==FileUtils.getRelativeFilename(projectDirectory,filename)}function getUserPrefFile(){return PreferencesImpl.userPrefFile}function _toggleProjectScope(){_includeProjectScope()!==projectScopeIsIncluded&&(projectScopeIsIncluded?PreferencesImpl.manager.removeFromScopeOrder("project"):PreferencesImpl.manager.addToScopeOrder("project","user"),projectScopeIsIncluded=!projectScopeIsIncluded)}function _setProjectSettingsFile(settingsFile){projectDirectory=FileUtils.getDirectoryPath(settingsFile),_toggleProjectScope(),PreferencesImpl.projectPathLayer.setPrefFilePath(settingsFile),PreferencesImpl.projectStorage.setPath(settingsFile)}function getExtensionPrefs(prefix){return PreferencesImpl.manager.getPrefixedSystem(prefix)}var CURRENT_PROJECT={},scopeOrderWithProject=null,scopeOrderWithoutProject=null;function _adjustScopeOrderForProject(scopeOrder,includeProject){var hasProject,newScopeOrder;if(scopeOrder.indexOf("project")>-1===includeProject)return scopeOrder;if(includeProject){var before=scopeOrder.indexOf("user");-1===before&&(before=scopeOrder.length-2),(newScopeOrder=_.take(scopeOrder,before)).push("project"),newScopeOrder.push.apply(newScopeOrder,_.drop(scopeOrder,before))}else newScopeOrder=_.without(scopeOrder,"project");return newScopeOrder}function _buildContext(filename,languageId){var ctx={};return ctx.path=filename||currentFilename,ctx.language=languageId||currentLanguageId,ctx.scopeOrder=_includeProjectScope(ctx.path)?scopeOrderWithProject:scopeOrderWithoutProject,ctx}function _getContext(context){return _buildContext((context=context||{}).path,context.language)}function _setCurrentFile(newFilename){var oldFilename=currentFilename;oldFilename!==newFilename&&(currentFilename=newFilename,_toggleProjectScope(),PreferencesImpl.manager.signalContextChanged(_buildContext(oldFilename,currentLanguageId),_buildContext(newFilename,currentLanguageId)))}function _setCurrentLanguage(newLanguageId){var oldLanguageId=currentLanguageId;oldLanguageId!==newLanguageId&&(currentLanguageId=newLanguageId,PreferencesImpl.manager.signalContextChanged(_buildContext(currentFilename,oldLanguageId),_buildContext(currentFilename,newLanguageId)))}function _updateCurrentProjectContext(){var defaultScopeOrder=PreferencesImpl.manager._getScopeOrder({});scopeOrderWithProject=_adjustScopeOrderForProject(defaultScopeOrder,!0),scopeOrderWithoutProject=_adjustScopeOrderForProject(defaultScopeOrder,!1),CURRENT_PROJECT.scopeOrder=scopeOrderWithProject}function _handleOpenPreferences(){var fullPath=getUserPrefFile(),file=FileSystem.getFileForPath(fullPath);file.exists(function(err,doesExist){doesExist?CommandManager.execute(Commands.FILE_OPEN,{fullPath:fullPath}):FileUtils.writeText(file,"",!0).done(function(){CommandManager.execute(Commands.FILE_OPEN,{fullPath:fullPath})})})}function getViewState(id,context){return StateManager.get(id,context)}function setViewState(id,value,context){return StateManager.set(id,value,context)}PreferencesImpl.manager.contextBuilder=_getContext,_updateCurrentProjectContext(),PreferencesImpl.manager.on("scopeOrderChange",_updateCurrentProjectContext),CommandManager.register(Strings.CMD_OPEN_PREFERENCES,Commands.FILE_OPEN_PREFERENCES,_handleOpenPreferences),AppInit.appReady(function(){PreferencesImpl.manager.resumeChangeEvents()}),exports._isUserScopeCorrupt=PreferencesImpl.isUserScopeCorrupt,exports._setCurrentFile=_setCurrentFile,exports._setCurrentLanguage=_setCurrentLanguage,exports._setProjectSettingsFile=_setProjectSettingsFile,exports._reloadUserPrefs=PreferencesImpl.reloadUserPrefs,exports._buildContext=_buildContext,exports.CURRENT_PROJECT=CURRENT_PROJECT,exports.STATE_PROJECT_CONTEXT=StateManager.PROJECT_CONTEXT,exports.STATE_GLOBAL_CONTEXT=StateManager.GLOBAL_CONTEXT,exports.STATE_PROJECT_THEN_GLOBAL_CONTEXT=StateManager.PROJECT_THEN_GLOBAL_CONTEXT,exports.PROJECT_SCOPE={location:{scope:"project"}},exports.ready=PreferencesImpl.managerReady,exports.getUserPrefFile=getUserPrefFile,exports.get=PreferencesImpl.manager.get.bind(PreferencesImpl.manager),exports.set=PreferencesImpl.manager.set.bind(PreferencesImpl.manager),exports.save=PreferencesImpl.manager.save.bind(PreferencesImpl.manager),exports.on=PreferencesImpl.manager.on.bind(PreferencesImpl.manager),exports.off=PreferencesImpl.manager.off.bind(PreferencesImpl.manager),exports.getPreference=PreferencesImpl.manager.getPreference.bind(PreferencesImpl.manager),exports.getAllPreferences=PreferencesImpl.manager.getAllPreferences.bind(PreferencesImpl.manager),exports.getExtensionPrefs=getExtensionPrefs,exports.getViewState=getViewState,exports.setViewState=setViewState,exports.addScope=PreferencesImpl.manager.addScope.bind(PreferencesImpl.manager),exports.stateManager=StateManager,exports.FileStorage=PreferencesBase.FileStorage,exports.SETTINGS_FILENAME=PreferencesImpl.SETTINGS_FILENAME,exports.SETTINGS_FILENAME_BRACKETS=PreferencesImpl.SETTINGS_FILENAME_BRACKETS,exports.definePreference=PreferencesImpl.manager.definePreference.bind(PreferencesImpl.manager),exports.fileChanged=PreferencesImpl.manager.fileChanged.bind(PreferencesImpl.manager)});