Home > marsbar > @marmoire > save_item_data.m

save_item_data

PURPOSE ^

save data for item to file

SYNOPSIS ^

function [saved_f, o] = save_item_data(o, item, flags, filename)

DESCRIPTION ^

 save data for item to file
 FORMAT [saved_f o] = save_item_data(o, item, flags, filename)

 o        - object
 item     - name of item
 flags    - flags for save; fields in flag structure can be
                  'force' - force save even if not flagged as needed
                  'warn_empty' - GUI warn if no data to save
                  'ync' - start save with save y/n/cancel dialog
                  'prompt' - prompt for save; 
                  'prompt_suffix - suffix for prompt
                  'prompt_prefix - prefix for prompt
                  'ui' - use UI prompts for save - forced if save_ui
                  'no_no_save' - if 'no' is chosen in the save dialog,
                     contents are flagged as not needing a save in
                     the future (has_changed flag set to 0)  
 filename - filename for save
 
 Returns
 saved_f  - flag set to 1 if save done, 0 not done, -1 if cancel
            Note that, if saving with more than one item, then the value
            is from the last value saved/not saved.  Cancel aborts the
            attempt to save.
 o        - possibly modified object (changed filename, maybe data is
            left as a file, and data field made empty) 
 
 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [saved_f, o] = save_item_data(o, item, flags, filename)
0002 % save data for item to file
0003 % FORMAT [saved_f o] = save_item_data(o, item, flags, filename)
0004 %
0005 % o        - object
0006 % item     - name of item
0007 % flags    - flags for save; fields in flag structure can be
0008 %                  'force' - force save even if not flagged as needed
0009 %                  'warn_empty' - GUI warn if no data to save
0010 %                  'ync' - start save with save y/n/cancel dialog
0011 %                  'prompt' - prompt for save;
0012 %                  'prompt_suffix - suffix for prompt
0013 %                  'prompt_prefix - prefix for prompt
0014 %                  'ui' - use UI prompts for save - forced if save_ui
0015 %                  'no_no_save' - if 'no' is chosen in the save dialog,
0016 %                     contents are flagged as not needing a save in
0017 %                     the future (has_changed flag set to 0)
0018 % filename - filename for save
0019 %
0020 % Returns
0021 % saved_f  - flag set to 1 if save done, 0 not done, -1 if cancel
0022 %            Note that, if saving with more than one item, then the value
0023 %            is from the last value saved/not saved.  Cancel aborts the
0024 %            attempt to save.
0025 % o        - possibly modified object (changed filename, maybe data is
0026 %            left as a file, and data field made empty)
0027 %
0028 % $Id$
0029 
0030 if nargin < 2
0031   error('Need item');
0032 end
0033 if nargin < 3
0034   flags = NaN;
0035 end
0036 if nargin < 4
0037   filename = NaN;
0038 end
0039 
0040 if ~isstruct(flags), flags = []; end
0041 
0042 if strcmp(item, 'all')
0043   item_list = fieldnames(o.items);
0044   if ~pr_is_nix(filename)
0045     warning('Ignoring passed filename for multiple save');
0046     filename = NaN;
0047   end
0048 else 
0049   item_list = {item};
0050 end
0051 
0052 n_items = length(item_list);
0053 saved_f = 0;
0054 for i_no = 1:n_items
0055   item = item_list{i_no};
0056   I = get_item_struct(o, item);
0057   tmp_flags = flags;
0058   
0059   % If there is no valid filename, do UI save
0060   if pr_is_nix(filename) && ...
0061     isempty(I.file_name)
0062     tmp_flags.ui = 1;
0063   end
0064   
0065   % Try save
0066   [saved_f o] = do_save(o, item, tmp_flags, filename);
0067   
0068   % Stop if cancel
0069   if saved_f == -1, return, end
0070 end

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019