Skip to content

Commit

Permalink
don't add new action, just rename labels
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Dec 20, 2024
1 parent a6f55a1 commit 3488b34
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 36 deletions.
2 changes: 0 additions & 2 deletions jadx-gui/src/main/java/jadx/gui/ui/action/ActionModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ public enum ActionModel {
Shortcut.keyboard(KeyEvent.VK_D)),
CODE_COMMENT(CODE_AREA, "popup.add_comment", "popup.add_comment", null,
Shortcut.keyboard(KeyEvent.VK_SEMICOLON)),
UPDATE_CODE_COMMENT(CODE_AREA, "popup.update_comment", "popup.update_comment", null,
Shortcut.keyboard(KeyEvent.VK_SEMICOLON)),
CODE_COMMENT_SEARCH(CODE_AREA, "popup.search_comment", "popup.search_comment", null,
Shortcut.keyboard(KeyEvent.VK_SEMICOLON, UiUtils.ctrlButton())),
CODE_RENAME(CODE_AREA, "popup.rename", "popup.rename", null,
Expand Down
7 changes: 1 addition & 6 deletions jadx-gui/src/main/java/jadx/gui/ui/action/JadxGuiAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class JadxGuiAction extends ActionHandler implements IShortcutAction {
private static final String COMMAND_PREFIX = "JadxGuiAction.Command.";

private ActionModel actionModel;
private final ActionModel actionModel;
private final String id;
private JComponent shortcutComponent = null;
private KeyStroke addedKeyStroke = null;
Expand Down Expand Up @@ -53,11 +53,6 @@ public JadxGuiAction(String id) {
updateProperties();
}

public void setActionModel(ActionModel actionModel) {
this.actionModel = actionModel;
updateProperties();
}

private void updateProperties() {
if (actionModel == null) {
return;
Expand Down
46 changes: 19 additions & 27 deletions jadx-gui/src/main/java/jadx/gui/ui/codearea/CommentAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,67 +37,59 @@ public class CommentAction extends CodeAreaAction implements DefaultPopupMenuLis
private static final long serialVersionUID = 4753838562204629112L;

private static final Logger LOG = LoggerFactory.getLogger(CommentAction.class);

private final boolean enabled;
private @Nullable ICodeComment actionComment;
private boolean updateComment;

private ICodeComment actionComment;

public CommentAction(CodeArea codeArea) {
super(ActionModel.CODE_COMMENT, codeArea);
this.enabled = codeArea.getNode() instanceof JClass;
}

@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
if (enabled) {
ICodeComment codeComment = getCommentRef(UiUtils.getOffsetAtMousePosition(codeArea));
if (codeComment != null) {
actionComment = getActionComment(codeComment);
setEnabled(true);
} else {
setActionModel(ActionModel.CODE_COMMENT);
setEnabled(false);
}
if (enabled && updateCommentAction(UiUtils.getOffsetAtMousePosition(codeArea))) {
setNameAndDesc(updateComment ? NLS.str("popup.update_comment") : NLS.str("popup.add_comment"));
setEnabled(true);
} else {
setEnabled(false);
}
}

private ICodeComment getActionComment(ICodeComment codeComment) {
ICodeComment exitsComment = searchForExistComment(codeArea, codeComment);
private boolean updateCommentAction(int pos) {
ICodeComment codeComment = getCommentRef(pos);
if (codeComment == null) {
actionComment = null;
return false;
}
ICodeComment exitsComment = searchForExistComment(codeComment);
if (exitsComment != null) {
setActionModel(ActionModel.UPDATE_CODE_COMMENT);
actionComment = exitsComment;
updateComment = true;
return exitsComment;
} else {
setActionModel(ActionModel.CODE_COMMENT);
actionComment = codeComment;
updateComment = false;
return codeComment;
}
return true;
}

@Override
public void actionPerformed(ActionEvent e) {
if (!enabled) {
return;
}

if (JadxGuiAction.isSource(e)) {
showCommentDialog(getActionComment(getCommentRef(codeArea.getCaretPosition())));
} else {
showCommentDialog(this.actionComment);
updateCommentAction(codeArea.getCaretPosition());
}
}

private void showCommentDialog(ICodeComment codeComment) {
if (codeComment == null) {
if (actionComment == null) {
UiUtils.showMessageBox(codeArea.getMainWindow(), NLS.str("msg.cant_add_comment"));
return;
}
CommentDialog.show(codeArea, codeComment, updateComment);
CommentDialog.show(codeArea, actionComment, updateComment);
}

private static ICodeComment searchForExistComment(CodeArea codeArea, ICodeComment blankComment) {
private @Nullable ICodeComment searchForExistComment(ICodeComment blankComment) {
try {
JadxProject project = codeArea.getProject();
JadxCodeData codeData = project.getCodeData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class CommentDialog extends JDialog {
private static final Logger LOG = LoggerFactory.getLogger(CommentDialog.class);

public static void show(CodeArea codeArea, ICodeComment comment, boolean updateComment) {
var dialog = new CommentDialog(codeArea, comment, updateComment);
CommentDialog dialog = new CommentDialog(codeArea, comment, updateComment);
dialog.setVisible(true);
}

Expand Down

0 comments on commit 3488b34

Please sign in to comment.