From 69344c357c8055678e2b9bb1cbb8a74b1650a1fb Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 2 Apr 2012 16:31:54 +0200 Subject: [PATCH] do not automatically include ignored files when adding a directory to cvs --- .../actions/AddFileOrDirectoryAction.java | 77 +++++++------------ .../cvsSupport2/actions/IgnoreFileAction.java | 34 ++++---- 2 files changed, 44 insertions(+), 67 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/AddFileOrDirectoryAction.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/AddFileOrDirectoryAction.java index e55d902b6098..678ac3383951 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/AddFileOrDirectoryAction.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/AddFileOrDirectoryAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -28,9 +28,10 @@ import com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler; import com.intellij.cvsSupport2.cvshandlers.CvsHandler; import com.intellij.cvsSupport2.cvsoperations.cvsAdd.AddedFileInfo; import com.intellij.cvsSupport2.cvsoperations.cvsAdd.ui.AbstractAddOptionsDialog; -import com.intellij.cvsSupport2.ui.Options; import com.intellij.cvsSupport2.ui.CvsTabbedWindow; +import com.intellij.cvsSupport2.ui.Options; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.actions.VcsContext; import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager; @@ -47,31 +48,27 @@ public class AddFileOrDirectoryAction extends ActionOnSelectedElement { private final String myTitle; private final Options myOptions; - private final boolean myIsAutomaticallyAction; public static AddFileOrDirectoryAction createActionToAddNewFileAutomatically() { - return new AddFileOrDirectoryAction(CvsBundle.getAddingFilesOperationName(), Options.ON_FILE_ADDING, true); + return new AddFileOrDirectoryAction(CvsBundle.getAddingFilesOperationName(), Options.ON_FILE_ADDING); } public AddFileOrDirectoryAction() { - this(CvsBundle.getAddingFilesOperationName(), Options.ADD_ACTION, false); + this(CvsBundle.getAddingFilesOperationName(), Options.ADD_ACTION); getVisibility().canBePerformedOnSeveralFiles(); } - public AddFileOrDirectoryAction(String title, Options options, boolean isAutomatically) { + public AddFileOrDirectoryAction(String title, Options options) { super(false); myTitle = title; myOptions = options; - myIsAutomaticallyAction = isAutomatically; - - CvsActionVisibility visibility = getVisibility(); + final CvsActionVisibility visibility = getVisibility(); visibility.addCondition(FILES_ARENT_UNDER_CVS); } public void update(AnActionEvent e) { super.update(e); - if (!e.getPresentation().isVisible()) - return; - Project project = CvsContextWrapper.createInstance(e).getProject(); + if (!e.getPresentation().isVisible()) return; + final Project project = CvsContextWrapper.createInstance(e).getProject(); if (project == null) return; adjustName(CvsVcs2.getInstance(project).getAddOptions().getValue(), e); } @@ -81,41 +78,34 @@ public class AddFileOrDirectoryAction extends ActionOnSelectedElement { } protected CvsHandler getCvsHandler(CvsContext context) { - Project project = context.getProject(); - boolean showDialog = myOptions.isToBeShown(project) || OptionsDialog.shiftIsPressed(context.getModifiers()); - - return getCvsHandler(project, context.getSelectedFiles(), !myIsAutomaticallyAction, showDialog, myOptions); + final Project project = context.getProject(); + final boolean showDialog = myOptions.isToBeShown(project) || OptionsDialog.shiftIsPressed(context.getModifiers()); + return getCvsHandler(project, context.getSelectedFiles(), showDialog, myOptions); } public static CvsHandler getDefaultHandler(Project project, VirtualFile[] files) { - return getCvsHandler(project, files, true, true, Options.NULL); + return getCvsHandler(project, files, true, Options.NULL); } private static CvsHandler getCvsHandler(final Project project, final VirtualFile[] files, - final boolean includeAllRoots, final boolean showDialog, final Options dialogOptions) { - ArrayList filesToAdd = collectFilesToAdd(files); + final ArrayList filesToAdd = collectFilesToAdd(files); if (filesToAdd.isEmpty()) return CvsHandler.NULL; LOG.assertTrue(!filesToAdd.isEmpty()); - Collection roots = new CreateTreeOnFileList(filesToAdd, project, includeAllRoots).getRoots(); - - if (roots.size() == 0) { + final Collection roots = new CreateTreeOnFileList(filesToAdd, project).getRoots(); + if (roots.isEmpty()) { LOG.error(filesToAdd); } if (showDialog){ - AbstractAddOptionsDialog dialog = AbstractAddOptionsDialog.createDialog(project, - roots, - dialogOptions); + final AbstractAddOptionsDialog dialog = AbstractAddOptionsDialog.createDialog(project, roots, dialogOptions); dialog.show(); - if (!dialog.isOK()) return CvsHandler.NULL; } - return CommandCvsHandler.createAddFilesHandler(project, roots); } @@ -123,7 +113,7 @@ public class AddFileOrDirectoryAction extends ActionOnSelectedElement { protected void onActionPerformed(final CvsContext context, final CvsTabbedWindow tabbedWindow, final boolean successfully, final CvsHandler handler) { super.onActionPerformed(context, tabbedWindow, successfully, handler); - VirtualFile[] filesToAdd = context.getSelectedFiles(); + final VirtualFile[] filesToAdd = context.getSelectedFiles(); final VcsDirtyScopeManager dirtyScopeManager = VcsDirtyScopeManager.getInstance(context.getProject()); for(VirtualFile file: filesToAdd) { if (file.isDirectory()) { @@ -136,9 +126,9 @@ public class AddFileOrDirectoryAction extends ActionOnSelectedElement { } private static ArrayList collectFilesToAdd(final VirtualFile[] files) { - ArrayList result = new ArrayList(); + final ArrayList result = new ArrayList(); for (VirtualFile file : files) { - List parentsToAdd = new ArrayList(); + final List parentsToAdd = new ArrayList(); VirtualFile parent = file.getParent(); do { if (parent == null || CvsUtil.fileExistsInCvs(parent) || result.contains(parent)) break; @@ -150,23 +140,20 @@ public class AddFileOrDirectoryAction extends ActionOnSelectedElement { if (parent != null) { result.addAll(parentsToAdd); } - addFilesToCollection(result, file); } - Collections.sort(result, new Comparator() { public int compare(final VirtualFile o1, final VirtualFile o2) { return o1.getPath().compareTo(o2.getPath()); } }); - return result; } private static void addFilesToCollection(Collection collection, VirtualFile file) { if (DeletedCVSDirectoryStorage.isAdminDir(file)) return; collection.add(file); - VirtualFile[] children = file.getChildren(); + final VirtualFile[] children = file.getChildren(); if (children == null) return; for (VirtualFile child : children) { addFilesToCollection(collection, child); @@ -175,21 +162,18 @@ public class AddFileOrDirectoryAction extends ActionOnSelectedElement { static class CreateTreeOnFileList { private final Collection myFiles; - private final Map myResult - = new HashMap(); + private final Map myResult = new HashMap(); private final Project myProject; - public CreateTreeOnFileList(Collection files, Project project, boolean shouldIncludeAllRoots) { + public CreateTreeOnFileList(Collection files, Project project) { myFiles = files; myProject = project; fillFileToInfoMap(); setAllParents(); - if (!shouldIncludeAllRoots) { - final CvsEntriesManager entriesManager = CvsEntriesManager.getInstance(); - for (final VirtualFile file : files) { - if (entriesManager.fileIsIgnored(file)) { - myResult.get(file).setIncluded(false); - } + final CvsEntriesManager entriesManager = CvsEntriesManager.getInstance(); + for (final VirtualFile file : files) { + if (entriesManager.fileIsIgnored(file) || FileTypeManager.getInstance().isFileIgnored(file)) { + myResult.get(file).setIncluded(false); } } removeFromMapInfoWithParentAndResortAll(); @@ -202,7 +186,7 @@ public class AddFileOrDirectoryAction extends ActionOnSelectedElement { private void removeFromMapInfoWithParentAndResortAll() { for (final VirtualFile file : myFiles) { if (myResult.containsKey(file)) { - AddedFileInfo info = myResult.get(file); + final AddedFileInfo info = myResult.get(file); if (info.getParent() != null) { myResult.remove(file); } @@ -216,7 +200,7 @@ public class AddFileOrDirectoryAction extends ActionOnSelectedElement { private void setAllParents() { for (final VirtualFile file : myFiles) { if (myResult.containsKey(file.getParent()) && myResult.containsKey(file)) { - AddedFileInfo info = myResult.get(file); + final AddedFileInfo info = myResult.get(file); info.setParent(myResult.get(file.getParent())); } } @@ -227,8 +211,5 @@ public class AddFileOrDirectoryAction extends ActionOnSelectedElement { myResult.put(file, new AddedFileInfo(file, myProject, CvsConfiguration.getInstance(myProject))); } } - - } - } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/IgnoreFileAction.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/IgnoreFileAction.java index 75b428a19981..8e4b2258378b 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/IgnoreFileAction.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/actions/IgnoreFileAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -35,6 +35,7 @@ import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager; import com.intellij.openapi.vcs.ui.Refreshable; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.containers.HashMap; import java.io.File; import java.io.IOException; @@ -43,13 +44,12 @@ import java.util.*; /** * author: lesya */ - public class IgnoreFileAction extends AnAction { private static final Logger LOG = Logger.getInstance("#com.intellij.cvsSupport2.actions.IgnoreFileAction"); private final CvsActionVisibility myVisibility = new CvsActionVisibility(); - private final Map> myParentToSelectedChildren = new com.intellij.util.containers.HashMap>(); + private final Map> myParentToSelectedChildren = new HashMap>(); public IgnoreFileAction() { myVisibility.canBePerformedOnSeveralFiles(); @@ -57,17 +57,15 @@ public class IgnoreFileAction extends AnAction { myVisibility.addCondition(ActionOnSelectedElement.FILES_ARE_NOT_IGNORED); } - public void update(AnActionEvent e) { myVisibility.applyToEvent(e); } public void actionPerformed(AnActionEvent e) { - CvsContext context = CvsContextWrapper.createCachedInstance(e); - VirtualFile[] selectedFiles = context.getSelectedFiles(); - + final CvsContext context = CvsContextWrapper.createCachedInstance(e); + final VirtualFile[] selectedFiles = context.getSelectedFiles(); for (VirtualFile selectedFile : selectedFiles) { - VirtualFile parent = selectedFile.getParent(); + final VirtualFile parent = selectedFile.getParent(); if (!myParentToSelectedChildren.containsKey(parent)) myParentToSelectedChildren.put(parent, new HashSet()); myParentToSelectedChildren.get(parent).add(selectedFile); try { @@ -79,13 +77,11 @@ public class IgnoreFileAction extends AnAction { CvsBundle.message("message.error.ignore.files.title")); } } - refreshFilesAndStatuses(context); - } private static void refreshPanel(CvsContext context) { - Refreshable refreshablePanel = context.getRefreshableDialog(); + final Refreshable refreshablePanel = context.getRefreshableDialog(); if (refreshablePanel != null) { refreshablePanel.restoreState(); refreshablePanel.refresh(); @@ -93,7 +89,7 @@ public class IgnoreFileAction extends AnAction { } private void refreshFilesAndStatuses(final CvsContext context) { - Refreshable refreshablePanel = context.getRefreshableDialog(); + final Refreshable refreshablePanel = context.getRefreshableDialog(); if (refreshablePanel != null) refreshablePanel.saveState(); final int[] refreshedParents = new int[]{0}; final Collection createdCvsIgnoreFiles = new ArrayList(); @@ -109,10 +105,11 @@ public class IgnoreFileAction extends AnAction { return new Runnable() { public void run() { try { - VirtualFile cvsIgnoreFile = CvsVfsUtil.refreshAndfFindChild(parent, CvsUtil.CVS_IGNORE_FILE); + final VirtualFile cvsIgnoreFile = CvsVfsUtil.refreshAndfFindChild(parent, CvsUtil.CVS_IGNORE_FILE); if (cvsIgnoreFile == null) { - String path = parent.getPath() + "/" + CvsUtil.CVS_IGNORE_FILE; - LOG.error(String.valueOf(CvsVfsUtil.findFileByPath(path)) + " " + parent.getPath() + " " + new File(VfsUtil.virtualToIoFile(parent), CvsUtil.CVS_IGNORE_FILE).isFile()); + final String path = parent.getPath() + "/" + CvsUtil.CVS_IGNORE_FILE; + LOG.error(String.valueOf(CvsVfsUtil.findFileByPath(path)) + " " + parent.getPath() + " " + + new File(VfsUtil.virtualToIoFile(parent), CvsUtil.CVS_IGNORE_FILE).isFile()); return; } @@ -120,7 +117,7 @@ public class IgnoreFileAction extends AnAction { createdCvsIgnoreFiles.add(cvsIgnoreFile); } - Set filesToUpdateStatus = myParentToSelectedChildren.get(parent); + final Set filesToUpdateStatus = myParentToSelectedChildren.get(parent); for (final VirtualFile file : filesToUpdateStatus) { FileStatusManager.getInstance(context.getProject()).fileStatusChanged(file); VcsDirtyScopeManager.getInstance(context.getProject()).fileDirty(file); @@ -144,7 +141,7 @@ public class IgnoreFileAction extends AnAction { } private AddFileOrDirectoryAction createAddFilesAction() { - return new AddFileOrDirectoryAction(CvsBundle.message("adding.cvsignore.files.to.cvs.action.name"), Options.ON_FILE_ADDING, true) { + return new AddFileOrDirectoryAction(CvsBundle.message("adding.cvsignore.files.to.cvs.action.name"), Options.ON_FILE_ADDING) { protected void onActionPerformed(CvsContext context, CvsTabbedWindow tabbedWindow, boolean successfully, @@ -156,8 +153,7 @@ public class IgnoreFileAction extends AnAction { }; } - private static CvsContextAdapter createContext(final Collection createdCvsIgnoreFiles, - final CvsContext context) { + private static CvsContextAdapter createContext(final Collection createdCvsIgnoreFiles, final CvsContext context) { return new CvsContextAdapter() { public VirtualFile[] getSelectedFiles() { return VfsUtil.toVirtualFileArray(createdCvsIgnoreFiles);