From 988c8a14e28e5739f17935d6585226b45b55ccc1 Mon Sep 17 00:00:00 2001 From: UNV Date: Mon, 10 Nov 2025 23:24:53 +0300 Subject: [PATCH] Adding @ActionImpl annotations to all actions. Refactoring and localizing. --- .../consulo/git/action/ContextMenuGroup.java | 28 +++++++++ .../consulo/git/action/FileActionsGroup.java | 40 ++++++++++++ .../git/action/RepositoryActionsGroup.java | 41 +++++++++++++ .../action/RepositoryContextMenuGroup.java | 21 +++++++ .../java/consulo/git/action/VcsMenuGroup.java | 34 +++++++++++ .../actions/GitCompareWithBranchAction.java | 21 ++++--- .../git4idea/actions/GitFileActionGroup.java | 3 +- .../main/java/git4idea/actions/GitInit.java | 21 +++++-- .../actions/GitMainMenuActionGroup.java | 2 +- .../en_US/consulo.git.GitLocalize.yaml | 10 +++ plugin/src/main/resources/META-INF/plugin.xml | 61 ------------------- 11 files changed, 208 insertions(+), 74 deletions(-) create mode 100644 plugin/src/main/java/consulo/git/action/ContextMenuGroup.java create mode 100644 plugin/src/main/java/consulo/git/action/FileActionsGroup.java create mode 100644 plugin/src/main/java/consulo/git/action/RepositoryActionsGroup.java create mode 100644 plugin/src/main/java/consulo/git/action/RepositoryContextMenuGroup.java create mode 100644 plugin/src/main/java/consulo/git/action/VcsMenuGroup.java diff --git a/plugin/src/main/java/consulo/git/action/ContextMenuGroup.java b/plugin/src/main/java/consulo/git/action/ContextMenuGroup.java new file mode 100644 index 0000000..76b123d --- /dev/null +++ b/plugin/src/main/java/consulo/git/action/ContextMenuGroup.java @@ -0,0 +1,28 @@ +package consulo.git.action; + +import consulo.annotation.component.ActionImpl; +import consulo.annotation.component.ActionParentRef; +import consulo.annotation.component.ActionRef; +import consulo.git.localize.GitLocalize; +import consulo.ui.ex.action.AnSeparator; +import git4idea.actions.GitMenu; + +/** + * @author UNV + * @since 2025-11-09 + */ +@ActionImpl( + id = "Git.ContextMenu", + children = { + @ActionRef(type = FileActionsGroup.class), + @ActionRef(type = AnSeparator.class), + @ActionRef(type = RepositoryContextMenuGroup.class) + }, + parents = @ActionParentRef(@ActionRef(id = "VcsGroup")) +) +public class ContextMenuGroup extends GitMenu { + public ContextMenuGroup() { + getTemplatePresentation().setTextValue(GitLocalize.groupContextMenuText()); + setPopup(true); + } +} diff --git a/plugin/src/main/java/consulo/git/action/FileActionsGroup.java b/plugin/src/main/java/consulo/git/action/FileActionsGroup.java new file mode 100644 index 0000000..cdf7c4c --- /dev/null +++ b/plugin/src/main/java/consulo/git/action/FileActionsGroup.java @@ -0,0 +1,40 @@ +package consulo.git.action; + +import consulo.annotation.component.ActionImpl; +import consulo.annotation.component.ActionRef; +import consulo.application.dumb.DumbAware; +import consulo.localize.LocalizeValue; +import consulo.ui.ex.action.AnSeparator; +import consulo.ui.ex.action.DefaultActionGroup; +import git4idea.actions.GitAdd; +import git4idea.actions.GitCompareWithBranchAction; +import git4idea.actions.GitResolveConflictsAction; + +/** + * @author UNV + * @since 2025-11-09 + */ +@ActionImpl( + id = "Git.FileActions", + children = { + @ActionRef(id = "CheckinFiles"), + @ActionRef(type = GitAdd.class), + @ActionRef(type = AnSeparator.class), + @ActionRef(id = "Annotate"), + @ActionRef(id = "Show.Current.Revision"), + @ActionRef(id = "Compare.SameVersion"), + @ActionRef(id = "Compare.LastVersion"), + @ActionRef(id = "Compare.Selected"), + @ActionRef(type = GitCompareWithBranchAction.class), + @ActionRef(id = "Vcs.ShowTabbedFileHistory"), + @ActionRef(id = "Vcs.ShowHistoryForBlock"), + @ActionRef(type = AnSeparator.class), + @ActionRef(id = "ChangesView.Revert"), + @ActionRef(type = GitResolveConflictsAction.class) + } +) +public class FileActionsGroup extends DefaultActionGroup implements DumbAware { + public FileActionsGroup() { + super(LocalizeValue.empty(), false); + } +} diff --git a/plugin/src/main/java/consulo/git/action/RepositoryActionsGroup.java b/plugin/src/main/java/consulo/git/action/RepositoryActionsGroup.java new file mode 100644 index 0000000..9e250e0 --- /dev/null +++ b/plugin/src/main/java/consulo/git/action/RepositoryActionsGroup.java @@ -0,0 +1,41 @@ +package consulo.git.action; + +import consulo.annotation.component.ActionImpl; +import consulo.annotation.component.ActionRef; +import consulo.application.dumb.DumbAware; +import consulo.localize.LocalizeValue; +import consulo.ui.ex.action.AnSeparator; +import consulo.ui.ex.action.DefaultActionGroup; +import git4idea.actions.*; +import git4idea.ui.branch.GitBranchesAction; + +/** + * @author UNV + * @since 2025-11-09 + */ +@ActionImpl( + id = "GitRepositoryActions", + children = { + @ActionRef(type = GitBranchesAction.class), + @ActionRef(type = GitTag.class), + @ActionRef(type = GitMerge.class), + @ActionRef(type = GitStash.class), + @ActionRef(type = GitUnstash.class), + @ActionRef(type = GitResetHead.class), + @ActionRef(type = AnSeparator.class), + @ActionRef(type = GitFetch.class), + @ActionRef(type = GitPull.class), + @ActionRef(id = "Vcs.Push"), + @ActionRef(type = AnSeparator.class), + @ActionRef(type = GitRebase.class), + @ActionRef(type = GitRebaseAbort.class), + @ActionRef(type = GitRebaseContinue.class), + @ActionRef(type = GitRebaseSkip.class), + @ActionRef(type = AnSeparator.class) + } +) +public class RepositoryActionsGroup extends DefaultActionGroup implements DumbAware { + public RepositoryActionsGroup() { + super(LocalizeValue.empty(), false); + } +} diff --git a/plugin/src/main/java/consulo/git/action/RepositoryContextMenuGroup.java b/plugin/src/main/java/consulo/git/action/RepositoryContextMenuGroup.java new file mode 100644 index 0000000..439a171 --- /dev/null +++ b/plugin/src/main/java/consulo/git/action/RepositoryContextMenuGroup.java @@ -0,0 +1,21 @@ +package consulo.git.action; + +import consulo.annotation.component.ActionImpl; +import consulo.annotation.component.ActionRef; +import consulo.application.dumb.DumbAware; +import consulo.git.localize.GitLocalize; +import consulo.ui.ex.action.DefaultActionGroup; + +/** + * @author UNV + * @since 2025-11-09 + */ +@ActionImpl( + id = "Git.RepositoryContextMenu", + children = @ActionRef(type = RepositoryActionsGroup.class) +) +public class RepositoryContextMenuGroup extends DefaultActionGroup implements DumbAware { + public RepositoryContextMenuGroup() { + super(GitLocalize.groupRepositoryContextMenuText(), true); + } +} diff --git a/plugin/src/main/java/consulo/git/action/VcsMenuGroup.java b/plugin/src/main/java/consulo/git/action/VcsMenuGroup.java new file mode 100644 index 0000000..35ef507 --- /dev/null +++ b/plugin/src/main/java/consulo/git/action/VcsMenuGroup.java @@ -0,0 +1,34 @@ +package consulo.git.action; + +import consulo.annotation.component.ActionImpl; +import consulo.annotation.component.ActionParentRef; +import consulo.annotation.component.ActionRef; +import consulo.annotation.component.ActionRefAnchor; +import consulo.git.localize.GitLocalize; +import consulo.ui.ex.action.AnSeparator; +import git4idea.actions.GitFileActionGroup; +import git4idea.actions.GitMenu; + +/** + * @author UNV + * @since 2025-11-09 + */ +@ActionImpl( + id = "Git.Menu", + children = { + @ActionRef(type = GitFileActionGroup.class), + @ActionRef(type = AnSeparator.class), + @ActionRef(type = RepositoryActionsGroup.class) + }, + parents = @ActionParentRef( + value = @ActionRef(id = "VcsGlobalGroup"), + anchor = ActionRefAnchor.AFTER, + relatedToAction = @ActionRef(id = "Vcs.Specific") + ) +) +public class VcsMenuGroup extends GitMenu { + public VcsMenuGroup() { + getTemplatePresentation().setTextValue(GitLocalize.groupVcsMenuText()); + setPopup(true); + } +} diff --git a/plugin/src/main/java/git4idea/actions/GitCompareWithBranchAction.java b/plugin/src/main/java/git4idea/actions/GitCompareWithBranchAction.java index 4b8bfb3..be73317 100644 --- a/plugin/src/main/java/git4idea/actions/GitCompareWithBranchAction.java +++ b/plugin/src/main/java/git4idea/actions/GitCompareWithBranchAction.java @@ -15,8 +15,10 @@ */ package git4idea.actions; +import consulo.annotation.component.ActionImpl; +import consulo.git.localize.GitLocalize; +import consulo.localize.LocalizeValue; import consulo.project.Project; -import consulo.util.collection.ContainerUtil; import consulo.versionControlSystem.FilePath; import consulo.versionControlSystem.VcsException; import consulo.versionControlSystem.change.Change; @@ -38,7 +40,12 @@ import java.util.Collections; import java.util.List; +@ActionImpl(id = "Git.CompareWithBranch") public class GitCompareWithBranchAction extends DvcsCompareWithBranchAction { + public GitCompareWithBranchAction() { + getTemplatePresentation().setTextValue(GitLocalize.actionCompareWithBranchText()); + } + @Override protected boolean noBranchesToCompare(@Nonnull GitRepository repository) { int locals = repository.getBranches().getLocalBranches().size(); @@ -61,7 +68,7 @@ protected List getBranchNamesExceptCurrent(@Nonnull GitRepository reposi localBranches.remove(repository.getCurrentBranch()); } - List branchNames = ContainerUtil.newArrayList(); + List branchNames = new ArrayList<>(); for (GitBranch branch : localBranches) { branchNames.add(branch.getName()); } @@ -85,11 +92,11 @@ protected Collection getDiffChanges( @Nonnull String branchToCompare ) throws VcsException { FilePath filePath = VcsUtil.getFilePath(file); - final GitRepository gitRepository = GitUtil.getRepositoryManager(project).getRepositoryForFile(file); + GitRepository gitRepository = GitUtil.getRepositoryManager(project).getRepositoryForFile(file); if (gitRepository == null) { throw new VcsException("Couldn't find Git Repository for " + file.getName()); } - final VirtualFile gitRepositoryRoot = gitRepository.getRoot(); + VirtualFile gitRepositoryRoot = gitRepository.getRoot(); GitRevisionNumber compareRevisionNumber = new GitRevisionNumber(branchToCompare); Collection changes = GitChangeUtils.getDiffWithWorkingDir(project, gitRepositoryRoot, branchToCompare, Collections.singletonList(filePath), false); @@ -100,8 +107,8 @@ protected Collection getDiffChanges( } return changes.isEmpty() && !filePath.isDirectory() ? VcsUtil.createChangesWithCurrentContentForFile( - filePath, - GitContentRevision.createRevision(filePath, compareRevisionNumber, project, null) - ) : changes; + filePath, + GitContentRevision.createRevision(filePath, compareRevisionNumber, project, null) + ) : changes; } } diff --git a/plugin/src/main/java/git4idea/actions/GitFileActionGroup.java b/plugin/src/main/java/git4idea/actions/GitFileActionGroup.java index 332643f..37c02ba 100644 --- a/plugin/src/main/java/git4idea/actions/GitFileActionGroup.java +++ b/plugin/src/main/java/git4idea/actions/GitFileActionGroup.java @@ -4,6 +4,7 @@ import consulo.annotation.component.ActionRef; import consulo.application.dumb.DumbAware; import consulo.codeEditor.Editor; +import consulo.git.action.FileActionsGroup; import consulo.ui.ex.action.DefaultActionGroup; import consulo.virtualFileSystem.VirtualFile; import consulo.util.collection.JBIterable; @@ -20,7 +21,7 @@ // from kotlin @ActionImpl( id = "Git.MainMenu.FileActions", - children = @ActionRef(id = "Git.FileActions") + children = @ActionRef(type = FileActionsGroup.class) ) public class GitFileActionGroup extends DefaultActionGroup implements DumbAware { public GitFileActionGroup() { diff --git a/plugin/src/main/java/git4idea/actions/GitInit.java b/plugin/src/main/java/git4idea/actions/GitInit.java index a7ce382..c253607 100644 --- a/plugin/src/main/java/git4idea/actions/GitInit.java +++ b/plugin/src/main/java/git4idea/actions/GitInit.java @@ -15,6 +15,9 @@ */ package git4idea.actions; +import consulo.annotation.component.ActionImpl; +import consulo.annotation.component.ActionParentRef; +import consulo.annotation.component.ActionRef; import consulo.application.progress.ProgressIndicator; import consulo.application.progress.Task; import consulo.fileChooser.FileChooserDescriptor; @@ -22,8 +25,10 @@ import consulo.fileChooser.IdeaFileChooser; import consulo.git.localize.GitLocalize; import consulo.ide.ServiceManager; +import consulo.localize.LocalizeValue; import consulo.project.Project; import consulo.project.ProjectManager; +import consulo.project.ui.notification.NotificationService; import consulo.ui.annotation.RequiredUIAccess; import consulo.ui.ex.action.AnActionEvent; import consulo.ui.ex.action.DumbAwareAction; @@ -45,10 +50,15 @@ /** * Initialize git repository action */ +@ActionImpl(id = "Git.Init", parents = @ActionParentRef(@ActionRef(id = "Vcs.Import"))) public class GitInit extends DumbAwareAction { + public GitInit() { + super(GitLocalize.actionInitText()); + } + @Override @RequiredUIAccess - public void actionPerformed(final AnActionEvent e) { + public void actionPerformed(AnActionEvent e) { Project project = e.getData(Project.KEY); if (project == null) { project = ProjectManager.getInstance().getDefaultProject(); @@ -66,7 +76,7 @@ public void actionPerformed(final AnActionEvent e) { } @RequiredUIAccess - private static void doInit(final Project project, FileChooserDescriptor fcd, VirtualFile baseDir, final VirtualFile finalBaseDir) { + private static void doInit(final Project project, FileChooserDescriptor fcd, VirtualFile baseDir, VirtualFile finalBaseDir) { IdeaFileChooser.chooseFile( fcd, project, @@ -86,7 +96,10 @@ private static void doInit(final Project project, FileChooserDescriptor fcd, Vir if (!result.success()) { GitVcs vcs = GitVcs.getInstance(project); if (vcs != null && vcs.getExecutableValidator().checkExecutableAndNotifyIfNeeded()) { - VcsNotifier.getInstance(project).notifyError("Git init failed", result.getErrorOutputAsHtmlString()); + NotificationService.getInstance().newError(VcsNotifier.IMPORTANT_ERROR_NOTIFICATION) + .title(LocalizeValue.localizeTODO("Git init failed")) + .content(LocalizeValue.localizeTODO(result.getErrorOutputAsHtmlString())) + .notify(project); } return; } @@ -105,7 +118,7 @@ public void run(@Nonnull ProgressIndicator indicator) { ); } - public static void refreshAndConfigureVcsMappings(final Project project, final VirtualFile root, final String path) { + public static void refreshAndConfigureVcsMappings(Project project, VirtualFile root, String path) { VirtualFileUtil.markDirtyAndRefresh(false, true, false, root); ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(project); manager.setDirectoryMappings(VcsUtil.addMapping(manager.getDirectoryMappings(), path, GitVcs.NAME)); diff --git a/plugin/src/main/java/git4idea/actions/GitMainMenuActionGroup.java b/plugin/src/main/java/git4idea/actions/GitMainMenuActionGroup.java index ea0d2e4..235b556 100644 --- a/plugin/src/main/java/git4idea/actions/GitMainMenuActionGroup.java +++ b/plugin/src/main/java/git4idea/actions/GitMainMenuActionGroup.java @@ -41,7 +41,7 @@ @ActionRef(id = "Vcs.Show.Log"), @ActionRef(type = MainMenuPatchGroup.class), @ActionRef(type = MainMenuUncommittedChangesGroup.class), - @ActionRef(id = "Git.MainMenu.FileActions"), + @ActionRef(type = GitFileActionGroup.class), @ActionRef(type = AnSeparator.class), //@ActionRef(type = GitConfigureRemotesAction.class), //@ActionRef(type = GitCloneAction.class), diff --git a/plugin/src/main/resources/LOCALIZE-LIB/en_US/consulo.git.GitLocalize.yaml b/plugin/src/main/resources/LOCALIZE-LIB/en_US/consulo.git.GitLocalize.yaml index 200e8b1..cd01edf 100644 --- a/plugin/src/main/resources/LOCALIZE-LIB/en_US/consulo.git.GitLocalize.yaml +++ b/plugin/src/main/resources/LOCALIZE-LIB/en_US/consulo.git.GitLocalize.yaml @@ -14,6 +14,10 @@ action.branches.text: text: _Branches... action.checkout.revision.text: text: Checkout Revision +action.init.text: + text: Create Git Repository... +action.compare.with.branch.text: + text: Compare with Branch or Tag... action.create.new.branch.description: text: Create new branch starting from the selected commit action.create.new.branch.text: @@ -461,6 +465,8 @@ git4idea.vcs.name: text: Git group.Git.MainMenu.MergeActions.text: text: _Merge +group.context.menu.text: + text: _Git group.log.context.menu.text: text: Git Log Context Menu group.log.toolbar.text: @@ -473,6 +479,10 @@ group.main.menu.rebase.actions.text: text: _Rebase group.main.menu.uncommitted.changes.text: text: _Uncommitted Changes +group.repository.context.menu.text: + text: _Repository +group.vcs.menu.text: + text: _Git index.file.error: text: Updating file in the index failed init.add.root.message: diff --git a/plugin/src/main/resources/META-INF/plugin.xml b/plugin/src/main/resources/META-INF/plugin.xml index c643e31..4509aad 100644 --- a/plugin/src/main/resources/META-INF/plugin.xml +++ b/plugin/src/main/resources/META-INF/plugin.xml @@ -11,67 +11,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -