From b3b2984616bc6da660d41b9130ca0400d0530ba0 Mon Sep 17 00:00:00 2001 From: UNV Date: Fri, 22 Aug 2025 20:31:51 +0300 Subject: [PATCH] Compilation fixes after platform update. Refactoring. --- .../main/java/git4idea/actions/GitAdd.java | 9 + .../git4idea/history/GitHistoryProvider.java | 339 ++++++++++-------- .../ui/ChangesBrowserWithRollback.java | 56 ++- .../git4idea/update/GitSkippedCommits.java | 287 ++++++++------- plugin/src/main/resources/META-INF/plugin.xml | 3 +- 5 files changed, 361 insertions(+), 333 deletions(-) diff --git a/plugin/src/main/java/git4idea/actions/GitAdd.java b/plugin/src/main/java/git4idea/actions/GitAdd.java index 63f0360..20e9b24 100644 --- a/plugin/src/main/java/git4idea/actions/GitAdd.java +++ b/plugin/src/main/java/git4idea/actions/GitAdd.java @@ -15,13 +15,22 @@ */ package git4idea.actions; +import consulo.annotation.component.ActionImpl; +import consulo.annotation.component.ActionRef; import consulo.ide.impl.idea.openapi.vcs.changes.actions.ScheduleForAdditionAction; +import consulo.localize.LocalizeValue; +import consulo.platform.base.icon.PlatformIconGroup; import consulo.ui.ex.action.AnActionEvent; import consulo.virtualFileSystem.status.FileStatus; import jakarta.annotation.Nonnull; +@ActionImpl(id = "Git.Add", shortcutFrom = @ActionRef(id = "ChangesView.AddUnversioned")) public class GitAdd extends ScheduleForAdditionAction { + public GitAdd() { + super(LocalizeValue.localizeTODO("Add"), LocalizeValue.localizeTODO("Add"), PlatformIconGroup.generalAdd()); + } + @Override protected boolean isStatusForAddition(FileStatus status) { return status == FileStatus.UNKNOWN diff --git a/plugin/src/main/java/git4idea/history/GitHistoryProvider.java b/plugin/src/main/java/git4idea/history/GitHistoryProvider.java index 4927045..24fdc64 100644 --- a/plugin/src/main/java/git4idea/history/GitHistoryProvider.java +++ b/plugin/src/main/java/git4idea/history/GitHistoryProvider.java @@ -18,10 +18,10 @@ import consulo.annotation.component.ComponentScope; import consulo.annotation.component.ServiceAPI; import consulo.annotation.component.ServiceImpl; -import consulo.ide.impl.idea.openapi.vcs.annotate.ShowAllAffectedGenericAction; import consulo.ide.impl.idea.openapi.vcs.history.CopyRevisionNumberAction; import consulo.logging.Logger; import consulo.project.Project; +import consulo.ui.ex.action.ActionManager; import consulo.ui.ex.action.AnAction; import consulo.ui.ex.awt.ColumnInfo; import consulo.util.collection.ArrayUtil; @@ -29,6 +29,7 @@ import consulo.versionControlSystem.FilePath; import consulo.versionControlSystem.VcsConfiguration; import consulo.versionControlSystem.VcsException; +import consulo.versionControlSystem.action.VcsActions; import consulo.versionControlSystem.action.VcsContextFactory; import consulo.versionControlSystem.change.ContentRevision; import consulo.versionControlSystem.history.*; @@ -46,6 +47,7 @@ import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; + import javax.swing.*; import java.util.Collections; import java.util.List; @@ -57,167 +59,188 @@ @Singleton @ServiceAPI(ComponentScope.PROJECT) @ServiceImpl -public class GitHistoryProvider implements VcsHistoryProvider, VcsCacheableHistorySessionFactory, VcsBaseRevisionAdviser { - private static final Logger log = Logger.getInstance(GitHistoryProvider.class.getName()); - - @Nonnull - private final Project myProject; - - @Inject - public GitHistoryProvider(@Nonnull Project project) { - myProject = project; - } - - public VcsDependentHistoryComponents getUICustomization(final VcsHistorySession session, - JComponent forShortcutRegistration) { - return VcsDependentHistoryComponents.createOnlyColumns(new ColumnInfo[0]); - } - - public AnAction[] getAdditionalActions(Runnable refresher) { - return new AnAction[]{ - ShowAllAffectedGenericAction.getInstance(), - new CopyRevisionNumberAction() - }; - } - - public boolean isDateOmittable() { - return false; - } - - @Nullable - public String getHelpId() { - return null; - } - - @Override - public FilePath getUsedFilePath(VcsAbstractHistorySession session) { - return null; - } - - @Override - public Boolean getAddinionallyCachedData(VcsAbstractHistorySession session) { - return null; - } - - @Override - public VcsAbstractHistorySession createFromCachedData(Boolean aBoolean, - @Nonnull List revisions, - @Nonnull FilePath filePath, - VcsRevisionNumber currentRevision) { - return createSession(filePath, revisions, currentRevision); - } - - @Nullable - public VcsHistorySession createSessionFor(final FilePath filePath) throws VcsException { - List revisions = null; - try { - revisions = GitHistoryUtils.history(myProject, filePath); - } - catch (VcsException e) { - GitVcs.getInstance(myProject).getExecutableValidator().showNotificationOrThrow(e); - } - return createSession(filePath, revisions, null); - } - - private VcsAbstractHistorySession createSession(final FilePath filePath, final List revisions, - @Nullable final VcsRevisionNumber number) { - return new VcsAbstractHistorySession(revisions, number) { - @Nullable - protected VcsRevisionNumber calcCurrentRevisionNumber() { +public class GitHistoryProvider + implements VcsHistoryProvider, VcsCacheableHistorySessionFactory, VcsBaseRevisionAdviser { + private static final Logger log = Logger.getInstance(GitHistoryProvider.class); + + @Nonnull + private final Project myProject; + + @Inject + public GitHistoryProvider(@Nonnull Project project) { + myProject = project; + } + + @Override + public VcsDependentHistoryComponents getUICustomization( + final VcsHistorySession session, + JComponent forShortcutRegistration + ) { + return VcsDependentHistoryComponents.createOnlyColumns(new ColumnInfo[0]); + } + + @Override + public AnAction[] getAdditionalActions(Runnable refresher) { + return new AnAction[]{ + ActionManager.getInstance().getAction(VcsActions.ACTION_SHOW_ALL_AFFECTED), + new CopyRevisionNumberAction() + }; + } + + @Override + public boolean isDateOmittable() { + return false; + } + + @Nullable + @Override + public String getHelpId() { + return null; + } + + @Override + public FilePath getUsedFilePath(VcsAbstractHistorySession session) { + return null; + } + + @Override + public Boolean getAddinionallyCachedData(VcsAbstractHistorySession session) { + return null; + } + + @Override + public VcsAbstractHistorySession createFromCachedData( + Boolean aBoolean, + @Nonnull List revisions, + @Nonnull FilePath filePath, + VcsRevisionNumber currentRevision + ) { + return createSession(filePath, revisions, currentRevision); + } + + @Nullable + @Override + public VcsHistorySession createSessionFor(final FilePath filePath) throws VcsException { + List revisions = null; try { - return GitHistoryUtils.getCurrentRevision(myProject, filePath, "HEAD"); + revisions = GitHistoryUtils.history(myProject, filePath); } catch (VcsException e) { - // likely the file is not under VCS anymore. - if (log.isDebugEnabled()) { - log.debug("Unable to retrieve the current revision number", e); - } - return null; + GitVcs.getInstance(myProject).getExecutableValidator().showNotificationOrThrow(e); } - } + return createSession(filePath, revisions, null); + } - public HistoryAsTreeProvider getHistoryAsTreeProvider() { - return null; - } - - @Override - public VcsHistorySession copy() { - return createSession(filePath, getRevisionList(), getCurrentRevisionNumber()); - } - }; - } - - @Override - public boolean getBaseVersionContent(FilePath filePath, - Predicate processor, - final String beforeVersionId, - List warnings) - throws VcsException { - if (StringUtil.isEmptyOrSpaces(beforeVersionId) || filePath.getVirtualFile() == null) { - return false; - } - // apply if base revision id matches revision - final VirtualFile root = GitUtil.getGitRoot(filePath); - if (root == null) { - return false; - } - - final SHAHash shaHash = GitChangeUtils.commitExists(myProject, root, beforeVersionId, null, "HEAD"); - if (shaHash == null) { - throw new VcsException("Can not apply patch to " + filePath.getPath() + ".\nCan not find revision '" + beforeVersionId + "'."); - } - - final ContentRevision content = GitVcs.getInstance(myProject).getDiffProvider() - .createFileContent(new GitRevisionNumber(shaHash.getValue()), filePath.getVirtualFile()); - if (content == null) { - throw new VcsException("Can not load content of '" + filePath.getPath() + "' for revision '" + shaHash.getValue() + "'"); - } - return !processor.test(content.getContent()); - } - - public void reportAppendableHistory(final FilePath path, final VcsAppendableHistorySessionPartner partner) throws VcsException { - final VcsAbstractHistorySession emptySession = createSession(path, Collections.emptyList(), null); - partner.reportCreatedEmptySession(emptySession); - - VcsConfiguration vcsConfiguration = VcsConfiguration.getInstance(myProject); - String[] additionalArgs = vcsConfiguration.LIMIT_HISTORY ? - new String[]{"--max-count=" + vcsConfiguration.MAXIMUM_HISTORY_ROWS} : - ArrayUtil.EMPTY_STRING_ARRAY; - - final GitExecutableValidator validator = GitVcs.getInstance(myProject).getExecutableValidator(); - GitHistoryUtils.history(myProject, refreshPath(path), null, gitFileRevision -> partner.acceptRevision(gitFileRevision), e -> { - if (validator.checkExecutableAndNotifyIfNeeded()) { - partner.reportException(e); - } - }, additionalArgs); - } - - /** - * Refreshes the IO File inside this FilePath to let it survive moves. - */ - @Nonnull - private static FilePath refreshPath(@Nonnull FilePath path) { - VirtualFile virtualFile = path.getVirtualFile(); - if (virtualFile == null) { - return path; - } - return VcsContextFactory.getInstance().createFilePathOn(virtualFile); - } - - public boolean supportsHistoryForDirectories() { - return true; - } - - @Override - public DiffFromHistoryHandler getHistoryDiffHandler() { - return new GitDiffFromHistoryHandler(myProject); - } - - @Override - public boolean canShowHistoryFor(@Nonnull VirtualFile file) { - GitRepositoryManager manager = GitUtil.getRepositoryManager(myProject); - GitRepository repository = manager.getRepositoryForFile(file); - return repository != null && !repository.isFresh(); - } + private VcsAbstractHistorySession createSession( + final FilePath filePath, final List revisions, + @Nullable final VcsRevisionNumber number + ) { + return new VcsAbstractHistorySession(revisions, number) { + @Nullable + @Override + protected VcsRevisionNumber calcCurrentRevisionNumber() { + try { + return GitHistoryUtils.getCurrentRevision(myProject, filePath, "HEAD"); + } + catch (VcsException e) { + // likely the file is not under VCS anymore. + if (log.isDebugEnabled()) { + log.debug("Unable to retrieve the current revision number", e); + } + return null; + } + } + + @Override + public HistoryAsTreeProvider getHistoryAsTreeProvider() { + return null; + } + + @Override + public VcsHistorySession copy() { + return createSession(filePath, getRevisionList(), getCurrentRevisionNumber()); + } + }; + } + + @Override + public boolean getBaseVersionContent( + FilePath filePath, + Predicate processor, + final String beforeVersionId, + List warnings + ) + throws VcsException { + if (StringUtil.isEmptyOrSpaces(beforeVersionId) || filePath.getVirtualFile() == null) { + return false; + } + // apply if base revision id matches revision + final VirtualFile root = GitUtil.getGitRoot(filePath); + + final SHAHash shaHash = GitChangeUtils.commitExists(myProject, root, beforeVersionId, null, "HEAD"); + if (shaHash == null) { + throw new VcsException("Can not apply patch to " + filePath.getPath() + ".\nCan not find revision '" + beforeVersionId + "'."); + } + + final ContentRevision content = GitVcs.getInstance(myProject).getDiffProvider() + .createFileContent(new GitRevisionNumber(shaHash.getValue()), filePath.getVirtualFile()); + if (content == null) { + throw new VcsException("Can not load content of '" + filePath.getPath() + "' for revision '" + shaHash.getValue() + "'"); + } + return !processor.test(content.getContent()); + } + @Override + public void reportAppendableHistory(final FilePath path, final VcsAppendableHistorySessionPartner partner) throws VcsException { + final VcsAbstractHistorySession emptySession = createSession(path, Collections.emptyList(), null); + partner.reportCreatedEmptySession(emptySession); + + VcsConfiguration vcsConfiguration = VcsConfiguration.getInstance(myProject); + String[] additionalArgs = vcsConfiguration.LIMIT_HISTORY ? + new String[]{"--max-count=" + vcsConfiguration.MAXIMUM_HISTORY_ROWS} : + ArrayUtil.EMPTY_STRING_ARRAY; + + final GitExecutableValidator validator = GitVcs.getInstance(myProject).getExecutableValidator(); + GitHistoryUtils.history( + myProject, + refreshPath(path), + null, + partner::acceptRevision, + e -> { + if (validator.checkExecutableAndNotifyIfNeeded()) { + partner.reportException(e); + } + }, + additionalArgs + ); + } + + /** + * Refreshes the IO File inside this FilePath to let it survive moves. + */ + @Nonnull + private static FilePath refreshPath(@Nonnull FilePath path) { + VirtualFile virtualFile = path.getVirtualFile(); + if (virtualFile == null) { + return path; + } + return VcsContextFactory.getInstance().createFilePathOn(virtualFile); + } + + @Override + public boolean supportsHistoryForDirectories() { + return true; + } + + @Override + public DiffFromHistoryHandler getHistoryDiffHandler() { + return new GitDiffFromHistoryHandler(myProject); + } + + @Override + public boolean canShowHistoryFor(@Nonnull VirtualFile file) { + GitRepositoryManager manager = GitUtil.getRepositoryManager(myProject); + GitRepository repository = manager.getRepositoryForFile(file); + return repository != null && !repository.isFresh(); + } } diff --git a/plugin/src/main/java/git4idea/ui/ChangesBrowserWithRollback.java b/plugin/src/main/java/git4idea/ui/ChangesBrowserWithRollback.java index 377497b..5d2b83e 100644 --- a/plugin/src/main/java/git4idea/ui/ChangesBrowserWithRollback.java +++ b/plugin/src/main/java/git4idea/ui/ChangesBrowserWithRollback.java @@ -34,41 +34,29 @@ * After the revert completes, the changes list is automatically refreshed according to the actual changes * retrieved from the {@link ChangeListManager}. */ -public class ChangesBrowserWithRollback extends ChangesBrowser -{ - private final List myOriginalChanges; +public class ChangesBrowserWithRollback extends ChangesBrowser { + private final List myOriginalChanges; - public ChangesBrowserWithRollback(@Nonnull Project project, @Nonnull List changes) - { - super(project, null, changes, null, false, true, null, MyUseCase.LOCAL_CHANGES, null); - myOriginalChanges = changes; - RollbackDialogAction rollback = new RollbackDialogAction(); - EmptyAction.setupAction(rollback, IdeActions.CHANGES_VIEW_ROLLBACK, this); - addToolbarAction(rollback); - setChangesToDisplay(changes); - } + public ChangesBrowserWithRollback(@Nonnull Project project, @Nonnull List changes) { + super(project, null, changes, null, false, true, null, MyUseCase.LOCAL_CHANGES, null); + myOriginalChanges = changes; + RollbackDialogAction rollback = new RollbackDialogAction(); + EmptyAction.setupAction(rollback, IdeActions.CHANGES_VIEW_REVERT, this); + addToolbarAction(rollback); + setChangesToDisplay(changes); + } - @Override - public void rebuildList() - { - if(myOriginalChanges != null) - { // null is possible because rebuildList is called during initialization - myChangesToDisplay = filterActualChanges(myProject, myOriginalChanges); - } - super.rebuildList(); - } + @Override + public void rebuildList() { + if (myOriginalChanges != null) { // null is possible because rebuildList is called during initialization + myChangesToDisplay = filterActualChanges(myProject, myOriginalChanges); + } + super.rebuildList(); + } - @Nonnull - private static List filterActualChanges(@Nonnull Project project, @Nonnull List originalChanges) - { - final Collection allChanges = ChangeListManager.getInstance(project).getAllChanges(); - return ContainerUtil.filter(originalChanges, new Condition() - { - @Override - public boolean value(Change change) - { - return allChanges.contains(change); - } - }); - } + @Nonnull + private static List filterActualChanges(@Nonnull Project project, @Nonnull List originalChanges) { + Collection allChanges = ChangeListManager.getInstance(project).getAllChanges(); + return ContainerUtil.filter(originalChanges, allChanges::contains); + } } diff --git a/plugin/src/main/java/git4idea/update/GitSkippedCommits.java b/plugin/src/main/java/git4idea/update/GitSkippedCommits.java index 122b68e..0d59bd7 100644 --- a/plugin/src/main/java/git4idea/update/GitSkippedCommits.java +++ b/plugin/src/main/java/git4idea/update/GitSkippedCommits.java @@ -20,6 +20,7 @@ import consulo.language.editor.CommonDataKeys; import consulo.project.Project; import consulo.ui.ex.JBColor; +import consulo.ui.ex.action.ActionManager; import consulo.ui.ex.action.CommonShortcuts; import consulo.ui.ex.action.CustomShortcutSet; import consulo.ui.ex.action.DefaultActionGroup; @@ -29,6 +30,7 @@ import consulo.ui.ex.content.ContentManager; import consulo.util.dataholder.Key; import consulo.versionControlSystem.VcsDataKeys; +import consulo.versionControlSystem.action.VcsActions; import consulo.versionControlSystem.util.VcsUtil; import consulo.virtualFileSystem.VirtualFile; import git4idea.GitFileRevision; @@ -48,157 +50,164 @@ * The panel that displays list of skipped commits during update */ public class GitSkippedCommits extends PanelWithActionsAndCloseButton { - /** - * The current project - */ - private final Project myProject; - /** - * Tree control - */ - private final Tree myTree; - /** - * Get center component - */ - private JBScrollPane myCenterComponent; - - /** - * The constructor - * - * @param contentManager content manager - * @param project the context project - * @param skippedCommits the map with skipped commits - */ - public GitSkippedCommits(@Nonnull ContentManager contentManager, - Project project, - SortedMap> skippedCommits) { - super(contentManager, null); - myProject = project; - DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode("ROOT", true); - for (Map.Entry> e : skippedCommits.entrySet()) { - DefaultMutableTreeNode vcsRoot = new DefaultMutableTreeNode(new VcsRoot(e.getKey())); - int missed = 0; - for (GitRebaseUtils.CommitInfo c : e.getValue()) { - if (c != null) { - vcsRoot.add(new DefaultMutableTreeNode(new Commit(e.getKey(), c))); + /** + * The current project + */ + private final Project myProject; + /** + * Tree control + */ + private final Tree myTree; + /** + * Get center component + */ + private JBScrollPane myCenterComponent; + + /** + * The constructor + * + * @param contentManager content manager + * @param project the context project + * @param skippedCommits the map with skipped commits + */ + public GitSkippedCommits( + @Nonnull ContentManager contentManager, + Project project, + SortedMap> skippedCommits + ) { + super(contentManager, null); + myProject = project; + DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode("ROOT", true); + for (Map.Entry> e : skippedCommits.entrySet()) { + DefaultMutableTreeNode vcsRoot = new DefaultMutableTreeNode(new VcsRoot(e.getKey())); + int missed = 0; + for (GitRebaseUtils.CommitInfo c : e.getValue()) { + if (c != null) { + vcsRoot.add(new DefaultMutableTreeNode(new Commit(e.getKey(), c))); + } + else { + missed++; + } + } + treeRoot.add(vcsRoot); + if (missed > 0) { + vcsRoot.add(new DefaultMutableTreeNode( + "The " + missed + " commit(s) were not parsed due to unsupported rebase directory format" + )); + } } - else { - missed++; - } - } - treeRoot.add(vcsRoot); - if (missed > 0) { - vcsRoot.add(new DefaultMutableTreeNode("The " + missed + " commit(s) were not parsed due to unsupported rebase directory format")); - } + myTree = new Tree(treeRoot); + myTree.setCellRenderer(createTreeCellRenderer()); + myTree.setRootVisible(false); + myCenterComponent = new JBScrollPane(myTree); + init(); + TreeUtil.expandAll(myTree); } - myTree = new Tree(treeRoot); - myTree.setCellRenderer(createTreeCellRenderer()); - myTree.setRootVisible(false); - myCenterComponent = new JBScrollPane(myTree); - init(); - TreeUtil.expandAll(myTree); - } - - /** - * @return new cell renderer - */ - private DefaultTreeCellRenderer createTreeCellRenderer() { - return new DefaultTreeCellRenderer() { - @Override - public Component getTreeCellRendererComponent(JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) { - Component r = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); - Object o = value instanceof DefaultMutableTreeNode ? ((DefaultMutableTreeNode)value).getUserObject() : null; - if (o instanceof VcsRoot) { - r.setFont(tree.getFont().deriveFont(Font.BOLD)); - r.setForeground(sel ? textSelectionColor : textNonSelectionColor); - } - else if (o instanceof String) { - r.setForeground(sel ? textSelectionColor : JBColor.RED); - r.setFont(tree.getFont()); - } - else { - r.setForeground(sel ? textSelectionColor : textNonSelectionColor); - r.setFont(tree.getFont()); - } - return r; - } - }; - } - - @Override - protected JComponent createCenterPanel() { - return myCenterComponent; - } - - @Override - protected void addActionsTo(DefaultActionGroup group) { - super.addActionsTo(group); - ShowAllAffectedGenericAction showCommit = ShowAllAffectedGenericAction.getInstance(); - showCommit.registerCustomShortcutSet(new CustomShortcutSet(CommonShortcuts.DOUBLE_CLICK_1.getShortcuts()[0]), myTree); - group.addAction(showCommit); - - } - - @Override - public Object getData(@Nonnull Key dataId) { - if (CommonDataKeys.PROJECT == dataId) { - return myProject; + + /** + * @return new cell renderer + */ + private DefaultTreeCellRenderer createTreeCellRenderer() { + return new DefaultTreeCellRenderer() { + @Override + public Component getTreeCellRendererComponent( + JTree tree, + Object value, + boolean sel, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus + ) { + Component r = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); + Object o = value instanceof DefaultMutableTreeNode treeNode ? treeNode.getUserObject() : null; + if (o instanceof VcsRoot) { + r.setFont(tree.getFont().deriveFont(Font.BOLD)); + r.setForeground(sel ? textSelectionColor : textNonSelectionColor); + } + else if (o instanceof String) { + r.setForeground(sel ? textSelectionColor : JBColor.RED); + r.setFont(tree.getFont()); + } + else { + r.setForeground(sel ? textSelectionColor : textNonSelectionColor); + r.setFont(tree.getFont()); + } + return r; + } + }; } - TreePath selectionPath = myTree.getSelectionPath(); - DefaultMutableTreeNode node = selectionPath == null ? null : (DefaultMutableTreeNode)selectionPath.getLastPathComponent(); - Object o = node == null ? null : node.getUserObject(); - if (o instanceof Commit) { - Commit c = (Commit)o; - if (VcsDataKeys.VCS_VIRTUAL_FILE == dataId) { - return c.root; - } - if (VcsDataKeys.VCS_FILE_REVISION == dataId) { - return new GitFileRevision(myProject, VcsUtil.getFilePath(c.root.getPath()), c.commitInfo.revision); - } + + @Override + protected JComponent createCenterPanel() { + return myCenterComponent; } - return super.getData(dataId); - } - @Override - public void dispose() { - } + @Override + protected void addActionsTo(DefaultActionGroup group) { + super.addActionsTo(group); + ShowAllAffectedGenericAction showCommit = + (ShowAllAffectedGenericAction) ActionManager.getInstance().getAction(VcsActions.ACTION_SHOW_ALL_AFFECTED); + showCommit.registerCustomShortcutSet(new CustomShortcutSet(CommonShortcuts.DOUBLE_CLICK_1.getShortcuts()[0]), myTree); + group.addAction(showCommit); - /** - * Wrapper for vcs root - */ - private static class VcsRoot { - final VirtualFile root; + } - public VcsRoot(VirtualFile root) { - this.root = root; + @Override + public Object getData(@Nonnull Key dataId) { + if (CommonDataKeys.PROJECT == dataId) { + return myProject; + } + TreePath selectionPath = myTree.getSelectionPath(); + DefaultMutableTreeNode node = selectionPath == null ? null : (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); + Object o = node == null ? null : node.getUserObject(); + if (o instanceof Commit) { + Commit c = (Commit) o; + if (VcsDataKeys.VCS_VIRTUAL_FILE == dataId) { + return c.root; + } + if (VcsDataKeys.VCS_FILE_REVISION == dataId) { + return new GitFileRevision(myProject, VcsUtil.getFilePath(c.root.getPath()), c.commitInfo.revision); + } + } + return super.getData(dataId); } @Override - public String toString() { - return root.getPath(); + public void dispose() { } - } - - /** - * Wrapper for commit - */ - private static class Commit { - final VirtualFile root; - final GitRebaseUtils.CommitInfo commitInfo; - - public Commit(VirtualFile root, GitRebaseUtils.CommitInfo commitInfo) { - this.root = root; - this.commitInfo = commitInfo; + + /** + * Wrapper for vcs root + */ + private static class VcsRoot { + final VirtualFile root; + + public VcsRoot(VirtualFile root) { + this.root = root; + } + + @Override + public String toString() { + return root.getPath(); + } } - @Override - public String toString() { - return commitInfo.revision.asString().substring(0, 8) + ": " + commitInfo.subject; + /** + * Wrapper for commit + */ + private static class Commit { + final VirtualFile root; + final GitRebaseUtils.CommitInfo commitInfo; + + public Commit(VirtualFile root, GitRebaseUtils.CommitInfo commitInfo) { + this.root = root; + this.commitInfo = commitInfo; + } + + @Override + public String toString() { + return commitInfo.revision.asString().substring(0, 8) + ": " + commitInfo.subject; + } } - } } diff --git a/plugin/src/main/resources/META-INF/plugin.xml b/plugin/src/main/resources/META-INF/plugin.xml index be15c2e..08d2f6e 100644 --- a/plugin/src/main/resources/META-INF/plugin.xml +++ b/plugin/src/main/resources/META-INF/plugin.xml @@ -21,8 +21,7 @@ - +