Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jadx
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
jadx
Commits
ac3f3e83
Commit
ac3f3e83
authored
May 31, 2015
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gui: add common popup actions for text fields.
parent
bc8ad4df
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
165 additions
and
0 deletions
+165
-0
SearchBar.java
jadx-gui/src/main/java/jadx/gui/ui/SearchBar.java
+2
-0
SearchDialog.java
jadx-gui/src/main/java/jadx/gui/ui/SearchDialog.java
+1
-0
TextStandardActions.java
...gui/src/main/java/jadx/gui/utils/TextStandardActions.java
+154
-0
Messages_en_US.properties
jadx-gui/src/main/resources/i18n/Messages_en_US.properties
+8
-0
No files found.
jadx-gui/src/main/java/jadx/gui/ui/SearchBar.java
View file @
ac3f3e83
package
jadx
.
gui
.
ui
;
import
jadx.gui.utils.TextStandardActions
;
import
jadx.gui.utils.NLS
;
import
jadx.gui.utils.Utils
;
...
...
@@ -73,6 +74,7 @@ class SearchBar extends JToolBar {
search
(
1
);
}
});
new
TextStandardActions
(
searchField
);
add
(
searchField
);
JButton
prevButton
=
new
JButton
(
NLS
.
str
(
"search.previous"
));
...
...
jadx-gui/src/main/java/jadx/gui/ui/SearchDialog.java
View file @
ac3f3e83
...
...
@@ -236,6 +236,7 @@ public class SearchDialog extends JDialog {
searchField
=
new
JTextField
();
searchField
.
setAlignmentX
(
LEFT_ALIGNMENT
);
searchField
.
getDocument
().
addDocumentListener
(
new
SearchFieldListener
());
new
TextStandardActions
(
searchField
);
JCheckBox
clsChBox
=
makeOptionsCheckBox
(
NLS
.
str
(
"search_dialog.class"
),
SearchOptions
.
CLASS
);
JCheckBox
mthChBox
=
makeOptionsCheckBox
(
NLS
.
str
(
"search_dialog.method"
),
SearchOptions
.
METHOD
);
...
...
jadx-gui/src/main/java/jadx/gui/utils/TextStandardActions.java
0 → 100644
View file @
ac3f3e83
package
jadx
.
gui
.
utils
;
import
javax.swing.AbstractAction
;
import
javax.swing.Action
;
import
javax.swing.JPopupMenu
;
import
javax.swing.KeyStroke
;
import
javax.swing.event.UndoableEditEvent
;
import
javax.swing.event.UndoableEditListener
;
import
javax.swing.text.JTextComponent
;
import
javax.swing.undo.UndoManager
;
import
java.awt.Toolkit
;
import
java.awt.datatransfer.DataFlavor
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.InputEvent
;
import
java.awt.event.KeyEvent
;
import
java.awt.event.MouseAdapter
;
import
java.awt.event.MouseEvent
;
@SuppressWarnings
(
"serial"
)
public
class
TextStandardActions
{
private
final
JTextComponent
textComponent
;
private
final
JPopupMenu
popup
=
new
JPopupMenu
();
private
final
UndoManager
undoManager
;
private
Action
undoAction
;
private
Action
redoAction
;
private
Action
cutAction
;
private
Action
copyAction
;
private
Action
pasteAction
;
private
Action
deleteAction
;
private
Action
selectAllAction
;
public
TextStandardActions
(
JTextComponent
textComponent
)
{
this
.
textComponent
=
textComponent
;
this
.
undoManager
=
new
UndoManager
();
initActions
();
addPopupItems
();
addKeyActions
();
registerListeners
();
}
private
void
initActions
()
{
undoAction
=
new
AbstractAction
(
NLS
.
str
(
"popup.undo"
))
{
@Override
public
void
actionPerformed
(
ActionEvent
ae
)
{
if
(
undoManager
.
canUndo
())
{
undoManager
.
undo
();
}
}
};
redoAction
=
new
AbstractAction
(
NLS
.
str
(
"popup.redo"
))
{
@Override
public
void
actionPerformed
(
ActionEvent
ae
)
{
if
(
undoManager
.
canRedo
())
{
undoManager
.
redo
();
}
}
};
cutAction
=
new
AbstractAction
(
NLS
.
str
(
"popup.cut"
))
{
@Override
public
void
actionPerformed
(
ActionEvent
ae
)
{
textComponent
.
cut
();
}
};
copyAction
=
new
AbstractAction
(
NLS
.
str
(
"popup.copy"
))
{
@Override
public
void
actionPerformed
(
ActionEvent
ae
)
{
textComponent
.
copy
();
}
};
pasteAction
=
new
AbstractAction
(
NLS
.
str
(
"popup.paste"
))
{
@Override
public
void
actionPerformed
(
ActionEvent
ae
)
{
textComponent
.
paste
();
}
};
deleteAction
=
new
AbstractAction
(
NLS
.
str
(
"popup.delete"
))
{
@Override
public
void
actionPerformed
(
ActionEvent
ae
)
{
textComponent
.
replaceSelection
(
""
);
}
};
selectAllAction
=
new
AbstractAction
(
NLS
.
str
(
"popup.select_all"
))
{
@Override
public
void
actionPerformed
(
ActionEvent
ae
)
{
textComponent
.
selectAll
();
}
};
}
void
addPopupItems
()
{
popup
.
add
(
undoAction
);
popup
.
add
(
redoAction
);
popup
.
addSeparator
();
popup
.
add
(
cutAction
);
popup
.
add
(
copyAction
);
popup
.
add
(
pasteAction
);
popup
.
add
(
deleteAction
);
popup
.
addSeparator
();
popup
.
add
(
selectAllAction
);
}
private
void
addKeyActions
()
{
KeyStroke
undoKey
=
KeyStroke
.
getKeyStroke
(
KeyEvent
.
VK_Z
,
InputEvent
.
CTRL_MASK
);
textComponent
.
getInputMap
().
put
(
undoKey
,
undoAction
);
KeyStroke
redoKey
=
KeyStroke
.
getKeyStroke
(
KeyEvent
.
VK_R
,
InputEvent
.
CTRL_MASK
);
textComponent
.
getInputMap
().
put
(
redoKey
,
redoAction
);
}
private
void
registerListeners
()
{
textComponent
.
addMouseListener
(
new
MouseAdapter
()
{
public
void
mouseReleased
(
MouseEvent
e
)
{
if
(
e
.
getModifiers
()
==
InputEvent
.
BUTTON3_MASK
&&
e
.
getSource
()
==
textComponent
)
{
process
(
e
);
}
}
});
textComponent
.
getDocument
().
addUndoableEditListener
(
new
UndoableEditListener
()
{
public
void
undoableEditHappened
(
UndoableEditEvent
event
)
{
undoManager
.
addEdit
(
event
.
getEdit
());
}
});
}
private
void
process
(
MouseEvent
e
)
{
textComponent
.
requestFocus
();
boolean
enabled
=
textComponent
.
isEnabled
();
boolean
editable
=
textComponent
.
isEditable
();
boolean
nonempty
=
!(
textComponent
.
getText
()
==
null
||
textComponent
.
getText
().
equals
(
""
));
boolean
marked
=
textComponent
.
getSelectedText
()
!=
null
;
boolean
pasteAvailable
=
Toolkit
.
getDefaultToolkit
().
getSystemClipboard
()
.
getContents
(
null
).
isDataFlavorSupported
(
DataFlavor
.
stringFlavor
);
undoAction
.
setEnabled
(
enabled
&&
editable
&&
undoManager
.
canUndo
());
redoAction
.
setEnabled
(
enabled
&&
editable
&&
undoManager
.
canRedo
());
cutAction
.
setEnabled
(
enabled
&&
editable
&&
marked
);
copyAction
.
setEnabled
(
enabled
&&
marked
);
pasteAction
.
setEnabled
(
enabled
&&
editable
&&
pasteAvailable
);
deleteAction
.
setEnabled
(
enabled
&&
editable
&&
marked
);
selectAllAction
.
setEnabled
(
enabled
&&
nonempty
);
int
nx
=
e
.
getX
();
if
(
nx
>
500
)
{
nx
=
nx
-
popup
.
getSize
().
width
;
}
popup
.
show
(
e
.
getComponent
(),
nx
,
e
.
getY
()
-
popup
.
getSize
().
height
);
}
}
jadx-gui/src/main/resources/i18n/Messages_en_US.properties
View file @
ac3f3e83
...
...
@@ -68,3 +68,11 @@ preferences.cancel=Cancel
msg.open_file
=
Please open file
msg.saving_sources
=
Saving sources
popup.undo
=
Undo
popup.redo
=
Redo
popup.cut
=
Cut
popup.copy
=
Copy
popup.paste
=
Paste
popup.delete
=
Delete
popup.select_all
=
Select All
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment