4141 ' MenuSelectedFcn' , fcn , ' Checked' , ' on' , ' Tag' , ' randomize button' );
4242 obj .ContextMenus(3 ) = uimenu(c , ' Label' , ' Sort by selected column' , ...
4343 ' MenuSelectedFcn' , @(~,~)disp(' feature not yet implemented' ), ...
44- ' Tag' , ' sort by' , ' Enable' , ' off' );
44+ ' Tag' , ' sort by' , ' Enable' , ' off' ); % TODO Implement sort by column
4545 % Create condition table
4646 p = uix .Panel(' Parent' , obj .UIPanel , ' BorderType' , ' none' );
4747 obj.ConditionTable = uitable(' Parent' , p ,...
@@ -118,25 +118,19 @@ function delete(obj)
118118 end
119119
120120 function onSelect(obj , ~, eventData )
121- obj.SelectedCells = eventData .Indices ;
122- if size(eventData .Indices , 1 ) > 0
123- % cells selected, enable buttons
124- set(obj .MakeGlobalButton , ' Enable' , ' on' );
125- set(obj .DeleteConditionButton , ' Enable' , ' on' );
126- set(obj .SetValuesButton , ' Enable' , ' on' );
127- set(obj .ContextMenus(1 ), ' Enable' , ' on' );
128- set(obj .ContextMenus(3 ), ' Enable' , ' on' );
129- else
130- % nothing selected, disable buttons
131- set(obj .MakeGlobalButton , ' Enable' , ' off' );
132- set(obj .DeleteConditionButton , ' Enable' , ' off' );
133- set(obj .SetValuesButton , ' Enable' , ' off' );
134- set(obj .ContextMenus(1 ), ' Enable' , ' off' );
135- set(obj .ContextMenus(3 ), ' Enable' , ' off' );
136- end
121+ % If at least one cell is selected, ensure buttons and menu items are
122+ % enabled, otherwise disable them.
123+ if nargin > 2 ; obj.SelectedCells = eventData .Indices ; end
124+ controls = ...
125+ [obj .MakeGlobalButton , ...
126+ obj .DeleteConditionButton , ...
127+ obj .SetValuesButton , ...
128+ obj .ContextMenus([1 ,3 ])];
129+ set(controls , ' Enable' , iff(size(obj .SelectedCells , 1 ) > 0 , ' on' , ' off' ));
137130 end
138131
139132 function makeGlobal(obj )
133+ % FIXME Don't allow only numRepeats to remain
140134 if isempty(obj .SelectedCells )
141135 disp(' nothing selected' )
142136 return
@@ -146,6 +140,11 @@ function makeGlobal(obj)
146140 rows = num2cell(obj .SelectedCells(iu ,1 )); % get rows of unique selected cols
147141 PE = obj .ParamEditor ;
148142 cellfun(@PE .globaliseParamAtCell , names , rows );
143+ % If only numRepeats remains, globalise it
144+ if isequal(PE .Parameters .TrialSpecificNames , {' numRepeats' })
145+ PE .Parameters .Struct .numRepeats(1 ,1 ) = sum(PE .Parameters .Struct .numRepeats );
146+ PE .globaliseParamAtCell(' numRepeats' , 1 )
147+ end
149148 end
150149
151150 function deleteSelectedConditions(obj )
@@ -158,7 +157,7 @@ function deleteSelectedConditions(obj)
158157 % See also EXP.PARAMETERS, GLOBALISESELECTEDPARAMETERS
159158 rows = unique(obj .SelectedCells(: ,1 ));
160159 names = obj .ConditionTable .ColumnName ;
161- numConditions = size(obj .ConditionTable .Data ,2 );
160+ numConditions = size(obj .ConditionTable .Data ,1 );
162161 % If the number of remaining conditions is 1 or less...
163162 if numConditions - length(rows ) <= 1
164163 remainingIdx = find(all(1 : numConditions ~= rows ,1 ));
@@ -169,10 +168,10 @@ function deleteSelectedConditions(obj)
169168 % ... globalize them
170169 obj .makeGlobal ;
171170 else % Otherwise delete the selected conditions as usual
172- obj .ParamEditor .Parameters .removeConditions(rows ); % FIXME: Should be in ParamEditor
171+ obj .ParamEditor .Parameters .removeConditions(rows );
173172 end
174- % Refresh the table of conditions FIXME: Should be in ParamEditor
175- obj .ParamEditor . fillConditionTable();
173+ % Refresh the table of conditions
174+ obj .fillConditionTable();
176175 end
177176
178177 function setSelectedValues(obj ) % Set multiple fields in conditional table
@@ -244,19 +243,19 @@ function fillConditionTable(obj)
244243 obj.ButtonPanel.Visible = ' on' ;
245244 obj.UIPanel.Visible = ' on' ;
246245 obj.ParamEditor.Parent.Widths = [-1 , - 1 ];
247- data = reshape(struct2cell(trialParams ), numel(titles ), [])' ;
248- data = mapToCell(@(e ) obj .ParamEditor .paramValue2Control(e ), data );
249- set(obj .ConditionTable , ' ColumnName' , titles , ' Data' , data ,...
250- ' ColumnEditable' , true(1 , numel(titles )));
251246 end
247+ data = reshape(struct2cell(trialParams ), numel(titles ), [])' ;
248+ data = mapToCell(@(e ) obj .ParamEditor .paramValue2Control(e ), data );
249+ set(obj .ConditionTable , ' ColumnName' , titles , ' Data' , data ,...
250+ ' ColumnEditable' , true(1 , numel(titles )));
252251 end
253252
254253 function newCondition(obj )
255254 disp(' adding new condition row' );
256255 PE = obj .ParamEditor ;
257256 cellfun(@PE .addEmptyConditionToParam , ...
258257 PE .Parameters .TrialSpecificNames );
259- obj .ParamEditor . fillConditionTable();
258+ obj .fillConditionTable();
260259 end
261260
262261 end
0 commit comments