mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
hide and make visible from prev subtasks actions
This commit is contained in:
committed by
liana.bakradze
parent
4994935b7c
commit
f743e8baaf
@@ -80,6 +80,8 @@
|
||||
</group>
|
||||
|
||||
<group id="AnswerPlaceholderGroup">
|
||||
<action id="CC.HideFromPrevSubtasks" class="com.jetbrains.edu.coursecreator.actions.CCHidePlaceholderFromPrevSubtasks"/>
|
||||
<action id="CC.MakeVisibleFromPrevSubtasks" class="com.jetbrains.edu.coursecreator.actions.CCMakeVisibleForPrevSubtasks"/>
|
||||
<action id="EditAnswerPlaceholder" class="com.jetbrains.edu.coursecreator.actions.CCEditAnswerPlaceholder"/>
|
||||
<action id="AddTaskWindow" class="com.jetbrains.edu.coursecreator.actions.CCAddAnswerPlaceholder"/>
|
||||
<action id="DeleteAllPlaceholders" class="com.jetbrains.edu.coursecreator.actions.CCDeleteAllAnswerPlaceholdersAction"/>
|
||||
|
||||
+1
-2
@@ -75,7 +75,6 @@ public class CCAddAnswerPlaceholder extends CCAnswerPlaceholderAction {
|
||||
}
|
||||
final AnswerPlaceholder answerPlaceholder = new AnswerPlaceholder();
|
||||
AnswerPlaceholderSubtaskInfo info = new AnswerPlaceholderSubtaskInfo();
|
||||
info.setNeedInsertText(!model.hasSelection());
|
||||
answerPlaceholder.getSubtaskInfos().put(stepIndex, info);
|
||||
int index = taskFile.getAnswerPlaceholders().size();
|
||||
answerPlaceholder.setIndex(index);
|
||||
@@ -92,7 +91,7 @@ public class CCAddAnswerPlaceholder extends CCAnswerPlaceholderAction {
|
||||
String answerPlaceholderText = dlg.getTaskText();
|
||||
answerPlaceholder.setPossibleAnswer(model.hasSelection() ? model.getSelectedText() : defaultPlaceholderText);
|
||||
answerPlaceholder.setTaskText(StringUtil.notNullize(answerPlaceholderText));
|
||||
answerPlaceholder.setLength(model.hasSelection() ? StringUtil.notNullize(answerPlaceholderText).length() : 0);
|
||||
answerPlaceholder.setLength(StringUtil.notNullize(answerPlaceholderText).length());
|
||||
answerPlaceholder.setHints(dlg.getHints());
|
||||
|
||||
if (!model.hasSelection()) {
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package com.jetbrains.edu.coursecreator.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.command.undo.BasicUndoableAction;
|
||||
import com.intellij.openapi.command.undo.UnexpectedUndoException;
|
||||
import com.jetbrains.edu.learning.StudyUtils;
|
||||
import com.jetbrains.edu.learning.core.EduUtils;
|
||||
import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
|
||||
import com.jetbrains.edu.learning.courseFormat.Task;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public abstract class CCChangePlaceholderVisibility extends CCAnswerPlaceholderAction {
|
||||
|
||||
protected CCChangePlaceholderVisibility(@Nullable String text, @Nullable String description) {
|
||||
super(text, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performAnswerPlaceholderAction(@NotNull CCState state) {
|
||||
AnswerPlaceholder placeholder = state.getAnswerPlaceholder();
|
||||
if (placeholder == null) {
|
||||
return;
|
||||
}
|
||||
EduUtils.runUndoableAction(state.getProject(), getName(), new BasicUndoableAction(state.getEditor().getDocument()) {
|
||||
@Override
|
||||
public void undo() throws UnexpectedUndoException {
|
||||
setVisible(placeholder, isVisible(), state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redo() throws UnexpectedUndoException {
|
||||
setVisible(placeholder, !isVisible(), state);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setVisible(AnswerPlaceholder placeholder, boolean visible, CCState state) {
|
||||
placeholder.getActiveSubtaskInfo().setNeedInsertText(visible);
|
||||
int length = isVisible() ? placeholder.getTaskText().length() : 0;
|
||||
placeholder.setLength(length);
|
||||
StudyUtils.drawAllWindows(state.getEditor(), state.getTaskFile());
|
||||
}
|
||||
|
||||
protected abstract String getName();
|
||||
|
||||
protected abstract boolean isVisible();
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
Presentation presentation = e.getPresentation();
|
||||
presentation.setEnabledAndVisible(false);
|
||||
CCState state = getState(e);
|
||||
if (state == null) {
|
||||
return;
|
||||
}
|
||||
AnswerPlaceholder placeholder = state.getAnswerPlaceholder();
|
||||
if (placeholder == null) {
|
||||
return;
|
||||
}
|
||||
Task task = state.getTaskFile().getTask();
|
||||
if (!task.hasSubtasks()) {
|
||||
return;
|
||||
}
|
||||
Integer minSubtaskIndex = Collections.min(placeholder.getSubtaskInfos().keySet());
|
||||
if (placeholder.isActive() && minSubtaskIndex != 0 && minSubtaskIndex == task.getActiveSubtaskIndex() && isAvailable(placeholder)) {
|
||||
presentation.setEnabledAndVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract boolean isAvailable(AnswerPlaceholder placeholder);
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.jetbrains.edu.coursecreator.actions;
|
||||
|
||||
import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
|
||||
|
||||
public class CCHidePlaceholderFromPrevSubtasks extends CCChangePlaceholderVisibility {
|
||||
|
||||
public static final String TITLE = "Hide for Previous Subtasks";
|
||||
|
||||
public CCHidePlaceholderFromPrevSubtasks() {
|
||||
super(TITLE, TITLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName() {
|
||||
return TITLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAvailable(AnswerPlaceholder placeholder) {
|
||||
return !placeholder.getActiveSubtaskInfo().isNeedInsertText();
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.jetbrains.edu.coursecreator.actions;
|
||||
|
||||
import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
|
||||
|
||||
public class CCMakeVisibleForPrevSubtasks extends CCChangePlaceholderVisibility {
|
||||
|
||||
public static final String TITLE = "Make Visible For Previous Subtasks";
|
||||
|
||||
protected CCMakeVisibleForPrevSubtasks() {
|
||||
super(TITLE, TITLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName() {
|
||||
return TITLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isVisible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAvailable(AnswerPlaceholder placeholder) {
|
||||
return placeholder.getActiveSubtaskInfo().isNeedInsertText();
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,9 @@ public class StudyTaskManager implements PersistentStateComponent<Element>, Dumb
|
||||
}
|
||||
|
||||
public JBColor getColor(@NotNull final AnswerPlaceholder placeholder) {
|
||||
if (!placeholder.getUseLength() && placeholder.isActive() && placeholder.getActiveSubtaskInfo().isNeedInsertText()) {
|
||||
return JBColor.LIGHT_GRAY;
|
||||
}
|
||||
final StudyStatus status = placeholder.getStatus();
|
||||
if (status == StudyStatus.Solved) {
|
||||
return JBColor.GREEN;
|
||||
|
||||
Reference in New Issue
Block a user