comparison +mpm/MatlabPathManager.m @ 38:16d56bf04117

Change place of storage of the state
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 05 Dec 2018 15:43:13 +0100
parents 3a28f6de13c2
children 3156ace843f5
comparison
equal deleted inserted replaced
37:01e81c77bca1 38:16d56bf04117
1 classdef MatlabPathManager 1 classdef MatlabPathManager
2 properties 2 properties
3 projectFileName = '.subpaths'; 3 projectFileName = '.subpaths';
4 stateFileName = 'state'; 4 prefGroup = 'matlabpathmanager';
5 end 5 end
6 6
7 methods 7 methods
8 function obj = MatlabPathManager() 8 function obj = MatlabPathManager()
9 end 9 end
14 14
15 p = join(pathParts(1:end-2), filesep); 15 p = join(pathParts(1:end-2), filesep);
16 p = p{1}; 16 p = p{1};
17 end 17 end
18 18
19 function p = stateFilePath(obj)
20 p = fullfile(obj.installLocation(), obj.stateFileName);
21 end
22
23 % Load a given subpath into the state file and the matlab path and do savepath(), atomically 19 % Load a given subpath into the state file and the matlab path and do savepath(), atomically
24 function loadSubpath(obj, p) 20 function loadSubpath(obj, p)
25 state = mpm.PersistentState(obj.stateFilePath); 21 state = mpm.PersistentState(obj.prefGroup);
26 22
27 addpath(p); 23 addpath(p);
28 state.subpaths(p) = true; 24 state.subpaths(p) = true;
29 state.saveState(); 25 state.saveState();
30 26
31 savepath() % after save state to make sure saved paths are always present in the state 27 savepath() % after save state to make sure saved paths are always present in the state
32 end 28 end
33 29
34 % Unload a given subpath from the state file and the matlab path and do savepath(), atomically 30 % Unload a given subpath from the state file and the matlab path and do savepath(), atomically
35 function unloadSubpath(obj, p) 31 function unloadSubpath(obj, p)
36 state = mpm.PersistentState(obj.stateFilePath); 32 state = mpm.PersistentState(obj.prefGroup);
37 33
38 rmpath(p); 34 rmpath(p);
39 savepath() % before save state to make sure saved paths are always present in the state 35 savepath() % before save state to make sure saved paths are always present in the state
40 state.subpaths.remove(p); 36 state.subpaths.remove(p);
41 state.saveState(); 37 state.saveState();
54 end 50 end
55 sp = splitlines(strtrim(fstr)); 51 sp = splitlines(strtrim(fstr));
56 end 52 end
57 53
58 function s = loadedSubpaths(obj) 54 function s = loadedSubpaths(obj)
59 state = mpm.PersistentState(obj.stateFilePath); 55 state = mpm.PersistentState(obj.prefGroup);
60 s_unordered = state.subpaths.keys(); 56 s_unordered = state.subpaths.keys();
61 57
62 mpath = obj.matlabPath(); 58 mpath = obj.matlabPath();
63 [ok, I] = ismember(s_unordered, mpath); 59 [ok, I] = ismember(s_unordered, mpath);
64 s = mpath(sort(I)); 60 s = mpath(sort(I));