Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Trofimov
2015-08-10 21:18:25 +02:00
28 changed files with 153 additions and 91 deletions
@@ -42,12 +42,14 @@ import com.intellij.psi.PsiReference;
import com.intellij.psi.statistics.JavaStatisticsManager;
import com.intellij.psi.statistics.StatisticsManager;
import com.intellij.ui.popup.list.ListPopupImpl;
import com.intellij.ui.popup.list.PopupListElementRenderer;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
@@ -161,7 +163,18 @@ public class AddImportAction implements QuestionAction {
ListPopupImpl popup = new ListPopupImpl(step) {
@Override
protected ListCellRenderer getListElementRenderer() {
return new DefaultPsiElementCellRenderer();
final PopupListElementRenderer baseRenderer = (PopupListElementRenderer)super.getListElementRenderer();
final DefaultPsiElementCellRenderer psiRenderer = new DefaultPsiElementCellRenderer();
return new ListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
JPanel panel = new JPanel(new BorderLayout());
baseRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
panel.add(baseRenderer.getNextStepLabel(), BorderLayout.EAST);
panel.add(psiRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus));
return panel;
}
};
}
};
popup.showInBestPositionFor(myEditor);
@@ -17,20 +17,16 @@ package com.intellij.psi.codeStyle;
import com.intellij.application.options.IndentOptionsEditor;
import com.intellij.lang.Language;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiFile;
import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.HashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
/**
@@ -189,6 +185,7 @@ public abstract class LanguageCodeStyleSettingsProvider {
return null;
}
@SuppressWarnings("unused")
public static DisplayPriority getDisplayPriority(Language language) {
LanguageCodeStyleSettingsProvider langProvider = forLanguage(language);
if (langProvider == null) return DisplayPriority.LANGUAGE_SETTINGS;
@@ -207,15 +207,13 @@ public class CreateDirectoryOrPackageHandler implements InputValidatorEx {
final Runnable run = new Runnable() {
@Override
public void run() {
LocalHistoryAction action = LocalHistoryAction.NULL;
String dirPath = myDirectory.getVirtualFile().getPresentableUrl();
String actionName = IdeBundle.message("progress.creating.directory", dirPath, File.separator, subDirName);
LocalHistoryAction action = LocalHistory.getInstance().startAction(actionName);
try {
String actionName;
String dirPath = myDirectory.getVirtualFile().getPresentableUrl();
actionName = IdeBundle.message("progress.creating.directory", dirPath, File.separator, subDirName);
action = LocalHistory.getInstance().startAction(actionName);
if (createFile) {
myCreatedElement = myDirectory.createFile(subDirName);
CreateFileAction.MkDirs mkdirs = new CreateFileAction.MkDirs(subDirName, myDirectory);
myCreatedElement = mkdirs.directory.createFile(mkdirs.newName);
} else {
createDirectories(subDirName);
}
@@ -29,10 +29,7 @@ import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.util.ProgressWrapper;
import com.intellij.openapi.project.DumbModeTask;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.*;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.util.Computable;
@@ -114,7 +111,7 @@ public class PushedFilePropertiesUpdaterImpl extends PushedFilePropertiesUpdater
// avoid dumb mode for just one file
doPushRecursively(file, pushers, ProjectRootManager.getInstance(myProject).getFileIndex());
}
else {
else if (!ProjectCoreUtil.isProjectOrWorkspaceFile(file)) {
ContainerUtil.addIfNotNull(delayedTasks, createRecursivePushTask(file, pushers));
}
} else if (event instanceof VFileMoveEvent) {
@@ -64,7 +64,8 @@ import java.util.Set;
*/
public class ITNProxy {
private static final String NEW_THREAD_VIEW_URL = "https://ea.jetbrains.com/browser/ea_reports/";
private static final String NEW_THREAD_POST_URL = "https://ea-report.jetbrains.com/trackerRpc/idea/createScr";
private static final String NEW_THREAD_POST_URL_SECURE = "https://ea-report.jetbrains.com/trackerRpc/idea/createScr";
private static final String NEW_THREAD_POST_URL = "http://ea-report.jetbrains.com/trackerRpc/idea/createScr";
private static final String ENCODING = "UTF8";
public static void sendError(Project project,
@@ -110,7 +111,8 @@ public class ITNProxy {
}
Map<String, String> params = createParameters(login, password, error);
HttpURLConnection connection = post(new URL(NEW_THREAD_POST_URL), join(params));
String newThreadPostUrl = NetUtils.isSniEnabled() ? NEW_THREAD_POST_URL_SECURE : NEW_THREAD_POST_URL;
HttpURLConnection connection = post(new URL(newThreadPostUrl), join(params));
int responseCode = connection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new InternalEAPException(DiagnosticBundle.message("error.http.result.code", responseCode));
@@ -62,7 +62,6 @@ public class EditorWithProviderComposite extends EditorComposite {
public Pair<FileEditor, FileEditorProvider> getSelectedEditorWithProvider() {
LOG.assertTrue(myEditors.length > 0, myEditors.length);
if (myEditors.length == 1) {
LOG.assertTrue(myTabbedPaneWrapper == null);
return Pair.create(myEditors[0], myProviders[0]);
}
else { // we have to get myEditor from tabbed pane
@@ -21,8 +21,6 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.help.HelpManager;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurableGroup;
import com.intellij.openapi.project.DumbModePermission;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import org.jetbrains.annotations.NonNls;
@@ -143,12 +141,7 @@ public class SettingsDialog extends DialogWrapper implements DataProvider {
@Override
public void doOKAction() {
if (myEditor.apply()) {
DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().saveAll();
}
});
ApplicationManager.getApplication().saveAll();
super.doOKAction();
}
}
@@ -17,6 +17,7 @@ package com.intellij.ui.mac;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
@@ -62,6 +63,7 @@ public class MacFileChooserDialogImpl implements PathChooserDialog {
private final FileChooserDescriptor myChooserDescriptor;
private final Project myProject;
private ModalityState myModalityState;
private Consumer<List<VirtualFile>> myCallback;
private static final Callback SHOULD_ENABLE_CALLBACK = new Callback() {
@@ -160,14 +162,14 @@ public class MacFileChooserDialogImpl implements PathChooserDialog {
}
});
}
});
}, impl.myModalityState);
} else if (impl.myCallback instanceof FileChooser.FileChooserConsumer) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
((FileChooser.FileChooserConsumer)impl.myCallback).cancelled();
}
});
}, impl.myModalityState);
}
}
finally {
@@ -324,6 +326,7 @@ public class MacFileChooserDialogImpl implements PathChooserDialog {
ExtensionsInitializer.initialize();
myCallback = callback;
myModalityState = ModalityState.current();
final VirtualFile lastOpenedFile = FileChooserUtil.getLastOpenedFile(myProject);
final VirtualFile selectFile = FileChooserUtil.getFileToSelect(myChooserDescriptor, myProject, toSelect, lastOpenedFile);
@@ -110,8 +110,8 @@ public class FileHistoryDialogTest extends LocalHistoryUITestCase {
DiffContent left = getLeftDiffContent(m);
DiffContent right = getRightDiffContent(m);
assertEquals(leftContent, left);
assertEquals(rightContent, right);
assertContent(leftContent, left);
assertContent(rightContent, right);
}
private DiffContent getLeftDiffContent(FileHistoryDialogModel m) {
@@ -23,7 +23,7 @@ import com.intellij.testFramework.SkipInHeadlessEnvironment;
@SkipInHeadlessEnvironment
public abstract class LocalHistoryUITestCase extends IntegrationTestCase {
protected void assertEquals(String expected, DiffContent actual) {
protected void assertContent(String expected, DiffContent actual) {
actual.onAssigned(true);
try {
assertEquals(expected, ((DocumentContent)actual).getDocument().getText());
@@ -90,8 +90,8 @@ public class SelectionHistoryDialogTest extends LocalHistoryUITestCase {
DiffContent left = dm.getLeftDiffContent(new NullRevisionsProgress());
DiffContent right = dm.getRightDiffContent(new NullRevisionsProgress());
assertEquals("b", left);
assertEquals("bc", right);
assertContent("b", left);
assertContent("bc", right);
}
public void testDiffContentsAndTitleForCurrentRevision() throws IOException {
@@ -101,7 +101,7 @@ public class SelectionHistoryDialogTest extends LocalHistoryUITestCase {
DiffContent right = dm.getRightDiffContent(new NullRevisionsProgress());
assertEquals("bcd", right);
assertContent("bcd", right);
assertTrue(right instanceof DocumentFragmentContent);
}
@@ -114,8 +114,8 @@ public class SelectionHistoryDialogTest extends LocalHistoryUITestCase {
initModelOnSecondLineAndSelectRevisions(3, 3);
assertEquals("b", dm.getLeftDiffContent(new NullRevisionsProgress()));
assertEquals("bcd", dm.getRightDiffContent(new NullRevisionsProgress()));
assertContent("b", dm.getLeftDiffContent(new NullRevisionsProgress()));
assertContent("bcd", dm.getRightDiffContent(new NullRevisionsProgress()));
}
public void testRevert() throws IOException {
@@ -85,6 +85,10 @@ public class JBUI {
else if (scale < 2f) scale = 1.75f;
else scale = 2.0f;
if (SystemInfo.isLinux && scale == 1.25f) {
//Default UI font size for Unity and Gnome is 15. Scaling factor 1.25f works badly on Linux
scale = 1f;
}
SCALE_FACTOR = scale;
IconLoader.setScale(scale);
}
@@ -28,6 +28,7 @@ import com.intellij.util.Consumer;
import com.intellij.util.concurrency.Semaphore;
import com.intellij.util.io.storage.HeavyProcessLatch;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import javax.swing.*;
import java.util.ArrayList;
@@ -150,6 +151,7 @@ public class UpdateRequestsQueue {
LOG.debug("Stop finished for project: " + myProject.getName());
}
@TestOnly
public void waitUntilRefreshed() {
while (true) {
final Semaphore semaphore = new Semaphore();
@@ -77,11 +77,11 @@ public abstract class AbstractVcsTestCase {
ChangeListManagerImpl.getInstanceImpl(myProject).waitUntilRefreshed();
}
protected static void refreshVfs() {
protected void refreshVfs() {
UsefulTestCase.edt(new Runnable() {
@Override
public void run() {
LocalFileSystem.getInstance().refresh(false);
myWorkingCopyDir.refresh(false, true);
}
});
}
@@ -79,12 +79,14 @@ public class XDebuggerEvaluateActionHandler extends XDebuggerActionHandler {
value.calculateEvaluationExpression().done(new Consumer<XExpression>() {
@Override
public void consume(final XExpression expression) {
AppUIUtil.invokeOnEdt(new Runnable() {
@Override
public void run() {
showDialog(session, file, editorsProvider, stackFrame, evaluator, expression);
}
});
if (expression != null) {
AppUIUtil.invokeOnEdt(new Runnable() {
@Override
public void run() {
showDialog(session, file, editorsProvider, stackFrame, evaluator, expression);
}
});
}
}
});
return;
@@ -100,7 +102,7 @@ public class XDebuggerEvaluateActionHandler extends XDebuggerActionHandler {
XDebuggerEditorsProvider editorsProvider,
XStackFrame stackFrame,
XDebuggerEvaluator evaluator,
XExpression expression) {
@NotNull XExpression expression) {
if (expression.getLanguage() == null) {
Language language = null;
if (stackFrame != null) {
@@ -136,7 +136,6 @@
<referencesSearch implementation="org.jetbrains.idea.devkit.references.IconsReferencesContributor"/>
<unusedDeclarationFixProvider implementation="org.jetbrains.idea.devkit.inspections.quickfix.RegisterExtensionFixProvider"/>
<stacktrace.fold substring="at com.intellij.testFramework."/>
<stacktrace.fold substring="at com.intellij.util.messages.impl.MessageBus"/>
<stacktrace.fold substring="com.intellij.openapi.command.WriteCommandAction"/>
<stacktrace.fold substring="at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction("/>
@@ -16,6 +16,8 @@ public class CCCreateAnswerPlaceholderPanel extends JPanel {
super(new BorderLayout());
add(myPanel, BorderLayout.CENTER);
enableHint(false);
myHintText.setLineWrap(true);
myHintText.setWrapStyleWord(true);
myCreateHintCheckBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
@@ -106,15 +106,11 @@ public class StudyUtils {
public static void updateAction(@NotNull final AnActionEvent e) {
final Presentation presentation = e.getPresentation();
presentation.setEnabled(false);
presentation.setVisible(false);
final Project project = e.getProject();
if (project != null) {
final FileEditor[] editors = FileEditorManager.getInstance(project).getAllEditors();
for (FileEditor editor : editors) {
if (editor instanceof StudyEditor) {
presentation.setEnabled(true);
presentation.setVisible(true);
}
final StudyEditor studyEditor = getSelectedStudyEditor(project);
if (studyEditor != null) {
presentation.setEnabled(true);
}
}
}
@@ -7,6 +7,7 @@ import com.intellij.ide.projectView.ProjectView;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.KeyboardShortcut;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.diagnostic.Logger;
@@ -396,6 +397,10 @@ public class StudyCheckAction extends DumbAwareAction {
@Override
public void update(AnActionEvent e) {
e.getPresentation().setEnabled(!checkInProgress);
final Presentation presentation = e.getPresentation();
StudyUtils.updateAction(e);
if (presentation.isEnabled()) {
presentation.setEnabled(!checkInProgress);
}
}
}
@@ -175,13 +175,13 @@ public class StudyRefreshTaskFileAction extends DumbAwareAction {
@Override
public void update(AnActionEvent event) {
EduUtils.enableAction(event, false);
StudyUtils.updateAction(event);
final Project project = event.getProject();
if (project != null) {
StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
StudyState studyState = new StudyState(studyEditor);
if (studyState.isValid()) {
EduUtils.enableAction(event, true);
if (!studyState.isValid()) {
event.getPresentation().setEnabled(false);
}
}
}
@@ -115,4 +115,9 @@ abstract public class StudyTaskNavigationAction extends DumbAwareAction {
protected abstract String getNavigationFinishedMessage();
protected abstract Task getTargetTask(@NotNull final Task sourceTask);
@Override
public void update(AnActionEvent e) {
StudyUtils.updateAction(e);
}
}
@@ -8,6 +8,8 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.DumbModePermission;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.io.FileUtil;
@@ -66,17 +68,21 @@ public class StudyProjectGenerator {
new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() {
@Override
public void run() {
course.initCourse(false);
final File courseDirectory = new File(ourCoursesDir, course.getName());
StudyGenerator.createCourse(course, baseDir, courseDirectory, project);
course.setCourseDirectory(new File(ourCoursesDir, mySelectedCourseInfo.getName()).getAbsolutePath());
VirtualFileManager.getInstance().refreshWithoutFileWatcher(true);
StudyProjectComponent.getInstance(project).registerStudyToolwindow(course);
openFirstTask(course, project);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
course.initCourse(false);
final File courseDirectory = new File(ourCoursesDir, course.getName());
StudyGenerator.createCourse(course, baseDir, courseDirectory, project);
course.setCourseDirectory(new File(ourCoursesDir, mySelectedCourseInfo.getName()).getAbsolutePath());
VirtualFileManager.getInstance().refreshWithoutFileWatcher(true);
StudyProjectComponent.getInstance(project).registerStudyToolwindow(course);
openFirstTask(course, project);
}
});
}
});
}
@@ -3,6 +3,7 @@ package com.jetbrains.edu.learning.navigation;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.LogicalPosition;
import com.intellij.openapi.project.Project;
import com.jetbrains.edu.EduNames;
import com.jetbrains.edu.courseFormat.AnswerPlaceholder;
import com.jetbrains.edu.courseFormat.Lesson;
import com.jetbrains.edu.courseFormat.Task;
@@ -52,7 +53,10 @@ public class StudyNavigator {
if (nextLessonIndex >= lessons.size()) {
return null;
}
return lessons.get(nextLessonIndex);
final Lesson nextLesson = lessons.get(nextLessonIndex);
if (EduNames.PYCHARM_ADDITIONAL.equals(nextLesson.getName()))
return null;
return nextLesson;
}
public static Lesson previousLesson(@NotNull final Lesson lesson) {
@@ -93,7 +93,7 @@
<properties>
<horizontalTextPosition value="0"/>
<text value=""/>
<toolTipText value="Select local course"/>
<toolTipText value="Refresh course list"/>
</properties>
</component>
</children>
@@ -16,14 +16,15 @@ import com.intellij.util.Consumer;
import com.jetbrains.edu.courseFormat.Course;
import com.jetbrains.edu.learning.StudyUtils;
import com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator;
import com.jetbrains.edu.stepic.StudySettings;
import com.jetbrains.edu.stepic.CourseInfo;
import com.jetbrains.edu.stepic.EduStepicConnector;
import com.jetbrains.edu.stepic.StudySettings;
import icons.InteractiveLearningIcons;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
@@ -51,6 +52,8 @@ public class StudyNewProjectPanel{
public StudyNewProjectPanel(StudyProjectGenerator generator) {
myGenerator = generator;
myAvailableCourses = myGenerator.getCourses(false);
myBrowseButton.setPreferredSize(new Dimension(28, 28));
myRefreshButton.setPreferredSize(new Dimension(28, 28));
if (myAvailableCourses.isEmpty()) {
setError(CONNECTION_ERROR);
}
@@ -59,7 +62,8 @@ public class StudyNewProjectPanel{
myCoursesComboBox.addItem(courseInfo);
}
final CourseInfo selectedCourse = StudyUtils.getFirst(myAvailableCourses);
myAuthorLabel.setText("Author: " + Course.getAuthorsString(selectedCourse.getAuthors()));
final String authorsString = Course.getAuthorsString(selectedCourse.getAuthors());
myAuthorLabel.setText(!StringUtil.isEmptyOrSpaces(authorsString) ? "Author: " + authorsString : "");
myDescriptionLabel.setText(selectedCourse.getDescription());
//setting the first course in list as selected
myGenerator.setSelectedCourse(selectedCourse);
@@ -209,7 +213,8 @@ public class StudyNewProjectPanel{
myDescriptionLabel.setText("");
return;
}
myAuthorLabel.setText("Author: " + Course.getAuthorsString(selectedCourse.getAuthors()));
final String authorsString = Course.getAuthorsString(selectedCourse.getAuthors());
myAuthorLabel.setText(!StringUtil.isEmptyOrSpaces(authorsString) ?"Author: " + authorsString : "");
myCoursesComboBox.removeItem(CourseInfo.INVALID_COURSE);
myDescriptionLabel.setText(selectedCourse.getDescription());
myGenerator.setSelectedCourse(selectedCourse);
@@ -21,6 +21,7 @@ import com.intellij.openapi.actionSystem.ActionToolbar;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
@@ -40,29 +41,35 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import java.awt.*;
public class StudyToolWindow extends SimpleToolWindowPanel implements DataProvider, Disposable {
private static final String EMPTY_TASK_TEXT = "Please, open any task to see task description";
public StudyToolWindow(final Project project) {
super(true, true);
JPanel toolbarPanel = createToolbarPanel();
setToolbar(toolbarPanel);
final StudyEditor studyEditor = StudyUtils.getSelectedStudyEditor(project);
if (studyEditor == null) return;
Task task = studyEditor.getTaskFile().getTask();
final JTextPane taskTextPane = createTaskTextPane();
if (studyEditor == null) {
taskTextPane.setText(EMPTY_TASK_TEXT);
setContent(taskTextPane);
return;
}
final Task task = studyEditor.getTaskFile().getTask();
if (task != null) {
final String taskText = task.getText();
final JTextPane taskTextPane = new JTextPane();
JBScrollPane scrollPane = new JBScrollPane(taskTextPane);
taskTextPane.setContentType("text/html");
taskTextPane.setEditable(false);
taskTextPane.setText(taskText);
taskTextPane.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);
taskTextPane.setBackground(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground());
taskTextPane.setBorder(new EmptyBorder(15, 20, 0, 100));
setContent(scrollPane);
final FileEditorManagerListener listener = new StudyFileEditorManagerListener(project, taskTextPane);
@@ -70,6 +77,23 @@ public class StudyToolWindow extends SimpleToolWindowPanel implements DataProvid
}
}
@NotNull
private JTextPane createTaskTextPane() {
final JTextPane taskTextPane = new JTextPane();
taskTextPane.setContentType(new HTMLEditorKit().getContentType());
final EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
int fontSize = editorColorsScheme.getEditorFontSize();
final String fontName = editorColorsScheme.getEditorFontName();
final Font font = new Font(fontName, Font.PLAIN, fontSize);
String bodyRule = "body { font-family: " + font.getFamily() + "; " +
"font-size: " + font.getSize() + "pt; }";
((HTMLDocument)taskTextPane.getDocument()).getStyleSheet().addRule(bodyRule);
taskTextPane.setEditable(false);
taskTextPane.setBackground(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground());
taskTextPane.setBorder(new EmptyBorder(15, 20, 0, 100));
return taskTextPane;
}
public void dispose() {
}
@@ -92,22 +116,24 @@ public class StudyToolWindow extends SimpleToolWindowPanel implements DataProvid
private Project myProject;
private JTextPane myTaskTextPane;
StudyFileEditorManagerListener(@NotNull final Project project, JTextPane taskTextPane){
StudyFileEditorManagerListener(@NotNull final Project project, JTextPane taskTextPane) {
myProject = project;
myTaskTextPane = taskTextPane;
}
@Override
public void fileOpened (@NotNull FileEditorManager source, @NotNull VirtualFile file){
@Override
public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
Task task = getTask(file);
setTaskText(task);
}
@Override
public void fileClosed (@NotNull FileEditorManager source, @NotNull VirtualFile file){
@Override
public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
myTaskTextPane.setText(EMPTY_TASK_TEXT);
}
@Override
public void selectionChanged (@NotNull FileEditorManagerEvent event){
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
VirtualFile file = event.getNewFile();
if (file != null) {
Task task = getTask(file);
@@ -115,8 +141,8 @@ public class StudyToolWindow extends SimpleToolWindowPanel implements DataProvid
}
}
@Nullable
private Task getTask (@NotNull VirtualFile file){
@Nullable
private Task getTask(@NotNull VirtualFile file) {
TaskFile taskFile = StudyUtils.getTaskFile(myProject, file);
if (taskFile != null) {
return taskFile.getTask();
@@ -128,6 +154,7 @@ public class StudyToolWindow extends SimpleToolWindowPanel implements DataProvid
private void setTaskText(@Nullable final Task task) {
if (task == null) {
myTaskTextPane.setText(EMPTY_TASK_TEXT);
return;
}
String text = task.getText();
@@ -25,7 +25,6 @@ public class StudyToolWindowFactory implements ToolWindowFactory, DumbAware {
final Content content = contentManager.getFactory().createContent(studyToolWindow, null, false);
contentManager.addContent(content);
Disposer.register(project, studyToolWindow);
}
}
@@ -200,6 +200,10 @@ public class EduUtils {
taskFile.sortAnswerPlaceholders();
for (int i = taskFile.getAnswerPlaceholders().size() - 1; i >= 0; i--) {
final AnswerPlaceholder answerPlaceholder = taskFile.getAnswerPlaceholders().get(i);
if (answerPlaceholder.getRealStartOffset(document) > document.getTextLength() || answerPlaceholder.getRealStartOffset(document) + answerPlaceholder.getPossibleAnswerLength() > document.getTextLength()) {
LOG.error("Wrong startOffset: " + answerPlaceholder.getRealStartOffset(document) + "; document: " + file.getPath());
return;
}
replaceAnswerPlaceholder(project, document, answerPlaceholder);
}
CommandProcessor.getInstance().executeCommand(project, new Runnable() {