📄 rri_changepath_ui.m
字号:
function rri_changepath_ui(varargin)
%
% usage: rri_changepath_ui(old_file, title)
%
if nargin == 0 | ischar(varargin{1}) % create figure
old_file = '';
tit_nam = 'Change PLS Path';
if (nargin >= 1), old_file = varargin{1}; end;
if (nargin >= 2), tit_nam = varargin{2}; end;
init(old_file, tit_nam);
return;
end;
% clear the message line,
%
h = findobj(gcf,'Tag','MessageLine');
set(h,'String','');
action = upper(varargin{1}{1});
if strcmp(action,'UPDATE_FILE_LIST'),
update_file_list;
elseif strcmp(action,'SELECT_A_FILE'),
select_a_file;
elseif strcmp(action,'SELECT_ALL_FILE'),
select_all_file;
elseif strcmp(action,'SELECT_NEW_PATH_EDIT'),
select_new_path_edit;
elseif strcmp(action,'BROWSE_BUTTON_PRESSED'),
new_path_edit_hdl = findobj(gcf,'tag','NewPathEdit');
newpath = get(new_path_edit_hdl,'string');
newpath = rri_getdirectory({newpath});
if ~isempty(newpath), set(new_path_edit_hdl,'string',newpath); end;
elseif strcmp(action,'SELECT_BUTTON_PRESSED'),
click_select;
elseif strcmp(action,'DONE_BUTTON_PRESSED'),
select_save;
elseif strcmp(action,'CANCEL_BUTTON_PRESSED'),
close(gcf);
elseif strcmp(action,'DELETE_FIG')
delete_fig;
end;
return;
% --------------------------------------------------------------------
function init(old_file, tit_nam)
save_setting_status = 'on';
rri_changepath_pos = [];
try
load('pls_profile');
catch
end
if ~isempty(rri_changepath_pos) & strcmp(save_setting_status,'on')
pos = rri_changepath_pos;
else
w = 0.7;
h = 0.4;
x = (1-w)/2;
y = (1-h)/2;
pos = [x y w h];
end
h0 = figure('Color',[0.8 0.8 0.8], ...
'Units','normal', ...
'Name',tit_nam, ...
'NumberTitle','off', ...
'MenuBar','none', ...
'Position',pos, ...
'DeleteFcn','rri_changepath_ui({''DELETE_FIG''});', ...
'WindowStyle', 'normal', ...
'Tag','GetFilesFigure', ...
'ToolBar','none');
left_margin = 0.05;
text_height = 0.1;
x = left_margin;
y = 0.85;
w = 0.3 - left_margin;
h = text_height;
pos = [x y w h];
fnt = 0.5;
h1 = uicontrol('Parent',h0, ... % file label
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'fontunit','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','File Name:', ...
'Tag','FileLabel');
y = 0.35;
h = 0.5;
pos = [x y w h];
fnt = 0.1;
h1 = uicontrol('Parent',h0, ... % file listbox
'Style','list', ...
'Units','normal', ...
'fontunit','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'Position',pos, ...
'String','', ...
'Callback','rri_changepath_ui({''UPDATE_FILE_LIST''});', ...
'Tag','FILE_LIST');
y = 0.2;
h = text_height;
pos = [x y w h];
fnt = 0.5;
h1 = uicontrol('Parent',h0, ... % select a file
'Style','radio', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'fontunit','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','Select one file', ...
'Callback','rri_changepath_ui({''SELECT_A_FILE''});', ...
'value',1, ...
'Tag','SELECT_A_FILE');
y = 0.1;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % select all files
'Style','radio', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'fontunit','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','Select more files', ...
'Callback','rri_changepath_ui({''SELECT_ALL_FILE''});', ...
'value',0, ...
'Tag','SELECT_ALL_FILE');
x = left_margin+0.3;
w = 1 - x - left_margin;
y = 0.75;
h = text_height;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % old path label
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'fontunit','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','Old path (default: PLS Data Directory):', ...
'Tag','OldPathLabel');
y = 0.45;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % new path label
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'fontunit','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','New path (Old path will be changed to New path):', ...
'Tag','NewPathLabel');
y = 0.65;
w = w - 0.2;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % old path edit
'Style','edit', ...
'Units','normal', ...
'BackgroundColor',[1 1 1], ...
'fontunit','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','N/A', ...
'enable','on', ...
'Tag','OldPathEdit');
% 'enable','inactive', ...
y = 0.35;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % new path edit
'Style','edit', ...
'Units','normal', ...
'BackgroundColor',[1 1 1], ...
'fontunit','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'ListboxTop',0, ...
'Position',pos, ...
'String','', ...
'enable','inactive', ...
'Tag','NewPathEdit');
% 'buttondown','rri_changepath_ui({''SELECT_NEW_PATH_EDIT''});', ...
x = x + w + 0.05;
w = 0.15;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % BROWSE
'Units','normal', ...
'fontunit','normal', ...
'FontSize',fnt, ...
'ListboxTop',0, ...
'Position',pos, ...
'HorizontalAlignment','center', ...
'String','Browse', ...
'Callback','rri_changepath_ui({''BROWSE_BUTTON_PRESSED''});', ...
'Tag','BROWSEButton');
y = 0.65;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % SELECT
'Units','normal', ...
'fontunit','normal', ...
'FontSize',fnt, ...
'ListboxTop',0, ...
'Position',pos, ...
'HorizontalAlignment','center', ...
'String','Search', ...
'Callback','rri_changepath_ui({''SELECT_BUTTON_PRESSED''});', ...
'Tag','SELECTButton');
w = 0.15;
x = 1-w-left_margin;
y = 0.1;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % CANCEL
'Units','normal', ...
'fontunit','normal', ...
'FontSize',fnt, ...
'ListboxTop',0, ...
'Position',pos, ...
'HorizontalAlignment','center', ...
'String','Close', ...
'Callback','rri_changepath_ui({''CANCEL_BUTTON_PRESSED''});', ...
'Tag','CANCELButton');
x = x-w-0.05;
pos = [x y w h];
h1 = uicontrol('Parent',h0, ... % DONE
'Units','normal', ...
'fontunit','normal', ...
'FontSize',fnt, ...
'ListboxTop',0, ...
'Position',pos, ...
'HorizontalAlignment','center', ...
'String','Change', ...
'Callback','rri_changepath_ui({''DONE_BUTTON_PRESSED''});', ...
'Tag','DONEButton');
x = .01;
y = 0;
w = 1;
pos = [x y w h];
c = uicontrol('Parent',h0, ... % Message Line
'Style','text', ...
'Units','normal', ...
'BackgroundColor',[0.8 0.8 0.8], ...
'ForegroundColor',[0.8 0.0 0.0], ...
'fontunit','normal', ...
'FontSize',fnt, ...
'HorizontalAlignment','left', ...
'Position',pos, ...
'String','', ...
'Tag','MessageLine');
arch = computer;
ispc = strcmp(arch(1:2),'PC');
setappdata(gcf,'ispc',ispc);
setappdata(gcf,'old_file',old_file);
select_a_file;
return; % Init
%----------------------------------------------------------------------------
function num_dir = list_file(dir_name)
file_list_hdl = findobj(gcf,'Tag','FILE_LIST');
select_a_file_hdl = findobj(gcf,'Tag','SELECT_A_FILE');
select_all_file_hdl = findobj(gcf,'Tag','SELECT_ALL_FILE');
old_path_edit_hdl = findobj(gcf,'tag','OldPathEdit');
new_path_edit_hdl = findobj(gcf,'tag','NewPathEdit');
% get dir list
%
dir_struct11 = dir(dir_name);
if isempty(dir_struct11)
msg = 'ERROR: Directory not found!';
msgbox(msg);
return;
end;
% preserve old mouse pointer, and make current pointer as 'Busy'
% it is useful to execute slow process
%
old_pointer = get(gcf,'Pointer');
set(gcf,'Pointer','watch');
dir_list = dir_struct11(find([dir_struct11.isdir] == 1));
[sorted_dir_names,sorted_dir_index] = sortrows({dir_list.name}');
% get file list
%
dir_struct1 = dir([dir_name, filesep, '*session.mat']);
dir_struct2 = dir([dir_name, filesep, '*datamat.mat']);
dir_struct3 = dir([dir_name, filesep, '*result.mat']);
sorted_file_names = [];
% get sorted_file_name
%
if ~isempty(dir_struct1)
file_list1 = dir_struct1(find([dir_struct1.isdir] == 0));
sorted_file_names = [sorted_file_names {file_list1.name}];
end
if ~isempty(dir_struct2)
file_list2 = dir_struct2(find([dir_struct2.isdir] == 0));
sorted_file_names = [sorted_file_names {file_list2.name}];
end
if ~isempty(dir_struct3)
file_list3 = dir_struct3(find([dir_struct3.isdir] == 0));
sorted_file_names = [sorted_file_names {file_list3.name}];
end
[sorted_file_names, sorted_file_index] = sortrows(sorted_file_names');
out_names = [sorted_dir_names; sorted_file_names];
num_dir = length(sorted_dir_names);
for i=1:num_dir,
out_names{i} = sprintf('[%s]',sorted_dir_names{i});
end;
setappdata(gcf,'num_dir',num_dir);
set(file_list_hdl, 'String',out_names, 'user',dir_name);
if isempty(sorted_file_names)
set(file_list_hdl, 'value',1, 'listboxtop',1);
else
set(file_list_hdl, 'value',num_dir+1, 'listboxtop',num_dir+1);
end
set(gcf,'Pointer',old_pointer); % Put 'Arrow' pointer back
return; % list_file
%----------------------------------------------------------------------------
function update_file_list
file_list_hdl = findobj(gcf,'Tag','FILE_LIST');
select_a_file_hdl = findobj(gcf,'Tag','SELECT_A_FILE');
select_all_file_hdl = findobj(gcf,'Tag','SELECT_ALL_FILE');
old_path_edit_hdl = findobj(gcf,'tag','OldPathEdit');
new_path_edit_hdl = findobj(gcf,'tag','NewPathEdit');
dir_name = get(file_list_hdl,'user');
listed_dir = get(gcbo,'String');
selected_dir_idx = get(gcbo,'Value');
if isempty(selected_dir_idx)
return;
end
selected_dir_idx = selected_dir_idx(1);
selected_dir_name1 = listed_dir{selected_dir_idx};
selected_dir_name = selected_dir_name1(2:end-1);
selected_dir = [dir_name filesep selected_dir_name];
% go into subdirectory
%
try
cd (selected_dir);
% not subdirectory
%
catch
if get(file_list_hdl,'max') == 1
old_path = get_old_path(selected_dir_name1);
set(old_path_edit_hdl,'string',old_path);
end
return;
end
if isempty(pwd)
selected_dir = filesep;
else
selected_dir = pwd;
end
if get(file_list_hdl,'max') == 1
select_a_file;
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -