VCS: ignore selected file from Unversioned files dialog, edit source on dbl click...
authorirengrig <Irina.Chernushina@jetbrains.com>
Mon, 22 Mar 2010 11:51:31 +0000 (14:51 +0300)
committerirengrig <Irina.Chernushina@jetbrains.com>
Mon, 22 Mar 2010 11:51:31 +0000 (14:51 +0300)
platform/platform-api/src/com/intellij/util/EditSourceOnDoubleClickHandler.java
platform/platform-api/src/com/intellij/util/EditSourceOnEnterKeyHandler.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/UnversionedViewDialog.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/IgnoreUnversionedAction.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesListView.java

index fe14492f353a3e3ea2d577f5b6a7d92c6225b984..6bd9ca0deed3e83f0d28e46224e475d1a81b1913 100644 (file)
@@ -19,10 +19,11 @@ import com.intellij.ide.DataManager;
 import com.intellij.ide.util.treeView.NodeDescriptor;
 import com.intellij.openapi.actionSystem.DataContext;
 import com.intellij.openapi.actionSystem.PlatformDataKeys;
-import com.intellij.openapi.project.Project;
 import com.intellij.openapi.application.ModalityState;
+import com.intellij.openapi.project.Project;
 import com.intellij.ui.treeStructure.treetable.TreeTable;
 import com.intellij.util.ui.Table;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import javax.swing.tree.DefaultMutableTreeNode;
