Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control clicking exercise opens submit window #447

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/main/java/fi/aalto/cs/apluscourses/ui/base/TreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public class TreeView extends com.intellij.ui.treeStructure.Tree {
}
};

private final transient Set<ActionListener> nodeAppliedListeners = ConcurrentHashMap.newKeySet();
private final transient Set<ActionListener> ctrlClickListeners = ConcurrentHashMap.newKeySet();
private final transient Set<ActionListener> doubleClickListeners = ConcurrentHashMap.newKeySet();

@NotNull
public static SelectableNodeViewModel<?> getViewModel(Object node) {
Expand Down Expand Up @@ -98,12 +99,20 @@ private void update() {
restoreExpandedState(expandedState);
}

public void addNodeAppliedListener(ActionListener listener) {
nodeAppliedListeners.add(listener);
public void addDoubleClickListener(ActionListener listener) {
doubleClickListeners.add(listener);
}

public void removeNodeAppliedListener(ActionListener listener) {
nodeAppliedListeners.remove(listener);
public void removeDoubleClickListener(ActionListener listener) {
doubleClickListeners.remove(listener);
}

public void addCtrlClickListener(ActionListener listener) {
ctrlClickListeners.add(listener);
}

public void removeCtrlClickListener(ActionListener listener) {
ctrlClickListeners.remove(listener);
}

@NotNull
Expand Down Expand Up @@ -151,9 +160,12 @@ protected class TreeMouseListener extends MouseAdapter {

@Override
public void mouseClicked(@NotNull MouseEvent e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think the logic inside the method can be tested fully or maybe at least to the extent of the conditional statements?

if (e.getClickCount() == 2 && selectedItem != null) {
if (e.getClickCount() == 1 && e.isControlDown() && selectedItem != null) {
ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null);
ctrlClickListeners.forEach(listener -> listener.actionPerformed(actionEvent));
} else if (e.getClickCount() == 2 && selectedItem != null) {
ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null);
nodeAppliedListeners.forEach(listener -> listener.actionPerformed(actionEvent));
doubleClickListeners.forEach(listener -> listener.actionPerformed(actionEvent));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intellij.openapi.application.ModalityState;
import fi.aalto.cs.apluscourses.intellij.actions.ActionUtil;
import fi.aalto.cs.apluscourses.intellij.actions.OpenSubmissionAction;
import fi.aalto.cs.apluscourses.intellij.actions.SubmitExerciseAction;
import fi.aalto.cs.apluscourses.presentation.exercise.ExercisesTreeViewModel;
import fi.aalto.cs.apluscourses.ui.GuiObject;
import fi.aalto.cs.apluscourses.ui.base.TreeView;
Expand Down Expand Up @@ -42,8 +43,10 @@ public void viewModelChanged(@Nullable ExercisesTreeViewModel viewModel) {
private void createUIComponents() {
exerciseGroupsTree = new TreeView();
exerciseGroupsTree.setCellRenderer(new ExercisesTreeRenderer());
exerciseGroupsTree.addNodeAppliedListener(
exerciseGroupsTree.addDoubleClickListener(
ActionUtil.createOnEventLauncher(OpenSubmissionAction.ACTION_ID, exerciseGroupsTree));
exerciseGroupsTree.addCtrlClickListener(
ActionUtil.createOnEventLauncher(SubmitExerciseAction.ACTION_ID, exerciseGroupsTree));
}

public TreeView getExerciseGroupsTree() {
Expand Down