Search in sources :

Example 1 with DefaultPopupMenuListener

use of jadx.gui.utils.DefaultPopupMenuListener in project jadx by skylot.

the class AbstractCodeArea method addWrapLineMenuAction.

private void addWrapLineMenuAction(JadxSettings settings) {
    JPopupMenu popupMenu = getPopupMenu();
    popupMenu.addSeparator();
    JCheckBoxMenuItem wrapItem = new JCheckBoxMenuItem(NLS.str("popup.line_wrap"), getLineWrap());
    wrapItem.setAction(new AbstractAction(NLS.str("popup.line_wrap")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            boolean wrap = !getLineWrap();
            settings.setCodeAreaLineWrap(wrap);
            contentPanel.getTabbedPane().getOpenTabs().values().forEach(v -> {
                if (v instanceof AbstractCodeContentPanel) {
                    AbstractCodeArea codeArea = ((AbstractCodeContentPanel) v).getCodeArea();
                    setCodeAreaLineWrap(codeArea, wrap);
                    if (v instanceof ClassCodeContentPanel) {
                        codeArea = ((ClassCodeContentPanel) v).getSmaliCodeArea();
                        setCodeAreaLineWrap(codeArea, wrap);
                    }
                }
            });
            settings.sync();
        }
    });
    popupMenu.add(wrapItem);
    popupMenu.addPopupMenuListener(new DefaultPopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            wrapItem.setState(getLineWrap());
        }
    });
}
Also used : Rectangle(java.awt.Rectangle) FocusListener(java.awt.event.FocusListener) SearchContext(org.fife.ui.rtextarea.SearchContext) LoggerFactory(org.slf4j.LoggerFactory) Point(java.awt.Point) KeyAdapter(java.awt.event.KeyAdapter) NLS(jadx.gui.utils.NLS) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) JadxSettings(jadx.gui.settings.JadxSettings) SwingUtilities(javax.swing.SwingUtilities) SearchEngine(org.fife.ui.rtextarea.SearchEngine) JumpPosition(jadx.gui.utils.JumpPosition) UiUtils(jadx.gui.utils.UiUtils) MouseAdapter(java.awt.event.MouseAdapter) JNode(jadx.gui.treemodel.JNode) JClass(jadx.gui.treemodel.JClass) Logger(org.slf4j.Logger) DefaultPopupMenuListener(jadx.gui.utils.DefaultPopupMenuListener) JPopupMenu(javax.swing.JPopupMenu) RSyntaxTextArea(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea) StringUtils(jadx.core.utils.StringUtils) Caret(javax.swing.text.Caret) CaretListener(javax.swing.event.CaretListener) BadLocationException(javax.swing.text.BadLocationException) ContentPanel(jadx.gui.ui.panel.ContentPanel) KeyEvent(java.awt.event.KeyEvent) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) Nullable(org.jetbrains.annotations.Nullable) Dimension(java.awt.Dimension) AbstractAction(javax.swing.AbstractAction) PopupMenuEvent(javax.swing.event.PopupMenuEvent) FocusEvent(java.awt.event.FocusEvent) CaretEvent(javax.swing.event.CaretEvent) MainWindow(jadx.gui.ui.MainWindow) DefaultCaret(javax.swing.text.DefaultCaret) JViewport(javax.swing.JViewport) ActionEvent(java.awt.event.ActionEvent) DefaultPopupMenuListener(jadx.gui.utils.DefaultPopupMenuListener) AbstractAction(javax.swing.AbstractAction) PopupMenuEvent(javax.swing.event.PopupMenuEvent) JPopupMenu(javax.swing.JPopupMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 2 with DefaultPopupMenuListener

use of jadx.gui.utils.DefaultPopupMenuListener in project jadx by skylot.

the class CodeArea method addMenuItems.

private void addMenuItems() {
    FindUsageAction findUsage = new FindUsageAction(this);
    GoToDeclarationAction goToDeclaration = new GoToDeclarationAction(this);
    RenameAction rename = new RenameAction(this);
    CommentAction comment = new CommentAction(this);
    FridaAction frida = new FridaAction(this);
    XposedAction xposed = new XposedAction(this);
    JPopupMenu popup = getPopupMenu();
    popup.addSeparator();
    popup.add(findUsage);
    popup.add(goToDeclaration);
    popup.add(comment);
    popup.add(new CommentSearchAction(this));
    popup.add(rename);
    popup.addSeparator();
    popup.add(frida);
    popup.add(xposed);
    popup.addPopupMenuListener(findUsage);
    popup.addPopupMenuListener(goToDeclaration);
    popup.addPopupMenuListener(comment);
    popup.addPopupMenuListener(rename);
    popup.addPopupMenuListener(frida);
    popup.addPopupMenuListener(xposed);
    // move caret on mouse right button click
    popup.addPopupMenuListener(new DefaultPopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            CodeArea codeArea = CodeArea.this;
            if (codeArea.getSelectedText() == null) {
                int offset = UiUtils.getOffsetAtMousePosition(codeArea);
                if (offset >= 0) {
                    codeArea.setCaretPosition(offset);
                }
            }
        }
    });
}
Also used : DefaultPopupMenuListener(jadx.gui.utils.DefaultPopupMenuListener) PopupMenuEvent(javax.swing.event.PopupMenuEvent) JPopupMenu(javax.swing.JPopupMenu)

Aggregations

DefaultPopupMenuListener (jadx.gui.utils.DefaultPopupMenuListener)2 JPopupMenu (javax.swing.JPopupMenu)2 PopupMenuEvent (javax.swing.event.PopupMenuEvent)2 StringUtils (jadx.core.utils.StringUtils)1 JadxSettings (jadx.gui.settings.JadxSettings)1 JClass (jadx.gui.treemodel.JClass)1 JNode (jadx.gui.treemodel.JNode)1 MainWindow (jadx.gui.ui.MainWindow)1 ContentPanel (jadx.gui.ui.panel.ContentPanel)1 JumpPosition (jadx.gui.utils.JumpPosition)1 NLS (jadx.gui.utils.NLS)1 UiUtils (jadx.gui.utils.UiUtils)1 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 ActionEvent (java.awt.event.ActionEvent)1 FocusEvent (java.awt.event.FocusEvent)1 FocusListener (java.awt.event.FocusListener)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1