diff --git a/Ghidra/Features/Base/developer_scripts/FixLangId.java b/Ghidra/Features/Base/developer_scripts/FixLangId.java index d68ead2229..d3f05a0218 100644 --- a/Ghidra/Features/Base/developer_scripts/FixLangId.java +++ b/Ghidra/Features/Base/developer_scripts/FixLangId.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import static ghidra.framework.main.DataTreeDialogType.*; import java.io.IOException; @@ -20,8 +21,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; - -import javax.swing.SwingUtilities; +import java.util.concurrent.atomic.AtomicReference; import db.*; import db.buffers.BufferFile; @@ -30,7 +30,8 @@ import ghidra.app.script.ImproperUseException; import ghidra.framework.data.GhidraFile; import ghidra.framework.data.GhidraFileData; import ghidra.framework.main.DataTreeDialog; -import ghidra.framework.model.*; +import ghidra.framework.model.DefaultDomainFileFilter; +import ghidra.framework.model.DomainFile; import ghidra.framework.store.FolderItem; import ghidra.framework.store.local.LocalDatabaseItem; import ghidra.program.model.lang.LanguageDescription; @@ -38,6 +39,7 @@ import ghidra.program.model.lang.LanguageID; import ghidra.program.model.listing.Program; import ghidra.program.util.DefaultLanguageService; import ghidra.util.Msg; +import ghidra.util.Swing; import ghidra.util.exception.CancelledException; import ghidra.util.task.TaskMonitor; @@ -138,28 +140,30 @@ public class FixLangId extends GhidraScript { } public DomainFile askProgramFile(String title) { - final DomainFile[] domainFile = new DomainFile[] { null }; - // The file filter employed restricts selection to a program file within the active - // project where we have the ability to update file data. - final DataTreeDialog dtd = - new DataTreeDialog(null, title, OPEN, new DefaultDomainFileFilter(Program.class, true)); - dtd.addOkActionListener(e -> { - dtd.close(); - domainFile[0] = dtd.getDomainFile(); + + AtomicReference ref = new AtomicReference<>(); + Swing.runNow(() -> { + + // The file filter employed restricts selection to a program file within the active + // project where we have the ability to update file data. + DefaultDomainFileFilter filter = new DefaultDomainFileFilter(Program.class, true); + DataTreeDialog dtd = new DataTreeDialog(null, title, OPEN, filter); + dtd.addOkActionListener(e -> { + dtd.close(); + ref.set(dtd.getDomainFile()); + }); + + dtd.showComponent(); }); - try { - SwingUtilities.invokeAndWait(() -> dtd.showComponent()); - } - catch (Exception e) { - return null; - } - if (domainFile[0] != null && - !Program.class.isAssignableFrom(domainFile[0].getDomainObjectClass())) { + + DomainFile domainFile = ref.get(); + if (domainFile != null && + !Program.class.isAssignableFrom(domainFile.getDomainObjectClass())) { Msg.showError(getClass(), null, "Script Error", "Selected project file is not a program file!"); return null; } - return domainFile[0]; + return domainFile; } public static Object getInstanceField(String fieldName, Object ownerInstance)