本文整理匯總了Java中com.intellij.openapi.editor.Document.addDocumentListener方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.addDocumentListener方法的具體用法?Java Document.addDocumentListener怎麽用?Java Document.addDocumentListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.openapi.editor.Document
的用法示例。
在下文中一共展示了Document.addDocumentListener方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: selectionChanged
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
VirtualFile fileNew = event.getNewFile();
Editor rootEditor = event.getManager().getSelectedTextEditor();
if (rootEditor == null) {
return;
}
Document rootDocument = rootEditor.getDocument();
if (fileNew != null) {
if (!isFeatureFile(fileNew))
return;
String pathNewFile = getRelativePath(fileNew.getPath());
if (openedGherkinFiles.stream().noneMatch(f -> f.equals(pathNewFile))) {
openedGherkinFiles.add(pathNewFile);
GherkinIconUtils gherkinIconUtils = new GherkinIconUtils(pathNewFile);
gherkinIconUtils.generateGherkinRunIcons(rootDocument, rootEditor);
GherkinDocumentListener listener = new GherkinDocumentListener(pathNewFile, rootEditor);
rootDocument.addDocumentListener(listener);
documentListeners.add(listener);
}
}
}
示例2: getCopyWithAnswers
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
static Pair<VirtualFile, TaskFile> getCopyWithAnswers(@NotNull final VirtualFile taskDir,
@NotNull final VirtualFile file,
@NotNull final TaskFile source) {
try {
VirtualFile answerFile = file.copy(taskDir, taskDir, file.getNameWithoutExtension() + EduNames.ANSWERS_POSTFIX + "." + file.getExtension());
final FileDocumentManager documentManager = FileDocumentManager.getInstance();
final Document document = documentManager.getDocument(answerFile);
if (document != null) {
TaskFile answerTaskFile = source.getTask().copy().getTaskFile(StudyUtils.pathRelativeToTask(file));
if (answerTaskFile == null) {
return null;
}
EduDocumentListener listener = new EduDocumentListener(answerTaskFile);
document.addDocumentListener(listener);
for (AnswerPlaceholder answerPlaceholder : answerTaskFile.getActivePlaceholders()) {
final int start = answerPlaceholder.getOffset();
final int end = start + answerPlaceholder.getRealLength();
final String text = answerPlaceholder.getPossibleAnswer();
document.replaceString(start, end, text);
}
ApplicationManager.getApplication().runWriteAction(() -> documentManager.saveDocument(document));
return Pair.create(answerFile, answerTaskFile);
}
}
catch (IOException e) {
LOG.error(e);
}
return null;
}
示例3: smartCheck
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
private static void smartCheck(@NotNull final AnswerPlaceholder placeholder,
@NotNull final Project project,
@NotNull final VirtualFile answerFile,
@NotNull final TaskFile answerTaskFile,
@NotNull final TaskFile usersTaskFile,
@NotNull final PyStudyTestRunner testRunner,
@NotNull final VirtualFile virtualFile,
@NotNull final Document usersDocument) {
VirtualFile fileWindows = null;
VirtualFile windowCopy = null;
try {
final int index = placeholder.getIndex();
String windowCopyName = answerFile.getNameWithoutExtension() + index + EduNames.WINDOW_POSTFIX + answerFile.getExtension();
windowCopy = answerFile.copy(project, answerFile.getParent(), windowCopyName);
final FileDocumentManager documentManager = FileDocumentManager.getInstance();
final Document windowDocument = documentManager.getDocument(windowCopy);
if (windowDocument != null) {
TaskFile windowTaskFile = answerTaskFile.getTask().copy().getTaskFile(StudyUtils.pathRelativeToTask(virtualFile));
if (windowTaskFile == null) {
return;
}
EduDocumentListener listener = new EduDocumentListener(windowTaskFile);
windowDocument.addDocumentListener(listener);
int start = placeholder.getOffset();
int end = start + placeholder.getRealLength();
final AnswerPlaceholder userAnswerPlaceholder = usersTaskFile.getAnswerPlaceholders().get(placeholder.getIndex());
int userStart = userAnswerPlaceholder.getOffset();
int userEnd = userStart + userAnswerPlaceholder.getRealLength();
String text = usersDocument.getText(new TextRange(userStart, userEnd));
windowDocument.replaceString(start, end, text);
ApplicationManager.getApplication().runWriteAction(() -> documentManager.saveDocument(windowDocument));
fileWindows = EduUtils.flushWindows(windowTaskFile, windowCopy);
Process smartTestProcess = testRunner.createCheckProcess(project, windowCopy.getPath());
final CapturingProcessHandler handler = new CapturingProcessHandler(smartTestProcess, null, windowCopy.getPath());
final ProcessOutput output = handler.runProcess();
final Course course = StudyTaskManager.getInstance(project).getCourse();
if (course != null) {
boolean res = StudyTestsOutputParser.getTestsOutput(output, course.isAdaptive()).isSuccess();
StudyTaskManager.getInstance(project).setStatus(userAnswerPlaceholder, res ? StudyStatus.Solved : StudyStatus.Failed);
}
}
}
catch (ExecutionException | IOException e) {
LOG.error(e);
}
finally {
StudyUtils.deleteFile(windowCopy);
StudyUtils.deleteFile(fileWindows);
}
}
示例4: switchStep
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
/***
* @param toSubtaskIndex from 0 to subtaskNum - 1
*/
public static void switchStep(@NotNull Project project, @NotNull TaskWithSubtasks task, int toSubtaskIndex, boolean navigateToTask) {
if (toSubtaskIndex == task.getActiveSubtaskIndex()) {
return;
}
VirtualFile taskDir = task.getTaskDir(project);
if (taskDir == null) {
return;
}
VirtualFile srcDir = taskDir.findChild(EduNames.SRC);
if (srcDir != null) {
taskDir = srcDir;
}
int fromSubtaskIndex = task.getActiveSubtaskIndex();
for (Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
String name = entry.getKey();
VirtualFile virtualFile = taskDir.findFileByRelativePath(name);
if (virtualFile == null) {
continue;
}
TaskFile taskFile = entry.getValue();
Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
if (document == null) {
continue;
}
EduDocumentListener listener = null;
if (!FileEditorManager.getInstance(project).isFileOpen(virtualFile)) {
listener = new EduDocumentListener(taskFile, true);
document.addDocumentListener(listener);
}
updatePlaceholderTexts(document, taskFile, fromSubtaskIndex, toSubtaskIndex);
if (listener != null) {
document.removeDocumentListener(listener);
}
UndoManager.getInstance(project).nonundoableActionPerformed(DocumentReferenceManager.getInstance().create(document), false);
EditorNotifications.getInstance(project).updateNotifications(virtualFile);
if (StudyUtils.isStudentProject(project)) {
WolfTheProblemSolver.getInstance(project).clearProblems(virtualFile);
taskFile.setHighlightErrors(false);
}
}
transformTestFile(project, toSubtaskIndex, taskDir);
task.setActiveSubtaskIndex(toSubtaskIndex);
updateUI(project, task, !CCUtils.isCourseCreator(project) && navigateToTask);
if (CCUtils.isCourseCreator(project)) {
updateOpenedTestFiles(project, taskDir, fromSubtaskIndex, toSubtaskIndex);
}
}
示例5: addDocumentListener
import com.intellij.openapi.editor.Document; //導入方法依賴的package包/類
public static void addDocumentListener(@NotNull final Document document, @NotNull final EduDocumentListener listener) {
document.addDocumentListener(listener);
myDocumentListeners.put(document, listener);
}