Ignore:
Timestamp:
Jul 31, 2012, 6:55:39 PM (12 years ago)
Author:
sommeria
Message:

various improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/datatree_browser.m

    r507 r508  
    8080        set(handles.UpdateLink,'String','create_link')
    8181        set(handles.MarkupDir,'Visible','on')
    82 
     82       
    8383    else% opening by uvmat/Open
    8484        InputDir=regexprep(InputName,'.xml$','');
     
    9494                set(handles.MarkupDir,'String','CreateLink')
    9595            end
    96         end
    97                 FillExperiments(handles)
    98         set(handles.OK,'Visible','on')
    99         drawnow
    100        
     96        end     
    10197    end
     98    FillExperiments(handles)
     99    set(handles.OK,'Visible','on')
     100    drawnow
    102101end
    103102
     
    196195MirrorPath='';
    197196if strcmp(get(handles.LinkDir,'Visible'),'on')
    198 MirrorPath=get(handles.LinkDir,'String');
     197    MirrorPath=get(handles.LinkDir,'String');
    199198end
    200199ListExperiments=get(handles.ListExperiments,'String');
    201200if isequal(get(handles.ListExperiments,'Value'),1)
    202     ListExperiments=ListExperiments(2:end); %choose all experiments
     201    ListExperiments=ListExperiments(2:end); %choose all experiments if the first line '*' has been selected
    203202else
    204203    ListExperiments=ListExperiments(get(handles.ListExperiments,'Value'));
     
    206205ListDevices={};
    207206
     207%% loop on the list of selected experiments
    208208for iexp=1:numel(ListExperiments)
    209     hdir=dir(fullfile(SourcePath,ListExperiments{iexp})); %list files and dirs
     209   
     210    % update the directory of the sources and update the links in the case of a link dir
     211    hdir=dir(fullfile(SourcePath,ListExperiments{iexp})); %list files and folders in the source
    210212    for ilist=1:length(hdir)
    211213        Device=hdir(ilist).name;
     
    213215            if ~isempty(MirrorPath)% we list the links to the data directories of files
    214216                link=fullfile(MirrorPath,ListExperiments{iexp},Device);
    215                 if ~exist(link)
     217                if ~exist(link)% create a link if it does not exist
    216218                    source=fullfile(SourcePath,ListExperiments{iexp},Device);
    217219                    system(['ln -s ' source ' ' link])%TODO translate for DOS
     
    228230        end
    229231    end
    230 end
     232   
     233    % check for dir and files in the link dir which do not exist in the source dir
     234    if ~isempty(MirrorPath)
     235        hdir=dir(fullfile(MirrorPath,ListExperiments{iexp})); %list files and folders in the link dir
     236        for ilist=1:length(hdir)
     237            Device=hdir(ilist).name;
     238            if ~isequal(Device(1),'.')
     239                if hdir(ilist).isdir
     240                    Device=[Device '/'];
     241                end
     242                check_list=strcmp(Device,ListDevices) | strcmp(['@' Device],ListDevices);
     243                if isempty(find(check_list))
     244                    ListDevices=[ListDevices;Device];
     245                end
     246            end
     247        end
     248    end
     249end
     250
     251%% display the updated list, keeping track of the previously selected item
     252PreviousList=get(handles.ListDevices,'String');
     253NewValue=[];
     254if ~isempty(PreviousList)&&iscell(PreviousList)
     255    PreviousDevice=PreviousList{get(handles.ListDevices,'Value')};
     256    NewValue=find(strcmp(PreviousDevice,ListDevices));
     257end
     258if isempty(NewValue)
     259    NewValue=1;
     260end
     261set(handles.ListDevices,'Value',NewValue)
    231262set(handles.ListDevices,'String',ListDevices)
    232263
     
    237268%------------------------------------------------------------------------   
    238269list_val=get(handles.ListExperiments,'Value');
    239 if numel(list_val)~=1
    240     msgbox_uvmat('ERROR','select a single experiment')
     270if isequal(list_val,1) || numel(list_val)~=1
     271    msgbox_uvmat('ERROR','select a single experiment in the column ''Experiments''')
    241272    return
    242273end
     
    253284Device=ListDevices{get(handles.ListDevices,'Value')};
    254285Device=regexprep(Device,'^@','');
     286
     287%% open the selected file
     288% case of a directory, open a file inside
    255289if strcmp(Device(end),'/')
    256290    DataDir=fullfile(RootPath,Experiment,Device(1:end-1));
    257291    DirList=dir(DataDir);
    258292    for ilist=1:numel(DirList)
    259         [tild,tild,FileExt]=fileparts(DirList(ilist).name);
    260         FileExt=regexprep(FileExt,'^.','');
    261         if ~isempty(FileExt) && (~isempty(imformats(FileExt))||strcmp(lower(FileExt),'avi')||strcmp(lower(FileExt),'nc'))
    262             uvmat(fullfile(DataDir,DirList(ilist).name))
    263             return
     293        if ~DirList(ilist).isdir
     294            [tild,tild,FileExt]=fileparts(DirList(ilist).name);
     295            FileExt=regexprep(FileExt,'^.','');
     296            if ~isempty(FileExt) && (~isempty(imformats(FileExt))||strcmp(lower(FileExt),'avi')||strcmp(lower(FileExt),'nc'))
     297                uvmat(fullfile(DataDir,DirList(ilist).name))
     298                return
     299            end
    264300        end
    265301    end
    266 end
    267 %
    268 % set(handles.ListRecords,'Value',1)
    269 % set(handles.ListXml,'Value',1)
    270 % ListDevices=get(handles.ListDevices,'String');
    271 % list_val=get(handles.ListDevices,'Value');
    272 % if isequal(list_val,1)
    273 %     ListDevices=ListDevices(2:end);
    274 % else
    275 %     ListDevices=ListDevices(list_val);
    276 % end
    277 % [ListDevices,ListRecords,ListXml]=ListDir(CurrentPath,ListExperiments,ListDevices,{});
    278 % set(handles.ListRecords,'String',[{'*'};ListRecords'])
    279 % set(handles.ListXml,'String',[{'*'};ListXml'])
     302    % open browser if no valid input file has been detected
     303    [FileName, PathName] = uigetfile( ...
     304            { '*.*', 'All Files (*.*)'}, ...
     305            'Pick a mask file *.png',DataDir);
     306    if ~isempty(FileName)
     307        uvmat(fullfile(PathName,FileName));
     308        return
     309    end
     310else %case of a file
     311    uvmat(fullfile(RootPath,Experiment,Device))
     312    return
     313end
     314
    280315
    281316
Note: See TracChangeset for help on using the changeset viewer.