Skip to content

Commit 804e093

Browse files
authored
Merge pull request #198 from ZenUml/upgrade-intellij
Upgrade intellij platform and fix deprecated APIs
2 parents ef59cca + 789390d commit 804e093

File tree

10 files changed

+50
-214
lines changed

10 files changed

+50
-214
lines changed

build.gradle

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
plugins {
22
id 'java'
33
id 'idea'
4-
id 'org.jetbrains.intellij' version '1.1.4'
5-
id 'org.jetbrains.kotlin.jvm' version '1.4.21'
4+
id 'org.jetbrains.intellij' version '1.4.0'
5+
id 'org.jetbrains.kotlin.jvm' version '1.6.10'
66
id "com.github.node-gradle.node" version "3.2.1"
77
}
88
buildSearchableOptions.enabled = false
@@ -15,12 +15,12 @@ dependencies {
1515
// https://mvnrepository.com/artifact/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer
1616
compile group: 'com.googlecode.owasp-java-html-sanitizer', name: 'owasp-java-html-sanitizer'
1717
// compile "org.jetbrains:markdown:${markdownParserVersion}"
18-
compile 'org.jetbrains.kotlin:kotlin-reflect:1.5.31'
19-
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.5.31'
18+
compile 'org.jetbrains.kotlin:kotlin-reflect:1.6.10'
19+
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.6.10'
2020
compile 'io.reactivex.rxjava2:rxjava:2.2.21'
2121

2222
testCompile group: 'junit', name: 'junit', version: '4.12'
23-
testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31'
23+
testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10'
2424
}
2525

