Mercurial > repos > public > matlab_path_manager
changeset 28:0842a1b2ac7e
Factor out function for checking if a subpath is active
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 18 Sep 2018 13:18:02 +0200 |
parents | 05a8b30ee4a7 |
children | 91724783a931 |
files | +mpm/MatlabPathManager.m |
diffstat | 1 files changed, 19 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/+mpm/MatlabPathManager.m Tue Sep 18 13:03:53 2018 +0200 +++ b/+mpm/MatlabPathManager.m Tue Sep 18 13:18:02 2018 +0200 @@ -98,27 +98,12 @@ sp = obj.projectSubpaths(projectFolder); for i = 1:length(sp) - if ~isAtTop(sp{i}, fullfile(projectFolder, sp{i}), mpath) + if ~subpathIsActive(fullfile(projectFolder,sp{i}), mpath) b = false; return; end end b = true; - - function b = isAtTop(subpath, fullsubpath, paths) - for i = 1:length(paths) - if ~endsWith(paths{i}, subpath) - continue - end - - b = strcmp(fullsubpath, paths{i}); - return - end - - b = false; - end - - % TODO: Refactor this into several methods? end % Unload all loaded subpaths. The matlab path should be returned to it's original state @@ -132,6 +117,23 @@ end end +% Test if the path p is active among folders in path with the same final foldername +function b = subpathIsActive(p, paths) + pathparts = split(p, filesep); + foldername = pathparts{end}; + + for i = 1:length(paths) + if ~endsWith(paths{i}, foldername) + % Ignore files with different end foldername + continue + end + + b = strcmp(p, paths{i}); + return + end + + b = false; +end + % TODO: Organize order of methods % TODO: Add flag for being persistent or not? (savepath or not) -% TODO: Make is at top a method? \ No newline at end of file