From fd17b33b062c049ccaa5753660e49788da09704a Mon Sep 17 00:00:00 2001
From: Jacques Grelet <jacques.grelet@ird.fr>
Date: Thu, 13 Mar 2008 09:01:58 +0000
Subject: [PATCH] met fid =-2 pour desactiver la gestion des preferences

---
 tsg_util/tsg_preferences.m | 152 ++++++++++++++++++++++---------------
 1 file changed, 90 insertions(+), 62 deletions(-)

diff --git a/tsg_util/tsg_preferences.m b/tsg_util/tsg_preferences.m
index 7ef192b..4f18283 100644
--- a/tsg_util/tsg_preferences.m
+++ b/tsg_util/tsg_preferences.m
@@ -16,97 +16,125 @@ function tsg_preferences(hTsgGUI, app_name, DEFAULT_PATH_FILE)
 % $Id$
 %
 
+% global variable VERSION, update revision number when tsg structure change
+% -------------------------------------------------------------------------
 global VERSION
 
-% init empty tsg structure
-% ------------------------
-tsg = [];
-
 % Construct config file path
 % --------------------------
 config_file = [prefdir, filesep, app_name, '.mat'];
 
 % Open config file
 % ----------------
-% config = fopen( config_file, 'r' );
-config = -1;
+
+% desactive la gestion des preferences, car la classe tsg.qc.hash (tsg_nc)
+% est transformee en structure lors de l'ecriture, a verifier
+% -----------------------------------------------------------
+% fid = fopen( config_file, 'r' );
+fid = -2;
+
 % test fopen return value
 % -----------------------
-if config == -1
+switch fid 
+  
+  % preference file is missing 
+  % --------------------------
+  case -1
 
-  % call new config private function
-  % ---------------------------------
-  new_config;
+    % create new tsg structure and save it to appdata
+    % -----------------------------------------------
+    new_config;
 
-else
-  
-  % Pointer set to watch during loading preference file 
-  % ---------------------------------------------------
-  set( hTsgGUI, 'Pointer', 'watch' );
+  % disactive the preference mode (for test or bug)
+  % -----------------------------------------------
+  case -2
     
-  % Initialize loading preference file waitbar
-  % ------------------------------------------
-  wb = waitbar(0, 'Loading préference file. Please  wait...');
-  
-  % display waitbar
-  % ---------------
-  waitbar( 1/10, wb, 'loading structure root' );
+    % init root structure to default values
+    % -------------------------------------
+    root.preference.autoload = 'off';
+    root.version             = VERSION;
 
-  try
+    % call default tsg_initialisation
+    % -------------------------------
+    tsg_initialisation(hTsgGUI);
+    
+    % save root in root object for next use
+    % -------------------------------------
+    set(0, 'userdata', root);
+    
+    return;
+
+  % file exist and is open, fid > 2
+  % -------------------------------
+  otherwise
 
-    % if file exist, load in workspace
-    % --------------------------------
-    load( config_file, 'root', 'tsg' );
+    % Pointer set to watch during loading preference file
+    % ---------------------------------------------------
+    set( hTsgGUI, 'Pointer', 'watch' );
 
-  catch
+    % Initialize loading preference file waitbar
+    % ------------------------------------------
+    wb = waitbar(0, 'Loading préference file. Please  wait...');
 
-    % display warning
+    % display waitbar
     % ---------------
-    warning('tsgqc_GUI:tsg_preferences', ...
-      'Can''t load preference file ''%s''', config_file);
+    waitbar( 1/10, wb, 'loading structure root' );
 
-    % quit program
-    % ------------
-    quitProgram(hTsgGUI, DEFAULT_PATH_FILE);
+    try
 
-  end
+      % if file exist, load in workspace
+      % --------------------------------
+      load( config_file, 'root', 'tsg' );
 
-  % display waitbar
-  % ---------------
-  waitbar( 1/2, wb, 'loading structure tsg' );
+    catch
 
-  % Close waitbar
-  % -------------
-  close(wb)
-  
-  % cursor back to normal
-  % ---------------------
-  set(hTsgGUI,'Pointer','arrow');
+      % display warning
+      % ---------------
+      warning('tsgqc_GUI:tsg_preferences', ...
+        'Can''t load preference file ''%s''', config_file);
 
-  try
+      % quit program
+      % ------------
+      quitProgram(hTsgGUI, DEFAULT_PATH_FILE);
 
-    % set current preference autoload in submenu option/preference
-    % ------------------------------------------------------------
-    set(findobj('tag', 'TAG_UIMENU_OPTION_PREFERENCES', ...
-      'checked', root.preference.autoload));
+    end
 
-  catch
-    warning('tsgqc_GUI:tsg_preferences', ...
-      ['Preference file ''%s''\nis malformed\n' ...
-      'delete it.'], config_file);
-    quitProgram(hTsgGUI, DEFAULT_PATH_FILE);
+    % display waitbar
+    % ---------------
+    waitbar( 1/2, wb, 'loading structure tsg' );
 
-  end
+    % Close waitbar
+    % -------------
+    close(wb)
 
-  % If there no field version or wrong version, initialize
-  % -------------------------------------------------------
-  if ~isfield( root, 'version') || ~strcmp(root.version, VERSION)
+    % cursor back to normal
+    % ---------------------
+    set(hTsgGUI,'Pointer','arrow');
 
-    % call new config private function
-    % --------------------------------
-    new_config;
+    try
 
-  end
+      % set current preference autoload in submenu option/preference
+      % ------------------------------------------------------------
+      set(findobj('tag', 'TAG_UIMENU_OPTION_PREFERENCES', ...
+        'checked', root.preference.autoload));
+
+    catch
+      warning('tsgqc_GUI:tsg_preferences', ...
+        ['Preference file ''%s''\nis malformed\n' ...
+        'delete it.'], config_file);
+      quitProgram(hTsgGUI, DEFAULT_PATH_FILE);
+
+    end
+
+    % If there no field version or wrong version, initialize
+    % -------------------------------------------------------
+    if ~isfield( root, 'version') || ~strcmp(root.version, VERSION)
+
+      % call new config private function
+      % --------------------------------
+      new_config;
+
+    end
 
 end
 
-- 
GitLab