IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
listbox_load_from_workspace.m
Go to the documentation of this file.
1 %>@ingroup misc
2 %> @file
3 %> @brief Populates listbox/popupmenu with variables in workspace that belong to certain class
4 %>
5 %> Note: "leave blank" option should be used with popup menus only.
6 
7 %> @param classname
8 %> @param h_list Handle to listbox or popupmenu
9 %> @param flag_blank=0 Whether to include a "(leave blank)" option
10 %> @param string_empty (optional) String to show instead of the default <b>(leave blank)</b> or <b>(none)</b> entries.
11 %> May also be a cell of strings. In this case, all options in the cell will be added at the beginning.
12 %> @param input (optional) (may be either a string with a class name or an instance of such class)
13 %> Input class to match. This is applicable only if @c classname is "block" or descendant.
14 function listbox_load_from_workspace(classname, h_list, flag_blank, string_empty, input)
15 
16 if ~exist('input', 'var')
17  input = [];
18 end;
19 
20 idxs = get(h_list, 'Value');
21 
22 vars = get_varnames(classname, input);
23 
24 if ~exist('flag_blank', 'var')
25  flag_blank = 0;
26 end;
27 
28 if ~exist('string_empty', 'var')
29  if flag_blank
30  string_empty = 'leave blank';
31  else
32  string_empty = 'none';
33  end;
34 end;
35 
36 
37 if isempty(vars)
38  vars = make_cell(string_empty);
39 elseif flag_blank
40  vars = [make_cell(string_empty), vars];
41 end;
42 
43 if ~isempty(find(idxs > length(vars)))
44  set(h_list, 'Value', 1); %> Prevents from selection falling beyond listbox items (MATLAB does not do it automatically)
45 end;
46 set(h_list, 'String', vars);
47 
48 
49 %-------
50 function c = make_cell(s)
51 if iscell(s)
52  c = cellfun(@(x) iif(x(1) ~= '(', ['(', x, ')'], x), s, 'UniformOutput', 0);
53 else
54  if s(1) ~= '('
55  s = ['(', s, ')'];
56  end;
57  c = {s};
58 end;
Base Block class.
Definition: block.m:2
function get_varnames(in classname, in input)
function make_cell(in s)
function iif(in cond, in x1, in x2)
function listbox_load_from_workspace(in classname, in h_list, in flag_blank, in string_empty, in input)