mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
create theme editor Toolbar and remove line marker provider
This commit is contained in:
@@ -267,11 +267,11 @@
|
||||
<fileEditorProvider implementation="org.jetbrains.idea.devkit.cachedValueProfiler.CVPFileEditorProvider"/>
|
||||
|
||||
<!-- themes -->
|
||||
<codeInsight.lineMarkerProvider language="JSON" implementationClass="org.jetbrains.idea.devkit.themes.ApplyThemeLineMarkerProvider"/>
|
||||
<completion.contributor implementationClass="org.jetbrains.idea.devkit.themes.ThemeJsonCompletionContributor" language="JSON"/>
|
||||
<spellchecker.support language="JSON"
|
||||
order="first"
|
||||
implementationClass="org.jetbrains.idea.devkit.themes.ThemeSpellcheckingStrategy"/>
|
||||
<editorNotificationProvider implementation="org.jetbrains.idea.devkit.themes.ThemeEditorToolbar"/>
|
||||
</extensions>
|
||||
<extensions defaultExtensionNs="JavaScript.JsonSchema">
|
||||
<ProviderFactory implementation="org.jetbrains.idea.devkit.themes.ThemeJsonSchemaProviderFactory"/>
|
||||
@@ -347,6 +347,11 @@
|
||||
<add-to-group group-id="FindMenuGroup" anchor="last"/>
|
||||
</action>
|
||||
|
||||
<!-- Theme Toolbar -->
|
||||
<group id="DevKit.ThemeEditorToolbar">
|
||||
<action class="org.jetbrains.idea.devkit.themes.ApplyThemeAction" id="DevKit.ApplyTheme" text="Apply Theme" icon="AllIcons.Actions.Execute"/>
|
||||
</group>
|
||||
|
||||
</actions>
|
||||
|
||||
</idea-plugin>
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.idea.devkit.themes;
|
||||
|
||||
import com.intellij.ide.ui.LafManager;
|
||||
import com.intellij.ide.ui.UITheme;
|
||||
import com.intellij.ide.ui.laf.UIThemeBasedLookAndFeelInfo;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.EditorNotificationPanel;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class ApplyThemeAction extends DumbAwareAction {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
if (project == null) return;
|
||||
VirtualFile file = fromMouseEvent(e);
|
||||
|
||||
if (file == null) {
|
||||
file = e.getData(CommonDataKeys.VIRTUAL_FILE);
|
||||
if (file == null || !UITheme.isThemeFile(file)) {
|
||||
for (FileEditor fileEditor : FileEditorManager.getInstance(project).getSelectedEditors()) {
|
||||
if (UITheme.isThemeFile(fileEditor.getFile())) {
|
||||
file = fileEditor.getFile();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (file != null && UITheme.isThemeFile(file)) {
|
||||
applyTempTheme(file);
|
||||
}
|
||||
}
|
||||
|
||||
private VirtualFile fromMouseEvent(AnActionEvent e) {
|
||||
if (e.getInputEvent() instanceof MouseEvent) {
|
||||
Component component = e.getInputEvent().getComponent();
|
||||
EditorNotificationPanel panel = UIUtil.getParentOfType(EditorNotificationPanel.class, component);
|
||||
if (panel != null) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void applyTempTheme(@NotNull VirtualFile json) {
|
||||
try {
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
UITheme theme = UITheme.loadFromJson(json.getInputStream(), "Temp theme", null);
|
||||
LafManager.getInstance().setCurrentLookAndFeel(new UIThemeBasedLookAndFeelInfo(theme));
|
||||
LafManager.getInstance().updateUI();
|
||||
}
|
||||
catch (IOException ignore) {}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.idea.devkit.themes;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
||||
import com.intellij.execution.lineMarker.RunLineMarkerProvider;
|
||||
import com.intellij.ide.ui.LafManager;
|
||||
import com.intellij.ide.ui.UITheme;
|
||||
import com.intellij.ide.ui.laf.UIThemeBasedLookAndFeelInfo;
|
||||
import com.intellij.json.psi.JsonProperty;
|
||||
import com.intellij.json.psi.JsonStringLiteral;
|
||||
import com.intellij.json.psi.JsonValue;
|
||||
import com.intellij.openapi.editor.markup.GutterIconRenderer;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class ApplyThemeLineMarkerProvider extends RunLineMarkerProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Apply theme";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement psiElement) {
|
||||
String name = psiElement.getContainingFile().getName();
|
||||
if (!name.endsWith(".theme.json")) {
|
||||
return null;
|
||||
}
|
||||
PsiElement element = psiElement.getParent();
|
||||
if (element instanceof JsonStringLiteral && element.getText().equals("\"name\"")) {
|
||||
return new LineMarkerInfo<>(psiElement, element.getTextRange(), getIcon(),
|
||||
|
||||
psi -> {
|
||||
PsiElement parent = psi.getParent().getParent();
|
||||
if (parent instanceof JsonProperty) {
|
||||
JsonValue value = ((JsonProperty)parent).getValue();
|
||||
if (value != null) {
|
||||
return "Apply '" + value.getText() + "' theme";
|
||||
}
|
||||
}
|
||||
return getName();
|
||||
},
|
||||
|
||||
(e, psi) -> applyTempTheme(psi.getContainingFile()),
|
||||
GutterIconRenderer.Alignment.RIGHT);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void applyTempTheme(@NotNull PsiFile json) {
|
||||
try {
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
UITheme theme = UITheme.loadFromJson(json.getVirtualFile().getInputStream(), "Temp theme", null);
|
||||
LafManager.getInstance().setCurrentLookAndFeel(new UIThemeBasedLookAndFeelInfo(theme));
|
||||
LafManager.getInstance().updateUI();
|
||||
}
|
||||
catch (IOException ignore) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.idea.devkit.themes;
|
||||
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataProvider;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.EditorNotificationPanel;
|
||||
import com.intellij.ui.EditorNotifications;
|
||||
import com.intellij.ui.JBColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class ThemeEditorToolbar extends EditorNotifications.Provider<EditorNotificationPanel> implements DumbAware {
|
||||
private static final Key<EditorNotificationPanel> KEY = Key.create("ThemeEditorToolbar");
|
||||
@NotNull
|
||||
@Override
|
||||
public Key<EditorNotificationPanel> getKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
|
||||
if (StringUtil.endsWithIgnoreCase(file.getName(), ".theme.json")) {
|
||||
EditorNotificationPanel panel = new EditorNotificationPanel(JBColor.PanelBackground);
|
||||
panel.removeAll();
|
||||
DefaultActionGroup group = (DefaultActionGroup)ActionManager.getInstance().getAction("DevKit.ThemeEditorToolbar");
|
||||
panel.add(ActionManager.getInstance().createActionToolbar("ThemeEditor", group, true).getComponent());
|
||||
DataManager.registerDataProvider(panel, new DataProvider() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getData(@NotNull String dataId) {
|
||||
if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
|
||||
return fileEditor.getFile();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return panel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user