<projectSetProcessor implementation="com.intellij.openapi.vcs.OpenProjectSetProcessor"/>
<getDataRule key="VCS_REVISION_NUMBERS" implementationClass="com.intellij.openapi.vcs.history.VcsRevisionNumberArrayRule"/>
+ <getDataRule key="vcs.ChangesSelection" implementationClass="com.intellij.openapi.vcs.changes.VcsChangesSelectionRule"/>
<jbProtocolCommand implementation="com.intellij.openapi.vcs.checkout.JBProtocolCheckoutCommand"/>
</extensions>
</idea-plugin>
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.changes.ChangeList;
import com.intellij.openapi.vcs.changes.ChangeRequestChain;
+import com.intellij.openapi.vcs.changes.ChangesSelection;
import com.intellij.openapi.vcs.history.VcsFileRevision;
import com.intellij.openapi.vcs.history.VcsHistoryProvider;
import com.intellij.openapi.vcs.history.VcsHistorySession;
DataKey<ChangeList[]> CHANGE_LISTS = DataKey.create("vcs.ChangeList");
DataKey<Change> CURRENT_CHANGE = DataKey.create("vcs.CurrentChange");
DataKey<Change[]> CHANGES = DataKey.create("vcs.Change");
+ DataKey<ChangesSelection> CHANGES_SELECTION = DataKey.create("vcs.ChangesSelection");
DataKey<Change[]> CHANGES_WITH_MOVED_CHILDREN = DataKey.create("ChangeListView.ChangesWithDetails");
DataKey<Change[]> SELECTED_CHANGES_IN_DETAILS = DataKey.create("ChangeListView.SelectedChangesWithMovedSubtrees");
@NonNls DataKey<List<Change>> CHANGES_IN_LIST_KEY = DataKey.create("ChangeListView.ChangesInList");
--- /dev/null
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.openapi.vcs.changes;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
+public class ChangesSelection {
+ @NotNull private final List<Change> myChanges;
+ private final int myIndex;
+
+ public ChangesSelection(@NotNull List<Change> changes, int index) {
+ myChanges = changes;
+ myIndex = index;
+ }
+
+ @NotNull
+ public List<Change> getChanges() {
+ return myChanges;
+ }
+
+ public int getIndex() {
+ return myIndex;
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.openapi.vcs.changes;
+
+import com.intellij.ide.impl.dataRules.GetDataRule;
+import com.intellij.openapi.actionSystem.DataProvider;
+import com.intellij.openapi.vcs.VcsDataKeys;
+import com.intellij.util.ArrayUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+public class VcsChangesSelectionRule implements GetDataRule {
+ @Nullable
+ @Override
+ public Object getData(DataProvider dataProvider) {
+ return getChangesSelection(dataProvider);
+ }
+
+ @Nullable
+ public ChangesSelection getChangesSelection(@NotNull DataProvider dataProvider) {
+ Change currentChange = VcsDataKeys.CURRENT_CHANGE.getData(dataProvider);
+
+ Change[] selectedChanges = VcsDataKeys.SELECTED_CHANGES.getData(dataProvider);
+ if (selectedChanges != null) {
+ int index = Math.max(ArrayUtil.indexOf(selectedChanges, currentChange), 0);
+ return new ChangesSelection(Arrays.asList(selectedChanges), index);
+ }
+
+ Change[] changes = VcsDataKeys.CHANGES.getData(dataProvider);
+ if (changes != null) {
+ int index = Math.max(ArrayUtil.indexOf(changes, currentChange), 0);
+ return new ChangesSelection(Arrays.asList(changes), index);
+ }
+
+ if (currentChange != null) {
+ return new ChangesSelection(Collections.singletonList(currentChange), 0);
+ }
+ return null;
+ }
+}
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.VcsDataKeys;
-import com.intellij.openapi.vcs.changes.Change;
-import com.intellij.openapi.vcs.changes.ChangeListManager;
-import com.intellij.openapi.vcs.changes.ContentRevision;
-import com.intellij.openapi.vcs.changes.CurrentContentRevision;
+import com.intellij.openapi.vcs.changes.*;
import com.intellij.openapi.vcs.changes.committed.CommittedChangesBrowserUseCase;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
-import static com.intellij.openapi.vcs.changes.actions.diff.ShowDiffAction.*;
+import static com.intellij.openapi.vcs.changes.actions.diff.ShowDiffAction.showDiffForChange;
/**
* @author yole
public void actionPerformed(AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
if (ChangeListManager.getInstance(project).isFreezedWithNotification(null)) return;
- Change[] changes = e.getData(VcsDataKeys.CHANGES);
- assert changes != null;
+ ChangesSelection selection = e.getRequiredData(VcsDataKeys.CHANGES_SELECTION);
+
+ int index = 0;
List<Change> changesToLocal = new ArrayList<Change>();
- for(Change change: changes) {
- ContentRevision afterRevision = change.getAfterRevision();
+ for (int i = 0; i < selection.getChanges().size(); i++) {
+ if (i == selection.getIndex()) index = changesToLocal.size();
+ ContentRevision afterRevision = selection.getChanges().get(i).getAfterRevision();
if (afterRevision != null && isValidAfterRevision(afterRevision)) {
changesToLocal.add(new Change(afterRevision, CurrentContentRevision.create(afterRevision.getFile())));
}
}
if (!changesToLocal.isEmpty()) {
- showDiffForChange(project, changesToLocal, 0);
+ showDiffForChange(project, changesToLocal, index);
}
}
public void update(final AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
- Change[] changes = e.getData(VcsDataKeys.CHANGES);
+ ChangesSelection selection = e.getData(VcsDataKeys.CHANGES_SELECTION);
+ boolean isInAir = CommittedChangesBrowserUseCase.IN_AIR.equals(CommittedChangesBrowserUseCase.DATA_KEY.getData(e.getDataContext()));
- e.getPresentation().setEnabled(project != null && changes != null &&
- (! CommittedChangesBrowserUseCase.IN_AIR
- .equals(CommittedChangesBrowserUseCase.DATA_KEY.getData(e.getDataContext()))) &&
- anyHasAfterRevision(changes));
+ e.getPresentation().setEnabled(project != null && selection != null && !isInAir && anyHasAfterRevision(selection.getChanges()));
}
- private static boolean isValidAfterRevision(final ContentRevision afterRevision) {
+ private static boolean isValidAfterRevision(@Nullable final ContentRevision afterRevision) {
return afterRevision != null && !afterRevision.getFile().isNonLocal() && !afterRevision.getFile().isDirectory();
}
- private static boolean anyHasAfterRevision(final Change[] changes) {
- for(Change c: changes) {
+ private static boolean anyHasAfterRevision(@NotNull final List<Change> changes) {
+ for (Change c : changes) {
if (isValidAfterRevision(c.getAfterRevision())) {
return true;
}
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
}
protected static boolean canShowDiff(@Nullable Project project, @Nullable Change[] changes) {
- if (changes == null || changes.length == 0) return false;
+ return changes != null && canShowDiff(project, Arrays.asList(changes));
+ }
+
+ protected static boolean canShowDiff(@Nullable Project project, @Nullable List<Change> changes) {
+ if (changes == null || changes.size() == 0) return false;
for (Change change : changes) {
if (ChangeDiffRequestProducer.canCreate(project, change)) return true;
}
*/
package com.intellij.openapi.vcs.changes.ui;
+import com.intellij.diff.DiffDialogHints;
+import com.intellij.diff.util.DiffUserDataKeysEx;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ex.CheckboxAction;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
-import com.intellij.diff.DiffDialogHints;
-import com.intellij.diff.util.DiffUserDataKeysEx;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.VcsDataKeys;
protected Runnable getDoubleClickHandler() {
return new Runnable() {
public void run() {
- showDiff();
+ showDiff(getChangesSelection());
}
};
}
if (key == VcsDataKeys.CHANGES) {
List<Change> list = myViewer.getSelectedChanges();
if (list.isEmpty()) list = myViewer.getChanges();
- sink.put(VcsDataKeys.CHANGES, list.toArray(new Change [list.size()]));
+ 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());
protected void updateDiffContext(@NotNull ShowDiffContext context) {
}
- private void showDiff() {
+ private void showDiff(@NotNull ChangesSelection selection) {
+ List<Change> changes = selection.getChanges();
+
+ Change[] changesArray = changes.toArray(new Change[changes.size()]);
+ showDiffForChanges(changesArray, selection.getIndex());
+
+ afterDiffRefresh();
+ }
+
+ @NotNull
+ protected ChangesSelection getChangesSelection() {
final Change leadSelection = myViewer.getLeadSelection();
List<Change> changes = myViewer.getSelectedChanges();
if (changes.size() < 2) {
- changes = myViewer.getChanges();
+ List<Change> allChanges = myViewer.getChanges();
+ if (allChanges.size() > 1) {
+ changes = allChanges;
+ }
}
- Change[] changesArray = changes.toArray(new Change[changes.size()]);
-
if (leadSelection != null) {
int indexInSelection = changes.indexOf(leadSelection);
if (indexInSelection == -1) {
- showDiffForChanges(new Change[]{leadSelection}, 0);
+ return new ChangesSelection(Collections.singletonList(leadSelection), 0);
}
else {
- showDiffForChanges(changesArray, indexInSelection);
+ return new ChangesSelection(changes, indexInSelection);
}
}
else {
- showDiffForChanges(changesArray, 0);
+ return new ChangesSelection(changes, 0);
}
-
- afterDiffRefresh();
}
protected void afterDiffRefresh() {
protected void buildToolBar(final DefaultActionGroup toolBarGroup) {
myDiffAction = new ShowDiffAction() {
public void update(AnActionEvent e) {
- Change[] changes = e.getData(VcsDataKeys.CHANGES);
- e.getPresentation().setEnabled(canShowDiff(myProject, changes));
+ ChangesSelection selection = e.getData(VcsDataKeys.CHANGES_SELECTION);
+ e.getPresentation().setEnabled(selection != null && canShowDiff(myProject, selection.getChanges()));
}
public void actionPerformed(AnActionEvent e) {
- showDiff(); // todo here
+ showDiff(e.getRequiredData(VcsDataKeys.CHANGES_SELECTION));
}
};
myDiffAction.registerCustomShortcutSet(CommonShortcuts.getDiff(), myViewer);