comparison +mpm/MatlabPathManager.m @ 23:0b4be0d4e207

Use new class for state management
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 18 Sep 2018 11:52:14 +0200
parents 2e29cca20d8a
children fdad9fe450c5
comparison
equal deleted inserted replaced
22:29da718b8e7f 23:0b4be0d4e207
1 classdef MatlabPathManager 1 classdef MatlabPathManager
2 properties 2 properties
3 projectFileName = '.subpaths'; 3 projectFileName = '.subpaths';
4 stateFileName = ''; 4 stateFileName = 'state';
5 end 5 end
6 6
7 methods 7 methods
8 function obj = MatlabPathManager() 8 function obj = MatlabPathManager()
9 end 9 end
12 p = fullfile(mpm.install_location(), obj.stateFileName); 12 p = fullfile(mpm.install_location(), obj.stateFileName);
13 end 13 end
14 14
15 % Load a given subpath into the state file and the matlab path and do savepath(), atomically 15 % Load a given subpath into the state file and the matlab path and do savepath(), atomically
16 function loadSubpath(obj, p) 16 function loadSubpath(obj, p)
17 state = mpm.load_state(); 17 state = mpm.PersistentState(obj.stateFilePath);
18 18
19 addpath(p); 19 addpath(p);
20 state.added_paths(p) = true; 20 state.added_paths(p) = true;
21 21
22 mpm.save_state(state); 22 state.saveState();
23 23
24 % TODO: Make atomic + add savepath() 24 % TODO: Add savepath()
25 end 25 end
26 26
27 % Unload a given subpath from the state file and the matlab path and do savepath(), atomically 27 % Unload a given subpath from the state file and the matlab path and do savepath(), atomically
28 function unloadSubpath(obj, p) 28 function unloadSubpath(obj, p)
29 state = mpm.load_state(); 29 state = mpm.PersistentState(obj.stateFilePath);
30 30
31 rmpath(p); 31 rmpath(p);
32 state.added_paths.remove(p); 32 state.added_paths.remove(p);
33 33
34 mpm.save_state(state); 34 state.saveState();
35 35
36 % TODO: Make atomic + add savepath() 36 % TODO: Add savepath()
37 end 37 end
38 38
39 % Read project file in a folder and return cell array of all subpaths 39 % Read project file in a folder and return cell array of all subpaths
40 function sp = projectSubpaths(obj, projectFolder) 40 function sp = projectSubpaths(obj, projectFolder)
41 try 41 try
45 end 45 end
46 sp = splitlines(strtrim(fstr)); 46 sp = splitlines(strtrim(fstr));
47 end 47 end
48 48
49 function s = loadedSubpaths(obj) 49 function s = loadedSubpaths(obj)
50 state = mpm.load_state(); 50 state = mpm.PersistentState(obj.stateFilePath);
51 s = state.added_paths.keys(); 51 s = state.added_paths.keys();
52 % TODO: Make it respect order from the matlab path 52 % TODO: Make it respect order from the matlab path
53 end 53 end
54 54
55 function ps = matlabPath(obj) 55 function ps = matlabPath(obj)
124 obj.unload(sp{i}); 124 obj.unload(sp{i});
125 end 125 end
126 end 126 end
127 end 127 end
128 end 128 end
129
130 % TODO: get rid of mpm.load_state and mpm.save_state