Fix clicking on already selected tree item
The editor now scrolls back to the clicked node
This commit is contained in:
@@ -244,7 +244,7 @@ public class MainDesignerController implements Initializable, SettingsOwner {
|
||||
|
||||
|
||||
public void onNameDeclarationSelected(NameDeclaration declaration) {
|
||||
sourceEditorController.clearNodeHighlight();
|
||||
Platform.runLater(() -> onNodeItemSelected(declaration.getNode()));
|
||||
|
||||
List<NameOccurrence> occ = declaration.getNode().getScope().getDeclarations().get(declaration);
|
||||
if (occ != null) {
|
||||
@@ -253,7 +253,6 @@ public class MainDesignerController implements Initializable, SettingsOwner {
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
sourceEditorController.highlightNodePrimary(declaration.getNode());
|
||||
}
|
||||
|
||||
|
||||
|
@@ -28,6 +28,7 @@ import net.sourceforge.pmd.util.fxdesigner.util.beans.SettingsPersistenceUtil.Pe
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.codearea.AvailableSyntaxHighlighters;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.codearea.CustomCodeArea;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.codearea.SyntaxHighlighter;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.controls.ASTTreeCell;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.controls.ASTTreeItem;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.controls.TreeViewWrapper;
|
||||
|
||||
@@ -72,6 +73,8 @@ public class SourceEditorController implements Initializable, SettingsOwner {
|
||||
|
||||
treeViewWrapper = new TreeViewWrapper<>(astTreeView);
|
||||
|
||||
astTreeView.setCellFactory(treeView -> new ASTTreeCell(parent));
|
||||
|
||||
languageVersionProperty().values()
|
||||
.filterMap(Objects::nonNull, LanguageVersion::getLanguage)
|
||||
.distinct()
|
||||
|
@@ -5,10 +5,11 @@
|
||||
package net.sourceforge.pmd.util.fxdesigner.util.controls;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.util.fxdesigner.MainDesignerController;
|
||||
|
||||
import javafx.scene.control.TreeCell;
|
||||
import javafx.scene.control.TreeView;
|
||||
import javafx.util.Callback;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
|
||||
|
||||
/**
|
||||
@@ -19,6 +20,14 @@ import javafx.util.Callback;
|
||||
*/
|
||||
public class ASTTreeCell extends TreeCell<Node> {
|
||||
|
||||
private final MainDesignerController controller;
|
||||
|
||||
|
||||
public ASTTreeCell(MainDesignerController controller) {
|
||||
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateItem(Node item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
@@ -26,13 +35,19 @@ public class ASTTreeCell extends TreeCell<Node> {
|
||||
if (empty || item == null) {
|
||||
setText(null);
|
||||
setGraphic(null);
|
||||
return;
|
||||
} else {
|
||||
setText(item.toString() + (item.getImage() == null ? "" : " \"" + item.getImage() + "\""));
|
||||
}
|
||||
}
|
||||
|
||||
// Reclicking the selected node in the ast will scroll back to the node in the editor
|
||||
this.addEventHandler(MouseEvent.MOUSE_CLICKED, t -> {
|
||||
if (t.getButton() == MouseButton.PRIMARY
|
||||
&& getTreeView().getSelectionModel().getSelectedItem().getValue() == item) {
|
||||
controller.onNodeItemSelected(item);
|
||||
t.consume();
|
||||
}
|
||||
});
|
||||
|
||||
public static Callback<TreeView<Node>, ASTTreeCell> callback() {
|
||||
return p -> new ASTTreeCell();
|
||||
}
|
||||
}
|
||||
|
@@ -13,8 +13,6 @@ import net.sourceforge.pmd.lang.symboltable.Scope;
|
||||
import net.sourceforge.pmd.util.fxdesigner.MainDesignerController;
|
||||
|
||||
import javafx.scene.control.TreeCell;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
|
||||
|
||||
/**
|
||||
@@ -43,15 +41,6 @@ public class ScopeHierarchyTreeCell extends TreeCell<Object> {
|
||||
setText(item instanceof Scope ? getTextForScope((Scope) item)
|
||||
: getTextForDeclaration((NameDeclaration) item));
|
||||
}
|
||||
|
||||
this.addEventHandler(MouseEvent.MOUSE_CLICKED, t -> {
|
||||
if (t.getButton() == MouseButton.PRIMARY
|
||||
&& getTreeView().getSelectionModel().getSelectedItem() == item) {
|
||||
if (item instanceof NameDeclaration) {
|
||||
controller.onNodeItemSelected(((NameDeclaration) item).getNode());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@@ -38,11 +38,7 @@
|
||||
<children>
|
||||
<BorderPane prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<center>
|
||||
<TreeView fx:id="astTreeView" prefHeight="200.0" prefWidth="200.0" styleClass="secondary-panel" BorderPane.alignment="CENTER">
|
||||
<cellFactory>
|
||||
<ASTTreeCell fx:factory="callback" />
|
||||
</cellFactory>
|
||||
</TreeView>
|
||||
<TreeView fx:id="astTreeView" prefHeight="200.0" prefWidth="200.0" styleClass="secondary-panel" BorderPane.alignment="CENTER"/>
|
||||
</center>
|
||||
<top>
|
||||
<ToolBar prefHeight="40.0" prefWidth="200.0" styleClass="accent-header" BorderPane.alignment="CENTER">
|
||||
|
Reference in New Issue
Block a user