restoreDefault() vs setValue(getDefaultValue())
I'm looking at an older plugin a client uses. This is using SequenceAnnotationGenerator. Two of the Options defined have the following pattern:
this.foo = this.addStringOption("foo", "foo", value);
this.foo.restoreDefault();
There's a UI issue where when the plugin is launched, the "foo" option will be populated with the last value the user typed in from a previous run, and not the selection that had been made. Manually clicking into the settings button and "Restore Defaults" will set "foo" to the expected "value".
Looking at the code, I replaced the "restoreDefault()" call with:
this.foo.setValue(this.foo.getDefaultValue());
And now the issue goes away. Hooray! But - when I look at the decompiled version of restoreDefault() I think that it's doing the exact same thing? Hard to tell for sure as the code is a bit obfuscated and I do see it setting a boolean value (perhaps it is isRestoreDefaultApplies()? And if so, perhaps that's the issue?):
this.c();
this.setValue(this.b);
this.q = false;
}
-
I'm thinking that the this.q = false is important for figuring this out. Would anyone from the Geneious camp know what the heck q is? I see that setValue() sets it to true and then restoreDefault() sets it back to false. But I can't figure out what setting q is in real life to tweak it and find out.
0 -
Hi Jeff,
That q is hasSetValueBeenCalled.
I think there might be a simpler way to achieve what you want. It sounds like what you want is for the value to never be remembered across runs of the annotation generator. If that's the case you can use BooleanOption.setRestorePreferenceApplies(false).
Hope that helps.
0 -
Hi - yeah, I did eventually work out that it was `hasSetValueBeenCalled`. It appeared to be private so couldn't try out what I really wanted to try, that is if the following would replicate the same behavior:
setValue(x)setHasSetValueBeenCalled(false)
As I said, when I call `setValue()` instead of (or after) `restoreAllDefaults()` it worked as expected. I'll try what you suggest to see if that also works. For this use case the users are selecting a region and want the selected sequence to appear in a text box.
But - my larger question is what changed? The plugin code hadn't been updated in 4 years and the users described this as something that "recently" started to happen. This makes me wonder if something at the Geneious level may have changed?
0 -
My suspicion is that nothing on the code-side changed but instead the behaviour changed once the user typed in a value which in turn got saved to preferences and would be restored each time the plugin is run. Only calling setRestorePreferenceApplies(false) will prevent this from happening.
In other words, I expect your previous approach would work fine if the user never modified the default value.
0 -
I just started working with them so an't say for sure. But that's not how they describe it. The plugin in question, the user selects a region and launches the plugin. The bases get populated into the text field.
What they described was that it worked as expected for ~4 years, and then recently stopped working. Instead it started populating the last manually typed value. This is across multiple users.0 -
One thought I had. As I'd been picturing this as being tied to an update in Geneious, if I can get a better sense of timeline on "recently" from the users, assuming it's possible (haven't looked to see) I could try to download an older version of Geneious Prime and compare the two. It could either confirm or deny what's going on here. I'll
0 -
Also wanted to confirm that the setRestorePreferenceApplies(false) fix both worked and was cleaner than my original workaround. Thanks!
0
Please sign in to leave a comment.
Comments
7 comments