mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -59,6 +59,9 @@
|
||||
<action id="CreateTaskFile" class="com.jetbrains.edu.coursecreator.actions.CCCreateTaskFile">
|
||||
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewFile"/>
|
||||
</action>
|
||||
<action id="AddTaskFile" class="com.jetbrains.edu.coursecreator.actions.CCAddAsTaskFile" text="Add As Task File">
|
||||
<add-to-group group-id="ProjectViewPopupMenu" anchor="first"/>
|
||||
</action>
|
||||
<action id="AddTaskWindow" class="com.jetbrains.edu.coursecreator.actions.CCAddAnswerPlaceholder">
|
||||
<add-to-group group-id="EditorPopupMenu" anchor="before" relative-to-action="CopyReference"/>
|
||||
</action>
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package com.jetbrains.edu.coursecreator.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.jetbrains.edu.courseFormat.Task;
|
||||
import com.jetbrains.edu.coursecreator.CCProjectService;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CCAddAsTaskFile extends AnAction {
|
||||
private static final Logger LOG = Logger.getInstance(CCAddAsTaskFile.class);
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
Task task = CCProjectService.getInstance(project).getTask(file);
|
||||
if (task == null) {
|
||||
return;
|
||||
}
|
||||
task.addTaskFile(file.getName(), task.getTaskFiles().size());
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String name = file.getNameWithoutExtension();
|
||||
String extension = file.getExtension();
|
||||
try {
|
||||
file.rename(this, name + ".answer." + extension);
|
||||
}
|
||||
catch (IOException e1) {
|
||||
LOG.error(e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
Presentation presentation = e.getPresentation();
|
||||
if (project == null) {
|
||||
presentation.setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
|
||||
if (file == null || file.isDirectory() || CCProjectService.getInstance(project).isAnswerFile(file)) {
|
||||
presentation.setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
Task task = CCProjectService.getInstance(project).getTask(file);
|
||||
if (task == null) {
|
||||
presentation.setEnabledAndVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user