summaryrefslogtreecommitdiff
path: root/python/edu/learn-python/src/com/jetbrains/python/edu/actions/StudyNextWindowAction.java
blob: 595aeeff42e3bd4353933e9730fc8a4fee1096ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.jetbrains.python.edu.actions;

import com.jetbrains.python.edu.StudyUtils;
import com.jetbrains.python.edu.course.TaskWindow;
import icons.StudyIcons;
import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * move caret to next task window
 */
public class StudyNextWindowAction extends StudyWindowNavigationAction {
  public static final String ACTION_ID = "NextWindow";
  public static final String SHORTCUT = "ctrl pressed PERIOD";
  public static final String SHORTCUT2 = "ctrl pressed ENTER";

  public StudyNextWindowAction() {
    super("NextWindowAction", "Select next window", StudyIcons.Next);
  }

  @Override
  protected TaskWindow getNextTaskWindow(@NotNull final TaskWindow window) {
    int index = window.getIndex();
    List<TaskWindow> windows = window.getTaskFile().getTaskWindows();
    if (StudyUtils.indexIsValid(index, windows)) {
      int newIndex = index + 1;
        return newIndex == windows.size() ? windows.get(0) : windows.get(newIndex);
    }
    return null;
  }
}