changeset 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 01e81c77bca1
children 3156ace843f5
files +mpm/MatlabPathManager.m +mpm/PersistentState.m
diffstat 2 files changed, 9 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/+mpm/MatlabPathManager.m	Fri Nov 02 14:43:27 2018 +0100
+++ b/+mpm/MatlabPathManager.m	Wed Dec 05 15:43:13 2018 +0100
@@ -1,7 +1,7 @@
 classdef MatlabPathManager
     properties
         projectFileName = '.subpaths';
-        stateFileName = 'state';
+        prefGroup = 'matlabpathmanager';
     end
 
     methods
@@ -16,13 +16,9 @@
             p = p{1};
         end
 
-        function p = stateFilePath(obj)
-            p = fullfile(obj.installLocation(), obj.stateFileName);
-        end
-
         % Load a given subpath into the state file and the matlab path and do savepath(), atomically
         function loadSubpath(obj, p)
-            state = mpm.PersistentState(obj.stateFilePath);
+            state = mpm.PersistentState(obj.prefGroup);
 
             addpath(p);
             state.subpaths(p) = true;
@@ -33,7 +29,7 @@
 
         % Unload a given subpath from the state file and the matlab path and do savepath(), atomically
         function unloadSubpath(obj, p)
-            state = mpm.PersistentState(obj.stateFilePath);
+            state = mpm.PersistentState(obj.prefGroup);
 
             rmpath(p);
             savepath() % before save state to make sure saved paths are always present in the state
@@ -56,7 +52,7 @@
         end
 
         function s = loadedSubpaths(obj)
-            state = mpm.PersistentState(obj.stateFilePath);
+            state = mpm.PersistentState(obj.prefGroup);
             s_unordered = state.subpaths.keys();
 
             mpath = obj.matlabPath();
--- a/+mpm/PersistentState.m	Fri Nov 02 14:43:27 2018 +0100
+++ b/+mpm/PersistentState.m	Wed Dec 05 15:43:13 2018 +0100
@@ -1,17 +1,16 @@
 classdef PersistentState < handle
     properties
-        filepath
+        prefGroup
         subpaths
     end
 
     methods
-        function obj = PersistentState(filepath)
-            obj.filepath = filepath;
+        function obj = PersistentState(prefGroup)
+            obj.prefGroup = prefGroup;
 
             try
                 % Read state from file
-                s = load(filepath);
-                obj.subpaths = s.subpaths;
+                obj.subpaths = getpref(prefGroup, 'state');
             catch
                 % If reading the file failed, create an empty state
                 obj.subpaths = containers.Map();
@@ -19,10 +18,7 @@
         end
 
         function s = saveState(obj)
-            s = struct();
-            s.subpaths = obj.subpaths;
-
-            save(obj.filepath, '-struct', 's');
+            setpref(obj.prefGroup, 'state', obj.subpaths);
         end
     end
 end