Getting selected revisions from the vcs history view

Another vcs history question...

I'm implementing an additional action that is returned via VcsHistoryProvider.getAdditionalActions

What I'd like this action to do, in part, is get the selected revisions from the revision list. For example, this action is only applicable when 1 or 2 revisions are selected (just like the "compare" action). Therefore as part of the code I would like to evaluate the number of selected objects and eventually use those objects in my plugin.

How might I go about doing this? The only applicable DataKey I've found so far is VcsDataKeys.VCS_FILE_REVISION, but that only returns one VcsFileRevision object, not an array representing all selections.

I've also tried to get at the data via AnActionEvent.getData(DataKeys.CONTEXT_COMPONENT), which returns a DualView object with getSelection() returning a list, however I'm getting a CastClassException trying the following:
(DualView)event.getData(DataKeys.CONTEXT_COMPONENT);

Error message: java.lang.ClassCastException: com.intellij.ui.dualView.DualView$5 cannot be cast to com.intellij.ui.dualView.DualView

I'm heading down the wrong path it seems.

5 comments

Any ideas? Am I simply casting DualView incorrectly? Or perhaps is there a better way to get the selected revisions?

0

Hello lstahlm,

Any ideas? Am I simply casting DualView incorrectly? Or perhaps is
there a better way to get the selected revisions?


Right now there's no good API for that. I can add a DataKey for that in 7.0.3
if that will be OK for your plugin, or I can describe the hacky way to do
this which is available in the current version.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Dmitry,

That would be great. I think I found a "hacky" way to do it, but a DataKey would be much preferred.

I had some fun with the debugger and found this seemed to do the trick:
((DualView)event.getData(DataKeys.CONTENT_MANAGER).getContents()[0].getComponent().getComponentAt(50,50).getComponentAt(30,30)).getSelection()

...but I'm too scared to actually use that in any sort of production code. :)

0

Hello lstahlm,

That would be great. I think I found a "hacky" way to do it, but a
DataKey would be much preferred.


OK, I'll add one.


I had some fun with the debugger and found this seemed to do the
trick:

((DualView)event.getData(DataKeys.CONTENT_MANAGER).getContents()[0].ge
tComponent().getComponentAt(50,50).getComponentAt(30,30)).getSelection
()

..but I'm too scared to actually use that in any sort of production
code. :)


Oh, that's too scary. :)

FileHistoryPanelImpl panel = (FileHistoryPanelImpl) event.getData(VcsDataConstants.FILE_HISTORY_PANEL);
for(Object o: panel.getSelection()) {
revisions.add(((TreeNodeOnVcsRevision) o).myRevision);
}

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

That's definitely more usable. I'll use it for testing until 7.0.3 comes out.

Thanks for the help.

0

Please sign in to leave a comment.