Skip to content

Commit

Permalink
fix(gui): hide not needed popup action for not editable code
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Oct 21, 2023
1 parent fdffe20 commit 4a92ee0
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions jadx-gui/src/main/java/jadx/gui/ui/codearea/AbstractCodeArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ public AbstractCodeArea(ContentPanel contentPanel, JNode node) {
this.node = Objects.requireNonNull(node);

setMarkOccurrences(false);
setEditable(node.isEditable());
setCodeFoldingEnabled(false);
setFadeCurrentLineHighlight(true);
setCloseCurlyBraces(true);
setAntiAliasingEnabled(true);
applyEditableProperties(node);
loadSettings();

JadxSettings settings = contentPanel.getTabbedPane().getMainWindow().getSettings();
Expand All @@ -107,6 +105,47 @@ public AbstractCodeArea(ContentPanel contentPanel, JNode node) {
}
}

private void applyEditableProperties(JNode node) {
boolean editable = node.isEditable();
setEditable(editable);
setCodeFoldingEnabled(editable);
if (editable) {
setCloseCurlyBraces(true);
setCloseMarkupTags(true);
setAutoIndentEnabled(true);
setClearWhitespaceLinesEnabled(true);
}
}

@Override
protected JPopupMenu createPopupMenu() {
JPopupMenu menu = new JPopupMenu();
if (node.isEditable()) {
menu.add(createPopupMenuItem(getAction(UNDO_ACTION)));
menu.add(createPopupMenuItem(getAction(REDO_ACTION)));
menu.addSeparator();
menu.add(createPopupMenuItem(cutAction));
menu.add(createPopupMenuItem(copyAction));
menu.add(createPopupMenuItem(getAction(PASTE_ACTION)));
menu.add(createPopupMenuItem(getAction(DELETE_ACTION)));
menu.addSeparator();
menu.add(createPopupMenuItem(getAction(SELECT_ALL_ACTION)));
} else {
menu.add(createPopupMenuItem(copyAction));
menu.add(createPopupMenuItem(getAction(SELECT_ALL_ACTION)));
}
appendFoldingMenu(menu);
return menu;
}

@Override
protected void appendFoldingMenu(JPopupMenu popup) {
// append code folding popup menu entry only if enabled
if (isCodeFoldingEnabled()) {
super.appendFoldingMenu(popup);
}
}

private void addWrapLineMenuAction(JadxSettings settings) {
JPopupMenu popupMenu = getPopupMenu();
popupMenu.addSeparator();
Expand Down Expand Up @@ -280,6 +319,7 @@ private static String getWordFromToken(@Nullable Token token) {

public void setLoaded() {
this.loaded = true;
discardAllEdits(); // disable 'undo' action to empty state (before load)
}

/**
Expand Down

0 comments on commit 4a92ee0

Please sign in to comment.