1 |
function [newstring] = EditString(titlestr, labelstr, string) |
---|
2 |
%function [newstring] = EditString(titlestr, labelstr, string) |
---|
3 |
% |
---|
4 |
% Abstract: |
---|
5 |
% Pop-up window with editable text control that allows user |
---|
6 |
% to interactively change a string. |
---|
7 |
% |
---|
8 |
% Usage: |
---|
9 |
% Intended to be used from another program that requires user |
---|
10 |
% input or user requests change. The window stays open and |
---|
11 |
% consequently the function is in a wait state until user |
---|
12 |
% completes requested change. |
---|
13 |
% |
---|
14 |
% >> option = EditString('Edit String', 'Text:', ''); |
---|
15 |
% |
---|
16 |
|
---|
17 |
% History: |
---|
18 |
% o 11 August 1995 create function, window, by Sara Haines |
---|
19 |
% |
---|
20 |
|
---|
21 |
if nargin < 3 |
---|
22 |
disp('EditString: error! Not enough input arguments'); |
---|
23 |
return; |
---|
24 |
end |
---|
25 |
|
---|
26 |
Wpos = [130 300 560 100]; |
---|
27 |
EditStrWin = figure('Position', [Wpos], ... |
---|
28 |
'NumberTitle','off',... |
---|
29 |
'Name', titlestr,... |
---|
30 |
'NextPlot','new',... |
---|
31 |
'Userdata', [1], ... |
---|
32 |
'Tag','EditStrWin'); |
---|
33 |
|
---|
34 |
LabelText = uicontrol('Parent', EditStrWin, ... |
---|
35 |
'CallBack','', ... |
---|
36 |
'Style','text',... |
---|
37 |
'String', labelstr, ... |
---|
38 |
'ForeGround', 'w', ... |
---|
39 |
'BackGround', 'k', ... |
---|
40 |
'Horiz', 'center', ... |
---|
41 |
'Units', 'normal', ... |
---|
42 |
'Position',[0.1 0.7 0.8 0.3], ... |
---|
43 |
'Tag','LabelText'); |
---|
44 |
|
---|
45 |
EditText = uicontrol('Parent', EditStrWin, ... |
---|
46 |
'CallBack',... |
---|
47 |
'set(findobj(0,''Tag'',''EditStrWin''), ''Userdata'', -1)', ... |
---|
48 |
'Style','edit',... |
---|
49 |
'String', [string], ... |
---|
50 |
'ForeGround', 'r', ... |
---|
51 |
'BackGround', 'w', ... |
---|
52 |
'Horiz', 'center', ... |
---|
53 |
'Units', 'normal', ... |
---|
54 |
'Position',[0.1 0.4 0.8 0.3], ... |
---|
55 |
'Tag','EditText'); |
---|
56 |
|
---|
57 |
% set userdata to original string |
---|
58 |
set(EditText, 'Userdata', string); |
---|
59 |
newstring = string; % until user changes it! |
---|
60 |
|
---|
61 |
CancelButton = uicontrol('Parent',EditStrWin,... |
---|
62 |
'Callback','set(findobj(0,''Tag'',''EditStrWin''), ''Userdata'', 0)',... |
---|
63 |
'BackgroundColor',[1;0;0],... |
---|
64 |
'Style','pushbutton',... |
---|
65 |
'String','Cancel',... |
---|
66 |
'Units', 'normal', ... |
---|
67 |
'Position',[0.45 0.1 0.1 0.2],... |
---|
68 |
'Tag','CancelButton'); |
---|
69 |
|
---|
70 |
% purposefully suspend other action until user finishes edit change |
---|
71 |
% or presses the cancel button |
---|
72 |
figure(EditStrWin); |
---|
73 |
while get(EditStrWin, 'Userdata')==1 |
---|
74 |
figure(EditStrWin); |
---|
75 |
pause(1); |
---|
76 |
end |
---|
77 |
|
---|
78 |
newstring = get(EditText, 'String'); |
---|
79 |
close(EditStrWin); |
---|