From d9705da3670e83f99a0417046d2af10cbf7b536f Mon Sep 17 00:00:00 2001 From: Denis Zaichenko Date: Mon, 23 Dec 2024 18:32:56 +0100 Subject: [PATCH] [vcs] [RD] IJPL-160237 Get rid of vcs-api dependency on the frontend side. GitOrigin-RevId: 24d76803793805f2916fcbfab6d1b46707422bca --- .../intellij.platform.vcs.impl.frontend.iml | 1 - .../messages/VcsFrontendBundle.properties | 5 +++ .../vcs/impl/frontend/VcsFrontendBundle.kt | 20 ++++++++++ .../impl/frontend/VcsFrontendConfiguration.kt | 26 +++++++++++++ ...electChangesGroupingFrontendActionGroup.kt | 3 -- .../frontend/shelf/ShelfToolWindowPanel.kt | 10 ++--- .../shelf/tree/ChangesBrowserNode.java | 39 +++++++------------ .../tree/ChangesBrowserNodeRenderer.java | 17 -------- .../shelf/tree/ShelvedChangeListNode.kt | 4 +- .../frontend/shelf/tree/ShelvedChangeNode.kt | 4 +- 10 files changed, 73 insertions(+), 56 deletions(-) create mode 100644 platform/vcs-impl/frontend/resources/messages/VcsFrontendBundle.properties create mode 100644 platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/VcsFrontendBundle.kt create mode 100644 platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/VcsFrontendConfiguration.kt diff --git a/platform/vcs-impl/frontend/intellij.platform.vcs.impl.frontend.iml b/platform/vcs-impl/frontend/intellij.platform.vcs.impl.frontend.iml index b79654fe171a..355018e44dd3 100644 --- a/platform/vcs-impl/frontend/intellij.platform.vcs.impl.frontend.iml +++ b/platform/vcs-impl/frontend/intellij.platform.vcs.impl.frontend.iml @@ -36,7 +36,6 @@ - diff --git a/platform/vcs-impl/frontend/resources/messages/VcsFrontendBundle.properties b/platform/vcs-impl/frontend/resources/messages/VcsFrontendBundle.properties new file mode 100644 index 000000000000..a810662dc31e --- /dev/null +++ b/platform/vcs-impl/frontend/resources/messages/VcsFrontendBundle.properties @@ -0,0 +1,5 @@ +changes.nodetitle.empty.changelist.name= +shelve.default.path.rendering= +changes.nodetitle.changecount={0,choice, 0#No files|1#1 file|2#{0} files} +changes.nodetitle.directory.changecount={0,choice, 0#No directories|1#1 directory|2#{0} directories} +changes.nodetitle.directory.file.changecount={0,choice, 0#No directories|1#1 directory|2#{0} directories} and {1,choice, 0#no files|1#1 file|2#{1} files} \ No newline at end of file diff --git a/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/VcsFrontendBundle.kt b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/VcsFrontendBundle.kt new file mode 100644 index 000000000000..a43522e00dac --- /dev/null +++ b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/VcsFrontendBundle.kt @@ -0,0 +1,20 @@ +// 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. +package com.intellij.vcs.impl.frontend + +import com.intellij.DynamicBundle +import org.jetbrains.annotations.Nls +import org.jetbrains.annotations.NonNls +import org.jetbrains.annotations.PropertyKey + +internal object VcsFrontendBundle { + const val BUNDLE: @NonNls String = "messages.VcsFrontendBundle" + val INSTANCE: DynamicBundle = DynamicBundle(VcsFrontendBundle::class.java, BUNDLE) + + @JvmStatic + fun message( + key: @PropertyKey(resourceBundle = BUNDLE) String, + vararg params: Any, + ): @Nls String { + return INSTANCE.getMessage(key, *params) + } +} \ No newline at end of file diff --git a/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/VcsFrontendConfiguration.kt b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/VcsFrontendConfiguration.kt new file mode 100644 index 000000000000..c62eaf60820c --- /dev/null +++ b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/VcsFrontendConfiguration.kt @@ -0,0 +1,26 @@ +// 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.vcs.impl.frontend + +import com.intellij.openapi.components.* +import com.intellij.util.xmlb.XmlSerializerUtil +import org.jetbrains.annotations.ApiStatus + +@ApiStatus.Internal +@Service(Service.Level.PROJECT) +@State(name = "VcsFrontendConfiguration", storages = [Storage(StoragePathMacros.WORKSPACE_FILE)]) +class VcsFrontendConfiguration : PersistentStateComponent { + var shelveDetailsPreviewShown: Boolean = false + override fun getState(): VcsFrontendConfiguration { + return this + } + + override fun loadState(state: VcsFrontendConfiguration) { + XmlSerializerUtil.copyBean(state, this) + } + + companion object { + + @JvmStatic + fun getInstance(project: com.intellij.openapi.project.Project): VcsFrontendConfiguration = project.service() + } +} \ No newline at end of file diff --git a/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/changes/actions/SelectChangesGroupingFrontendActionGroup.kt b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/changes/actions/SelectChangesGroupingFrontendActionGroup.kt index 290674e7026c..6d8a51abdc36 100644 --- a/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/changes/actions/SelectChangesGroupingFrontendActionGroup.kt +++ b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/changes/actions/SelectChangesGroupingFrontendActionGroup.kt @@ -14,9 +14,6 @@ import com.intellij.vcs.impl.frontend.changes.ChangesTree import com.intellij.vcs.impl.shared.rhizome.RepositoryCountEntity import com.jetbrains.rhizomedb.entities import com.jetbrains.rhizomedb.entity -import fleet.kernel.rete.each -import fleet.kernel.rete.filter -import fleet.kernel.rete.first import org.jetbrains.annotations.ApiStatus @ApiStatus.Internal diff --git a/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/ShelfToolWindowPanel.kt b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/ShelfToolWindowPanel.kt index 5e30b7227d3f..66076ae2cf0d 100644 --- a/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/ShelfToolWindowPanel.kt +++ b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/ShelfToolWindowPanel.kt @@ -6,7 +6,6 @@ import com.intellij.openapi.application.EDT import com.intellij.openapi.project.Project import com.intellij.openapi.ui.SimpleToolWindowPanel import com.intellij.openapi.util.registry.Registry -import com.intellij.openapi.vcs.VcsConfiguration import com.intellij.openapi.vcs.changes.DiffPreview import com.intellij.openapi.wm.ToolWindowId import com.intellij.openapi.wm.ToolWindowManager @@ -16,6 +15,7 @@ import com.intellij.ui.ScrollPaneFactory import com.intellij.ui.components.panels.Wrapper import com.intellij.util.ui.JBUI import com.intellij.util.ui.components.BorderLayoutPanel +import com.intellij.vcs.impl.frontend.VcsFrontendConfiguration import com.intellij.vcs.impl.frontend.changes.EDITOR_TAB_DIFF_PREVIEW import com.intellij.vcs.impl.frontend.changes.actions.SHOW_DIFF_ACTION_ID import com.intellij.vcs.impl.frontend.navigation.FrontendNavigateToSourceAction @@ -40,7 +40,7 @@ class ShelfToolWindowPanel(private val project: Project, tree: ShelfTree, cs: Co private val diffEditorPreview = ShelfTreeEditorDiffPreview(tree, cs, project) private var splitterPreview: ShelveSplitterDiffPreview? = null - private val vcsConfiguration = VcsConfiguration.getInstance(project) + private val vcsConfiguration = VcsFrontendConfiguration.getInstance(project) init { mainPanelContent.setContent(shelvePanel) @@ -65,7 +65,7 @@ class ShelfToolWindowPanel(private val project: Project, tree: ShelfTree, cs: Co if (!isPanelVertical()) { cs.launch(Dispatchers.EDT) { splitterPreview = ShelveSplitterDiffPreview(splitterComponent) - DiffPreview.setPreviewVisible(splitterPreview!!, vcsConfiguration.SHELVE_DETAILS_PREVIEW_SHOWN) + DiffPreview.setPreviewVisible(splitterPreview!!, vcsConfiguration.shelveDetailsPreviewShown) } } } @@ -121,14 +121,14 @@ class ShelfToolWindowPanel(private val project: Project, tree: ShelfTree, cs: Co inner class TogglePreviewAction() : ToggleAction() { override fun isSelected(e: AnActionEvent): Boolean { - return vcsConfiguration.SHELVE_DETAILS_PREVIEW_SHOWN + return vcsConfiguration.shelveDetailsPreviewShown } override fun setSelected(e: AnActionEvent, state: Boolean) { val preview = splitterPreview if (preview != null) { DiffPreview.setPreviewVisible(preview, state) - vcsConfiguration.SHELVE_DETAILS_PREVIEW_SHOWN = state + vcsConfiguration.shelveDetailsPreviewShown = state } } diff --git a/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ChangesBrowserNode.java b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ChangesBrowserNode.java index ee7c11428bd0..fc8ba75d46f2 100644 --- a/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ChangesBrowserNode.java +++ b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ChangesBrowserNode.java @@ -1,39 +1,23 @@ // 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.vcs.impl.frontend.shelf.tree; -import com.intellij.diagnostic.PluginException; -import com.intellij.ide.util.treeView.FileNameComparator; -import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.util.UserDataHolderEx; -import com.intellij.openapi.vcs.FilePath; -import com.intellij.openapi.vcs.FileStatus; -import com.intellij.openapi.vcs.VcsBundle; -import com.intellij.openapi.vcs.changes.ChangesUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.newvfs.VfsPresentationUtil; import com.intellij.ui.ColoredTreeCellRenderer; -import com.intellij.ui.DirtyUI; -import com.intellij.ui.JBColor; import com.intellij.ui.SimpleTextAttributes; -import com.intellij.util.ObjectUtils; -import com.intellij.util.SlowOperations; -import com.intellij.util.containers.Convertor; import com.intellij.util.containers.JBIterable; import com.intellij.util.ui.tree.TreeUtil; -import com.intellij.vcsUtil.VcsUtil; -import org.jetbrains.annotations.*; +import com.intellij.vcs.impl.frontend.VcsFrontendBundle; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.MutableTreeNode; -import javax.swing.tree.TreePath; -import java.awt.*; -import java.util.List; -import java.util.Objects; import java.util.function.ToIntFunction; import static com.intellij.util.FontUtil.spaceAndThinSpace; @@ -145,7 +129,11 @@ public abstract class ChangesBrowserNode extends DefaultMutableTreeNode imple return (JBIterable>)iterable; } - public void render(@NotNull JTree tree, @NotNull ChangesBrowserNodeRenderer renderer, boolean selected, boolean expanded, boolean hasFocus) { + public void render(@NotNull JTree tree, + @NotNull ChangesBrowserNodeRenderer renderer, + boolean selected, + boolean expanded, + boolean hasFocus) { render(renderer, selected, expanded, hasFocus); } @@ -164,10 +152,10 @@ public abstract class ChangesBrowserNode extends DefaultMutableTreeNode imple if (dirCount != 0 || count != 0) { result = spaceAndThinSpace() + (dirCount == 0 - ? VcsBundle.message("changes.nodetitle.changecount", count) + ? VcsFrontendBundle.message("changes.nodetitle.changecount", count) : count == 0 - ? VcsBundle.message("changes.nodetitle.directory.changecount", dirCount) - : VcsBundle.message("changes.nodetitle.directory.file.changecount", dirCount, count)); + ? VcsFrontendBundle.message("changes.nodetitle.directory.changecount", dirCount) + : VcsFrontendBundle.message("changes.nodetitle.directory.file.changecount", dirCount, count)); } return result; @@ -205,5 +193,4 @@ public abstract class ChangesBrowserNode extends DefaultMutableTreeNode imple renderer.append(spaceAndThinSpace() + parentPath, SimpleTextAttributes.GRAYED_ATTRIBUTES); } } - } diff --git a/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ChangesBrowserNodeRenderer.java b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ChangesBrowserNodeRenderer.java index 9da72ebebca2..2548dfaece57 100644 --- a/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ChangesBrowserNodeRenderer.java +++ b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ChangesBrowserNodeRenderer.java @@ -4,16 +4,12 @@ package com.intellij.vcs.impl.frontend.shelf.tree; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.BooleanGetter; import com.intellij.openapi.util.NlsSafe; -import com.intellij.openapi.vcs.FilePath; -import com.intellij.openapi.vcs.changes.FilePathIconProvider; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.ColoredTreeCellRenderer; import com.intellij.ui.DirtyUI; import com.intellij.ui.SimpleTextAttributes; import com.intellij.ui.speedSearch.SpeedSearchUtil; -import com.intellij.util.PlatformIcons; import com.intellij.util.ui.JBInsets; -import com.intellij.vcsUtil.VcsUtil; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -94,19 +90,6 @@ public class ChangesBrowserNodeRenderer extends ColoredTreeCellRenderer { //} } - public void setIcon(@NotNull FilePath filePath, boolean isDirectory) { - if (isDirectory) { - setIcon(PlatformIcons.FOLDER_ICON); - return; - } - Icon icon = FilePathIconProvider.EP_NAME.computeSafeIfAny(provider -> provider.getIcon(filePath, myProject)); - if (icon != null) { - setIcon(icon); - return; - } - setIcon(VcsUtil.getIcon(myProject, filePath)); - } - public void setBackgroundInsets(@Nullable JBInsets backgroundInsets) { myBackgroundInsets = backgroundInsets; } diff --git a/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ShelvedChangeListNode.kt b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ShelvedChangeListNode.kt index aa5d98ddaa33..2b2fb37e605c 100644 --- a/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ShelvedChangeListNode.kt +++ b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ShelvedChangeListNode.kt @@ -1,10 +1,10 @@ // 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.vcs.impl.frontend.shelf.tree -import com.intellij.openapi.vcs.VcsBundle import com.intellij.ui.SimpleTextAttributes import com.intellij.util.FontUtil import com.intellij.util.text.DateFormatUtil +import com.intellij.vcs.impl.frontend.VcsFrontendBundle import com.intellij.vcs.impl.shared.rhizome.ShelvedChangeListEntity import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.Nls @@ -14,7 +14,7 @@ class ShelvedChangeListNode(private val changeList: ShelvedChangeListEntity) : E override fun render(renderer: ChangesBrowserNodeRenderer, selected: Boolean, expanded: Boolean, hasFocus: Boolean) { var listName = changeList.description - if (listName.isBlank()) listName = VcsBundle.message("changes.nodetitle.empty.changelist.name") + if (listName.isBlank()) listName = VcsFrontendBundle.message("changes.nodetitle.empty.changelist.name") if (changeList.isRecycled || changeList.isDeleted) { renderer.appendTextWithIssueLinks(listName, SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES) } diff --git a/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ShelvedChangeNode.kt b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ShelvedChangeNode.kt index 63244eab573a..2b4e0858a434 100644 --- a/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ShelvedChangeNode.kt +++ b/platform/vcs-impl/frontend/src/com/intellij/vcs/impl/frontend/shelf/tree/ShelvedChangeNode.kt @@ -5,10 +5,10 @@ import com.intellij.openapi.fileTypes.FileTypeManager import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.vcs.FileStatus -import com.intellij.openapi.vcs.VcsBundle import com.intellij.ui.SimpleTextAttributes import com.intellij.util.FontUtil import com.intellij.util.PathUtil +import com.intellij.vcs.impl.frontend.VcsFrontendBundle import com.intellij.vcs.impl.frontend.changes.findFileStatusById import com.intellij.vcs.impl.shared.rhizome.ShelvedChangeEntity import org.jetbrains.annotations.ApiStatus @@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nls class ShelvedChangeNode(val entity: ShelvedChangeEntity) : EntityChangesBrowserNode(entity) { override fun render(renderer: ChangesBrowserNodeRenderer, selected: Boolean, expanded: Boolean, hasFocus: Boolean) { val path = entity.filePath - val directory = StringUtil.defaultIfEmpty(PathUtil.getParentPath(path), VcsBundle.message("shelve.default.path.rendering")) + val directory = StringUtil.defaultIfEmpty(PathUtil.getParentPath(path), VcsFrontendBundle.message("shelve.default.path.rendering")) val fileName = StringUtil.defaultIfEmpty(PathUtil.getFileName(path), path) val fileStatus = findFileStatusById(entity.fileStatus) ?: FileStatus.MODIFIED renderer.append(fileName, SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, fileStatus.color))