mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
export to HTML: take read actions properly (IDEA-136348), remove unnecessary extension point and support method separators in all IDEs, not just in IDEA
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 25-Jan-2008
|
||||
*/
|
||||
package com.intellij.codeEditor.printing;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
||||
import com.intellij.codeInsight.daemon.impl.LineMarkersPass;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class MethodSeparatorProvider extends FileSeparatorProvider {
|
||||
@Override
|
||||
public List<LineMarkerInfo> getFileSeparators(final PsiFile file, final Document document, @Nullable final Editor editor) {
|
||||
final List<LineMarkerInfo> result = new ArrayList<LineMarkerInfo>();
|
||||
LineMarkersPass pass = new LineMarkersPass(file.getProject(), file, editor, document, file.getTextRange());
|
||||
for (LineMarkerInfo lineMarkerInfo : pass.queryLineMarkers()) {
|
||||
if (lineMarkerInfo.separatorColor != null) {
|
||||
result.add(lineMarkerInfo);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(result, new Comparator<LineMarkerInfo>() {
|
||||
public int compare(final LineMarkerInfo i1, final LineMarkerInfo i2) {
|
||||
return i1.startOffset - i2.startOffset;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import com.intellij.CommonBundle;
|
||||
import com.intellij.ide.BrowserUtil;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
@@ -130,32 +131,39 @@ class ExportToHTMLManager {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean exportPsiFile(final PsiFile psiFile, String outputDirectoryName, Project project, HashMap<PsiFile, PsiFile> filesMap) {
|
||||
ExportToHTMLSettings exportToHTMLSettings = ExportToHTMLSettings.getInstance(project);
|
||||
private static boolean exportPsiFile(final PsiFile psiFile,
|
||||
final String outputDirectoryName,
|
||||
final Project project,
|
||||
final HashMap<PsiFile, PsiFile> filesMap) {
|
||||
final ExportToHTMLSettings exportToHTMLSettings = ExportToHTMLSettings.getInstance(project);
|
||||
|
||||
if (psiFile instanceof PsiBinaryFile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
TreeMap<Integer, PsiReference> refMap = null;
|
||||
for (PrintOption printOption : Extensions.getExtensions(PrintOption.EP_NAME)) {
|
||||
final TreeMap<Integer, PsiReference> map = printOption.collectReferences(psiFile, filesMap);
|
||||
if (map != null) {
|
||||
refMap = new TreeMap<Integer, PsiReference>();
|
||||
refMap.putAll(map);
|
||||
}
|
||||
}
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TreeMap<Integer, PsiReference> refMap = null;
|
||||
for (PrintOption printOption : Extensions.getExtensions(PrintOption.EP_NAME)) {
|
||||
final TreeMap<Integer, PsiReference> map = printOption.collectReferences(psiFile, filesMap);
|
||||
if (map != null) {
|
||||
refMap = new TreeMap<Integer, PsiReference>();
|
||||
refMap.putAll(map);
|
||||
}
|
||||
}
|
||||
|
||||
String dirName = constructOutputDirectory(psiFile, outputDirectoryName);
|
||||
HTMLTextPainter textPainter = new HTMLTextPainter(psiFile, project, dirName, exportToHTMLSettings.PRINT_LINE_NUMBERS);
|
||||
try {
|
||||
textPainter.paint(refMap, psiFile.getFileType());
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
myLastException = e;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
String dirName = constructOutputDirectory(psiFile, outputDirectoryName);
|
||||
HTMLTextPainter textPainter = new HTMLTextPainter(psiFile, project, dirName, exportToHTMLSettings.PRINT_LINE_NUMBERS);
|
||||
try {
|
||||
textPainter.paint(refMap, psiFile.getFileType());
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
myLastException = e;
|
||||
}
|
||||
}
|
||||
});
|
||||
return myLastException == null;
|
||||
}
|
||||
|
||||
private static String constructOutputDirectory(PsiFile psiFile, String outputDirectoryName) {
|
||||
@@ -241,11 +249,18 @@ class ExportToHTMLManager {
|
||||
final ArrayList<PsiFile> filesList = new ArrayList<PsiFile>();
|
||||
final boolean isRecursive = myExportToHTMLSettings.isIncludeSubdirectories();
|
||||
|
||||
try {
|
||||
addToPsiFileList(myPsiDirectory, filesList, isRecursive, myOutputDirectoryName);
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
myLastException = e;
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
addToPsiFileList(myPsiDirectory, filesList, isRecursive, myOutputDirectoryName);
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
myLastException = e;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (myLastException != null) {
|
||||
return;
|
||||
}
|
||||
HashMap<PsiFile, PsiFile> filesMap = new HashMap<PsiFile, PsiFile>();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,21 +21,32 @@
|
||||
package com.intellij.codeEditor.printing;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.codeInsight.daemon.impl.LineMarkersPass;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class FileSeparatorProvider {
|
||||
public static FileSeparatorProvider getInstance() {
|
||||
return ServiceManager.getService(FileSeparatorProvider.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<LineMarkerInfo> getFileSeparators(PsiFile file, final Document document, @Nullable final Editor editor) {
|
||||
return null;
|
||||
public static List<LineMarkerInfo> getFileSeparators(PsiFile file, final Document document) {
|
||||
final List<LineMarkerInfo> result = new ArrayList<LineMarkerInfo>();
|
||||
LineMarkersPass pass = new LineMarkersPass(file.getProject(), file, null, document, file.getTextRange());
|
||||
for (LineMarkerInfo lineMarkerInfo : pass.queryLineMarkers()) {
|
||||
if (lineMarkerInfo.separatorColor != null) {
|
||||
result.add(lineMarkerInfo);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(result, new Comparator<LineMarkerInfo>() {
|
||||
public int compare(final LineMarkerInfo i1, final LineMarkerInfo i2) {
|
||||
return i1.startOffset - i2.startOffset;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,7 +35,6 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.impl.file.PsiDirectoryFactory;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.ui.JBColor;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
@@ -86,8 +85,7 @@ class HTMLTextPainter {
|
||||
|
||||
ArrayList<LineMarkerInfo> methodSeparators = new ArrayList<LineMarkerInfo>();
|
||||
if (document != null) {
|
||||
final List<LineMarkerInfo> separators = FileSeparatorProvider.getInstance().getFileSeparators(psiFile, document,
|
||||
PsiUtilBase.findEditor(psiFile));
|
||||
final List<LineMarkerInfo> separators = FileSeparatorProvider.getFileSeparators(psiFile, document);
|
||||
if (separators != null) {
|
||||
methodSeparators.addAll(separators);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -100,7 +100,7 @@ class TextPainter extends BasePainter {
|
||||
FileType fileType,
|
||||
Editor editor) {
|
||||
this(editorDocument, highlighter, fullFileName, shortFileName, psiFile.getProject(), fileType,
|
||||
FileSeparatorProvider.getInstance().getFileSeparators(psiFile, editorDocument, editor));
|
||||
FileSeparatorProvider.getFileSeparators(psiFile, editorDocument));
|
||||
}
|
||||
|
||||
public TextPainter(@NotNull DocumentEx editorDocument,
|
||||
|
||||
@@ -109,7 +109,7 @@ public class LineMarkersPass extends TextEditorHighlightingPass implements LineM
|
||||
myMarkers = mergeLineMarkers(lineMarkers, myEditor);
|
||||
}
|
||||
|
||||
static List<LineMarkerInfo> mergeLineMarkers(@NotNull List<LineMarkerInfo> markers, Editor editor) {
|
||||
static List<LineMarkerInfo> mergeLineMarkers(@NotNull List<LineMarkerInfo> markers, @Nullable Editor editor) {
|
||||
List<MergeableLineMarkerInfo> forMerge = new ArrayList<MergeableLineMarkerInfo>();
|
||||
final Iterator<LineMarkerInfo> iterator = markers.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
@@ -71,8 +71,6 @@
|
||||
|
||||
<refactoring.copyHandler implementation="com.intellij.refactoring.copy.CopyFilesOrDirectoriesHandler"/>
|
||||
<refactoring.moveHandler implementation="com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesHandler" id="moveFileOrDir"/>
|
||||
<applicationService serviceInterface="com.intellij.codeEditor.printing.FileSeparatorProvider"
|
||||
serviceImplementation="com.intellij.codeEditor.printing.FileSeparatorProvider"/>
|
||||
|
||||
<treeStructureProvider implementation="com.intellij.platform.PlatformProjectViewStructureProvider"/>
|
||||
|
||||
|
||||
@@ -1341,8 +1341,6 @@
|
||||
<macro implementation="com.intellij.ide.macro.OutputPathMacro"/>
|
||||
|
||||
<printOption implementation="com.intellij.codeEditor.printing.HyperlinksToClassesOption"/>
|
||||
<applicationService serviceInterface="com.intellij.codeEditor.printing.FileSeparatorProvider"
|
||||
serviceImplementation="com.intellij.codeEditor.printing.MethodSeparatorProvider"/>
|
||||
|
||||
<indexPatternBuilder implementation="com.intellij.psi.impl.search.JavaIndexPatternBuilder"/>
|
||||
<indexPatternBuilder implementation="com.intellij.psi.impl.search.JspIndexPatternBuilder"/>
|
||||
|
||||
Reference in New Issue
Block a user