mirror of
https://github.com/processing/processing4.git
synced 2026-02-11 17:40:48 +01:00
added show usage menu item
This commit is contained in:
@@ -36,6 +36,7 @@ x Completion for array access, strings[0].
|
||||
|
||||
Finer details
|
||||
|
||||
* findDeclarations should support 3rd party classes too. It's about time. ;)
|
||||
* printStuff(int,float,String) - completion endings have to be appropriate. Right now it's just printStuff(,,). Cursor positioning also needs to be taken care of(done). Argument list as tooltip if possible?
|
||||
*! p5 enhanced stuff in java, how does it fit in with everything else, and edge cases. Possibly add support for them. Offset handling improvements should help here.
|
||||
* Diamond operator isn't supported for now. Bummer.
|
||||
|
||||
@@ -1422,7 +1422,8 @@ public class ASTGenerator {
|
||||
fullName.append(simpleName);
|
||||
if (node.getNode() instanceof MethodDeclaration) {
|
||||
MethodDeclaration md = (MethodDeclaration) node.getNode();
|
||||
type = md.getReturnType2().toString();
|
||||
if (!md.isConstructor())
|
||||
type = md.getReturnType2().toString();
|
||||
fullName.append('(');
|
||||
if (!md.parameters().isEmpty()) {
|
||||
List<ASTNode> params = md.parameters();
|
||||
@@ -1761,11 +1762,7 @@ public class ASTGenerator {
|
||||
}
|
||||
|
||||
protected void done() {
|
||||
DefaultMutableTreeNode defCU = findAllOccurrences();
|
||||
treeRename.setModel(new DefaultTreeModel(defCU));
|
||||
((DefaultTreeModel) treeRename.getModel()).reload();
|
||||
frmOccurenceList.setTitle("Usage of " + editor.ta.getSelectedText());
|
||||
frmOccurenceList.setVisible(true);
|
||||
handleShowUsage();
|
||||
}
|
||||
};
|
||||
worker.execute();
|
||||
@@ -1809,6 +1806,10 @@ public class ASTGenerator {
|
||||
private void refactorIt(){
|
||||
String newName = txtRenameField.getText();
|
||||
DefaultMutableTreeNode defCU = findAllOccurrences();
|
||||
if(defCU == null){
|
||||
editor.statusError("Can't locate definition of " + editor.ta.getSelectedText());
|
||||
return;
|
||||
}
|
||||
treeRename.setModel(new DefaultTreeModel(defCU));
|
||||
((DefaultTreeModel) treeRename.getModel()).reload();
|
||||
frmOccurenceList.setTitle("Usage of " + editor.ta.getSelectedText());
|
||||
@@ -1858,6 +1859,27 @@ public class ASTGenerator {
|
||||
frmRename.setVisible(false);
|
||||
}
|
||||
|
||||
public void handleShowUsage(){
|
||||
if(editor.ta.getSelectedText() == null){
|
||||
editor.statusError("Highlight the class/function/variable name first");
|
||||
return;
|
||||
}
|
||||
|
||||
if(errorCheckerService.hasSyntaxErrors()){
|
||||
editor.statusError("Can't perform action until syntax errors are fixed :(");
|
||||
return;
|
||||
}
|
||||
DefaultMutableTreeNode defCU = findAllOccurrences();
|
||||
if(defCU == null){
|
||||
editor.statusError("Can't locate definition of " + editor.ta.getSelectedText());
|
||||
return;
|
||||
}
|
||||
treeRename.setModel(new DefaultTreeModel(defCU));
|
||||
((DefaultTreeModel) treeRename.getModel()).reload();
|
||||
frmOccurenceList.setTitle("Usage of " + editor.ta.getSelectedText());
|
||||
frmOccurenceList.setVisible(true);
|
||||
}
|
||||
|
||||
private DefaultMutableTreeNode findAllOccurrences(){
|
||||
String selText = editor.ta.getSelectedText();
|
||||
int line = editor.ta.getSelectionStartLine();
|
||||
@@ -1877,6 +1899,9 @@ public class ASTGenerator {
|
||||
selText,
|
||||
editor.ta.getSelectionStart()
|
||||
- offwhitespace, false);
|
||||
if(wnode.getNode() == null){
|
||||
return null;
|
||||
}
|
||||
System.err.println("Gonna find all occurrences of "
|
||||
+ getNodeAsString(wnode.getNode()));
|
||||
|
||||
@@ -1900,7 +1925,11 @@ public class ASTGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
DefaultMutableTreeNode defCU = new DefaultMutableTreeNode(wnode);
|
||||
DefaultMutableTreeNode defCU = new DefaultMutableTreeNode(
|
||||
new ASTNodeWrapper(
|
||||
wnode
|
||||
.getNode(),
|
||||
selText));
|
||||
dfsNameOnly(defCU, wnode.getNode(), selText);
|
||||
System.out.println(wnode);
|
||||
return defCU;
|
||||
@@ -1972,7 +2001,7 @@ public class ASTGenerator {
|
||||
// System.out.println("Visiting: " + getNodeAsString(awnode.getNode()));
|
||||
if(isInstanceOfType(awnode.getNode(), decl, name)){
|
||||
tnode.add(new DefaultMutableTreeNode(new ASTNodeWrapper(awnode
|
||||
.getNode(), name + " | Line " + awnode.getLineNumber())));
|
||||
.getNode(), "Line " + awnode.getLineNumber())));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2055,7 +2084,7 @@ public class ASTGenerator {
|
||||
}
|
||||
|
||||
if(errorCheckerService.hasSyntaxErrors()){
|
||||
editor.statusError("Can't rename until syntax errors are fixed :(");
|
||||
editor.statusError("Can't perform action until syntax errors are fixed :(");
|
||||
return;
|
||||
}
|
||||
if (!frmRename.isVisible()){
|
||||
|
||||
@@ -156,13 +156,23 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
// access to customized (i.e. subclassed) text area
|
||||
ta = (TextArea) textarea;
|
||||
|
||||
// Add show usage option
|
||||
JMenuItem showUsageItem = new JMenuItem("Show Usage..");
|
||||
showUsageItem.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleShowUsage();
|
||||
}
|
||||
});
|
||||
ta.getRightClickPopup().add(showUsageItem);
|
||||
|
||||
// add refactor option
|
||||
JMenuItem renameItem = new JMenuItem("Rename..");
|
||||
renameItem.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleRefactor();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: Add support for word select on right click and rename.
|
||||
// ta.customPainter.addMouseListener(new MouseAdapter() {
|
||||
// public void mouseClicked(MouseEvent evt) {
|
||||
@@ -1144,6 +1154,12 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
errorCheckerService.astGenerator.handleRefactor();
|
||||
}
|
||||
|
||||
private void handleShowUsage() {
|
||||
System.out.println("Caret at:");
|
||||
System.out.println(ta.getLineText(ta.getCaretLine()));
|
||||
errorCheckerService.astGenerator.handleShowUsage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the sketch contains java tabs. If it does, XQMode ain't built
|
||||
* for it, yet. Also, user should really start looking at Eclipse. Disable
|
||||
|
||||
Reference in New Issue
Block a user