summaryrefslogtreecommitdiff
path: root/platform/vcs-impl
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2013-07-08 11:26:24 -0700
committerTor Norbye <tnorbye@google.com>2013-07-08 11:26:24 -0700
commitc1ace1f7e1e49c81bb4b75377c99f07be340abfe (patch)
tree9d0db96bd3d86ddfec80e7e3554cad9dcc066553 /platform/vcs-impl
parentc6218e46d5d2017e987ecdbd99b318a95c42abc0 (diff)
downloadidea-c1ace1f7e1e49c81bb4b75377c99f07be340abfe.tar.gz
Snapshot aea001abfc1b38fec3a821bcd5174cc77dc75787 from master branch of git://git.jetbrains.org/idea/community.git
Change-Id: Icdea2a2bd7ad43b4d05967b1f0479db3bda1c93c
Diffstat (limited to 'platform/vcs-impl')
-rw-r--r--platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java62
-rw-r--r--platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/WarnOnDeletion.java46
-rw-r--r--platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java30
-rw-r--r--platform/vcs-impl/src/com/intellij/openapi/vcs/actions/SelectedBlockHistoryAction.java1
-rw-r--r--platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/DeleteUnversionedFilesAction.java4
-rw-r--r--platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsHistoryDialog.java28
-rw-r--r--platform/vcs-impl/src/com/intellij/openapi/vcs/impl/DefaultVcsRootPolicy.java2
7 files changed, 155 insertions, 18 deletions
diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java
index 1ac6b8b7e46c..aea844d201c6 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/DirDiffTableModel.java
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.diff.impl.dir;
+import com.intellij.CommonBundle;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.diff.*;
import com.intellij.openapi.Disposable;
@@ -23,8 +24,11 @@ import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.diff.impl.dir.actions.popup.WarnOnDeletion;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.MessageType;
+import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.Condition;
@@ -755,6 +759,9 @@ public class DirDiffTableModel extends AbstractTableModel implements DirDiffMode
}
public void synchronizeSelected() {
+ if (!checkCanDelete()) {
+ return;
+ }
rememberSelection();
for (DirDiffElementImpl element : getSelectedElements()) {
syncElement(element);
@@ -769,12 +776,67 @@ public class DirDiffTableModel extends AbstractTableModel implements DirDiffMode
}
public void synchronizeAll() {
+ if (!checkCanDelete()) {
+ return;
+ }
for (DirDiffElementImpl element : myElements.toArray(new DirDiffElementImpl[myElements.size()])) {
syncElement(element);
}
selectFirstRow();
}
+ private boolean checkCanDelete() {
+ if (WarnOnDeletion.isWarnWhenDeleteItems()) {
+ int count = 0;
+ for (DirDiffElementImpl element : myElements) {
+ if (element.getOperation() == DirDiffOperation.DELETE) {
+ count++;
+ }
+ }
+ if (count > 0) {
+ if (!confirmDeletion(count)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private static boolean confirmDeletion(int count) {
+ DialogWrapper.DoNotAskOption option = new DialogWrapper.DoNotAskOption() {
+ @Override
+ public boolean isToBeShown() {
+ return WarnOnDeletion.isWarnWhenDeleteItems();
+ }
+
+ @Override
+ public void setToBeShown(boolean value, int exitCode) {
+ WarnOnDeletion.setWarnWhenDeleteItems(value);
+ }
+
+ @Override
+ public boolean canBeHidden() {
+ return true;
+ }
+
+ @Override
+ public boolean shouldSaveOptionsOnCancel() {
+ return true;
+ }
+
+ @Override
+ public String getDoNotShowMessage() {
+ return "Do not ask me again";
+ }
+ };
+
+ return DialogWrapper.OK_EXIT_CODE == Messages.showYesNoDialog("Delete " + count + " items?", "Confirm Delete",
+ "Delete",
+ CommonBundle.message("button.cancel"),
+ Messages.getQuestionIcon(),
+ option);
+ }
+
private void syncElement(DirDiffElementImpl element) {
final DirDiffOperation operation = element.getOperation();
if (operation == null) return;
diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/WarnOnDeletion.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/WarnOnDeletion.java
new file mode 100644
index 000000000000..92dc87016add
--- /dev/null
+++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/dir/actions/popup/WarnOnDeletion.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2000-2013 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.diff.impl.dir.actions.popup;
+
+import com.intellij.ide.util.PropertiesComponent;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.ToggleAction;
+import com.intellij.openapi.project.DumbAware;
+
+/**
+ * @author Konstantin Bulenkov
+ */
+public class WarnOnDeletion extends ToggleAction implements DumbAware {
+ private static final String PROPERTY_NAME = "dir.diff.do.not.show.warnings.when.deleting";
+
+ @Override
+ public boolean isSelected(AnActionEvent e) {
+ return isWarnWhenDeleteItems();
+ }
+
+ @Override
+ public void setSelected(AnActionEvent e, boolean state) {
+ setWarnWhenDeleteItems(state);
+ }
+
+ public static boolean isWarnWhenDeleteItems() {
+ return !PropertiesComponent.getInstance().isTrueValue(PROPERTY_NAME);
+ }
+
+ public static void setWarnWhenDeleteItems(boolean warn) {
+ PropertiesComponent.getInstance().setValue(PROPERTY_NAME, Boolean.valueOf(!warn).toString());
+ }
+}
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java
index 37ab3dd37a6b..b869c574b0f9 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java
@@ -101,7 +101,25 @@ public class AnnotateToggleAction extends ToggleAction implements DumbAware, Ann
public boolean isSelected(AnActionEvent e) {
VcsContext context = VcsContextFactory.SERVICE.getInstance().createContextOn(e);
Editor editor = context.getEditor();
- if (editor == null) return false;
+ if (editor != null) {
+ return isAnnotated(editor);
+ }
+ VirtualFile selectedFile = context.getSelectedFile();
+ if (selectedFile == null) {
+ return false;
+ }
+
+ for (FileEditor fileEditor : FileEditorManager.getInstance(context.getProject()).getEditors(selectedFile)) {
+ if (fileEditor instanceof TextEditor) {
+ if (isAnnotated(((TextEditor)fileEditor).getEditor())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static boolean isAnnotated(@NotNull Editor editor) {
Collection annotations = editor.getUserData(KEY_IN_EDITOR);
return annotations != null && !annotations.isEmpty();
}
@@ -109,14 +127,18 @@ public class AnnotateToggleAction extends ToggleAction implements DumbAware, Ann
public void setSelected(AnActionEvent e, boolean selected) {
final VcsContext context = VcsContextFactory.SERVICE.getInstance().createContextOn(e);
Editor editor = context.getEditor();
+ VirtualFile selectedFile = context.getSelectedFile();
+ if (selectedFile == null) return;
+
if (!selected) {
- if (editor != null) {
- editor.getGutter().closeAllAnnotations();
+ for (FileEditor fileEditor : FileEditorManager.getInstance(context.getProject()).getEditors(selectedFile)) {
+ if (fileEditor instanceof TextEditor) {
+ ((TextEditor)fileEditor).getEditor().getGutter().closeAllAnnotations();
+ }
}
}
else {
if (editor == null) {
- VirtualFile selectedFile = context.getSelectedFile();
FileEditor[] fileEditors = FileEditorManager.getInstance(context.getProject()).openFile(selectedFile, false);
for (FileEditor fileEditor : fileEditors) {
if (fileEditor instanceof TextEditor) {
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/SelectedBlockHistoryAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/SelectedBlockHistoryAction.java
index 867c009ba775..a899185e8ec8 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/SelectedBlockHistoryAction.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/SelectedBlockHistoryAction.java
@@ -90,6 +90,7 @@ public class SelectedBlockHistoryAction extends AbstractVcsAction {
final VcsHistoryDialog vcsHistoryDialog =
new VcsHistoryDialog(project,
context.getSelectedFiles()[0],
+ context.getEditor(),
provider,
session,
activeVcs,
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/DeleteUnversionedFilesAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/DeleteUnversionedFilesAction.java
index 08fc2358cf4e..13410248fc32 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/DeleteUnversionedFilesAction.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/DeleteUnversionedFilesAction.java
@@ -23,12 +23,12 @@
package com.intellij.openapi.vcs.changes.actions;
import com.intellij.ide.DeleteProvider;
-import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
+import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.util.IconUtil;
-public class DeleteUnversionedFilesAction extends AnAction {
+public class DeleteUnversionedFilesAction extends DumbAwareAction {
public DeleteUnversionedFilesAction() {
super("Delete", "Delete", IconUtil.getRemoveIcon());
}
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsHistoryDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsHistoryDialog.java
index 2dbbf7357cf5..0225e5e5263a 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsHistoryDialog.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsHistoryDialog.java
@@ -23,6 +23,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.diff.DiffManager;
import com.intellij.openapi.diff.DiffPanel;
import com.intellij.openapi.diff.SimpleContent;
+import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.help.HelpManager;
import com.intellij.openapi.project.Project;
@@ -56,6 +57,7 @@ import java.util.*;
import java.util.List;
public class VcsHistoryDialog extends DialogWrapper implements DataProvider {
+ private final Editor myEditor;
private final int mySelectionStart;
private final int mySelectionEnd;
@@ -115,7 +117,7 @@ public class VcsHistoryDialog extends DialogWrapper implements DataProvider {
public VcsHistoryDialog(Project project,
final VirtualFile file,
- final VcsHistoryProvider vcsHistoryProvider,
+ Editor editor, final VcsHistoryProvider vcsHistoryProvider,
VcsHistorySession session,
AbstractVcs vcs,
int selectionStart,
@@ -123,6 +125,7 @@ public class VcsHistoryDialog extends DialogWrapper implements DataProvider {
final String title, final CachedRevisionsContents cachedContents){
super(project, true);
myProject = project;
+ myEditor = editor;
mySelectionStart = selectionStart;
mySelectionEnd = selectionEnd;
myCachedContents = cachedContents;
@@ -456,20 +459,23 @@ public class VcsHistoryDialog extends DialogWrapper implements DataProvider {
@Nullable
private Block getBlock(VcsFileRevision revision) throws FilesTooBigForDiffException, VcsException {
- if (myRevisionToContentMap.containsKey(revision))
+ if (myRevisionToContentMap.containsKey(revision)) {
return myRevisionToContentMap.get(revision);
-
- int index = myRevisions.indexOf(revision);
+ }
final String revisionContent = getContentOf(revision);
if (revisionContent == null) return null;
- if (index == 0)
- myRevisionToContentMap.put(revision, new Block(revisionContent, mySelectionStart, mySelectionEnd));
- else {
- Block prevBlock = getBlock(myRevisions.get(index - 1));
- if (prevBlock == null) return null;
- myRevisionToContentMap.put(revision, new FindBlock(revisionContent, prevBlock).getBlockInThePrevVersion());
- }
+
+ int index = myRevisions.indexOf(revision);
+ Block blockByIndex = getBlock(index);
+ if (blockByIndex == null) return null;
+
+ myRevisionToContentMap.put(revision, new FindBlock(revisionContent, blockByIndex).getBlockInThePrevVersion());
return myRevisionToContentMap.get(revision);
}
+
+ private Block getBlock(int index) throws FilesTooBigForDiffException, VcsException {
+ return index > 0 ? getBlock(myRevisions.get(index - 1)) : new Block(myEditor.getDocument().getText(), mySelectionStart, mySelectionEnd);
+ }
+
}
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/DefaultVcsRootPolicy.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/DefaultVcsRootPolicy.java
index 2be72ffccb42..622099e7e0fa 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/DefaultVcsRootPolicy.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/DefaultVcsRootPolicy.java
@@ -52,7 +52,7 @@ public abstract class DefaultVcsRootPolicy {
final StorageScheme storageScheme = ((ProjectEx) project).getStateStore().getStorageScheme();
boolean isDirectoryBased = StorageScheme.DIRECTORY_BASED.equals(storageScheme);
final String[] parts = new String[] {"Content roots of all modules", "all immediate descendants of project base directory",
- ".idea directory contents"};
+ Project.DIRECTORY_STORE_FOLDER + " directory contents"};
final StringBuilder sb = new StringBuilder(parts[0]);
if (isDirectoryBased) {
sb.append(", ");