Skip to content
This repository has been archived by the owner on Nov 25, 2018. It is now read-only.

Commit

Permalink
Initial loading fuctionality
Browse files Browse the repository at this point in the history
  • Loading branch information
sco1 committed Feb 11, 2016
1 parent 8d3f917 commit a036de4
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions loadGUIstate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function loadGUIstate(GUIstate, h)
% Write better documentation here <-
%
% Input is a structure containing the saved GUI state output by
% saveGUIstate along with the handles structure of the target GUI.
% This function modifies the GUI handles directly so there is no output
%
% Assumes the GUI state is being loaded into the same GUI that it was saved
% from

savedobjlist = fieldnames(GUIstate);

for ii = 1:length(savedobjlist)
% Verify that our saved handle is part of the passed handles structure,
% otherwise ignore it
if isfield(h, savedobjlist{ii}) && ~isempty(GUIstate.(savedobjlist{ii}))
% set can address properties of multiple objects at the same time,
% which is useful for nested structure arrays of handles (e.g. 3
% sliders stored as h.slider(1), h.slider(2), ...)
nsubhandles = length(h.(savedobjlist{ii}));

% set can also set multiple properties at once, where each row of
% the passed cell array is the value to pass for each object
% handle. This syntax will not be utilized until a robust method
% for generating the cell array is developed. Get something
% functional first, then prettify...
propstoset = fieldnames(GUIstate.(savedobjlist{ii}));
for jj = 1:length(propstoset)
if nsubhandles == 1
ValueArray = {GUIstate.(savedobjlist{ii}).(propstoset{jj})};
elseif nsubhandles > 1
ValueArray = GUIstate.(savedobjlist{ii}).(propstoset{jj});
end
set(h.(savedobjlist{ii}), propstoset(jj), ValueArray);
end
end
end
end

0 comments on commit a036de4

Please sign in to comment.