1717import java .util .stream .Stream ;
1818
1919import org .eclipse .core .resources .IFile ;
20+ import org .eclipse .core .resources .IProject ;
2021import org .eclipse .core .resources .IResource ;
22+ import org .eclipse .core .resources .ProjectScope ;
2123import org .eclipse .core .runtime .CoreException ;
2224import org .eclipse .core .runtime .NullProgressMonitor ;
25+ import org .eclipse .core .runtime .preferences .IEclipsePreferences ;
26+ import org .eclipse .core .runtime .preferences .IScopeContext ;
2327import org .eclipse .jface .dialogs .IDialogConstants ;
2428import org .eclipse .jface .dialogs .IMessageProvider ;
2529import org .eclipse .jface .dialogs .MessageDialog ;
5155import org .eclipse .swt .widgets .Label ;
5256import org .eclipse .swt .widgets .Table ;
5357import org .eclipse .swt .widgets .Text ;
58+ import org .osgi .service .prefs .BackingStoreException ;
5459
5560import com .espressif .idf .core .build .NvsTableBean ;
5661import com .espressif .idf .core .logging .Logger ;
6570 */
6671public class NvsCsvEditorPage
6772{
73+ // --- Preference Constants ---
74+ private static final String PLUGIN_ID = "com.espressif.idf.core" ; //$NON-NLS-1$
75+
76+ private static final String PREF_PARTITION_SIZE = "nvsPartitionSize" ; //$NON-NLS-1$
77+ private static final String PREF_ENCRYPT_ENABLED = "nvsEncryptEnabled" ; //$NON-NLS-1$
78+ private static final String PREF_GENERATE_KEY_ENABLED = "nvsGenerateKeyEnabled" ; //$NON-NLS-1$
79+ private static final String PREF_ENCRYPTION_KEY_PATH = "nvsEncryptionKeyPath" ; //$NON-NLS-1$
80+ // --- End of Preference Constants ---
81+
6882 private static final String DEFAULT_PARTITION_SIZE = "0x3000" ; //$NON-NLS-1$
6983 private Composite mainControl ;
7084 private IFile csvFile ;
@@ -125,6 +139,9 @@ public void createControl()
125139 createToolButtonBar (group );
126140 createTableViewer ();
127141
142+ // Load saved preferences
143+ loadPreferences ();
144+
128145 // Initial setup
129146 setMessage (Messages .NvsEditorDialog_DefaultMessage , IMessageProvider .INFORMATION );
130147 encryptAction .notifyListeners (SWT .Selection , new Event ());
@@ -250,6 +267,7 @@ public boolean getSaveAction()
250267 Logger .log (e );
251268 }
252269 dirtyStateListener .accept (false );
270+ savePreferences ();
253271 return true ;
254272 }
255273
@@ -448,7 +466,6 @@ public void widgetSelected(SelectionEvent e)
448466 validateGenerationState ();
449467 }
450468 });
451- generateEncryptionKeyCheckBox .setSelection (true );
452469 }
453470
454471 private void createSizeOfPartitionLable (Composite parent )
@@ -466,7 +483,6 @@ private void createSizeOfPartitionLable(Composite parent)
466483 sizeText = new Text (sizeComposite , SWT .BORDER );
467484 sizeText .setLayoutData (new GridData (SWT .FILL , SWT .CENTER , true , false ));
468485 sizeText .setMessage (Messages .NvsEditorDialog_DefaultSizeMsg );
469- sizeText .setText (DEFAULT_PARTITION_SIZE );
470486 ControlDecoration deco = new ControlDecoration (sizeText , SWT .RIGHT );
471487 Image image = FieldDecorationRegistry .getDefault ().getFieldDecoration (FieldDecorationRegistry .DEC_ERROR )
472488 .getImage ();
@@ -914,4 +930,56 @@ private void getAddRowAction()
914930 tableViewer .refresh ();
915931 markDirty ();
916932 }
933+
934+ // ========================================================================
935+ // Preference Handling Methods
936+ // ========================================================================
937+
938+ /**
939+ * Returns the preference node for the current project.
940+ */
941+ private IEclipsePreferences getProjectPreferences ()
942+ {
943+ IProject project = csvFile .getProject ();
944+ IScopeContext projectScope = new ProjectScope (project );
945+ return projectScope .getNode (PLUGIN_ID );
946+ }
947+
948+ /**
949+ * Loads settings from the project's preferences and applies them to the UI.
950+ */
951+ private void loadPreferences ()
952+ {
953+ IEclipsePreferences prefs = getProjectPreferences ();
954+
955+ // Load and set values, using your class defaults as fallbacks
956+ sizeText .setText (prefs .get (PREF_PARTITION_SIZE , DEFAULT_PARTITION_SIZE ));
957+ encryptAction .setSelection (prefs .getBoolean (PREF_ENCRYPT_ENABLED , false ));
958+ generateEncryptionKeyCheckBox .setSelection (prefs .getBoolean (PREF_GENERATE_KEY_ENABLED , true ));
959+ encryptionKeyText .setText (prefs .get (PREF_ENCRYPTION_KEY_PATH , StringUtil .EMPTY ));
960+ }
961+
962+ /**
963+ * Saves the current UI settings to the project's preferences.
964+ */
965+ private void savePreferences ()
966+ {
967+ IEclipsePreferences prefs = getProjectPreferences ();
968+
969+ // Store the current values
970+ prefs .put (PREF_PARTITION_SIZE , sizeText .getText ());
971+ prefs .putBoolean (PREF_ENCRYPT_ENABLED , encryptAction .getSelection ());
972+ prefs .putBoolean (PREF_GENERATE_KEY_ENABLED , generateEncryptionKeyCheckBox .getSelection ());
973+ prefs .put (PREF_ENCRYPTION_KEY_PATH , encryptionKeyText .getText ());
974+
975+ try
976+ {
977+ // Flush the changes to disk
978+ prefs .flush ();
979+ }
980+ catch (BackingStoreException e )
981+ {
982+ Logger .log (e );
983+ }
984+ }
917985}
0 commit comments