diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/AddEditDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/AddEditDialog.java index f32686bdfd..ed5cbf9fb7 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/AddEditDialog.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/AddEditDialog.java @@ -190,7 +190,7 @@ public class AddEditDialog extends ReusableDialogComponentProvider { boolean isCurrentlyEntryPoint = false; boolean isCurrentlyPinned = false; - CompoundCmd cmd = new CompoundCmd(symbol == null ? "Add Label" : "Edit Label"); + CompoundCmd cmd = new CompoundCmd<>(symbol == null ? "Add Label" : "Edit Label"); if (symbol == null) { cmd.add(new AddLabelCmd(addr, symbolName, parent, SourceType.USER_DEFINED)); } @@ -205,7 +205,7 @@ public class AddEditDialog extends ReusableDialogComponentProvider { return; } - cmd = new CompoundCmd(symbol == null ? "Add Label" : "Edit Label"); + cmd = new CompoundCmd<>(symbol == null ? "Add Label" : "Edit Label"); if (primaryCheckBox.isEnabled() && primaryCheckBox.isSelected()) { cmd.add(new SetLabelPrimaryCmd(addr, symbolName, parent)); } @@ -245,7 +245,8 @@ public class AddEditDialog extends ReusableDialogComponentProvider { "You have removed the label text--would you like to remove the existing label?"); if (choice == OptionDialog.YES_OPTION) { - Command cmd = new DeleteLabelCmd(addr, symbol.getName(), symbol.getParentNamespace()); + Command cmd = + new DeleteLabelCmd(addr, symbol.getName(), symbol.getParentNamespace()); if (!tool.execute(cmd, program)) { setStatusText(cmd.getStatusMsg()); } @@ -328,18 +329,17 @@ public class AddEditDialog extends ReusableDialogComponentProvider { private void initRecentChoices() { labelNameChoices.removeAllItems(); - Iterator it = recentLabels.iterator(); - while (it.hasNext()) { - labelNameChoices.addItem(it.next()); + for (String recentLabel : recentLabels) { + labelNameChoices.addItem(recentLabel); } if (recentLabels.size() > 0) { labelNameChoices.setSelectedIndex(-1); } } -// This method only gets the namespace associated with the current address -// and it's tree of namespaces. It does not walk the namespace tree of -// the symbol, which can be different than that of the address. + // This method only gets the namespace associated with the current address + // and it's tree of namespaces. It does not walk the namespace tree of + // the symbol, which can be different than that of the address. private void initNamespaces() { namespaceChoices.removeAllItems(); diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RenameLabelAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RenameLabelAction.java index 5b4f4093c8..756173e776 100644 --- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RenameLabelAction.java +++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RenameLabelAction.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,7 +24,7 @@ import ghidra.app.decompiler.ClangToken; import ghidra.app.plugin.core.decompile.DecompilerActionContext; import ghidra.app.util.AddEditDialog; import ghidra.app.util.HelpTopics; -import ghidra.program.model.symbol.Symbol; +import ghidra.program.model.symbol.*; import ghidra.util.HelpLocation; public class RenameLabelAction extends AbstractDecompilerAction { @@ -47,10 +47,15 @@ public class RenameLabelAction extends AbstractDecompilerAction { @Override protected void decompilerActionPerformed(DecompilerActionContext context) { - Symbol symbol = getSymbol(context); - if (symbol != null) { - AddEditDialog dialog = new AddEditDialog("", context.getTool()); - dialog.editLabel(symbol, context.getProgram()); + Symbol s = getSymbol(context); + if (s != null) { + AddEditDialog dialog = new AddEditDialog("Add/Edit Label", context.getTool()); + if (s.getSource() == SourceType.DEFAULT && s.getSymbolType() == SymbolType.LABEL) { + dialog.addLabel(s.getAddress(), context.getProgram()); + } + else { + dialog.editLabel(s, context.getProgram()); + } } }