mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
IJPL-156885 refactor WebPreviewFileEditor
GitOrigin-RevId: f978ce3c2ae1468d9d7a5b4bc28fa16b0c98b27f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7df314f081
commit
c40285b58d
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 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.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.builtInWebServer.liveReload
|
||||
|
||||
import com.google.common.net.HttpHeaders
|
||||
@@ -199,7 +199,7 @@ class WebServerPageConnectionService {
|
||||
|
||||
private fun showGotItTooltip(modifiedFiles: List<VirtualFile>) {
|
||||
val gotItTooltip = GotItTooltip(SERVER_RELOAD_TOOLTIP_ID, BuiltInServerBundle.message("reload.on.save.got.it.content"), myServer!!)
|
||||
if (!gotItTooltip.canShow() || WebPreviewFileEditor.isPreviewOpened()) return
|
||||
if (!gotItTooltip.canShow() || WebPreviewFileEditor.isPreviewOpened) return
|
||||
|
||||
if (WebBrowserManager.BROWSER_RELOAD_MODE_DEFAULT !== ReloadMode.RELOAD_ON_SAVE) {
|
||||
Logger.getInstance(WebServerPageConnectionService::class.java).error(
|
||||
|
||||
@@ -6009,22 +6009,6 @@ f:com.intellij.ide.browsers.actions.OpenInBrowserBaseGroupAction$OpenInBrowserEd
|
||||
f:com.intellij.ide.browsers.actions.OpenInBrowserBaseGroupAction$OpenInBrowserGroupAction
|
||||
- com.intellij.ide.browsers.actions.OpenInBrowserBaseGroupAction
|
||||
- <init>():V
|
||||
f:com.intellij.ide.browsers.actions.WebPreviewFileEditor
|
||||
- com.intellij.openapi.util.UserDataHolderBase
|
||||
- com.intellij.openapi.fileEditor.FileEditor
|
||||
- sf:WEB_PREVIEW_RELOAD_TOOLTIP_ID:java.lang.String
|
||||
- <init>(com.intellij.openapi.project.Project,com.intellij.ide.browsers.actions.WebPreviewVirtualFile):V
|
||||
- addPropertyChangeListener(java.beans.PropertyChangeListener):V
|
||||
- dispose():V
|
||||
- getComponent():javax.swing.JComponent
|
||||
- getFile():com.intellij.openapi.vfs.VirtualFile
|
||||
- getName():java.lang.String
|
||||
- getPreferredFocusedComponent():javax.swing.JComponent
|
||||
- isModified():Z
|
||||
- s:isPreviewOpened():Z
|
||||
- isValid():Z
|
||||
- removePropertyChangeListener(java.beans.PropertyChangeListener):V
|
||||
- setState(com.intellij.openapi.fileEditor.FileEditorState):V
|
||||
f:com.intellij.ide.browsers.actions.WebPreviewFileType
|
||||
- com.intellij.openapi.fileTypes.ex.FakeFileType
|
||||
- sf:INSTANCE:com.intellij.ide.browsers.actions.WebPreviewFileType
|
||||
|
||||
@@ -1,147 +1,119 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.ide.browsers.actions;
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.ide.browsers.actions
|
||||
|
||||
import com.intellij.CommonBundle;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.browsers.ReloadMode;
|
||||
import com.intellij.ide.browsers.WebBrowserManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorState;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.Balloon;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.GotItTooltip;
|
||||
import com.intellij.ui.jcef.*;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.ide.BuiltInServerBundle;
|
||||
import com.intellij.CommonBundle
|
||||
import com.intellij.ide.IdeBundle
|
||||
import com.intellij.ide.browsers.ReloadMode
|
||||
import com.intellij.ide.browsers.WebBrowserManager
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||
import com.intellij.openapi.fileEditor.FileEditor
|
||||
import com.intellij.openapi.fileEditor.FileEditorState
|
||||
import com.intellij.openapi.options.Configurable
|
||||
import com.intellij.openapi.options.SearchableConfigurable
|
||||
import com.intellij.openapi.options.ShowSettingsUtil
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.popup.Balloon
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.UserDataHolderBase
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.ui.GotItTooltip
|
||||
import com.intellij.ui.jcef.JCEFHtmlPanel
|
||||
import org.jetbrains.annotations.ApiStatus.Internal
|
||||
import org.jetbrains.annotations.Nls
|
||||
import org.jetbrains.ide.BuiltInServerBundle
|
||||
import java.awt.Color
|
||||
import java.awt.Point
|
||||
import java.beans.PropertyChangeListener
|
||||
import javax.swing.JComponent
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.beans.PropertyChangeListener;
|
||||
private const val WEB_PREVIEW_RELOAD_TOOLTIP_ID: String = "web.preview.reload.on.save"
|
||||
|
||||
@Internal
|
||||
class WebPreviewFileEditor(project: Project, file: WebPreviewVirtualFile) : UserDataHolderBase(), FileEditor {
|
||||
private val file = file.originalFile
|
||||
private val panel: JCEFHtmlPanel
|
||||
private val url = file.previewUrl.toExternalForm()
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public final class WebPreviewFileEditor extends UserDataHolderBase implements FileEditor {
|
||||
public static final String WEB_PREVIEW_RELOAD_TOOLTIP_ID = "web.preview.reload.on.save";
|
||||
private final VirtualFile myFile;
|
||||
private final JCEFHtmlPanel myPanel;
|
||||
private final String myUrl;
|
||||
private static int previewsOpened = 0;
|
||||
init {
|
||||
panel = object : JCEFHtmlPanel(url) {
|
||||
override fun getBackgroundColor(): Color = Color.WHITE
|
||||
}
|
||||
reloadPage()
|
||||
previewsOpened++
|
||||
showPreviewTooltip()
|
||||
}
|
||||
|
||||
public WebPreviewFileEditor(@NotNull Project project, @NotNull WebPreviewVirtualFile file) {
|
||||
myFile = file.getOriginalFile();
|
||||
myUrl = file.getPreviewUrl().toExternalForm();
|
||||
myPanel = new JCEFHtmlPanel(myUrl) {
|
||||
@Override
|
||||
protected @NotNull Color getBackgroundColor() {
|
||||
//noinspection UseJBColor
|
||||
return Color.WHITE;
|
||||
companion object {
|
||||
private var previewsOpened = 0
|
||||
|
||||
val isPreviewOpened: Boolean
|
||||
get() = previewsOpened > 0
|
||||
}
|
||||
|
||||
private fun reloadPage() {
|
||||
FileDocumentManager.getInstance().saveAllDocuments()
|
||||
ApplicationManager.getApplication().saveAll()
|
||||
panel.loadURL(url)
|
||||
}
|
||||
|
||||
private fun showPreviewTooltip() {
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
val gotItTooltip = GotItTooltip(WEB_PREVIEW_RELOAD_TOOLTIP_ID, BuiltInServerBundle.message("reload.on.save.preview.got.it.content"),
|
||||
this)
|
||||
if (!gotItTooltip.canShow()) {
|
||||
return@invokeLater
|
||||
}
|
||||
};
|
||||
reloadPage();
|
||||
previewsOpened++;
|
||||
showPreviewTooltip();
|
||||
}
|
||||
|
||||
private void reloadPage() {
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
ApplicationManager.getApplication().saveAll();
|
||||
myPanel.loadURL(myUrl);
|
||||
}
|
||||
|
||||
private void showPreviewTooltip() {
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
GotItTooltip gotItTooltip = new GotItTooltip(WEB_PREVIEW_RELOAD_TOOLTIP_ID, BuiltInServerBundle.message("reload.on.save.preview.got.it.content"), this);
|
||||
if (!gotItTooltip.canShow()) return;
|
||||
|
||||
if (WebBrowserManager.PREVIEW_RELOAD_MODE_DEFAULT != ReloadMode.RELOAD_ON_SAVE) {
|
||||
Logger.getInstance(WebPreviewFileEditor.class).error(
|
||||
"Default value for " + BuiltInServerBundle.message("reload.on.save.preview.got.it.title") + " has changed, tooltip is outdated.");
|
||||
return;
|
||||
logger<WebPreviewFileEditor>().error(
|
||||
"Default value for " + BuiltInServerBundle.message("reload.on.save.preview.got.it.title") + " has changed, tooltip is outdated.")
|
||||
return@invokeLater
|
||||
}
|
||||
if (WebBrowserManager.getInstance().getWebPreviewReloadMode() != ReloadMode.RELOAD_ON_SAVE) {
|
||||
if (WebBrowserManager.getInstance().webPreviewReloadMode != ReloadMode.RELOAD_ON_SAVE) {
|
||||
// changed before gotIt was shown
|
||||
return;
|
||||
return@invokeLater
|
||||
}
|
||||
|
||||
gotItTooltip
|
||||
.withHeader(BuiltInServerBundle.message("reload.on.save.preview.got.it.title"))
|
||||
.withPosition(Balloon.Position.above)
|
||||
.withLink(CommonBundle.message("action.text.configure.ellipsis"), () -> {
|
||||
ShowSettingsUtil.getInstance().showSettingsDialog( null, (it) ->
|
||||
it instanceof SearchableConfigurable &&
|
||||
((SearchableConfigurable)it).getId().equals("reference.settings.ide.settings.web.browsers"),
|
||||
null);
|
||||
});
|
||||
|
||||
|
||||
gotItTooltip.show(myPanel.getComponent(), (c, b) -> new Point(0, 0) );
|
||||
});
|
||||
.withLink(CommonBundle.message("action.text.configure.ellipsis"), Runnable {
|
||||
ShowSettingsUtil.getInstance().showSettingsDialog(null, { it: Configurable? ->
|
||||
it is SearchableConfigurable &&
|
||||
it.id == "reference.settings.ide.settings.web.browsers"
|
||||
}, null)
|
||||
})
|
||||
gotItTooltip.show(panel.component) { _, _ -> Point(0, 0) }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull JComponent getComponent() {
|
||||
return myPanel.getComponent();
|
||||
override fun getComponent(): JComponent = panel.component
|
||||
|
||||
override fun getPreferredFocusedComponent() = panel.component
|
||||
|
||||
override fun getName(): @Nls(capitalization = Nls.Capitalization.Title) String {
|
||||
return IdeBundle.message("web.preview.file.editor.name", file.name)
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable JComponent getPreferredFocusedComponent() {
|
||||
return myPanel.getComponent();
|
||||
override fun setState(state: FileEditorState) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nls(capitalization = Nls.Capitalization.Title) @NotNull String getName() {
|
||||
return IdeBundle.message("web.preview.file.editor.name", myFile.getName());
|
||||
override fun getFile(): VirtualFile = file
|
||||
|
||||
override fun isModified(): Boolean = false
|
||||
|
||||
override fun isValid(): Boolean = true
|
||||
|
||||
override fun addPropertyChangeListener(listener: PropertyChangeListener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(@NotNull FileEditorState state) {
|
||||
|
||||
override fun removePropertyChangeListener(listener: PropertyChangeListener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull VirtualFile getFile() {
|
||||
return myFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyChangeListener(@NotNull PropertyChangeListener listener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePropertyChangeListener(@NotNull PropertyChangeListener listener) {
|
||||
|
||||
}
|
||||
|
||||
public static boolean isPreviewOpened() {
|
||||
return previewsOpened > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
previewsOpened--;
|
||||
Disposer.dispose(myPanel);
|
||||
override fun dispose() {
|
||||
previewsOpened--
|
||||
Disposer.dispose(panel)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user