aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blewitt2009-10-15 14:47:05 (EDT)
committerShawn O. Pearce2009-11-30 20:57:51 (EST)
commit7fe41b7e3c0732c8f391a61d5feabfc14d2965ba (patch)
tree8c5ad59c40c303bb85b3ded912d112682d5db447
parentcb9adcf59464fc49a555516039435c45eb6ccb60 (diff)
downloadegit-7fe41b7e3c0732c8f391a61d5feabfc14d2965ba.zip
egit-7fe41b7e3c0732c8f391a61d5feabfc14d2965ba.tar.gz
egit-7fe41b7e3c0732c8f391a61d5feabfc14d2965ba.tar.bz2
Add to '.gitignore' actionrefs/changes/76/76/2
This adds .gitignore to the object contribution menu, and adds the highlighted elements to the .gitignore file Bug: 291133 Change-Id: Ic202fb67b80be93260974cde21d872a64a4561e6 Signed-off-by: Alex Blewitt <alex.blewitt@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r--org.eclipse.egit.ui/plugin.properties3
-rw-r--r--org.eclipse.egit.ui/plugin.xml19
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/IgnoreAction.java104
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties3
5 files changed, 131 insertions, 7 deletions
diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties
index d05a3b3..040c723 100644
--- a/org.eclipse.egit.ui/plugin.properties
+++ b/org.eclipse.egit.ui/plugin.properties
@@ -43,6 +43,9 @@ CompareWithRevisionAction_tooltip=Compare With a Git Revision
CompareWithIndexAction_label=Git Index
CompareWithIndexAction_tooltip=Compare with Git's index version
+IgnoreAction_label=Add to .git&ignore...
+IgnoreAction_tooltip=Ignore the selected resources
+
ShowResourceInHistoryAction_label=Show in Resource History
ShowResourceInHistoryAction_tooltip=Show selected files in the resource history view.
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index d2936a5..8e2d8b4 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -108,13 +108,18 @@
label="%CommitAction_label"
menubarPath="team.main/group1"
tooltip="%CommitAction_tooltip"/>
- <action
- class="org.eclipse.egit.ui.internal.actions.CompareWithIndexAction"
- id="org.eclipse.egit.ui.internal.actions.CompareWithIndexAction"
- label="%CompareWithIndexAction_label"
- menubarPath="compareWithMenu/gitCompareWithGroup"
- tooltip="%CompareWithIndexAction_tooltip">
- </action>
+ <action
+ class="org.eclipse.egit.ui.internal.actions.CompareWithIndexAction"
+ id="org.eclipse.egit.ui.internal.actions.CompareWithIndexAction"
+ label="%CompareWithIndexAction_label"
+ menubarPath="compareWithMenu/gitCompareWithGroup"
+ tooltip="%CompareWithIndexAction_tooltip"/>
+ <action
+ class="org.eclipse.egit.ui.internal.actions.IgnoreAction"
+ id="org.eclipse.egit.ui.internal.actions.IgnoreAction"
+ label="%IgnoreAction_label"
+ menubarPath="team.main/group1"
+ tooltip="%IgnoreAction_tooltip"/>
</objectContribution>
<objectContribution
id="org.eclipse.egit.ui.resetto"
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
index 6cb986c..8212cee 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
@@ -1082,6 +1082,15 @@ public class UIText extends NLS {
/** */
public static String DecoratorPreferencesPage_iconsShowAssumeValid;
+ /** */
+ public static String IgnoreAction_jobName;
+
+ /** */
+ public static String IgnoreAction_taskName;
+
+ /** */
+ public static String IgnoreAction_error;
+
static {
initializeMessages("org.eclipse.egit.ui.uitext", UIText.class); //$NON-NLS-1$
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/IgnoreAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/IgnoreAction.java
new file mode 100644
index 0000000..1e2088a
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/IgnoreAction.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (C) 2009, Alex Blewitt <alex.blewitt@gmail.com>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * See LICENSE for the full license text, also available.
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.actions;
+
+import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.team.core.Team;
+
+/** Action for ignoring files via .gitignore. */
+public class IgnoreAction extends RepositoryAction {
+ @SuppressWarnings("restriction")
+ @Override
+ public void run(IAction action) {
+ final IResource[] resources = getSelectedResources();
+ if (resources.length == 0)
+ return;
+
+ WorkspaceJob job = new WorkspaceJob(UIText.IgnoreAction_jobName) {
+ public IStatus runInWorkspace(IProgressMonitor monitor)
+ throws CoreException {
+ monitor.beginTask(UIText.IgnoreAction_taskName, resources.length);
+ try {
+ for (IResource resource : resources) {
+ // TODO This is pretty inefficient; multiple ignores in
+ // the same directory cause multiple writes.
+
+ // NB This does the same thing in
+ // DecoratableResourceAdapter, but neither currently
+ // consult .gitignore
+
+ if (!Team.isIgnoredHint(resource)) {
+ addIgnore(monitor, resource);
+ }
+ monitor.worked(1);
+ }
+ monitor.done();
+ } catch (CoreException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new CoreException(
+ new Status(
+ IStatus.ERROR,
+ "org.eclipse.egit.ui", UIText.IgnoreAction_error, e)); //$NON-NLS-1$
+ }
+ return Status.OK_STATUS;
+ }
+
+ private void addIgnore(IProgressMonitor monitor, IResource resource)
+ throws UnsupportedEncodingException, CoreException {
+ IContainer container = resource.getParent();
+ IFile gitignore = container.getFile(new Path(
+ Constants.GITIGNORE_FILENAME));
+ String entry = "/" + resource.getName() + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
+ ByteArrayInputStream entryBytes = asStream(entry);
+
+ if (gitignore.exists())
+ gitignore.appendContents(entryBytes, true, true, monitor);
+ else
+ gitignore.create(entryBytes, true, monitor);
+ }
+
+ private ByteArrayInputStream asStream(String entry)
+ throws UnsupportedEncodingException {
+ return new ByteArrayInputStream(entry
+ .getBytes(Constants.CHARACTER_ENCODING));
+ }
+ };
+ job.schedule();
+ }
+
+ @SuppressWarnings("restriction")
+ @Override
+ public boolean isEnabled() {
+ if (getProjectsInRepositoryOfSelectedResources().length == 0)
+ return false;
+
+ IResource[] resources = getSelectedResources();
+ for (IResource resource : resources) {
+ // NB This does the same thing in DecoratableResourceAdapter, but
+ // neither currently consult .gitignore
+ if (!Team.isIgnoredHint(resource))
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
index 86023c8..4ad29aa 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
@@ -395,3 +395,6 @@ DecoratorPreferencesPage_iconsShowAssumeValid=Assumed unchanged resources
Decorator_exceptionMessage=Errors occurred while applying Git decorations to resources.
+IgnoreAction_jobName=Ignore Git resources
+IgnoreAction_taskName=Ignoring Git resources
+IgnoreAction_error=Unable to ignore resources