com.intellij.openapi.vcs.VcsDataKeys Java Examples
The following examples show how to use
com.intellij.openapi.vcs.VcsDataKeys.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VcsRevisionNumberArrayRule.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public List<VcsRevisionNumber> getRevisionNumbers(@Nonnull DataProvider dataProvider) { VcsRevisionNumber revisionNumber = dataProvider.getDataUnchecked(VcsDataKeys.VCS_REVISION_NUMBER); if (revisionNumber != null) { return Collections.singletonList(revisionNumber); } ChangeList[] changeLists = dataProvider.getDataUnchecked(VcsDataKeys.CHANGE_LISTS); if (changeLists != null && changeLists.length > 0) { List<CommittedChangeList> committedChangeLists = ContainerUtil.findAll(changeLists, CommittedChangeList.class); if (!committedChangeLists.isEmpty()) { ContainerUtil.sort(committedChangeLists, CommittedChangeListByDateComparator.DESCENDING); return ContainerUtil.mapNotNull(committedChangeLists, CommittedChangeListToRevisionNumberFunction.INSTANCE); } } VcsFileRevision[] fileRevisions = dataProvider.getDataUnchecked(VcsDataKeys.VCS_FILE_REVISIONS); if (fileRevisions != null && fileRevisions.length > 0) { return ContainerUtil.mapNotNull(fileRevisions, FileRevisionToRevisionNumberFunction.INSTANCE); } return null; }
Example #2
Source File: RepositoryChangesBrowser.java From consulo with Apache License 2.0 | 6 votes |
@Override public Object getData(@Nonnull Key<?> dataId) { if (CommittedChangesBrowserUseCase.DATA_KEY == dataId) { return myUseCase; } else if (VcsDataKeys.SELECTED_CHANGES == dataId) { final List<Change> list = myViewer.getSelectedChanges(); return list.toArray(new Change[list.size()]); } else if (VcsDataKeys.CHANGE_LEAD_SELECTION == dataId) { final Change highestSelection = myViewer.getHighestLeadSelection(); return (highestSelection == null) ? new Change[]{} : new Change[]{highestSelection}; } else { final TypeSafeDataProviderAdapter adapter = new TypeSafeDataProviderAdapter(this); return adapter.getData(dataId); } }
Example #3
Source File: CommittedChangesTreeBrowser.java From consulo with Apache License 2.0 | 6 votes |
public void calcData(final Key key, final DataSink sink) { if (PlatformDataKeys.COPY_PROVIDER == key) { sink.put(PlatformDataKeys.COPY_PROVIDER, myCopyProvider); } else if (PlatformDataKeys.TREE_EXPANDER == key) { sink.put(PlatformDataKeys.TREE_EXPANDER, myTreeExpander); } else { if (VcsDataKeys.SELECTED_CHANGES == key || VcsDataKeys.CHANGE_LEAD_SELECTION == key || CommittedChangesBrowserUseCase.DATA_KEY == key) { final Object data = myDetailsView.getData(key); if (data != null) { sink.put(key, data); } } } }
Example #4
Source File: CreatePatchFromChangesAction.java From consulo with Apache License 2.0 | 6 votes |
public void actionPerformed(AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); final Change[] changes = e.getData(VcsDataKeys.CHANGES); if ((changes == null) || (changes.length == 0)) return; String commitMessage = null; ShelvedChangeList[] shelvedChangeLists = e.getData(ShelvedChangesViewManager.SHELVED_CHANGELIST_KEY); if (shelvedChangeLists != null && shelvedChangeLists.length > 0) { commitMessage = shelvedChangeLists [0].DESCRIPTION; } else { ChangeList[] changeLists = e.getData(VcsDataKeys.CHANGE_LISTS); if (changeLists != null && changeLists.length > 0) { commitMessage = changeLists [0].getComment(); } } if (commitMessage == null) { commitMessage = e.getData(VcsDataKeys.PRESET_COMMIT_MESSAGE); } if (commitMessage == null) { commitMessage = ""; } List<Change> changeCollection = new ArrayList<Change>(); Collections.addAll(changeCollection, changes); createPatch(project, commitMessage, changeCollection); }
Example #5
Source File: MoveChangesToAnotherListAction.java From consulo with Apache License 2.0 | 6 votes |
public void actionPerformed(@Nonnull AnActionEvent e) { Project project = e.getRequiredData(CommonDataKeys.PROJECT); List<Change> changesList = ContainerUtil.newArrayList(); Change[] changes = e.getData(VcsDataKeys.CHANGES); if (changes != null) { ContainerUtil.addAll(changesList, changes); } List<VirtualFile> unversionedFiles = ContainerUtil.newArrayList(); final List<VirtualFile> changedFiles = ContainerUtil.newArrayList(); VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY); if (files != null) { changesList.addAll(getChangesForSelectedFiles(project, files, unversionedFiles, changedFiles)); } if (changesList.isEmpty() && unversionedFiles.isEmpty()) { VcsBalloonProblemNotifier.showOverChangesView(project, "Nothing is selected that can be moved", MessageType.INFO); return; } if (!askAndMove(project, changesList, unversionedFiles)) return; if (!changedFiles.isEmpty()) { selectAndShowFile(project, changedFiles.get(0)); } }
Example #6
Source File: RollbackDialogAction.java From consulo with Apache License 2.0 | 6 votes |
public void actionPerformed(AnActionEvent e) { FileDocumentManager.getInstance().saveAllDocuments(); Change[] changes = e.getData(VcsDataKeys.CHANGES); Project project = e.getData(CommonDataKeys.PROJECT); final ChangesBrowserBase browser = e.getData(ChangesBrowserBase.DATA_KEY); if (browser != null) { browser.setDataIsDirty(true); } RollbackChangesDialog.rollbackChanges(project, Arrays.asList(changes), true, new Runnable() { public void run() { if (browser != null) { browser.rebuildList(); browser.setDataIsDirty(false); } } }); }
Example #7
Source File: ChangelistDescriptionAction.java From p4ic4idea with Apache License 2.0 | 6 votes |
private Pair<OptionalClientServerConfig, P4ChangelistId> findAttachedFileRevision(AnActionEvent e) { final VirtualFile file; { final Boolean nonLocal = e.getData(VcsDataKeys.VCS_NON_LOCAL_HISTORY_SESSION); if (Boolean.TRUE.equals(nonLocal)) { LOG.info("non-local VCS history session; ignoring changelist description action"); return null; } file = e.getData(VcsDataKeys.VCS_VIRTUAL_FILE); if (file == null || file.isDirectory()) { LOG.info("No VCS virtual file associated with changelist description action; ignoring request."); return null; } } final VcsFileRevision revision = e.getData(VcsDataKeys.VCS_FILE_REVISION); if (!(revision instanceof P4HistoryVcsFileRevision)) { LOG.info("No file revision associated with file " + file); return null; } P4HistoryVcsFileRevision history = (P4HistoryVcsFileRevision) revision; return Pair.create(new OptionalClientServerConfig(history.getClientConfig()), history.getChangelistId()); }
Example #8
Source File: GitDiffProvider.java From review-board-idea-plugin with Apache License 2.0 | 6 votes |
@Override public String generateDiff(Project project, AnActionEvent action) throws VcsException { String diffContent; VcsRevisionNumber[] data = action.getData(VcsDataKeys.VCS_REVISION_NUMBERS); if (data != null) { diffContent = fromRevisions(project, project.getBaseDir(), data[data.length - 1], data[0]); } else { final Change[] changes = action.getData(VcsDataKeys.CHANGES); // if (changes == null) { // return null; // } List<VirtualFile> virtualFiles = new ArrayList<>(); // for (Change change : changes) { // if (change.getVirtualFile() != null) { // virtualFiles.add(change.getVirtualFile()); // } // } diffContent = fromHead(project, project.getBaseDir(), virtualFiles); } return diffContent; }
Example #9
Source File: CopyRevisionNumberAction.java From consulo with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(AnActionEvent e) { VcsRevisionNumber revision = e.getData(VcsDataKeys.VCS_REVISION_NUMBER); if (revision == null) { VcsFileRevision fileRevision = e.getData(VcsDataKeys.VCS_FILE_REVISION); if (fileRevision != null) { revision = fileRevision.getRevisionNumber(); } } if (revision == null) { return; } String rev = revision instanceof ShortVcsRevisionNumber ? ((ShortVcsRevisionNumber)revision).toShortString() : revision.asString(); CopyPasteManager.getInstance().setContents(new StringSelection(rev)); }
Example #10
Source File: SelectWorkItemsAction.java From azure-devops-intellij with MIT License | 6 votes |
@Override public void actionPerformed(AnActionEvent anActionEvent) { final DataContext dc = anActionEvent.getDataContext(); final Project project = CommonDataKeys.PROJECT.getData(dc); final Refreshable panel = CheckinProjectPanel.PANEL_KEY.getData(dc); final CommitMessageI commitMessageI = (panel instanceof CommitMessageI) ? (CommitMessageI) panel : VcsDataKeys.COMMIT_MESSAGE_CONTROL.getData(dc); if (commitMessageI != null && project != null) { String commitMessage = ""; // Attempt to append the message instead of overwriting it if (commitMessageI instanceof CommitChangeListDialog) { commitMessage = ((CommitChangeListDialog) commitMessageI).getCommitMessage(); } SelectWorkItemsDialog dialog = new SelectWorkItemsDialog(project); if (dialog.showAndGet()) { if (StringUtils.isNotEmpty(commitMessage)) { commitMessage += "\n" + dialog.getComment(); } else { commitMessage = dialog.getComment(); } commitMessageI.setCommitMessage(commitMessage); } } }
Example #11
Source File: GetCommitMessageAction.java From GitCommitMessage with Apache License 2.0 | 5 votes |
@Nullable private static CommitMessageI getCommitPanel(@Nullable AnActionEvent e) { if (e == null) { return null; } Refreshable data = Refreshable.PANEL_KEY.getData(e.getDataContext()); if (data instanceof CommitMessageI) { return (CommitMessageI) data; } return VcsDataKeys.COMMIT_MESSAGE_CONTROL.getData(e.getDataContext()); }
Example #12
Source File: ChangesBrowserBase.java From consulo with Apache License 2.0 | 5 votes |
public void setSelected(AnActionEvent e, boolean state) { T change = ObjectUtils.tryCast(e.getData(VcsDataKeys.CURRENT_CHANGE), myClass); if (change == null) return; if (state) { myViewer.includeChange(change); } else { myViewer.excludeChange(change); } }
Example #13
Source File: ShowDiffWithLocalAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void update(@Nonnull AnActionEvent e) { VcsFileRevision[] selectedRevisions = e.getData(VcsDataKeys.VCS_FILE_REVISIONS); VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE); VcsHistorySession historySession = e.getData(VcsDataKeys.HISTORY_SESSION); e.getPresentation().setVisible(true); e.getPresentation().setEnabled(selectedRevisions != null && selectedRevisions.length == 1 && virtualFile != null && historySession != null && historySession.getCurrentRevisionNumber() != null && historySession.isContentAvailable(selectedRevisions[0]) && e.getData(VcsDataKeys.FILE_PATH) != null && e.getData(VcsDataKeys.HISTORY_PROVIDER) != null && e.getData(CommonDataKeys.PROJECT) != null); }
Example #14
Source File: OpenRepositoryVersionAction.java From consulo with Apache License 2.0 | 5 votes |
public void update(final AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); Change[] changes = e.getData(VcsDataKeys.SELECTED_CHANGES); e.getPresentation().setEnabled(project != null && changes != null && (! CommittedChangesBrowserUseCase.IN_AIR.equals(e.getDataContext().getData(CommittedChangesBrowserUseCase.DATA_KEY))) && hasValidChanges(changes) && ModalityState.NON_MODAL.equals(ModalityState.current())); }
Example #15
Source File: RevertSelectedChangesAction.java From consulo with Apache License 2.0 | 5 votes |
private static boolean allSelectedChangeListsAreRevertable(AnActionEvent e) { ChangeList[] changeLists = e.getData(VcsDataKeys.CHANGE_LISTS); if (changeLists == null) { return true; } for (ChangeList list : changeLists) { if (list instanceof CommittedChangeList) { if (!((CommittedChangeList)list).isModifiable()) { return false; } } } return true; }
Example #16
Source File: RevertSelectedChangesAction.java From consulo with Apache License 2.0 | 5 votes |
public RevertSelectedChangesAction() { super(e -> e.getData(VcsDataKeys.SELECTED_CHANGES_IN_DETAILS), e -> { // to ensure directory flags for SVN are initialized e.getData(VcsDataKeys.CHANGES_WITH_MOVED_CHILDREN); return e.getData(VcsDataKeys.SELECTED_CHANGES_IN_DETAILS); }); }
Example #17
Source File: SetDefaultChangeListAction.java From consulo with Apache License 2.0 | 5 votes |
public void update(AnActionEvent e) { ChangeList[] lists = e.getData(VcsDataKeys.CHANGE_LISTS); final boolean visible = lists != null && lists.length == 1 && lists[0] instanceof LocalChangeList && !((LocalChangeList)lists[0]).isDefault(); if (e.getPlace().equals(ActionPlaces.CHANGES_VIEW_POPUP)) e.getPresentation().setVisible(visible); else e.getPresentation().setEnabled(visible); }
Example #18
Source File: ShowDiffWithLocalAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(@Nonnull AnActionEvent e) { Project project = e.getRequiredData(CommonDataKeys.PROJECT); if (ChangeListManager.getInstance(project).isFreezedWithNotification(null)) return; VcsRevisionNumber currentRevisionNumber = e.getRequiredData(VcsDataKeys.HISTORY_SESSION).getCurrentRevisionNumber(); VcsFileRevision selectedRevision = e.getRequiredData(VcsDataKeys.VCS_FILE_REVISIONS)[0]; FilePath filePath = e.getRequiredData(VcsDataKeys.FILE_PATH); if (currentRevisionNumber != null && selectedRevision != null) { DiffFromHistoryHandler diffHandler = ObjectUtil.notNull(e.getRequiredData(VcsDataKeys.HISTORY_PROVIDER).getHistoryDiffHandler(), new StandardDiffFromHistoryHandler()); diffHandler.showDiffForTwo(project, filePath, selectedRevision, new CurrentRevision(filePath.getVirtualFile(), currentRevisionNumber)); } }
Example #19
Source File: CreatePatchFromChangesAction.java From consulo with Apache License 2.0 | 5 votes |
public void update(final AnActionEvent e) { final Boolean haveSelectedChanges = e.getData(VcsDataKeys.HAVE_SELECTED_CHANGES); Change[] changes; ChangeList[] data1 = e.getData(VcsDataKeys.CHANGE_LISTS); ShelvedChangeList[] data2 = e.getData(ShelvedChangesViewManager.SHELVED_CHANGELIST_KEY); ShelvedChangeList[] data3 = e.getData(ShelvedChangesViewManager.SHELVED_RECYCLED_CHANGELIST_KEY); int sum = data1 == null ? 0 : data1.length; sum += data2 == null ? 0 : data2.length; sum += data3 == null ? 0 : data3.length; e.getPresentation().setEnabled(Boolean.TRUE.equals(haveSelectedChanges) && (sum == 1) && ((changes = e.getData(VcsDataKeys.CHANGES)) != null && changes.length > 0)); }
Example #20
Source File: MoveChangesToAnotherListAction.java From consulo with Apache License 2.0 | 5 votes |
protected boolean isEnabled(@Nonnull AnActionEvent e) { Project project = e.getData(CommonDataKeys.PROJECT); if (project == null || !ProjectLevelVcsManager.getInstance(project).hasActiveVcss()) { return false; } return !VcsUtil.isEmpty(e.getData(ChangesListView.UNVERSIONED_FILES_DATA_KEY)) || !ArrayUtil.isEmpty(e.getData(VcsDataKeys.CHANGES)) || !ArrayUtil.isEmpty(e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY)); }
Example #21
Source File: RollbackDialogAction.java From consulo with Apache License 2.0 | 5 votes |
public void update(AnActionEvent e) { Change[] changes = e.getData(VcsDataKeys.CHANGES); Project project = e.getData(CommonDataKeys.PROJECT); boolean enabled = changes != null && project != null; e.getPresentation().setEnabled(enabled); if (enabled) { String operationName = RollbackUtil.getRollbackOperationName(project); e.getPresentation().setText(operationName); e.getPresentation().setDescription(operationName + " selected changes"); } }
Example #22
Source File: ShowDiffAction.java From consulo with Apache License 2.0 | 5 votes |
public void update(@Nonnull AnActionEvent e) { Change[] changes = e.getData(VcsDataKeys.CHANGES); Project project = e.getData(CommonDataKeys.PROJECT); if (ActionPlaces.MAIN_MENU.equals(e.getPlace())) { e.getPresentation().setEnabled(project != null && changes != null && changes.length > 0); } else { e.getPresentation().setEnabled(project != null && canShowDiff(project, changes)); } }
Example #23
Source File: RenameChangeListAction.java From consulo with Apache License 2.0 | 5 votes |
public void update(AnActionEvent e) { ChangeList[] lists = e.getData(VcsDataKeys.CHANGE_LISTS); final boolean visible = lists != null && lists.length == 1 && lists[0] instanceof LocalChangeList && !((LocalChangeList)lists[0]).isReadOnly(); if (e.getPlace().equals(ActionPlaces.CHANGES_VIEW_POPUP)) e.getPresentation().setVisible(visible); else e.getPresentation().setEnabled(visible); }
Example #24
Source File: RemoveChangeListAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void update(@Nonnull AnActionEvent e) { ChangeList[] changeLists = e.getData(VcsDataKeys.CHANGE_LISTS); boolean visible = canRemoveChangeLists(e.getProject(), changeLists); Presentation presentation = e.getPresentation(); presentation.setEnabled(visible); presentation .setText(ActionsBundle.message("action.ChangesView.RemoveChangeList.text", changeLists != null && changeLists.length > 1 ? 1 : 0)); if (e.getPlace().equals(ActionPlaces.CHANGES_VIEW_POPUP)) { presentation.setVisible(visible); } presentation.setDescription(ArrayUtil.isEmpty(e.getData(VcsDataKeys.CHANGES)) ? presentation.getText() : getDescription(changeLists)); }
Example #25
Source File: RemoveChangeListAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(@Nonnull AnActionEvent e) { final Project project = e.getRequiredData(CommonDataKeys.PROJECT); final ChangeList[] selectedLists = e.getRequiredData(VcsDataKeys.CHANGE_LISTS); //noinspection unchecked ChangeListRemoveConfirmation.processLists(project, true, (Collection)Arrays.asList(selectedLists), new ChangeListRemoveConfirmation() { @Override public boolean askIfShouldRemoveChangeLists(@Nonnull List<? extends LocalChangeList> lists) { return RemoveChangeListAction.askIfShouldRemoveChangeLists(lists, project); } }); }
Example #26
Source File: ChangeListViewerDialog.java From consulo with Apache License 2.0 | 5 votes |
public Object getData(@Nonnull @NonNls final Key<?> dataId) { if (VcsDataKeys.CHANGES == dataId) { return myChanges; } else if (VcsDataKeys.VCS_REVISION_NUMBER == dataId) { if (myChangeList instanceof VcsRevisionNumberAware) { return ((VcsRevisionNumberAware)myChangeList).getRevisionNumber(); } } return null; }
Example #27
Source File: ChangesBrowserBase.java From consulo with Apache License 2.0 | 5 votes |
public void calcData(Key<?> key, DataSink sink) { if (key == VcsDataKeys.CHANGES) { List<Change> list = getSelectedChanges(); if (list.isEmpty()) list = getAllChanges(); sink.put(VcsDataKeys.CHANGES, list.toArray(new Change[list.size()])); } else if (key == VcsDataKeys.CHANGES_SELECTION) { sink.put(VcsDataKeys.CHANGES_SELECTION, getChangesSelection()); } else if (key == VcsDataKeys.CHANGE_LISTS) { sink.put(VcsDataKeys.CHANGE_LISTS, getSelectedChangeLists()); } else if (key == VcsDataKeys.CHANGE_LEAD_SELECTION) { final Change highestSelection = ObjectUtils.tryCast(myViewer.getHighestLeadSelection(), Change.class); sink.put(VcsDataKeys.CHANGE_LEAD_SELECTION, (highestSelection == null) ? new Change[]{} : new Change[]{highestSelection}); } else if (key == CommonDataKeys.VIRTUAL_FILE_ARRAY) { sink.put(CommonDataKeys.VIRTUAL_FILE_ARRAY, getSelectedFiles().toArray(VirtualFile[]::new)); } else if (key == CommonDataKeys.NAVIGATABLE_ARRAY) { sink.put(CommonDataKeys.NAVIGATABLE_ARRAY, getNavigatableArray(myProject, getSelectedFiles())); } else if (VcsDataKeys.IO_FILE_ARRAY.equals(key)) { sink.put(VcsDataKeys.IO_FILE_ARRAY, getSelectedIoFiles()); } else if (key == DATA_KEY) { sink.put(DATA_KEY, this); } else if (VcsDataKeys.SELECTED_CHANGES_IN_DETAILS.equals(key)) { final List<Change> selectedChanges = getSelectedChanges(); sink.put(VcsDataKeys.SELECTED_CHANGES_IN_DETAILS, selectedChanges.toArray(new Change[selectedChanges.size()])); } else if (UNVERSIONED_FILES_DATA_KEY.equals(key)) { sink.put(UNVERSIONED_FILES_DATA_KEY, getVirtualFiles(myViewer.getSelectionPaths(), UNVERSIONED_FILES_TAG)); } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.equals(key)) { sink.put(PlatformDataKeys.DELETE_ELEMENT_PROVIDER, myDeleteProvider); } }
Example #28
Source File: RepositoryChangesBrowser.java From consulo with Apache License 2.0 | 5 votes |
@Override protected Navigatable[] getNavigatables(final DataContext dataContext) { Change[] changes = dataContext.getData(VcsDataKeys.SELECTED_CHANGES); if (changes != null) { Collection<Change> changeCollection = Arrays.asList(changes); return ChangesUtil.getNavigatableArray(myProject, ChangesUtil.getFilesFromChanges(changeCollection)); } return null; }
Example #29
Source File: SvnDiffProvider.java From review-board-idea-plugin with Apache License 2.0 | 5 votes |
@Override public boolean isFromRevision(Project project, AnActionEvent action) throws VcsException { ChangeList[] data = action.getData(VcsDataKeys.CHANGE_LISTS); if (data != null && data.length > 0 && data[0] instanceof CommittedChangeList) { return true; } else { return false; } }
Example #30
Source File: SvnDiffProvider.java From review-board-idea-plugin with Apache License 2.0 | 5 votes |
@Override public String generateDiff(Project project, AnActionEvent action) throws VcsException { String diffContent; if (isFromRevision(project, action)) { ChangeList[] data = action.getData(VcsDataKeys.CHANGE_LISTS); diffContent = fromRevisions(project, project.getBaseDir(), ((CommittedChangeList) data[data.length - 1]).getNumber(), ((CommittedChangeList) data[0]).getNumber()); } else { final Change[] changes = action.getData(VcsDataKeys.CHANGES); diffContent = fromHead(project, project.getBaseDir(), changes); } return diffContent; }