2626
compileKotlin {
@@ -52,7 +52,8 @@ sourceSets {
5252
}
5353

5454
intellij {
55-
version = 'IC-2021.2.3'
55+
// version = 'IC-2021.2.3'
56+
version = 'IC-LATEST-EAP-SNAPSHOT'
5657
pluginName = 'zenuml'
5758
downloadSources = false
5859
updateSinceUntilBuild = false

src/com/intellij/ide/scratch/NewZenUmlBufferAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.intellij.ide.scratch;
22

33
import com.intellij.lang.Language;
4-
import com.intellij.lang.StdLanguages;
54
import com.intellij.openapi.actionSystem.AnActionEvent;
5+
import com.intellij.openapi.fileTypes.PlainTextLanguage;
66
import com.intellij.openapi.project.DumbAwareAction;
77
import com.intellij.openapi.project.Project;
88
import com.intellij.openapi.util.registry.Registry;
@@ -70,6 +70,6 @@ public void actionPerformed(@NotNull AnActionEvent e) {
7070

7171
private Language getLanguage() {
7272
Language zenUML = Language.findLanguageByID("ZenUML");
73-
return zenUML != null ? zenUML : StdLanguages.TEXT;
73+
return zenUML != null ? zenUML : PlainTextLanguage.INSTANCE;
7474
}
7575
}

src/org/intellij/plugins/markdown/injection/LanguageGuesser.java

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/org/intellij/plugins/markdown/settings/ZenUmlApplicationSettings.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.intellij.plugins.markdown.settings;
22

3-
import com.intellij.ide.ui.LafManager;
3+
import com.intellij.ide.ui.LafManagerListener;
4+
import com.intellij.openapi.Disposable;
45
import com.intellij.openapi.application.ApplicationManager;
56
import com.intellij.openapi.components.PersistentStateComponent;
67
import com.intellij.openapi.components.ServiceManager;
@@ -23,13 +24,15 @@
2324
)
2425
public class ZenUmlApplicationSettings implements PersistentStateComponent<ZenUmlApplicationSettings.State>,
2526
MarkdownCssSettings.Holder,
26-
MarkdownPreviewSettings.Holder {
27+
MarkdownPreviewSettings.Holder, Disposable {
2728

2829
private final State myState = new State();
2930

3031
public ZenUmlApplicationSettings() {
3132
final MarkdownLAFListener lafListener = new MarkdownLAFListener();
32-
LafManager.getInstance().addLafManagerListener(lafListener);
33+
ApplicationManager
34+
.getApplication().getMessageBus().connect(this)
35+
.subscribe(LafManagerListener.TOPIC, lafListener);
3336
// Let's init proper CSS scheme
3437
ApplicationManager.getApplication().invokeLater(() -> lafListener.updateCssSettingsForced(UIUtil.isUnderDarcula()));
3538
}
@@ -90,6 +93,10 @@ public boolean isDisableInjections() {
9093
return myState.myDisableInjections;
9194
}
9295

96+
@Override
97+
public void dispose() {
98+
}
99+
93100

94101
public static class State {
95102
@Property(surroundWithTag = false)

src/org/intellij/plugins/markdown/ui/preview/MarkdownPreviewFileEditor.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ public class MarkdownPreviewFileEditor extends UserDataHolderBase implements Fil
4545

4646
private final static long RENDERING_DELAY_MS = 20L;
4747

48-
final static NotNullLazyValue<PolicyFactory> SANITIZER_VALUE = new NotNullLazyValue<PolicyFactory>() {
49-
@NotNull
50-
@Override
51-
protected PolicyFactory compute() {
48+
final static NotNullLazyValue<PolicyFactory> SANITIZER_VALUE = NotNullLazyValue.lazy(() -> {
5249
return Sanitizers.BLOCKS
5350
.and(Sanitizers.FORMATTING)
5451
.and(new HtmlPolicyBuilder()
@@ -74,8 +71,8 @@ protected PolicyFactory compute() {
7471
.allowAttributes(HtmlGenerator.Companion.getSRC_ATTRIBUTE_NAME()).globally()
7572
.allowAttributes("class").onElements("code", "tr", "span")
7673
.toFactory());
77-
}
78-
};
74+
});
75+
7976
@NotNull
8077
private final JPanel myHtmlPanelWrapper;
8178
@Nullable

src/org/intellij/plugins/markdown/ui/preview/MarkdownPreviewFileEditorProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.intellij.plugins.markdown.ui.preview;
22

3-
import com.intellij.ide.scratch.ScratchFileType;
3+
import com.intellij.ide.scratch.ScratchUtil;
44
import com.intellij.lang.LanguageUtil;
55
import com.intellij.openapi.fileEditor.FileEditor;
66
import com.intellij.openapi.fileEditor.FileEditorPolicy;
@@ -18,7 +18,7 @@ public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
1818
final FileType fileType = file.getFileType();
1919

2020
return (fileType == ZenUmlFileType.INSTANCE ||
21-
fileType == ScratchFileType.INSTANCE && LanguageUtil.getLanguageForPsi(project, file) == ZenUmlLanguage.INSTANCE) &&
21+
ScratchUtil.isScratch(file) && LanguageUtil.getLanguageForPsi(project, file) == ZenUmlLanguage.INSTANCE) &&
2222
MarkdownHtmlPanelProvider.hasAvailableProviders();
2323
}
2424

src/org/intellij/plugins/markdown/ui/preview/MarkdownSplitEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void navigateTo(@NotNull Navigatable navigatable) {
6969
@Override
7070
@NotNull
7171
public VirtualFile getFile() {
72-
return FILE_KEY.get(this);
72+
return getMainEditor().getFile();
7373
}
7474

7575
public boolean isAutoScrollPreview() {

src/org/intellij/plugins/markdown/ui/preview/javafx/JavaFXInstallator.java

Lines changed: 0 additions & 86 deletions
This file was deleted.

src/org/intellij/plugins/markdown/ui/preview/javafx/MarkdownJavaFxHtmlPanel.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.zenuml.sequence.plugins.jetbrains.html.ZenUmlHtmlGenerator;
77
import org.apache.commons.io.FileUtils;
88
import org.intellij.plugins.markdown.html.AddProtocolAndHost;
9+
import org.intellij.plugins.markdown.settings.ZenUmlApplicationSettings;
910
import org.intellij.plugins.markdown.ui.preview.MarkdownHtmlPanel;
1011
import org.intellij.plugins.markdown.ui.preview.PreviewStaticServer2;
1112
import org.jetbrains.annotations.NotNull;
@@ -24,15 +25,19 @@ public class MarkdownJavaFxHtmlPanel extends JCEFHtmlPanel implements MarkdownHt
2425

2526
public MarkdownJavaFxHtmlPanel() {
2627
super(null);
27-
InputStream inputStream = this.getClass().getResourceAsStream("/html/zenuml/index.html");
28+
29+
String resource = "/html/zenuml/index.html";
30+
InputStream inputStream = this.getClass().getResourceAsStream(resource);
31+
if (inputStream == null) {
32+
throw new IllegalStateException(String.format("Resource %s not found", resource));
33+
}
34+
2835
setHtml(readFromInputStream(inputStream));
2936
}
3037

31-
private String readFromInputStream(InputStream inputStream)
32-
{
38+
private String readFromInputStream(InputStream inputStream) {
3339
StringBuilder resultStringBuilder = new StringBuilder();
34-
try (BufferedReader br
35-
= new BufferedReader(new InputStreamReader(inputStream))) {
40+
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
3641
String line;
3742
while ((line = br.readLine()) != null) {
3843
resultStringBuilder.append(line).append("\n");

src/org/intellij/sequencer/SequencePlugin2.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ public SequencePlugin2(Project project) {
6262

6363
public void projectOpened() {
6464
createTabPane();
65-
_toolWindow = getToolWindowManager().registerToolWindow(
66-
PLAGIN_NAME, false, ToolWindowAnchor.BOTTOM);
67-
final Content content = ServiceManager.getService(ContentFactory.class).createContent(_jTabbedPane, "", false);
68-
_toolWindow.getContentManager().addContent(content);
69-
_toolWindow.setIcon(SequencePluginIcons.SEQUENCE_ICON_13);
70-
_toolWindow.setAvailable(false, null);
65+
getToolWindowManager().invokeLater(() -> {
66+
_toolWindow = getToolWindowManager().registerToolWindow(
67+
PLAGIN_NAME, false, ToolWindowAnchor.BOTTOM);
68+
69+
final Content content = ServiceManager.getService(ContentFactory.class).createContent(_jTabbedPane, "", false);
70+
_toolWindow.getContentManager().addContent(content);
71+
_toolWindow.setIcon(SequencePluginIcons.SEQUENCE_ICON_13);
72+
_toolWindow.setAvailable(false, null);
73+
});
7174
}
7275

7376
private ToolWindowManager getToolWindowManager() {
@@ -136,14 +139,15 @@ private String generateZenUML(PsiMethod psiMethod) {
136139
private void createZenUMLScratch(String dsl, AnActionEvent event) {
137140
NewZenUmlBufferAction newBufferAction = new NewZenUmlBufferAction();
138141

139-
HashMap<String, Object> map = new HashMap<>();
140-
map.put(CommonDataKeys.PROJECT.getName(), event.getData(CommonDataKeys.PROJECT));
141-
map.put(LangDataKeys.IDE_VIEW.getName(), event.getData(LangDataKeys.IDE_VIEW));
142-
map.put(PlatformDataKeys.PREDEFINED_TEXT.getName(), dsl);
142+
DataContext context = SimpleDataContext.builder()
143+
.add(CommonDataKeys.PROJECT, event.getData(CommonDataKeys.PROJECT))
144+
.add(LangDataKeys.IDE_VIEW, event.getData(LangDataKeys.IDE_VIEW))
145+
.add(PlatformDataKeys.PREDEFINED_TEXT, dsl)
146+
.build();
143147
AnActionEvent anActionEvent = AnActionEvent.createFromAnAction(newBufferAction,
144148
null,
145149
event.getPlace(),
146-
SimpleDataContext.getSimpleContext(map, null));
150+
context);
147151
newBufferAction.actionPerformed(anActionEvent);
148152
}
149153

0 commit comments

Comments
 (0)