@@ -33,8 +34,15 @@ import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 
 public class EditSourceOnDoubleClickHandler {
+  private EditSourceOnDoubleClickHandler() {
+  }
+
+  public static void install(final JTree tree, @Nullable final Runnable whenPerformed) {
+    tree.addMouseListener(new TreeMouseListener(tree, whenPerformed));
+  }
+
   public static void install(final JTree tree) {
-    tree.addMouseListener(new TreeMouseListener(tree));
+    install(tree, null);
   }
 
   public static void install(final TreeTable treeTable) {
@@ -84,9 +92,15 @@ public class EditSourceOnDoubleClickHandler {
 
   public static class TreeMouseListener extends MouseAdapter {
     private final JTree myTree;
+    @Nullable private final Runnable myWhenPerformed;
 
     public TreeMouseListener(final JTree tree) {
+      this(tree, null);
+    }
+
+    public TreeMouseListener(final JTree tree, @Nullable final Runnable whenPerformed) {
       myTree = tree;
+      myWhenPerformed = whenPerformed;
     }
 
     public void mouseClicked(MouseEvent e) {
@@ -107,6 +121,7 @@ public class EditSourceOnDoubleClickHandler {
 
     protected void processDoubleClick(final MouseEvent e, final DataContext dataContext, final TreeNode lastPathComponent) {
       OpenSourceUtil.openSourcesFrom(dataContext, true);
+      if (myWhenPerformed != null) myWhenPerformed.run();
     }
 
     private static boolean expandOnDoubleClick(final TreeNode treeNode) {
index d2034512564ffb5ef891636bd9f092e746a6c323..3c91e846d55d421b49a82422fd3895bfefa0e0dc 100644 (file)
@@ -60,4 +60,15 @@ public class EditSourceOnEnterKeyHandler{
     }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED);
   }
 
+  public static void install(@Nullable final Runnable before, final JComponent component,
+                           @Nullable final Runnable whenPerformed) {
+    component.registerKeyboardAction(new ActionListener() {
+      public void actionPerformed(ActionEvent e) {
+        DataContext dataContext = DataManager.getInstance().getDataContext(component);
+        if (before != null) before.run();
+        OpenSourceUtil.openSourcesFrom(dataContext, true);
+        if (whenPerformed != null) whenPerformed.run();
+      }
+    }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED);
+  }
 }
index b7666194d9b70b0fb1bb9f9e9d4df9bc57f536bb..b27c8b889cd0ae6f0821f33ea25528bc2e2b4d0c 100644 (file)
@@ -25,12 +25,15 @@ import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.vcs.VcsBundle;
+import com.intellij.openapi.vcs.changes.actions.IgnoreUnversionedAction;
 import com.intellij.openapi.vcs.changes.actions.MoveChangesToAnotherListAction;
 import com.intellij.openapi.vcs.changes.ui.ChangesBrowserNode;
 import com.intellij.openapi.vcs.changes.ui.ChangesBrowserNodeRenderer;
 import com.intellij.openapi.vcs.changes.ui.ChangesListView;
 import com.intellij.openapi.vcs.changes.ui.TreeModelBuilder;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.EditSourceOnDoubleClickHandler;
+import com.intellij.util.EditSourceOnEnterKeyHandler;
 import com.intellij.util.Icons;
 import com.intellij.util.ui.tree.TreeUtil;
 
@@ -39,6 +42,7 @@ import javax.swing.tree.DefaultTreeModel;
 import javax.swing.tree.TreePath;
 import java.awt.*;
 import java.util.Arrays;
+import java.util.LinkedList;
 import java.util.List;
 
 public class UnversionedViewDialog extends DialogWrapper {
@@ -53,6 +57,11 @@ public class UnversionedViewDialog extends DialogWrapper {
     super(project, true);
     setTitle("Unversioned files");
     myProject = project;
+    final Runnable closer = new Runnable() {
+      public void run() {
+        UnversionedViewDialog.this.close(0);
+      }
+    };
     myView = new ChangesListView(project) {
       @Override
       public void calcData(DataKey key, DataSink sink) {
@@ -61,6 +70,12 @@ public class UnversionedViewDialog extends DialogWrapper {
           sink.put(key, Arrays.asList(getSelectedFiles()));
         }
       }
+
+      @Override
+      protected void editSourceRegistration() {
+        EditSourceOnDoubleClickHandler.install(this, closer);
+        EditSourceOnEnterKeyHandler.install(this, closer);
+      }
     };
     myChangeListManager = ChangeListManager.getInstance(project);
     createPanel();
@@ -92,14 +107,16 @@ public class UnversionedViewDialog extends DialogWrapper {
     myPanel = new JPanel(new BorderLayout());
 
     final DefaultActionGroup group = new DefaultActionGroup();
+
+    final List<AnAction> actions = new LinkedList<AnAction>();
     final CommonActionsManager cam = CommonActionsManager.getInstance();
     final Expander expander = new Expander();
     final AnAction expandAction = cam.createExpandAllAction(expander, myView);
-    group.add(expandAction);
+    actions.add(expandAction);
     final AnAction collapseAction = cam.createCollapseAllAction(expander, myView);
-    group.add(collapseAction);
-    group.add(new ToggleShowFlattenAction());
-    group.add(new MoveChangesToAnotherListAction() {
+    actions.add(collapseAction);
+    actions.add(new ToggleShowFlattenAction());
+    actions.add(new MoveChangesToAnotherListAction() {
       @Override
       public void actionPerformed(AnActionEvent e) {
         super.actionPerformed(e);
@@ -107,12 +124,28 @@ public class UnversionedViewDialog extends DialogWrapper {
       }
     });
 
-    myView.setMenuActions(group);
-    myView.setShowFlatten(false);
-
+    for (AnAction action : actions) {
+      group.add(action);
+    }
     final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar("UNVERSIONED_DIALOG", group, false);
     myPanel.add(actionToolbar.getComponent(), BorderLayout.WEST);
     myPanel.add(new JScrollPane(myView), BorderLayout.CENTER);
+
+    actions.add(new IgnoreUnversionedAction() {
+      @Override
+      public void actionPerformed(AnActionEvent e) {
+        super.actionPerformed(e);
+        refreshView();
+      }
+    });
+
+    final DefaultActionGroup secondGroup = new DefaultActionGroup();
+    for (AnAction action : actions) {
+      secondGroup.add(action);
+    }
+
+    myView.setMenuActions(secondGroup);
+    myView.setShowFlatten(false);
   }
 
   @Override
index 6adfb0074b1eec3273bb18eb542e071e3861cee9..e0ef66dacf47514f13454b3fcdaa2cb1f4f40b4b 100644 (file)
@@ -33,6 +33,10 @@ import com.intellij.openapi.vfs.VirtualFile;
 import java.util.List;
 
 public class IgnoreUnversionedAction extends AnAction {
+  public IgnoreUnversionedAction() {
+    super("Ignore...");
+  }
+
   public void actionPerformed(AnActionEvent e) {
     Project project = e.getData(PlatformDataKeys.PROJECT);
     final List<VirtualFile> files = e.getData(ChangesListView.UNVERSIONED_FILES_DATA_KEY);
index 3159ff6a118f77e542e0c019993e48fbead35271..dc0c545f97cbf7d8cdac6963ce10673612e882a5 100644 (file)
@@ -342,6 +342,10 @@ public class ChangesListView extends Tree implements TypeSafeDataProvider, Advan
   public void setMenuActions(final ActionGroup menuGroup) {
     myMenuGroup = menuGroup;
     updateMenu();
+    editSourceRegistration();
+  }
+
+  protected void editSourceRegistration() {
     EditSourceOnDoubleClickHandler.install(this);
     EditSourceOnEnterKeyHandler.install(this);
   }