IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
rename_object.m
Go to the documentation of this file.
1 %>@ingroup code guigroup
2 %>@file
3 %>@brief Renames object
4 %>
5 %> Actually a mix of GUI and code generation.
6 %
7 %> @param s
8 function rename_object(s)
9 
10 obj = evalin('base', [s, ';']);
11 classname = class(obj);
12 
13 p = inputdlg(sprintf('Enter new name for %s object named ''%s''', classname, s), 'Rename object', 1, {s});
14 if ~isempty(p) && ~isempty(p{1})
15  name_new = p{1};
16  if strcmp(s, name_new)
17  irerrordlg('Please type a different name!', 'Invalid name');
18  else
19  a = evalin('base', ['who(''' name_new ''');']);
20  flag_ok = 1;
21  if ~isempty(a)
22  answer = questdlg(sprintf('Name ''%s'' already exists in the workspace. Overwrite variable?', name_new), 'Confirmation', 'Yes', 'No', 'No');
23  if strcmp(answer, 'No')
24  flag_ok = 0;
25  end;
26  end;
27 
28  if flag_ok
29  code = sprintf('%s = %s;\nclear %s;\n', name_new, s, s);
30  try
31  ircode_eval(code, sprintf('Rename %s object', classname));
32  catch ME
33  irerrordlg(ME.message);
34  rethrow(ME);
35  end;
36  end;
37  end;
38 end;
function ircode_eval(in s, in title)
function irerrordlg(in errorstring, in dlgname)
function rename_object(in s)