From 7826dc8379067b8b8558eb03a30569475f606802 Mon Sep 17 00:00:00 2001
From: giuliaghirardini <giulia.ghirardini@skywarder.eu>
Date: Wed, 12 Mar 2025 16:58:15 +0100
Subject: [PATCH] [fixes][utilities] Added import settings button. Now both
 save settings and export functions open a dialog window in which choose the
 folder

---
 functions/utilities/exportFigureGUI.m | 58 +++++++++++++++++++++++----
 1 file changed, 51 insertions(+), 7 deletions(-)

diff --git a/functions/utilities/exportFigureGUI.m b/functions/utilities/exportFigureGUI.m
index f680175..a4fa852 100644
--- a/functions/utilities/exportFigureGUI.m
+++ b/functions/utilities/exportFigureGUI.m
@@ -175,27 +175,61 @@ autoNameButton = uibutton(fig, 'Text', 'Auto name', ...
 % -------------------- BOTTOM PART ---------------------
 % Export Button
 exportButton = uibutton(fig, 'Text', 'Export Figure', ...
-    'Position', [200 100 100 30], ...
+    'Position', [130 100 100 30], ...
     'BackgroundColor', '#cbffbe', ...
     'Tooltip', 'Click to export', ...
     'ButtonPushedFcn', @(src, event) exportFigureCallback());
 
 % Save settings Button
 settingsSaveButton = uibutton(fig, 'Text', 'Save settings', ...
-    'Position', [350 100 100 30], ...
+    'Position', [270 100 100 30], ...
     'BackgroundColor', '#cbffbe', ...
-    'Tooltip', 'Save your configuration', ...
+    'Tooltip', 'Save your configuration in .json file', ...
     'ButtonPushedFcn', @(src, event) saveSettings());
 
+% Import settings Button
+settingsImportButton = uibutton(fig, 'Text', 'Import settings', ...
+    'Position', [410 100 100 30], ...
+    'BackgroundColor', '#9fc9eb', ...
+    'Tooltip', 'Import settings from .json file', ...
+    'ButtonPushedFcn', @(src, event) importSettings());
+
 % Reset to default settings to start over
 allDefaultButton = uibutton(fig, 'Text', 'Reset All', ...
-    'Position', [500 100 100 30], ...
-    'BackgroundColor', '#e17b4b', ...
+    'Position', [550 100 100 30], ...
+    'BackgroundColor', '#d99779', ...
     'Tooltip', 'Reset all settings to default', ...
     'ButtonPushedFcn', @(src, event) resetToDefaultAll());
 
 %% Functions
 % Function to update dropdown menu with new figures
+    function importSettings()
+        [fileSettings, pathSettings] = uigetfile('*.json');
+        fileName = fullfile(pathSettings,fileSettings);
+        fid = fopen(fileName);
+        str = char(fread(fid,inf)');
+        fclose(fid);
+        settings = jsondecode(str);
+        
+        % Apply values
+        addMarkersBox.Value = settings.addMarkers;
+        changeColorsBox.Value = settings.changeColors;
+        changeLineStyleBox.Value = settings.changeLineStyle;
+        gridBox.Value = settings.gridOption;
+        satelliteMapColorsBox.Value = settings.satelliteMapColors;  
+
+        legendLocationDropDown.Value = settings.legendLocation;
+        legendOrientationDropDown.Value = settings.legendOrientation;
+
+        exportPDFBox.Value = settings.exportPDF;
+        exportFIGBox.Value = settings.exportFIG;
+        overwriteFigureBox.Value = settings.overwriteFigure;
+
+        percTextField.Value = settings.percTextwidth;
+        forcedMarkersField.Value = settings.forcedMarkers;
+        WHratioField.Value = settings.WHratio;
+    end
+
     function saveSettings()
         % This function save all the settings in a json file
 
@@ -216,9 +250,13 @@ allDefaultButton = uibutton(fig, 'Text', 'Reset All', ...
         settings.forcedMarkers = forcedMarkersField.Value;
         settings.WHratio = WHratioField.Value;
 
+        filter = '*.json';
+        [fileName, location] = uiputfile(filter);
+
         encoded = jsonencode(settings,PrettyPrint=true);
-        nameFile = ['settings_' strrep(figSelectionDropDown.Value,' ','-') '.json'];
-        fid = fopen(nameFile,'w');
+        name = ['settings_' fileName];
+        fullNameFile = fullfile(location, name);
+        fid = fopen(fullNameFile,'w');
         fprintf(fid,'%s',encoded);
         fclose(fid);
     end
@@ -254,6 +292,8 @@ allDefaultButton = uibutton(fig, 'Text', 'Reset All', ...
     end
 
     function resetToDefaultAll()
+        prefixIPTNameDropDown.Value = '[]';
+        figNameField.Value = '';
         forcedMarkersField.Value = 0;
         WHratioField.Value = 0;
         percTextField.Value = 0.75;
@@ -440,6 +480,9 @@ allDefaultButton = uibutton(fig, 'Text', 'Reset All', ...
             return;
         end
 
+        % Figure path
+        figurePath = uigetdir;
+
         % Try to export figure
         try
             % Call the exportStandardizedFigure function
@@ -456,6 +499,7 @@ allDefaultButton = uibutton(fig, 'Text', 'Reset All', ...
                 'exportPDF', exportPDF, ...
                 'exportFIG', exportFIG, ...
                 'satelliteMapColors', satelliteMapColors, ...
+                'figurePath', figurePath, ...
                 'WHratio', WHratio, ...
                 'overwriteFigure', overwriteFigure);
             uialert(fig, 'Figure exported successfully!', 'Success', 'Icon', 'success');
-- 
GitLab