Merge remote-tracking branch

'origin/GP-5579_ghidra1_RememberUserId--SQUASHED' into Ghidra_12.0
(Closes #7454)
This commit is contained in:
Ryan Kurtz
2025-10-14 11:10:36 -04:00
@@ -26,6 +26,7 @@ import docking.DialogComponentProvider;
import docking.widgets.checkbox.GCheckBox;
import docking.widgets.combobox.GComboBox;
import docking.widgets.label.GLabel;
import ghidra.framework.preferences.Preferences;
import ghidra.util.MessageType;
import ghidra.util.layout.PairLayout;
@@ -42,6 +43,7 @@ public class PasswordDialog extends DialogComponentProvider {
private JCheckBox anonymousAccess;
private boolean okPressed = false;
private String defaultUserId;
private String userIdPreferenceKey;
/**
* Construct a new PasswordDialog which may include user ID specification/prompt, if either
@@ -181,8 +183,12 @@ public class PasswordDialog extends DialogComponentProvider {
}
if (allowUserIdEntry) {
String userId = defaultUserId;
if (serverName != null) {
userId = getPreferredUserId(serverType, serverName);
}
workPanel.add(new GLabel(userIdPrompt));
nameField = new JTextField(defaultUserId, 16);
nameField = new JTextField(userId, 16);
nameField.setName("NAME-ENTRY-COMPONENT");
nameField.getAccessibleContext().setAccessibleName("Name");
workPanel.add(nameField);
@@ -260,6 +266,26 @@ public class PasswordDialog extends DialogComponentProvider {
// setInitialLocation( centerPoint.x, centerPoint.y );
}
private String getPreferredUserId(String serverType, String serverName) {
userIdPreferenceKey =
"UserID_" + sanitizeString(serverType) + "_" + sanitizeString(serverName);
return Preferences.getProperty(userIdPreferenceKey, defaultUserId);
}
private void savePreferredUserId(String userId) {
if (userIdPreferenceKey != null) {
Preferences.setProperty(userIdPreferenceKey, userId);
}
}
private String sanitizeString(String str) {
if (str == null) {
return "_";
}
String newStr = str.replaceAll("[^a-zA-Z0-9_-]", "");
return newStr.length() == 0 ? "_" : newStr;
}
/**
* Display error status
* @param text the text
@@ -292,7 +318,12 @@ public class PasswordDialog extends DialogComponentProvider {
* @return the user ID / Name entered in the password field
*/
public String getUserID() {
return nameField != null ? nameField.getText().trim() : defaultUserId;
String userId = defaultUserId;
if (nameField != null) {
userId = nameField.getText().trim();
savePreferredUserId(userId);
}
return userId;
}
/**