mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactoring [git]: Switched to GitRepository from GitRepositoryModel in GitWorkingTrees APIs for IJPL-204771 IJ-MR-185641
GitOrigin-RevId: 35d9b54f7ed38964977c2cf3bae428689e845e0b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
66f4aad23f
commit
a547d21d56
+5
-5
@@ -1,16 +1,16 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package git4idea.actions.workingTree
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataKey
|
||||
import com.intellij.platform.vcs.impl.shared.RepositoryId
|
||||
import git4idea.GitWorkingTree
|
||||
import git4idea.repo.GitRepository
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
|
||||
@ApiStatus.Internal
|
||||
object GitWorkingTreeActionsDataKeys {
|
||||
object GitWorkingTreeTabActionsDataKeys {
|
||||
@JvmField
|
||||
val SELECTED_WORKING_TREES: DataKey<List<GitWorkingTree>> = DataKey.create("SELECTED_GIT_WORKING_TREE")
|
||||
val SELECTED_WORKING_TREES: DataKey<List<GitWorkingTree>> = DataKey.create("SELECTED_GIT_WORKING_TREE_IN_WORKING_TREE_TAB")
|
||||
@JvmField
|
||||
val GIT_REPOSITORY_MODEL_ID: DataKey<RepositoryId> = DataKey.create("GIT_REPOSITORY_MODEL_ID")
|
||||
val CURRENT_REPOSITORY: DataKey<GitRepository> = DataKey.create("CURRENT_REPOSITORY_IN_WORKING_TREE_TAB")
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package git4idea.workingTrees
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.project.BaseProjectDirectories.Companion.getBaseDirectories
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.platform.vcs.impl.shared.RepositoryId
|
||||
import com.intellij.vcs.git.repo.GitRepositoriesHolder
|
||||
import com.intellij.vcs.git.repo.GitRepositoryModel
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import git4idea.repo.GitRepository
|
||||
import git4idea.repo.GitRepositoryManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
||||
@@ -23,30 +22,22 @@ internal class GitWorkingTreesService(private val project: Project, val coroutin
|
||||
/**
|
||||
* So far only the case `single repository in project root` is supported for working trees
|
||||
*/
|
||||
fun getSingleRepositoryInProjectRootOrNull(): GitRepositoryModel? {
|
||||
val baseDirectories = project.getBaseDirectories()
|
||||
if (baseDirectories.size != 1) {
|
||||
fun getSingleRepositoryInProjectRootOrNull(): GitRepository? {
|
||||
val projectRoot = getOnlyProjectRootOrNull()
|
||||
if (projectRoot == null) {
|
||||
return null
|
||||
}
|
||||
val projectRoot = baseDirectories.first()
|
||||
val holder = GitRepositoriesHolder.getInstance(project)
|
||||
if (!holder.initialized) {
|
||||
return null
|
||||
}
|
||||
val repositoryModels = holder.getAll()
|
||||
if (repositoryModels.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
if (repositoryModels.size > 1) {
|
||||
val repositories = GitRepositoryManager.getInstance(project).repositories
|
||||
val repository = repositories.singleOrNull() ?: return null
|
||||
if (projectRoot != repository.root) {
|
||||
return null
|
||||
}
|
||||
return repository
|
||||
}
|
||||
|
||||
val model = repositoryModels[0]
|
||||
val modelRoot = model.root.virtualFile ?: return null
|
||||
if (modelRoot != projectRoot) {
|
||||
return null
|
||||
}
|
||||
return model
|
||||
private fun getOnlyProjectRootOrNull(): VirtualFile? {
|
||||
val baseDirectories = project.getBaseDirectories()
|
||||
return baseDirectories.singleOrNull()
|
||||
}
|
||||
|
||||
fun shouldWorkingTreesTabBeShown(): Boolean {
|
||||
@@ -66,10 +57,4 @@ internal class GitWorkingTreesService(private val project: Project, val coroutin
|
||||
fun workingTreesTabClosedByUser() {
|
||||
PropertiesComponent.getInstance(project).setValue(WORKING_TREE_TAB_CLOSED_BY_USER_PROPERTY, true)
|
||||
}
|
||||
|
||||
fun reloadRepository(repositoryId: RepositoryId) {
|
||||
val repositoryModel = GitRepositoriesHolder.getInstance(project).get(repositoryId) ?: return
|
||||
val repository = GitRepositoryManager.getInstance(project).getRepositoryForFile(repositoryModel.root) ?: return
|
||||
repository.workingTreeHolder.reload()
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package git4idea.workingTrees.ui
|
||||
|
||||
import com.intellij.icons.AllIcons
|
||||
@@ -23,10 +23,10 @@ import com.intellij.ui.content.ContentManagerEvent
|
||||
import com.intellij.ui.content.ContentManagerListener
|
||||
import com.intellij.util.ui.components.BorderLayoutPanel
|
||||
import com.intellij.vcs.git.repo.GitRepositoriesHolder
|
||||
import com.intellij.vcs.git.repo.GitRepositoryModel
|
||||
import git4idea.GitWorkingTree
|
||||
import git4idea.actions.workingTree.GitWorkingTreeActionsDataKeys
|
||||
import git4idea.actions.workingTree.GitWorkingTreeTabActionsDataKeys
|
||||
import git4idea.i18n.GitBundle
|
||||
import git4idea.repo.GitRepository
|
||||
import git4idea.workingTrees.GitWorkingTreesService
|
||||
import java.awt.Component
|
||||
import java.awt.Point
|
||||
@@ -88,13 +88,13 @@ internal class GitWorkingTreesContentProvider(private val project: Project) : Ch
|
||||
}
|
||||
|
||||
override fun uiDataSnapshot(sink: DataSink) {
|
||||
sink[GitWorkingTreeActionsDataKeys.SELECTED_WORKING_TREES] = list.selectedValuesList
|
||||
sink[GitWorkingTreeActionsDataKeys.GIT_REPOSITORY_MODEL_ID] = model.repository?.repositoryId
|
||||
sink[GitWorkingTreeTabActionsDataKeys.SELECTED_WORKING_TREES] = list.selectedValuesList
|
||||
sink[GitWorkingTreeTabActionsDataKeys.CURRENT_REPOSITORY] = model.repository
|
||||
}
|
||||
}
|
||||
|
||||
private class WorkingTreesListModel(project: Project) : DefaultListModel<GitWorkingTree>() {
|
||||
var repository: GitRepositoryModel? = null
|
||||
var repository: GitRepository? = null
|
||||
private set
|
||||
|
||||
init {
|
||||
@@ -105,7 +105,7 @@ internal class GitWorkingTreesContentProvider(private val project: Project) : Ch
|
||||
clear()
|
||||
val currentRepository = GitWorkingTreesService.getInstance(project).getSingleRepositoryInProjectRootOrNull()
|
||||
repository = currentRepository
|
||||
val workingTrees = currentRepository?.state?.workingTrees
|
||||
val workingTrees = currentRepository?.workingTreeHolder?.getWorkingTrees()
|
||||
if (workingTrees != null && workingTrees.size > 1) {
|
||||
workingTrees.forEach {
|
||||
if (it.isMain) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package git4idea.workingTrees.ui
|
||||
|
||||
import com.intellij.ide.impl.OpenProjectTask
|
||||
@@ -9,7 +9,7 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.ProjectManager
|
||||
import com.intellij.platform.PlatformProjectOpenProcessor
|
||||
import git4idea.GitWorkingTree
|
||||
import git4idea.actions.workingTree.GitWorkingTreeActionsDataKeys.SELECTED_WORKING_TREES
|
||||
import git4idea.actions.workingTree.GitWorkingTreeTabActionsDataKeys.SELECTED_WORKING_TREES
|
||||
import git4idea.workingTrees.GitWorkingTreesService
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package git4idea.workingTrees.ui
|
||||
|
||||
import com.intellij.CommonBundle
|
||||
@@ -11,12 +11,12 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.vcs.VcsNotifier
|
||||
import com.intellij.platform.ide.progress.withBackgroundProgress
|
||||
import com.intellij.platform.vcs.impl.shared.RepositoryId
|
||||
import git4idea.GitNotificationIdsHolder
|
||||
import git4idea.GitWorkingTree
|
||||
import git4idea.actions.workingTree.GitWorkingTreeActionsDataKeys
|
||||
import git4idea.actions.workingTree.GitWorkingTreeActionsDataKeys.SELECTED_WORKING_TREES
|
||||
import git4idea.actions.workingTree.GitWorkingTreeTabActionsDataKeys
|
||||
import git4idea.actions.workingTree.GitWorkingTreeTabActionsDataKeys.SELECTED_WORKING_TREES
|
||||
import git4idea.i18n.GitBundle
|
||||
import git4idea.repo.GitRepository
|
||||
import git4idea.workingTrees.GitWorkingTreesCommandService
|
||||
import git4idea.workingTrees.GitWorkingTreesService
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -31,19 +31,19 @@ internal class RemoveWorkingTreeAction : DumbAwareAction() {
|
||||
override fun update(e: AnActionEvent) {
|
||||
super.update(e)
|
||||
val data = e.getData(SELECTED_WORKING_TREES)
|
||||
val repositoryId = e.getData(GitWorkingTreeActionsDataKeys.GIT_REPOSITORY_MODEL_ID)
|
||||
e.presentation.isEnabled = isEnabledFor(data, e.project, repositoryId)
|
||||
val repository = e.getData(GitWorkingTreeTabActionsDataKeys.CURRENT_REPOSITORY)
|
||||
e.presentation.isEnabled = isEnabledFor(data, e.project, repository)
|
||||
}
|
||||
|
||||
private fun isEnabledFor(trees: List<GitWorkingTree>?, project: Project?, repository: RepositoryId?): Boolean {
|
||||
private fun isEnabledFor(trees: List<GitWorkingTree>?, project: Project?, repository: GitRepository?): Boolean {
|
||||
return project != null && repository != null && !trees.isNullOrEmpty() && trees.all { !it.isCurrent && !it.isMain }
|
||||
}
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val project = e.project ?: return
|
||||
val data = e.getData(SELECTED_WORKING_TREES)
|
||||
val repositoryId = e.getData(GitWorkingTreeActionsDataKeys.GIT_REPOSITORY_MODEL_ID)
|
||||
if (!isEnabledFor(data, project, repositoryId)) return
|
||||
val repository = e.getData(GitWorkingTreeTabActionsDataKeys.CURRENT_REPOSITORY)
|
||||
if (!isEnabledFor(data, project, repository)) return
|
||||
|
||||
val result = if (data!!.size == 1) {
|
||||
val tree = data.first()
|
||||
@@ -64,17 +64,17 @@ internal class RemoveWorkingTreeAction : DumbAwareAction() {
|
||||
if (result != Messages.YES) return
|
||||
GitWorkingTreesService.getInstance(project).coroutineScope.launch(Dispatchers.IO) {
|
||||
for (tree in data) {
|
||||
delete(project, tree, repositoryId!!)
|
||||
delete(project, tree, repository!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun delete(project: Project, tree: GitWorkingTree, repositoryId: RepositoryId) {
|
||||
private suspend fun delete(project: Project, tree: GitWorkingTree, repository: GitRepository) {
|
||||
val commandResult = withBackgroundProgress(project, GitBundle.message("progress.title.deleting.worktree"), cancellable = true) {
|
||||
service<GitWorkingTreesCommandService>().deleteWorkingTree(project, tree)
|
||||
}
|
||||
if (commandResult.success()) {
|
||||
GitWorkingTreesService.getInstance(project).reloadRepository(repositoryId)
|
||||
repository.workingTreeHolder.reload()
|
||||
VcsNotifier.getInstance(project).notifySuccess(GitNotificationIdsHolder.WORKING_TREE_DELETED,
|
||||
"",
|
||||
GitBundle.message("Git.WorkingTrees.delete.worktree.success.message", tree.path.presentableUrl))
|
||||
|
||||
Reference in New Issue
Block a user