Ignore:
Timestamp:
Apr 18, 2013, 9:09:13 PM (8 years ago)
Author:
sommeria
Message:

a few bugs repaired

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/uigetfile_uvmat.m

    r611 r612  
    5050    uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.89 0.9 0.08],'tag','titlebox','Max',2,'BackgroundColor',[1 1 1],...
    5151        'String',InputDir,'FontUnits','points','FontSize',12,'FontWeight','bold');
    52 %     uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.85 0.5 0.03],'BackgroundColor',BackgroundColor,...
    53 %             'String','first modified:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','right');
    54 %     uicontrol('Style','text','Units','normalized', 'Position', [0.05 0.82 0.5 0.03],'BackgroundColor',BackgroundColor,...
    55 %             'String','last modified:','FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','right');
    56     uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.08 0.9 0.66], 'Callback', @(src,event)view_file(option,src,event),'tag','list',...
     52    uicontrol('Style','pushbutton','Tag','backward','Units','normalized','Position',[0.05 0.75 0.1 0.07],...
     53            'String','<--','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@backward);
     54    uicontrol('Style','togglebutton','Units','normalized', 'Position', [0.75 0.75 0.2 0.04],'tag','check_date','Callback',@dates_Callback,...
     55            'String','dates','FontUnits','points','FontSize',12,'FontWeight','bold');
     56    uicontrol('Style','text','Units','normalized', 'Position', [0.4 0.8 0.35 0.03],'BackgroundColor',BackgroundColor,...
     57            'String','sort: ','FontUnits','points','FontSize',12,'FontWeight','bold','HorizontalAlignment','right');
     58    uicontrol('Style','popupmenu','Units','normalized', 'Position', [0.75 0.8 0.2 0.04],'tag','sort_option','Callback',@refresh_GUI,'Visible','off',...
     59            'String',{'name';'date'},'FontUnits','points','FontSize',12,'FontWeight','bold');   
     60    uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.08 0.9 0.66], 'Callback', @(src,event)list_Callback(option,src,event),'tag','list',...
    5761        'FontUnits','points','FontSize',12);
    5862    uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.005 0.2 0.07],'Callback',@(src,event)close(option,src,event),...
     
    6670        uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.81 0.9 0.05]);
    6771    else  %put a title and additional pushbuttons
    68         uicontrol('Style','text','Units','normalized', 'Position', [0.15 0.75 0.8 0.03],'BackgroundColor',BackgroundColor,...
     72        uicontrol('Style','text','Units','normalized', 'Position', [0.15 0.75 0.6 0.03],'BackgroundColor',BackgroundColor,...
    6973            'String',title,'FontUnits','points','FontSize',12,'FontWeight','bold','ForegroundColor','blue','HorizontalAlignment','left');
    70         uicontrol('Style','pushbutton','Tag','backward','Units','normalized','Position',[0.05 0.75 0.1 0.07],...
    71             'String','<--','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@backward);
     74
    7275        uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.4 0.005 0.2 0.07],...
    7376            'String','Home','FontWeight','bold','FontUnits','points','FontSize',12,'Callback',@home_dir);
     
    9598htitlebox=findobj(hfig,'tag','titlebox');
    9699DirName=get(htitlebox,'String');
    97 ListFiles=list_files(DirName);% list the directory content
     100hsort_option=findobj(hfig,'tag','sort_option');
     101sort_option='name';
     102if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2)
     103    sort_option='date';
     104end
     105hcheck_date=findobj(hfig,'tag','check_date');
     106ListFiles=list_files(DirName,get(hcheck_date,'Value'),sort_option);% list the directory content
    98107hlist=findobj(hfig,'tag','list');% find the list object
    99108set(hlist,'String',ListFiles)
     
    107116set(hlist,'Value',Value)
    108117
    109 if strcmp(get(hfig,'Tag'),'status_display')
    110    
     118if strcmp(get(hfig,'Tag'),'status_display')
    111119    hseries=findobj(allchild(0),'tag','series');
    112120    hstatus=findobj(hseries,'tag','status_display');
     
    115123    if isfield(StatusData,'TimeStart')
    116124        TimeStart=StatusData.TimeStart;
    117     end
    118    
    119    
    120 
     125    end
    121126    hlist=findobj(hfig,'tag','list');
    122    % OutputDir=get(hfig,'UserData');
    123    
    124127    testrecent=0;
    125128    datnum=zeros(numel(ListDisplay),1);
     
    172175%------------------------------------------------------------------------   
    173176% --- launched by selecting an item on the file list
    174 function view_file(option,hObject,event)
     177function dates_Callback(hObject,event)
     178%------------------------------------------------------------------------
     179hfig=get(hObject,'parent');
     180hsort_option=findobj(hfig,'tag','sort_option');
     181if get(hObject,'Value')
     182    set(hsort_option,'Visible','on')
     183    set(hsort_option,'Value',2)
     184else
     185    set(hsort_option,'Visible','off')
     186end
     187refresh_GUI(hObject,[])
     188
     189%------------------------------------------------------------------------   
     190% --- launched by selecting an item on the file list
     191function list_Callback(option,hObject,event)
    175192%------------------------------------------------------------------------
    176193list=get(hObject,'String');
     
    180197DirName=get(htitlebox,'String');
    181198SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir
     199ind_dot=regexp(SelectName,'\s*\.\.\.');%remove what is beyond  '...'
     200if ~isempty(ind_dot)
     201    SelectName=SelectName(1:ind_dot-1);
     202end
    182203if strcmp(SelectName,'..')% the upward dir option has been selected
    183204    FullSelectName=fileparts(DirName);
    184205else
    185     %ind_dot=regexp(SelectName,'\.\.\.');
    186     % if ~isempty(ind_dot)
    187     %     SelectName=SelectName(1:ind_dot-1);
    188     % end
    189206    FullSelectName=fullfile(DirName,SelectName);
    190207end
    191208if exist(FullSelectName,'dir')% a directory has been selected
    192 %     ListFiles=dir(FullSelectName);
    193 %     ListDisplay=cell(numel(ListFiles),1);
    194 %     for ilist=2:numel(ListDisplay)% suppress the first line '.'
    195 %         ListDisplay{ilist-1}=ListFiles(ilist).name;
    196 %     end
    197 %     set(hObject,'Value',1)
    198 %     set(hObject,'String',ListDisplay)
    199 %     if strcmp(selectname,'..')
    200 %         FullSelectName=fileparts(fileparts(FullSelectName));
    201 %     end
     209    %     ListFiles=dir(FullSelectName);
     210    %     ListDisplay=cell(numel(ListFiles),1);
     211    %     for ilist=2:numel(ListDisplay)% suppress the first line '.'
     212    %         ListDisplay{ilist-1}=ListFiles(ilist).name;
     213    %     end
     214    %     set(hObject,'Value',1)
     215    %     set(hObject,'String',ListDisplay)
     216    %     if strcmp(selectname,'..')
     217    %         FullSelectName=fileparts(fileparts(FullSelectName));
     218    %     end
    202219    hbackward=findobj(hfig,'Tag','backward');
    203220    set(hbackward,'UserData',DirName); %store the current dir for future backward action
    204     ListFiles=list_files(FullSelectName);
     221    hsort_option=findobj(hfig,'tag','sort_option');
     222    sort_option='name';%default
     223    if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2)
     224        sort_option='date';
     225    end
     226    hcheck_date=findobj(hfig,'tag','check_date');
     227    ListFiles=list_files(FullSelectName,get(hcheck_date,'Value'),sort_option);% list the directory content
    205228    set(hObject,'Value',1)
    206229    set(hObject,'String',ListFiles)
     
    212235    elseif strcmp(FileType,'xml')
    213236        editxml(FullSelectName)
    214             elseif strcmp(FileType,'figure')
     237    elseif strcmp(FileType,'figure')
    215238        open(FullSelectName)
    216239    else
     
    218241        switch option
    219242            case 'browser'
    220         set(htitlebox,'String',FullSelectName);
    221         uiresume(hfig)
     243                set(htitlebox,'String',FullSelectName);
     244                uiresume(hfig)
    222245            case 'status_display'
    223            uvmat(FullSelectName);
     246                uvmat(FullSelectName);
    224247        end
    225248    end
     
    228251%-------------------------------------------------------------------------   
    229252% list the content of a directory
    230 function [ListFiles,ListDates]=list_files(DirName)
     253function ListFiles=list_files(DirName,check_date,sort_option)
    231254%-------------------------------------------------------------------------
    232255ListStruct=dir(DirName);% get structure of the current directory
    233256if numel(ListStruct)<1  % case of empty dir
    234257    ListFiles={};
    235     ListDates={};
    236258    return
    237259end
    238 % if strcmp(ListStruct(1).name,'.')
    239 %     ListStruct(1)=[];%removes the first line ='.'
    240 % end
    241260ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
    242261ListFiles=ListCells(1,:);%list of file names
    243262check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
    244 ListDates=cell2mat(ListCells(5,:));%list of numerical dates
    245263ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
    246 ListDates(check_dir)=0; % we set the dir dates to 0
    247 [tild,index_sort]=sort(check_dir,2,'descend');% put the dir first in the list
    248 ListFiles=ListFiles(index_sort);% list of names sorted by alaphabetical order and dir and file
    249 ListDates=ListDates(index_sort);% sort the corresponding dates
     264if strcmp(sort_option,'date')
     265    ListDates=cell2mat(ListCells(5,:));%list of numerical dates
     266    ListDates(check_dir)=max(ListDates(~check_dir))+1000; % we set the dir in front
     267    [tild,index_sort]=sort(ListDates,2,'descend');% sort files by chronological order, recent first, put the dir first in the list
     268else
     269    [tild,index_sort]=sort(check_dir,2,'descend');% put the dir first in the list
     270end
     271ListFiles=ListFiles(index_sort);% list of names sorted by alaphabetical order and dir and file
    250272cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
    251 check_keep=cellfun('isempty', cell_remove);               
     273check_keep=cellfun('isempty', cell_remove);
    252274ListFiles=[{'+/..'} ListFiles(check_keep)];
    253 ListDates=[0 ListDates(check_keep)];
     275if check_date
     276ListDateString=ListCells(2,:);%list of file dates
     277ListDateString(check_dir)={''};
     278ListDateString=ListDateString(index_sort);% sort the corresponding dates
     279ListDateString=[{''} ListDateString(check_keep)];
     280ListFiles=[ListFiles; ListDateString];
     281ListFiles=cell2tab(ListFiles','...');
     282end
    254283
    255284%------------------------------------------------------------------------   
     
    258287%------------------------------------------------------------------------
    259288DirName=pwd;
    260 ListFiles=list_files(DirName);% list the directory content
    261289hfig=get(hObject,'parent');
     290sort_option='name';%default
     291hsort_option=findobj(hfig,'tag','sort_option');
     292if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2)
     293    sort_option='date';
     294end
     295hcheck_date=findobj(hfig,'tag','check_date');
     296ListFiles=list_files(DirName,get(hcheck_date,'Value'),sort_option);% list the directory content
    262297htitlebox=findobj(hfig,'Tag','titlebox');
    263298set(htitlebox,'String',DirName)% record the new dir name
Note: See TracChangeset for help on using the changeset viewer.