From 9b37a87e9f401374a889ece1f6fc17b046aad61d Mon Sep 17 00:00:00 2001 From: OpherV Date: Tue, 13 Apr 2021 14:29:28 +0300 Subject: [PATCH 1/4] Fix "Error using shortcuts" #322 --- .../gitflow/GitflowBranchUtilManager.java | 21 ++++++------------- src/main/java/gitflow/GitflowConfigUtil.java | 10 ++++----- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/main/java/gitflow/GitflowBranchUtilManager.java b/src/main/java/gitflow/GitflowBranchUtilManager.java index 2ed4949..b17daa1 100644 --- a/src/main/java/gitflow/GitflowBranchUtilManager.java +++ b/src/main/java/gitflow/GitflowBranchUtilManager.java @@ -1,22 +1,13 @@ package gitflow; -import com.intellij.openapi.application.Application; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import git4idea.GitUtil; import git4idea.repo.GitRepository; -import gitflow.actions.GitflowActions; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.concurrent.Future; /** * This class maps repos to their corresponding branch utils @@ -24,11 +15,11 @@ */ public class GitflowBranchUtilManager { - private static HashMap repoBranchUtilMap; + private static HashMap repoBranchUtilMap; static public GitflowBranchUtil getBranchUtil(GitRepository repo){ - if (repoBranchUtilMap != null) { - return repoBranchUtilMap.get(repo); + if (repo != null && repoBranchUtilMap != null) { + return repoBranchUtilMap.get(repo.getPresentableUrl()); } else { return null; } @@ -36,18 +27,18 @@ static public GitflowBranchUtil getBranchUtil(GitRepository repo){ static public void setupBranchUtil(Project project, GitRepository repo){ GitflowBranchUtil gitflowBranchUtil = new GitflowBranchUtil(project, repo); - repoBranchUtilMap.put(repo, gitflowBranchUtil); + repoBranchUtilMap.put(repo.getPresentableUrl(), gitflowBranchUtil); // clean up Disposer.register(repo, () -> repoBranchUtilMap.remove(repo)); } /** * Repopulates the branchUtils for each repo - * @param project + * @param proj */ static public void update(Project proj){ if (repoBranchUtilMap == null){ - repoBranchUtilMap = new HashMap(); + repoBranchUtilMap = new HashMap(); } List gitRepositories = GitUtil.getRepositoryManager(proj).getRepositories(); diff --git a/src/main/java/gitflow/GitflowConfigUtil.java b/src/main/java/gitflow/GitflowConfigUtil.java index 692c8b1..f0c7dcf 100644 --- a/src/main/java/gitflow/GitflowConfigUtil.java +++ b/src/main/java/gitflow/GitflowConfigUtil.java @@ -31,7 +31,7 @@ public class GitflowConfigUtil { public static final String PREFIX_SUPPORT = "gitflow.prefix.support"; public static final String PREFIX_VERSIONTAG = "gitflow.prefix.versiontag"; - private static Map> gitflowConfigUtilMap = new HashMap>(); + private static Map> gitflowConfigUtilMap = new HashMap>(); Project project; GitRepository repo; @@ -47,14 +47,14 @@ public class GitflowConfigUtil { public static GitflowConfigUtil getInstance(Project project_, GitRepository repo_) { GitflowConfigUtil instance; - if (gitflowConfigUtilMap.containsKey(project_) && gitflowConfigUtilMap.get(project_).containsKey(repo_)) { - instance = gitflowConfigUtilMap.get(project_).get(repo_); + if (gitflowConfigUtilMap.containsKey(project_) && gitflowConfigUtilMap.get(project_).containsKey(repo_.getPresentableUrl())) { + instance = gitflowConfigUtilMap.get(project_).get(repo_.getPresentableUrl()); } else { - Map innerMap = new HashMap(); + Map innerMap = new HashMap(); instance = new GitflowConfigUtil(project_, repo_); gitflowConfigUtilMap.put(project_, innerMap); - innerMap.put(repo_, instance); + innerMap.put(repo_.getPresentableUrl(), instance); //cleanup Disposer.register(repo_, () -> innerMap.remove(repo_)); From 31051574b237bf3ddfcae5e5df43ee5a9132db6c Mon Sep 17 00:00:00 2001 From: OpherV Date: Tue, 13 Apr 2021 20:21:38 +0300 Subject: [PATCH 2/4] Sort out build 211 compatibility issues --- src/main/java/gitflow/GitflowConfigUtil.java | 3 ++- src/main/java/gitflow/IDEAUtils.java | 21 +++++++++++++++ .../java/gitflow/actions/GitflowAction.java | 3 ++- src/main/java/gitflow/ui/GitflowWidget.java | 26 ++++++++++++++----- src/main/resources/META-INF/plugin.xml | 2 +- 5 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 src/main/java/gitflow/IDEAUtils.java diff --git a/src/main/java/gitflow/GitflowConfigUtil.java b/src/main/java/gitflow/GitflowConfigUtil.java index f0c7dcf..28d5cdf 100644 --- a/src/main/java/gitflow/GitflowConfigUtil.java +++ b/src/main/java/gitflow/GitflowConfigUtil.java @@ -10,6 +10,7 @@ import git4idea.config.GitConfigUtil; import git4idea.repo.GitRepository; import gitflow.ui.NotifyUtil; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; @@ -44,7 +45,7 @@ public class GitflowConfigUtil { public String supportPrefix; public String versiontagPrefix; - public static GitflowConfigUtil getInstance(Project project_, GitRepository repo_) + public static GitflowConfigUtil getInstance(@NotNull Project project_, @NotNull GitRepository repo_) { GitflowConfigUtil instance; if (gitflowConfigUtilMap.containsKey(project_) && gitflowConfigUtilMap.get(project_).containsKey(repo_.getPresentableUrl())) { diff --git a/src/main/java/gitflow/IDEAUtils.java b/src/main/java/gitflow/IDEAUtils.java new file mode 100644 index 0000000..fca02fa --- /dev/null +++ b/src/main/java/gitflow/IDEAUtils.java @@ -0,0 +1,21 @@ +package gitflow; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; +import com.intellij.openapi.wm.WindowManager; + +import java.awt.*; + +public class IDEAUtils { + public static Project getActiveProject(){ + Project[] projects = ProjectManager.getInstance().getOpenProjects(); + Project activeProject = null; + for (Project project : projects) { + Window window = WindowManager.getInstance().suggestParentWindow(project); + if (window != null && window.isActive()) { + activeProject = project; + } + } + return activeProject; + } +} diff --git a/src/main/java/gitflow/actions/GitflowAction.java b/src/main/java/gitflow/actions/GitflowAction.java index aa752df..a30236d 100644 --- a/src/main/java/gitflow/actions/GitflowAction.java +++ b/src/main/java/gitflow/actions/GitflowAction.java @@ -13,6 +13,7 @@ import gitflow.Gitflow; import gitflow.GitflowBranchUtil; import gitflow.GitflowBranchUtilManager; +import gitflow.IDEAUtils; import gitflow.ui.NotifyUtil; import org.jetbrains.annotations.Nullable; @@ -41,7 +42,7 @@ public abstract class GitflowAction extends DumbAwareAction { @Override public void actionPerformed(AnActionEvent e) { - Project project = e.getProject(); + Project project = IDEAUtils.getActiveProject(); // if repo isn't set explicitly, such as in the case of starting from keyboard shortcut, infer it if (myRepo == null){ diff --git a/src/main/java/gitflow/ui/GitflowWidget.java b/src/main/java/gitflow/ui/GitflowWidget.java index 7f6f6ed..9be14a3 100644 --- a/src/main/java/gitflow/ui/GitflowWidget.java +++ b/src/main/java/gitflow/ui/GitflowWidget.java @@ -16,6 +16,8 @@ package gitflow.ui; import com.intellij.ide.BrowserUtil; +import com.intellij.ide.DataManager; +import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.actionSystem.impl.SimpleDataContext; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileEditor.FileEditorManager; @@ -25,18 +27,19 @@ import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.openapi.wm.StatusBar; import com.intellij.openapi.wm.StatusBarWidget; import com.intellij.openapi.wm.WindowManager; +import com.intellij.openapi.wm.impl.status.EditorBasedWidget; import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.popup.PopupFactoryImpl; import com.intellij.util.Consumer; import com.intellij.openapi.vcs.VcsRoot; import com.intellij.openapi.vcs.ProjectLevelVcsManager; -import gitflow.GitflowBranchUtil; -import gitflow.GitflowBranchUtilManager; -import gitflow.GitflowVersionTester; +import git4idea.GitBranch; +import gitflow.*; import gitflow.actions.GitflowPopupGroup; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -107,9 +110,10 @@ public void repositoryChanged(@NotNull GitRepository repository) { } @Nullable - @Override + @ Override public ListPopup getPopupStep() { - Project project = getProject(); + Project project = IDEAUtils.getActiveProject(); + if (project == null) { return null; } @@ -118,7 +122,17 @@ public ListPopup getPopupStep() { return null; } - ListPopup listPopup = new PopupFactoryImpl.ActionGroupPopup("Gitflow Actions", popupGroup.getActionGroup(), SimpleDataContext.getProjectContext(project), false, false, false, true, null, -1, + Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); + if (focusOwner == null) { + IdeFocusManager focusManager = IdeFocusManager.getInstance(project); + Window frame = focusManager.getLastFocusedIdeWindow(); + if (frame != null) { + focusOwner = focusManager.getLastFocusedFor(frame); + } + } + + DataContext dataContext = DataManager.getInstance().getDataContext(focusOwner); + ListPopup listPopup = new PopupFactoryImpl.ActionGroupPopup("Gitflow Actions", popupGroup.getActionGroup(), dataContext, false, false, false, true, null, -1, null, null); return listPopup; diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index f4ecd52..53f1176 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -95,7 +95,7 @@ - + From d04c7d1241283a5b25991268970fef98191821b2 Mon Sep 17 00:00:00 2001 From: OpherV Date: Tue, 13 Apr 2021 20:31:04 +0300 Subject: [PATCH 3/4] fix Finishing BugFix throws stacktrace. #320 --- src/main/java/gitflow/actions/FinishBugfixAction.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/gitflow/actions/FinishBugfixAction.java b/src/main/java/gitflow/actions/FinishBugfixAction.java index 30af59a..75a468e 100644 --- a/src/main/java/gitflow/actions/FinishBugfixAction.java +++ b/src/main/java/gitflow/actions/FinishBugfixAction.java @@ -59,14 +59,14 @@ public void runAction(final Project project, final String bugfixName){ GitflowConfigUtil gitflowConfigUtil = GitflowConfigUtil.getInstance(project, myRepo); - //get the base branch for this bugfix - final String baseBranch = gitflowConfigUtil.getBaseBranch(branchUtil.getPrefixBugfix()+bugfixName); - new Task.Backgroundable(myProject,"Finishing bugfix "+bugfixName,false){ @Override public void run(@NotNull ProgressIndicator indicator) { GitCommandResult result = myGitflow.finishBugfix(myRepo, bugfixName, errorLineHandler); + //get the base branch for this bugfix + final String baseBranch = gitflowConfigUtil.getBaseBranch(branchUtil.getPrefixBugfix()+bugfixName); + if (result.success()) { String finishedBugfixMessage = String.format("The bugfix branch '%s%s' was merged into '%s'", branchUtil.getPrefixBugfix(), bugfixName, baseBranch); NotifyUtil.notifySuccess(myProject, bugfixName, finishedBugfixMessage); From abd4f8c053c22b6b16467ab31285c993247eb6b8 Mon Sep 17 00:00:00 2001 From: OpherV Date: Tue, 13 Apr 2021 20:32:40 +0300 Subject: [PATCH 4/4] Update version and changelog --- build.gradle | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 8ce3d2a..b4d5ec5 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ compileJava { } group 'gitflow4idea' -version '0.7.5' +version '0.7.6' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 @@ -22,18 +22,25 @@ dependencies { } intellij { - version '2020.3' + version '2021.1' plugins 'git4idea', 'tasks' } patchPluginXml { pluginId "Gitflow" pluginDescription 'Git Flow Integration' - version '0.7.5' - sinceBuild '203.0' - untilBuild '203.*' + version '0.7.6' + sinceBuild '211.0' + untilBuild '211.*' changeNotes """ +

Changelog for 0.7.6

+
    +
  • Fix "Error using shortcuts" #322
  • +
  • fix Finishing BugFix throws stacktrace #320
  • +
  • Support for 2021.1 build
  • +
+

Changelog for 0.7.5

  • PluginException: Icon cannot be found in 'AllIcons.Vcs.CheckOut' #314 (@tumb1er)