Code covered by the BSD License  

Highlights from
Project Packaging interface

Project Packaging interface

by

 

15 Apr 2013 (Updated )

An interface and command line tool for creating an archive containing project files and dependencies

guiModifyPackage(varargin)
function varargout = guiModifyPackage(varargin)
% GUIMODIFYPACKAGE MATLAB code for guiModifyPackage.fig
%      GUIMODIFYPACKAGE, by itself, creates a new GUIMODIFYPACKAGE or raises the existing
%      singleton*.
%
%      H = GUIMODIFYPACKAGE returns the handle to a new GUIMODIFYPACKAGE or the handle to
%      the existing singleton*.
%
%      GUIMODIFYPACKAGE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUIMODIFYPACKAGE.M with the given input arguments.
%
%      GUIMODIFYPACKAGE('Property','Value',...) creates a new GUIMODIFYPACKAGE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before guiModifyPackage_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to guiModifyPackage_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help guiModifyPackage

% Last Modified by GUIDE v2.5 27-Apr-2013 16:32:52

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @guiModifyPackage_OpeningFcn, ...
                   'gui_OutputFcn',  @guiModifyPackage_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before guiModifyPackage is made visible.
function guiModifyPackage_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to guiModifyPackage (see VARARGIN)

% Choose default command line output for guiModifyPackage
handles.output = hObject;

setappdata(0, 'h_mod', gcf);

if numel(varargin) == 1
    modidx = varargin{1};
    setappdata(gcf, 'modidx', modidx);
else
    return;
end

hmain = getappdata(0, 'h_pack');
packageStruct = getappdata(hmain, 'packageStruct');
packmodify    = packageStruct(modidx);

%set all the fields
set(handles.edit_rootfolder, 'String', packmodify.rootdir);
set(handles.edit_ziploc, 'String', packmodify.archive);
set(handles.edit_projectname, 'String', packmodify.packagename);

%handle the ignore parameters
ignorelist = packmodify.ignorelist;

ignorelist_dirs = ignorelist.dirs;
ignorelist_file = ignorelist.files;

%format the string for viewing
ignorelist_dirs = regexprep(ignorelist_dirs, '\\', '');
ignorelist_file = regexprep(ignorelist_file, '\\', '');
ignorelist_dirs = sprintf('%s, ', ignorelist_dirs{:});
ignorelist_dirs = ignorelist_dirs(1:end-2);
ignorelist_file = sprintf('%s, ', ignorelist_file{:});
ignorelist_file = ignorelist_file(1:end-2);

