mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EDIDE-88 loop task windows
This commit is contained in:
+12
-42
@@ -1,23 +1,16 @@
|
||||
package com.jetbrains.python.edu.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.python.edu.StudyTaskManager;
|
||||
import com.jetbrains.python.edu.StudyUtils;
|
||||
import com.jetbrains.python.edu.course.StudyStatus;
|
||||
import com.jetbrains.python.edu.course.TaskFile;
|
||||
import com.jetbrains.python.edu.course.TaskWindow;
|
||||
import com.jetbrains.python.edu.editor.StudyEditor;
|
||||
import icons.StudyIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* move caret to next task window
|
||||
*/
|
||||
public class StudyNextWindowAction extends DumbAwareAction {
|
||||
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";
|
||||
@@ -26,37 +19,14 @@ public class StudyNextWindowAction extends DumbAwareAction {
|
||||
super("NextWindowAction", "Select next window", StudyIcons.Next);
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
if (project != null) {
|
||||
Editor selectedEditor = StudyEditor.getSelectedEditor(project);
|
||||
if (selectedEditor != null) {
|
||||
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
|
||||
VirtualFile openedFile = fileDocumentManager.getFile(selectedEditor.getDocument());
|
||||
if (openedFile != null) {
|
||||
StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
|
||||
TaskFile selectedTaskFile = taskManager.getTaskFile(openedFile);
|
||||
if (selectedTaskFile != null) {
|
||||
TaskWindow selectedTaskWindow = selectedTaskFile.getSelectedTaskWindow();
|
||||
boolean ifDraw = false;
|
||||
for (TaskWindow taskWindow : selectedTaskFile.getTaskWindows()) {
|
||||
if (ifDraw) {
|
||||
selectedTaskFile.setSelectedTaskWindow(taskWindow);
|
||||
taskWindow.draw(selectedEditor, taskWindow.getStatus() != StudyStatus.Solved, true);
|
||||
return;
|
||||
}
|
||||
if (taskWindow == selectedTaskWindow) {
|
||||
ifDraw = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
StudyUtils.updateAction(e);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+13
-41
@@ -1,24 +1,18 @@
|
||||
package com.jetbrains.python.edu.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.python.edu.StudyTaskManager;
|
||||
import com.jetbrains.python.edu.StudyUtils;
|
||||
import com.jetbrains.python.edu.course.StudyStatus;
|
||||
import com.jetbrains.python.edu.course.TaskFile;
|
||||
import com.jetbrains.python.edu.course.TaskWindow;
|
||||
import com.jetbrains.python.edu.editor.StudyEditor;
|
||||
import icons.StudyIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* author: liana
|
||||
* data: 6/30/14.
|
||||
*/
|
||||
public class StudyPrevWindowAction extends DumbAwareAction {
|
||||
public class StudyPrevWindowAction extends StudyWindowNavigationAction {
|
||||
public static final String ACTION_ID = "PrevWindowAction";
|
||||
public static final String SHORTCUT = "ctrl pressed COMMA";
|
||||
|
||||
@@ -26,37 +20,15 @@ public class StudyPrevWindowAction extends DumbAwareAction {
|
||||
super("PrevWindowAction", "Select previous window", StudyIcons.Prev);
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
assert project != null;
|
||||
Editor selectedEditor = StudyEditor.getSelectedEditor(project);
|
||||
if (selectedEditor != null) {
|
||||
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
|
||||
VirtualFile openedFile = fileDocumentManager.getFile(selectedEditor.getDocument());
|
||||
if (openedFile != null) {
|
||||
StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
|
||||
TaskFile selectedTaskFile = taskManager.getTaskFile(openedFile);
|
||||
if (selectedTaskFile != null) {
|
||||
TaskWindow selectedTaskWindow = selectedTaskFile.getSelectedTaskWindow();
|
||||
TaskWindow prev = null;
|
||||
for (TaskWindow taskWindow : selectedTaskFile.getTaskWindows()) {
|
||||
if (taskWindow == selectedTaskWindow) {
|
||||
break;
|
||||
}
|
||||
prev = taskWindow;
|
||||
}
|
||||
|
||||
if (prev != null) {
|
||||
selectedTaskFile.setSelectedTaskWindow(prev);
|
||||
prev.draw(selectedEditor, prev.getStatus() != StudyStatus.Solved, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
StudyUtils.updateAction(e);
|
||||
protected TaskWindow getNextTaskWindow(@NotNull final TaskWindow window) {
|
||||
int prevIndex = window.getIndex() - 1;
|
||||
List<TaskWindow> windows = window.getTaskFile().getTaskWindows();
|
||||
if (StudyUtils.indexIsValid(prevIndex, windows)) {
|
||||
return windows.get(prevIndex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package com.jetbrains.python.edu.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.python.edu.StudyTaskManager;
|
||||
import com.jetbrains.python.edu.StudyUtils;
|
||||
import com.jetbrains.python.edu.course.TaskFile;
|
||||
import com.jetbrains.python.edu.course.TaskWindow;
|
||||
import com.jetbrains.python.edu.editor.StudyEditor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
abstract public class StudyWindowNavigationAction extends DumbAwareAction {
|
||||
|
||||
public StudyWindowNavigationAction(String actionId, String description, Icon icon) {
|
||||
super(actionId, description, icon);
|
||||
}
|
||||
|
||||
public void navigateWindow(@NotNull final Project project) {
|
||||
Editor selectedEditor = StudyEditor.getSelectedEditor(project);
|
||||
if (selectedEditor != null) {
|
||||
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
|
||||
VirtualFile openedFile = fileDocumentManager.getFile(selectedEditor.getDocument());
|
||||
if (openedFile != null) {
|
||||
StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
|
||||
TaskFile selectedTaskFile = taskManager.getTaskFile(openedFile);
|
||||
if (selectedTaskFile != null) {
|
||||
TaskWindow selectedTaskWindow = selectedTaskFile.getSelectedTaskWindow();
|
||||
if (selectedTaskWindow == null) {
|
||||
return;
|
||||
}
|
||||
TaskWindow nextTaskWindow = getNextTaskWindow(selectedTaskWindow);
|
||||
if (nextTaskWindow == null) {
|
||||
return;
|
||||
}
|
||||
nextTaskWindow.draw(selectedEditor, true, true);
|
||||
selectedTaskFile.setSelectedTaskWindow(nextTaskWindow);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract TaskWindow getNextTaskWindow(@NotNull final TaskWindow window);
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
navigateWindow(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
StudyUtils.updateAction(e);
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@ public class TaskFile implements Stateful{
|
||||
return myTask;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Transient
|
||||
public TaskWindow getSelectedTaskWindow() {
|
||||
return mySelectedTaskWindow;
|
||||
@@ -215,6 +216,7 @@ public class TaskFile implements Stateful{
|
||||
public void navigateToFirstTaskWindow(@NotNull final Editor editor) {
|
||||
if (!taskWindows.isEmpty()) {
|
||||
TaskWindow firstTaskWindow = StudyUtils.getFirst(taskWindows);
|
||||
mySelectedTaskWindow = firstTaskWindow;
|
||||
LogicalPosition taskWindowStart = new LogicalPosition(firstTaskWindow.getLine(), firstTaskWindow.getStart());
|
||||
editor.getCaretModel().moveToLogicalPosition(taskWindowStart);
|
||||
int startOffset = firstTaskWindow.getRealStartOffset(editor.getDocument());
|
||||
|
||||
Reference in New Issue
Block a user