%set the content
set(handles.edit_ignoredirs, 'String', ignorelist_dirs);
set(handles.edit_ignorefiles, 'String', ignorelist_file);

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes guiModifyPackage wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = guiModifyPackage_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edit_ignoredirs_Callback(hObject, eventdata, handles)
% hObject    handle to edit_ignoredirs (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_ignoredirs as text
%        str2double(get(hObject,'String')) returns contents of edit_ignoredirs as a double


% --- Executes during object creation, after setting all properties.
function edit_ignoredirs_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_ignoredirs (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_ignorefiles_Callback(hObject, eventdata, handles)
% hObject    handle to edit_ignorefiles (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_ignorefiles as text
%        str2double(get(hObject,'String')) returns contents of edit_ignorefiles as a double


% --- Executes during object creation, after setting all properties.
function edit_ignorefiles_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_ignorefiles (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_rootfolder_Callback(hObject, eventdata, handles)
% hObject    handle to edit_rootfolder (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_rootfolder as text
%        str2double(get(hObject,'String')) returns contents of edit_rootfolder as a double


% --- Executes during object creation, after setting all properties.
function edit_rootfolder_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_rootfolder (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_ziploc_Callback(hObject, eventdata, handles)
% hObject    handle to edit_ziploc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_ziploc as text
%        str2double(get(hObject,'String')) returns contents of edit_ziploc as a double


% --- Executes during object creation, after setting all properties.
function edit_ziploc_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_ziploc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_projectname_Callback(hObject, eventdata, handles)
% hObject    handle to edit_projectname (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_projectname as text
%        str2double(get(hObject,'String')) returns contents of edit_projectname as a double


% --- Executes during object creation, after setting all properties.
function edit_projectname_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_projectname (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in button_modifyzip.
function button_modifyzip_Callback(hObject, eventdata, handles)
%get the current location
defloc = get(handles.edit_ziploc, 'String');

%ask the user for a zip file
[zipfile, zippath] = uiputfile({'*.zip' 'Zip archive (*.zip)'}, 'Create an archive for the project', defloc);

if zippath == 0
    return;
else
    set(handles.edit_ziploc, 'String', fullfile(zippath, zipfile));
end

% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%remove the appdata of this gui
rmappdata(0, 'h_mod');

% Hint: delete(hObject) closes the figure
delete(hObject);


% --- Executes on button press in button_apply.
function button_apply_Callback(hObject, eventdata, handles)
%collect the data from the fields
ziploc     = get(handles.edit_ziploc, 'String');
packname   = get(handles.edit_projectname, 'String');
ignoredirs = get(handles.edit_ignoredirs, 'String');
ignorefile = get(handles.edit_ignorefiles, 'String');

%process the ignore patterns
ignoredirs = regexprep(ignoredirs, '\.', '\\.');
ignoredirs = regexprep(ignoredirs, '\s', '');
ignorefile = regexprep(ignorefile, '\.', '\\.');
ignorefile = regexprep(ignorefile, '\s', '');
%create the cell arrays
ignoredirs = regexp(ignoredirs, ',', 'split');
ignorefile = regexp(ignorefile, ',', 'split');
%add it to the structure
ignore.files = ignorefile;
ignore.dirs  = ignoredirs;

%apply the changes to the selected package
hmain = getappdata(0, 'h_pack');
hmod  = getappdata(0, 'h_mod');
packageStruct = getappdata(hmain, 'packageStruct');
modidx        = getappdata(hmod, 'modidx');

packageStruct(modidx).archive     = ziploc;
packageStruct(modidx).packagename = packname;
packageStruct(modidx).ignorelist  = ignore;
packageStruct(modidx).modified    = datestr(now());

setappdata(hmain, 'packageStruct', packageStruct);

%exit the interface now that we're done
figure1_CloseRequestFcn(hmod, eventdata, handles);



% --- Executes on button press in button_delete.
function button_delete_Callback(hObject, eventdata, handles)
%remove the selected package
%apply the changes to the selected package
hmain = getappdata(0, 'h_pack');
hmod  = getappdata(0, 'h_mod');
packageStruct = getappdata(hmain, 'packageStruct');
modidx        = getappdata(hmod, 'modidx');

%remove and update the copy in the main interface
packageStruct(modidx) = [];
setappdata(hmain, 'packageStruct', packageStruct);

%exit the interface now that we're done
figure1_CloseRequestFcn(hmod, eventdata, handles);


% --- Executes on button press in button_list.
function button_list_Callback(hObject, eventdata, handles)
%get the data from the fields and do a look up
projroot = get(handles.edit_rootfolder, 'String');

ignoredirs = get(handles.edit_ignoredirs, 'String');
ignorefile = get(handles.edit_ignorefiles, 'String');

%process the ignore patterns
ignoredirs = regexprep(ignoredirs, '\.', '\\.');
ignoredirs = regexprep(ignoredirs, '\s', '');
ignorefile = regexprep(ignorefile, '\.', '\\.');
ignorefile = regexprep(ignorefile, '\s', '');
%create the cell arrays
ignoredirs = regexp(ignoredirs, ',', 'split');
ignorefile = regexp(ignorefile, ',', 'split');
%add it to the structure
ignore.files = ignorefile;
ignore.dirs  = ignoredirs;

filelist = collectProjectFiles(projroot, ignore);

%show only the filenames and not the whole path
filelist = strrep(filelist, projroot, '');
%filelist = strrep(filelist, filesep, '');

[selection, ok] = listdlg('ListString', filelist,...
                          'PromptString', 'List of files to be included:',...
                          'SelectionMode', 'multiple',...
                          'OKString', 'Ignore ext.',...
                          'CancelString', 'No changes',...
                          'ListSize', [300 400]);
if ok == 0
    return;
end

%add an ignore pattern based on the extension
filenames = filelist(selection);
for f = 1:numel(filenames)
    [~,~,ext] = fileparts(filenames{f});
    
    ignore_file = get(handles.edit_ignorefiles, 'String');
    ignore_file = [ignore_file [', ' ext '$']];
    set(handles.edit_ignorefiles, 'String', ignore_file);
end


% --------------------------------------------------------------------
function menu_depend_Callback(hObject, eventdata, handles)

% --------------------------------------------------------------------
function menu_depend_files_Callback(hObject, eventdata, handles)
%add file dependencies manually
hmain = getappdata(0, 'h_pack');
hmod  = getappdata(0, 'h_mod');
packageStruct = getappdata(hmain, 'packageStruct');
modidx        = getappdata(hmod, 'modidx');

[files, path, ~] = uigetfile({'*.*' 'All files (*.*)'},...
                             'Select files',...
                             'MultiSelect', 'on');
%check the input
if path == 0
    return;
end

if ~iscell(files)
    files = {files};
end

%we're ready to process the files
selfiles = cellfun(@(c) fullfile(path, c), files, 'UniformOutput', false);
if isfield(packageStruct(modidx), 'extdepends')
    packageStruct(modidx).extdepends = [packageStruct(modidx).extdepends, selfiles];
else
    %the field does not exist add the files directly
    packageStruct(modidx).extdepends = selfiles;
end

setappdata(hmain, 'packageStruct', packageStruct);

% --------------------------------------------------------------------
function menu_depend_folders_Callback(hObject, eventdata, handles)
%add folder dependencies manually
hmain = getappdata(0, 'h_pack');
hmod  = getappdata(0, 'h_mod');
packageStruct = getappdata(hmain, 'packageStruct');
modidx        = getappdata(hmod, 'modidx');

path = uigetdir([], 'Select a folder');

if path == 0
    return;
end

%add the entire folder
if isfield(packageStruct(modidx), 'extdepends')
    packageStruct(modidx).extdepends = [packageStruct(modidx).extdepends, {fullfile(path, '*')}];
else
    packageStruct(modidx).extdepends = {fullfile(path, '*')};
end

setappdata(hmain, 'packageStruct', packageStruct);

Contact us